[Bf-blender-cvs] [3b52c40] master: Fix glUniform called from glBegin/glEnd blocks

Sergey Sharybin noreply at git.blender.org
Mon Sep 5 10:21:05 CEST 2016


Commit: 3b52c4056aafe8267feb45b934e02d5047bb8179
Author: Sergey Sharybin
Date:   Fri Sep 2 16:17:20 2016 +0200
Branches: master
https://developer.blender.org/rB3b52c4056aafe8267feb45b934e02d5047bb8179

Fix glUniform called from glBegin/glEnd blocks

Was causing some invalid operations in OpenGL.

After more testing should be fine for 2.78.

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

M	source/blender/blenkernel/BKE_DerivedMesh.h
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/editderivedmesh.c
M	source/blender/blenkernel/intern/subsurf_ccg.c

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

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 606488f..789bc8d 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -783,6 +783,7 @@ void DM_vertex_attributes_from_gpu(
         struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
 
 void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert, int loop);
+void DM_draw_attrib_vertex_uniforms(const DMVertexAttribs *attribs);
 
 void DM_calc_tangents_names_from_gpu(
         const struct GPUVertexAttribs *gattribs,
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 714417a..293309c 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -3797,7 +3797,6 @@ void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert,
 			glTexCoord3fv(orco);
 		else
 			glVertexAttrib3fv(attribs->orco.gl_index, orco);
-		glUniform1i(attribs->orco.gl_info_index, 0);
 	}
 
 	/* uv texture coordinates */
@@ -3816,7 +3815,6 @@ void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert,
 			glTexCoord2fv(uv);
 		else
 			glVertexAttrib2fv(attribs->tface[b].gl_index, uv);
-		glUniform1i(attribs->tface[b].gl_info_index, 0);
 	}
 
 	/* vertex colors */
@@ -3832,7 +3830,6 @@ void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert,
 		}
 
 		glVertexAttrib4fv(attribs->mcol[b].gl_index, col);
-		glUniform1i(attribs->mcol[b].gl_info_index, GPU_ATTR_INFO_SRGB);
 	}
 
 	/* tangent for normal mapping */
@@ -3842,7 +3839,24 @@ void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert,
 			const float *tang = (array) ? array[a * 4 + vert] : zero;
 			glVertexAttrib4fv(attribs->tang[b].gl_index, tang);
 		}
-		glUniform1i(attribs->tang[b].gl_info_index, 0);
+	}
+}
+
+void DM_draw_attrib_vertex_uniforms(const DMVertexAttribs *attribs)
+{
+	int i;
+	if (attribs->totorco) {
+		glUniform1i(attribs->orco.gl_info_index, 0);
+	}
+	for (i = 0; i < attribs->tottface; i++) {
+		glUniform1i(attribs->tface[i].gl_info_index, 0);
+	}
+	for (i = 0; i < attribs->totmcol; i++) {
+		glUniform1i(attribs->mcol[i].gl_info_index, GPU_ATTR_INFO_SRGB);
+	}
+
+	for (i = 0; i < attribs->tottang; i++) {
+		glUniform1i(attribs->tang[i].gl_info_index, 0);
 	}
 }
 
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 2d06bc8..f2dd2a3 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -941,8 +941,10 @@ static void cdDM_drawMappedFacesGLSL(
 
 				matnr = new_matnr;
 				do_draw = setMaterial(matnr + 1, &gattribs);
-				if (do_draw)
+				if (do_draw) {
 					DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
+					DM_draw_attrib_vertex_uniforms(&attribs);
+				}
 
 				glBegin(GL_TRIANGLES);
 			}
@@ -1210,6 +1212,7 @@ static void cdDM_drawMappedFacesMat(
 
 			setMaterial(userData, matnr = new_matnr, &gattribs);
 			DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
+			DM_draw_attrib_vertex_uniforms(&attribs);
 
 			glBegin(GL_TRIANGLES);
 		}
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 1aba76b..e51a3c3 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -1410,24 +1410,6 @@ static void emDM_drawMappedFacesTex(
 	emDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
 }
 
-static void emdm_pass_attrib_update_uniforms(const DMVertexAttribs *attribs)
-{
-	int i;
-	if (attribs->totorco) {
-		glUniform1i(attribs->orco.gl_info_index, 0);
-	}
-	for (i = 0; i < attribs->tottface; i++) {
-		glUniform1i(attribs->tface[i].gl_info_index, 0);
-	}
-	for (i = 0; i < attribs->totmcol; i++) {
-		glUniform1i(attribs->mcol[i].gl_info_index, GPU_ATTR_INFO_SRGB);
-	}
-
-	for (i = 0; i < attribs->tottang; i++) {
-		glUniform1i(attribs->tang[i].gl_info_index, 0);
-	}
-}
-
 /**
  * \note
  *
@@ -1548,7 +1530,7 @@ static void emDM_drawMappedFacesGLSL(
 			do_draw = setMaterial(matnr = new_matnr, &gattribs);
 			if (do_draw) {
 				DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
-				emdm_pass_attrib_update_uniforms(&attribs);
+				DM_draw_attrib_vertex_uniforms(&attribs);
 				if (UNLIKELY(attribs.tottang && bm->elem_index_dirty & BM_LOOP)) {
 					BM_mesh_elem_index_ensure(bm, BM_LOOP);
 				}
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 60f1eb6..ce9fdec 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -2820,12 +2820,13 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
 		int matnr = -1;
 		int do_draw = 0;
 
-#define PASSATTRIB(dx, dy, vert) {                                            \
-	if (attribs.totorco)                                                      \
-		index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize);   \
-	else                                                                      \
-		index = 0;                                                            \
-	DM_draw_attrib_vertex(&attribs, a, index, vert, ((a) * 4) + vert);        \
+#define PASSATTRIB(dx, dy, vert) {                                                  \
+	if (attribs.totorco)                                                        \
+		index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
+	else                                                                        \
+		index = 0;                                                          \
+	DM_draw_attrib_vertex(&attribs, a, index, vert, ((a) * 4) + vert);          \
+	DM_draw_attrib_vertex_uniforms(&attribs);                                   \
 } (void)0
 
 		totpoly = ccgSubSurf_getNumFaces(ss);
@@ -3222,12 +3223,13 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm,
 
 	matnr = -1;
 
-#define PASSATTRIB(dx, dy, vert) {                                            \
-	if (attribs.totorco)                                                      \
-		index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize);   \
-	else                                                                      \
-		index = 0;                                                            \
-	DM_draw_attrib_vertex(&attribs, a, index, vert, ((a) * 4) + vert);          \
+#define PASSATTRIB(dx, dy, vert) {                                                   \
+	if (attribs.totorco)                                                         \
+		index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize);  \
+	else                                                                         \
+		index = 0;                                                           \
+	DM_draw_attrib_vertex(&attribs, a, index, vert, ((a) * 4) + vert);           \
+	DM_draw_attrib_vertex_uniforms(&attribs);                                    \
 } (void)0
 
 	totface = ccgSubSurf_getNumFaces(ss);




More information about the Bf-blender-cvs mailing list