Code cleanup: simplify the DerivedMesh.drawMappedFaces interface.

This function pointer's 'setDrawOptions' parameter took a slightly
different type than the other drawing callbacks. In particular, it
could set a 'drawSmooth' value to indicate that smoothing should
always be enabled, overriding the face flag. However, all callbacks
either did not set this value, or set it unconditionally to
1. Replaced this by adding a new 'flag' parameter to drawFacesMapped,
which can be set to DM_DRAW_ALWAYS_SMOOTH where appropriate.

Also removed the 'useColors' parameter and replaced it with another
flag value, DM_DRAW_USE_COLORS.

Removed the 'wpaint__setSolidDrawOptions' callback, was only being
used to set the shading to smooth.
This commit is contained in:
Nicholas Bishop 2012-03-07 12:48:52 +00:00
parent 43711d8568
commit 925f213427
6 changed files with 48 additions and 44 deletions

@ -130,7 +130,11 @@ typedef int (*DMCompareDrawOptions)(void *userData, int cur_index, int next_inde
typedef void (*DMSetDrawInterpOptions)(void *userData, int index, float t);
typedef int (*DMSetDrawOptions)(void *userData, int index);
typedef int (*DMSetDrawOptionsTex)(struct MTFace *tface, int has_vcol, int matnr);
typedef int (*DMSetDrawOptionsShading)(void *userData, int index, int *drawSmooth_r);
typedef enum DMDrawFlag {
DM_DRAW_USE_COLORS = 1,
DM_DRAW_ALWAYS_SMOOTH = 2
} DMDrawFlag;
typedef struct DerivedMesh DerivedMesh;
struct DerivedMesh {
@ -346,10 +350,11 @@ struct DerivedMesh {
* smooth shaded.
*/
void (*drawMappedFaces)(DerivedMesh *dm,
DMSetDrawOptionsShading setDrawOptions,
DMSetDrawOptions setDrawOptions,
DMSetMaterial setMaterial,
DMCompareDrawOptions compareDrawOptions,
void *userData, int useColors);
void *userData,
DMDrawFlag flag);
/* Draw mapped faces using MTFace
* o Drawing options too complicated to enumerate, look at code.

@ -796,16 +796,17 @@ static void cdDM_drawFacesTex(DerivedMesh *dm,
}
static void cdDM_drawMappedFaces(DerivedMesh *dm,
DMSetDrawOptionsShading setDrawOptions,
DMSetDrawOptions setDrawOptions,
DMSetMaterial setMaterial,
DMCompareDrawOptions compareDrawOptions,
void *userData, int useColors)
void *userData, DMDrawFlag flag)
{
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
MVert *mv = cddm->mvert;
MFace *mf = cddm->mface;
MCol *mc;
float *nors= DM_get_tessface_data_layer(dm, CD_NORMAL);
int useColors = flag & DM_DRAW_USE_COLORS;
int i, orig, *index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
mc = DM_get_tessface_data_layer(dm, CD_ID_MCOL);
@ -821,7 +822,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
if( GPU_buffer_legacy(dm) || G.f & G_BACKBUFSEL) {
DEBUG_VBO( "Using legacy code. cdDM_drawMappedFaces\n" );
for(i = 0; i < dm->numTessFaceData; i++, mf++) {
int drawSmooth = (mf->flag & ME_SMOOTH);
int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mf->flag & ME_SMOOTH);
int draw= 1;
orig= (index==NULL) ? i : *index++;
@ -829,7 +830,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
if(orig == ORIGINDEX_NONE)
draw= setMaterial(mf->mat_nr + 1, NULL);
else if (setDrawOptions != NULL)
draw= setDrawOptions(userData, orig, &drawSmooth);
draw= setDrawOptions(userData, orig);
if(draw) {
unsigned char *cp = NULL;
@ -914,7 +915,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
//int actualFace = dm->drawObject->triangle_to_mface[i];
int actualFace = next_actualFace;
MFace *mface= mf + actualFace;
int drawSmooth= (mface->flag & ME_SMOOTH);
/*int drawSmooth= (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mface->flag & ME_SMOOTH);*/ /* UNUSED */
int draw = 1;
int flush = 0;
@ -926,7 +927,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
if(orig == ORIGINDEX_NONE)
draw= setMaterial(mface->mat_nr + 1, NULL);
else if (setDrawOptions != NULL)
draw= setDrawOptions(userData, orig, &drawSmooth);
draw= setDrawOptions(userData, orig);
/* Goal is to draw as long of a contiguous triangle
array as possible, so draw when we hit either an

@ -579,10 +579,11 @@ static void emDM_foreachMappedFaceCenter(
static void emDM_drawMappedFaces(
DerivedMesh *dm,
DMSetDrawOptionsShading setDrawOptions,
DMSetDrawOptions setDrawOptions,
DMSetMaterial setMaterial,
DMCompareDrawOptions compareDrawOptions,
void *userData, int UNUSED(useColors))
void *userData,
DMDrawFlag flag)
{
EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
BMFace *efa;
@ -615,9 +616,9 @@ static void emDM_drawMappedFaces(
int drawSmooth;
efa = l[0]->f;
drawSmooth= BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
drawSmooth= (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, BM_elem_index_get(efa), &drawSmooth);
draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, BM_elem_index_get(efa));
if (draw) {
const GLenum poly_type= GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
if (draw==2) { /* enabled with stipple */
@ -687,9 +688,9 @@ static void emDM_drawMappedFaces(
int drawSmooth;
efa = l[0]->f;
drawSmooth= BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
drawSmooth= (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, BM_elem_index_get(efa), &drawSmooth);
draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, BM_elem_index_get(efa));
if (draw) {
const GLenum poly_type= GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
if (draw==2) { /* enabled with stipple */

@ -2111,16 +2111,17 @@ static void ccgDM_drawUVEdges(DerivedMesh *dm)
}
static void ccgDM_drawMappedFaces(DerivedMesh *dm,
DMSetDrawOptionsShading setDrawOptions,
DMSetDrawOptions setDrawOptions,
DMSetMaterial setMaterial,
DMCompareDrawOptions compareDrawOptions,
void *userData, int useColors)
void *userData, DMDrawFlag flag)
{
CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
CCGSubSurf *ss = ccgdm->ss;
MCol *mcol= NULL;
int i, gridSize = ccgSubSurf_getGridSize(ss);
DMFlagMat *faceFlags = ccgdm->faceFlags;
int useColors = flag & DM_DRAW_USE_COLORS;
int gridFaces = gridSize - 1, totface;
/* currently unused -- each original face is handled separately */
@ -2142,7 +2143,8 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm,
origIndex = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
if(faceFlags) drawSmooth = (faceFlags[origIndex].flag & ME_SMOOTH);
if(flag & DM_DRAW_ALWAYS_SMOOTH) drawSmooth = 1;
else if(faceFlags) drawSmooth = (faceFlags[origIndex].flag & ME_SMOOTH);
else drawSmooth = 1;
if(mcol) {
@ -2156,7 +2158,7 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm,
if(index == ORIGINDEX_NONE)
draw= setMaterial(faceFlags ? faceFlags[origIndex].mat_nr + 1: 1, NULL); /* XXX, no faceFlags no material */
else if (setDrawOptions)
draw= setDrawOptions(userData, index, &drawSmooth);
draw= setDrawOptions(userData, index);
if (draw) {
if (draw==2) {

@ -576,7 +576,7 @@ static int draw_em_tf_mapped__set_draw(void *userData, int index)
}
}
static int wpaint__setSolidDrawOptions_material(void *userData, int index, int *drawSmooth_r)
static int wpaint__setSolidDrawOptions_material(void *userData, int index)
{
Mesh *me = (Mesh*)userData;
@ -587,17 +587,15 @@ static int wpaint__setSolidDrawOptions_material(void *userData, int index, int *
}
}
*drawSmooth_r = 1;
return 1;
}
/* when face select is on, use face hidden flag */
static int wpaint__setSolidDrawOptions_facemask(void *userData, int index, int *drawSmooth_r)
static int wpaint__setSolidDrawOptions_facemask(void *userData, int index)
{
Mesh *me = (Mesh*)userData;
MPoly *mp = &me->mpoly[index];
if (mp->flag & ME_HIDE) return 0;
*drawSmooth_r = 1;
return 1;
}
@ -783,7 +781,8 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
}
else if (draw_flags & DRAW_FACE_SELECT) {
if (ob->mode & OB_MODE_WEIGHT_PAINT)
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions_facemask, GPU_enable_material, NULL, me, 1);
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions_facemask, GPU_enable_material, NULL, me,
DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
else
dm->drawMappedFacesTex(dm, me->mpoly ? draw_tface_mapped__set_draw : NULL, NULL, me);
}
@ -940,10 +939,8 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o
if (ob->mode & OB_MODE_WEIGHT_PAINT) {
/* weight paint mode exception */
int useColors= 1;
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions_material,
GPU_enable_material, NULL, ob->data, useColors);
GPU_enable_material, NULL, ob->data, DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
}
else {
Mesh *me= ob->data;

@ -2482,7 +2482,7 @@ static void draw_dm_edges_sharp(BMEditMesh *em, DerivedMesh *dm)
/* Draw faces with color set based on selection
* 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))
static int draw_dm_faces_sel__setDrawOptions(void *userData, int index)
{
drawDMFacesSel_userData * data = userData;
BMFace *efa = EDBM_get_face_for_index(data->em, index);
@ -2965,7 +2965,7 @@ static void draw_em_indices(BMEditMesh *em)
}
}
static int draw_em_fancy__setFaceOpts(void *userData, int index, int *UNUSED(drawSmooth_r))
static int draw_em_fancy__setFaceOpts(void *userData, int index)
{
BMFace *efa = EDBM_get_face_for_index(userData, index);
@ -3189,12 +3189,6 @@ static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
}
}
static int wpaint__setSolidDrawOptions(void *UNUSED(userData), int UNUSED(index), int *drawSmooth_r)
{
*drawSmooth_r = 1;
return 1;
}
static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
{
Object *ob= base->object;
@ -3283,7 +3277,8 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
/* weight paint in solid mode, special case. focus on making the weights clear
* rather than the shading, this is also forced in wire view */
GPU_enable_material(0, NULL);
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, GPU_enable_material, NULL, me->mpoly, 1);
dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, me->mpoly,
DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
bglPolygonOffset(rv3d->dist, 1.0);
glDepthMask(0); // disable write in zbuffer, selected edge wires show better
@ -3336,7 +3331,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, NULL, 1);
dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, NULL, DM_DRAW_USE_COLORS);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
@ -3411,7 +3406,8 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, GPU_enable_material, NULL, me->mpoly, 1);
dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, me->mpoly,
DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
@ -3419,10 +3415,12 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
}
else if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_TEXTURE_PAINT)) {
if (me->mloopcol)
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, GPU_enable_material, NULL, NULL, 1);
dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, NULL,
DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
else {
glColor3f(1.0f, 1.0f, 1.0f);
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, GPU_enable_material, NULL, NULL, 0);
dm->drawMappedFaces(dm, NULL, GPU_enable_material, NULL, NULL,
DM_DRAW_ALWAYS_SMOOTH);
}
}
}
@ -7147,7 +7145,7 @@ static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *dm, int offset)
dm->drawMappedEdges(dm, bbs_mesh_wire__setDrawOptions, ptrs);
}
static int bbs_mesh_solid__setSolidDrawOptions(void *userData, int index, int *UNUSED(drawSmooth_r))
static int bbs_mesh_solid__setSolidDrawOptions(void *userData, int index)
{
BMFace *efa = EDBM_get_face_for_index(((void**)userData)[0], index);
@ -7198,13 +7196,13 @@ static void bbs_mesh_solid_EM(BMEditMesh *em, Scene *scene, View3D *v3d,
}
}
static int bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index, int *UNUSED(drawSmooth_r))
static int bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index)
{
WM_set_framebuffer_index_color(index+1);
return 1;
}
static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r))
static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index)
{
Mesh *me = userData;
@ -7218,7 +7216,7 @@ static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUS
}
// must have called WM_set_framebuffer_index_color beforehand
static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r))
static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index)
{
Mesh *me = userData;