gsk gl: Make it possible to clear a rectangle

Add a blend mode to the draw command, so it can draw transparent
black. This will be used to erase the area on top of a subsurface
when we do passthrough.
This commit is contained in:
Matthias Clasen 2023-11-08 11:26:50 +01:00
parent b7c2528ad1
commit c636baf6f5
2 changed files with 10 additions and 1 deletions

View File

@ -609,6 +609,7 @@ gsk_gl_command_queue_begin_draw (GskGLCommandQueue *self,
batch->any.next_batch_index = -1;
batch->any.viewport.width = width;
batch->any.viewport.height = height;
batch->draw.blend = 1;
batch->draw.framebuffer = 0;
batch->draw.uniform_count = 0;
batch->draw.uniform_offset = self->batch_uniforms.len;
@ -685,6 +686,7 @@ gsk_gl_command_queue_end_draw (GskGLCommandQueue *self)
last_batch->any.program == batch->any.program &&
last_batch->any.viewport.width == batch->any.viewport.width &&
last_batch->any.viewport.height == batch->any.viewport.height &&
last_batch->draw.blend == batch->draw.blend &&
last_batch->draw.framebuffer == batch->draw.framebuffer &&
last_batch->draw.vbo_offset + last_batch->draw.vbo_count == batch->draw.vbo_offset &&
last_batch->draw.vbo_count + batch->draw.vbo_count <= 0xffff &&
@ -1247,8 +1249,13 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self,
n_uniforms += batch->draw.uniform_count;
}
if (batch->draw.blend == 0)
glDisable (GL_BLEND);
glDrawArrays (GL_TRIANGLES, batch->draw.vbo_offset, batch->draw.vbo_count);
if (batch->draw.blend == 0)
glEnable (GL_BLEND);
break;
default:

View File

@ -101,13 +101,15 @@ typedef struct _GskGLCommandDraw
{
GskGLCommandBatchAny head;
guint blend : 1;
/* There doesn't seem to be a limit on the framebuffer identifier that
* can be returned, so we have to use a whole unsigned for the framebuffer
* we are drawing to. When processing batches, we check to see if this
* changes and adjust the render target accordingly. Some sorting is
* performed to reduce the amount we change framebuffers.
*/
guint framebuffer;
guint framebuffer : 31;
/* The number of uniforms to change. This must be less than or equal to
* GL_MAX_UNIFORM_LOCATIONS but only guaranteed up to 1024 by any OpenGL