Window capture: clear background with black color

This commit is contained in:
dec05eba
2024-02-08 19:06:09 +01:00
parent ad777a5136
commit d1c49f35a5
4 changed files with 47 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ typedef struct {
int gsr_color_conversion_init(gsr_color_conversion *self, const gsr_color_conversion_params *params);
void gsr_color_conversion_deinit(gsr_color_conversion *self);
int gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture);
void gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture);
void gsr_color_conversion_clear(gsr_color_conversion *self);
#endif /* GSR_COLOR_CONVERSION_H */

View File

@@ -272,6 +272,7 @@ static void gsr_capture_xcomposite_cuda_stop(gsr_capture *cap, AVCodecContext *v
static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) {
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT);
bool init_new_window = false;

View File

@@ -199,6 +199,7 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext *
gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv;
// TODO:
cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT);
bool init_new_window = false;
@@ -418,6 +419,8 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext *
return;
}
}
gsr_color_conversion_clear(&cap_xcomp->color_conversion);
}
}

View File

@@ -362,7 +362,7 @@ void gsr_color_conversion_deinit(gsr_color_conversion *self) {
}
/* |source_pos| is in pixel coordinates and |source_size| */
int gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture) {
void gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture) {
/* TODO: Do not call this every frame? */
vec2i dest_texture_size = {0, 0};
self->params.egl->glBindTexture(GL_TEXTURE_2D, self->params.destination_textures[0]);
@@ -453,5 +453,44 @@ int gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_i
gsr_shader_use_none(&self->shaders[0]);
self->params.egl->glBindTexture(texture_target, 0);
self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, 0);
return 0;
}
void gsr_color_conversion_clear(gsr_color_conversion *self) {
float color1[4];
float color2[4];
switch(self->params.destination_color) {
case GSR_DESTINATION_COLOR_BGR: {
color1[0] = 0.0f;
color1[1] = 0.0f;
color1[2] = 0.0f;
color1[3] = 1.0f;
break;
}
case GSR_DESTINATION_COLOR_NV12:
case GSR_DESTINATION_COLOR_P010: {
color1[0] = 0.0f;
color1[1] = 0.0f;
color1[2] = 0.0f;
color1[3] = 1.0f;
color2[0] = 0.5f;
color2[1] = 0.5f;
color2[2] = 0.0f;
color2[3] = 1.0f;
break;
}
}
self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffers[0]);
self->params.egl->glClearColor(color1[0], color1[1], color1[2], color1[3]);
self->params.egl->glClear(GL_COLOR_BUFFER_BIT);
if(self->params.num_destination_textures > 1) {
self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffers[1]);
self->params.egl->glClearColor(color2[0], color2[1], color2[2], color2[3]);
self->params.egl->glClear(GL_COLOR_BUFFER_BIT);
}
self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, 0);
}