Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-09-02 01:27:41 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-09-05 18:49:14 +0300
commitf72c1c4547e5fab769c22652d9872192029ad7fe (patch)
tree4b89ee42810e0505ed386b76bf5f76f5d4107a1c
parentc598e939ad25dfc3b4eb1c92b16de401bde0d88a (diff)
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.
-rw-r--r--source/blender/blenfont/intern/blf_font.c7
-rw-r--r--source/blender/blenkernel/intern/image_gpu.c8
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_render.c2
-rw-r--r--source/blender/draw/intern/draw_cache_impl_volume.c2
-rw-r--r--source/blender/draw/intern/draw_color_management.c4
-rw-r--r--source/blender/draw/intern/draw_fluid.c2
-rw-r--r--source/blender/draw/intern/draw_manager_texture.c4
-rw-r--r--source/blender/editors/sculpt_paint/paint_cursor.c4
-rw-r--r--source/blender/gpu/GPU_batch.h2
-rw-r--r--source/blender/gpu/intern/gpu_texture.cc84
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c3
11 files changed, 76 insertions, 46 deletions
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 e00aac85655..f26f706d058 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);
+ /* Save and restore. */
+ GLint texture_bound = 0;
+ if (tex->number == -1) {
+ glActiveTexture(GL_TEXTURE0);
+ glGetIntegerv(gl_enum_target_to_binding(tex->target), &texture_bound);
+ glBindTexture(tex->target, tex->bindcode);
+ }
+ else {
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ }
switch (tex->target) {
case GL_TEXTURE_1D:
@@ -1522,6 +1548,10 @@ void GPU_texture_update_sub(GPUTexture *tex,
default:
BLI_assert(!"tex->target mode not supported");
}
+
+ if (tex->number == -1) {
+ glBindTexture(tex->target, texture_bound);
+ }
}
void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat gpu_data_format, int miplvl)
@@ -1822,12 +1852,19 @@ void GPU_texture_unbind_all(void)
void GPU_texture_generate_mipmap(GPUTexture *tex)
{
- WARN_NOT_BOUND(tex);
-
gpu_texture_memory_footprint_remove(tex);
int levels = 1 + floor(log2(max_ii(tex->w, tex->h)));
- glActiveTexture(GL_TEXTURE0 + tex->number);
+ /* Save and restore. */
+ GLint texture_bound = 0;
+ if (tex->number == -1) {
+ glActiveTexture(GL_TEXTURE0);
+ glGetIntegerv(gl_enum_target_to_binding(tex->target), &texture_bound);
+ glBindTexture(tex->target, tex->bindcode);
+ }
+ else {
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ }
if (GPU_texture_depth(tex)) {
/* Some drivers have bugs when using glGenerateMipmap with depth textures (see T56789).
@@ -1846,6 +1883,10 @@ void GPU_texture_generate_mipmap(GPUTexture *tex)
tex->mipmaps = levels;
gpu_texture_memory_footprint_add(tex);
+
+ if (tex->number == -1) {
+ glBindTexture(tex->target, texture_bound);
+ }
}
static GLenum gpu_texture_default_attachment(GPUTexture *tex)
@@ -2002,7 +2043,16 @@ static int gpu_texture_swizzle_to_enum(const char swizzle)
void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4])
{
- WARN_NOT_BOUND(tex);
+ /* Save and restore. */
+ GLint texture_bound = 0;
+ if (tex->number == -1) {
+ glActiveTexture(GL_TEXTURE0);
+ glGetIntegerv(gl_enum_target_to_binding(tex->target), &texture_bound);
+ glBindTexture(tex->target, tex->bindcode);
+ }
+ else {
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ }
GLint gl_swizzle[4] = {gpu_texture_swizzle_to_enum(swizzle[0]),
gpu_texture_swizzle_to_enum(swizzle[1]),
@@ -2011,6 +2061,10 @@ void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4])
glActiveTexture(GL_TEXTURE0 + tex->number);
glTexParameteriv(tex->target_base, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle);
+
+ if (tex->number == -1) {
+ glBindTexture(tex->target, texture_bound);
+ }
}
void GPU_texture_free(GPUTexture *tex)
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index db8a1511da3..67511d2b433 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2220,10 +2220,7 @@ static void radial_control_set_tex(RadialControl *rc)
rc->texture = GPU_texture_create_nD(
ibuf->x, ibuf->y, 0, 2, ibuf->rect_float, GPU_R8, GPU_DATA_FLOAT, 0, false, NULL);
GPU_texture_filter_mode(rc->texture, true);
-
- GPU_texture_bind(rc->texture, 0);
GPU_texture_swizzle_set(rc->texture, "111r");
- GPU_texture_unbind(rc->texture);
MEM_freeN(ibuf->rect_float);
MEM_freeN(ibuf);