De-duplicate large block of shared code for GL vert attribs

Code in ccgdm_draw_attrib_vertex() was entirely the same as the top
portion of the code in cddm_draw_attrib_vertex(). Moved this code to a
new function, DM_draw_attrib_vertex().

ccgdm_draw_attrib_vertex() was removed in favor of calling
DM_draw_attrib_vertex(). cddm_draw_attrib_vertex() still does a couple
extra things, so it still exists but calls DM_draw_attrib_vertex().

In the interest of easy code review, no changes made to the code in
DM_draw_attrib_vertex() other than the new name and an added comment.

Reviewers: campbellbarton

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D1010
This commit is contained in:
Nicholas Bishop 2015-01-20 14:17:08 +01:00
parent 58e5509da0
commit 8604ec9053
4 changed files with 68 additions and 113 deletions

@ -746,6 +746,8 @@ typedef struct DMVertexAttribs {
void DM_vertex_attributes_from_gpu(DerivedMesh *dm, void DM_vertex_attributes_from_gpu(DerivedMesh *dm,
struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs); struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert);
void DM_add_tangent_layer(DerivedMesh *dm); void DM_add_tangent_layer(DerivedMesh *dm);
void DM_calc_auto_bump_scale(DerivedMesh *dm); void DM_calc_auto_bump_scale(DerivedMesh *dm);

@ -3080,6 +3080,69 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
} }
} }
/* Set vertex shader attribute inputs for a particular tessface vert
*
* a: tessface index
* index: vertex index
* vert: corner index (0, 1, 2, 3)
*/
void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert)
{
const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
int b;
/* orco texture coordinates */
if (attribs->totorco) {
/*const*/ float (*array)[3] = attribs->orco.array;
const float *orco = (array) ? array[index] : zero;
if (attribs->orco.gl_texco)
glTexCoord3fv(orco);
else
glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
}
/* uv texture coordinates */
for (b = 0; b < attribs->tottface; b++) {
const float *uv;
if (attribs->tface[b].array) {
MTFace *tf = &attribs->tface[b].array[a];
uv = tf->uv[vert];
}
else {
uv = zero;
}
if (attribs->tface[b].gl_texco)
glTexCoord2fv(uv);
else
glVertexAttrib2fvARB(attribs->tface[b].gl_index, uv);
}
/* vertex colors */
for (b = 0; b < attribs->totmcol; b++) {
GLubyte col[4];
if (attribs->mcol[b].array) {
MCol *cp = &attribs->mcol[b].array[a * 4 + vert];
col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
}
else {
col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0;
}
glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col);
}
/* tangent for normal mapping */
if (attribs->tottang) {
/*const*/ float (*array)[4] = attribs->tang.array;
const float *tang = (array) ? array[a * 4 + vert] : zero;
glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
}
}
/* Set object's bounding box based on DerivedMesh min/max data */ /* Set object's bounding box based on DerivedMesh min/max data */
void DM_set_object_boundbox(Object *ob, DerivedMesh *dm) void DM_set_object_boundbox(Object *ob, DerivedMesh *dm)
{ {

@ -869,59 +869,7 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm,
static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, const MVert *mvert, int a, int index, int vert, static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, const MVert *mvert, int a, int index, int vert,
const short (*lnor)[3], const bool smoothnormal) const short (*lnor)[3], const bool smoothnormal)
{ {
const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; DM_draw_attrib_vertex(attribs, a, index, vert);
int b;
/* orco texture coordinates */
if (attribs->totorco) {
/*const*/ float (*array)[3] = attribs->orco.array;
const float *orco = (array) ? array[index] : zero;
if (attribs->orco.gl_texco)
glTexCoord3fv(orco);
else
glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
}
/* uv texture coordinates */
for (b = 0; b < attribs->tottface; b++) {
const float *uv;
if (attribs->tface[b].array) {
MTFace *tf = &attribs->tface[b].array[a];
uv = tf->uv[vert];
}
else {
uv = zero;
}
if (attribs->tface[b].gl_texco)
glTexCoord2fv(uv);
else
glVertexAttrib2fvARB(attribs->tface[b].gl_index, uv);
}
/* vertex colors */
for (b = 0; b < attribs->totmcol; b++) {
GLubyte col[4];
if (attribs->mcol[b].array) {
MCol *cp = &attribs->mcol[b].array[a * 4 + vert];
col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
}
else {
col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0;
}
glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col);
}
/* tangent for normal mapping */
if (attribs->tottang) {
/*const*/ float (*array)[4] = attribs->tang.array;
const float *tang = (array) ? array[a * 4 + vert] : zero;
glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
}
/* vertex normal */ /* vertex normal */
if (lnor) { if (lnor) {

@ -1871,64 +1871,6 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
} }
} }
static void ccgdm_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert)
{
const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
int b;
/* orco texture coordinates */
if (attribs->totorco) {
/*const*/ float (*array)[3] = attribs->orco.array;
const float *orco = (array) ? array[index] : zero;
if (attribs->orco.gl_texco)
glTexCoord3fv(orco);
else
glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
}
/* uv texture coordinates */
for (b = 0; b < attribs->tottface; b++) {
const float *uv;
if (attribs->tface[b].array) {
MTFace *tf = &attribs->tface[b].array[a];
uv = tf->uv[vert];
}
else {
uv = zero;
}
if (attribs->tface[b].gl_texco)
glTexCoord2fv(uv);
else
glVertexAttrib2fvARB(attribs->tface[b].gl_index, uv);
}
/* vertex colors */
for (b = 0; b < attribs->totmcol; b++) {
GLubyte col[4];
if (attribs->mcol[b].array) {
MCol *cp = &attribs->mcol[b].array[a * 4 + vert];
col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
}
else {
col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0;
}
glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col);
}
/* tangent for normal mapping */
if (attribs->tottang) {
/*const*/ float (*array)[4] = attribs->tang.array;
const float *tang = (array) ? array[a * 4 + vert] : zero;
glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
}
}
/* Only used by non-editmesh types */ /* Only used by non-editmesh types */
static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
DMSetMaterial setMaterial, DMSetMaterial setMaterial,
@ -1959,7 +1901,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
else \ else \
index = 0; \ index = 0; \
ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \ DM_draw_attrib_vertex(&attribs, a, index, vert); \
} (void)0 } (void)0
totface = ccgSubSurf_getNumFaces(ss); totface = ccgSubSurf_getNumFaces(ss);
@ -2130,7 +2072,7 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm,
index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \ index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
else \ else \
index = 0; \ index = 0; \
ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \ DM_draw_attrib_vertex(&attribs, a, index, vert); \
} (void)0 } (void)0
totface = ccgSubSurf_getNumFaces(ss); totface = ccgSubSurf_getNumFaces(ss);