[Bf-blender-cvs] [f7e1c007ab7] tmp-gltexture: GPUTexture: Remove bind to edit calls

Clément Foucault noreply at git.blender.org
Fri Sep 4 02:46:54 CEST 2020


Commit: f7e1c007ab7c7d114b8361ac2f8566380c582cce
Author: Clément Foucault
Date:   Wed Sep 2 00:27:41 2020 +0200
Branches: tmp-gltexture
https://developer.blender.org/rBf7e1c007ab7c7d114b8361ac2f8566380c582cce

GPUTexture: Remove bind to edit calls

This is going to be unecessary after the GPU opengl texture backend refactor.

For now add a save/restore mechanism to leave the state untouched.

Also remove some calls where the caller would bind to particular binding
point and set the shader uniform.

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

M	source/blender/blenfont/intern/blf_font.c
M	source/blender/blenkernel/intern/image_gpu.c
M	source/blender/draw/engines/gpencil/gpencil_render.c
M	source/blender/draw/intern/draw_cache_impl_volume.c
M	source/blender/draw/intern/draw_color_management.c
M	source/blender/draw/intern/draw_fluid.c
M	source/blender/draw/intern/draw_manager_texture.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/gpu/GPU_batch.h
M	source/blender/gpu/intern/gpu_texture.cc
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 5724d844089..1b27b6dd4c1 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -187,8 +187,6 @@ static GPUTexture *blf_batch_cache_texture_load(void)
     int offset_x = bitmap_len_landed % tex_width;
     int offset_y = bitmap_len_landed / tex_width;
 
-    GPU_texture_bind(gc->texture, 0);
-
     /* TODO(germano): Update more than one row in a single call. */
     while (remain) {
       int remain_row = tex_width - offset_x;
@@ -229,16 +227,17 @@ void blf_batch_draw(void)
 #endif
 
   GPUTexture *texture = blf_batch_cache_texture_load();
-  GPU_texture_bind(texture, 0);
   GPU_vertbuf_data_len_set(g_batch.verts, g_batch.glyph_len);
   GPU_vertbuf_use(g_batch.verts); /* send data */
 
   GPU_batch_program_set_builtin(g_batch.batch, GPU_SHADER_TEXT);
-  GPU_batch_uniform_1i(g_batch.batch, "glyph", 0);
+  GPU_batch_texture_bind(g_batch.batch, "glyph", texture);
   GPU_batch_draw(g_batch.batch);
 
   GPU_blend(GPU_BLEND_NONE);
 
+  GPU_texture_unbind(texture);
+
   /* restart to 1st vertex data pointers */
   GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step);
   GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step);
diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c
index 78a705ae145..0a6015a3933 100644
--- a/source/blender/blenkernel/intern/image_gpu.c
+++ b/source/blender/blenkernel/intern/image_gpu.c
@@ -182,8 +182,6 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
   GPUTexture *tex = IMB_touch_gpu_texture(
       main_ibuf, arraywidth, arrayheight, arraylayers, use_high_bitdepth);
 
-  GPU_texture_bind(tex, 0);
-
   /* Upload each tile one by one. */
   LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
     int tilelayer = tile->runtime.tilearray_layer;
@@ -225,8 +223,6 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
     GPU_texture_mipmap_mode(tex, false, true);
   }
 
-  GPU_texture_unbind(tex);
-
   return tex;
 }
 
@@ -323,9 +319,7 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
     *tex = IMB_create_gpu_texture(ibuf_intern, use_high_bitdepth, store_premultiplied);
 
     if (GPU_mipmap_enabled()) {
-      GPU_texture_bind(*tex, 0);
       GPU_texture_generate_mipmap(*tex);
-      GPU_texture_unbind(*tex);
       if (ima) {
         ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
       }
@@ -666,8 +660,6 @@ static void gpu_texture_update_from_ibuf(
     }
   }
 
