Some GLES fixes in ResourcePool::create_2d_texture().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 20 Mar 2014 20:19:27 +0000 (21:19 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 20 Mar 2014 20:43:47 +0000 (21:43 +0100)
In particular, some of the type strictness needed to be fixed here to,
and there are some fixes for some of the more obscure formats.

resource_pool.cpp

index b515769..0557751 100644 (file)
@@ -190,6 +190,8 @@ GLuint ResourcePool::create_2d_texture(GLint internal_format, GLsizei width, GLs
        case GL_RG16F:
                format = GL_RG;
                break;
+       case GL_R32F:
+       case GL_R16F:
        case GL_R8:
                format = GL_RED;
                break;
@@ -198,12 +200,34 @@ GLuint ResourcePool::create_2d_texture(GLint internal_format, GLsizei width, GLs
                assert(false);
        }
 
+       // Same with type; GLES is stricter than desktop OpenGL here.
+       GLenum type;
+       switch (internal_format) {
+       case GL_RGBA32F_ARB:
+       case GL_RGBA16F_ARB:
+       case GL_RG32F:
+       case GL_RG16F:
+       case GL_R32F:
+       case GL_R16F:
+               type = GL_FLOAT;
+               break;
+       case GL_RGBA8:
+       case GL_SRGB8_ALPHA8:
+       case GL_R8:
+               type = GL_UNSIGNED_BYTE;
+               break;
+       default:
+               // TODO: Add more here as needed.
+               assert(false);
+       }
+
+
        GLuint texture_num;
        glGenTextures(1, &texture_num);
        check_error();
        glBindTexture(GL_TEXTURE_2D, texture_num);
        check_error();
-       glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, NULL);
+       glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, NULL);
        check_error();
        glBindTexture(GL_TEXTURE_2D, 0);
        check_error();
@@ -259,6 +283,12 @@ size_t ResourcePool::estimate_texture_size(const Texture2D &texture_format)
        case GL_RG16F:
                bytes_per_pixel = 4;
                break;
+       case GL_R32F:
+               bytes_per_pixel = 4;
+               break;
+       case GL_R16F:
+               bytes_per_pixel = 2;
+               break;
        case GL_R8:
                bytes_per_pixel = 1;
                break;