[Bf-blender-cvs] [65ebb668ec8] blender2.8: glPushAttrib/Pop change implementation to use a stack

Dalai Felinto noreply at git.blender.org
Tue May 9 15:29:27 CEST 2017


Commit: 65ebb668ec8d1fed282d59eea47da6dd47b699db
Author: Dalai Felinto
Date:   Tue May 9 15:09:39 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB65ebb668ec8d1fed282d59eea47da6dd47b699db

glPushAttrib/Pop change implementation to use a stack

The original implementation (cbd78c81268f) broke depth of field.

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

M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/gpu/GPU_draw.h
M	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/intern/gpu_draw.c
M	source/blender/gpu/intern/gpu_framebuffer.c
M	source/blender/gpu/intern/gpu_select_pick.c
M	source/blender/gpu/intern/gpu_select_sample_query.c
M	source/blender/gpu/intern/gpu_viewport.c

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

diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index 976c27ee7a4..d48b6f86831 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -782,8 +782,7 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
 	/* color means that primary brush texture is colured and secondary is used for alpha/mask control */
 	bool col = ELEM(mode, ePaintTextureProjective, ePaintTexture2D, ePaintVertex) ? true : false;
 	OverlayControlFlags flags = BKE_paint_get_overlay_flags();
-	GPUStateValues attribs;
-	gpuSaveState(&attribs, GPU_DEPTH_BUFFER_BIT | GPU_BLEND_BIT);
+	gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_BLEND_BIT);
 
 	/* coloured overlay should be drawn separately */
 	if (col) {
@@ -801,7 +800,7 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
 			paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom);
 	}
 
-	gpuRestoreState(&attribs);
+	gpuPopAttrib();
 }
 
 
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h
index cd305d5697f..52076c307df 100644
--- a/source/blender/gpu/GPU_draw.h
+++ b/source/blender/gpu/GPU_draw.h
@@ -174,58 +174,16 @@ void	GPU_select_index_get(int index, int *r_col);
 int		GPU_select_to_index(unsigned int col);
 void	GPU_select_to_index_array(unsigned int *col, const unsigned int size);
 
-typedef enum eGPUStateMask {
+typedef enum eGPUAttribMask {
 	GPU_DEPTH_BUFFER_BIT = (1 << 0),
 	GPU_ENABLE_BIT = (1 << 1),
 	GPU_SCISSOR_BIT = (1 << 2),
 	GPU_VIEWPORT_BIT = (1 << 3),
 	GPU_BLEND_BIT = (1 << 4),
-} eGPUStateMask;
-
-typedef struct GPUStateValues
-{
-	eGPUStateMask mask;
-
-	/* GL_ENABLE_BIT */
-	unsigned int is_blend : 1;
-	unsigned int is_cull_face : 1;
-	unsigned int is_depth_test : 1;
-	unsigned int is_dither : 1;
-	unsigned int is_lighting : 1;
-	unsigned int is_line_smooth : 1;
-	unsigned int is_color_logic_op : 1;
-	unsigned int is_multisample : 1;
-	unsigned int is_polygon_offset_line : 1;
-	unsigned int is_polygon_offset_fill : 1;
-	unsigned int is_polygon_smooth : 1;
-	unsigned int is_sample_alpha_to_coverage : 1;
-	unsigned int is_scissor_test : 1;
-	unsigned int is_stencil_test : 1;
-
-#ifdef WITH_LEGACY_OPENGL
-	unsigned int is_alpha_test : 1;
-	bool is_light[8];
-#endif
-
-	bool is_clip_plane[6];
-
-	/* GL_DEPTH_BUFFER_BIT */
-	/* unsigned int is_depth_test : 1; */
-	int depth_func;
-	double depth_clear_value;
-	bool depth_write_mask;
-
-	/* GL_SCISSOR_BIT */
-	int scissor_box[4];
-	/* unsigned int is_scissor_test : 1; */
-
-	/* GL_VIEWPORT_BIT */
-	int viewport[4];
-	double near_far[2];
-} GPUStateValues;
+} eGPUAttribMask;
 
