OpenGL: use sized texture internal formats
authorMike Erwin <significant.bit@gmail.com>
Tue, 8 Dec 2015 06:19:08 +0000 (01:19 -0500)
committerMike Erwin <significant.bit@gmail.com>
Tue, 8 Dec 2015 06:19:55 +0000 (01:19 -0500)
Maybe this is pedantic but I read it’s best to explicitly set the
desired component size.

Also append “_ARB” to float texture formats since those need an
extension in GL 2.1.

intern/cycles/device/device_cuda.cpp
source/blender/blenfont/intern/blf_glyph.c
source/blender/editors/interface/interface_icons.c
source/blender/editors/sculpt_paint/paint_cursor.c
source/blender/gpu/intern/gpu_draw.c
source/blender/gpu/intern/gpu_extensions.c
source/blender/windowmanager/intern/wm_operators.c

index 65d5e096c425f4656b20f0d3de426a54872fa76f..d9d6fd77ecb315331b1f47503197ba6b43ff18b3 100644 (file)
@@ -830,7 +830,7 @@ public:
                        if(mem.data_type == TYPE_HALF)
                                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, pmem.w, pmem.h, 0, GL_RGBA, GL_HALF_FLOAT, NULL);
                        else
-                               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pmem.w, pmem.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+                               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, pmem.w, pmem.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                        glBindTexture(GL_TEXTURE_2D, 0);
index 215d2484c18597dfcb923f9653a9271283bd0c7a..4399cbf97c62041d0cf2b5e144971483d106bad5 100644 (file)
@@ -175,7 +175,7 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, gc->p2_width, gc->p2_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, gc->p2_width, gc->p2_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
 }
 
 GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
index eb07a9d9fbc0739840444fd5f50bbce061fdb2c9..43b48e31271ea9469a21c00377d9969ddc7011c8 100644 (file)
@@ -640,12 +640,12 @@ static void init_internal_icons(void)
 
                                glBindTexture(GL_TEXTURE_2D, icongltex.id);
                                
-                               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, b32buf->x, b32buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b32buf->rect);
-                               glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, b16buf->x, b16buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b16buf->rect);
+                               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, b32buf->x, b32buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b32buf->rect);
+                               glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, b16buf->x, b16buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b16buf->rect);
                                
                                while (b16buf->x > 1) {
                                        ImBuf *nbuf = IMB_onehalf(b16buf);
-                                       glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, nbuf->x, nbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nbuf->rect);
+                                       glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, nbuf->x, nbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nbuf->rect);
                                        level++;
                                        IMB_freeImBuf(b16buf);
                                        b16buf = nbuf;
index 76f6854e54f4657a553313749619df3c3cd82ab3..a531a29f26acaa105a48546b8915e0a4b0e87803 100644 (file)
@@ -151,7 +151,6 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
        int size;
        int j;
        int refresh;
-       GLenum format = col ? GL_RGBA : GL_ALPHA;
        OverlayControlFlags invalid = (primary) ? (overlay_flags & PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY) :
                                   (overlay_flags & PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY);
 
@@ -323,6 +322,9 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
        glBindTexture(GL_TEXTURE_2D, target->overlay_texture);
 
        if (refresh) {
+               GLenum format = col ? GL_RGBA : GL_ALPHA;
+               GLenum internalformat = col ? GL_RGBA8 : GL_ALPHA8;
+
                if (!init || (target->old_col != col)) {
                        glTexImage2D(GL_TEXTURE_2D, 0, format, size, size, 0, format, GL_UNSIGNED_BYTE, buffer);
                }
@@ -449,7 +451,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
 
        if (refresh) {
                if (!init) {
-                       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
                }
                else {
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
index d35536f04b90b75d140993aeb4f6d8323b4cde6f..719dc53f9fed8e6748765d94a12d15cacb1e93d1 100644 (file)
@@ -755,12 +755,12 @@ void GPU_create_gl_tex(unsigned int *bind, unsigned int *rect, float *frect, int
 
        if (use_high_bit_depth) {
                if (GLEW_ARB_texture_float)
-                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
                else
                        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
        }
        else
-               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
 
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
 
@@ -786,12 +786,12 @@ void GPU_create_gl_tex(unsigned int *bind, unsigned int *rect, float *frect, int
                                ImBuf *mip = ibuf->mipmap[i - 1];
                                if (use_high_bit_depth) {
                                        if (GLEW_ARB_texture_float)
-                                               glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA16F, mip->x, mip->y, 0, GL_RGBA, GL_FLOAT, mip->rect_float);
+                                               glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA16F_ARB, mip->x, mip->y, 0, GL_RGBA, GL_FLOAT, mip->rect_float);
                                        else
                                                glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA16, mip->x, mip->y, 0, GL_RGBA, GL_FLOAT, mip->rect_float);
                                }
                                else {
-                                       glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, mip->x, mip->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip->rect);
+                                       glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA8, mip->x, mip->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip->rect);
                                }
                        }
                }
index 6410418615aa511d6329f941e694664aca0a5dee..ff62e07b449b05e79a8e8f22ea5a7af8f326074a 100644 (file)
@@ -484,17 +484,19 @@ static GPUTexture *GPU_texture_create_nD(
                                case GPU_HDR_NONE:
                                        internalformat = GL_RGBA8;
                                        break;
+                               /* the following formats rely on ARB_texture_float or OpenGL 3.0 */
                                case GPU_HDR_HALF_FLOAT:
-                                       internalformat = GL_RGBA16F;
+                                       internalformat = GL_RGBA16F_ARB;
                                        break;
                                case GPU_HDR_FULL_FLOAT:
-                                       internalformat = GL_RGBA32F;
+                                       internalformat = GL_RGBA32F_ARB;
                                        break;
                                default:
                                        break;
                        }
                }
                else if (components == 2) {
+                       /* these formats rely on ARB_texture_rg or OpenGL 3.0 */
                        format = GL_RG;
                        switch (hdr_type) {
                                case GPU_HDR_NONE:
@@ -615,11 +617,11 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const f
        type = GL_FLOAT;
        if (channels == 4) {
                format = GL_RGBA;
-               internalformat = GL_RGBA;
+               internalformat = GL_RGBA8;
        }
        else {
                format = GL_RED;
-               internalformat = GL_INTENSITY;
+               internalformat = GL_INTENSITY8;
        }
 
        /* 3D textures are quite heavy, test if it's possible to create them first */
@@ -1542,7 +1544,7 @@ void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
                }
 
                glBindTexture(GL_TEXTURE_2D, tex_blit);
-               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, type, 0);
+               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, type, 0);
 
 #ifdef USE_FBO_CTX_SWITCH
                /* read from multi-sample buffer */
index f7f2487e49ca8287623b2e98c24d31e24f00035f..a4a563457983dae9af6dcd373b87421cb769bc6e 100644 (file)
@@ -4145,7 +4145,7 @@ static void radial_control_set_tex(RadialControl *rc)
                        if ((ibuf = BKE_brush_gen_radial_control_imbuf(rc->image_id_ptr.data, rc->use_secondary_tex))) {
                                glGenTextures(1, &rc->gltex);
                                glBindTexture(GL_TEXTURE_2D, rc->gltex);
-                               glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, ibuf->x, ibuf->y, 0,
+                               glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, ibuf->x, ibuf->y, 0,
                                             GL_ALPHA, GL_FLOAT, ibuf->rect_float);
                                MEM_freeN(ibuf->rect_float);
                                MEM_freeN(ibuf);