mirror of
https://repo.dec05eba.com/gpu-screen-recorder
synced 2026-05-06 15:00:43 +09:00
Dont use glGetTexLevelParameteriv, it's only available in opengl es 3.1
This commit is contained in:
@@ -12,6 +12,7 @@ typedef struct {
|
||||
gsr_video_encoder_nvenc_params params;
|
||||
|
||||
unsigned int target_textures[2];
|
||||
vec2i target_texture_size[2];
|
||||
|
||||
AVBufferRef *device_ctx;
|
||||
|
||||
@@ -95,7 +96,8 @@ static bool gsr_video_encoder_nvenc_setup_textures(gsr_video_encoder_nvenc *self
|
||||
const int div[2] = {1, 2}; // divide UV texture size by 2 because chroma is half size
|
||||
|
||||
for(int i = 0; i < 2; ++i) {
|
||||
self->target_textures[i] = gl_create_texture(self->params.egl, video_codec_context->width / div[i], video_codec_context->height / div[i], self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
|
||||
self->target_texture_size[i] = (vec2i){ video_codec_context->width / div[i], video_codec_context->height / div[i] };
|
||||
self->target_textures[i] = gl_create_texture(self->params.egl, self->target_texture_size[i].x, self->target_texture_size[i].y, self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
|
||||
if(self->target_textures[i] == 0) {
|
||||
fprintf(stderr, "gsr error: gsr_video_encoder_nvenc_setup_textures: failed to create opengl texture\n");
|
||||
return false;
|
||||
@@ -198,10 +200,12 @@ static void gsr_video_encoder_nvenc_copy_textures_to_frame(gsr_video_encoder *en
|
||||
self->cuda.cuStreamSynchronize(self->cuda_stream);
|
||||
}
|
||||
|
||||
static void gsr_video_encoder_nvenc_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
|
||||
static void gsr_video_encoder_nvenc_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
|
||||
gsr_video_encoder_nvenc *self = encoder->priv;
|
||||
textures[0] = self->target_textures[0];
|
||||
textures[1] = self->target_textures[1];
|
||||
texture_sizes[0] = self->target_texture_size[0];
|
||||
texture_sizes[1] = self->target_texture_size[1];
|
||||
*num_textures = 2;
|
||||
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef struct {
|
||||
gsr_video_encoder_software_params params;
|
||||
|
||||
unsigned int target_textures[2];
|
||||
vec2i texture_sizes[2];
|
||||
} gsr_video_encoder_software;
|
||||
|
||||
static bool gsr_video_encoder_software_setup_textures(gsr_video_encoder_software *self, AVCodecContext *video_codec_context, AVFrame *frame) {
|
||||
@@ -34,7 +35,8 @@ static bool gsr_video_encoder_software_setup_textures(gsr_video_encoder_software
|
||||
const int div[2] = {1, 2}; // divide UV texture size by 2 because chroma is half size
|
||||
|
||||
for(int i = 0; i < 2; ++i) {
|
||||
self->target_textures[i] = gl_create_texture(self->params.egl, video_codec_context->width / div[i], video_codec_context->height / div[i], self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
|
||||
self->texture_sizes[i] = (vec2i){ video_codec_context->width / div[i], video_codec_context->height / div[i] };
|
||||
self->target_textures[i] = gl_create_texture(self->params.egl, self->texture_sizes[i].x, self->texture_sizes[i].y, self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
|
||||
if(self->target_textures[i] == 0) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_kms_setup_cuda_textures: failed to create opengl texture\n");
|
||||
return false;
|
||||
@@ -86,10 +88,12 @@ static void gsr_video_encoder_software_copy_textures_to_frame(gsr_video_encoder
|
||||
//self->params.egl->glFinish();
|
||||
}
|
||||
|
||||
static void gsr_video_encoder_software_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
|
||||
static void gsr_video_encoder_software_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
|
||||
gsr_video_encoder_software *self = encoder->priv;
|
||||
textures[0] = self->target_textures[0];
|
||||
textures[1] = self->target_textures[1];
|
||||
texture_sizes[0] = self->texture_sizes[0];
|
||||
texture_sizes[1] = self->texture_sizes[1];
|
||||
*num_textures = 2;
|
||||
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ typedef struct {
|
||||
gsr_video_encoder_vaapi_params params;
|
||||
|
||||
unsigned int target_textures[2];
|
||||
vec2i texture_sizes[2];
|
||||
|
||||
AVBufferRef *device_ctx;
|
||||
VADisplay va_dpy;
|
||||
@@ -112,6 +113,7 @@ static bool gsr_video_encoder_vaapi_setup_textures(gsr_video_encoder_vaapi *self
|
||||
intptr_t img_attr[44];
|
||||
setup_dma_buf_attrs(img_attr, formats[i], self->prime.width / div[i], self->prime.height / div[i],
|
||||
fds, offsets, pitches, modifiers, self->prime.layers[layer].num_planes, true);
|
||||
self->texture_sizes[i] = (vec2i){ self->prime.width / div[i], self->prime.height / div[i] };
|
||||
|
||||
while(self->params.egl->eglGetError() != EGL_SUCCESS){}
|
||||
EGLImage image = self->params.egl->eglCreateImage(self->params.egl->egl_display, 0, EGL_LINUX_DMA_BUF_EXT, NULL, img_attr);
|
||||
@@ -214,10 +216,12 @@ void gsr_video_encoder_vaapi_stop(gsr_video_encoder_vaapi *self, AVCodecContext
|
||||
}
|
||||
}
|
||||
|
||||
static void gsr_video_encoder_vaapi_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
|
||||
static void gsr_video_encoder_vaapi_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
|
||||
gsr_video_encoder_vaapi *self = encoder->priv;
|
||||
textures[0] = self->target_textures[0];
|
||||
textures[1] = self->target_textures[1];
|
||||
texture_sizes[0] = self->texture_sizes[0];
|
||||
texture_sizes[1] = self->texture_sizes[1];
|
||||
*num_textures = 2;
|
||||
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ void gsr_video_encoder_copy_textures_to_frame(gsr_video_encoder *encoder, AVFram
|
||||
encoder->copy_textures_to_frame(encoder, frame, color_conversion);
|
||||
}
|
||||
|
||||
void gsr_video_encoder_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
|
||||
void gsr_video_encoder_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
|
||||
assert(encoder->started);
|
||||
encoder->get_textures(encoder, textures, num_textures, destination_color);
|
||||
encoder->get_textures(encoder, textures, texture_sizes, num_textures, destination_color);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
typedef struct {
|
||||
gsr_video_encoder_vulkan_params params;
|
||||
unsigned int target_textures[2];
|
||||
vec2i texture_sizes[2];
|
||||
AVBufferRef *device_ctx;
|
||||
} gsr_video_encoder_vulkan;
|
||||
|
||||
@@ -224,6 +225,9 @@ static bool gsr_video_encoder_vulkan_setup_textures(gsr_video_encoder_vulkan *se
|
||||
|
||||
fprintf(stderr, "3 gl error: %d\n", self->params.egl->glGetError());
|
||||
self->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
self->texture_sizes[0] = (vec2i){ frame->width, frame->height };
|
||||
self->texture_sizes[1] = (vec2i){ frame->width/2, frame->height/2 };
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
@@ -270,10 +274,12 @@ void gsr_video_encoder_vulkan_stop(gsr_video_encoder_vulkan *self, AVCodecContex
|
||||
av_buffer_unref(&self->device_ctx);
|
||||
}
|
||||
|
||||
static void gsr_video_encoder_vulkan_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
|
||||
static void gsr_video_encoder_vulkan_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
|
||||
gsr_video_encoder_vulkan *self = encoder->priv;
|
||||
textures[0] = self->target_textures[0];
|
||||
textures[1] = self->target_textures[1];
|
||||
texture_sizes[0] = self->texture_sizes[0];
|
||||
texture_sizes[1] = self->texture_sizes[1];
|
||||
*num_textures = 2;
|
||||
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user