Commit: f5e2d4209234d41cade98660e2e51a06940005e1
Author: Clément Foucault
Date:   Sat Jan 13 17:14:01 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBf5e2d4209234d41cade98660e2e51a06940005e1

GPU Texture: Add GL_RG16I format.

===================================================================

M       source/blender/draw/intern/DRW_render.h
M       source/blender/draw/intern/draw_manager.c
M       source/blender/gpu/GPU_texture.h
M       source/blender/gpu/intern/gpu_texture.c

===================================================================

diff --git a/source/blender/draw/intern/DRW_render.h 
b/source/blender/draw/intern/DRW_render.h
index fb736061c61..c9a97131097 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -157,7 +157,9 @@ typedef struct DefaultTextureList {
 #endif
 
 /* Textures */
-
+/* NOTE naming in this struct is broken.
+ * There should either be suffixes for Normalized int formats or float formats.
+ * Right now every 8bit texture is Normalized int and others are Floating 
point. */
 typedef enum {
        DRW_TEX_RGBA_8,
        DRW_TEX_RGBA_16,
@@ -168,6 +170,7 @@ typedef enum {
        DRW_TEX_RGB_32,
        DRW_TEX_RG_8,
        DRW_TEX_RG_16,
+       DRW_TEX_RG_16I,
        DRW_TEX_RG_32,
        DRW_TEX_R_8,
        DRW_TEX_R_16,
diff --git a/source/blender/draw/intern/draw_manager.c 
b/source/blender/draw/intern/draw_manager.c
index c2318949e9c..6553bc385b5 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -397,6 +397,7 @@ static void drw_texture_get_format(
                case DRW_TEX_RGB_11_11_10: *r_data_type = GPU_R11F_G11F_B10F; 
break;
                case DRW_TEX_RG_8: *r_data_type = GPU_RG8; break;
                case DRW_TEX_RG_16: *r_data_type = GPU_RG16F; break;
+               case DRW_TEX_RG_16I: *r_data_type = GPU_RG16I; break;
                case DRW_TEX_RG_32: *r_data_type = GPU_RG32F; break;
                case DRW_TEX_R_8: *r_data_type = GPU_R8; break;
                case DRW_TEX_R_16: *r_data_type = GPU_R16F; break;
@@ -430,6 +431,7 @@ static void drw_texture_get_format(
                        break;
                case DRW_TEX_RG_8:
                case DRW_TEX_RG_16:
+               case DRW_TEX_RG_16I:
                case DRW_TEX_RG_32:
                        *r_channels = 2;
                        break;
@@ -2294,6 +2296,7 @@ static GPUTextureFormat convert_tex_format(
                case DRW_TEX_R_32:     *r_channels = 1; return GPU_R32F;
                case DRW_TEX_RG_8:     *r_channels = 2; return GPU_RG8;
                case DRW_TEX_RG_16:    *r_channels = 2; return GPU_RG16F;
+               case DRW_TEX_RG_16I:   *r_channels = 2; return GPU_RG16I;
                case DRW_TEX_RG_32:    *r_channels = 2; return GPU_RG32F;
                case DRW_TEX_RGBA_8:   *r_channels = 4; return GPU_RGBA8;
                case DRW_TEX_RGBA_16:  *r_channels = 4; return GPU_RGBA16F;
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 3ed9ab4bf2c..1b64d66469b 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -67,6 +67,7 @@ typedef enum GPUTextureFormat {
        GPU_RGBA8,
        GPU_RG32F,
        GPU_RG16F,
+       GPU_RG16I,
        GPU_R32F,
        GPU_R16F,
        GPU_RG8,
@@ -82,7 +83,6 @@ typedef enum GPUTextureFormat {
        GPU_RG32I,
        GPU_RG32UI,
        GPU_RG16,
-       GPU_RG16I,
        GPU_RG16UI,
        GPU_RG8I,
        GPU_RG8UI,
diff --git a/source/blender/gpu/intern/gpu_texture.c 
b/source/blender/gpu/intern/gpu_texture.c
index bcc0bb2649f..d6b641af225 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -115,9 +115,9 @@ static GLenum gpu_texture_get_format(
         int components, GPUTextureFormat data_type,
         GLenum *format, GLenum *data_format, bool *is_depth, bool *is_stencil, 
unsigned int *bytesize)
 {
-       if (data_type == GPU_DEPTH_COMPONENT24 ||
-           data_type == GPU_DEPTH_COMPONENT16 ||
-           data_type == GPU_DEPTH_COMPONENT32F)
+       if (ELEM(data_type, GPU_DEPTH_COMPONENT24,
+                           GPU_DEPTH_COMPONENT16,
+                           GPU_DEPTH_COMPONENT32F))
        {
                *is_depth = true;
                *is_stencil = false;
@@ -133,14 +133,29 @@ static GLenum gpu_texture_get_format(
        else {
                *is_depth = false;
                *is_stencil = false;
-               *data_format = GL_FLOAT;
 
-               switch (components) {
-                       case 1: *format = GL_RED; break;
-                       case 2: *format = GL_RG; break;
-                       case 3: *format = GL_RGB; break;
-                       case 4: *format = GL_RGBA; break;
-                       default: break;
+               /* Integer formats */
+               if (ELEM(data_type, GPU_RG16I)) {
+                       *data_format = GL_INT;
+
+                       switch (components) {
+                               case 1: *format = GL_RED_INTEGER; break;
+                               case 2: *format = GL_RG_INTEGER; break;
+                               case 3: *format = GL_RGB_INTEGER; break;
+                               case 4: *format = GL_RGBA_INTEGER; break;
+                               default: break;
+                       }
+               }
+               else {
+                       *data_format = GL_FLOAT;
+
+                       switch (components) {
+                               case 1: *format = GL_RED; break;
+                               case 2: *format = GL_RG; break;
+                               case 3: *format = GL_RGB; break;
+                               case 4: *format = GL_RGBA; break;
+                               default: break;
+                       }
                }
        }
 
@@ -156,6 +171,7 @@ static GLenum gpu_texture_get_format(
                        *bytesize = 12;
                        break;
                case GPU_RG16F:
+               case GPU_RG16I:
                case GPU_DEPTH24_STENCIL8:
                case GPU_DEPTH_COMPONENT32F:
                case GPU_RGBA8:
@@ -188,6 +204,7 @@ static GLenum gpu_texture_get_format(
                case GPU_RG32F: return GL_RG32F;
                case GPU_RGB16F: return GL_RGB16F;
                case GPU_RG16F: return GL_RG16F;
+               case GPU_RG16I: return GL_RG16I;
                case GPU_RGBA8: return GL_RGBA8;
                case GPU_R32F: return GL_R32F;
                case GPU_R16F: return GL_R16F;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to