Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/cdderivedmesh.c
| Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_curve_types.h" /* for Curve */ | #include "DNA_curve_types.h" /* for Curve */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "GPU_buffers.h" | #include "GPU_buffers.h" | ||||
| #include "GPU_draw.h" | #include "GPU_draw.h" | ||||
| #include "GPU_glew.h" | #include "GPU_glew.h" | ||||
| #include "GPU_legacy_stubs.h" | |||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_basic_shader.h" | #include "GPU_basic_shader.h" | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <limits.h> | #include <limits.h> | ||||
| #include <math.h> | #include <math.h> | ||||
| typedef struct { | typedef struct { | ||||
| ▲ Show 20 Lines • Show All 755 Lines • ▼ Show 20 Lines | |||||
| static void cddm_draw_attrib_vertex( | static void cddm_draw_attrib_vertex( | ||||
| DMVertexAttribs *attribs, const MVert *mvert, int a, int index, int loop, int vert, | DMVertexAttribs *attribs, const MVert *mvert, int a, int index, int loop, int vert, | ||||
| const float *lnor, const bool smoothnormal) | const float *lnor, const bool smoothnormal) | ||||
| { | { | ||||
| DM_draw_attrib_vertex(attribs, a, index, vert, loop); | DM_draw_attrib_vertex(attribs, a, index, vert, loop); | ||||
| /* vertex normal */ | /* vertex normal */ | ||||
| if (lnor) { | if (lnor) { | ||||
| glNormal3fv(lnor); | oldNormal3fv(lnor); | ||||
| } | } | ||||
| else if (smoothnormal) { | else if (smoothnormal) { | ||||
| glNormal3sv(mvert[index].no); | oldNormal3sv(mvert[index].no); | ||||
| } | } | ||||
| /* vertex coordinate */ | /* vertex coordinate */ | ||||
| glVertex3fv(mvert[index].co); | oldVertex3fv(mvert[index].co); | ||||
| } | } | ||||
| typedef struct { | typedef struct { | ||||
| DMVertexAttribs attribs; | DMVertexAttribs attribs; | ||||
| int numdata; | int numdata; | ||||
| GPUAttrib datatypes[GPU_MAX_ATTRIB]; /* TODO, messing up when switching materials many times - [#21056]*/ | GPUAttrib datatypes[GPU_MAX_ATTRIB]; /* TODO, messing up when switching materials many times - [#21056]*/ | ||||
| } GPUMaterialConv; | } GPUMaterialConv; | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | static void cdDM_drawMappedFacesGLSL( | ||||
| matnr = -1; | matnr = -1; | ||||
| do_draw = false; | do_draw = false; | ||||
| if (setDrawOptions != NULL) { | if (setDrawOptions != NULL) { | ||||
| DMVertexAttribs attribs; | DMVertexAttribs attribs; | ||||
| DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n"); | DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n"); | ||||
| memset(&attribs, 0, sizeof(attribs)); | memset(&attribs, 0, sizeof(attribs)); | ||||
| glBegin(GL_TRIANGLES); | oldBegin(GL_TRIANGLES); | ||||
| for (a = 0; a < tottri; a++, lt++) { | for (a = 0; a < tottri; a++, lt++) { | ||||
| const MPoly *mp = &mpoly[lt->poly]; | const MPoly *mp = &mpoly[lt->poly]; | ||||
| const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v}; | const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v}; | ||||
| const unsigned int *ltri = lt->tri; | const unsigned int *ltri = lt->tri; | ||||
| const float *ln1 = NULL, *ln2 = NULL, *ln3 = NULL; | const float *ln1 = NULL, *ln2 = NULL, *ln3 = NULL; | ||||
| const bool smoothnormal = lnors || (mp->flag & ME_SMOOTH); | const bool smoothnormal = lnors || (mp->flag & ME_SMOOTH); | ||||
| new_matnr = mp->mat_nr; | new_matnr = mp->mat_nr; | ||||
| if (new_matnr != matnr) { | if (new_matnr != matnr) { | ||||
| glEnd(); | oldEnd(); | ||||
| matnr = new_matnr; | matnr = new_matnr; | ||||
| do_draw = setMaterial(matnr + 1, &gattribs); | do_draw = setMaterial(matnr + 1, &gattribs); | ||||
| if (do_draw) { | if (do_draw) { | ||||
| DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs); | DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs); | ||||
| DM_draw_attrib_vertex_uniforms(&attribs); | DM_draw_attrib_vertex_uniforms(&attribs); | ||||
| } | } | ||||
| glBegin(GL_TRIANGLES); | oldBegin(GL_TRIANGLES); | ||||
| } | } | ||||
| if (!do_draw) { | if (!do_draw) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| else /* if (setDrawOptions) */ { | else /* if (setDrawOptions) */ { | ||||
| orig = (index_mp_to_orig) ? index_mp_to_orig[lt->poly] : lt->poly; | orig = (index_mp_to_orig) ? index_mp_to_orig[lt->poly] : lt->poly; | ||||
| if (orig == ORIGINDEX_NONE) { | if (orig == ORIGINDEX_NONE) { | ||||
| /* since the material is set by setMaterial(), faces with no | /* since the material is set by setMaterial(), faces with no | ||||
| * origin can be assumed to be generated by a modifier */ | * origin can be assumed to be generated by a modifier */ | ||||
| /* continue */ | /* continue */ | ||||
| } | } | ||||
| else if (setDrawOptions(userData, orig) == DM_DRAW_OPTION_SKIP) | else if (setDrawOptions(userData, orig) == DM_DRAW_OPTION_SKIP) | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!smoothnormal) { | if (!smoothnormal) { | ||||
| if (nors) { | if (nors) { | ||||
| glNormal3fv(nors[lt->poly]); | oldNormal3fv(nors[lt->poly]); | ||||
| } | } | ||||
| else { | else { | ||||
| /* TODO ideally a normal layer should always be available */ | /* TODO ideally a normal layer should always be available */ | ||||
| float nor[3]; | float nor[3]; | ||||
| normal_tri_v3(nor, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co); | normal_tri_v3(nor, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co); | ||||
| glNormal3fv(nor); | oldNormal3fv(nor); | ||||
| } | } | ||||
| } | } | ||||
| else if (lnors) { | else if (lnors) { | ||||
| ln1 = lnors[ltri[0]]; | ln1 = lnors[ltri[0]]; | ||||
| ln2 = lnors[ltri[1]]; | ln2 = lnors[ltri[1]]; | ||||
| ln3 = lnors[ltri[2]]; | ln3 = lnors[ltri[2]]; | ||||
| } | } | ||||
| cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[0], ltri[0], 0, ln1, smoothnormal); | cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[0], ltri[0], 0, ln1, smoothnormal); | ||||
| cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[1], ltri[1], 1, ln2, smoothnormal); | cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[1], ltri[1], 1, ln2, smoothnormal); | ||||
| cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal); | cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal); | ||||
| } | } | ||||
| glEnd(); | oldEnd(); | ||||
| } | } | ||||
| else { | else { | ||||
| GPUMaterialConv *matconv; | GPUMaterialConv *matconv; | ||||
| int offset; | int offset; | ||||
| int *mat_orig_to_new; | int *mat_orig_to_new; | ||||
| int tot_active_mat; | int tot_active_mat; | ||||
| GPUBuffer *buffer = NULL; | GPUBuffer *buffer = NULL; | ||||
| unsigned char *varray; | unsigned char *varray; | ||||
| ▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | else { | ||||
| cdDM_update_normals_from_pbvh(dm); | cdDM_update_normals_from_pbvh(dm); | ||||
| } | } | ||||
| } | } | ||||
| matnr = -1; | matnr = -1; | ||||
| memset(&attribs, 0, sizeof(attribs)); | memset(&attribs, 0, sizeof(attribs)); | ||||
| glBegin(GL_TRIANGLES); | oldBegin(GL_TRIANGLES); | ||||
| for (a = 0; a < tottri; a++, lt++) { | for (a = 0; a < tottri; a++, lt++) { | ||||
| const MPoly *mp = &mpoly[lt->poly]; | const MPoly *mp = &mpoly[lt->poly]; | ||||
| const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v}; | const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v}; | ||||
| const unsigned int *ltri = lt->tri; | const unsigned int *ltri = lt->tri; | ||||
| const bool smoothnormal = lnors || (mp->flag & ME_SMOOTH); | const bool smoothnormal = lnors || (mp->flag & ME_SMOOTH); | ||||
| const float *ln1 = NULL, *ln2 = NULL, *ln3 = NULL; | const float *ln1 = NULL, *ln2 = NULL, *ln3 = NULL; | ||||
| /* material */ | /* material */ | ||||
| new_matnr = mp->mat_nr + 1; | new_matnr = mp->mat_nr + 1; | ||||
| if (new_matnr != matnr) { | if (new_matnr != matnr) { | ||||
| glEnd(); | oldEnd(); | ||||
| setMaterial(userData, matnr = new_matnr, &gattribs); | setMaterial(userData, matnr = new_matnr, &gattribs); | ||||
| DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs); | DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs); | ||||
| DM_draw_attrib_vertex_uniforms(&attribs); | DM_draw_attrib_vertex_uniforms(&attribs); | ||||
| glBegin(GL_TRIANGLES); | oldBegin(GL_TRIANGLES); | ||||
| } | } | ||||
| /* skipping faces */ | /* skipping faces */ | ||||
| if (setFace) { | if (setFace) { | ||||
| orig = (index_mp_to_orig) ? index_mp_to_orig[lt->poly] : lt->poly; | orig = (index_mp_to_orig) ? index_mp_to_orig[lt->poly] : lt->poly; | ||||
| if (orig != ORIGINDEX_NONE && !setFace(userData, orig)) | if (orig != ORIGINDEX_NONE && !setFace(userData, orig)) | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* smooth normal */ | /* smooth normal */ | ||||
| if (!smoothnormal) { | if (!smoothnormal) { | ||||
| if (nors) { | if (nors) { | ||||
| glNormal3fv(nors[lt->poly]); | oldNormal3fv(nors[lt->poly]); | ||||
| } | } | ||||
| else { | else { | ||||
| /* TODO ideally a normal layer should always be available */ | /* TODO ideally a normal layer should always be available */ | ||||
| float nor[3]; | float nor[3]; | ||||
| normal_tri_v3(nor, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co); | normal_tri_v3(nor, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co); | ||||
| glNormal3fv(nor); | oldNormal3fv(nor); | ||||
| } | } | ||||
| } | } | ||||
| else if (lnors) { | else if (lnors) { | ||||
| ln1 = lnors[ltri[0]]; | ln1 = lnors[ltri[0]]; | ||||
| ln2 = lnors[ltri[1]]; | ln2 = lnors[ltri[1]]; | ||||
| ln3 = lnors[ltri[2]]; | ln3 = lnors[ltri[2]]; | ||||
| } | } | ||||
| /* vertices */ | /* vertices */ | ||||
| cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[0], ltri[0], 0, ln1, smoothnormal); | cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[0], ltri[0], 0, ln1, smoothnormal); | ||||
| cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[1], ltri[1], 1, ln2, smoothnormal); | cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[1], ltri[1], 1, ln2, smoothnormal); | ||||
| cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal); | cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal); | ||||
| } | } | ||||
| glEnd(); | oldEnd(); | ||||
| } | } | ||||
| static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData) | static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData) | ||||
| { | { | ||||
| CDDerivedMesh *cddm = (CDDerivedMesh *) dm; | CDDerivedMesh *cddm = (CDDerivedMesh *) dm; | ||||
| MVert *vert = cddm->mvert; | MVert *vert = cddm->mvert; | ||||
| MEdge *edge = cddm->medge; | MEdge *edge = cddm->medge; | ||||
| int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX); | int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX); | ||||
| glBegin(GL_LINES); | oldBegin(GL_LINES); | ||||
| for (i = 0; i < dm->numEdgeData; i++, edge++) { | for (i = 0; i < dm->numEdgeData; i++, edge++) { | ||||
| if (index) { | if (index) { | ||||
| orig = *index++; | orig = *index++; | ||||
| if (setDrawOptions && orig == ORIGINDEX_NONE) continue; | if (setDrawOptions && orig == ORIGINDEX_NONE) continue; | ||||
| } | } | ||||
| else | else | ||||
| orig = i; | orig = i; | ||||
| if (!setDrawOptions || (setDrawOptions(userData, orig) != DM_DRAW_OPTION_SKIP)) { | if (!setDrawOptions || (setDrawOptions(userData, orig) != DM_DRAW_OPTION_SKIP)) { | ||||
| glVertex3fv(vert[edge->v1].co); | oldVertex3fv(vert[edge->v1].co); | ||||
| glVertex3fv(vert[edge->v2].co); | oldVertex3fv(vert[edge->v2].co); | ||||
| } | } | ||||
| } | } | ||||
| glEnd(); | oldEnd(); | ||||
| } | } | ||||
| typedef struct FaceCount { | typedef struct FaceCount { | ||||
| unsigned int i_visible; | unsigned int i_visible; | ||||
| unsigned int i_hidden; | unsigned int i_hidden; | ||||
| unsigned int i_tri_visible; | unsigned int i_tri_visible; | ||||
| unsigned int i_tri_hidden; | unsigned int i_tri_hidden; | ||||
| } FaceCount; | } FaceCount; | ||||
| ▲ Show 20 Lines • Show All 2,348 Lines • Show Last 20 Lines | |||||