[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21076] branches/soc-2009-imbusy/source/ blender: experimented with a few more rendering modes.
Lukas Steiblys
imbusy at imbusy.org
Mon Jun 22 13:48:32 CEST 2009
Revision: 21076
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21076
Author: imbusy
Date: 2009-06-22 13:48:31 +0200 (Mon, 22 Jun 2009)
Log Message:
-----------
experimented with a few more rendering modes. Can't understand where does cdDM_drawFacesColored get the colors from.
Modified Paths:
--------------
branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c
branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.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/intern/DerivedMesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c 2009-06-22 09:22:31 UTC (rev 21075)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c 2009-06-22 11:48:31 UTC (rev 21076)
@@ -218,7 +218,7 @@
{
if (dm->needsFree) {
bvhcache_free(&dm->bvhCache);
- GPU_buffer_release(dm);
+ GPU_drawobject_free( dm->drawObject );
CustomData_free(&dm->vertData, dm->numVertData);
CustomData_free(&dm->edgeData, dm->numEdgeData);
CustomData_free(&dm->faceData, dm->numFaceData);
Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c 2009-06-22 09:22:31 UTC (rev 21075)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c 2009-06-22 11:48:31 UTC (rev 21076)
@@ -287,6 +287,22 @@
if(col1 && col2)
glEnable(GL_CULL_FACE);
+ /* TODO: why does the code below give different results? */
+ /*GPU_color4_upload(dm,cp1);
+ GPU_vertex_setup(dm);
+ GPU_color_setup(dm);
+ glDrawArrays(GL_TRIANGLES, 0, dm->drawObject->nelements);
+
+ if( useTwoSided ) {
+ GPU_color4_upload(dm,cp2);
+ GPU_color_setup(dm);
+ glCullFace(GL_FRONT);
+ glDrawArrays(GL_TRIANGLES, 0, dm->drawObject->nelements);
+ glCullFace(GL_BACK);
+ }
+ GPU_buffer_unbind();*/
+
+ /* old code */
glShadeModel(GL_SMOOTH);
glBegin(glmode = GL_QUADS);
for(a = 0; a < dm->numFaceData; a++, mface++, cp1 += 16) {
@@ -435,7 +451,18 @@
if(!mc)
mc = DM_get_face_data_layer(dm, CD_MCOL);
- for(i = 0; i < dm->numFaceData; i++, mf++) {
+ /* TODO: not yet tested */
+ GPU_vertex_setup(dm);
+ GPU_normal_setup(dm);
+ if( useColors && mc )
+ GPU_color_setup(dm);
+ glShadeModel(GL_SMOOTH);
+ glDrawArrays(GL_TRIANGLES,0,dm->drawObject->nelements);
+ glShadeModel(GL_FLOAT);
+ GPU_buffer_unbind();
+
+ /* old code */
+ /*for(i = 0; i < dm->numFaceData; i++, mf++) {
int drawSmooth = (mf->flag & ME_SMOOTH);
if(index) {
@@ -460,7 +487,6 @@
glNormal3fv(nors);
}
else {
- /* TODO make this better (cache facenormals as layer?) */
float nor[3];
if(mf->v4) {
CalcNormFloat4(mv[mf->v1].co, mv[mf->v2].co,
@@ -504,7 +530,7 @@
}
if (nors) nors += 3;
- }
+ }*/
}
static void cdDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void *userData)
Modified: branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h 2009-06-22 09:22:31 UTC (rev 21075)
+++ branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h 2009-06-22 11:48:31 UTC (rev 21076)
@@ -90,12 +90,11 @@
void GPU_color_setup( struct DerivedMesh *dm );
/* upload three unsigned chars, representing RGB colors, for each vertex */
-void GPU_color_upload( struct DerivedMesh *dm, char *data );
+void GPU_color3_upload( struct DerivedMesh *dm, char *data );
+/* upload four unsigned chars, representing RGBA colors, for each vertex */
+void GPU_color4_upload( struct DerivedMesh *dm, char *data );
/* called after drawing */
void GPU_buffer_unbind();
-/* called when destroying DerivedMesh */
-void GPU_buffer_release( struct DerivedMesh *dm );
-
#endif
Modified: branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c 2009-06-22 09:22:31 UTC (rev 21075)
+++ branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c 2009-06-22 11:48:31 UTC (rev 21076)
@@ -61,7 +61,7 @@
if( useVBOs < 0 ) {
if( GL_ARB_vertex_buffer_object )
- useVBOs = 0;
+ useVBOs = 1;
else
useVBOs = 0;
}
@@ -274,7 +274,7 @@
MEM_freeN(object);
}
-GPUBuffer *GPU_buffer_setup( DerivedMesh *dm, GPUDrawObject *object, int size, void (*copy_f)(DerivedMesh *, float *, int *, int *) )
+GPUBuffer *GPU_buffer_setup( DerivedMesh *dm, GPUDrawObject *object, int size, void *user, void (*copy_f)(DerivedMesh *, float *, int *, int *, void *) )
{
GPUBuffer *buffer;
float *varray;
@@ -304,14 +304,14 @@
uploaded = GL_FALSE;
while( !uploaded ) {
- (*copy_f)( dm, varray, index, redir );
+ (*copy_f)( dm, varray, index, redir, user );
uploaded = glUnmapBufferARB( GL_ARRAY_BUFFER_ARB ); /* returns false if data got corruped during transfer */
}
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
else {
varray = buffer->pointer;
- (*copy_f)( dm, varray, index, redir );
+ (*copy_f)( dm, varray, index, redir, user );
}
MEM_freeN(index);
@@ -319,7 +319,7 @@
return buffer;
}
-void GPU_buffer_copy_vertex( DerivedMesh *dm, float *varray, int *index, int *redir )
+void GPU_buffer_copy_vertex( DerivedMesh *dm, float *varray, int *index, int *redir, void *user )
{
int start;
int i;
@@ -357,10 +357,10 @@
{
DEBUG_VBO("GPU_buffer_vertex\n");
- return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*dm->drawObject->nelements, GPU_buffer_copy_vertex);
+ return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*dm->drawObject->nelements, 0, GPU_buffer_copy_vertex);
}
-void GPU_buffer_copy_normal( DerivedMesh *dm, float *varray, int *index, int *redir )
+void GPU_buffer_copy_normal( DerivedMesh *dm, float *varray, int *index, int *redir, void *user )
{
int i;
int start;
@@ -417,10 +417,10 @@
{
DEBUG_VBO("GPU_buffer_normal\n");
- return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*dm->drawObject->nelements, GPU_buffer_copy_normal);
+ return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*dm->drawObject->nelements, 0, GPU_buffer_copy_normal);
}
-void GPU_buffer_copy_uv( DerivedMesh *dm, float *varray, int *index, int *redir )
+void GPU_buffer_copy_uv( DerivedMesh *dm, float *varray, int *index, int *redir, void *user )
{
int start;
int i;
@@ -463,26 +463,24 @@
{
DEBUG_VBO("GPU_buffer_uv\n");
- return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*2*dm->drawObject->nelements, GPU_buffer_copy_uv);
+ return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*2*dm->drawObject->nelements, 0, GPU_buffer_copy_uv);
}
-void GPU_buffer_copy_color( DerivedMesh *dm, float *varray_, int *index, int *redir )
+void GPU_buffer_copy_color3( DerivedMesh *dm, float *varray_, int *index, int *redir, void *user )
{
int start;
int i;
- char *varray;
MFace *mface;
- MCol *mcol;
+ unsigned char *varray;
+ unsigned char *mcol;
- DEBUG_VBO("GPU_buffer_copy_color\n");
+ DEBUG_VBO("GPU_buffer_copy_color3\n");
- varray = (char *)varray_;
+ mcol = user;
+ varray = (unsigned char *)varray_;
mface = dm->getFaceArray(dm);
- mcol = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
- if(!mcol)
- mcol = DM_get_face_data_layer(dm, CD_MCOL);
for( i=0; i < dm->getNumFaces(dm); i++ ) {
start = index[redir[mface[i].mat_nr+127]];
@@ -492,36 +490,75 @@
index[redir[mface[i].mat_nr+127]] += 9;
/* v1 v2 v3 */
- varray[start] = mcol[i*4].r;
- varray[start+1] = mcol[i*4].g;
- varray[start+2] = mcol[i*4].b;
- varray[start+3] = mcol[i*4+1].r;
- varray[start+4] = mcol[i*4+1].g;
- varray[start+5] = mcol[i*4+1].b;
- varray[start+6] = mcol[i*4+2].r;
- varray[start+7] = mcol[i*4+2].g;
- varray[start+8] = mcol[i*4+2].b;
+ VECCOPY(&varray[start],&mcol[i*4]);
+ VECCOPY(&varray[start+3],&mcol[i*4+3]);
+ VECCOPY(&varray[start+6],&mcol[i*4+6]);
+ if( mface[i].v4 ) {
+ /* v3 v4 v1 */
+ VECCOPY(&varray[start+9],&mcol[i*4+6]);
+ VECCOPY(&varray[start+12],&mcol[i*4+9]);
+ VECCOPY(&varray[start+15],&mcol[i*4]);
+ }
+ }
+}
+void GPU_buffer_copy_color4( DerivedMesh *dm, float *varray_, int *index, int *redir, void *user )
+{
+ int start;
+ int i;
+
+ MFace *mface;
+ unsigned char *varray;
+ unsigned char *mcol;
+
+ DEBUG_VBO("GPU_buffer_copy_color4\n");
+
+ mcol = user;
+ varray = (unsigned char *)varray_;
+
+ mface = dm->getFaceArray(dm);
+
+ for( i=0; i < dm->getNumFaces(dm); i++ ) {
+ start = index[redir[mface[i].mat_nr+127]];
+ if( mface[i].v4 )
+ index[redir[mface[i].mat_nr+127]] += 18;
+ else
+ index[redir[mface[i].mat_nr+127]] += 9;
+
+ /* v1 v2 v3 */
+ VECCOPY(&varray[start],&mcol[i*4]);
+ VECCOPY(&varray[start+3],&mcol[i*4+4]);
+ VECCOPY(&varray[start+6],&mcol[i*4+8]);
if( mface[i].v4 ) {
/* v3 v4 v1 */
- varray[start+9] = mcol[i*4+2].r;
- varray[start+10] = mcol[i*4+2].g;
- varray[start+11] = mcol[i*4+2].b;
- varray[start+12] = mcol[i*4+3].r;
- varray[start+13] = mcol[i*4+3].g;
- varray[start+14] = mcol[i*4+3].b;
- varray[start+15] = mcol[i*4].r;
- varray[start+16] = mcol[i*4].g;
- varray[start+17] = mcol[i*4].b;
+ VECCOPY(&varray[start+9],&mcol[i*4+8]);
+ VECCOPY(&varray[start+12],&mcol[i*4+12]);
+ VECCOPY(&varray[start+15],&mcol[i*4]);
}
}
}
GPUBuffer *GPU_buffer_color( DerivedMesh *dm )
{
+ unsigned char *colors;
+ int i;
+ MCol *mcol;
+ GPUBuffer *result;
DEBUG_VBO("GPU_buffer_color\n");
- return GPU_buffer_setup( dm, dm->drawObject, sizeof(char)*3*dm->drawObject->nelements, GPU_buffer_copy_color );
+ mcol = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
+ if(!mcol)
+ mcol = DM_get_face_data_layer(dm, CD_MCOL);
+
+ colors = MEM_mallocN(dm->getNumFaces(dm)*3*sizeof(unsigned char), "GPU_buffer_color");
+ for( i=0; i < dm->getNumFaces(dm); i++ ) {
+ colors[i*3] = mcol[i].r;
+ colors[i*3+1] = mcol[i].g;
+ colors[i*3+2] = mcol[i].b;
+ }
+ result = GPU_buffer_setup( dm, dm->drawObject, sizeof(char)*3*dm->drawObject->nelements, colors, GPU_buffer_copy_color3 );
+ MEM_freeN(colors);
+ return result;
}
void GPU_vertex_setup( DerivedMesh *dm )
@@ -620,7 +657,17 @@
glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
}
-void GPU_buffer_release( DerivedMesh *dm )
+void GPU_color3_upload( struct DerivedMesh *dm, char *data )
{
- GPU_drawobject_free( dm->drawObject );
+ if( dm->drawObject == 0 )
+ dm->drawObject = GPU_drawobject_new(dm);
+ GPU_buffer_free(dm->drawObject->colors,globalPool);
+ dm->drawObject->colors = GPU_buffer_setup( dm, dm->drawObject, sizeof(char)*3*dm->drawObject->nelements, data, GPU_buffer_copy_color3 );
+}
+void GPU_color4_upload( struct DerivedMesh *dm, char *data )
+{
+ if( dm->drawObject == 0 )
+ dm->drawObject = GPU_drawobject_new(dm);
+ GPU_buffer_free(dm->drawObject->colors,globalPool);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list