Revision: 21480
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21480
Author:   imbusy
Date:     2009-07-10 13:22:11 +0200 (Fri, 10 Jul 2009)

Log Message:
-----------
textured mode works a bit better, buffer pool is cleaned up on exit

Modified Paths:
--------------
    branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2009-imbusy/source/blender/blenkernel/intern/customdata.c
    branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawmesh.c
    branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c
    branches/soc-2009-imbusy/source/blender/makesdna/DNA_customdata_types.h
    branches/soc-2009-imbusy/source/blender/windowmanager/intern/wm_init_exit.c

Modified: 
branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c   
2009-07-10 10:48:25 UTC (rev 21479)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c   
2009-07-10 11:22:11 UTC (rev 21480)
@@ -427,11 +427,12 @@
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
        MVert *mv = cddm->mvert;
-       MFace *mf = cddm->mface;
+       MFace *mf = DM_get_face_data_layer(dm, CD_MFACE);
        MCol *mcol = dm->getFaceDataArray(dm, CD_MCOL);
+       MCol *realcol = dm->getFaceDataArray(dm, CD_TEXTURE_MCOL);
        float *nors= dm->getFaceDataArray(dm, CD_NORMAL);
        MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
-       int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
+       int i, j, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
        int startFace = 0, lastFlag = 0xdeadbeef;
 
        if( GPU_buffer_legacy(dm) ) {
@@ -510,67 +511,82 @@
                        if(nors) nors += 3;
                }
        } else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster 
rendering */
+               MCol *col = realcol;
+               if(!col)
+                       col = mcol;
+
                GPU_vertex_setup( dm );
                GPU_normal_setup( dm );
                GPU_uv_setup( dm );
-               if( mcol != 0 ) {
-                       if( dm->drawObject->colType != CD_MCOL ) {
-                               unsigned char *colors = 
MEM_mallocN(dm->getNumFaces(dm)*3*sizeof(unsigned char), 
"cdDM_drawFacesTex_common");
+               if( col != 0 ) {
+                       /*if( realcol && dm->drawObject->colType == 
CD_TEXTURE_MCOL )  {
+                               col = 0;
+                       } else if( mcol && dm->drawObject->colType == CD_MCOL ) 
{
+                               col = 0;
+                       }
+                       
+                       if( col != 0 ) {*/
+                               unsigned char *colors = 
MEM_mallocN(dm->getNumFaces(dm)*4*3*sizeof(unsigned char), 
"cdDM_drawFacesTex_common");
                                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;
+                                       for( j=0; j < 4; j++ ) {
+                                               colors[i*12+j*3] = col[i*4+j].r;
+                                               colors[i*12+j*3+1] = 
col[i*4+j].g;
+                                               colors[i*12+j*3+2] = 
col[i*4+j].b;
+                                       }
                                }
                                GPU_color3_upload(dm,colors);
                                MEM_freeN(colors);
-                               dm->drawObject->colType = CD_MCOL;
-                       }
+                               if(realcol)
+                                       dm->drawObject->colType = 
CD_TEXTURE_MCOL;
+                               else if(mcol)
+                                       dm->drawObject->colType = CD_MCOL;
+                       //}
                        GPU_color_setup( dm );
                }