-  GPU_texture_bind(tex, 0);
-
   if (scaled) {
     /* Slower update where we first have to scale the input pixels. */
     if (tile != NULL) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_render.c b/source/blender/draw/engines/gpencil/gpencil_render.c
index df52b65aa78..1402448a699 100644
--- a/source/blender/draw/engines/gpencil/gpencil_render.c
+++ b/source/blender/draw/engines/gpencil/gpencil_render.c
@@ -143,11 +143,9 @@ void GPENCIL_render_init(GPENCIL_Data *vedata,
     int w = BLI_rcti_size_x(rect);
     int h = BLI_rcti_size_y(rect);
     if (pix_col) {
-      GPU_texture_bind(txl->render_color_tx, 0);
       GPU_texture_update_sub(txl->render_color_tx, GPU_DATA_FLOAT, pix_col, x, y, 0, w, h, 0);
     }
     if (pix_z) {
-      GPU_texture_bind(txl->render_depth_tx, 0);
       GPU_texture_update_sub(txl->render_depth_tx, GPU_DATA_FLOAT, pix_z, x, y, 0, w, h, 0);
     }
   }
diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c
index 825fec83cf1..a74e557cc29 100644
--- a/source/blender/draw/intern/draw_cache_impl_volume.c
+++ b/source/blender/draw/intern/draw_cache_impl_volume.c
@@ -265,10 +265,8 @@ static DRWVolumeGrid *volume_grid_cache_get(Volume *volume,
                                                 voxels,
                                                 NULL);
 
-    GPU_texture_bind(cache_grid->texture, 0);
     GPU_texture_swizzle_set(cache_grid->texture, (channels == 3) ? "rgb1" : "rrr1");
     GPU_texture_wrap_mode(cache_grid->texture, false, false);
-    GPU_texture_unbind(cache_grid->texture);
 
     MEM_freeN(voxels);
 
diff --git a/source/blender/draw/intern/draw_color_management.c b/source/blender/draw/intern/draw_color_management.c
index 33000d1ecd0..bd851dc4ba7 100644
--- a/source/blender/draw/intern/draw_color_management.c
+++ b/source/blender/draw/intern/draw_color_management.c
@@ -53,10 +53,10 @@ void DRW_transform_none(GPUTexture *tex)
   GPUBatch *geom = DRW_cache_fullscreen_quad_get();
   GPU_batch_program_set_builtin(geom, GPU_SHADER_2D_IMAGE_COLOR);
   GPU_batch_uniform_4f(geom, "color", 1.0f, 1.0f, 1.0f, 1.0f);
-  GPU_batch_uniform_1i(geom, "image", 0);
+  GPU_batch_texture_bind(geom, "image", tex);
 
-  GPU_texture_bind(tex, 0);
   GPU_batch_draw(geom);
+
   GPU_texture_unbind(tex);
 }
 
diff --git a/source/blender/draw/intern/draw_fluid.c b/source/blender/draw/intern/draw_fluid.c
index fea379126d2..89714c04351 100644
--- a/source/blender/draw/intern/draw_fluid.c
+++ b/source/blender/draw/intern/draw_fluid.c
@@ -128,9 +128,7 @@ static void swizzle_texture_channel_single(GPUTexture *tex)
 {
   /* Swizzle texture channels so that we get useful RGBA values when sampling
    * a texture with fewer channels, e.g. when using density as color. */
-  GPU_texture_bind(tex, 0);
   GPU_texture_swizzle_set(tex, "rrr1");
-  GPU_texture_unbind(tex);
 }
 
 static GPUTexture *create_field_texture(FluidDomainSettings *fds)
diff --git a/source/blender/draw/intern/draw_manager_texture.c b/source/blender/draw/intern/draw_manager_texture.c
index b94a6db3bad..083d5224e16 100644
--- a/source/blender/draw/intern/draw_manager_texture.c
+++ b/source/blender/draw/intern/draw_manager_texture.c
@@ -67,9 +67,7 @@ void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
 
   if (flags & DRW_TEX_MIPMAP) {
     GPU_texture_mipmap_mode(tex, true, flags & DRW_TEX_FILTER);
-    GPU_texture_bind(tex, 0);
     GPU_texture_generate_mipmap(tex);
-    GPU_texture_unbind(tex);
   }
   else {
     GPU_texture_filter_mode(tex, flags & DRW_TEX_FILTER);
@@ -172,9 +170,7 @@ void DRW_texture_ensure_2d(
 
 void DRW_texture_generate_mipmaps(GPUTexture *tex)
 {
-  GPU_texture_bind(tex, 0);
   GPU_texture_generate_mipmap(tex);
-  GPU_texture_unbind(tex);
 }
 
 void DRW_texture_free(GPUTexture *tex)
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index ee514fa745c..0486fc9fe0f 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -352,9 +352,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
           size, size, 0, 2, buffer, format, GPU_DATA_UNSIGNED_BYTE, 0, false, NULL);
 
       if (!col) {
-        GPU_texture_bind(target->overlay_texture, 0);
         GPU_texture_swizzle_set(target->overlay_texture, "rrrr");
-        GPU_texture_unbind(target->overlay_texture);
       }
     }
 
