From 03fe50651baeb506ca8b6fb2b597598a096be2f6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 20 Mar 2017 13:20:35 +0100 Subject: vo_opengl: move some init_gl code to utility functions --- video/out/opengl/utils.c | 46 +++++++++++++++++++++++++++++++++++ video/out/opengl/utils.h | 3 +++ video/out/opengl/video.c | 62 ++++++++++-------------------------------------- 3 files changed, 61 insertions(+), 50 deletions(-) (limited to 'video') diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c index 9b01912041..420df369f0 100644 --- a/video/out/opengl/utils.c +++ b/video/out/opengl/utils.c @@ -1249,3 +1249,49 @@ void gl_pbo_upload_uninit(struct gl_pbo_upload *pbo) pbo->gl->DeleteBuffers(NUM_PBO_BUFFERS, &pbo->buffers[0]); *pbo = (struct gl_pbo_upload){0}; } + +// The intention is to return the actual depth of any fixed point 16 bit +// textures. (Actually tests only 1 format - hope that is good enough.) +int gl_determine_16bit_tex_depth(GL *gl) +{ + const struct gl_format *fmt = gl_find_unorm_format(gl, 2, 1); + if (!gl->GetTexLevelParameteriv || !fmt) + return -1; + + GLuint tex; + gl->GenTextures(1, &tex); + gl->BindTexture(GL_TEXTURE_2D, tex); + gl->TexImage2D(GL_TEXTURE_2D, 0, fmt->internal_format, 64, 64, 0, + fmt->format, fmt->type, NULL); + GLenum pname = 0; + switch (fmt->format) { + case GL_RED: pname = GL_TEXTURE_RED_SIZE; break; + case GL_LUMINANCE: pname = GL_TEXTURE_LUMINANCE_SIZE; break; + } + GLint param = -1; + if (pname) + gl->GetTexLevelParameteriv(GL_TEXTURE_2D, 0, pname, ¶m); + gl->DeleteTextures(1, &tex); + return param; +} + +int gl_get_fb_depth(GL *gl, int fbo) +{ + if ((gl->es < 300 && !gl->version) || !(gl->mpgl_caps & MPGL_CAP_FB)) + return -1; + + gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); + + GLenum obj = gl->version ? GL_BACK_LEFT : GL_BACK; + if (fbo) + obj = GL_COLOR_ATTACHMENT0; + + GLint depth_g = -1; + + gl->GetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, obj, + GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &depth_g); + + gl->BindFramebuffer(GL_FRAMEBUFFER, 0); + + return depth_g > 0 ? depth_g : -1; +} diff --git a/video/out/opengl/utils.h b/video/out/opengl/utils.h index f4e522cdf7..069844caa6 100644 --- a/video/out/opengl/utils.h +++ b/video/out/opengl/utils.h @@ -200,4 +200,7 @@ void gl_pbo_upload_tex(struct gl_pbo_upload *pbo, GL *gl, bool use_pbo, int x, int y, int w, int h); void gl_pbo_upload_uninit(struct gl_pbo_upload *pbo); +int gl_determine_16bit_tex_depth(GL *gl); +int gl_get_fb_depth(GL *gl, int fbo); + #endif diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 955fa2868a..6ad1db6b90 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -3122,56 +3122,18 @@ static void init_gl(struct gl_video *p) gl_video_set_gl_state(p); - // Test whether we can use 10 bit. Hope that testing a single format/channel - // is good enough (instead of testing all 1-4 channels variants etc.). - const struct gl_format *fmt = gl_find_unorm_format(gl, 2, 1); - if (gl->GetTexLevelParameteriv && fmt) { - GLuint tex; - gl->GenTextures(1, &tex); - gl->BindTexture(GL_TEXTURE_2D, tex); - gl->TexImage2D(GL_TEXTURE_2D, 0, fmt->internal_format, 64, 64, 0, - fmt->format, fmt->type, NULL); - GLenum pname = 0; - switch (fmt->format) { - case GL_RED: pname = GL_TEXTURE_RED_SIZE; break; - case GL_LUMINANCE: pname = GL_TEXTURE_LUMINANCE_SIZE; break; - } - GLint param = 0; - if (pname) - gl->GetTexLevelParameteriv(GL_TEXTURE_2D, 0, pname, ¶m); - if (param) { - MP_VERBOSE(p, "16 bit texture depth: %d.\n", (int)param); - p->texture_16bit_depth = param; - } - gl->DeleteTextures(1, &tex); - } - - if ((gl->es >= 300 || gl->version) && (gl->mpgl_caps & MPGL_CAP_FB)) { - gl->BindFramebuffer(GL_FRAMEBUFFER, gl->main_fb); - - debug_check_gl(p, "before retrieving framebuffer depth"); - - GLenum obj = gl->version ? GL_BACK_LEFT : GL_BACK; - if (gl->main_fb) - obj = GL_COLOR_ATTACHMENT0; - - GLint depth_r = -1, depth_g = -1, depth_b = -1; - - gl->GetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, obj, - GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &depth_r); - gl->GetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, obj, - GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &depth_g); - gl->GetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, obj, - GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &depth_b); - - debug_check_gl(p, "retrieving framebuffer depth"); - - MP_VERBOSE(p, "Reported display depth: R=%d, G=%d, B=%d\n", - depth_r, depth_g, depth_b); - - p->fb_depth = depth_g > 0 ? depth_g : 8; - - gl->BindFramebuffer(GL_FRAMEBUFFER, 0); + // Test whether we can use 10 bit. + p->texture_16bit_depth = gl_determine_16bit_tex_depth(gl); + if (p->texture_16bit_depth > 0) + MP_VERBOSE(p, "16 bit texture depth: %d.\n", p->texture_16bit_depth); + + debug_check_gl(p, "before retrieving framebuffer depth"); + p->fb_depth = gl_get_fb_depth(gl, gl->main_fb); + debug_check_gl(p, "retrieving framebuffer depth"); + if (p->fb_depth > 0) { + MP_VERBOSE(p, "Reported display depth: %d\n", p->fb_depth); + } else { + p->fb_depth = 8; } p->upload_timer = gl_timer_create(p->gl); -- cgit v1.2.3