[Bf-blender-cvs] [738bb309f94] master: GPU: Add GPU support to fill a texture image with a constant value

mano-wii noreply at git.blender.org
Sat Feb 15 16:19:02 CET 2020


Commit: 738bb309f9490c4d6e056e7df8ff9a6e60ad45df
Author: mano-wii
Date:   Sat Feb 15 12:17:39 2020 -0300
Branches: master
https://developer.blender.org/rB738bb309f9490c4d6e056e7df8ff9a6e60ad45df

GPU: Add GPU support to fill a texture image with a constant value

This solution is optimized for GL version 4.4 or greater.

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

M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_texture.c

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

diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 4e24a3172dc..e8800b75143 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -217,6 +217,7 @@ void GPU_texture_update_sub(GPUTexture *tex,
                             int depth);
 
 void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat gpu_data_format, int miplvl);
+void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat gpu_data_format, const void *color);
 
 void GPU_invalid_tex_init(void);
 void GPU_invalid_tex_bind(int mode);
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index ccafc785526..9ef42592b55 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -21,6 +21,8 @@
  * \ingroup gpu
  */
 
+#include <string.h>
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_image_types.h"
@@ -1435,6 +1437,30 @@ void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat gpu_data_format, int mipl
   return buf;
 }
 
+void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat gpu_data_format, const void *color)
+{
+  if (GLEW_ARB_clear_texture) {
+    GLenum data_format = gpu_get_gl_dataformat(tex->format, &tex->format_flag);
+    GLenum data_type = gpu_get_gl_datatype(gpu_data_format);
+    glClearTexImage(tex->bindcode, 0, data_format, data_type, color);
+  }
+  else {
+    size_t buffer_len = gpu_texture_memory_footprint_compute(tex);
+    unsigned char *pixels = MEM_mallocN(buffer_len, __func__);
+    if (color) {
+      size_t bytesize = tex->bytesize;
+      for (size_t byte = 0; byte < buffer_len; byte += bytesize) {
+        memcpy(&pixels[byte], color, bytesize);
+      }
+    }
+    else {
+      memset(pixels, 0, buffer_len);
+    }
+    GPU_texture_update(tex, gpu_data_format, pixels);
+    MEM_freeN(pixels);
+  }
+}
+
 void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *pixels)
 {
   GPU_texture_update_sub(tex, data_format, pixels, 0, 0, 0, tex->w, tex->h, tex->d);



More information about the Bf-blender-cvs mailing list