Fixed crash caused by recent VBO's changes

Crash was caused by non-initialized original index passing to compareDrawOptions
callback. Due to in some cases it's enough to know indices of faces in final DM
(like for comparing if the same texture used for mesh drawing) assume this
callback receives index in final DM and if it's needed it will make conversion
to original index itself.

This should help reaching extra speed if textured object is affected by
bevel modifiers, i.e.
This commit is contained in:
2011-12-01 18:26:48 +00:00
parent 9b931aa0db
commit c21f19374b
3 changed files with 23 additions and 29 deletions

View File

@@ -804,15 +804,9 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
flush= !flag || i == tottri - 1;
if(!flush && compareDrawOptions) {
int next_orig= (index==NULL) ? next_actualFace : index[next_actualFace];
if(orig==ORIGINDEX_NONE || next_orig==ORIGINDEX_NONE) {
flush= 1;
} else {
/* also compare draw options and flush buffer if they're different
need for face selection highlight in edit mode */
flush|= compareDrawOptions(userData, orig, next_orig) == 0;
}
/* also compare draw options and flush buffer if they're different
need for face selection highlight in edit mode */
flush|= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
}
if(flush) {
@@ -990,15 +984,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
flush|= mf[actualFace].mat_nr != mf[next_actualFace].mat_nr;
if(!flush && compareDrawOptions) {
int next_orig= (index==NULL) ? next_actualFace : index[next_actualFace];
if(orig==ORIGINDEX_NONE || next_orig==ORIGINDEX_NONE) {
flush= 1;
} else {
/* also compare draw options and flush buffer if they're different
need for face selection highlight in edit mode */
flush|= compareDrawOptions(userData, orig, next_orig) == 0;
}
flush|= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
}
if(flush) {

View File

@@ -631,14 +631,14 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
static int compareDrawOptions(void *userData, int cur_index, int next_index)
{
Mesh *me= (Mesh*) userData;
MFace *mf= CustomData_get_layer(&me->fdata, CD_MFACE);
MTFace *tf= CustomData_get_layer(&me->fdata, CD_MTFACE);
DerivedMesh *dm= (DerivedMesh*) userData;
MFace *mf = DM_get_face_data_layer(dm, CD_MFACE);
MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
if(mf[cur_index].mat_nr != mf[next_index].mat_nr)
if(mf && mf[cur_index].mat_nr != mf[next_index].mat_nr)
return 0;
if(tf[cur_index].tpage != tf[next_index].tpage)
if(tf && tf[cur_index].tpage != tf[next_index].tpage)
return 0;
return 1;
@@ -683,7 +683,7 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
if(!CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL))
add_tface_color_layer(dm);
dm->drawFacesTex(dm, draw_tface__set_draw, compareDrawOptions, ob->data);
dm->drawFacesTex(dm, draw_tface__set_draw, compareDrawOptions, dm);
}
}

View File

@@ -2323,7 +2323,7 @@ static void draw_dm_edges_sharp(DerivedMesh *dm)
* return 2 for the active face so it renders with stipple enabled */
static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNUSED(drawSmooth_r))
{
struct { unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
struct { DerivedMesh *dm; unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
EditFace *efa = EM_get_face_for_index(index);
unsigned char *col;
@@ -2343,11 +2343,18 @@ static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNU
static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int next_index)
{
struct { unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
EditFace *efa = EM_get_face_for_index(index);
EditFace *next_efa = EM_get_face_for_index(next_index);
struct { DerivedMesh *dm; unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
int *orig_index= DM_get_face_data_layer(data->dm, CD_ORIGINDEX);
EditFace *efa;
EditFace *next_efa;
unsigned char *col, *next_col;
if(!orig_index)
return 0;
efa= EM_get_face_for_index(orig_index[index]);
next_efa= EM_get_face_for_index(orig_index[next_index]);
if(efa == next_efa)
return 1;
@@ -2366,7 +2373,8 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
/* also draws the active face */
static void draw_dm_faces_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol, unsigned char *actCol, EditFace *efa_act)
{
struct { unsigned char *cols[3]; EditFace *efa_act; } data;
struct { DerivedMesh *dm; unsigned char *cols[3]; EditFace *efa_act; } data;
data.dm= dm;
data.cols[0] = baseCol;
data.cols[1] = selCol;
data.cols[2] = actCol;