[Bf-blender-cvs] [b1c025d1e8d] blender2.8: GPUTexture: Small refactor.

Clément Foucault noreply at git.blender.org
Sun Mar 25 21:33:08 CEST 2018


Commit: b1c025d1e8dd3a26e66740eab102814da76c06bf
Author: Clément Foucault
Date:   Sat Mar 24 20:27:39 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBb1c025d1e8dd3a26e66740eab102814da76c06bf

GPUTexture: Small refactor.

This includes a few modification:
 - The biggest one is call glActiveTexture before doing any call to
   glBindTexture for rendering purpose (uniform value depends on it).
   This is also better to know what's going on when rendering UI. So if
   there is missing UI elements because of this commit look for this first.
   This allows us to have "less calls" to glActiveTexture (I did not
   measure the final count) and less checks inside GPU_texture.

 - Remove use of GL_TEXTURE0 as a uniform value in a few places.

 - Be more strict and use BLI_assert for bad usage of GPU_texture functions.

 - Disable filtering for integer and stencil textures (not supported by
   OGL specs).

 - Replace bools inside GPUTexture by a bitflag supporting more options to
   identify texture types.

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

M	source/blender/blenfont/intern/blf_glyph.c
M	source/blender/draw/intern/draw_manager_texture.c
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/screen/glutil.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/space_clip/clip_draw.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_texture.c
M	source/blender/gpu/intern/gpu_viewport.c
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/intern/wm_stereo.c

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

diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index a7d52e96800..5a8691c9b4f 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -410,6 +410,8 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
 	if ((!g->width) || (!g->height))
 		return;
 
+	glActiveTexture(GL_TEXTURE0);
+
 	if (g->build_tex == 0) {
 		GlyphCacheBLF *gc = font->glyph_cache;
 
diff --git a/source/blender/draw/intern/draw_manager_texture.c b/source/blender/draw/intern/draw_manager_texture.c
index f3b4af7df1b..3a258954dbd 100644
--- a/source/blender/draw/intern/draw_manager_texture.c
+++ b/source/blender/draw/intern/draw_manager_texture.c
@@ -120,7 +120,7 @@ void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
 	GPU_texture_bind(tex, 0);
 	if (flags & DRW_TEX_MIPMAP) {
 		GPU_texture_mipmap_mode(tex, true, flags & DRW_TEX_FILTER);
-		DRW_texture_generate_mipmaps(tex);
+		GPU_texture_generate_mipmap(tex);
 	}
 	else {
 		GPU_texture_filter_mode(tex, flags & DRW_TEX_FILTER);
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 6f56576a208..f7cdb5cdc9c 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1027,6 +1027,7 @@ static void icon_draw_texture(
 	y1 = iy * icongltex.invh;
 	y2 = (iy + ih) * icongltex.invh;
 
+	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, icongltex.id);
 	Gwn_VertFormat *format = immVertexFormat();
 	unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index cd53655a0bb..cd875c73eda 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -198,6 +198,7 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state,
 	glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpack_row_length);
 
 	glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
+	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, texid);
 
 	/* don't want nasty border artifacts */
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index d2063d15ddf..6229b91a518 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -338,6 +338,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
 		size = target->old_size;
 	}
 
+	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, target->overlay_texture);
 
 	if (refresh) {
@@ -464,6 +465,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
 		size = cursor_snap.size;
 	}
 
