forked from bartvdbraak/blender
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:
parent
58e5509da0
commit
8604ec9053
@ -746,6 +746,8 @@ typedef struct DMVertexAttribs {
|
||||
void DM_vertex_attributes_from_gpu(DerivedMesh *dm,
|
||||
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_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 */
|
||||
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,
|
||||
const short (*lnor)[3], const bool smoothnormal)
|
||||
{
|
||||
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);
|
||||
}
|
||||
DM_draw_attrib_vertex(attribs, a, index, vert);
|
||||
|
||||
/* vertex normal */
|
||||
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 */
|
||||
static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
|
||||
DMSetMaterial setMaterial,
|
||||
@ -1959,7 +1901,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
|
||||
index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
|
||||
else \
|
||||
index = 0; \
|
||||
ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \
|
||||
DM_draw_attrib_vertex(&attribs, a, index, vert); \
|
||||
} (void)0
|
||||
|
||||
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); \
|
||||
else \
|
||||
index = 0; \
|
||||
ccgdm_draw_attrib_vertex(&attribs, a, index, vert); \
|
||||
DM_draw_attrib_vertex(&attribs, a, index, vert); \
|
||||
} (void)0
|
||||
|
||||
totface = ccgSubSurf_getNumFaces(ss);
|
||||
|
Loading…
Reference in New Issue
Block a user