From 284eaf157692469e061782fbf3753e22ee5eb861 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 10 Apr 2016 19:38:57 +0200 Subject: [PATCH] Use Depth Texture on OpenGL 3.3 --- src/rlgl.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rlgl.c b/src/rlgl.c index f0acf124..b659577a 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1688,7 +1688,7 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height) target.depth.id = 0; target.depth.width = width; target.depth.height = height; - target.depth.format = 19; //DEPTH_COMPONENT_16BIT + target.depth.format = 19; //DEPTH_COMPONENT_24BIT target.depth.mipmaps = 1; #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) @@ -1701,14 +1701,18 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, 0); - -#define USE_DEPTH_RENDERBUFFER + +#if defined(GRAPHICS_API_OPENGL_33) + #define USE_DEPTH_TEXTURE +#else + #define USE_DEPTH_RENDERBUFFER +#endif + #if defined(USE_DEPTH_RENDERBUFFER) // Create the renderbuffer that will serve as the depth attachment for the framebuffer. glGenRenderbuffers(1, &target.depth.id); glBindRenderbuffer(GL_RENDERBUFFER, target.depth.id); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); - #elif defined(USE_DEPTH_TEXTURE) // NOTE: We can also use a texture for depth buffer (GL_ARB_depth_texture/GL_OES_depth_texture extension required) // A renderbuffer is simpler than a texture and could offer better performance on embedded devices @@ -1718,7 +1722,7 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); glBindTexture(GL_TEXTURE_2D, 0); #endif