Commit: cd4a166a32913006a23d202c4a822b1bade8762d
Author: Sergey Sharybin
Date:   Thu Jul 16 10:00:01 2015 +0200
Branches: opensubdiv-modifier
https://developer.blender.org/rBcd4a166a32913006a23d202c4a822b1bade8762d

OpenSubdiv: Do some documentation of new fields in CCGSubSurf

Also get rid of some functions which are unlikely to be used.

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

M       intern/opensubdiv/opensubdiv_capi.cc
M       source/blender/blenkernel/intern/CCGSubSurf.c
M       source/blender/blenkernel/intern/CCGSubSurf_intern.h
M       source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c

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

diff --git a/intern/opensubdiv/opensubdiv_capi.cc 
b/intern/opensubdiv/opensubdiv_capi.cc
index 5d6053b..26247ed 100644
--- a/intern/opensubdiv/opensubdiv_capi.cc
+++ b/intern/opensubdiv/opensubdiv_capi.cc
@@ -142,73 +142,6 @@ typedef PartitionedMesh<GLVertexBuffer,
                         GLPatchTable> OsdGLSLComputeMesh;
 #endif
 
-#if 0
-static OpenSubdiv::OsdUtilMesh<OsdVertex>::Scheme get_osd_scheme(int scheme)
-{
-       switch (scheme) {
-               case OPENSUBDIV_SCHEME_CATMARK:
-                       return 
OpenSubdiv::OsdUtilMesh<OsdVertex>::SCHEME_CATMARK;
-               case OPENSUBDIV_SCHEME_BILINEAR:
-                       return 
OpenSubdiv::OsdUtilMesh<OsdVertex>::SCHEME_BILINEAR;
-               case OPENSUBDIV_SCHEME_LOOP:
-                       return OpenSubdiv::OsdUtilMesh<OsdVertex>::SCHEME_LOOP;
-               default:
-                       assert(!"Wrong subdivision scheme");
-       }
-       return OpenSubdiv::OsdUtilMesh<OsdVertex>::SCHEME_BILINEAR;
-}
-#endif
-
-/* TODO(sergey): Currently we use single coarse face per partition,
- * which allows to have per-face material assignment but which also
- * increases number of glDrawElements() calls.
- *
- * Ideally here we need to partition like this, but do some conjunction
- * at draw time, so adjacent faces with the same material are displayed
- * in a single chunk.
- */
-#if 0
-static void get_partition_per_face(OsdHbrMesh &hmesh,
-                                   std::vector<int> *idsOnPtexFaces)
-{
-       int numFaces = hmesh.GetNumCoarseFaces();
-
-       /* First, assign partition ID to each coarse face. */
-       std::vector<int> idsOnCoarseFaces;
-       for (int i = 0; i < numFaces; ++i) {
-               int partitionID = i;
-               idsOnCoarseFaces.push_back(partitionID);
-       }
-
-       /* Create ptex index to coarse face index mapping. */
-       OsdHbrFace *lastFace = hmesh.GetFace(numFaces - 1);
-       int numPtexFaces = lastFace->GetPtexIndex();
-       numPtexFaces += (hmesh.GetSubdivision()->FaceIsExtraordinary(&hmesh,
-                                                                    lastFace) ?
-                        lastFace->GetNumVertices() : 1);
-
-       /* TODO(sergey): Duplicated logic to simpleHbr. */
-       std::vector<int> ptexIndexToFaceMapping(numPtexFaces);
-       int ptexIndex = 0;
-       for (int i = 0; i < numFaces; ++i) {
-               OsdHbrFace *f = hmesh.GetFace(i);
-               ptexIndexToFaceMapping[ptexIndex++] = i;
-               int numVerts = f->GetNumVertices();
-               if (numVerts != 4 ) {
-                       for (int j = 0; j < numVerts-1; ++j) {
-                               ptexIndexToFaceMapping[ptexIndex++] = i;
-                       }
-               }
-       }
-       assert((int)ptexIndexToFaceMapping.size() == numPtexFaces);
-
-       /* Convert ID array from coarse face index space to ptex index space. */
-       for (int i = 0; i < numPtexFaces; ++i) {
-               
idsOnPtexFaces->push_back(idsOnCoarseFaces[ptexIndexToFaceMapping[i]]);
-       }
-}
-#endif
-
 struct OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner(
         OpenSubdiv_TopologyRefinerDescr *topology_refiner,
         int evaluator_type,
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c 
b/source/blender/blenkernel/intern/CCGSubSurf.c
index 9f09212..1a51ef2 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -308,16 +308,16 @@ CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int 
subdivLevels, CCGAllocatorIFC *a
                ss->osd_mesh = NULL;
                ss->osd_topology_refiner = NULL;
                ss->osd_mesh_invalid = false;
-               ss->osd_coords_invalid = false;
+               ss->osd_coarse_coords_invalid = false;
                ss->osd_vao = 0;
                ss->skip_grids = false;
                ss->osd_compute = 0;
                ss->osd_uvs_invalid = true;
                ss->osd_subsurf_uv = 0;
                ss->osd_uv_index = -1;
-               ss->osd_next_face_index = 0;
-               ss->osd_coarse_positions = NULL;
-               ss->osd_num_coarse_positions = 0;
+               ss->osd_next_face_ptex_index = 0;
+               ss->osd_coarse_coords = NULL;
+               ss->osd_num_coarse_coords = 0;
 #endif
 
                return ss;
@@ -339,8 +339,8 @@ void ccgSubSurf_free(CCGSubSurf *ss)
        if (ss->osd_vao != 0) {
                glDeleteVertexArrays(1, &ss->osd_vao);
        }
-       if (ss->osd_coarse_positions != NULL) {
-               MEM_freeN(ss->osd_coarse_positions);
+       if (ss->osd_coarse_coords != NULL) {
+               MEM_freeN(ss->osd_coarse_coords);
        }
        /* TODO(sergey): This is not valid when viewport is not visible. */
        BLI_assert(ss->osd_topology_refiner == NULL);
@@ -508,7 +508,7 @@ CCGError ccgSubSurf_initFullSync(CCGSubSurf *ss)
        ss->tempEdges = MEM_mallocN(sizeof(*ss->tempEdges) * ss->lenTempArrays, 
"CCGSubsurf tempEdges");
 
        ss->syncState = eSyncState_Vert;
-       ss->osd_next_face_index = 0;
+       ss->osd_next_face_ptex_index = 0;
 
        return eCCGError_None;
 }
@@ -835,12 +835,12 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL 
fHDL, int numVerts, CCGV
                        }
                }
 #ifdef WITH_OPENSUBDIV
