Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/editderivedmesh.c')
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c473
1 files changed, 280 insertions, 193 deletions
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 8d430eb58b5..d2f2e3f01d2 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -33,8 +33,6 @@
#include <limits.h>
#include <math.h>
-#include "GL/glew.h"
-
#include "BLI_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_edgehash.h"
@@ -57,6 +55,7 @@
#include "GPU_draw.h"
#include "GPU_extensions.h"
#include "GPU_material.h"
+#include "GPU_compatibility.h"
/* bmesh */
#include "BKE_tessmesh.h"
@@ -404,29 +403,28 @@ static void emDM_drawMappedEdges(DerivedMesh *dm,
BMIter iter;
int i;
- if (bmdm->vertexCos) {
+ gpuBegin(GL_LINES);
+ if (bmdm->vertexCos) {
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT);
- glBegin(GL_LINES);
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
+ gpuVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
+ gpuVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
}
}
- glEnd();
}
else {
- glBegin(GL_LINES);
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
- glVertex3fv(eed->v1->co);
- glVertex3fv(eed->v2->co);
+ gpuVertex3fv(eed->v1->co);
+ gpuVertex3fv(eed->v2->co);
}
}
- glEnd();
}
+
+ gpuEnd();
}
static void emDM_drawEdges(DerivedMesh *dm,
int UNUSED(drawLooseEdges),
@@ -449,28 +447,28 @@ static void emDM_drawMappedEdgesInterp(DerivedMesh *dm,
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT);
- glBegin(GL_LINES);
+ gpuBegin(GL_LINES);
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
setDrawInterpOptions(userData, i, 0.0);
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
+ gpuVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
setDrawInterpOptions(userData, i, 1.0);
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
+ gpuVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
}
}
- glEnd();
+ gpuEnd();
}
else {
- glBegin(GL_LINES);
+ gpuBegin(GL_LINES);
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
setDrawInterpOptions(userData, i, 0.0);
- glVertex3fv(eed->v1->co);
+ gpuVertex3fv(eed->v1->co);
setDrawInterpOptions(userData, i, 1.0);
- glVertex3fv(eed->v2->co);
+ gpuVertex3fv(eed->v2->co);
}
}
- glEnd();
+ gpuEnd();
}
}
@@ -481,7 +479,9 @@ static void emDM_drawUVEdges(DerivedMesh *dm)
BMFace *efa;
BMIter iter;
- glBegin(GL_LINES);
+ gpuImmediateFormat_V3();
+
+ gpuBegin(GL_LINES);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
BMIter liter;
BMLoop *l;
@@ -495,21 +495,25 @@ static void emDM_drawUVEdges(DerivedMesh *dm)
if (luv) {
if (lastluv)
- glVertex2fv(luv->uv);
- glVertex2fv(luv->uv);
+ gpuVertex2fv(luv->uv);
+
+ gpuVertex2fv(luv->uv);
lastluv = luv;
+
if (!firstluv)
firstluv = luv;
}
}
if (lastluv) {
- glVertex2fv(lastluv->uv);
- glVertex2fv(firstluv->uv);
+ gpuVertex2fv(lastluv->uv);
+ gpuVertex2fv(firstluv->uv);
}
}
- glEnd();
+ gpuEnd();
+
+ gpuImmediateUnformat();
}
static void emDM__calcFaceCent(BMFace *efa, float cent[3], float (*vertexCos)[3])
@@ -564,12 +568,13 @@ static void emDM_foreachMappedFaceCenter(DerivedMesh *dm,
}
}
-static void emDM_drawMappedFaces(DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetMaterial setMaterial,
- DMCompareDrawOptions compareDrawOptions,
- void *userData,
- DMDrawFlag flag)
+static void emDM_drawMappedFaces(
+ DerivedMesh *dm,
+ DMSetDrawOptions setDrawOptions,
+ DMSetMaterial setMaterial,
+ DMCompareDrawOptions compareDrawOptions,
+ void *userData,
+ DMDrawFlag flag)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMFace *efa;
@@ -577,18 +582,24 @@ static void emDM_drawMappedFaces(DerivedMesh *dm,
const int tottri = bmdm->tc->tottri;
const int lasttri = tottri - 1; /* compare agasint this a lot */
DMDrawOption draw_option;
+ int useNormals = flag & DM_DRAW_USE_NORMALS;
int i, flush;
- const int skip_normals = !glIsEnabled(GL_LIGHTING); /* could be passed as an arg */
- /* GL_ZERO is used to detect if drawing has started or not */
- GLenum poly_prev = GL_ZERO;
- GLenum shade_prev = GL_ZERO;
+ /* GL_NOOP is used to detect if drawing has started or not */
+ GLenum poly_prev = GL_NOOP;
+ GLenum shade_prev = GL_NOOP;
(void)setMaterial; /* UNUSED */
/* currently unused -- each original face is handled separately */
(void)compareDrawOptions;
+ if (flag & DM_DRAW_USE_COLORS)
+ gpuImmediateFormat_C4_V3();
+ else
+ if (flag & DM_DRAW_USE_COLORS)
+ gpuImmediateFormat_C4_N3_V3();
+ else
if (bmdm->vertexCos) {
/* add direct access */
float (*vertexCos)[3] = bmdm->vertexCos;
@@ -606,63 +617,63 @@ static void emDM_drawMappedFaces(DerivedMesh *dm,
drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
draw_option = (!setDrawOptions ?
- DM_DRAW_OPTION_NORMAL :
+ DM_DRAW_OPTION_NORMALLY :
setDrawOptions(userData, BM_elem_index_get(efa)));
if (draw_option != DM_DRAW_OPTION_SKIP) {
const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
+ if (poly_prev != GL_NOOP) gpuEnd();
+ poly_prev = GL_NOOP; /* force gpuBegin */
glEnable(GL_POLYGON_STIPPLE);
glPolygonStipple(stipple_quarttone);
}
- if (skip_normals) {
+ if (!useNormals) {
if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
+ if (poly_prev != GL_NOOP) gpuEnd();
+ gpuBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
- glVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
}
else {
const GLenum shade_type = drawSmooth ? GL_SMOOTH : GL_FLAT;
if (shade_type != shade_prev) {
- if (poly_prev != GL_ZERO) glEnd();
+ if (poly_prev != GL_NOOP) gpuEnd();
glShadeModel((shade_prev = shade_type)); /* same as below but switch shading */
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
+ gpuBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
+ if (poly_prev != GL_NOOP) gpuEnd();
+ gpuBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
if (!drawSmooth) {
- glNormal3fv(polyNos[BM_elem_index_get(efa)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
+ gpuNormal3fv(polyNos[BM_elem_index_get(efa)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
}
else {
- glNormal3fv(vertexNos[BM_elem_index_get(l[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
- glNormal3fv(vertexNos[BM_elem_index_get(l[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
- glNormal3fv(vertexNos[BM_elem_index_get(l[2]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(l[0]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(l[1]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(l[2]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
}
}
flush = (draw_option == DM_DRAW_OPTION_STIPPLE);
- if (!skip_normals && !flush && (i != lasttri))
+ if (useNormals && !flush && (i != lasttri))
flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */
if (flush) {
- glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
+ gpuEnd();
+ poly_prev = GL_NOOP; /* force gpuBegin */
glDisable(GL_POLYGON_STIPPLE);
}
@@ -672,6 +683,9 @@ static void emDM_drawMappedFaces(DerivedMesh *dm,
else {
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_FACE);
+ poly_prev = GL_TRIANGLES;
+ gpuBegin(GL_TRIANGLES);
+
for (i = 0; i < tottri; i++) {
BMLoop **l = looptris[i];
int drawSmooth;
@@ -680,73 +694,75 @@ static void emDM_drawMappedFaces(DerivedMesh *dm,
drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
draw_option = (!setDrawOptions ?
- DM_DRAW_OPTION_NORMAL :
+ DM_DRAW_OPTION_NORMALLY :
setDrawOptions(userData, BM_elem_index_get(efa)));
if (draw_option != DM_DRAW_OPTION_SKIP) {
const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
+ if (poly_prev != GL_NOOP) gpuEnd();
+ poly_prev = GL_NOOP; /* force gpuBegin */
glEnable(GL_POLYGON_STIPPLE);
glPolygonStipple(stipple_quarttone);
}
- if (skip_normals) {
+ if (!useNormals) {
if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
+ if (poly_prev != GL_NOOP) gpuEnd();
+ gpuBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
- glVertex3fv(l[0]->v->co);
- glVertex3fv(l[1]->v->co);
- glVertex3fv(l[2]->v->co);
+ gpuVertex3fv(l[0]->v->co);
+ gpuVertex3fv(l[1]->v->co);
+ gpuVertex3fv(l[2]->v->co);
}
else {
const GLenum shade_type = drawSmooth ? GL_SMOOTH : GL_FLAT;
if (shade_type != shade_prev) {
- if (poly_prev != GL_ZERO) glEnd();
+ if (poly_prev != GL_ZERO) gpuEnd();
glShadeModel((shade_prev = shade_type)); /* same as below but switch shading */
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
+ gpuBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
+ if (poly_prev != GL_NOOP) gpuEnd();
+ gpuBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
if (!drawSmooth) {
- glNormal3fv(efa->no);
- glVertex3fv(l[0]->v->co);
- glVertex3fv(l[1]->v->co);
- glVertex3fv(l[2]->v->co);
+ gpuNormal3fv(efa->no);
+ gpuVertex3fv(l[0]->v->co);
+ gpuVertex3fv(l[1]->v->co);
+ gpuVertex3fv(l[2]->v->co);
}
else {
- glNormal3fv(l[0]->v->no);
- glVertex3fv(l[0]->v->co);
- glNormal3fv(l[1]->v->no);
- glVertex3fv(l[1]->v->co);
- glNormal3fv(l[2]->v->no);
- glVertex3fv(l[2]->v->co);
+ gpuNormal3fv(l[0]->v->no);
+ gpuVertex3fv(l[0]->v->co);
+ gpuNormal3fv(l[1]->v->no);
+ gpuVertex3fv(l[1]->v->co);
+ gpuNormal3fv(l[2]->v->no);
+ gpuVertex3fv(l[2]->v->co);
}
}
flush = (draw_option == DM_DRAW_OPTION_STIPPLE);
- if (!skip_normals && !flush && (i != lasttri)) {
+ if (useNormals && !flush && (i != lasttri)) {
flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */
}
if (flush) {
- glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
+ gpuEnd();
glDisable(GL_POLYGON_STIPPLE);
+
+ poly_prev = GL_TRIANGLES;
+ gpuBegin(GL_TRIANGLES);
}
}
}
}
/* if non zero we know a face was rendered */
- if (poly_prev != GL_ZERO) glEnd();
+ if (poly_prev != GL_NOOP) gpuEnd();
}
static void bmdm_get_tri_tex(BMesh *bm, BMLoop **ls, MLoopUV *luv[3], MLoopCol *lcol[3],
@@ -795,6 +811,8 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
BM_mesh_elem_index_ensure(bm, BM_FACE);
+ gpuImmediateFormat_T2_C4_N3_V3();
+
if (vertexCos) {
BM_mesh_elem_index_ensure(bm, BM_VERT);
@@ -817,53 +835,53 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
else if (drawParamsMapped)
draw_option = drawParamsMapped(userData, BM_elem_index_get(efa));
else
- draw_option = DM_DRAW_OPTION_NORMAL;
+ draw_option = DM_DRAW_OPTION_NORMALLY;
if (draw_option != DM_DRAW_OPTION_SKIP) {
- glBegin(GL_TRIANGLES);
+ gpuBegin(GL_TRIANGLES);
if (!drawSmooth) {
- glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
+ gpuNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
- glTexCoord2fv(luv[0]->uv);
+ gpuTexCoord2fv(luv[0]->uv);
if (lcol[0])
- glColor3ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
+ gpuColor3ubv((const GLubyte *)&(lcol[0]->r));
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
- glTexCoord2fv(luv[1]->uv);
+ gpuTexCoord2fv(luv[1]->uv);
if (lcol[1])
- glColor3ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
+ gpuColor3ubv((const GLubyte *)&(lcol[1]->r));
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
- glTexCoord2fv(luv[2]->uv);
+ gpuTexCoord2fv(luv[2]->uv);
if (lcol[2])
- glColor3ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
+ gpuColor3ubv((const GLubyte *)&(lcol[2]->r));
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
}
else {
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
- glTexCoord2fv(luv[0]->uv);
+ gpuTexCoord2fv(luv[0]->uv);
if (lcol[0])
- glColor3ubv((const GLubyte *)&(lcol[0]->r));
- glNormal3fv(vertexNos[BM_elem_index_get(ls[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
+ gpuColor3ubv((const GLubyte *)&(lcol[0]->r));
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ls[0]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
- glTexCoord2fv(luv[1]->uv);
+ gpuTexCoord2fv(luv[1]->uv);
if (lcol[1])
- glColor3ubv((const GLubyte *)&(lcol[1]->r));
- glNormal3fv(vertexNos[BM_elem_index_get(ls[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
+ gpuColor3ubv((const GLubyte *)&(lcol[1]->r));
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ls[1]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
- glTexCoord2fv(luv[2]->uv);
+ gpuTexCoord2fv(luv[2]->uv);
if (lcol[2])
- glColor3ubv((const GLubyte *)&(lcol[2]->r));
- glNormal3fv(vertexNos[BM_elem_index_get(ls[2]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
+ gpuColor3ubv((const GLubyte *)&(lcol[2]->r));
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ls[2]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
}
- glEnd();
+ gpuEnd();
}
}
}
@@ -889,63 +907,65 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
else if (drawParamsMapped)
draw_option = drawParamsMapped(userData, BM_elem_index_get(efa));
else
- draw_option = DM_DRAW_OPTION_NORMAL;
+ draw_option = DM_DRAW_OPTION_NORMALLY;
if (draw_option != DM_DRAW_OPTION_SKIP) {
- glBegin(GL_TRIANGLES);
+ gpuBegin(GL_TRIANGLES);
if (!drawSmooth) {
- glNormal3fv(efa->no);
+ gpuNormal3fv(efa->no);
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
if (luv[0])
- glTexCoord2fv(luv[0]->uv);
+ gpuTexCoord2fv(luv[0]->uv);
if (lcol[0])
- glColor3ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(ls[0]->v->co);
+ gpuColor3ubv((const GLubyte *)&(lcol[0]->r));
+ gpuVertex3fv(ls[0]->v->co);
if (luv[1])
- glTexCoord2fv(luv[1]->uv);
+ gpuTexCoord2fv(luv[1]->uv);
if (lcol[1])
- glColor3ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(ls[1]->v->co);
+ gpuColor3ubv((const GLubyte *)&(lcol[1]->r));
+ gpuVertex3fv(ls[1]->v->co);
if (luv[2])
- glTexCoord2fv(luv[2]->uv);
+ gpuTexCoord2fv(luv[2]->uv);
if (lcol[2])
- glColor3ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(ls[2]->v->co);
+ gpuColor3ubv((const GLubyte *)&(lcol[2]->r));
+ gpuVertex3fv(ls[2]->v->co);
}
else {
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
if (luv[0])
- glTexCoord2fv(luv[0]->uv);
+ gpuTexCoord2fv(luv[0]->uv);
if (lcol[0])
- glColor3ubv((const GLubyte *)&(lcol[0]->r));
- glNormal3fv(ls[0]->v->no);
- glVertex3fv(ls[0]->v->co);
+ gpuColor3ubv((const GLubyte *)&(lcol[0]->r));
+ gpuNormal3fv(ls[0]->v->no);
+ gpuVertex3fv(ls[0]->v->co);
if (luv[1])
- glTexCoord2fv(luv[1]->uv);
+ gpuTexCoord2fv(luv[1]->uv);
if (lcol[1])
- glColor3ubv((const GLubyte *)&(lcol[1]->r));
- glNormal3fv(ls[1]->v->no);
- glVertex3fv(ls[1]->v->co);
+ gpuColor3ubv((const GLubyte *)&(lcol[1]->r));
+ gpuNormal3fv(ls[1]->v->no);
+ gpuVertex3fv(ls[1]->v->co);
if (luv[2])
- glTexCoord2fv(luv[2]->uv);
+ gpuTexCoord2fv(luv[2]->uv);
if (lcol[2])
- glColor3ubv((const GLubyte *)&(lcol[2]->r));
- glNormal3fv(ls[2]->v->no);
- glVertex3fv(ls[2]->v->co);
+ gpuColor3ubv((const GLubyte *)&(lcol[2]->r));
+ gpuNormal3fv(ls[2]->v->no);
+ gpuVertex3fv(ls[2]->v->co);
}
- glEnd();
+ gpuEnd();
}
}
}
+ gpuImmediateUnformat();
+
glShadeModel(GL_FLAT);
}
@@ -965,6 +985,64 @@ static void emDM_drawMappedFacesTex(DerivedMesh *dm,
emDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
}
+static void emdm_format_attrib_vertex(DMVertexAttribs *attribs)
+{
+ int b;
+ GLint attribMap_f[16];
+ GLint attribSize_f[16];
+ GLint attrib_f = 0;
+ GLint attribMap_ub[16];
+ GLint attribSize_ub[16];
+ GLint attrib_ub = 0;
+
+ /* orco texture coordinates */
+ if (attribs->totorco) {
+ attribMap_f[attrib_f] = attribs->orco.gl_index;
+ attribSize_f[attrib_f] = 3;
+ attrib_f++;
+ }
+
+ /* uv texture coordinates */
+ for (b = 0; b < attribs->tottface; b++) {
+ attribMap_f[attrib_f] = attribs->tface[b].gl_index;
+ attribSize_f[attrib_f] = 2;
+ attrib_f++;
+ }
+
+ /* vertex colors */
+ for (b = 0; b < attribs->totmcol; b++) {
+ attribMap_ub[attrib_ub] = attribs->mcol[b].gl_index;
+ attribSize_ub[attrib_ub] = 4;
+ attrib_ub++;
+ }
+
+ /* tangent for normal mapping */
+ if (attribs->tottang) {
+ attribMap_f[attrib_f] = attribs->tang.gl_index;
+ attribSize_f[attrib_f] = 3;
+ attrib_f++;
+ }
+
+ gpuImmediateFormatReset();
+
+ gpuImmediateElementSizes(3, 3, 0);
+
+ gpuImmediateFloatAttribCount(attrib_f);
+ gpuImmediateFloatAttribIndexMap(attribMap_f);
+ gpuImmediateFloatAttribSizes(attribSize_f);
+
+ gpuImmediateUbyteAttribCount(attrib_ub);
+ gpuImmediateUbyteAttribIndexMap(attribMap_ub);
+ gpuImmediateUbyteAttribSizes(attribMap_ub);
+
+ gpuImmediateLock();
+}
+
+static void emdm_unformat_attrib_vertex(void)
+{
+ gpuImmediateUnlock();
+}
+
static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
DMSetMaterial setMaterial,
DMSetDrawOptions setDrawOptions,
@@ -987,6 +1065,8 @@ static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
memset(&attribs, 0, sizeof(attribs));
+ emdm_format_attrib_vertex(&attribs); /* XXX: jwilkins, just to make this easy to write for now */
+
/* always use smooth shading even for flat faces, else vertex colors wont interpolate */
glShadeModel(GL_SMOOTH);
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
@@ -994,23 +1074,23 @@ static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
#define PASSATTRIB(loop, eve, vert) { \
if (attribs.totorco) { \
float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \
- glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \
+ gpuVertexAttrib3fv(attribs.orco.gl_index, orco); \
} \
for (b = 0; b < attribs.tottface; b++) { \
MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
CD_MLOOPUV, b); \
- glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \
+ gpuVertexAttrib2fv(attribs.tface[b].gl_index, _luv->uv); \
} \
for (b = 0; b < attribs.totmcol; b++) { \
MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
CD_MLOOPCOL, b); \
GLubyte _col[4]; \
_col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \
- glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \
+ gpuVertexAttrib4ubv(attribs.mcol[b].gl_index, _col); \
} \
if (attribs.tottang) { \
float *tang = attribs.tang.array[i * 4 + vert]; \
- glVertexAttrib3fvARB(attribs.tang.gl_index, tang); \
+ gpuVertexAttrib3fv(attribs.tang.gl_index, tang); \
} \
} (void)0
@@ -1027,62 +1107,69 @@ static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
new_matnr = efa->mat_nr + 1;
if (new_matnr != matnr) {
do_draw = setMaterial(matnr = new_matnr, &gattribs);
- if (do_draw)
+ if (do_draw) {
+ emdm_unformat_attrib_vertex();
+
DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
+
+ emdm_format_attrib_vertex(&attribs);
+ }
}
if (do_draw) {
- glBegin(GL_TRIANGLES);
+ gpuBegin(GL_TRIANGLES);
if (!drawSmooth) {
- if (vertexCos) glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
- else glNormal3fv(efa->no);
+ if (vertexCos) gpuNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
+ else gpuNormal3fv(efa->no);
PASSATTRIB(ltri[0], ltri[0]->v, 0);
- if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
- else glVertex3fv(ltri[0]->v->co);
+ if (vertexCos) gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
+ else gpuVertex3fv(ltri[0]->v->co);
PASSATTRIB(ltri[1], ltri[1]->v, 1);
- if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
- else glVertex3fv(ltri[1]->v->co);
+ if (vertexCos) gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
+ else gpuVertex3fv(ltri[1]->v->co);
PASSATTRIB(ltri[2], ltri[2]->v, 2);
- if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
- else glVertex3fv(ltri[2]->v->co);
+ if (vertexCos) gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
+ else gpuVertex3fv(ltri[2]->v->co);
}
else {
PASSATTRIB(ltri[0], ltri[0]->v, 0);
if (vertexCos) {
- glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
}
else {
- glNormal3fv(ltri[0]->v->no);
- glVertex3fv(ltri[0]->v->co);
+ gpuNormal3fv(ltri[0]->v->no);
+ gpuVertex3fv(ltri[0]->v->co);
}
PASSATTRIB(ltri[1], ltri[1]->v, 1);
if (vertexCos) {
- glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
}
else {
- glNormal3fv(ltri[1]->v->no);
- glVertex3fv(ltri[1]->v->co);
+ gpuNormal3fv(ltri[1]->v->no);
+ gpuVertex3fv(ltri[1]->v->co);
}
PASSATTRIB(ltri[2], ltri[2]->v, 2);
if (vertexCos) {
- glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
}
else {
- glNormal3fv(ltri[2]->v->no);
- glVertex3fv(ltri[2]->v->co);
+ gpuNormal3fv(ltri[2]->v->no);
+ gpuVertex3fv(ltri[2]->v->co);
}
}
- glEnd();
+ gpuEnd();
}
}
+
+ emdm_unformat_attrib_vertex();
#undef PASSATTRIB
}
@@ -1118,28 +1205,28 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm,
if (attribs.totorco) { \
float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \
if (attribs.orco.gl_texco) \
- glTexCoord3fv(orco); \
+ gpuTexCoord3fv(orco); \
else \
- glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \
+ gpuVertexAttrib3fv(attribs.orco.gl_index, orco); \
} \
for (b = 0; b < attribs.tottface; b++) { \
MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
CD_MLOOPUV, b); \
if (attribs.tface[b].gl_texco) \
- glTexCoord2fv(_luv->uv); \
+ gpuTexCoord2fv(_luv->uv); \
else \
- glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \
+ gpuVertexAttrib2fv(attribs.tface[b].gl_index, _luv->uv); \
} \
for (b = 0; b < attribs.totmcol; b++) { \
MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
CD_MLOOPCOL, b); \
GLubyte _col[4]; \
_col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \
- glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \
+ gpuVertexAttrib4ubv(attribs.mcol[b].gl_index, _col); \
} \
if (attribs.tottang) { \
float *tang = attribs.tang.array[i * 4 + vert]; \
- glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \
+ gpuVertexAttrib4fv(attribs.tang.gl_index, tang); \
} \
} (void)0
@@ -1161,56 +1248,56 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm,
}
/* face */
- glBegin(GL_TRIANGLES);
+ gpuBegin(GL_TRIANGLES);
if (!drawSmooth) {
- if (vertexCos) glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
- else glNormal3fv(efa->no);
+ if (vertexCos) gpuNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
+ else gpuNormal3fv(efa->no);
PASSATTRIB(ltri[0], ltri[0]->v, 0);
- if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
- else glVertex3fv(ltri[0]->v->co);
+ if (vertexCos) gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
+ else gpuVertex3fv(ltri[0]->v->co);
PASSATTRIB(ltri[1], ltri[1]->v, 1);
- if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
- else glVertex3fv(ltri[1]->v->co);
+ if (vertexCos) gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
+ else gpuVertex3fv(ltri[1]->v->co);
PASSATTRIB(ltri[2], ltri[2]->v, 2);
- if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
- else glVertex3fv(ltri[2]->v->co);
+ if (vertexCos) gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
+ else gpuVertex3fv(ltri[2]->v->co);
}
else {
PASSATTRIB(ltri[0], ltri[0]->v, 0);
if (vertexCos) {
- glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
}
else {
- glNormal3fv(ltri[0]->v->no);
- glVertex3fv(ltri[0]->v->co);
+ gpuNormal3fv(ltri[0]->v->no);
+ gpuVertex3fv(ltri[0]->v->co);
}
PASSATTRIB(ltri[1], ltri[1]->v, 1);
if (vertexCos) {
- glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
}
else {
- glNormal3fv(ltri[1]->v->no);
- glVertex3fv(ltri[1]->v->co);
+ gpuNormal3fv(ltri[1]->v->no);
+ gpuVertex3fv(ltri[1]->v->co);
}
PASSATTRIB(ltri[2], ltri[2]->v, 2);
if (vertexCos) {
- glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
+ gpuNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
+ gpuVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
}
else {
- glNormal3fv(ltri[2]->v->no);
- glVertex3fv(ltri[2]->v->co);
+ gpuNormal3fv(ltri[2]->v->no);
+ gpuVertex3fv(ltri[2]->v->co);
}
}
- glEnd();
+ gpuEnd();
}
#undef PASSATTRIB
}