[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21777] branches/soc-2009-imbusy/source/ blender: very bad sculpt mode support added (it's just the beginning), preparations for converting GLSL code to use VBOs, updated my code to support the newly allowed 32767 materials

Lukas Steiblys imbusy at imbusy.org
Tue Jul 21 20:49:19 CEST 2009


Revision: 21777
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21777
Author:   imbusy
Date:     2009-07-21 20:49:16 +0200 (Tue, 21 Jul 2009)

Log Message:
-----------
very bad sculpt mode support added (it's just the beginning), preparations for converting GLSL code to use VBOs, updated my code to support the newly allowed 32767 materials

Modified Paths:
--------------
    branches/soc-2009-imbusy/source/blender/blenkernel/BKE_sculpt.h
    branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2009-imbusy/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
    branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c

Modified: branches/soc-2009-imbusy/source/blender/blenkernel/BKE_sculpt.h
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/BKE_sculpt.h	2009-07-21 18:29:37 UTC (rev 21776)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/BKE_sculpt.h	2009-07-21 18:49:16 UTC (rev 21777)
@@ -43,6 +43,7 @@
 	struct MultiresModifierData *multires; /* Special handling for multires meshes */
 	struct MVert *mvert;
 	struct MFace *mface;
+	struct GPUDrawObject *drawobject;
 	int totvert, totface;
 	float *face_normals;
 	

Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-21 18:29:37 UTC (rev 21776)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-21 18:49:16 UTC (rev 21777)
@@ -760,106 +760,209 @@
 	transp = GPU_get_material_blend_mode();
 	orig_transp = transp;
 
-	memset(&attribs, 0, sizeof(attribs));
-
 	glShadeModel(GL_SMOOTH);
-	glBegin(GL_QUADS);
 
-	for(a = 0; a < dm->numFaceData; a++, mface++) {
-		new_matnr = mface->mat_nr + 1;
+	if( GPU_buffer_legacy(dm) ) {
+		DEBUG_VBO( "Using legacy code. cdDM_drawMappedFacesGLSL\n" );
+		memset(&attribs, 0, sizeof(attribs));
 
-		if(new_matnr != matnr) {
-			glEnd();
+		glBegin(GL_QUADS);
 
-			dodraw = setMaterial(matnr = new_matnr, &gattribs);
-			if(dodraw)
-				DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
+		for(a = 0; a < dm->numFaceData; a++, mface++) {
+			new_matnr = mface->mat_nr + 1;
 
-			glBegin(GL_QUADS);
-		}
+			if(new_matnr != matnr) {
+				glEnd();
 
-		if(!dodraw) {
-			continue;
-		}
-		else if(setDrawOptions) {
-			orig = index[a];
+				dodraw = setMaterial(matnr = new_matnr, &gattribs);
+				if(dodraw)
+					DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
 
-			if(orig == ORIGINDEX_NONE)
+				glBegin(GL_QUADS);
+			}
+
+			if(!dodraw) {
 				continue;
-			else if(!setDrawOptions(userData, orig))
-				continue;
+			}
+			else if(setDrawOptions) {
+				orig = index[a];
+
+				if(orig == ORIGINDEX_NONE)
+					continue;
+				else if(!setDrawOptions(userData, orig))
+					continue;
+			}
+
+			if(tf) {
+				new_transp = tf[a].transp;
+
+				if(new_transp != transp) {
+					glEnd();
+
+					if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID)
+						GPU_set_material_blend_mode(orig_transp);
+					else
+						GPU_set_material_blend_mode(new_transp);
+					transp = new_transp;
+
+					glBegin(GL_QUADS);
+				}
+			}
+
+			smoothnormal = (mface->flag & ME_SMOOTH);
+
+			if(!smoothnormal) {
+				if(nors) {
+					glNormal3fv(nors[a]);
+				}
+				else {
+					/* TODO ideally a normal layer should always be available */
+					float nor[3];
+					if(mface->v4) {
+						CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co,
+									   mvert[mface->v3].co, mvert[mface->v4].co,
+									   nor);
+					} else {
+						CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co,
+									  mvert[mface->v3].co, nor);
+					}
+					glNormal3fv(nor);
+				}
+			}
+
+#define PASSVERT(index, vert) {													\
+		if(attribs.totorco)															\
+			glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]);	\
+		for(b = 0; b < attribs.tottface; b++) {										\
+			MTFace *tf = &attribs.tface[b].array[a];								\
+			glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]);			\
+		}																			\
+		for(b = 0; b < attribs.totmcol; b++) {										\
+			MCol *cp = &attribs.mcol[b].array[a*4 + vert];							\
+			GLubyte col[4];															\
+			col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;				\
+			glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col);					\
+		}																			\
+		if(attribs.tottang) {														\
+			float *tang = attribs.tang.array[a*4 + vert];							\
+			glVertexAttrib3fvARB(attribs.tang.glIndex, tang);						\
+		}																			\
+		if(smoothnormal)															\
+			glNormal3sv(mvert[index].no);											\
+		glVertex3fv(mvert[index].co);												\
+	}
+
+			PASSVERT(mface->v1, 0);
+			PASSVERT(mface->v2, 1);
+			PASSVERT(mface->v3, 2);
+			if(mface->v4)
+				PASSVERT(mface->v4, 3)
+			else
+				PASSVERT(mface->v3, 2)
+
+#undef PASSVERT
 		}
