Parcourir la source

Fixes depth texture creation as used by DepthStencilBuffer. When calling glTexImage2D, <type> must be UNSIGNED_SHORT or UNSIGNED_INT for a format of DEPTH_COMPONENT. Without this change, INVALID_OPERATION is generated. Fixes #18

Adam Blake il y a 14 ans
Parent
commit
10e46e0e2e
1 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. 10 1
      gameplay/src/Texture.cpp

+ 10 - 1
gameplay/src/Texture.cpp

@@ -197,7 +197,16 @@ Texture* Texture::create(Format format, unsigned int width, unsigned int height,
     GLuint textureId;
     GL_ASSERT( glGenTextures(1, &textureId) );
     GL_ASSERT( glBindTexture(GL_TEXTURE_2D, textureId) );
-    GL_ASSERT( glTexImage2D(GL_TEXTURE_2D, 0, (GLenum)format, width, height, 0, (GLenum)format, GL_UNSIGNED_BYTE, data) );
+
+    if (format == DEPTH)
+    {
+        // <type> must be UNSIGNED_SHORT or UNSIGNED_INT for a format of DEPTH_COMPONENT.
+        GL_ASSERT( glTexImage2D(GL_TEXTURE_2D, 0, (GLenum)format, width, height, 0, (GLenum)format, GL_UNSIGNED_INT, data) );
+    }
+    else
+    {
+        GL_ASSERT( glTexImage2D(GL_TEXTURE_2D, 0, (GLenum)format, width, height, 0, (GLenum)format, GL_UNSIGNED_BYTE, data) );
+    }
 
     // Set initial minification filter based on whether or not mipmaping was enabled
     GL_ASSERT( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, generateMipmaps ? GL_NEAREST_MIPMAP_LINEAR : GL_LINEAR) );