+	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, cursor_snap.overlay_texture);
 
 	if (refresh) {
@@ -767,7 +769,7 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush,
 		/* draw textured quad */
 
 		/* draw textured quad */
-		immUniform1i("image", GL_TEXTURE0);
+		immUniform1i("image", 0);
 
 		immBegin(GWN_PRIM_TRI_FAN, 4);
 		immAttrib2f(texCoord, 0.0f, 0.0f);
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index 96968a14883..5962bfe33f3 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -1131,6 +1131,7 @@ static void draw_plane_marker_image(Scene *scene,
 
 			glGenTextures(1, (GLuint *)&texid);
 
+			glActiveTexture(GL_TEXTURE0);
 			glBindTexture(GL_TEXTURE_2D, texid);
 
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -1148,7 +1149,7 @@ static void draw_plane_marker_image(Scene *scene,
 
 			immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
 			immUniformColor4f(1.0f, 1.0f, 1.0f, plane_track->image_opacity);
-			immUniform1i("image", GL_TEXTURE0);
+			immUniform1i("image", 0);
 
 			immBegin(GWN_PRIM_TRI_FAN, 4);
 
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index f6d18ad0a52..8e5863fd514 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -1309,6 +1309,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 
 	glGenTextures(1, (GLuint *)&texid);
 
+	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, texid);
 
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -1322,7 +1323,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 	if (!glsl_used) {
 		immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
 		immUniformColor3f(1.0f, 1.0f, 1.0f);
-		immUniform1i("image", GL_TEXTURE0);
+		immUniform1i("image", 0);
 	}
 
 	immBegin(GWN_PRIM_TRI_FAN, 4);
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index ea92f18f714..f46d3c500bc 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -755,8 +755,6 @@ static void draw_empty_image(Object *ob, const short dflag, const unsigned char
 		immEnd();
 
 		immUnbindProgram();
-
-		glBindTexture(GL_TEXTURE_2D, 0); /* necessary? */
 	}
 
 	/* Draw the image outline */
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 0fde0edcf2b..72e3859a5a8 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -196,10 +196,12 @@ void GPU_texture_framebuffer_set(GPUTexture *tex, struct GPUFrameBuffer *fb, int
 int GPU_texture_target(const GPUTexture *tex);
 int GPU_texture_width(const GPUTexture *tex);
 int GPU_texture_height(const GPUTexture *tex);
-int GPU_texture_format(const GPUTexture *tex);
+GPUTextureFormat GPU_texture_format(const GPUTexture *tex);
 int GPU_texture_samples(const GPUTexture *tex);
+bool GPU_texture_cube(const GPUTexture *tex);
 bool GPU_texture_depth(const GPUTexture *tex);
 bool GPU_texture_stencil(const GPUTexture *tex);
+bool GPU_texture_integer(const GPUTexture *tex);
 int GPU_texture_opengl_bindcode(const GPUTexture *tex);
 
 #ifdef __cplusplus
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index bd25dd03f13..1aee994f29e 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -48,6 +48,19 @@ static struct GPUTextureGlobal {
 	GPUTexture *invalid_tex_3D;
 } GG = {NULL, NULL, NULL};
 
+typedef enum GPUTextureFormatFlag{
+	GPU_FORMAT_DEPTH     = (1 << 0),
+	GPU_FORMAT_STENCIL   = (1 << 1),
+	GPU_FORMAT_INTEGER   = (1 << 2),
+	GPU_FORMAT_FLOAT     = (1 << 3),
+
+	GPU_FORMAT_1D        = (1 << 10),
+	GPU_FORMAT_2D        = (1 << 11),
+	GPU_FORMAT_3D        = (1 << 12),
+	GPU_FORMAT_CUBE      = (1 << 13),
+	GPU_FORMAT_ARRAY     = (1 << 14),
+} GPUTextureFormatFlag;
+
 /* GPUTexture */
 struct GPUTexture {
 	int w, h, d;        /* width/height/depth */
@@ -59,13 +72,12 @@ struct GPUTexture {
 	GLuint bindcode;    /* opengl identifier for texture */
 	int fromblender;    /* we got the texture from Blender */
 
+	GPUTextureFormatFlag format_flag;
 	GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
 	int fb_attachment;  /* slot the texture is attached to */
-	bool depth;         /* is a depth texture? */
-	bool stencil;       /* is a stencil texture? */
 
 	unsigned int bytesize; /* number of byte for one pixel */
-	int format;         /* GPUTextureFormat */
+	GPUTextureFormat format;
 	int components;     /* number of color/alpha channels */
 	int samples;        /* number of samples for multisamples textures. 0 if not multisample target */
 };
@@ -114,30 +126,26 @@ unsigned int GPU_texture_memory_usage_get(void)
 
 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)
+        GLenum *format, GLenum *data_format, GPUTextureFormatFlag *format_flag, unsigned int *bytesize)
 {
 	if (ELEM(data_type, GPU_DEPTH_COMPONENT24,
 	                    GPU_DEPTH_COMPONENT16,
 	                    GPU_DEPTH_COMPONENT32F))
 	{
-		*is_depth = true;
-		*is_stencil = false;
+		*format_flag |= GPU_FORMAT_DEPTH;
 		*data_format = GL_FLOAT;
 		*format = GL_DEPTH_COMPONENT;
 	}
 	else if (data_type == GPU_DEPTH24_STENCIL8) {
-		*is_depth = true;
-		*is_stencil = true;
+		*format_flag |= GPU_FORMAT_DEPTH | GPU_FORMAT_STENCIL;
 		*data_format = GL_UNSIGNED_INT_24_8;
 		*format = GL_DEPTH_STENCIL;
 	}
 	else {
-		*is_depth = false;
-		*is_stencil = false;
-
 		/* Integer formats */
 		if (ELEM(data_type, GPU_RG16I, GPU_R16I)) {
 			*data_format = GL_INT;
+			*format_flag |= GPU_FORMAT_INTEGER;
 
 			switch (components) {
 				case 1: *format = GL_RED_INTEGER; break;
@@ -149,6 +157,7 @@ static GLenum gpu_texture_get_format(
 		}
 		else {
 			*data_format = GL_FLOAT;
+			*format_flag |= GPU_FORMAT_FLOAT;
 
 			switch (components) {
 				case 1: *format = GL_RED; break;
@@ -349,6 +358,7 @@ static GPUTexture *GPU_texture_create_nD(
 	tex->fb_attachment = -1;
 	tex->format = data_type;
 	tex->components = components;
+	tex->format_flag = 0;
 
 	if (n == 2) {
 		if (d == 0)
@@ -375,7 +385,8 @@ static GPUTexture *GPU_texture_create_nD(
 		tex->target = GL_TEXTURE_2D_MULTISAMPLE;
 
 	GLenum format, internalformat, data_format;
-	internalformat = gpu_texture_get_format(components, data_type, &format, &data_format, &tex->depth, &tex->stencil, &tex->bytesize);
+	internalformat = gpu_texture_get_format(components, data_type, &format, &data_format,
+	                                        &tex->format_flag, &tex->bytesize);
 
 	gpu_texture_memory_footprint_add(tex);
 
@@ -391,7 +402,6 @@ static GPUTexture *GPU_texture_create_nD(
 		return NULL;
 	}
 
-	tex->number = 0;
 	glBindTexture(tex->target, tex->bindcode);
 
 	/* Check if texture fit in VRAM */
@@ -450,17 +460,23 @@ static GPUTexture *GPU_texture_create_nD(
 		MEM_freeN(rescaled_fp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list