+		glEnd();
+	}
+	else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
+		memset(&attribs, 0, sizeof(attribs));
 
-		if(tf) {
-			new_transp = tf[a].transp;
+		for(a = 0; a < dm->numFaceData; a++, mface++) {
+			new_matnr = mface->mat_nr + 1;
 
-			if(new_transp != transp) {
+			if(new_matnr != matnr) {
 				glEnd();
 
-				if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID)
-					GPU_set_material_blend_mode(orig_transp);
-				else
-					GPU_set_material_blend_mode(new_transp);
-				transp = new_transp;
+				dodraw = setMaterial(matnr = new_matnr, &gattribs);
+				if(dodraw)
+					DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
 
 				glBegin(GL_QUADS);
 			}
-		}
 
-		smoothnormal = (mface->flag & ME_SMOOTH);
+			if(!dodraw) {
+				continue;
+			}
+			else if(setDrawOptions) {
+				orig = index[a];
 
-		if(!smoothnormal) {
-			if(nors) {
-				glNormal3fv(nors[a]);
+				if(orig == ORIGINDEX_NONE)
+					continue;
+				else if(!setDrawOptions(userData, orig))
+					continue;
 			}
-			else {
-				/* TODO ideally a normal layer should always be available */
-				float nor[3];
-				if(mface->v4) {
-					CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co,
-								   mvert[mface->v3].co, mvert[mface->v4].co,
-								   nor);
-				} else {
-					CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co,
-								  mvert[mface->v3].co, nor);
+
+			if(tf) {
+				new_transp = tf[a].transp;
+
+				if(new_transp != transp) {
+					glEnd();
+
+					if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID)
+						GPU_set_material_blend_mode(orig_transp);
+					else
+						GPU_set_material_blend_mode(new_transp);
+					transp = new_transp;
+
+					glBegin(GL_QUADS);
 				}
-				glNormal3fv(nor);
 			}
-		}
 
+			smoothnormal = (mface->flag & ME_SMOOTH);
+
+			if(!smoothnormal) {
+				if(nors) {
+					glNormal3fv(nors[a]);
+				}
+				else {
+					/* TODO ideally a normal layer should always be available */
+					float nor[3];
+					if(mface->v4) {
+						CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co,
+									   mvert[mface->v3].co, mvert[mface->v4].co,
+									   nor);
+					} else {
+						CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co,
+									  mvert[mface->v3].co, nor);
+					}
+					glNormal3fv(nor);
+				}
+			}
+
 #define PASSVERT(index, vert) {													\
