diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-07-25 14:17:37 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-07-25 15:42:26 +0300 |
commit | 50a46a5973d90787eaa37ea959b9035918a071af (patch) | |
tree | c32b8cd522d8400907770cf93c4154b7601b2569 /source/blender/gpu | |
parent | 38e19536bf6dd33cf73578260b17c5bc9d5db268 (diff) |
GPU buffer materials:
Separate and reuse some shared code.
Also avoid counting for information we already know,
such as total loop triangles etc.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_buffers.h | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 30 |
2 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index a50d63d89ec..8bb3ef4a3bc 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -48,6 +48,7 @@ struct DMFlagMat; struct DerivedMesh; struct GSet; struct GPUVertPointLink; +struct GPUDrawObject; struct PBVH; struct MVert; @@ -71,6 +72,8 @@ typedef struct GPUBufferMaterial { short mat_nr; } GPUBufferMaterial; +void GPU_buffer_material_finalize(struct GPUDrawObject *gdo, GPUBufferMaterial *matinfo, int totmat); + /* meshes are split up by material since changing materials requires * GL state changes that can't occur in the middle of drawing an * array. diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index b2bfb0b47b8..bbffa5a53c2 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -114,6 +114,36 @@ static int mres_prev_gridsize = -1; static GLenum mres_prev_index_type = 0; static unsigned mres_prev_totquad = 0; +void GPU_buffer_material_finalize(GPUDrawObject *gdo, GPUBufferMaterial *matinfo, int totmat) +{ + int i, curmat, curelement; + + /* count the number of materials used by this DerivedMesh */ + for (i = 0; i < totmat; i++) { + if (matinfo[i].totelements > 0) + gdo->totmaterial++; + } + + /* allocate an array of materials used by this DerivedMesh */ + gdo->materials = MEM_mallocN(sizeof(GPUBufferMaterial) * gdo->totmaterial, + "GPUDrawObject.materials"); + + /* initialize the materials array */ + for (i = 0, curmat = 0, curelement = 0; i < totmat; i++) { + if (matinfo[i].totelements > 0) { + gdo->materials[curmat] = matinfo[i]; + gdo->materials[curmat].start = curelement; + gdo->materials[curmat].mat_nr = i; + gdo->materials[curmat].polys = MEM_mallocN(sizeof(int) * matinfo[i].totpolys, "GPUBufferMaterial.polys"); + + curelement += matinfo[i].totelements; + curmat++; + } + } + + MEM_freeN(matinfo); +} + /* stores recently-deleted buffers so that new buffers won't have to * be recreated as often |