Immediate Mode / DerivedMesh: Handle UV Shadow

This commit is contained in:
Dalai Felinto
2017-04-04 12:26:57 +02:00
parent 0e95270eb7
commit c87bfb1f7d
5 changed files with 8 additions and 128 deletions

View File

@@ -387,9 +387,6 @@ struct DerivedMesh {
/** Draw all vertices as bgl points (no options) */
void (*drawVerts)(DerivedMesh *dm);
/** Draw edges in the UV mesh (if exists) */
void (*drawUVEdges)(DerivedMesh *dm);
/** Draw all edges as lines (no options)
*
* Also called for *final* editmode DerivedMeshes

View File

@@ -372,36 +372,6 @@ static void cdDM_drawVerts(DerivedMesh *dm)
GPU_buffers_unbind();
}
static void cdDM_drawUVEdges(DerivedMesh *dm)
{
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
const MPoly *mpoly = cddm->mpoly;
int totpoly = dm->getNumPolys(dm);
int prevstart = 0;
bool prevdraw = true;
int curpos = 0;
int i;
GPU_uvedge_setup(dm);
for (i = 0; i < totpoly; i++, mpoly++) {
const bool draw = (mpoly->flag & ME_HIDE) == 0;
if (prevdraw != draw) {
if (prevdraw && (curpos != prevstart)) {
glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
}
prevstart = curpos;
}
curpos += 2 * mpoly->totloop;
prevdraw = draw;
}
if (prevdraw && (curpos != prevstart)) {
glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
}
GPU_buffers_unbind();
}
static void cdDM_drawEdges(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEdges)
{
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
@@ -2008,7 +1978,6 @@ static CDDerivedMesh *cdDM_create(const char *desc)
dm->drawVerts = cdDM_drawVerts;
dm->drawUVEdges = cdDM_drawUVEdges;
dm->drawEdges = cdDM_drawEdges;
dm->drawLooseEdges = cdDM_drawLooseEdges;
dm->drawMappedEdges = cdDM_drawMappedEdges;

View File

@@ -810,39 +810,6 @@ static void emDM_drawMappedEdgesInterp(
}
}
static void emDM_drawUVEdges(DerivedMesh *dm)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMesh *bm = bmdm->em->bm;
BMFace *efa;
BMIter iter;
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
if (UNLIKELY(cd_loop_uv_offset == -1)) {
return;
}
glBegin(GL_LINES);
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
BMLoop *l_iter, *l_first;
const float *uv, *uv_prev;
if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
continue;
l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
uv_prev = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter->prev, cd_loop_uv_offset))->uv;
do {
uv = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset))->uv;
glVertex2fv(uv);
glVertex2fv(uv_prev);
uv_prev = uv;
} while ((l_iter = l_iter->next) != l_first);
}
glEnd();
}
static void emDM_foreachMappedLoop(
DerivedMesh *dm,
void (*func)(void *userData, int vertex_index, int face_index, const float co[3], const float no[3]),
@@ -2280,7 +2247,6 @@ DerivedMesh *getEditDerivedBMesh(
bmdm->dm.drawMappedFacesMat = emDM_drawMappedFacesMat;
bmdm->dm.drawFacesTex = emDM_drawFacesTex;
bmdm->dm.drawFacesGLSL = emDM_drawFacesGLSL;
bmdm->dm.drawUVEdges = emDM_drawUVEdges;
bmdm->dm.release = emDM_release;

View File

@@ -3634,36 +3634,6 @@ static void ccgDM_drawMappedFacesTex(DerivedMesh *dm,
ccgDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData, flag);
}
/* same as cdDM_drawUVEdges */
static void ccgDM_drawUVEdges(DerivedMesh *dm)
{
MPoly *mpoly = dm->getPolyArray(dm);
int totpoly = dm->getNumPolys(dm);
int prevstart = 0;
bool prevdraw = true;
int curpos = 0;
int i;
GPU_uvedge_setup(dm);
for (i = 0; i < totpoly; i++, mpoly++) {
const bool draw = (mpoly->flag & ME_HIDE) == 0;
if (prevdraw != draw) {
if (prevdraw && (curpos != prevstart)) {
glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
}
prevstart = curpos;
}
curpos += 2 * mpoly->totloop;
prevdraw = draw;
}
if (prevdraw && (curpos != prevstart)) {
glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
}
GPU_buffers_unbind();
}
static void ccgDM_drawMappedFaces(DerivedMesh *dm,
DMSetDrawOptions setDrawOptions,
DMSetMaterial setMaterial,
@@ -4589,7 +4559,6 @@ static void set_default_ccgdm_callbacks(CCGDerivedMesh *ccgdm)
ccgdm->dm.drawMappedFacesTex = ccgDM_drawMappedFacesTex;
ccgdm->dm.drawMappedFacesGLSL = ccgDM_drawMappedFacesGLSL;
ccgdm->dm.drawMappedFacesMat = ccgDM_drawMappedFacesMat;
ccgdm->dm.drawUVEdges = ccgDM_drawUVEdges;
ccgdm->dm.drawMappedEdgesInterp = ccgDM_drawMappedEdgesInterp;
ccgdm->dm.drawMappedEdges = ccgDM_drawMappedEdges;

View File

@@ -48,6 +48,7 @@
#include "BKE_DerivedMesh.h"
#include "BKE_editmesh.h"
#include "BKE_layer.h"
#include "BKE_material.h"
#include "BKE_scene.h"
@@ -184,19 +185,6 @@ static void draw_uvs_shadow(Object *obedit)
immUnbindProgram();
}
static int draw_uvs_dm_shadow(DerivedMesh *dm)
{
/* draw shadow mesh - this is the mesh with the modifier applied */
if (dm && dm->drawUVEdges && CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) {
UI_ThemeColor(TH_UV_SHADOW);
dm->drawUVEdges(dm);
return 1;
}
return 0;
}
static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTexPoly *activetf)
{
BMesh *bm = em->bm;
@@ -626,7 +614,6 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe
BMIter iter, liter;
MTexPoly *tf, *activetf = NULL;
MLoopUV *luv;
DerivedMesh *finaldm, *cagedm;
unsigned char col1[4], col2[4];
float pointsize;
int drawfaces, interpedges;
@@ -668,22 +655,14 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe
/* 1. draw shadow mesh */
if (sima->flag & SI_DRAWSHADOW) {
DM_update_materials(em->derivedFinal, obedit);
/* first try existing derivedmesh */
if (!draw_uvs_dm_shadow(em->derivedFinal)) {
/* create one if it does not exist */
cagedm = editbmesh_get_derived_cage_and_final(
scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH | CD_MASK_MTFACE,
&finaldm);
TODO_LAYER_DEPSGRAPH;
/* XXX TODO: Need to check if shadow mesh is different than original mesh. */
bool is_cage_like_final_meshes = true;
/* when sync selection is enabled, all faces are drawn (except for hidden)
* so if cage is the same as the final, theres no point in drawing this */
if (!((ts->uv_flag & UV_SYNC_SELECTION) && (cagedm == finaldm)))
draw_uvs_dm_shadow(finaldm);
/* release derivedmesh again */
if (cagedm != finaldm) cagedm->release(cagedm);
finaldm->release(finaldm);
/* When sync selection is enabled, all faces are drawn (except for hidden)
* so if cage is the same as the final, there is no point in drawing this. */
if (((ts->uv_flag & UV_SYNC_SELECTION) == 0) || is_cage_like_final_meshes) {
draw_uvs_shadow(obedit);
}
}