Revision: 15682
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15682
Author:   blendix
Date:     2008-07-22 00:07:51 +0200 (Tue, 22 Jul 2008)

Log Message:
-----------
Apricot Branch
==============

* Made GLSL respect opaque/add/alpha/clip flags.
* Fix bug for all material types to correctly deal with
  different transp flags in a single mesh.
* Also made 3d view material alpha code a bit easier to
  understand.

Modified Paths:
--------------
    branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c
    branches/apricot/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/apricot/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/apricot/source/blender/gpu/GPU_draw.h
    branches/apricot/source/blender/gpu/GPU_material.h
    branches/apricot/source/blender/gpu/intern/gpu_draw.c
    branches/apricot/source/blender/gpu/intern/gpu_material.c
    branches/apricot/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
    branches/apricot/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    branches/apricot/source/gameengine/Ketsji/BL_Texture.cpp
    branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
    branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.h
    branches/apricot/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
    branches/apricot/source/gameengine/Ketsji/KX_PolygonMaterial.h
    branches/apricot/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h

Modified: branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c     
2008-07-21 21:24:37 UTC (rev 15681)
+++ branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c     
2008-07-21 22:07:51 UTC (rev 15682)
@@ -86,6 +86,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "GPU_draw.h"
 #include "GPU_extensions.h"
 #include "GPU_material.h"
 
@@ -920,11 +921,18 @@
        EditFace *efa;
        DMVertexAttribs attribs;
        GPUVertexAttribs gattribs;
-       int i, b, matnr, new_matnr, dodraw;
+       MTFace *tf;
+       int transp, new_transp, orig_transp, tfoffset;
+       int i, b, matnr, new_matnr, dodraw, layer;
 
        dodraw = 0;
        matnr = -1;
 
+       transp = GPU_get_material_blend_mode();
+       orig_transp = transp;
+       layer = CustomData_get_layer_index(&em->fdata, CD_MTFACE);
+       tfoffset = (layer == -1)? -1: em->fdata.layers[layer].offset;
+
        memset(&attribs, 0, sizeof(attribs));
 
        /* always use smooth shading even for flat faces, else vertex colors 
wont interpolate */
@@ -967,6 +975,19 @@
                                DM_vertex_attributes_from_gpu(dm, &gattribs, 
&attribs);
                }
 
+               if(tfoffset != -1) {
+                       tf = (MTFace*)((char*)efa->data)+tfoffset;
+                       new_transp = tf->transp;
+
+                       if(new_transp != transp) {
+                               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;
+                       }
+               }
+
                if(dodraw) {
                        
                        TOTTRI_INC(efa->v4);

Modified: branches/apricot/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/cdderivedmesh.c   
2008-07-21 21:24:37 UTC (rev 15681)
+++ branches/apricot/source/blender/blenkernel/intern/cdderivedmesh.c   
2008-07-21 22:07:51 UTC (rev 15682)
@@ -58,6 +58,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "GPU_draw.h"
 #include "GPU_extensions.h"
 #include "GPU_material.h"
 
@@ -590,13 +591,17 @@
        DMVertexAttribs attribs;
        MVert *mvert = cddm->mvert;
        MFace *mface = cddm->mface;
+       MTFace *tf = dm->getFaceDataArray(dm, CD_MTFACE);
        float (*nors)[3] = dm->getFaceDataArray(dm, CD_NORMAL);
        int a, b, dodraw, smoothnormal, matnr, new_matnr;
+       int transp, new_transp, orig_transp;
        int orig, *index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
 
        matnr = -1;
        smoothnormal = 0;
        dodraw = 0;
+       transp = GPU_get_material_blend_mode();
+       orig_transp = transp;
 
        memset(&attribs, 0, sizeof(attribs));
 
@@ -628,6 +633,22 @@
                                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) {

Modified: branches/apricot/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/subsurf_ccg.c     
2008-07-21 21:24:37 UTC (rev 15681)
+++ branches/apricot/source/blender/blenkernel/intern/subsurf_ccg.c     
2008-07-21 22:07:51 UTC (rev 15682)
@@ -61,6 +61,7 @@
 
 #include "BIF_gl.h"
 
+#include "GPU_draw.h"
 #include "GPU_extensions.h"
 #include "GPU_material.h"
 
@@ -1677,15 +1678,19 @@
        CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
        GPUVertexAttribs gattribs;
        DMVertexAttribs attribs;
+       MTFace *tf = dm->getFaceDataArray(dm, CD_MTFACE);
        int gridSize = ccgSubSurf_getGridSize(ss);
        int gridFaces = gridSize - 1;
        int edgeSize = ccgSubSurf_getEdgeSize(ss);
+       int transp, orig_transp, new_transp;
        char *faceFlags = DM_get_face_data_layer(dm, CD_FLAGS);
        int a, b, i, doDraw, numVerts, matnr, new_matnr, totface;
 
        doDraw = 0;
        numVerts = 0;
        matnr = -1;
+       transp = GPU_get_material_blend_mode();
+       orig_transp = transp;
 
        memset(&attribs, 0, sizeof(attribs));
 
@@ -1738,6 +1743,18 @@
                        continue;
                }
 
+               if(tf) {
+                       new_transp = tf[i].transp;
+
+                       if(new_transp != transp) {
+                               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;
+                       }
+               }
+
                glShadeModel(drawSmooth? GL_SMOOTH: GL_FLAT);
                for (S=0; S<numVerts; S++) {
                        VertData *faceGridData = 
ccgSubSurf_getFaceGridDataArray(ss, f, S);

Modified: branches/apricot/source/blender/gpu/GPU_draw.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_draw.h      2008-07-21 21:24:37 UTC 
(rev 15681)
+++ branches/apricot/source/blender/gpu/GPU_draw.h      2008-07-21 22:07:51 UTC 
(rev 15682)
@@ -42,15 +42,17 @@
 struct Scene;
 struct Object;
 
-/* OpenGL drawing functions. These are also shared with
- * the game engine, whereas they were previously duplicated. */
+/* OpenGL drawing functions related to shading. These are also
+ * shared with the game engine, where there were previously
+ * duplicates of some of these functions. */
 
 /* Initialize */
 
 void GPU_state_init(void);
 
 /* Material drawing
- * - first the state is initialized by a particular object and it's materials
+ * - first the state is initialized by a particular object and
+ *   it's materials
  * - after this, materials can be quickly enabled by their number,
  *   GPU_enable_material returns 0 if drawing should be skipped
  * - after drawing, the material must be disabled again */
@@ -60,25 +62,34 @@
 int GPU_enable_material(int nr, void *attribs);
 void GPU_disable_material(void);
 
+void GPU_set_material_blend_mode(int blendmode);
+int GPU_get_material_blend_mode(void);
+
+/* TexFace drawing
+ * - this is mutually exclusive with material drawing, a mesh should
+ *   be drawn using one or the other
+ * - passing NULL clears the state again */
+
+int GPU_set_tpage(struct MTFace *tface);
+
 /* Lights
- * - returns how many lights were enabled */
+ * - returns how many lights were enabled
+ * - this affects fixed functions materials and texface, not glsl */
 
 int GPU_default_lights(void);
 int GPU_scene_object_lights(struct Scene *scene, struct Object *ob,
        int lay, float viewmat[][4]);
 
-/* Text render */
+/* Text render
+ * - based on moving uv coordinates */
 
 void GPU_render_text(struct MTFace *tface, int mode,
        const char *textstr, int textlen, unsigned int *col,
        float *v1, float *v2, float *v3, float *v4, int glattrib);
 
-/* TexFace state setting, NULL clears it */
+/* Mipmap settings
+ * - these will free textures on changes */
 
-int GPU_set_tpage(struct MTFace *tface);
-
-/* Mipmap settings, these free textures on changes */
-
 void GPU_set_mipmap(int mipmap);
 void GPU_set_linear_mipmap(int linear);
 void GPU_paint_set_mipmap(int mipmap);

Modified: branches/apricot/source/blender/gpu/GPU_material.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_material.h  2008-07-21 21:24:37 UTC 
(rev 15681)
+++ branches/apricot/source/blender/gpu/GPU_material.h  2008-07-21 22:07:51 UTC 
(rev 15682)
@@ -84,10 +84,10 @@
 } GPUBuiltin;
 
 typedef enum GPUBlendMode {
-       GPU_BLEND_SOLID,
-       GPU_BLEND_ALPHA,
-       GPU_BLEND_ADD,
-       GPU_BLEND_CLIPALPHA
+       GPU_BLEND_SOLID = 0,
+       GPU_BLEND_ADD = 1,
+       GPU_BLEND_ALPHA = 2,
+       GPU_BLEND_CLIP = 4
 } GPUBlendMode;
 
 typedef struct GPUNodeStack {

Modified: branches/apricot/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_draw.c       2008-07-21 
21:24:37 UTC (rev 15681)
+++ branches/apricot/source/blender/gpu/intern/gpu_draw.c       2008-07-21 
22:07:51 UTC (rev 15682)
@@ -274,54 +274,51 @@
        glDisable(GL_ALPHA_TEST);
 }
 
-static void gpu_verify_alpha_mode(MTFace *tface)
+static void gpu_set_blend_mode(GPUBlendMode blendmode)
 {
-       if(GTS.alphamode == tface->transp)
-               return;
+       if(blendmode == GPU_BLEND_SOLID) {
+               glDisable(GL_BLEND);
+               glDisable(GL_ALPHA_TEST);
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       }
+       else if(blendmode==GPU_BLEND_ADD) {
+               glEnable(GL_BLEND);
+               glBlendFunc(GL_ONE, GL_ONE);
+               glDisable(GL_ALPHA_TEST);
+       }
+       else if(blendmode==GPU_BLEND_ALPHA) {
+               glEnable(GL_BLEND);
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               
+               /* if U.glalphaclip == 1.0, some cards go bonkers...
+                * turn off alpha test in this case */
 
-       /* verify alpha blending modes */
-       GTS.alphamode= tface->transp;
-
-       if(GTS.alphamode) {
-               if(GTS.alphamode==TF_ADD) {
-                       glEnable(GL_BLEND);
-                       glBlendFunc(GL_ONE, GL_ONE);
+               /* added after 2.45 to clip alpha */
+               if(U.glalphaclip == 1.0) {
                        glDisable(GL_ALPHA_TEST);
-                       /* glBlendEquationEXT(GL_FUNC_ADD_EXT); */
                }
-               else if(GTS.alphamode==TF_ALPHA) {
-                       glEnable(GL_BLEND);
-                       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-                       
-                       /* added after 2.45 to clip alpha */
-                       
-                       /* if U.glalphaclip == 1.0, some cards go bonkers...
-                        * turn off alpha test in this case */
-                       if(U.glalphaclip == 1.0) {
-                               glDisable(GL_ALPHA_TEST);
-                       }
-                       else {
-                               glEnable(GL_ALPHA_TEST);
-                               glAlphaFunc(GL_GREATER, U.glalphaclip);
-                       }
-               }
-               else if(GTS.alphamode==TF_CLIP) {
-                       glDisable(GL_BLEND); 
+               else {
                        glEnable(GL_ALPHA_TEST);
-                       glAlphaFunc(GL_GREATER, 0.5f);
+                       glAlphaFunc(GL_GREATER, U.glalphaclip);
                }
-               /*      glBlendEquationEXT(GL_FUNC_ADD_EXT); */
-               /* else { */
-               /*      glBlendFunc(GL_ONE, GL_ONE); */
-               /*      glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT_EXT); */
-               /* } */
        }
-       else {
-               glDisable(GL_BLEND);
-               glDisable(GL_ALPHA_TEST);
+       else if(blendmode==GPU_BLEND_CLIP) {
+               glDisable(GL_BLEND); 
+               glEnable(GL_ALPHA_TEST);
+               glAlphaFunc(GL_GREATER, 0.5f);
        }
 }
 
+static void gpu_verify_alpha_mode(MTFace *tface)
+{
+       /* verify alpha blending modes */
+       if(GTS.alphamode == tface->transp)
+               return;
+
+       gpu_set_blend_mode(tface->transp);
+       GTS.alphamode= tface->transp;
+}
+
 static void gpu_verify_reflection(Image *ima)
 {
        if (ima && (ima->flag & IMA_REFLECT)) {
@@ -758,10 +755,11 @@
        Object *gob;
        Scene *gscene;
 
-       int hasalpha[MAXMATBUF];
+       GPUBlendMode blendmode[MAXMATBUF];
        int alphapass;
 
        int lastmatnr, lastretval;
+       GPUBlendMode lastblendmode;
 } GMS;
 
 Material *gpu_active_node_material(Material *ma)
@@ -783,12 +781,13 @@

@@ 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