-               f->osd_index = ss->osd_next_face_index;
+               f->osd_index = ss->osd_next_face_ptex_index;
                if (numVerts == 4) {
-                       ss->osd_next_face_index++;
+                       ss->osd_next_face_ptex_index++;
                }
                else {
-                       ss->osd_next_face_index += numVerts;
+                       ss->osd_next_face_ptex_index += numVerts;
                }
 #endif
        }
diff --git a/source/blender/blenkernel/intern/CCGSubSurf_intern.h 
b/source/blender/blenkernel/intern/CCGSubSurf_intern.h
index 874e50b..d7a95e4 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf_intern.h
+++ b/source/blender/blenkernel/intern/CCGSubSurf_intern.h
@@ -205,21 +205,57 @@ struct CCGSubSurf {
        CCGEdge **tempEdges;
 
 #ifdef WITH_OPENSUBDIV
-       struct OpenSubdiv_EvaluatorDescr *osd_evaluator;
+       /* Skip grids means no CCG geometry is created and subsurf is possible
+        * to be completely done on GPU.
+        */
+       bool skip_grids;
+
+       /* ** GPU backend. ** */
+
+       /* Compute device used by GL mesh. */
+       short osd_compute;
+       /* Coarse (base mesh) vertex coordinates.
+        *
+        * Filled in from the modifier stack and passed to OpenSubdiv compute
+        * on mesh display.
+        */
+       float (*osd_coarse_coords)[3];
+       int osd_num_coarse_coords;
+       /* Denotes whether coarse positions in the GL mesh are invalid.
+        * Used to avoid updating GL mesh coords on every redraw.
+        */
+       bool osd_coarse_coords_invalid;
+
+       /* GL mesh descriptor, used for refinment and draw. */
        struct OpenSubdiv_GLMesh *osd_mesh;
+       /* Refiner which is used to create GL mesh.
+        *
+        * Refiner is created from the modifier stack and used later from the 
main
+        * thread to construct GL mesh to avoid threaded access to GL.
+        */
        struct OpenSubdiv_TopologyRefinerDescr *osd_topology_refiner;  /* Only 
used at synchronization stage. */
-       bool osd_mesh_invalid, osd_coords_invalid;
+       /* Denotes whether osd_mesh is invalid now due to topology changes and 
needs
+        * to be reconstructed.
+        *
+        * Reconstruction happens from main thread due to OpenGL communication.
+        */
+       bool osd_mesh_invalid;
+       /* Vertex array used for osd_mesh draw. */
        unsigned int osd_vao;
-       bool skip_grids;
-       short osd_compute;
 
-       bool osd_uvs_invalid;
+       /* ** CPU backend. ** */
+
+       /* Limit evaluator, used to evaluate CCG. */
+       struct OpenSubdiv_EvaluatorDescr *osd_evaluator;
+       /* Next PTex face index, used while CCG synchroization
+        * to fill in PTex index of CCGFace.
+        */
+       int osd_next_face_ptex_index;
+
+       /* ** Needs review.  ** */
        bool osd_subsurf_uv;
        int osd_uv_index;
-       int osd_next_face_index;
-
-       float (*osd_coarse_positions)[3];
-       int osd_num_coarse_positions;
+       bool osd_uvs_invalid;
 #endif
 };
 