-void gpuSaveState(GPUStateValues *attribs, eGPUStateMask mask);
-void gpuRestoreState(GPUStateValues *attribs);
+void gpuPushAttrib(eGPUAttribMask mask);
+void gpuPopAttrib(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index f0692b91a80..6da71d17d33 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -197,8 +197,6 @@ struct GPUFX {
 
 	Batch *quad_batch;
 	Batch *point_batch;
-
-	struct GPUStateValues attribs;
 };
 
 #if 0
@@ -645,7 +643,7 @@ bool GPU_fx_compositor_initialize_passes(
 	if (scissor_rect) {
 		int w_sc = BLI_rcti_size_x(scissor_rect) + 1;
 		int h_sc = BLI_rcti_size_y(scissor_rect) + 1;
-		gpuSaveState(&fx->attribs, GPU_SCISSOR_BIT);
+		gpuPushAttrib(GPU_SCISSOR_BIT);
 		glEnable(GL_SCISSOR_TEST);
 		glScissor(scissor_rect->xmin - rect->xmin, scissor_rect->ymin - rect->ymin,
 		          w_sc, h_sc);
@@ -721,7 +719,7 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
 	GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, 0);
 
 	/* full screen quad where we will always write to depth buffer */
-	gpuSaveState(&fx->attribs, GPU_DEPTH_BUFFER_BIT | GPU_SCISSOR_BIT);
+	gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_SCISSOR_BIT);
 	glDepthFunc(GL_ALWAYS);
 	/* disable scissor from sculpt if any */
 	glDisable(GL_SCISSOR_TEST);
@@ -754,7 +752,7 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
 
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 
-	gpuRestoreState(&fx->attribs);
+	gpuPopAttrib();
 }
 
 
@@ -785,7 +783,7 @@ bool GPU_fx_do_composite_pass(
 	GPU_framebuffer_texture_detach(fx->depth_buffer);
 
 	if (fx->restore_stencil) {
-		gpuRestoreState(&fx->attribs);
+		gpuPopAttrib();
 	}
 
 	src = fx->color_buffer;
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 93b372336cb..0f4b105731d 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -2501,66 +2501,124 @@ void GPU_select_to_index_array(unsigned int *col, const unsigned int size)
 #undef INDEX_BUF_ARRAY
 }
 
+#define STATE_STACK_DEPTH 16
+
+typedef struct {
+	eGPUAttribMask mask;
+
+	/* GL_ENABLE_BIT */
+	unsigned int is_blend : 1;
+	unsigned int is_cull_face : 1;
+	unsigned int is_depth_test : 1;
+	unsigned int is_dither : 1;
+	unsigned int is_lighting : 1;
+	unsigned int is_line_smooth : 1;
+	unsigned int is_color_logic_op : 1;
+	unsigned int is_multisample : 1;
+	unsigned int is_polygon_offset_line : 1;
+	unsigned int is_polygon_offset_fill : 1;
+	unsigned int is_polygon_smooth : 1;
+	unsigned int is_sample_alpha_to_coverage : 1;
+	unsigned int is_scissor_test : 1;
+	unsigned int is_stencil_test : 1;
+
+#ifdef WITH_LEGACY_OPENGL
+	unsigned int is_alpha_test : 1;
+	bool is_light[8];
+#endif
+
+	bool is_clip_plane[6];
+
+	/* GL_DEPTH_BUFFER_BIT */
+	/* unsigned int is_depth_test : 1; */
+	int depth_func;
+	double depth_clear_value;
+	bool depth_write_mask;
+
+	/* GL_SCISSOR_BIT */
+	int scissor_box[4];
+	/* unsigned int is_scissor_test : 1; */
+
+	/* GL_VIEWPORT_BIT */
+	int viewport[4];
+	double near_far[2];
+}  GPUAttribValues;
+
+typedef struct {
+	GPUAttribValues attrib_stack[STATE_STACK_DEPTH];
+	unsigned int top;
+} GPUAttribStack;
+
+static GPUAttribStack state = {
+	.top = 0
+};
+
+#define AttribStack state
+#define Attrib state.attrib_stack[state.top]
+
 /**
  * Replacement for glPush/PopAttributes
  *
  * We don't need to cover all the options of legacy OpenGL
  * but simply the ones used by Blender.
  */