-               if( !GPU_buffer_legacy(dm) ) {
-                       glShadeModel( GL_SMOOTH );
-                       for(i = 0; i < dm->drawObject->nelements/3; i++) {
-                               int actualFace = dm->drawObject->faceRemap[i];
-                               int flag;
-                               unsigned char *cp = NULL;
 
-                               if(drawParams) {
-                                       flag = drawParams(tf? &tf[actualFace]: 
NULL, mcol? &mcol[actualFace*4]: NULL, mf[actualFace].mat_nr);
+               glShadeModel( GL_SMOOTH );
+               for(i = 0; i < dm->drawObject->nelements/3; i++) {
+                       int actualFace = dm->drawObject->faceRemap[i];
+                       int flag = 1;
+                       unsigned char *cp = NULL;
+
+                       if(drawParams) {
+                               flag = drawParams(tf? &tf[actualFace]: NULL, 
mcol? &mcol[actualFace*4]: NULL, mf[actualFace].mat_nr);
+                       }
+                       else {
+                               if(index) {
+                                       orig = index[actualFace];
+                                       if(drawParamsMapped)
+                                               flag = 
drawParamsMapped(userData, orig);
                                }
-                               else {
-                                       if(index) {
-                                               orig = index[actualFace];
-                                               if(drawParamsMapped)
-                                                       flag = 
drawParamsMapped(userData, orig);
+                               else
+                                       if(drawParamsMapped)
+                                               flag = 
drawParamsMapped(userData, actualFace);
+                       }
+                       if( flag != lastFlag ) {
+                               if( startFace < i ) {
+                                       if( lastFlag != 0 ) { /* if the flag is 
0 it means the face is hidden or invisible */
+                                               if (lastFlag==1 && mcol)
+                                                       GPU_color_switch(1);
+                                               else
+                                                       GPU_color_switch(0);
+                                               
glDrawArrays(GL_TRIANGLES,startFace*3,(i-startFace)*3);
                                        }
-                                       else
-                                               if(drawParamsMapped)
-                                                       flag = 
drawParamsMapped(userData, actualFace);
                                }
-                               if( flag != lastFlag ) {
-                                       if( startFace < i ) {
-                                               if( lastFlag != 0 ) { /* if the 
flag is 0 it means the face is hidden or invisible */
-                                                       if (lastFlag==1 && mcol)
-                                                               
GPU_color_switch(1);
-                                                       else
-                                                               
GPU_color_switch(0);
-                                                       
glDrawArrays(GL_TRIANGLES,startFace*3,(i-startFace)*3);
-                                               }
-                                       }
-                                       lastFlag = flag;
-                                       startFace = i;
-                               }
+                               lastFlag = flag;
+                               startFace = i;
                        }
-                       if( startFace < dm->drawObject->nelements/3 ) {
-                               if( lastFlag != 0 ) { /* if the flag is 0 it 
means the face is hidden or invisible */
-                                       if (lastFlag==1 && mcol)
-                                               GPU_color_switch(1);
-                                       else
-                                               GPU_color_switch(0);
-                                       
glDrawArrays(GL_TRIANGLES,startFace*3,dm->drawObject->nelements-startFace*3);
-                               }
+               }
+               if( startFace < dm->drawObject->nelements/3 ) {
+                       if( lastFlag != 0 ) { /* if the flag is 0 it means the 
face is hidden or invisible */
+                               if (lastFlag==1 && mcol)
+                                       GPU_color_switch(1);
+                               else
+                                       GPU_color_switch(0);
+                               
glDrawArrays(GL_TRIANGLES,startFace*3,dm->drawObject->nelements-startFace*3);
                        }
                }
+
                GPU_buffer_unbind();
                glShadeModel( GL_FLAT );
        }
@@ -591,8 +607,10 @@
        int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
 
 
-       mc = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
+       mc = DM_get_face_data_layer(dm, CD_ID_MCOL);
        if(!mc)
+               mc = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
+       if(!mc)
                mc = DM_get_face_data_layer(dm, CD_MCOL);
 
        if( GPU_buffer_legacy(dm) ) {

Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/customdata.c      
2009-07-10 10:48:25 UTC (rev 21479)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/customdata.c      
2009-07-10 11:22:11 UTC (rev 21480)
@@ -726,6 +726,10 @@
         layerFree_mdisps, layerInterp_mdisps, layerSwap_mdisps, NULL},
        {sizeof(MCol)*4, "MCol", 4, "WeightCol", NULL, NULL, layerInterp_mcol,
         layerSwap_mcol, layerDefault_mcol},
+        {sizeof(MCol)*4, "MCol", 4, "IDCol", NULL, NULL, layerInterp_mcol,
+        layerSwap_mcol, layerDefault_mcol},
+        {sizeof(MCol)*4, "MCol", 4, "TexturedCol", NULL, NULL, 
layerInterp_mcol,
+        layerSwap_mcol, layerDefault_mcol},
 };
 
 const char *LAYERTYPENAMES[CD_NUMTYPES] = {

Modified: 
branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawmesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawmesh.c     
2009-07-10 10:48:25 UTC (rev 21479)
+++ branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawmesh.c     
2009-07-10 11:22:11 UTC (rev 21480)
@@ -397,8 +397,7 @@
        glPopMatrix();
 }
 
-
-static int draw_tface__set_draw(MTFace *tface, MCol *mcol, int matnr)
+static int draw_tface__set_draw_legacy(MTFace *tface, MCol *mcol, int matnr)
 {
        if (tface && (tface->mode&TF_INVISIBLE)) return 0;
 
@@ -420,7 +419,85 @@
                return 1; /* Set color from mcol */
        }
 }
+static int draw_tface__set_draw(MTFace *tface, MCol *mcol, int matnr)
+{
+       if (tface && (tface->mode&TF_INVISIBLE)) return 0;
 
+       if (tface && set_draw_settings_cached(0, Gtexdraw.istex, tface, 
Gtexdraw.islit, Gtexdraw.ob, matnr, TF_TWOSIDE)) {
+               return 2; /* Don't set color */
+       } else if (tface && tface->mode&TF_OBCOL) {
+               return 2; /* Don't set color */
+       } else if (!mcol) {
+               return 2; /* Don't set color */
+       } else {
+               return 1; /* Set color from mcol */
+       }
+}
+static void add_tface_color_layer(DerivedMesh *dm)
+{
+       MTFace *tface = DM_get_face_data_layer(dm, CD_MTFACE);
+       MFace *mface = DM_get_face_data_layer(dm, CD_MFACE);
+       MCol *mcol = dm->getFaceDataArray(dm, CD_MCOL);
+       MCol *finalCol;
+       int i,j;
+       finalCol = 
MEM_mallocN(sizeof(MCol)*4*dm->getNumFaces(dm),"add_tface_color_layer");
+       for(i=0;i<dm->getNumFaces(dm);i++) {
+               if (tface && (tface->mode&TF_INVISIBLE)) {
+                       if( mcol )
+                               
memcpy(&finalCol[i*4],&mcol[i*4],sizeof(MCol)*4);
+                       else
+                               for(j=0;j<4;j++) {
+                                       finalCol[i*4+j].b = 255;
+                                       finalCol[i*4+j].g = 255;
+                                       finalCol[i*4+j].r = 255;
+                               }
+               }
+               else if (tface && mface && set_draw_settings_cached(0, 
Gtexdraw.istex, tface, Gtexdraw.islit, Gtexdraw.ob, mface[i].mat_nr, 
TF_TWOSIDE)) {
+                       for(j=0;j<4;j++) {
+                               finalCol[i*4+j].b = 255;
+                               finalCol[i*4+j].g = 0;
+                               finalCol[i*4+j].r = 255;
+                       }
+               } else if (tface && tface->mode&TF_OBCOL) {
+                       for(j=0;j<4;j++) {
+                               finalCol[i*4+j].r = Gtexdraw.obcol[0];
+                               finalCol[i*4+j].g = Gtexdraw.obcol[1];
+                               finalCol[i*4+j].b = Gtexdraw.obcol[2];
+                       }
+               } else if (!mcol) {
+                       if (tface) {
+                               for(j=0;j<4;j++) {
+                                       finalCol[i*4+j].b = 255;
+                                       finalCol[i*4+j].g = 255;
+                                       finalCol[i*4+j].r = 255;
+                               }
+                       }
+                       else {
+                               Material *ma= 
give_current_material(Gtexdraw.ob, mface[i].mat_nr+1);
+                               if(ma) 
+                                       for(j=0;j<4;j++) {
+                                               finalCol[i*4+j].b = ma->b;
+                                               finalCol[i*4+j].g = ma->g;
+                                               finalCol[i*4+j].r = ma->r;
+                                       }
+                               else
+                                       for(j=0;j<4;j++) {
+                                               finalCol[i*4+j].b = 255;
+                                               finalCol[i*4+j].g = 255;
+                                               finalCol[i*4+j].r = 255;
+                                       }
+                       }
+               } else {
+                       for(j=0;j<4;j++) {
+                               finalCol[i*4+j].b = mcol[i*4+j].r;
+                               finalCol[i*4+j].g = mcol[i*4+j].g;
+                               finalCol[i*4+j].r = mcol[i*4+j].b;
+                       }
+               }
+       }
+       CustomData_add_layer( &dm->faceData, CD_TEXTURE_MCOL, CD_ASSIGN, 
finalCol, dm->numFaceData );
+}
+
 static int draw_tface_mapped__set_draw(void *userData, int index)
 {
        Mesh *me = (Mesh*)userData;
@@ -568,7 +645,13 @@
                        dm->drawMappedFacesTex(dm, draw_tface_mapped__set_draw, 
me);
        }
        else {
-               dm->drawFacesTex(dm, draw_tface__set_draw);
+               if( GPU_buffer_legacy(dm) )
+                       dm->drawFacesTex(dm, draw_tface__set_draw_legacy);
+               else {
+                       if( 
!CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL) )
+                               add_tface_color_layer(dm);
+                       dm->drawFacesTex(dm, draw_tface__set_draw);
+               }
        }
 
        /* draw game engine text hack */

Modified: 
branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c   
2009-07-10 10:48:25 UTC (rev 21479)
+++ branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c   
2009-07-10 11:22:11 UTC (rev 21480)
@@ -5642,12 +5642,11 @@
                        }
                }
 
-               CustomData_free_layers( &dm->faceData, CD_WEIGHT_MCOL, 
dm->getNumFaces(dm) );
-               CustomData_add_layer( &dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, 
colors, dm->numFaceData );
+               CustomData_add_layer( &dm->faceData, CD_ID_MCOL, CD_ASSIGN, 
colors, dm->numFaceData );
                GPU_buffer_free(dm->drawObject->colors,0);
                dm->drawObject->colors = 0;

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to