diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 17:41:00 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:18:11 +0300 |
commit | d140e70c496122915eb5c05aba83153e2e0d7998 (patch) | |
tree | 1e589247d69da64aa7b0e7802319237ec050b5d6 /source/blender/gpu/intern/gpu_buffers.c | |
parent | 147bd16ed1bb3415b30408b0eab110d0854eadd2 (diff) | |
parent | 295d0c52a26730edc6d4ed1276e4051cce006be5 (diff) |
Merge branch 'master' into temp-ghash-experimentstemp-ghash-experiments
Note that 'store hash' feature was removed for now - to complex to maintain (conflicts)
and relatively easy to re-add if we ever really want this one day.
Conflicts:
source/blender/blenlib/BLI_ghash.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/hash_mm2a.c
source/blender/bmesh/tools/bmesh_region_match.c
tests/gtests/blenlib/BLI_ghash_performance_test.cc
tests/gtests/blenlib/BLI_ghash_test.cc
tests/gtests/blenlib/CMakeLists.txt
Diffstat (limited to 'source/blender/gpu/intern/gpu_buffers.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 248 |
1 files changed, 148 insertions, 100 deletions
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index e622943597a..62843f0905f 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -383,8 +383,9 @@ void GPU_buffer_free(GPUBuffer *buffer) BLI_mutex_unlock(&buffer_mutex); } -/* currently unused */ -// #define USE_GPU_POINT_LINK +#if 0 /* currently unused */ +# define USE_GPU_POINT_LINK +#endif typedef struct GPUVertPointLink { #ifdef USE_GPU_POINT_LINK @@ -452,7 +453,7 @@ static void gpu_drawobject_init_vert_points(GPUDrawObject *gdo, MFace *f, int to int i, *mat_orig_to_new; mat_orig_to_new = MEM_callocN(sizeof(*mat_orig_to_new) * totmat, - "GPUDrawObject.mat_orig_to_new"); + "GPUDrawObject.mat_orig_to_new"); /* allocate the array and space for links */ gdo->vert_points = MEM_mallocN(sizeof(GPUVertPointLink) * gdo->totvert, "GPUDrawObject.vert_points"); @@ -939,17 +940,62 @@ static void GPU_buffer_copy_mcol(DerivedMesh *dm, float *varray_, int *index, in static void GPU_buffer_copy_edge(DerivedMesh *dm, float *varray_, int *UNUSED(index), int *UNUSED(mat_orig_to_new), void *UNUSED(user)) { - MEdge *medge; + MEdge *medge, *medge_base; unsigned int *varray = (unsigned int *)varray_; - int i, totedge; + int i, totedge, iloose, inorm, iloosehidden, inormhidden; + int tot_loose_hidden = 0, tot_loose = 0; + int tot_hidden = 0, tot = 0; - medge = dm->getEdgeArray(dm); + medge_base = medge = dm->getEdgeArray(dm); totedge = dm->getNumEdges(dm); for (i = 0; i < totedge; i++, medge++) { - varray[i * 2] = dm->drawObject->vert_points[medge->v1].point_index; - varray[i * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index; + if (medge->flag & ME_EDGEDRAW) { + if (medge->flag & ME_LOOSEEDGE) tot_loose++; + else tot++; + } + else { + if (medge->flag & ME_LOOSEEDGE) tot_loose_hidden++; + else tot_hidden++; + } + } + + inorm = 0; + inormhidden = tot; + iloose = tot + tot_hidden; + iloosehidden = iloose + tot_loose; + + medge = medge_base; + for (i = 0; i < totedge; i++, medge++) { + if (medge->flag & ME_EDGEDRAW) { + if (medge->flag & ME_LOOSEEDGE) { + varray[iloose * 2] = dm->drawObject->vert_points[medge->v1].point_index; + varray[iloose * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index; + iloose++; + } + else { + varray[inorm * 2] = dm->drawObject->vert_points[medge->v1].point_index; + varray[inorm * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index; + inorm++; + } + } + else { + if (medge->flag & ME_LOOSEEDGE) { + varray[iloosehidden * 2] = dm->drawObject->vert_points[medge->v1].point_index; + varray[iloosehidden * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index; + iloosehidden++; + } + else { + varray[inormhidden * 2] = dm->drawObject->vert_points[medge->v1].point_index; + varray[inormhidden * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index; + inormhidden++; + } + } } + + dm->drawObject->tot_loose_edge_drawn = tot_loose; + dm->drawObject->loose_edge_offset = tot + tot_hidden; + dm->drawObject->tot_edge_drawn = tot; } static void GPU_buffer_copy_uvedge(DerivedMesh *dm, float *varray, int *UNUSED(index), int *UNUSED(mat_orig_to_new), void *UNUSED(user)) @@ -1007,7 +1053,7 @@ const GPUBufferTypeSettings gpu_buffer_type_settings[] = { {GPU_buffer_copy_normal, GL_ARRAY_BUFFER_ARB, 3}, {GPU_buffer_copy_mcol, GL_ARRAY_BUFFER_ARB, 3}, {GPU_buffer_copy_uv, GL_ARRAY_BUFFER_ARB, 2}, - {GPU_buffer_copy_uv_texpaint, GL_ARRAY_BUFFER_ARB, 4}, + {GPU_buffer_copy_uv_texpaint, GL_ARRAY_BUFFER_ARB, 4}, {GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER_ARB, 2}, {GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER_ARB, 4} }; @@ -1498,6 +1544,7 @@ struct GPU_PBVH_Buffers { bool use_matcaps; float diffuse_color[4]; }; + typedef enum { VBO_ENABLED, VBO_DISABLED @@ -1577,8 +1624,8 @@ static void gpu_color_from_mask_quad_set(const CCGKey *key, } void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert, - int *vert_indices, int totvert, const float *vmask, - int (*face_vert_indices)[4], bool show_diffuse_color) + int *vert_indices, int totvert, const float *vmask, + int (*face_vert_indices)[4], bool show_diffuse_color) { VertexBufferFormat *vert_data; int i, j, k; @@ -1715,9 +1762,9 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert, } GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4], - MFace *mface, MVert *mvert, - int *face_indices, - int totface) + MFace *mface, MVert *mvert, + int *face_indices, + int totface) { GPU_PBVH_Buffers *buffers; unsigned short *tri_data; @@ -1807,8 +1854,8 @@ GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4], } void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids, - const DMFlagMat *grid_flag_mats, int *grid_indices, - int totgrid, const CCGKey *key, bool show_diffuse_color) + const DMFlagMat *grid_flag_mats, int *grid_indices, + int totgrid, const CCGKey *key, bool show_diffuse_color) { VertexBufferFormat *vert_data; int i, j, k, x, y; @@ -1921,51 +1968,51 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids, /* Build the element array buffer of grid indices using either * unsigned shorts or unsigned ints. */ #define FILL_QUAD_BUFFER(type_, tot_quad_, buffer_) \ - { \ - type_ *tri_data; \ - int offset = 0; \ - int i, j, k; \ - \ - glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ - sizeof(type_) * (tot_quad_) * 6, NULL, \ - GL_STATIC_DRAW_ARB); \ - \ - /* Fill the buffer */ \ - tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ - GL_WRITE_ONLY_ARB); \ - if (tri_data) { \ - for (i = 0; i < totgrid; ++i) { \ - BLI_bitmap *gh = NULL; \ - if (grid_hidden) \ - gh = grid_hidden[(grid_indices)[i]]; \ - \ - for (j = 0; j < gridsize - 1; ++j) { \ - for (k = 0; k < gridsize - 1; ++k) { \ - /* Skip hidden grid face */ \ - if (gh && \ - paint_is_grid_face_hidden(gh, \ - gridsize, k, j)) \ - continue; \ - \ - *(tri_data++) = offset + j * gridsize + k + 1; \ - *(tri_data++) = offset + j * gridsize + k; \ - *(tri_data++) = offset + (j + 1) * gridsize + k; \ - \ - *(tri_data++) = offset + (j + 1) * gridsize + k + 1; \ - *(tri_data++) = offset + j * gridsize + k + 1; \ - *(tri_data++) = offset + (j + 1) * gridsize + k; \ - } \ - } \ - \ - offset += gridsize * gridsize; \ - } \ - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \ - } \ - else { \ - glDeleteBuffersARB(1, &(buffer_)); \ - (buffer_) = 0; \ - } \ - } (void)0 + { \ + type_ *tri_data; \ + int offset = 0; \ + int i, j, k; \ + \ + glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ + sizeof(type_) * (tot_quad_) * 6, NULL, \ + GL_STATIC_DRAW_ARB); \ + \ + /* Fill the buffer */ \ + tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ + GL_WRITE_ONLY_ARB); \ + if (tri_data) { \ + for (i = 0; i < totgrid; ++i) { \ + BLI_bitmap *gh = NULL; \ + if (grid_hidden) \ + gh = grid_hidden[(grid_indices)[i]]; \ + \ + for (j = 0; j < gridsize - 1; ++j) { \ + for (k = 0; k < gridsize - 1; ++k) { \ + /* Skip hidden grid face */ \ + if (gh && \ + paint_is_grid_face_hidden(gh, \ + gridsize, k, j)) \ + continue; \ + \ + *(tri_data++) = offset + j * gridsize + k + 1; \ + *(tri_data++) = offset + j * gridsize + k; \ + *(tri_data++) = offset + (j + 1) * gridsize + k; \ + \ + *(tri_data++) = offset + (j + 1) * gridsize + k + 1; \ + *(tri_data++) = offset + j * gridsize + k + 1; \ + *(tri_data++) = offset + (j + 1) * gridsize + k; \ + } \ + } \ + \ + offset += gridsize * gridsize; \ + } \ + glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \ + } \ + else { \ + glDeleteBuffersARB(1, &(buffer_)); \ + (buffer_) = 0; \ + } \ + } (void)0 /* end FILL_QUAD_BUFFER */ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *totquad) @@ -2021,7 +2068,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to } GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid, - BLI_bitmap **grid_hidden, int gridsize) + BLI_bitmap **grid_hidden, int gridsize) { GPU_PBVH_Buffers *buffers; int totquad; @@ -2103,7 +2150,6 @@ static void gpu_bmesh_vert_to_buffer_copy(BMVert *v, BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset), diffuse_color, vd->color); - /* Assign index for use in the triangle index buffer */ /* note: caller must set: bm->elem_index_dirty |= BM_VERT; */ @@ -2153,11 +2199,11 @@ static int gpu_bmesh_face_visible_count(GSet *bm_faces) /* Creates a vertex buffer (coordinate, normal, color) and, if smooth * shading, an element index buffer. */ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, - BMesh *bm, - GSet *bm_faces, - GSet *bm_unique_verts, - GSet *bm_other_verts, - bool show_diffuse_color) + BMesh *bm, + GSet *bm_faces, + GSet *bm_unique_verts, + GSet *bm_other_verts, + bool show_diffuse_color) { VertexBufferFormat *vert_data; void *tri_data; @@ -2204,8 +2250,8 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, /* Initialize vertex buffer */ glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); glBufferDataARB(GL_ARRAY_BUFFER_ARB, - sizeof(VertexBufferFormat) * totvert, - NULL, GL_STATIC_DRAW_ARB); + sizeof(VertexBufferFormat) * totvert, + NULL, GL_STATIC_DRAW_ARB); /* Fill vertex buffer */ vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); @@ -2246,7 +2292,9 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, float fmask = 0; int i; - // BM_iter_as_array(bm, BM_VERTS_OF_FACE, f, (void**)v, 3); +#if 0 + BM_iter_as_array(bm, BM_VERTS_OF_FACE, f, (void**)v, 3); +#endif BM_face_as_array_vert_tri(f, v); /* Average mask value */ @@ -2666,7 +2714,7 @@ bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, GSet *bm_faces, GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color); } else if (buffers->use_bmesh) { - /* due to dynamc nature of dyntopo, only get first material */ + /* due to dynamic nature of dyntopo, only get first material */ if (BLI_gset_size(bm_faces) > 0) { GSetIterator gs_iter; BMFace *f; @@ -2717,7 +2765,7 @@ static void gpu_pbvh_buffer_free_intern(GLuint id) if (pool->maxpbvhsize == pool->totpbvhbufids) { pool->maxpbvhsize += MAX_FREE_GPU_BUFF_IDS; pool->pbvhbufids = MEM_reallocN(pool->pbvhbufids, - sizeof(*pool->pbvhbufids) * pool->maxpbvhsize); + sizeof(*pool->pbvhbufids) * pool->maxpbvhsize); } /* insert the buffer into the beginning of the pool */ @@ -2742,33 +2790,33 @@ void GPU_free_pbvh_buffers(GPU_PBVH_Buffers *buffers) void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf) { const float quads[4][4][3] = { - { - {min[0], min[1], min[2]}, - {max[0], min[1], min[2]}, - {max[0], min[1], max[2]}, - {min[0], min[1], max[2]} - }, - - { - {min[0], min[1], min[2]}, - {min[0], max[1], min[2]}, - {min[0], max[1], max[2]}, - {min[0], min[1], max[2]} - }, - - { - {max[0], max[1], min[2]}, - {max[0], min[1], min[2]}, - {max[0], min[1], max[2]}, - {max[0], max[1], max[2]} - }, - - { - {max[0], max[1], min[2]}, - {min[0], max[1], min[2]}, - {min[0], max[1], max[2]}, - {max[0], max[1], max[2]} - }, + { + {min[0], min[1], min[2]}, + {max[0], min[1], min[2]}, + {max[0], min[1], max[2]}, + {min[0], min[1], max[2]} + }, + + { + {min[0], min[1], min[2]}, + {min[0], max[1], min[2]}, + {min[0], max[1], max[2]}, + {min[0], min[1], max[2]} + }, + + { + {max[0], max[1], min[2]}, + {max[0], min[1], min[2]}, + {max[0], min[1], max[2]}, + {max[0], max[1], max[2]} + }, + + { + {max[0], max[1], min[2]}, + {min[0], max[1], min[2]}, + {min[0], max[1], max[2]}, + {max[0], max[1], max[2]} + }, }; if (leaf) |