1
1

Compare commits

...

57 Commits

Author SHA1 Message Date
1a5777fd5e Fix compilation 2016-09-09 23:59:55 +02:00
ab7d449299 Merge branch 'master' into temp_display_optimization 2016-09-09 23:14:13 +02:00
Julian Eisel
5c706c6496 Merge branch 'master' into temp_display_optimization 2016-04-18 21:15:47 +02:00
a3762f1fab Define GPU buffer streams for material/ui data.
Declare UV/Normal/Color buffers as deprecated. We will prefer
unified interleaved formats if we need to.

vertex format stays separate because it is needed for passes
like shadow map or edge pass or uv drawing.
2016-03-12 12:33:15 +01:00
Antony Ryakiotakis
7fa7a0b703 WIP: Add some structs for vertex format of derivedmeshes. 2016-03-11 23:57:33 +01:00
Antony Ryakiotakis
a728572ce6 Merge branch 'master' into HEAD 2016-03-11 22:15:23 +01:00
c54b44592b Merge branch 'master' into temp_display_optimization 2015-12-28 20:55:01 +01:00
3b3cd248db editmesh VBO: support deformed vertex coordinates too. 2015-12-27 20:55:42 +01:00
613d505eab Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/blenkernel/intern/editderivedmesh.c
2015-12-27 20:18:15 +01:00
f713f39182 Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/blenkernel/intern/editderivedmesh.c
	source/blender/gpu/intern/gpu_buffers.c
2015-12-06 23:53:58 +01:00
d8dd5fa42c Merge branch 'master' into temp_display_optimization 2015-11-15 21:01:47 +01:00
fa05817bb5 Merge branch 'master' into temp_display_optimization 2015-10-20 22:32:53 +03:00
7b8d680064 Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/gpu/intern/gpu_buffers.c
2015-10-16 13:42:37 +03:00
8471b7145a WIP editmode colors 2015-07-30 12:41:31 +02:00
5b316690ed Merge branch 'master' into temp_display_optimization 2015-07-29 16:37:43 +02:00
388695b1f0 Mapped face selection uses VBOs properly now 2015-07-28 18:21:35 +02:00
9074d9572e Edit mode drawing
Draw all materials of the mesh
Don't display hidden triangles.
2015-07-28 17:52:45 +02:00
25d86e4459 First basic GPU upload for edit derived meshes.
Normals, coordinates and triangles work.
2015-07-28 16:58:59 +02:00
e9c7e0ee8c Merge branch 'master' into temp_display_optimization 2015-07-28 16:58:38 +02:00
e41731286e Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/blenkernel/BKE_DerivedMesh.h
	source/blender/blenkernel/intern/cdderivedmesh.c
	source/blender/windowmanager/intern/wm_subwindow.c
2015-07-24 17:45:51 +02:00
0b48bfae87 Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/blenkernel/intern/cdderivedmesh.c
2015-07-15 18:46:04 +02:00
eeb1d58167 Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/blenkernel/intern/cdderivedmesh.c
2015-07-14 23:56:43 +02:00
4f9b58cb71 VBO offscreen selection drawing, cdderivedmesh
Get rid of legacy drawing, it's only used for selection,
in which case we can prepare a temporary color buffer and draw
at once. Code is not complete here because we still redundantly
set the draw color in the draw function and don't ommit hidden
faces automatically. Still it works 100% without immediate mode
now.
2015-07-14 22:36:34 +02:00
94a6399a89 Merge branch 'master' into temp_display_optimization 2015-07-14 21:23:41 +02:00
f292199403 Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/blenkernel/intern/cdderivedmesh.c
	source/blender/blenkernel/intern/subsurf_ccg.c
2015-07-14 15:58:39 +02:00
05634836f0 Fast drawing for sculpting multires using VBOs (non VBO won't have
fast mode but will not spend time on that).

With this commit branch should be in full feature parity with master.
2015-07-14 15:26:37 +02:00
fb5ec0997e Subsurf drawing refactoring:
All textured drawing now works correctly using VBOs (with usual CPU
 overhead still, but this will be taken care of separately).
Solid texture painting should also work fine.
Renamed ccg GPU functions so they are more consistent with cddm
2015-07-14 12:28:07 +02:00
18b81af276 Merge branch 'master' into temp_display_optimization 2015-07-13 18:13:01 +02:00
43bf4a0f51 Bah, merge change that was left uncommitted 2015-07-12 16:40:47 +02:00
5a7b0cf1c7 Merge branch 'master' into temp_display_optimization
Conflicts:
	source/blender/gpu/intern/gpu_buffers.c
2015-07-12 16:26:12 +02:00
e8b187ca14 Merge branch 'master' into temp_display_optimization 2015-07-02 21:51:29 +02:00
2edc5b807b Use shorts for uploading normals to GPU instead of floats.
The range of shorts is acceptable for good looking
normals.

We allocate a buffer with 4 shorts to keep data aligned to 32bit
boundaries. The total mesh cost for full triangle meshes is now
equal to master branch even with index buffers and memory gains
are even more for ngons.
2015-07-01 12:16:03 +02:00
c255161468 Cleanup: Use GPU material counter instead of allocating new counter
array every time.
2015-06-30 18:51:15 +02:00
52187f826c Refactor subsurf multi material textured drawing.
Use the same system as cdderivermesh - still result is not correct
though.
2015-06-30 15:17:10 +02:00
9566b13672 GLSL fix one more error - meant that attributes would not get uploaded
correctly.
2015-06-30 12:22:53 +02:00
a5f03ee002 Merge branch 'master' into temp_display_optimization 2015-06-30 12:00:15 +02:00
60ad7c09c1 Temporarily fix crash until subsurf textured multi material is
completely supported.
2015-06-29 19:32:26 +02:00
09665a5301 GLSL drawing redesign:
Use new upload scheme. Idea here is that materials share a VBO where
the size of each element is the maximum size of all mesh materials.

While this will waste some size if material sizes differ it is the
simplest scheme to use and allows easy reuse of indices as opposed to
separating the materials in separate vertex buffers. In fact if we do
that, management gets quite complex and code much more error prone.

I may write an extra blog post to explain the choices here
at some point.
2015-06-29 17:18:39 +02:00
850e9ce176 Redesign of textured drawing: Get rid of triangle_to_mface array
Instead we can be smarter here and add an mface array to the
GPUBufferMaterial instead.
This will help us do less iterations on CPU for quad meshes as well as
avoiding checking materials every face (faces are now always sorted per
material so this happens implicitly).
2015-06-29 16:45:50 +02:00
a50de5fd94 Merge branch 'master' into temp_display_optimization 2015-06-27 17:21:12 +02:00
5d592a9686 Merge branch 'master' into temp_display_optimization 2015-06-26 17:51:41 +02:00
33ddcf4dc3 Fix crash in viewport benchmark file with GLSL
Total loops were calculated erroneously, probably due to ngon to loop
conversion.
2015-06-26 17:09:49 +02:00
1951604bab Make code compile with GPU_DEBUG 2015-06-26 16:18:06 +02:00
3351ab28d9 Merge branch 'master' into temp_display_optimization 2015-06-26 14:59:37 +02:00
43eabfe5b8 Fix error with vertex color upload for subsurf 2015-06-25 15:06:23 +02:00
8a077c90d2 Subsurf VBOs now properly supports colors 2015-06-24 18:44:33 +02:00
c314507cbf Semi fix UVs not working in higher level. Looks like issue is mesh
colors somehow being used. Disabled for now but real fix would be to
investigate why they are there in first place.
2015-06-24 17:27:39 +02:00
62f0f0607f First version of textured subsurf drawing with VBOs and index buffers.
TODOs:

* UVs fail for high subdivision
* Vertex colors still not supported
* Texture painting still not supported
2015-06-24 16:36:09 +02:00
188c1cc184 Fix crash reported on blenderartists
A really bad issue that meant we would miscount many mixed triangle/quad
meshes.
2015-06-24 11:58:12 +02:00
1b64055c2c WIP code that handles textured drawing for subsurf with vertex buffers. 2015-06-23 19:22:58 +02:00
4c553ce09f Merge branch 'master' into temp_display_optimization 2015-06-23 17:52:37 +02:00
d4ad7836b6 Subsurf drawing:
Solid shading uses indexed drawing (textured/GLSL drawing are still not
implemented).

For subsurf we might be able to squeeze more memory but it would only
work for smooth shading and it requires more elaborate counting for all
data upload functions. May be interesting to do in the future though.
2015-06-23 16:57:18 +02:00
21414b511f Cleanup: Use "elements", the OpenGL term instead of "points", makes it a
bit clearer what the use is intended for.
2015-06-23 12:26:31 +02:00
22f38137d7 Merge branch 'master' into temp_display_optimization 2015-06-23 12:07:05 +02:00
f018b99b51 Merge branch 'master' into temp_display_optimization 2015-06-23 11:28:53 +02:00
0c50ba7ec3 Use index buffers for drawing with vertex buffers.
Tests show that we gain approximately 20-25% performance
by that for solid mode drawing.

Good memory/performance is gained for quad meshes mostly
but we also gain performance in triangle meshes as well.

This commit will not get rid of the CPU overhead in
some modes (textured/GLSL) yet, but it prepares the
code for caching changes to make things better
.
2015-06-22 19:17:12 +02:00
530ee08e93 Port Subsurf to VBO code from GPUDataRequest branch.
This adds support for vertex buffers for solid shaded mode for subsurf
modifiers, making drawing of subsurf much faster in this mode.

It also moves towards the goal of data driven requests for our new
renderer system, but this will need further changes down the line.

Everything should work as before with the exception of simplified
multires drawing in sculpting (feature enabled while rotating the view).
2015-06-22 15:57:04 +02:00
6 changed files with 378 additions and 10 deletions

View File

@@ -153,7 +153,7 @@ typedef enum DMDrawFlag {
DM_DRAW_SKIP_HIDDEN = (1 << 4),
DM_DRAW_SKIP_SELECT = (1 << 5),
DM_DRAW_SELECT_USE_EDITMODE = (1 << 6),
DM_DRAW_NEED_NORMALS = (1 << 7)
DM_DRAW_NEED_NORMALS = (1 << 7),
} DMDrawFlag;
typedef enum DMForeachFlag {

View File

@@ -416,7 +416,7 @@ static void cdDM_drawEdges(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEdg
GPU_edge_setup(dm);
gdo = dm->drawObject;
if (gdo->edges && gdo->points) {
if (gdo->edges && gdo->vertices) {
if (drawAllEdges && drawLooseEdges) {
GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->totedge * 2);
}

View File

@@ -51,15 +51,19 @@
#include "BKE_editmesh.h"
#include "BKE_editmesh_bvh.h"
#include "BKE_global.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "MEM_guardedalloc.h"
#include "GPU_buffers.h"
#include "GPU_glew.h"
#include "GPU_buffers.h"
#include "GPU_shader.h"
#include "GPU_basic_shader.h"
#include "GPU_draw.h"
static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4]);
@@ -726,6 +730,256 @@ static void emDM_foreachMappedEdge(
}
}
static void emDM_buffer_copy_vertex(
DerivedMesh *dm, float *varray)
{
BMIter iter, iterv;
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMEditMesh *em = bmdm->em;
BMesh *bm = em->bm;
BMVert *v;
BMFace *efa;
int start = 0;
/* use deformed vertices instead if they exist */
const float (*vertexCos)[3] = bmdm->vertexCos;
BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
BM_ITER_ELEM(v, &iterv, efa, BM_VERTS_OF_FACE) {
if (vertexCos)
copy_v3_v3(&varray[start], vertexCos[BM_elem_index_get(v)]);
else
copy_v3_v3(&varray[start], v->co);
start += 3;
}
}
/* copy loose points
j = dm->drawObject->tot_loop_verts * 3;
for (i = 0; i < dm->drawObject->totvert; i++) {
if (dm->drawObject->vert_points[i].point_index >= dm->drawObject->tot_loop_verts) {
copy_v3_v3(&varray[j], mvert[i].co);
j += 3;
}
}
*/
}
static void emDM_buffer_copy_normal(
DerivedMesh *dm, short *varray)
{
BMIter iter, iterl;
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMEditMesh *em = bmdm->em;
BMesh *bm = em->bm;
BMLoop *l;
BMFace *efa;
int i;
int start;
const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
const float (*polyNos)[3] = NULL;
const float (*vertexNos)[3] = NULL;
if (bmdm->vertexCos) {
emDM_ensureVertNormals(bmdm);
emDM_ensurePolyNormals(bmdm);
polyNos = bmdm->polyNos;
vertexNos = bmdm->vertexNos;
}
start = 0;
BM_ITER_MESH_INDEX(efa, &iter, bm, BM_FACES_OF_MESH, i) {
const bool smoothnormal = BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
BM_ITER_ELEM(l, &iterl, efa, BM_LOOPS_OF_FACE) {
if (lnors) {
/* Copy loop normals */
normal_float_to_short_v3(&varray[start], lnors[BM_elem_index_get(l)]);
}
else if (smoothnormal) {
/* Copy vertex normal */
if (vertexNos)
normal_float_to_short_v3(&varray[start], vertexNos[BM_elem_index_get(l->v)]);
else
normal_float_to_short_v3(&varray[start], l->v->no);
}
else {
if (polyNos)
normal_float_to_short_v3(&varray[start], polyNos[i]);
else
normal_float_to_short_v3(&varray[start], efa->no);
}
start += 4;
}
}
}
typedef struct FaceCount {
unsigned int i_selected;
unsigned int i_visible;
unsigned int i_hidden;
unsigned int i_tri_visible;
unsigned int i_tri_hidden;
} FaceCount;
static void emDM_buffer_copy_triangles(
DerivedMesh *dm, unsigned int *varray,
const int *mat_orig_to_new)
{
GPUBufferMaterial *gpumat, *gpumaterials = dm->drawObject->materials;
int i, j, start;
BMIter iter;
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMEditMesh *em = bmdm->em;
BMesh *bm = em->bm;
BMLoop *(*lt)[3] = bmdm->em->looptris;
BMFace *efa;
const int totmat = dm->drawObject->totmaterial;
FaceCount *fc = MEM_mallocN(sizeof(*fc) * totmat, "gpumaterial.facecount");
for (i = 0; i < totmat; i++) {
fc[i].i_selected = 0;
fc[i].i_visible = 0;
fc[i].i_tri_visible = 0;
fc[i].i_hidden = gpumaterials[i].totpolys - 1;
fc[i].i_tri_hidden = gpumaterials[i].totelements - 1;
}
BM_mesh_elem_index_ensure(bm, BM_LOOP);
BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
int tottri = efa->len - 2;
int mati = mat_orig_to_new[efa->mat_nr];
gpumat = gpumaterials + mati;
if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
for (j = 0; j < tottri; j++, lt++) {
start = gpumat->start + fc[mati].i_tri_hidden;
/* v1 v2 v3 */
varray[start--] = BM_elem_index_get((*lt)[2]);
varray[start--] = BM_elem_index_get((*lt)[1]);
varray[start--] = BM_elem_index_get((*lt)[0]);
fc[mati].i_tri_hidden -= 3;
}
gpumat->polys[fc[mati].i_hidden--] = i;
}
else {
for (j = 0; j < tottri; j++, lt++) {
start = gpumat->start + fc[mati].i_tri_visible;
/* v1 v2 v3 */
varray[start++] = BM_elem_index_get((*lt)[0]);
varray[start++] = BM_elem_index_get((*lt)[1]);
varray[start++] = BM_elem_index_get((*lt)[2]);
fc[mati].i_tri_visible += 3;
}
gpumat->polys[fc[mati].i_visible++] = i;
}
}
/* set the visible polygons */
for (i = 0; i < totmat; i++) {
gpumaterials[i].totvisiblepolys = fc[i].i_visible;
gpumaterials[i].totvisibleelems = fc[i].i_tri_visible;
}
MEM_freeN(fc);
}
static void emDM_copy_gpu_data(
DerivedMesh *dm, int type, void *varray_p,
const int *mat_orig_to_new, const void *UNUSED(user_data))
{
/* 'varray_p' cast is redundant but include for self-documentation */
switch (type) {
case GPU_BUFFER_VERTEX:
emDM_buffer_copy_vertex(dm, (float *)varray_p);
break;
case GPU_BUFFER_NORMAL:
emDM_buffer_copy_normal(dm, (short *)varray_p);
break;
case GPU_BUFFER_COLOR:
// cdDM_buffer_copy_mcol(dm, (unsigned char *)varray_p, user_data);
break;
case GPU_BUFFER_UV:
// cdDM_buffer_copy_uv(dm, (float *)varray_p);
break;
case GPU_BUFFER_UV_TEXPAINT:
// this should apparently never happen in edit mode
BLI_assert(0);
break;
case GPU_BUFFER_EDGE:
// cdDM_buffer_copy_edge(dm, (unsigned int *)varray_p);
break;
case GPU_BUFFER_UVEDGE:
// cdDM_buffer_copy_uvedge(dm, (float *)varray_p);
break;
case GPU_BUFFER_TRIANGLES:
emDM_buffer_copy_triangles(dm, (unsigned int *)varray_p, mat_orig_to_new);
break;
default:
break;
}
}
/* see GPUDrawObject's structure definition for a description of the
* data being initialized here */
static GPUDrawObject *emDM_GPUobject_new(DerivedMesh *dm)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMEditMesh *em = bmdm->em;
BMesh *bm = em->bm;
GPUDrawObject *gdo;
BMIter iter;
const BMFace *efa;
const int tottri = bmdm->em->tottri;
int totmat = dm->totmat;
GPUBufferMaterial *mat_info;
int i;
/* object contains at least one material (default included) so zero means uninitialized dm */
BLI_assert(totmat != 0);
/* get the number of points used by each material, treating
* each quad as two triangles */
mat_info = MEM_callocN(sizeof(*mat_info) * totmat, "GPU_drawobject_new.mat_orig_to_new");
BM_ITER_MESH_INDEX(efa, &iter, bm, BM_FACES_OF_MESH, i) {
const int mat_nr = efa->mat_nr;
mat_info[mat_nr].totpolys++;
mat_info[mat_nr].totelements += 3 * (efa->len - 2);
mat_info[mat_nr].totloops += efa->len;
}
/* create the GPUDrawObject */
gdo = MEM_callocN(sizeof(GPUDrawObject), "GPUDrawObject");
gdo->totvert = bm->totvert;
gdo->totedge = bm->totedge;
GPU_buffer_material_finalize(gdo, mat_info, totmat);
gdo->tot_loop_verts = dm->getNumLoops(dm);
/* store total number of points used for triangles */
gdo->tot_triangle_point = tottri * 3;
return gdo;
}
static void emDM_drawMappedEdges(
DerivedMesh *dm,
DMSetDrawOptions setDrawOptions,
@@ -928,6 +1182,7 @@ static void emDM_drawMappedFaces(
BMEditMesh *em = bmdm->em;
BMesh *bm = em->bm;
BMFace *efa;
bool skip_hidden = (flag & DM_DRAW_SKIP_HIDDEN) != 0;
struct BMLoop *(*looptris)[3] = bmdm->em->looptris;
const int tottri = bmdm->em->tottri;
DMDrawOption draw_option;
@@ -940,6 +1195,7 @@ static void emDM_drawMappedFaces(
bool has_vcol_preview = (color_vert_array != NULL) && !skip_normals;
bool has_fcol_preview = (color_face_array != NULL) && !skip_normals;
bool has_vcol_any = has_vcol_preview;
GPUBuffer *findex_buffer = NULL;
/* GL_ZERO is used to detect if drawing has started or not */
GLenum poly_prev = GL_ZERO;
@@ -958,7 +1214,61 @@ static void emDM_drawMappedFaces(
/* weak, this logic should really be moved higher up */
setMaterial = NULL;
}
#if 1
GPU_vertex_setup(dm);
/* if we do selection, fill the selection buffer color */
if (G.f & G_BACKBUFSEL) {
if (!(flag & DM_DRAW_SKIP_SELECT)) {
unsigned int *fi_map;
unsigned int start_element = 0;
findex_buffer = GPU_buffer_alloc(dm->drawObject->tot_loop_verts * sizeof(int));
fi_map = GPU_buffer_lock(findex_buffer, GPU_BINDING_ARRAY);
if (fi_map) {
BMIter iter;
int j;
BM_ITER_MESH_INDEX(efa, &iter, bm, BM_FACES_OF_MESH, i) {
int selcol = 0xFFFFFFFF;
if (!skip_hidden || !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
GPU_select_index_get(i + 1, &selcol);
}
for (j = 0; j < efa->len; j++)
fi_map[start_element++] = selcol;
}
GPU_buffer_unlock(findex_buffer, GPU_BINDING_ARRAY);
GPU_buffer_bind_as_color(findex_buffer);
}
}
}
else if (!skip_normals){
/* no need to setup normals when selecting */
GPU_normal_setup(dm);
}
GPU_triangle_setup(dm);
glShadeModel(GL_SMOOTH);
for (i = 0; i < dm->drawObject->totmaterial; i++) {
if (!setMaterial || setMaterial(dm->drawObject->materials[i].mat_nr + 1, NULL)) {
unsigned int totalelem = (skip_hidden) ? dm->drawObject->materials[i].totvisibleelems :
dm->drawObject->materials[i].totelements;
GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES,
dm->drawObject->materials[i].start, totalelem);
}
}
glShadeModel(GL_FLAT);
GPU_buffers_unbind();
if (findex_buffer)
GPU_buffer_free(findex_buffer);
return;
#endif
if (bmdm->vertexCos) {
short prev_mat_nr = -1;
@@ -2282,6 +2592,9 @@ DerivedMesh *getEditDerivedBMesh(
bmdm->dm.drawFacesGLSL = emDM_drawFacesGLSL;
bmdm->dm.drawUVEdges = emDM_drawUVEdges;
bmdm->dm.gpuObjectNew = emDM_GPUobject_new;
bmdm->dm.copy_gpu_data = emDM_copy_gpu_data;
bmdm->dm.release = emDM_release;
bmdm->vertexCos = (const float (*)[3])vertexCos;

View File

@@ -1834,7 +1834,7 @@ static void ccgDM_drawEdges(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEd
GPU_edge_setup(dm);
gdo = dm->drawObject;
if (gdo->edges && gdo->points) {
if (gdo->edges && gdo->vertices) {
if (drawAllEdges && drawLooseEdges) {
GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, (gdo->totedge - gdo->totinterior) * 2);
}

View File

@@ -66,6 +66,7 @@ typedef struct GPUBufferMaterial {
unsigned int *polys; /* array of polygons for this material */
unsigned int totpolys; /* total polygons in polys */
unsigned int totvisiblepolys; /* total visible polygons */
unsigned int totvisibleelems; /* total visible elements */
/* original material index */
short mat_nr;
@@ -90,15 +91,31 @@ void GPU_buffer_material_finalize(struct GPUDrawObject *gdo, GPUBufferMaterial *
* for MFaces are referred to as triangles rather than faces.
*/
typedef struct GPUDrawObject {
GPUBuffer *points;
/* vertices are kept in a separate buffer to ensure better cache coherence for edge drawing or
* for passes not reliant to other formats, such as, for example, depth pass or shadow maps */
GPUBuffer *vertices;
/* legacy buffers, do not reuse */
GPUBuffer *normals;
GPUBuffer *uv;
GPUBuffer *uv_tex;
GPUBuffer *colors;
/* index buffers */
GPUBuffer *edges;
GPUBuffer *uvedges;
GPUBuffer *triangles; /* triangle index buffer */
/* material display data needed for the object. The resident data inside the buffer varies depending
* on the material that is assigned to each polygon. Vertex stride is the maximum vertex stride needed
* to accomodate the most fat material vertex format
* NOTE: For future deferred rendering we might want to separate data that are needed for normals as well */
GPUBuffer *materialData;
/* These data exist only to display UI helpers for the mesh that are not relevant to materials. Examples
* include selection state, weights and mode dependent visual debugging variables, uvs for uveditor */
GPUBuffer *workflowData;
/* for each original vertex, the list of related points */
struct GPUVertPointLink *vert_points;
@@ -144,7 +161,6 @@ typedef struct GPUVertPointLink {
} GPUVertPointLink;
/* used for GLSL materials */
typedef struct GPUAttrib {
int index;
@@ -153,6 +169,43 @@ typedef struct GPUAttrib {
int type;
} GPUAttrib;
/* generic vertex format used for all derivedmeshes
* customdatatype is enough to get size of format
* and we can infer the offset by the position in buffer.
* This corresponds in a single interleaved buffer */
typedef struct GPUMeshVertexAttribute
{
/* char is sufficient here, we have less than 255 customdata types */
char customdatatype;
/* layer number, for layers that need it */
char layer;
} GPUMeshVertexAttribute;
typedef struct GPUMeshVertexFormat
{
/* which customdata exist in the current vertex format */
long customdataflag;
/* number of customData in format */
char numData;
/* actual current data existing in buffer */
GPUMeshVertexAttribute *layout;
} GPUMeshVertexFormat;
/* create a vertex format with the specified formats */
GPUMeshVertexFormat *GPU_vertex_format_alloc(long iformat);
/* check if reusing the vertex format is possible */
bool GPU_vertex_format_reuse(GPUMeshVertexFormat *vformat, long iformat);
/* bind the vertex format existing in the currently bound buffer object,
* according to the format specified here (should be a subset of the format of the buffer) */
void GPU_vertex_format_bind(GPUMeshVertexFormat *vformat, long iformat);
/* get the size of the vertex format */
int GPU_vertex_format_size(GPUMeshVertexFormat *vformat);
void GPU_global_buffer_pool_free(void);
void GPU_global_buffer_pool_free_unused(void);
@@ -170,7 +223,7 @@ typedef enum {
GPU_BUFFER_UV_TEXPAINT,
GPU_BUFFER_EDGE,
GPU_BUFFER_UVEDGE,
GPU_BUFFER_TRIANGLES
GPU_BUFFER_TRIANGLES,
} GPUBufferType;
typedef enum {

View File

@@ -93,6 +93,8 @@ const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
{GL_ELEMENT_ARRAY_BUFFER, 4},
/* triangles, 1 point since we are allocating from tottriangle points, which account for all points */
{GL_ELEMENT_ARRAY_BUFFER, 1},
/* editface colors */
{GL_ARRAY_BUFFER, 4},
};
#define MAX_GPU_ATTRIB_DATA 32
@@ -426,7 +428,7 @@ void GPU_drawobject_free(DerivedMesh *dm)
#ifdef USE_GPU_POINT_LINK
MEM_freeN(gdo->vert_points_mem);
#endif
GPU_buffer_free(gdo->points);
GPU_buffer_free(gdo->vertices);
GPU_buffer_free(gdo->normals);
GPU_buffer_free(gdo->uv);
GPU_buffer_free(gdo->uv_tex);
@@ -529,7 +531,7 @@ static GPUBuffer **gpu_drawobject_buffer_from_type(GPUDrawObject *gdo, GPUBuffer
{
switch (type) {
case GPU_BUFFER_VERTEX:
return &gdo->points;
return &gdo->vertices;
case GPU_BUFFER_NORMAL:
return &gdo->normals;
case GPU_BUFFER_COLOR:
@@ -619,7 +621,7 @@ void GPU_vertex_setup(DerivedMesh *dm)
return;
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id);
glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->vertices->id);
glVertexPointer(3, GL_FLOAT, 0, 0);
GLStates |= GPU_BUFFER_VERTEX_STATE;
@@ -714,7 +716,7 @@ void GPU_edge_setup(DerivedMesh *dm)
return;
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id);
glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->vertices->id);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->edges->id);