Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2013-10-17 18:04:10 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2013-10-17 18:04:10 +0400
commitabee8a871718a99708100c0ad591b76d8f5767da (patch)
treeb07de49fd8f4a75d53cc64480430fa25f0cbe10b
parent31b38a6736af734d66f09caf6298d94f138b55f9 (diff)
Fix #37109: missing cycles texture display in edit mode.
My previous fix for uninitialized texture coordinates was not working well, and in fact there was a bigger issue with GLSL drawing and missing attributes with immediate draw mode. Now it will explicitly pass zero rather than having it use whatever value was set last.
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c71
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c140
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c82
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c110
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c2
5 files changed, 241 insertions, 164 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 368c1e517ef..884e7a813a8 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2859,14 +2859,19 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
else
layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV);
- if (layer != -1) {
- a = attribs->tottface++;
+ a = attribs->tottface++;
+ if (layer != -1) {
attribs->tface[a].array = tfdata->layers[layer].data;
attribs->tface[a].em_offset = ldata->layers[layer].offset;
- attribs->tface[a].gl_index = gattribs->layer[b].glindex;
- attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
}
+ else {
+ attribs->tface[a].array = NULL;
+ attribs->tface[a].em_offset = -1;
+ }
+
+ attribs->tface[a].gl_index = gattribs->layer[b].glindex;
+ attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
}
else {
if (gattribs->layer[b].name[0])
@@ -2875,14 +2880,19 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
else
layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE);
- if (layer != -1) {
- a = attribs->tottface++;
+ a = attribs->tottface++;
+ if (layer != -1) {
attribs->tface[a].array = tfdata->layers[layer].data;
attribs->tface[a].em_offset = tfdata->layers[layer].offset;
- attribs->tface[a].gl_index = gattribs->layer[b].glindex;
- attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
}
+ else {
+ attribs->tface[a].array = NULL;
+ attribs->tface[a].em_offset = -1;
+ }
+
+ attribs->tface[a].gl_index = gattribs->layer[b].glindex;
+ attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
}
}
else if (gattribs->layer[b].type == CD_MCOL) {
@@ -2896,14 +2906,19 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
else
layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL);
- if (layer != -1) {
- a = attribs->totmcol++;
+ a = attribs->totmcol++;
+ if (layer != -1) {
attribs->mcol[a].array = tfdata->layers[layer].data;
/* odd, store the offset for a different layer type here, but editmode draw code expects it */
attribs->mcol[a].em_offset = ldata->layers[layer].offset;
- attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
}
+ else {
+ attribs->mcol[a].array = NULL;
+ attribs->mcol[a].em_offset = -1;
+ }
+
+ attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
}
else {
/* vertex colors */
@@ -2913,40 +2928,54 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
else
layer = CustomData_get_active_layer_index(tfdata, CD_MCOL);
- if (layer != -1) {
- a = attribs->totmcol++;
+ a = attribs->totmcol++;
+ if (layer != -1) {
attribs->mcol[a].array = tfdata->layers[layer].data;
/* odd, store the offset for a different layer type here, but editmode draw code expects it */
attribs->mcol[a].em_offset = tfdata->layers[layer].offset;
- attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
}
+ else {
+ attribs->mcol[a].array = NULL;
+ attribs->mcol[a].em_offset = -1;
+ }
+
+ attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
}
}
else if (gattribs->layer[b].type == CD_TANGENT) {
/* tangents */
layer = CustomData_get_layer_index(fdata, CD_TANGENT);
- if (layer != -1) {
- attribs->tottang = 1;
+ attribs->tottang = 1;
+ if (layer != -1) {
attribs->tang.array = fdata->layers[layer].data;
attribs->tang.em_offset = fdata->layers[layer].offset;
- attribs->tang.gl_index = gattribs->layer[b].glindex;
}
+ else {
+ attribs->tang.array = NULL;
+ attribs->tang.em_offset = -1;
+ }
+
+ attribs->tang.gl_index = gattribs->layer[b].glindex;
}
else if (gattribs->layer[b].type == CD_ORCO) {
/* original coordinates */
layer = CustomData_get_layer_index(vdata, CD_ORCO);
+ attribs->totorco = 1;
if (layer != -1) {
- attribs->totorco = 1;
-
attribs->orco.array = vdata->layers[layer].data;
attribs->orco.em_offset = vdata->layers[layer].offset;
- attribs->orco.gl_index = gattribs->layer[b].glindex;
- attribs->orco.gl_texco = gattribs->layer[b].gltexco;
}
+ else {
+ attribs->orco.array = NULL;
+ attribs->orco.em_offset = -1;
+ }
+
+ attribs->orco.gl_index = gattribs->layer[b].glindex;
+ attribs->orco.gl_texco = gattribs->layer[b].gltexco;
}
}
}
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 1bc12cffe7b..309eb68ffc4 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1063,37 +1063,57 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm,
static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int a, int index, int vert, int smoothnormal)
{
+ const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
int b;
/* orco texture coordinates */
if (attribs->totorco) {
+ const float (*array)[3] = attribs->orco.array;
+ const float *orco = (array) ? array[index] : zero;
+
if (attribs->orco.gl_texco)
- glTexCoord3fv(attribs->orco.array[index]);
+ glTexCoord3fv(orco);
else
- glVertexAttrib3fvARB(attribs->orco.gl_index, attribs->orco.array[index]);
+ glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
}
/* uv texture coordinates */
for (b = 0; b < attribs->tottface; b++) {
- MTFace *tf = &attribs->tface[b].array[a];
+ const float *uv;
+
+ if (attribs->tface[b].array) {
+ MTFace *tf = &attribs->tface[b].array[a];
+ uv = tf->uv[vert];
+ }
+ else {
+ uv = zero;
+ }
if (attribs->tface[b].gl_texco)
- glTexCoord2fv(tf->uv[vert]);
+ glTexCoord2fv(uv);
else
- glVertexAttrib2fvARB(attribs->tface[b].gl_index, tf->uv[vert]);
+ glVertexAttrib2fvARB(attribs->tface[b].gl_index, uv);
}
/* vertex colors */
for (b = 0; b < attribs->totmcol; b++) {
- MCol *cp = &attribs->mcol[b].array[a * 4 + vert];
GLubyte col[4];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+
+ if (attribs->mcol[b].array) {
+ MCol *cp = &attribs->mcol[b].array[a * 4 + vert];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ }
+ else {
+ col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0;
+ }
+
glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col);
}
/* tangent for normal mapping */
if (attribs->tottang) {
- float *tang = attribs->tang.array[a * 4 + vert];
+ const float (*array)[4] = attribs->tang.array;
+ const float *tang = (array) ? array[a * 4 + vert] : zero;
glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
}
@@ -1264,25 +1284,29 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
if (do_draw) {
DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
- if (attribs.totorco) {
+ if (attribs.totorco && attribs.orco.array) {
datatypes[numdata].index = attribs.orco.gl_index;
datatypes[numdata].size = 3;
datatypes[numdata].type = GL_FLOAT;
numdata++;
}
for (b = 0; b < attribs.tottface; b++) {
- datatypes[numdata].index = attribs.tface[b].gl_index;
- datatypes[numdata].size = 2;
- datatypes[numdata].type = GL_FLOAT;
- numdata++;
+ if (attribs.tface[b].array) {
+ datatypes[numdata].index = attribs.tface[b].gl_index;
+ datatypes[numdata].size = 2;
+ datatypes[numdata].type = GL_FLOAT;
+ numdata++;
+ }
}
for (b = 0; b < attribs.totmcol; b++) {
- datatypes[numdata].index = attribs.mcol[b].gl_index;
- datatypes[numdata].size = 4;
- datatypes[numdata].type = GL_UNSIGNED_BYTE;
- numdata++;
+ if (attribs.mcol[b].array) {
+ datatypes[numdata].index = attribs.mcol[b].gl_index;
+ datatypes[numdata].size = 4;
+ datatypes[numdata].type = GL_UNSIGNED_BYTE;
+ numdata++;
+ }
}
- if (attribs.tottang) {
+ if (attribs.tottang && attribs.tang.array) {
datatypes[numdata].index = attribs.tang.gl_index;
datatypes[numdata].size = 4;
datatypes[numdata].type = GL_FLOAT;
@@ -1315,34 +1339,38 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
if (do_draw && numdata != 0) {
offset = 0;
- if (attribs.totorco) {
+ if (attribs.totorco && attribs.orco.array) {
copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v1]);
copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v2]);
copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v3]);
offset += sizeof(float) * 3;
}
for (b = 0; b < attribs.tottface; b++) {
- MTFace *tf = &attribs.tface[b].array[a];
- copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[0]);
- copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[1]);
+ if (attribs.tface[b].array) {
+ MTFace *tf = &attribs.tface[b].array[a];
+ copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[0]);
+ copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[1]);
- copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[2]);
- offset += sizeof(float) * 2;
+ copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[2]);
+ offset += sizeof(float) * 2;
+ }
}
for (b = 0; b < attribs.totmcol; b++) {
- MCol *cp = &attribs.mcol[b].array[a * 4 + 0];
- GLubyte col[4];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
- copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col);
- cp = &attribs.mcol[b].array[a * 4 + 1];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
- copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col);
- cp = &attribs.mcol[b].array[a * 4 + 2];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
- copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col);
- offset += sizeof(unsigned char) * 4;
+ if (attribs.mcol[b].array) {
+ MCol *cp = &attribs.mcol[b].array[a * 4 + 0];
+ GLubyte col[4];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col);
+ cp = &attribs.mcol[b].array[a * 4 + 1];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col);
+ cp = &attribs.mcol[b].array[a * 4 + 2];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col);
+ offset += sizeof(unsigned char) * 4;
+ }
}
- if (attribs.tottang) {
+ if (attribs.tottang && attribs.tang.array) {
float *tang = attribs.tang.array[a * 4 + 0];
copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang);
tang = attribs.tang.array[a * 4 + 1];
@@ -1357,33 +1385,37 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
if (mface->v4) {
if (do_draw && numdata != 0) {
offset = 0;
- if (attribs.totorco) {
+ if (attribs.totorco && attribs.orco.array) {
copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v3]);
copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v4]);
copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v1]);
offset += sizeof(float) * 3;
}
for (b = 0; b < attribs.tottface; b++) {
- MTFace *tf = &attribs.tface[b].array[a];
- copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[2]);
- copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[3]);
- copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[0]);
- offset += sizeof(float) * 2;
+ if (attribs.tface[b].array) {
+ MTFace *tf = &attribs.tface[b].array[a];
+ copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[2]);
+ copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[3]);
+ copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[0]);
+ offset += sizeof(float) * 2;
+ }
}
for (b = 0; b < attribs.totmcol; b++) {
- MCol *cp = &attribs.mcol[b].array[a * 4 + 2];
- GLubyte col[4];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
- copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col);
- cp = &attribs.mcol[b].array[a * 4 + 3];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
- copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col);
- cp = &attribs.mcol[b].array[a * 4 + 0];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
- copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col);
- offset += sizeof(unsigned char) * 4;
+ if (attribs.mcol[b].array) {
+ MCol *cp = &attribs.mcol[b].array[a * 4 + 2];
+ GLubyte col[4];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col);
+ cp = &attribs.mcol[b].array[a * 4 + 3];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col);
+ cp = &attribs.mcol[b].array[a * 4 + 0];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col);
+ offset += sizeof(unsigned char) * 4;
+ }
}
- if (attribs.tottang) {
+ if (attribs.tottang && attribs.tang.array) {
float *tang = attribs.tang.array[a * 4 + 2];
copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang);
tang = attribs.tang.array[a * 4 + 3];
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index caa5bf90584..f71bc83f5d3 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -888,23 +888,47 @@ static void emdm_pass_attrib_vertex_glsl(DMVertexAttribs *attribs, BMLoop *loop,
{
BMVert *eve = loop->v;
int i;
+ const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
if (attribs->totorco) {
- const float *orco = attribs->orco.array[BM_elem_index_get(eve)];
- glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
+ int index = BM_elem_index_get(eve);
+ const float *orco = (attribs->orco.array) ? attribs->orco.array[index] : zero;
+
+ if (attribs->orco.gl_texco)
+ glTexCoord3fv(orco);
+ else
+ glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
}
for (i = 0; i < attribs->tottface; i++) {
- const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
- glVertexAttrib2fvARB(attribs->tface[i].gl_index, luv->uv);
+ const float *uv;
+
+ if(attribs->tface[i].em_offset != -1) {
+ const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
+ uv = luv->uv;
+ }
+ else {
+ uv = zero;
+ }
+
+ if (attribs->tface[i].gl_texco)
+ glTexCoord2fv(uv);
+ else
+ glVertexAttrib2fvARB(attribs->tface[i].gl_index, uv);
}
for (i = 0; i < attribs->totmcol; i++) {
- const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset);
GLubyte col[4];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ if(attribs->mcol[i].em_offset != -1) {
+ const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset);
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ }
+ else {
+ col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0;
+ }
glVertexAttrib4ubvARB(attribs->mcol[i].gl_index, col);
}
if (attribs->tottang) {
- const float *tang = attribs->tang.array[i * 4 + index_in_face];
+ int index = i * 4 + index_in_face;
+ const float *tang = (attribs->tang.array) ? attribs->tang.array[index] : zero;
glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
}
}
@@ -1020,38 +1044,6 @@ static void emDM_drawFacesGLSL(DerivedMesh *dm,
dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
}
-/* emdm_pass_attrib_vertex_glsl's note about em_offset use applies here */
-static void emdm_pass_attrib_vertex_mat(DMVertexAttribs *attribs, BMLoop *loop, int index_in_face)
-{
- BMVert *eve = loop->v;
- int i;
-
- if (attribs->totorco) {
- float *orco = attribs->orco.array[BM_elem_index_get(eve)];
- if (attribs->orco.gl_texco)
- glTexCoord3fv(orco);
- else
- glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
- }
- for (i = 0; i < attribs->tottface; i++) {
- const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
- if (attribs->tface[i].gl_texco)
- glTexCoord2fv(luv->uv);
- else
- glVertexAttrib2fvARB(attribs->tface[i].gl_index, luv->uv);
- }
- for (i = 0; i < attribs->totmcol; i++) {
- const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset);
- GLubyte col[4];
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
- glVertexAttrib4ubvARB(attribs->mcol[i].gl_index, col);
- }
- if (attribs->tottang) {
- float *tang = attribs->tang.array[i * 4 + index_in_face];
- glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
- }
-}
-
static void emDM_drawMappedFacesMat(DerivedMesh *dm,
void (*setMaterial)(void *userData, int, void *attribs),
bool (*setFace)(void *userData, int index), void *userData)
@@ -1105,21 +1097,21 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm,
if (vertexCos) glNormal3fv(polyNos[BM_elem_index_get(efa)]);
else glNormal3fv(efa->no);
- emdm_pass_attrib_vertex_mat(&attribs, ltri[0], 0);
+ emdm_pass_attrib_vertex_glsl(&attribs, ltri[0], 0);
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
else glVertex3fv(ltri[0]->v->co);
- emdm_pass_attrib_vertex_mat(&attribs, ltri[1], 1);
+ emdm_pass_attrib_vertex_glsl(&attribs, ltri[1], 1);
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
else glVertex3fv(ltri[1]->v->co);
- emdm_pass_attrib_vertex_mat(&attribs, ltri[2], 2);
+ emdm_pass_attrib_vertex_glsl(&attribs, ltri[2], 2);
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
else glVertex3fv(ltri[2]->v->co);
}
else {
- emdm_pass_attrib_vertex_mat(&attribs, ltri[0], 0);
+ emdm_pass_attrib_vertex_glsl(&attribs, ltri[0], 0);
if (vertexCos) {
glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
@@ -1129,7 +1121,7 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm,
glVertex3fv(ltri[0]->v->co);
}
- emdm_pass_attrib_vertex_mat(&attribs, ltri[1], 1);
+ emdm_pass_attrib_vertex_glsl(&attribs, ltri[1], 1);
if (vertexCos) {
glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
@@ -1139,7 +1131,7 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm,
glVertex3fv(ltri[1]->v->co);
}
- emdm_pass_attrib_vertex_mat(&attribs, ltri[2], 2);
+ emdm_pass_attrib_vertex_glsl(&attribs, ltri[2], 2);
if (vertexCos) {
glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index ac11a012347..176e79aff36 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -1817,6 +1817,64 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
}
}
+static void ccgdm_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert)
+{
+ const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ int b;
+
+ /* orco texture coordinates */
+ if (attribs->totorco) {
+ const float (*array)[3] = attribs->orco.array;
+ const float *orco = (array) ? array[index] : zero;
+
+ if (attribs->orco.gl_texco)
+ glTexCoord3fv(orco);
+ else
+ glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
+ }
+
+ /* uv texture coordinates */
+ for (b = 0; b < attribs->tottface; b++) {
+ const float *uv;
+
+ if (attribs->tface[b].array) {
+ MTFace *tf = &attribs->tface[b].array[a];
+ uv = tf->uv[vert];
+ }
+ else {
+ uv = zero;
+ }
+
+ if (attribs->tface[b].gl_texco)
+ glTexCoord2fv(uv);
+ else
+ glVertexAttrib2fvARB(attribs->tface[b].gl_index, uv);
+ }
+
+ /* vertex colors */
+ for (b = 0; b < attribs->totmcol; b++) {
+ GLubyte col[4];
+
+ if (attribs->mcol[b].array) {
+ MCol *cp = &attribs->mcol[b].array[a * 4 + vert];
+ col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+ }
+ else {
+ col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0;
+ }
+
+ glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col);
+ }
+
+ /* tangent for normal mapping */
+ if (attribs->tottang) {
+ const float (*array)[4] = attribs->tang.array;
+ const float *tang = (array) ? array[a * 4 + vert] : zero;
+
+ glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
+ }
+}
+
/* Only used by non-editmesh types */
static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
DMSetMaterial setMaterial,
@@ -1833,7 +1891,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
int gridFaces = gridSize - 1;
int edgeSize = ccgSubSurf_getEdgeSize(ss);
DMFlagMat *faceFlags = ccgdm->faceFlags;
- int a, b, i, do_draw, numVerts, matnr, new_matnr, totface;
+ int a, i, do_draw, numVerts, matnr, new_matnr, totface;
CCG_key_top_level(&key, ss);
ccgdm_pbvh_update(ccgdm);
@@ -1842,25 +1900,11 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
matnr = -1;
#define PASSATTRIB(dx, dy, vert) { \
- if (attribs.totorco) { \
+ if (attribs.totorco) \
index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
- glVertexAttrib3fvARB(attribs.orco.gl_index, \
- attribs.orco.array[index]); \
- } \
- for (b = 0; b < attribs.tottface; b++) { \
- MTFace *tf = &attribs.tface[b].array[a]; \
- glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \
- } \
- for (b = 0; b < attribs.totmcol; b++) { \
- MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \
- GLubyte col[4]; \
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \
- glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \
- } \
- if (attribs.tottang) { \
- float *tang = attribs.tang.array[a * 4 + vert]; \
- glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \
- } \
+ else \
+ index = 0; \
+ ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \
} (void)0
totface = ccgSubSurf_getNumFaces(ss);
@@ -1992,31 +2036,11 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm,
matnr = -1;
#define PASSATTRIB(dx, dy, vert) { \
- if (attribs.totorco) { \
+ if (attribs.totorco) \
index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
- if (attribs.orco.gl_texco) \
- glTexCoord3fv(attribs.orco.array[index]); \
- else \
- glVertexAttrib3fvARB(attribs.orco.gl_index, \
- attribs.orco.array[index]); \
- } \
- for (b = 0; b < attribs.tottface; b++) { \
- MTFace *tf = &attribs.tface[b].array[a]; \
- if (attribs.tface[b].gl_texco) \
- glTexCoord2fv(tf->uv[vert]); \
- else \
- glVertexAttrib2fvARB(attribs.tface[b].gl_index, tf->uv[vert]); \
- } \
- for (b = 0; b < attribs.totmcol; b++) { \
- MCol *cp = &attribs.mcol[b].array[a * 4 + vert]; \
- GLubyte col[4]; \
- col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a; \
- glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, col); \
- } \
- if (attribs.tottang) { \
- float *tang = attribs.tang.array[a * 4 + vert]; \
- glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \
- } \
+ else \
+ index = 0; \
+ ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \
} (void)0
totface = ccgSubSurf_getNumFaces(ss);
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index d169fc58260..76fcf70a627 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -982,7 +982,7 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d,
GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
- if (glsl || picking || !CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) {
+ if (glsl || picking) {
/* draw glsl or solid */
dm->drawMappedFacesMat(dm,
tex_mat_set_material_cb,