Use Depth Texture on OpenGL 3.3
This commit is contained in:
parent
c1e49d2b13
commit
284eaf1576
1 changed files with 9 additions and 5 deletions
14
src/rlgl.c
14
src/rlgl.c
|
@ -1688,7 +1688,7 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height)
|
||||||
target.depth.id = 0;
|
target.depth.id = 0;
|
||||||
target.depth.width = width;
|
target.depth.width = width;
|
||||||
target.depth.height = height;
|
target.depth.height = height;
|
||||||
target.depth.format = 19; //DEPTH_COMPONENT_16BIT
|
target.depth.format = 19; //DEPTH_COMPONENT_24BIT
|
||||||
target.depth.mipmaps = 1;
|
target.depth.mipmaps = 1;
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#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);
|
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);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
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)
|
#if defined(USE_DEPTH_RENDERBUFFER)
|
||||||
// Create the renderbuffer that will serve as the depth attachment for the framebuffer.
|
// Create the renderbuffer that will serve as the depth attachment for the framebuffer.
|
||||||
glGenRenderbuffers(1, &target.depth.id);
|
glGenRenderbuffers(1, &target.depth.id);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, target.depth.id);
|
glBindRenderbuffer(GL_RENDERBUFFER, target.depth.id);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
||||||
|
|
||||||
#elif defined(USE_DEPTH_TEXTURE)
|
#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)
|
// 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
|
// 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_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue