Commit: 6abc9471811fb0f6622f1b8e4db97e2c00f9d073
Author: Sergey Sharybin
Date:   Wed Jul 15 16:06:26 2015 +0200
Branches: opensubdiv-modifier
https://developer.blender.org/rB6abc9471811fb0f6622f1b8e4db97e2c00f9d073

Merge branch 'master' into opensubdiv-modifier

Conflicts:
        source/blender/blenkernel/intern/subsurf_ccg.c
        source/blender/gpu/GPU_material.h

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



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

diff --cc source/blender/blenkernel/intern/subsurf_ccg.c
index 5d4932b,0b0c011..061f43b
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@@ -1793,167 -2255,18 +2271,82 @@@ static void ccgDM_drawFacesSolid(Derive
  
                return;
        }
 -      
 +
- 
 +#ifdef WITH_OPENSUBDIV
 +      if (ccgdm->useGpuBackend) {
++              const DMFlagMat *faceFlags = ccgdm->faceFlags;
++              const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, 
CD_TESSLOOPNORMAL);
++              CCGSubSurf *ss = ccgdm->ss;
 +              int i, matnr = -1, shademodel = -1;
 +              CCGFaceIterator fi;
 +              int start_partition = 0, num_partitions = 0;
 +              if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, setMaterial != NULL) 
== false)) {
 +                      return;
 +              }
 +
 +              for (ccgSubSurf_initFaceIterator(ss, &fi), i = 0;
 +                   !ccgFaceIterator_isStopped(&fi);
 +                   ccgFaceIterator_next(&fi), ++i)
 +              {
 +                      CCGFace *f = ccgFaceIterator_getCurrent(&fi);
 +                      int index = 
GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
 +                      int new_matnr, new_shademodel;
 +
 +                      if (faceFlags) {
 +                              new_shademodel = (lnors || 
(faceFlags[index].flag & ME_SMOOTH))
 +                                      ? GL_SMOOTH
 +                                      : GL_FLAT;
 +                              new_matnr = faceFlags[index].mat_nr;
 +                      }
 +                      else {
 +                              new_shademodel = GL_SMOOTH;
 +                              new_matnr = 0;
 +                      }
 +
 +                      if (new_shademodel != shademodel || new_matnr != matnr) 
{
 +                              if (num_partitions) {
 +                                      ccgSubSurf_drawGLMesh(ss, true,
 +                                                            start_partition, 
num_partitions);
 +                              }
 +
 +                              start_partition = i;
 +                              num_partitions = 0;
 +
 +                              /* Update material settings for the next 
partitions batch. */
 +                              glShadeModel(new_shademodel);
 +                              if (new_matnr != matnr && setMaterial) {
 +                                      setMaterial(new_matnr + 1, NULL);
 +                              }
 +
 +                              /* Cache settings. */
 +                              shademodel = new_shademodel;
 +                              matnr = new_matnr;
 +                      }
 +
 +                      num_partitions++;
 +              }
 +
 +              /* Draw residual tail of the partitions. */
 +              if (num_partitions) {
 +                      ccgSubSurf_drawGLMesh(ss, true, start_partition, 
num_partitions);
 +              }
 +
 +              /* We're done with drawing if drawing happens using OpenSubdiv. 
*/
 +              return;
 +      }
 +#endif
 +
-       for (i = 0; i < totface; i++) {
-               CCGFace *f = ccgdm->faceMap[i].face;
-               int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
-               int index = 
GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
-               int new_matnr, new_shademodel;
-               short (*ln)[4][3] = NULL;
- 
-               if (faceFlags) {
-                       new_shademodel = (lnors || (faceFlags[index].flag & 
ME_SMOOTH)) ? GL_SMOOTH : GL_FLAT;
-                       new_matnr = faceFlags[index].mat_nr;
-               }
-               else {
-                       new_shademodel = GL_SMOOTH;
-                       new_matnr = 0;
-               }
- 
-               if (lnors) {
-                       ln = lnors;
-                       lnors += gridFaces * gridFaces * numVerts;
-               }
- 
-               if (shademodel != new_shademodel || matnr != new_matnr) {
-                       matnr = new_matnr;
-                       shademodel = new_shademodel;
- 
-                       if (setMaterial)
-                               drawcurrent = setMaterial(matnr + 1, NULL);
-                       else
-                               drawcurrent = 1;
- 
-                       glShadeModel(shademodel);
-               }
- 
-               if (!drawcurrent)
-                       continue;
- 
-               for (S = 0; S < numVerts; S++) {
-                       CCGElem *faceGridData = 
ccgSubSurf_getFaceGridDataArray(ss, f, S);
- 
-                       if (ln) {
-                               /* Can't use quad strips here... */
-                               glBegin(GL_QUADS);
-                               for (y = 0; y < gridFaces; y += step) {
-                                       for (x = 0; x < gridFaces; x += step) {
-                                               float *a = 
CCG_grid_elem_co(&key, faceGridData, x, y + 0);
-                                               float *b = 
CCG_grid_elem_co(&key, faceGridData, x + step, y + 0);
-                                               float *c = 
CCG_grid_elem_co(&key, faceGridData, x + step, y + step);
-                                               float *d = 
CCG_grid_elem_co(&key, faceGridData, x, y + step);
- 
-                                               glNormal3sv(ln[0][1]);
-                                               glVertex3fv(d);
-                                               glNormal3sv(ln[0][2]);
-                                               glVertex3fv(c);
-                                               glNormal3sv(ln[0][3]);
-                                               glVertex3fv(b);
-                                               glNormal3sv(ln[0][0]);
-                                               glVertex3fv(a);
-                                               ln += step;
-                                       }
-                               }
-                               glEnd();
-                       }
-                       else if (shademodel == GL_SMOOTH) {
-                               for (y = 0; y < gridFaces; y += step) {
-                                       glBegin(GL_QUAD_STRIP);
-                                       for (x = 0; x < gridSize; x += step) {
-                                               CCGElem *a = 
CCG_grid_elem(&key, faceGridData, x, y + 0);
-                                               CCGElem *b = 
CCG_grid_elem(&key, faceGridData, x, y + step);
- 
-                                               glNormal3fv(CCG_elem_no(&key, 
a));
-                                               glVertex3fv(CCG_elem_co(&key, 
a));
-                                               glNormal3fv(CCG_elem_no(&key, 
b));
-                                               glVertex3fv(CCG_elem_co(&key, 
b));
-                                       }
-                                       glEnd();
-                               }
-                       }
-                       else {
-                               glBegin(GL_QUADS);
-                               for (y = 0; y < gridFaces; y += step) {
-                                       for (x = 0; x < gridFaces; x += step) {
-                                               float *a = 
CCG_grid_elem_co(&key, faceGridData, x, y + 0);
-                                               float *b = 
CCG_grid_elem_co(&key, faceGridData, x + step, y + 0);
-                                               float *c = 
CCG_grid_elem_co(&key, faceGridData, x + step, y + step);
-                                               float *d = 
CCG_grid_elem_co(&key, faceGridData, x, y + step);
- 
-                                               ccgDM_glNormalFast(a, b, c, d);
- 
-                                               glVertex3fv(d);
-                                               glVertex3fv(c);
-                                               glVertex3fv(b);
-                                               glVertex3fv(a);
-                                       }
-                               }
-                               glEnd();
-                       }
+       GPU_vertex_setup(dm);
+       GPU_normal_setup(dm);
+       GPU_triangle_setup(dm);
+       glShadeModel(GL_SMOOTH);
+       for (a = 0; a < dm->drawObject->totmaterial; a++) {
+               if (!setMaterial || 
setMaterial(dm->drawObject->materials[a].mat_nr + 1, NULL)) {
+                       GPU_buffer_draw_elements(dm->drawObject->triangles, 
GL_TRIANGLES, dm->drawObject->materials[a].start,
+                                                
dm->drawObject->materials[a].totelements);
                }
        }
+       GPU_buffer_unbind();
  }
  
  /* Only used by non-editmesh types */
@@@ -2400,76 -2622,16 +2793,71 @@@ static void ccgDM_drawFacesTex_common(D
        int colType = CD_TEXTURE_MCOL;
        MCol *mcol = dm->getTessFaceDataArray(dm, colType);
        MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE);
-       MTFace *tf_stencil_base = NULL;
-       MTFace *tf_stencil = NULL;
-       MTFace *tf_base;
-       short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL);
        DMFlagMat *faceFlags = ccgdm->faceFlags;
        DMDrawOption draw_option;
-       int i, totface, gridSize = ccgSubSurf_getGridSize(ss);
-       int gridFaces = gridSize - 1;
-       int gridOffset = 0;
-       int mat_nr_cache = -1;
- 
-       /* TODO(sergey): Not currently supported, might lead to some wrong
-        * shading/texturing artifacts due to batching in OpenSubdiv.
-        */
-       (void) compareDrawOptions;
+       int i, totpoly;
+       bool flush;
+       bool use_tface = (flag & DM_DRAW_USE_ACTIVE_UV) != 0;
+       unsigned int next_actualFace;
+       unsigned int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
+       int mat_index;
+       int tot_element, start_element, tot_drawn;
  
 +#ifdef WITH_OPENSUBDIV
 +      if (ccgdm->useGpuBackend) {
++              const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, 
CD_TESSLOOPNORMAL);
 +              /* TODO(sergey): Do we have shorter way to do this? */
 +              int active = CustomData_get_active_layer(&ccgdm->dm.polyData,
 +                                                       CD_MTEXPOLY);
 +              MTexPoly *mtexpoly = CustomData_get_layer_n(&ccgdm->dm.polyData,
 +                                                          CD_MTEXPOLY,
 +                                                          active);
 +
 +              CCGFaceIterator fi;
 +
 +              /* TODO(sergey): Face-by-face for now, in order to optimize
 +               * this we'll need to pass proper compareDrawOptions.
 +               */
 +
 +              if (ccgSubSurf_prepareGLMesh(ss, true) == false) {
 +                      return;
 +              }
 +
 +              for (ccgSubSurf_initFaceIterator(ss, &fi), i = 0;
 +                   !ccgFaceIterator_isStopped(&fi);
 +                   ccgFaceIterator_next(&fi), ++i)
 +              {
 +                      CCGFace *f = ccgFaceIterator_getCurrent(&fi);
 +                      int index = 
GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
-                       MTFace tmp_tf;
-                       int mat_nr;
 +                      bool drawSmooth;
- 
-                       if (mtexpoly != NULL) {
-                               ME_MTEXFACE_CPY(&tmp_tf, &mtexpoly[index]);
++                      MTexPoly tpoly;
++                      int mat_nr;
++                      if (tf) {
++                              ME_MTEXFACE_CPY(&tpoly, &mtexpoly[index]);
 +                      }
 +
 +                      if (faceFlags) {
 +                              drawSmooth = (lnors || (faceFlags[0].flag & 
ME_SMOOTH));
 +                              mat_nr = faceFlags[0].mat_nr;
 +                      }
 +                      else {
 +                              drawSmooth = 1;
 +                              mat_nr = 0;
 +                      }
 +
 +                      glShadeModel(drawSmooth ? GL_SMOOTH : GL_FLAT);
 +
-                       if (drawParams != NULL && mtexpoly != NULL)
-                               drawParams(&tmp_tf, (mcol != NULL), mat_nr);
++                      if (drawParams != NULL && mtexpoly != NULL) {
++                              drawParams((use_tface && tf) ? &tpoly : NULL, 
(mcol != NULL), mat_nr);
++                      }
 +
 +                      ccgSubSurf_drawGLMesh(ss, true, i, 1);
 +              }
 +
 +              return;
 +      }
 +#endif
 +
        CCG_key_top_level(&key, ss);
        ccgdm_pbvh_update(ccgdm);
  
@@@ -3709,17 -3721,14 +3992,19 @@@ static void set_default_ccgdm_callbacks
  
        ccgdm->dm.drawMappedEdgesInterp = ccgDM_drawMappedEdgesInterp;
        ccgdm->dm.drawMappedEdges = ccgDM_drawMappedEdges;
+       ccgdm->dm.gpuObjectNew = ccgDM_GPUObjectNew;
+       ccgdm->dm.copy_gpu_data = ccgDM_copy_gpu_data;
  
        ccgdm->dm.release = ccgDM_release;
 -      
 -      ccgdm->ss = ss;
 -      ccgdm->drawInteriorEdges = drawInteriorEdges;
 -      ccgdm->useSubsurfUv = useSubsurfUv;
 +}
 +
 +static void create_ccgdm_maps(CCGDerivedMesh *ccgdm,
 +                              CCGSubSurf *ss)
 +{
 +      CCGVertIterator vi;
 +      CCGEdgeIterator ei;
 +      CCGFaceIterator fi;
 +      int totvert, totedge, totface;
  
        totvert = ccgSubSurf_getNumVerts(ss);
        ccgdm->vertMap = MEM_mallocN(totvert * sizeof(*ccgdm->vertMap), 
"vertMap");
diff --cc source/blender/gpu/GPU_material.h
index b5906bb,5995366..dd08ed8
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@@ -308,12 -314,14 +314,20 @@@ void GPU_mist_update_values(int type, f
  void GPU_horizon_update_color(float color[3]);
  void GPU_ambient_update_color(float color[3]);
  
+ typedef struct GPUParticleInfo
+ {
+       float scalprops[4];
+       float location[3];
+       float velocity[3];
+       float angular_velocity[3];
+ } GPUParticleInfo;
+ 
 +#ifdef WITH_OPENSUBDIV
 +struct DerivedMesh;
 +void GPU_material_update_fvar_offset(GPUMaterial *gpu_material,
 +                                     struct DerivedMesh *dm);
 +#endif
 +
  #ifdef __cplusplus
  }
  #endif
diff --cc source/blender/gpu/intern/gpu_draw.c
index 3eae4d4,4e2af56..367dc66
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@@ -1705,10 -1726,16 +1757,16 @@@ int GPU_enable_material(int nr, void *a
                if (gattribs && GMS.gmatbuf[nr]) {
                        /* bind 

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