REVIEWED: Issue with depth textures on WebGL #2824
This commit is contained in:
parent
445ce51e51
commit
619331f4a7
1 changed files with 17 additions and 10 deletions
27
src/rlgl.h
27
src/rlgl.h
|
@ -987,7 +987,8 @@ typedef struct rlglData {
|
||||||
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
|
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
|
||||||
bool instancing; // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
|
bool instancing; // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
|
||||||
bool texNPOT; // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
|
bool texNPOT; // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
|
||||||
bool texDepth; // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)
|
bool texDepth; // Depth textures supported (GL_ARB_depth_texture, GL_OES_depth_texture)
|
||||||
|
bool texDepthWebGL; // Depth textures supported WebGL specific (GL_WEBGL_depth_texture)
|
||||||
bool texFloat32; // float textures support (32 bit per channel) (GL_OES_texture_float)
|
bool texFloat32; // float textures support (32 bit per channel) (GL_OES_texture_float)
|
||||||
bool texCompDXT; // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
|
bool texCompDXT; // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
|
||||||
bool texCompETC1; // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
|
bool texCompETC1; // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
|
||||||
|
@ -2218,11 +2219,12 @@ void rlLoadExtensions(void *loader)
|
||||||
if (strcmp(extList[i], (const char *)"GL_OES_texture_float") == 0) RLGL.ExtSupported.texFloat32 = true;
|
if (strcmp(extList[i], (const char *)"GL_OES_texture_float") == 0) RLGL.ExtSupported.texFloat32 = true;
|
||||||
|
|
||||||
// Check depth texture support
|
// Check depth texture support
|
||||||
if ((strcmp(extList[i], (const char *)"GL_OES_depth_texture") == 0) ||
|
if (strcmp(extList[i], (const char *)"GL_OES_depth_texture") == 0) RLGL.ExtSupported.texDepth = true;
|
||||||
(strcmp(extList[i], (const char *)"GL_WEBGL_depth_texture") == 0)) RLGL.ExtSupported.texDepth = true;
|
if (strcmp(extList[i], (const char *)"GL_WEBGL_depth_texture") == 0) RLGL.ExtSupported.texDepthWebGL = true; // WebGL requires unsized internal format
|
||||||
|
if (RLGL.ExtSupported.texDepthWebGL) RLGL.ExtSupported.texDepth = true;
|
||||||
|
|
||||||
if (strcmp(extList[i], (const char *)"GL_OES_depth24") == 0) RLGL.ExtSupported.maxDepthBits = 24;
|
if (strcmp(extList[i], (const char *)"GL_OES_depth24") == 0) RLGL.ExtSupported.maxDepthBits = 24; // Not available on WebGL
|
||||||
if (strcmp(extList[i], (const char *)"GL_OES_depth32") == 0) RLGL.ExtSupported.maxDepthBits = 32;
|
if (strcmp(extList[i], (const char *)"GL_OES_depth32") == 0) RLGL.ExtSupported.maxDepthBits = 32; // Not available on WebGL
|
||||||
|
|
||||||
// Check texture compression support: DXT
|
// Check texture compression support: DXT
|
||||||
if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) ||
|
if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) ||
|
||||||
|
@ -2975,7 +2977,7 @@ unsigned int rlLoadTexture(const void *data, int width, int height, int format,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load depth texture/renderbuffer (to be attached to fbo)
|
// Load depth texture/renderbuffer (to be attached to fbo)
|
||||||
// WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions
|
// WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture and WebGL requires WEBGL_depth_texture extensions
|
||||||
unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
|
unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
|
||||||
{
|
{
|
||||||
unsigned int id = 0;
|
unsigned int id = 0;
|
||||||
|
@ -2983,15 +2985,20 @@ unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// In case depth textures not supported, we force renderbuffer usage
|
// In case depth textures not supported, we force renderbuffer usage
|
||||||
if (!RLGL.ExtSupported.texDepth) useRenderBuffer = true;
|
if (!RLGL.ExtSupported.texDepth) useRenderBuffer = true;
|
||||||
|
|
||||||
// NOTE: We let the implementation to choose the best bit-depth
|
// NOTE: We let the implementation to choose the best bit-depth
|
||||||
// Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
|
// Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
|
||||||
unsigned int glInternalFormat = GL_DEPTH_COMPONENT;
|
unsigned int glInternalFormat = GL_DEPTH_COMPONENT;
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
if (RLGL.ExtSupported.maxDepthBits == 32) glInternalFormat = GL_DEPTH_COMPONENT32_OES;
|
// WARNING: WebGL platform requires unsized internal format definition (GL_DEPTH_COMPONENT)
|
||||||
else if (RLGL.ExtSupported.maxDepthBits == 24) glInternalFormat = GL_DEPTH_COMPONENT24_OES;
|
// while other platforms using OpenGL ES 2.0 require/support sized internal formats depending on the GPU capabilities
|
||||||
else glInternalFormat = GL_DEPTH_COMPONENT16;
|
if (!RLGL.ExtSupported.texDepthWebGL)
|
||||||
|
{
|
||||||
|
if (RLGL.ExtSupported.maxDepthBits == 32) glInternalFormat = GL_DEPTH_COMPONENT32_OES;
|
||||||
|
else if (RLGL.ExtSupported.maxDepthBits == 24) glInternalFormat = GL_DEPTH_COMPONENT24_OES;
|
||||||
|
else glInternalFormat = GL_DEPTH_COMPONENT16;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!useRenderBuffer && RLGL.ExtSupported.texDepth)
|
if (!useRenderBuffer && RLGL.ExtSupported.texDepth)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue