Commit: ed2dd1a181718236b7bef5ac2f3ba9104803f84b
Author: Nicholas Bishop
Date:   Tue Jan 20 12:35:50 2015 +0100
Branches: cycles-ptex-12
https://developer.blender.org/rBed2dd1a181718236b7bef5ac2f3ba9104803f84b

WIP add ptex vertex attrib to DerivedMesh for GPU drawing

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

M       source/blender/blenkernel/BKE_DerivedMesh.h
M       source/blender/blenkernel/intern/DerivedMesh.c

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

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h 
b/source/blender/blenkernel/BKE_DerivedMesh.h
index da982f8..0c5d57c 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -740,7 +740,12 @@ typedef struct DMVertexAttribs {
                int em_offset, gl_index, gl_texco;
        } orco;
 
-       int tottface, totmcol, tottang, totorco;
+       struct {
+               struct MTessFacePtex *array;
+               int em_offset, gl_index, gl_texco;
+       } ptex;
+
+       int tottface, totmcol, tottang, totorco, totptex;
 } DMVertexAttribs;
 
 void DM_vertex_attributes_from_gpu(DerivedMesh *dm,
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 9b5592b..849f871 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2275,7 +2275,7 @@ static void mesh_build_data(Scene *scene, Object *ob, 
CustomDataMask dataMask,
        BKE_object_sculpt_modifiers_changed(ob);
 
        // TODO:
-       dataMask |= CD_MASK_PTEX_TESSFACE | CD_MASK_PTEX_LOOP;
+       dataMask |= CD_MASK_TESSFACE_PTEX | CD_MASK_LOOP_PTEX_UV;
 
        mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform,
                            &ob->derivedFinal, 0, 1,
@@ -3080,6 +3080,21 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, 
GPUVertexAttribs *gattribs,
                        attribs->orco.gl_index = gattribs->layer[b].glindex;
                        attribs->orco.gl_texco = gattribs->layer[b].gltexco;
                }
+               else if (gattribs->layer[b].type == CD_TESSFACE_PTEX) {
+                       layer = CustomData_get_layer_index(fdata, 
CD_TESSFACE_PTEX);
+                       attribs->totptex = 1;
+                       if (layer != -1) {
+                               attribs->ptex.array = fdata->layers[layer].data;
+                               attribs->ptex.em_offset = 
vdata->layers[layer].offset;
+                       }
+                       else {
+                               attribs->ptex.array = NULL;
+                               attribs->ptex.em_offset = -1;
+                       }
+
+                       attribs->ptex.gl_index = gattribs->layer[b].glindex;
+                       attribs->ptex.gl_texco = gattribs->layer[b].gltexco;
+               }
        }
 }
 
@@ -3144,6 +3159,22 @@ void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int 
a, int index, int vert)
                const float *tang = (array) ? array[a * 4 + vert] : zero;
                glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
        }
+
+       /* ptex texture coordinates */
+       if (attribs->totptex) {
+               MTessFacePtex *array = attribs->ptex.array;
+               float ptex[3] = {0.0f, 0.0f, 0.0f};
+               if (array) {
+                       // TODO
+                       copy_v2_v2(ptex, 
attribs->ptex.array[a].corners[vert].uv);
+                       ptex[2] = attribs->ptex.array[a].corners[vert].id;
+               }
+
+               if (attribs->ptex.gl_texco)
+                       glTexCoord3fv(ptex);
+               else
+                       glVertexAttrib3fvARB(attribs->ptex.gl_index, ptex);
+       }
 }
 
 /* Set object's bounding box based on DerivedMesh min/max data */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to