[Bf-blender-cvs] [fd017c9] opensubdiv-modifier: OpenSubdiv: Make drawing even closer to legacy viewport drawing

Sergey Sharybin noreply at git.blender.org
Thu Jul 3 18:29:57 CEST 2014


Commit: fd017c95ebb9707cfed71c9ff0e8c672598282c6
Author: Sergey Sharybin
Date:   Thu Jul 3 22:23:57 2014 +0600
https://developer.blender.org/rBfd017c95ebb9707cfed71c9ff0e8c672598282c6

OpenSubdiv: Make drawing even closer to legacy viewport drawing

This actually disables using any GLSL for drawing quads in favor
of using default tessellation and shading.

This is achieved by enabling client states for vertices and
normals and this have the following benefits:

- Makes code closer to what's happening in GPU at this moment,
  hopefully this means we can use GPU_material and rest of the
  routines from this area for shading/texturing the model.

- For now it allows to have smooth and flat shading, currently
  this flag is used from the first face, need to fill in face
  flags accordingly to the original mesh.

This code is under OPENSUBDIV_LEGACY_DRAW define which makes
it rather easy to distinguish and get rid of when we'll have
viewport rrefactor in place and when it'll be more clear how
OpenSubdiv+shading/texturing would fit in there.

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

M	intern/opensubdiv/opensubdiv_capi.h
M	intern/opensubdiv/opensubdiv_gpu_capi.cc
M	source/blender/blenkernel/intern/CCGSubSurf.c
M	source/blender/blenkernel/intern/subsurf_ccg.c

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

diff --git a/intern/opensubdiv/opensubdiv_capi.h b/intern/opensubdiv/opensubdiv_capi.h
index 3491273..36604d6 100644
--- a/intern/opensubdiv/opensubdiv_capi.h
+++ b/intern/opensubdiv/opensubdiv_capi.h
@@ -26,6 +26,8 @@
 #ifndef __OPENSUBDIV_CAPI_H__
 #define __OPENSUBDIV_CAPI_H__
 
+#define OPENSUBDIV_LEGACY_DRAW
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index 3a409c0..29ce53c 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -45,6 +45,7 @@
 
 using OpenSubdiv::OsdGLMeshInterface;
 
+#ifndef OPENSUBDIV_LEGACY_DRAW
 extern "C" char datatoc_gpu_shader_opensubd_display_glsl[];
 
 static GLuint compileShader(GLenum shaderType,
@@ -108,30 +109,37 @@ static GLuint linkProgram(const char *define)
 
 	return program;
 }
+#endif  /* OPENSUBDIV_LEGACY_DRAW */
 
 void openSubdiv_osdGLMeshDisplay(OpenSubdiv_GLMesh *gl_mesh)
 {
+#ifndef OPENSUBDIV_LEGACY_DRAW
 	static GLuint quad_fill_program = 0;
 	static bool need_init = true;
-	OsdGLMeshInterface *mesh = (OsdGLMeshInterface *) gl_mesh->descriptor;
 
 	if (need_init) {
 		quad_fill_program = linkProgram("");
 		need_init = false;
 	}
+#endif
+
+	OsdGLMeshInterface *mesh = (OsdGLMeshInterface *) gl_mesh->descriptor;
 
 	using OpenSubdiv::OsdDrawContext;
 	using OpenSubdiv::FarPatchTables;
 
 	const OsdDrawContext::PatchArrayVector &patches = mesh->GetDrawContext()->patchArrays;
 
+#ifndef OPENSUBDIV_LEGACY_DRAW
+	glUseProgram(quad_fill_program);
+#endif
+
 	for (int i = 0; i < (int)patches.size(); ++i) {
 		OpenSubdiv::OsdDrawContext::PatchArray const &patch = patches[i];
 		OpenSubdiv::OsdDrawContext::PatchDescriptor desc = patch.GetDescriptor();
 		OpenSubdiv::FarPatchTables::Type patchType = desc.GetType();
 
 		if (patchType == OpenSubdiv::FarPatchTables::QUADS) {
-			glUseProgram(quad_fill_program);
 			glDrawElements(GL_QUADS,
 			               patch.GetNumIndices(),
 			               GL_UNSIGNED_INT,
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index 4f5df8b..13098bf 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -2359,12 +2359,22 @@ void ccgSubSurf_prepareGLMesh(CCGSubSurf *ss)
 		glBindVertexArray(ss->osd_vao);
 		glBindBuffer(GL_ARRAY_BUFFER,
 		             openSubdiv_bindOsdGLMeshVertexBuffer(ss->osd_mesh));
+
 		glEnableVertexAttribArray(0);
 		glEnableVertexAttribArray(1);
 		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
-		                      sizeof (GLfloat) * 6, 0);
+		                      sizeof(GLfloat) * 6, 0);
 		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
-		                      sizeof (GLfloat) * 6, (float*)12);
+		                      sizeof(GLfloat) * 6, (float*)12);
+
+#ifdef OPENSUBDIV_LEGACY_DRAW
+		glEnableClientState(GL_VERTEX_ARRAY);
+		glVertexPointer(3, GL_FLOAT, sizeof(GLfloat) * 6, 0);
+
+		glEnableClientState(GL_NORMAL_ARRAY);
+		glNormalPointer(GL_FLOAT, sizeof(GLfloat) * 6, (float*)12);
+#endif
+
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
 		             openSubdiv_getOsdGLMeshPatchIndexBuffer(ss->osd_mesh));
 		glBindBuffer(GL_ARRAY_BUFFER, 0);
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index b1d6beb..e494f38 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -1788,13 +1788,25 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
 
 #ifdef WITH_OPENSUBDIV
 	if (!ccgSubSurf_getSimpleSubdiv(ss)) {
-		(void) partial_redraw_planes;
-		(void) fast;
+		int matnr, shademodel;
+
+		/* TODO(sergey): This is just for the purposes of tests. */
+		if (faceFlags) {
+			shademodel = (lnors || (faceFlags[0].flag & ME_SMOOTH))
+				? GL_SMOOTH
+				: GL_FLAT;
+			matnr = faceFlags[0].mat_nr;
+		}
+		else {
+			shademodel = GL_SMOOTH;
+			matnr = 0;
+		}
 
 		/* TODO(sergey): Currently we only set first material,
 		 * in the future we need to set per-patch material.
 		 */
-		setMaterial(1, NULL);
+		setMaterial(matnr + 1, NULL);
+		glShadeModel(shademodel);
 
 		ccgSubSurf_prepareGLMesh(ss);
 		ccgSubSurf_drawGLMesh(ss);
@@ -3860,6 +3872,12 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 		}
 	}
 	else {
+		/* TODO(sergey): This is just for the purposes of tests. */
+		if (mpoly) {
+			faceFlags->flag = mpoly[0].flag;
+			faceFlags->mat_nr = mpoly[0].mat_nr;
+		}
+
 		vertNum = ccgSubSurf_getNumFinalVerts(ss);
 		edgeNum = ccgSubSurf_getNumFinalEdges(ss);
 		loopindex2 = ccgSubSurf_getNumFinalFaces(ss) * 4;




More information about the Bf-blender-cvs mailing list