Code cleanup: small glsl mesh drawing code changes, getting rid of an ugly macro.
This commit is contained in:
@@ -526,7 +526,7 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb);
|
||||
typedef struct DMVertexAttribs {
|
||||
struct {
|
||||
struct MTFace *array;
|
||||
int emOffset, glIndex;
|
||||
int emOffset, glIndex, glTexco;
|
||||
} tface[MAX_MTFACE];
|
||||
|
||||
struct {
|
||||
@@ -541,7 +541,7 @@ typedef struct DMVertexAttribs {
|
||||
|
||||
struct {
|
||||
float (*array)[3];
|
||||
int emOffset, glIndex;
|
||||
int emOffset, glIndex, glTexco;
|
||||
} orco;
|
||||
|
||||
int tottface, totmcol, tottang, totorco;
|
||||
|
||||
@@ -1050,6 +1050,7 @@ static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
#undef PASSATTRIB
|
||||
}
|
||||
|
||||
static void emDM_drawFacesGLSL(DerivedMesh *dm,
|
||||
@@ -2767,6 +2768,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
|
||||
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].type == CD_MCOL) {
|
||||
@@ -2807,6 +2809,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
|
||||
attribs->orco.array = vdata->layers[layer].data;
|
||||
attribs->orco.emOffset = vdata->layers[layer].offset;
|
||||
attribs->orco.glIndex = gattribs->layer[b].glindex;
|
||||
attribs->orco.glTexco = gattribs->layer[b].gltexco;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -993,6 +993,50 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void
|
||||
cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, userData);
|
||||
}
|
||||
|
||||
static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int a, int index, int vert, int smoothnormal)
|
||||
{
|
||||
int b;
|
||||
|
||||
/* orco texture coordinates */
|
||||
if(attribs->totorco) {
|
||||
if(attribs->orco.glTexco)
|
||||
glTexCoord3fv(attribs->orco.array[index]);
|
||||
else
|
||||
glVertexAttrib3fvARB(attribs->orco.glIndex, attribs->orco.array[index]);
|
||||
}
|
||||
|
||||
/* uv texture coordinates */
|
||||
for(b = 0; b < attribs->tottface; b++) {
|
||||
MTFace *tf = &attribs->tface[b].array[a];
|
||||
|
||||
if(attribs->tface[b].glTexco)
|
||||
glTexCoord2fv(tf->uv[vert]);
|
||||
else
|
||||
glVertexAttrib2fvARB(attribs->tface[b].glIndex, tf->uv[vert]);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
glVertexAttrib4ubvARB(attribs->mcol[b].glIndex, col);
|
||||
}
|
||||
|
||||
/* tangent for normal mapping */
|
||||
if(attribs->tottang) {
|
||||
float *tang = attribs->tang.array[a*4 + vert];
|
||||
glVertexAttrib4fvARB(attribs->tang.glIndex, tang);
|
||||
}
|
||||
|
||||
/* vertex normal */
|
||||
if(smoothnormal)
|
||||
glNormal3sv(mvert[index].no);
|
||||
|
||||
/* vertex coordinate */
|
||||
glVertex3fv(mvert[index].co);
|
||||
}
|
||||
|
||||
static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs), int (*setDrawOptions)(void *userData, int index), void *userData)
|
||||
{
|
||||
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
|
||||
@@ -1083,37 +1127,14 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
|
||||
}
|
||||
}
|
||||
|
||||
#define PASSVERT(index, vert) { \
|
||||
if(attribs.totorco) \
|
||||
glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]); \
|
||||
for(b = 0; b < attribs.tottface; b++) { \
|
||||
MTFace *tf = &attribs.tface[b].array[a]; \
|
||||
glVertexAttrib2fvARB(attribs.tface[b].glIndex, 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].glIndex, col); \
|
||||
} \
|
||||
if(attribs.tottang) { \
|
||||
float *tang = attribs.tang.array[a*4 + vert]; \
|
||||
glVertexAttrib4fvARB(attribs.tang.glIndex, tang); \
|
||||
} \
|
||||
if(smoothnormal) \
|
||||
glNormal3sv(mvert[index].no); \
|
||||
glVertex3fv(mvert[index].co); \
|
||||
}
|
||||
cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v1, 0, smoothnormal);
|
||||
cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v2, 1, smoothnormal);
|
||||
cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v3, 2, smoothnormal);
|
||||
|
||||
PASSVERT(mface->v1, 0);
|
||||
PASSVERT(mface->v2, 1);
|
||||
PASSVERT(mface->v3, 2);
|
||||
if(mface->v4)
|
||||
PASSVERT(mface->v4, 3)
|
||||
cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v4, 3, smoothnormal);
|
||||
else
|
||||
PASSVERT(mface->v3, 2)
|
||||
|
||||
#undef PASSVERT
|
||||
cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v3, 2, smoothnormal);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
@@ -178,6 +178,7 @@ typedef struct GPUVertexAttribs {
|
||||
struct {
|
||||
int type;
|
||||
int glindex;
|
||||
int gltexco;
|
||||
char name[32];
|
||||
} layer[GPU_MAX_ATTRIB];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user