summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/out/opengl/utils.c')
-rw-r--r--video/out/opengl/utils.c46
1 files changed, 46 insertions, 0 deletions
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, &param);
+ 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;
+}