[Bf-blender-cvs] [b75f35c] temp-derivedmesh-looptri: Merge branch 'master' into temp-derivedmesh-looptri

Antony Riakiotakis noreply at git.blender.org
Wed Jul 15 19:44:30 CEST 2015


Commit: b75f35c3bd9f08133469ae6cec1e828b15bf3f88
Author: Antony Riakiotakis
Date:   Wed Jul 15 19:24:59 2015 +0200
Branches: temp-derivedmesh-looptri
https://developer.blender.org/rBb75f35c3bd9f08133469ae6cec1e828b15bf3f88

Merge branch 'master' into temp-derivedmesh-looptri

Conflicts:
	source/blender/blenkernel/intern/cdderivedmesh.c

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



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

diff --cc source/blender/blenkernel/intern/cdderivedmesh.c
index 4a727c8,5b25a32..bfb5e1e
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@@ -634,197 -637,158 +636,153 @@@ static void cdDM_drawMappedFaces
          void *userData, DMDrawFlag flag)
  {
  	CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- 	const MVert *mvert = cddm->mvert;
 -	MFace *mf = cddm->mface;
 -	MCol *mcol;
 +	const MPoly *mpoly = cddm->mpoly;
- 	const MLoop *mloop = cddm->mloop;
- 	const MLoopTri *lt = dm->looptris.array;
 +	const MLoopCol *mloopcol = NULL;
- 	const float (*nors)[3] = DM_get_poly_data_layer(dm, CD_NORMAL);
- 	const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- 	int colType;
- 	int i;
+ 	int colType, useColors = flag & DM_DRAW_USE_COLORS, useHide = flag & DM_DRAW_SKIP_HIDDEN;
 -	int i, orig;
++	int i, j, orig;
+ 	int start_element = 0, tot_element, tot_drawn;
+ 	int totpoly;
+ 	int tottri;
+ 	int mat_index;
+ 	GPUBuffer *findex_buffer = NULL;
  
 -	/* double lookup */
 -	const int *index_mf_to_mpoly = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
  	const int *index_mp_to_orig  = dm->getPolyDataArray(dm, CD_ORIGINDEX);
 -	if (index_mf_to_mpoly == NULL) {
 -		index_mp_to_orig = NULL;
 -	}
 -
 -	cdDM_update_normals_from_pbvh(dm);
  
- 	if (flag & DM_DRAW_USE_COLORS) {
- 		colType = CD_TEXTURE_MLOOPCOL;
- 		mloopcol = DM_get_loop_data_layer(dm, colType);
- 		if (!mloopcol) {
- 			colType = CD_PREVIEW_MLOOPCOL;
- 			mloopcol = DM_get_loop_data_layer(dm, colType);
- 		}
- 		if (!mloopcol) {
- 			colType = CD_MLOOPCOL;
- 			mloopcol = DM_get_loop_data_layer(dm, colType);
- 		}
- 	}
+ 	/* fist, setup common buffers */
+ 	GPU_vertex_setup(dm);
+ 	GPU_triangle_setup(dm);
  
- 	cdDM_update_normals_from_pbvh(dm);
++	totpoly = dm->getNumPolys(dm);
 +
- 	/* back-buffer always uses legacy since VBO's would need the
- 	 * color array temporarily overwritten for drawing, then reset. */
+ 	/* if we do selection, fill the selection buffer color */
  	if (G.f & G_BACKBUFSEL) {
- 		DEBUG_VBO("Using legacy code. cdDM_drawMappedFaces\n");
- 		for (i = 0; i < dm->looptris.num; i++, lt++) {
- 			const MPoly *mp = &mpoly[lt->poly];
- 			int drawSmooth = ((flag & DM_DRAW_ALWAYS_SMOOTH) || lnors) ? 1 : (mp->flag & ME_SMOOTH);
- 			DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
- 			int orig;
+ 		Mesh *me = userData;
+ 		unsigned int *fi_map;
  
- 			orig = (index_mp_to_orig) ? index_mp_to_orig[lt->poly] : lt->poly;
- 			
- 			if (orig == ORIGINDEX_NONE)
- 				draw_option = setMaterial(mp->mat_nr + 1, NULL);
- 			else if (setDrawOptions != NULL)
- 				draw_option = setDrawOptions(userData, orig);
+ 		findex_buffer = GPU_buffer_alloc(dm->drawObject->tot_loop_verts * sizeof(int), false);
+ 		fi_map = GPU_buffer_lock(findex_buffer);
  
- 			if (draw_option != DM_DRAW_OPTION_SKIP) {
- 				const unsigned int  vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v};
- 				const unsigned int *ltri = lt->tri;
- 				int j;
+ 		if (fi_map) {
 -			for (i = 0; i < dm->numTessFaceData; i++, mf++) {
++			for (i = 0; i < totpoly; i++, mpoly++) {
+ 				int selcol = 0xFFFFFFFF;
 -				orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i;
++				orig = (index_mp_to_orig) ? index_mp_to_orig[i] : i;
  
- 				if (draw_option == DM_DRAW_OPTION_STIPPLE) {
- 					glEnable(GL_POLYGON_STIPPLE);
- 					glPolygonStipple(stipple_quarttone);
+ 				if ((orig != ORIGINDEX_NONE) && (!useHide || !(me->mpoly[orig].flag & ME_HIDE))) {
+ 					WM_framebuffer_index_get(orig + 1, &selcol);
  				}
  
- 				/* no need to set shading mode to flat because
- 				 *  normals are already used to change shading */
- 				glShadeModel(GL_SMOOTH);
- 				glBegin(GL_TRIANGLES);
 -				fi_map[start_element++] = selcol;
 -				fi_map[start_element++] = selcol;
 -				fi_map[start_element++] = selcol;
 -
 -				if (mf->v4) {
++				for (j = 0; j < mpoly->totloop; j++)
+ 					fi_map[start_element++] = selcol;
 -				}
+ 			}
  
- 				if (lnors) {
+ 			start_element = 0;
 -			mf = cddm->mface;
++			mpoly = cddm->mpoly;
  
- 					for (j = 0; j < 3; j++) {
- 						if (mloopcol) glColor3ubv((unsigned char *)&mloopcol[ltri[j]].r);
- 						glNormal3fv(lnors[ltri[j]]);
- 						glVertex3fv(mvert[vtri[j]].co);
- 					}
+ 			GPU_buffer_unlock(findex_buffer);
+ 			GPU_buffer_bind_as_color(findex_buffer);
+ 		}
+ 	}
+ 	else {
++		cdDM_update_normals_from_pbvh(dm);
 +
- 				}
- 				else if (!drawSmooth) {
- 					if (nors) {
- 						glNormal3fv(nors[lt->poly]);
- 					}
- 					else {
- 						float nor[3];
- 						normal_tri_v3(nor, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co);
- 						glNormal3fv(nor);
- 					}
+ 		GPU_normal_setup(dm);
  
- 					for (j = 0; j < 3; j++) {
- 						if (mloopcol) glColor3ubv((unsigned char *)&mloopcol[ltri[j]].r);
- 						glVertex3fv(mvert[vtri[j]].co);
- 					}
+ 		if (useColors) {
 -			colType = CD_TEXTURE_MCOL;
 -			mcol = DM_get_tessface_data_layer(dm, colType);
 -			if (!mcol) {
 -				colType = CD_PREVIEW_MCOL;
 -				mcol = DM_get_tessface_data_layer(dm, colType);
 -			}
 -			if (!mcol) {
 -				colType = CD_MCOL;
 -				mcol = DM_get_tessface_data_layer(dm, colType);
 +
++			if (flag & DM_DRAW_USE_COLORS) {
++				colType = CD_TEXTURE_MLOOPCOL;
++				mloopcol = DM_get_loop_data_layer(dm, colType);
++				if (!mloopcol) {
++					colType = CD_PREVIEW_MLOOPCOL;
++					mloopcol = DM_get_loop_data_layer(dm, colType);
 +				}
- 				else {
- 					for (j = 0; j < 3; j++) {
- 						if (mloopcol) glColor3ubv((unsigned char *)&mloopcol[ltri[j]].r);
- 						glNormal3sv(mvert[vtri[j]].no);
- 						glVertex3fv(mvert[vtri[j]].co);
- 					}
++				if (!mloopcol) {
++					colType = CD_MLOOPCOL;
++					mloopcol = DM_get_loop_data_layer(dm, colType);
 +				}
+ 			}
  
- 				glEnd();
- 
- 				if (draw_option == DM_DRAW_OPTION_STIPPLE)
- 					glDisable(GL_POLYGON_STIPPLE);
 -			if (useColors && mcol) {
++			if (useColors && mloopcol) {
+ 				GPU_color_setup(dm, colType);
  			}
  		}
  	}
- 	else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
- 		const MLoopTri *looptri = dm->looptris.array;
- 		int start_element = 0, tot_element, tot_drawn;
- 		int totpoly;
- 		int tottri;
- 		int mat_index;
- 		
- 		GPU_vertex_setup(dm);
- 		GPU_normal_setup(dm);
- 		GPU_triangle_setup(dm);
- 		if (mloopcol) {
- 			GPU_color_setup(dm, colType);
- 		}
- 		glShadeModel(GL_SMOOTH);
  		
- 		tottri = dm->drawObject->tot_triangle_point;
- 
- 		if (tottri == 0) {
- 			/* avoid buffer problems in following code */
- 		}
- 		else if (setDrawOptions == NULL) {
- 			/* just draw the entire face array */
- 			GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, 0, tottri);
- 		}
- 		else {
- 			for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
- 				GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index;
- 				DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
- 				int next_actualFace = looptri[bufmat->polys[0]].poly;
- 				totpoly = bufmat->totpolys;
  
- 				tot_element = 0;
- 				tot_drawn = 0;
- 				start_element = 0;
+ 	glShadeModel(GL_SMOOTH);
  
- 				if (setMaterial)
- 					draw_option = setMaterial(bufmat->mat_nr + 1, NULL);
+ 	tottri = dm->drawObject->tot_triangle_point;
  
- 				if (draw_option != DM_DRAW_OPTION_SKIP) {
- 					for (i = 0; i < totpoly; i++) {
- 						int actualFace = next_actualFace;
- 						int flush = 0;
- 						int orig;
+ 	if (tottri == 0) {
+ 		/* avoid buffer problems in following code */
+ 	}
+ 	else if (setDrawOptions == NULL) {
+ 		/* just draw the entire face array */
+ 		GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, 0, tottri);
+ 	}
+ 	else {
+ 		for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
+ 			GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index;
+ 			DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
+ 			int next_actualFace = bufmat->polys[0];
+ 			totpoly = bufmat->totpolys;
  
- 						orig = index_mp_to_orig ? index_mp_to_orig[actualFace] : actualFace;
+ 			tot_element = 0;
+ 			start_element = 0;
+ 			tot_drawn = 0;
  
- 						draw_option = DM_DRAW_OPTION_NORMAL;
+ 			if (setMaterial)
+ 				draw_option = setMaterial(bufmat->mat_nr + 1, NULL);
  
- 						if (i != totpoly - 1)
- 							next_actualFace = looptri[bufmat->polys[i + 1]].poly;
+ 			if (draw_option != DM_DRAW_OPTION_SKIP) {
+ 				for (i = 0; i < totpoly; i++) {
+ 					int actualFace = next_actualFace;
+ 					int flush = 0;
+ 					draw_option = DM_DRAW_OPTION_NORMAL;
  
- 						if (setDrawOptions != NULL && (orig != ORIGINDEX_NONE))
- 							draw_option = setDrawOptions(userData, orig);
+ 					if (i != totpoly - 1)
+ 						next_actualFace = bufmat->polys[i + 1];
  
- 						if (draw_option == DM_DRAW_OPTION_STIPPLE) {
- 							glEnable(GL_POLYGON_STIPPLE);
- 							glPolygonStipple(stipple_quarttone);
- 						}
 -					orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, actualFace) : actualFace;
++					orig = (index_mp_to_orig) ? index_mp_to_orig[i] : i;
  
- 						/* Goal is to draw as long of a contiguous triangle
- 						 * array as possible, so draw when we hit either an
- 						 * invisible triangle or at the end of the array */
+ 					if (setDrawOptions != NULL && (orig != ORIGINDEX_NONE))
+ 						draw_option = setDrawOptions(userData, orig);
  
- 						/* flush buffer if current triangle isn't drawable or it's last triangle... */
- 						flush = (ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE)) || (i == totpoly - 1);
+ 					if (draw_option == DM_DRAW_OPTION_STIPPLE) {
+ 						glEnable(GL_POLYGON_STIPPLE);
+ 						glPolygonStipple(stipple_quarttone);
+ 					}
  
- 						if (!flush && compareDrawOptions) {
- 							flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
- 						}
+ 					/* Goal is to draw as long of a contiguous triangle
+ 					 * array as possible, so draw when we hit either an
+ 					 * invisible triangle or at the end of the array */
  
- 						tot_element += 3;
+ 					/* flush buffer if current triangle isn't drawable or it's last triangle... */
+ 					flush = (ELEM(draw_option, DM_DRAW_OPTIO

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list