@@ -471,9 +469,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
       cursor_snap.overlay_texture = GPU_texture_create_nD(
           size, size, 0, 2, buffer, GPU_R8, GPU_DATA_UNSIGNED_BYTE, 0, false, NULL);
 
-      GPU_texture_bind(cursor_snap.overlay_texture, 0);
       GPU_texture_swizzle_set(cursor_snap.overlay_texture, "rrrr");
-      GPU_texture_unbind(cursor_snap.overlay_texture);
     }
 
     if (init) {
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index b45898f9c6a..4171f98ffed 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -146,6 +146,8 @@ void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
   GPU_shader_uniform_4fv_array((batch)->shader, name, len, val);
 #define GPU_batch_uniform_mat4(batch, name, val) \
   GPU_shader_uniform_mat4((batch)->shader, name, val);
+#define GPU_batch_texture_bind(batch, name, tex) \
+  GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name));
 
 void GPU_batch_draw(GPUBatch *batch);
 void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count);
diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc
index 3dedfcf763a..0a22df96382 100644
--- a/source/blender/gpu/intern/gpu_texture.cc
+++ b/source/blender/gpu/intern/gpu_texture.cc
@@ -46,16 +46,6 @@
 #include "gpu_context_private.hh"
 #include "gpu_framebuffer_private.hh"
 
-#define WARN_NOT_BOUND(_tex) \
-  { \
-    if (_tex->number == -1) { \
-      fprintf(stderr, "Warning : Trying to set parameter on a texture not bound.\n"); \
-      BLI_assert(0); \
-      return; \
-    } \
-  } \
-  ((void)0)
-
 static struct GPUTextureGlobal {
   /** Texture used in place of invalid textures (not loaded correctly, missing). */
   GPUTexture *invalid_tex_1D;
@@ -231,6 +221,33 @@ static const char *gl_enum_to_str(GLenum e)
 #undef ENUM_TO_STRING
 }
 
+static GLenum gl_enum_target_to_binding(GLenum target)
+{
+  switch (target) {
+    default:
+      BLI_assert(0);
+      ATTR_FALLTHROUGH;
+    case GL_TEXTURE_1D:
+      return GL_TEXTURE_BINDING_1D;
+    case GL_TEXTURE_1D_ARRAY:
+      return GL_TEXTURE_BINDING_1D_ARRAY;
+    case GL_TEXTURE_2D:
+      return GL_TEXTURE_BINDING_2D;
+    case GL_TEXTURE_2D_ARRAY:
+      return GL_TEXTURE_BINDING_2D_ARRAY;
+    case GL_TEXTURE_2D_MULTISAMPLE:
+      return GL_TEXTURE_BINDING_2D_MULTISAMPLE;
+    case GL_TEXTURE_3D:
+      return GL_TEXTURE_BINDING_3D;
+    case GL_TEXTURE_BUFFER:
+      return GL_TEXTURE_BINDING_BUFFER;
+    case GL_TEXTURE_CUBE_MAP:
+      return GL_TEXTURE_BINDING_CUBE_MAP;
+    case GL_TEXTURE_CUBE_MAP_ARRAY_ARB:
+      return GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB;
+  }
+}
+
 static int gpu_get_component_count(eGPUTextureFormat format)
 {
   switch (format) {
@@ -1493,7 +1510,16 @@ void GPU_texture_update_sub(GPUTexture *tex,
   GLenum data_format = gpu_get_gl_dataformat(tex->format, &tex->format_flag);
   GLenum data_type = gpu_get_gl_datatype(gpu_data_format);
 
-  WARN_NOT_BOUND(tex);
+  /* S

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list