-void gpuSaveState(GPUStateValues *values, eGPUStateMask mask)
+void gpuPushAttrib(eGPUAttribMask mask)
 {
-	values->mask = mask;
+	Attrib.mask = mask;
 
 	if ((mask & GPU_DEPTH_BUFFER_BIT) != 0) {
-		values->is_depth_test = glIsEnabled(GL_DEPTH_TEST);
-		glGetIntegerv(GL_DEPTH_FUNC, &values->depth_func);
-		glGetDoublev(GL_DEPTH_CLEAR_VALUE, &values->depth_clear_value);
-		glGetBooleanv(GL_DEPTH_WRITEMASK, (GLboolean *)&values->depth_write_mask);
+		Attrib.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
+		glGetIntegerv(GL_DEPTH_FUNC, &Attrib.depth_func);
+		glGetDoublev(GL_DEPTH_CLEAR_VALUE, &Attrib.depth_clear_value);
+		glGetBooleanv(GL_DEPTH_WRITEMASK, (GLboolean *)&Attrib.depth_write_mask);
 	}
 
 	if ((mask & GPU_ENABLE_BIT) != 0) {
-		values->is_blend = glIsEnabled(GL_BLEND);
+		Attrib.is_blend = glIsEnabled(GL_BLEND);
 
 		for (int i = 0; i < 6; i++) {
-			values->is_clip_plane[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
+			Attrib.is_clip_plane[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
 		}
 
-		values->is_cull_face = glIsEnabled(GL_CULL_FACE);
-		values->is_depth_test = glIsEnabled(GL_DEPTH_TEST);
-		values->is_dither = glIsEnabled(GL_DITHER);
+		Attrib.is_cull_face = glIsEnabled(GL_CULL_FACE);
+		Attrib.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
+		Attrib.is_dither = glIsEnabled(GL_DITHER);
 
 #ifdef WITH_LEGACY_OPENGL
-		values->is_alpha_test = glIsEnabled(GL_ALPHA_TEST);
+		Attrib.is_alpha_test = glIsEnabled(GL_ALPHA_TEST);
 
 		for (int i = 0; i < 8; i++) {
-			values->is_light[i] = glIsEnabled(GL_LIGHT0 + i);
+			Attrib.is_light[i] = glIsEnabled(GL_LIGHT0 + i);
 		}
 #endif
 
-		values->is_line_smooth = glIsEnabled(GL_LINE_SMOOTH);
-		values->is_color_logic_op = glIsEnabled(GL_COLOR_LOGIC_OP);
-		values->is_multisample = glIsEnabled(GL_MULTISAMPLE);
-		values->is_polygon_offset_line = glIsEnabled(GL_POLYGON_OFFSET_LINE);
-		values->is_polygon_offset_fill = glIsEnabled(GL_POLYGON_OFFSET_FILL);
-		values->is_polygon_smooth = glIsEnabled(GL_POLYGON_SMOOTH);
-		values->is_sample_alpha_to_coverage = glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE);
-		values->is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
-		values->is_stencil_test = glIsEnabled(GL_STENCIL_TEST);
+		Attrib.is_line_smooth = glIsEnabled(GL_LINE_SMOOTH);
+		Attrib.is_color_logic_op = glIsEnabled(GL_COLOR_LOGIC_OP);
+		Attrib.is_multisample = glIsEnabled(GL_MULTISAMPLE);
+		Attrib.is_polygon_offset_line = glIsEnabled(GL_POLYGON_OFFSET_LINE);
+		Attrib.is_polygon_offset_fill = glIsEnabled(GL_POLYGON_OFFSET_FILL);
+		Attrib.is_polygon_smooth = glIsEnabled(GL_POLYGON_SMOOTH);
+		Attrib.is_sample_alpha_to_coverage = glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE);
+		Attrib.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
+		Attrib.is_stencil_test = glIsEnabled(GL_STENCIL_TEST);
 	}
 
 	if ((mask & GPU_SCISSOR_BIT) != 0) {
-		values->is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
-		glGetIntegerv(GL_SCISSOR_BOX, (GLint *)&values->scissor_box);
+		Attrib.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
+		glGetIntegerv(GL_SCISSOR_BOX, (GLint *)&Attrib.scissor_box);
 	}
 
 	if ((mask & GPU_VIEWPORT_BIT) != 0) {
-		glGetDoublev(GL_DEPTH_RANGE, (GLdouble *)&values->near_far);
-		glGetIntegerv(GL_VIEWPORT, (GLint *)&values->viewport);
+		glGetDoublev(GL_DEPTH_RANGE, (GLdouble *)&Attrib.near_far);
+		glGetIntegerv(GL_VIEWPORT, (GLint *)&Attrib.viewport);
 	}
 
 	if ((mask & GPU_BLEND_BIT) != 0) {
-		values->is_blend = glIsEnabled(GL_BLEND);
+		Attrib.is_blend = glIsEnabled(GL_BLEND);
 	}
+
+	BLI_assert(AttribStack.top < STATE_STACK_DEPTH);
+	AttribStack.top++;
 }
 
 static void restore_mask(GLenum cap, const bool value) {
@@ -2572,60 +2630,66 @@ static void restore_mask(GLenum cap, const bool value) {
 	}
 }
 
-void gpuRestoreState(GPUStateValues *values)
+void gpuPopAttrib()
 {
-	GLint mask = values->mask;
+	BLI_assert(AttribStack.top > 0);
+	AttribStack.top--;
+
+	GLint mask = Attrib.mask;
 
 	if ((mask & GPU_DEPTH_BUFFER_BIT) 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list