diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-03-16 07:05:05 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-03-16 07:05:05 +0300 |
commit | 0fc4cf7637e8663aab695b2c33a6695f0604334f (patch) | |
tree | 258544a55422507b47e8828fb1497d8a339fc2d4 /source/blender/blenkernel/intern/DerivedMesh.c | |
parent | 0895550d24343e68c3773cae05978be13993ef8c (diff) |
OpenGL: draw navmesh with new imm mode
This is an old stash. Part of DerivedMesh so the whole thing might be removed soon.
part of T49043
Diffstat (limited to 'source/blender/blenkernel/intern/DerivedMesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 39f1db0b886..9022faba181 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -76,8 +76,8 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm); #include "BLI_sys_types.h" /* for intptr_t support */ #include "GPU_buffers.h" -#include "GPU_glew.h" #include "GPU_shader.h" +#include "GPU_immediate.h" #ifdef WITH_OPENSUBDIV # include "BKE_depsgraph.h" @@ -3937,7 +3937,6 @@ BLI_INLINE void navmesh_intToCol(int i, float col[3]) static void navmesh_drawColored(DerivedMesh *dm) { - int a, glmode; MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT); MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE); int *polygonIdx = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST); @@ -3952,34 +3951,42 @@ static void navmesh_drawColored(DerivedMesh *dm) dm->drawEdges(dm, 0, 1); #endif - /* if (GPU_buffer_legacy(dm) ) */ /* TODO - VBO draw code, not high priority - campbell */ - { - DEBUG_VBO("Using legacy code. drawNavMeshColored\n"); - glBegin(glmode = GL_QUADS); - for (a = 0; a < dm->numTessFaceData; a++, mface++) { - int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES; - int pi = polygonIdx[a]; - if (pi <= 0) { - zero_v3(col); - } - else { - navmesh_intToCol(pi, col); - } + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT); + unsigned color = add_attrib(format, "color", COMP_F32, 3, KEEP_FLOAT); - if (new_glmode != glmode) { - glEnd(); - glBegin(glmode = new_glmode); - } - glColor3fv(col); - glVertex3fv(mvert[mface->v1].co); - glVertex3fv(mvert[mface->v2].co); - glVertex3fv(mvert[mface->v3].co); - if (mface->v4) { - glVertex3fv(mvert[mface->v4].co); - } + immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR); + + /* Note: batch drawing API would let us share vertices */ + immBeginAtMost(PRIM_TRIANGLES, dm->numTessFaceData * 6); + for (int a = 0; a < dm->numTessFaceData; a++, mface++) { + int pi = polygonIdx[a]; + if (pi <= 0) { + zero_v3(col); + } + else { + navmesh_intToCol(pi, col); + } + + immSkipAttrib(color); + immVertex3fv(pos, mvert[mface->v1].co); + immSkipAttrib(color); + immVertex3fv(pos, mvert[mface->v2].co); + immAttrib3fv(color, col); + immVertex3fv(pos, mvert[mface->v3].co); + + if (mface->v4) { + /* this tess face is a quad, so draw the other triangle */ + immSkipAttrib(color); + immVertex3fv(pos, mvert[mface->v1].co); + immSkipAttrib(color); + immVertex3fv(pos, mvert[mface->v3].co); + immAttrib3fv(color, col); + immVertex3fv(pos, mvert[mface->v4].co); } - glEnd(); } + immEnd(); + immUnbindProgram(); } static void navmesh_DM_drawFacesTex( |