diff --git a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c 
b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
index 2420bf8..e7987c6 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
@@ -83,20 +83,15 @@ static void ccgSubSurf__updateGLMeshCoords(CCGSubSurf *ss)
 {
        BLI_assert(ss->meshIFC.numLayers == 3);
        openSubdiv_osdGLMeshUpdateVertexBuffer(ss->osd_mesh,
-                                              (float *) 
ss->osd_coarse_positions,
+                                              (float *) ss->osd_coarse_coords,
                                               0,
-                                              ss->osd_num_coarse_positions);
+                                              ss->osd_num_coarse_coords);
 }
 
 bool ccgSubSurf_prepareGLMesh(CCGSubSurf *ss, bool use_osd_glsl)
 {
        int compute_type;
 
-       /* Happens for meshes without faces. */
-       //if (UNLIKELY(ss->osd_evaluator == NULL)) {
-       //      return false;
-       //}
-
        switch (U.opensubdiv_compute_type) {
 #define CHECK_COMPUTE_TYPE(type) \
                case USER_OPENSUBDIV_COMPUTE_ ## type: \
@@ -153,11 +148,11 @@ bool ccgSubSurf_prepareGLMesh(CCGSubSurf *ss, bool 
use_osd_glsl)
 
                glBindBuffer(GL_ARRAY_BUFFER, 0);
        }
-       else if (ss->osd_coords_invalid) {
+       else if (ss->osd_coarse_coords_invalid) {
                ccgSubSurf__updateGLMeshCoords(ss);
                openSubdiv_osdGLMeshRefine(ss->osd_mesh);
                openSubdiv_osdGLMeshSynchronize(ss->osd_mesh);
-               ss->osd_coords_invalid = false;
+               ss->osd_coarse_coords_invalid = false;
        }
 
        openSubdiv_osdGLMeshDisplayPrepare(use_osd_glsl, ss->osd_uv_index);
@@ -414,63 +409,6 @@ static void 
opensubdiv_updateEvaluatorCoarsePositions(CCGSubSurf *ss)
        MEM_freeN(positions);
 }
 
-static void opensubdiv_updateCoarseNormals(CCGSubSurf *ss)
-{
-       int i;
-       int normalDataOffset = ss->normalDataOffset;
-       int vertDataSize = ss->meshIFC.vertDataSize;
-
-       if (ss->meshIFC.numLayers != 3) {
-               return;
-       }
-
-#pragma omp parallel for
-       for (i = 0; i < ss->vMap->curSize; ++i) {
-               CCGVert *v = (CCGVert *) ss->vMap->buckets[i];
-               for (; v; v = v->next) {
-                       float *no = VERT_getNo(v, 0);
-                       zero_v3(no);
-               }
-       }
-
-#pragma omp parallel for
-       for (i = 0; i < ss->fMap->curSize; ++i) {
-               CCGFace *f = (CCGFace *) ss->fMap->buckets[i];
-               for (; f; f = f->next) {
-                       int S;
-                       float face_no[3] = {0.0f, 0.0f, 0.0f};
-                       CCGVert *v_prev = FACE_getVerts(f)[f->numVerts - 1];
-                       float *co_prev = VERT_getCo(v_prev, 0);
-                       for (S = 0; S < f->numVerts; S++) {
-                               CCGVert *v_curr = FACE_getVerts(f)[S];
-                               float *co_curr = VERT_getCo(v_curr, 0);
-                               add_newell_cross_v3_v3v3(face_no, co_prev, 
co_curr);
-                               co_prev = co_curr;
-                       }
-                       if (UNLIKELY(normalize_v3(face_no) == 0.0f)) {
-                               face_no[2] = 1.0f; /* other axis set to 0.0 */
-                       }
-#pragma omp critical
-                       {
-                               for (S = 0; S < f->numVerts; S++) {
-                                       CCGVert *v = FACE_getVerts(f)[S];
-                                       float *no = VERT_getNo(v, 0);
-                                       add_v3_v3(no, face_no);
-                               }
-                       }
-               }
-       }
-
-#pragma omp parallel for
-       for (i = 0; i < ss->vMap->curSize; ++i) {


@@ Diff output truncated at 10240 characters. @@

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

Reply via email to