[Bf-blender-cvs] [b91ebca] GPU_data_request: add to GPUx state: interpolation (smooth shading)

Mike Erwin noreply at git.blender.org
Fri Apr 17 07:17:00 CEST 2015


Commit: b91ebca68e4c45574caa24f790e7701003eebecf
Author: Mike Erwin
Date:   Fri Apr 17 01:16:21 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rBb91ebca68e4c45574caa24f790e7701003eebecf

add to GPUx state: interpolation (smooth shading)

and remove manual calls to glShadeModel.

TODO: interpolation qualifier per attrib (flat/smooth/noperspective)
instead of here.

This requires GLSL 1.3 (OpenGL 3.0) or EXT_gpu_shader4 so we can’t go
down that path yet.

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

M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/gpu/GPUx_state.h
M	source/blender/gpu/intern/gpux_draw.c
M	source/blender/gpu/intern/gpux_state.c

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

diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 60c097b..ae22f1c 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -4482,6 +4482,7 @@ static bool draw_mesh_object_new_new(Scene *scene, ARegion *ar, View3D *v3d, Reg
 				int i, t, tri_ct = 0;
 				MFace *faces = dm->getTessFaceArray(dm);
 				dm->gpux_batch->state.common.lighting = true;
+				dm->gpux_batch->state.common.interpolate = true;
 				dm->gpux_batch->state.polygon.draw_back = false;
 
 				GPUx_specify_attrib(verts, 1, GL_NORMAL_ARRAY, GL_SHORT, 3, NORMALIZE_INT_TO_FLOAT);
@@ -4501,17 +4502,12 @@ static bool draw_mesh_object_new_new(Scene *scene, ARegion *ar, View3D *v3d, Reg
 						GPUx_set_triangle_vertices(elem, t++, face->v4, face->v1, face->v3);
 				}
 
-				/* TODO: update state tracking to handle all these */
-//				glShadeModel(GL_SMOOTH);
-
 				GPUx_vertex_buffer_prime(verts);
 				GPUx_element_list_prime(elem);
 
 				dm->gpux_batch->prim_type = GL_TRIANGLES;
 				dm->gpux_batch->buff = verts;
 				dm->gpux_batch->elem = elem;
-
-//				glShadeModel(GL_FLAT); /* restore default */
 			}
 			else if (dt == OB_WIRE) {
 				/* draw wireframe */
diff --git a/source/blender/gpu/GPUx_state.h b/source/blender/gpu/GPUx_state.h
index 84fa995..98bacb0 100644
--- a/source/blender/gpu/GPUx_state.h
+++ b/source/blender/gpu/GPUx_state.h
@@ -13,6 +13,9 @@ typedef struct {
 	bool depth_test;
 	bool depth_write;
 	bool lighting;
+	bool interpolate; /* affects lines & polygons, not points */
+	/* TODO: interpolation qualifier per attrib (flat/smooth/noperspective) instead of here */
+	/*       requires GLSL 1.3 (OpenGL 3.0) or EXT_gpu_shader4 */
 } CommonDrawState;
 
 typedef struct {
diff --git a/source/blender/gpu/intern/gpux_draw.c b/source/blender/gpu/intern/gpux_draw.c
index c26d146..0d0662a 100644
--- a/source/blender/gpu/intern/gpux_draw.c
+++ b/source/blender/gpu/intern/gpux_draw.c
@@ -181,7 +181,6 @@ void GPUx_draw_batch(const GPUxBatch *batch)
 		case GL_TRIANGLES:
 			GPUx_set_polygon_state(&batch->state.polygon);
 			vert_per_prim = 3;
-			glShadeModel(GL_SMOOTH);
 			break;
 		default:
 #ifdef TRUST_NO_ONE
@@ -205,9 +204,6 @@ void GPUx_draw_batch(const GPUxBatch *batch)
 	else
 		glDrawArrays(batch->prim_type, 0, chop_to_multiple(GPUx_vertex_ct(batch->buff), vert_per_prim));
 
-	if (batch->prim_type == GL_TRIANGLES)
-		glShadeModel(GL_FLAT);
-
 	GPUx_vertex_buffer_done_using(batch->buff);
 #endif /* REALLY_DRAW */
 }
diff --git a/source/blender/gpu/intern/gpux_state.c b/source/blender/gpu/intern/gpux_state.c
index c5cef43..37ded07 100644
--- a/source/blender/gpu/intern/gpux_state.c
+++ b/source/blender/gpu/intern/gpux_state.c
@@ -13,7 +13,8 @@ const DrawState default_state = {
 		.blend = false,
 		.depth_test = true,
 		.depth_write = true,
-		.lighting = false
+		.lighting = false,
+		.interpolate = false
 	},
 	.point = {
 		.smooth = false,
@@ -79,6 +80,14 @@ void GPUx_set_common_state(const CommonDrawState *state)
 			glDisable(GL_LIGHTING);
 		current.common.lighting = state->lighting;
 	}
+
+	if (state->interpolate != current.common.interpolate) {
+		if (state->interpolate)
+			glShadeModel(GL_SMOOTH);
+		else
+			glShadeModel(GL_FLAT);
+		current.common.interpolate = state->interpolate;
+	}
 }
 
 void GPUx_set_point_state(const PointDrawState *state)




More information about the Bf-blender-cvs mailing list