-	if(attribs.totorco)															\
-		glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]);	\
-	for(b = 0; b < attribs.tottface; b++) {										\
-		MTFace *tf = &attribs.tface[b].array[a];								\
-		glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]);			\
-	}																			\
-	for(b = 0; b < attribs.totmcol; b++) {										\
-		MCol *cp = &attribs.mcol[b].array[a*4 + vert];							\
-		GLubyte col[4];															\
-		col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;				\
-		glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col);					\
-	}																			\
-	if(attribs.tottang) {														\
-		float *tang = attribs.tang.array[a*4 + vert];							\
-		glVertexAttrib3fvARB(attribs.tang.glIndex, tang);						\
-	}																			\
-	if(smoothnormal)															\
-		glNormal3sv(mvert[index].no);											\
-	glVertex3fv(mvert[index].co);												\
-}
+		if(attribs.totorco)															\
+			glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]);	\
+		for(b = 0; b < attribs.tottface; b++) {										\
+			MTFace *tf = &attribs.tface[b].array[a];								\
+			glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]);			\
+		}																			\
+		for(b = 0; b < attribs.totmcol; b++) {										\
+			MCol *cp = &attribs.mcol[b].array[a*4 + vert];							\
+			GLubyte col[4];															\
+			col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;				\
+			glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col);					\
+		}																			\
+		if(attribs.tottang) {														\
+			float *tang = attribs.tang.array[a*4 + vert];							\
+			glVertexAttrib3fvARB(attribs.tang.glIndex, tang);						\
+		}																			\
+		if(smoothnormal)															\
+			glNormal3sv(mvert[index].no);											\
+		glVertex3fv(mvert[index].co);												\
+	}
 
-		PASSVERT(mface->v1, 0);
-		PASSVERT(mface->v2, 1);
-		PASSVERT(mface->v3, 2);
-		if(mface->v4)
-			PASSVERT(mface->v4, 3)
-		else
-			PASSVERT(mface->v3, 2)
+			PASSVERT(mface->v1, 0);
+			PASSVERT(mface->v2, 1);
+			PASSVERT(mface->v3, 2);
+			if(mface->v4)
+				PASSVERT(mface->v4, 3)
+			else
+				PASSVERT(mface->v3, 2)
 
 #undef PASSVERT
+		}
+		glEnd();
 	}
-	glEnd();
 
 	glShadeModel(GL_FLAT);
 }

Modified: branches/soc-2009-imbusy/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/editors/sculpt_paint/sculpt.c	2009-07-21 18:29:37 UTC (rev 21776)
+++ branches/soc-2009-imbusy/source/blender/editors/sculpt_paint/sculpt.c	2009-07-21 18:49:16 UTC (rev 21777)
@@ -90,6 +90,7 @@
 #include "RE_shader_ext.h" /*for multitex_ext*/
 
 #include "GPU_draw.h"
+#include "gpu_buffers.h"
 
 #include <math.h>
 #include <stdlib.h>
@@ -330,21 +331,43 @@
 static void do_draw_brush(Sculpt *sd, SculptSession *ss, const ListBase* active_verts)
 {
 	float area_normal[3];
+	int i, j, found;
 	ActiveData *node= active_verts->first;
+	float* buffer;
 
 	calc_area_normal(sd, area_normal, active_verts);
 	
+	buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );
 	while(node){
 		float *co= ss->mvert[node->Index].co;
 
 		const float val[3]= {co[0]+area_normal[0]*ss->cache->radius*node->Fade*ss->cache->scale[0],
 		                     co[1]+area_normal[1]*ss->cache->radius*node->Fade*ss->cache->scale[1],
 		                     co[2]+area_normal[2]*ss->cache->radius*node->Fade*ss->cache->scale[2]};
-		                     
+
+		if( buffer != 0 ) {
+			for( i = 0; i < ss->drawobject->nelements/3; i++ ) {
+				int realface = ss->drawobject->faceRemap[i];
+				if( ss->mface[realface].v1 == node->Index ||
+					ss->mface[realface].v2 == node->Index ||
+					ss->mface[realface].v3 == node->Index ||
+					ss->mface[realface].v4 == node->Index ) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list