Fix crash with texture draw in edit mode after commit 45672.

Don't create empty tesselated faces layers in edit derivedmesh, these are
being created on the fly so this will conflicted, and use loop data for
opengl attributes for edit derivedmesh drawing.
This commit is contained in:
Brecht Van Lommel
2012-04-17 11:02:32 +00:00
parent 09f722740f
commit 3d2f1fd8f9
2 changed files with 58 additions and 42 deletions

View File

@@ -2757,7 +2757,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
fdata = tfdata = dm->getTessFaceDataLayout(dm);
/* calc auto bump scale if necessary */
if (dm->auto_bump_scale<=0.0f)
if (dm->auto_bump_scale <= 0.0f)
DM_calc_auto_bump_scale(dm);
/* add a tangent layer if necessary */
@@ -2769,58 +2769,76 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
for (b = 0; b < gattribs->totlayer; b++) {
if (gattribs->layer[b].type == CD_MTFACE) {
/* uv coordinates */
if (gattribs->layer[b].name[0])
layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE,
gattribs->layer[b].name);
else
layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE);
if(dm->type == DM_TYPE_EDITBMESH) {
/* exception .. */
CustomData *ldata = dm->getLoopDataLayout(dm);
if (layer != -1) {
a = attribs->tottface++;
attribs->tface[a].array = tfdata->layers[layer].data;
attribs->tface[a].emOffset = tfdata->layers[layer].offset;
attribs->tface[a].glIndex = gattribs->layer[b].glindex;
attribs->tface[a].glTexco = gattribs->layer[b].gltexco;
}
/* BMESH_TODO - BMESH ONLY, may need to get this working?, otherwise remove */
#if 0
else {
int player;
CustomData *pdata = dm->getPolyDataLayout(dm);
if (gattribs->layer[b].name[0])
player = CustomData_get_named_layer_index(pdata, CD_MTEXPOLY,
layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV,
gattribs->layer[b].name);
else
player = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY);
if (player != -1) {
layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV);
if (layer != -1) {
a = attribs->tottface++;
attribs->tface[a].array = NULL;
attribs->tface[a].emOffset = pdata->layers[layer].offset;
attribs->tface[a].array = tfdata->layers[layer].data;
attribs->tface[a].emOffset = tfdata->layers[layer].offset;
attribs->tface[a].glIndex = gattribs->layer[b].glindex;
attribs->tface[a].glTexco = gattribs->layer[b].gltexco;
}
}
else {
if (gattribs->layer[b].name[0])
layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE,
gattribs->layer[b].name);
else
layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE);
if (layer != -1) {
a = attribs->tottface++;
attribs->tface[a].array = tfdata->layers[layer].data;
attribs->tface[a].emOffset = tfdata->layers[layer].offset;
attribs->tface[a].glIndex = gattribs->layer[b].glindex;
attribs->tface[a].glTexco = gattribs->layer[b].gltexco;
}
}
#endif
}
else if (gattribs->layer[b].type == CD_MCOL) {
/* vertex colors */
if (gattribs->layer[b].name[0])
layer = CustomData_get_named_layer_index(tfdata, CD_MCOL,
gattribs->layer[b].name);
else
layer = CustomData_get_active_layer_index(tfdata, CD_MCOL);
if(dm->type == DM_TYPE_EDITBMESH) {
/* exception .. */
CustomData *ldata = dm->getLoopDataLayout(dm);
if (layer != -1) {
a = attribs->totmcol++;
if (gattribs->layer[b].name[0])
layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL,
gattribs->layer[b].name);
else
layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL);
attribs->mcol[a].array = tfdata->layers[layer].data;
attribs->mcol[a].emOffset = tfdata->layers[layer].offset;
attribs->mcol[a].glIndex = gattribs->layer[b].glindex;
if (layer != -1) {
a = attribs->totmcol++;
attribs->mcol[a].array = tfdata->layers[layer].data;
attribs->mcol[a].emOffset = tfdata->layers[layer].offset;
attribs->mcol[a].glIndex = gattribs->layer[b].glindex;
}
}
else {
/* vertex colors */
if (gattribs->layer[b].name[0])
layer = CustomData_get_named_layer_index(tfdata, CD_MCOL,
gattribs->layer[b].name);
else
layer = CustomData_get_active_layer_index(tfdata, CD_MCOL);
if (layer != -1) {
a = attribs->totmcol++;
attribs->mcol[a].array = tfdata->layers[layer].data;
attribs->mcol[a].emOffset = tfdata->layers[layer].offset;
attribs->mcol[a].glIndex = gattribs->layer[b].glindex;
}
}
}
else if (gattribs->layer[b].type == CD_TANGENT) {

View File

@@ -1628,8 +1628,6 @@ DerivedMesh *getEditDerivedBMesh(
DM_init((DerivedMesh*)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert,
em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface);
CustomData_from_bmeshpoly(&bmdm->dm.faceData, &em->bm->pdata, &em->bm->ldata, 0);
bmdm->dm.getVertCos = emDM_getVertCos;
bmdm->dm.getMinMax = emDM_getMinMax;