Compare commits
57 Commits
temp-multi
...
temp_displ
Author | SHA1 | Date | |
---|---|---|---|
1a5777fd5e | |||
ab7d449299 | |||
![]() |
5c706c6496 | ||
a3762f1fab | |||
![]() |
7fa7a0b703 | ||
![]() |
a728572ce6 | ||
c54b44592b | |||
3b3cd248db | |||
613d505eab | |||
f713f39182 | |||
d8dd5fa42c | |||
fa05817bb5 | |||
7b8d680064 | |||
8471b7145a | |||
5b316690ed | |||
388695b1f0 | |||
9074d9572e | |||
25d86e4459 | |||
e9c7e0ee8c | |||
e41731286e | |||
0b48bfae87 | |||
eeb1d58167 | |||
4f9b58cb71 | |||
94a6399a89 | |||
f292199403 | |||
05634836f0 | |||
fb5ec0997e | |||
18b81af276 | |||
43bf4a0f51 | |||
5a7b0cf1c7 | |||
e8b187ca14 | |||
2edc5b807b | |||
c255161468 | |||
52187f826c | |||
9566b13672 | |||
a5f03ee002 | |||
60ad7c09c1 | |||
09665a5301 | |||
850e9ce176 | |||
a50de5fd94 | |||
5d592a9686 | |||
33ddcf4dc3 | |||
1951604bab | |||
3351ab28d9 | |||
43eabfe5b8 | |||
8a077c90d2 | |||
c314507cbf | |||
62f0f0607f | |||
188c1cc184 | |||
1b64055c2c | |||
4c553ce09f | |||
d4ad7836b6 | |||
21414b511f | |||
22f38137d7 | |||
f018b99b51 | |||
0c50ba7ec3 | |||
530ee08e93 |
@@ -153,7 +153,7 @@ typedef enum DMDrawFlag {
|
|||||||
DM_DRAW_SKIP_HIDDEN = (1 << 4),
|
DM_DRAW_SKIP_HIDDEN = (1 << 4),
|
||||||
DM_DRAW_SKIP_SELECT = (1 << 5),
|
DM_DRAW_SKIP_SELECT = (1 << 5),
|
||||||
DM_DRAW_SELECT_USE_EDITMODE = (1 << 6),
|
DM_DRAW_SELECT_USE_EDITMODE = (1 << 6),
|
||||||
DM_DRAW_NEED_NORMALS = (1 << 7)
|
DM_DRAW_NEED_NORMALS = (1 << 7),
|
||||||
} DMDrawFlag;
|
} DMDrawFlag;
|
||||||
|
|
||||||
typedef enum DMForeachFlag {
|
typedef enum DMForeachFlag {
|
||||||
|
@@ -416,7 +416,7 @@ static void cdDM_drawEdges(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEdg
|
|||||||
|
|
||||||
GPU_edge_setup(dm);
|
GPU_edge_setup(dm);
|
||||||
gdo = dm->drawObject;
|
gdo = dm->drawObject;
|
||||||
if (gdo->edges && gdo->points) {
|
if (gdo->edges && gdo->vertices) {
|
||||||
if (drawAllEdges && drawLooseEdges) {
|
if (drawAllEdges && drawLooseEdges) {
|
||||||
GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->totedge * 2);
|
GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->totedge * 2);
|
||||||
}
|
}
|
||||||
|
@@ -51,15 +51,19 @@
|
|||||||
#include "BKE_editmesh.h"
|
#include "BKE_editmesh.h"
|
||||||
#include "BKE_editmesh_bvh.h"
|
#include "BKE_editmesh_bvh.h"
|
||||||
|
|
||||||
|
#include "BKE_global.h"
|
||||||
|
|
||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
#include "DNA_object_types.h"
|
#include "DNA_object_types.h"
|
||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
|
#include "GPU_buffers.h"
|
||||||
#include "GPU_glew.h"
|
#include "GPU_glew.h"
|
||||||
#include "GPU_buffers.h"
|
#include "GPU_buffers.h"
|
||||||
#include "GPU_shader.h"
|
#include "GPU_shader.h"
|
||||||
#include "GPU_basic_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]);
|
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(
|
static void emDM_drawMappedEdges(
|
||||||
DerivedMesh *dm,
|
DerivedMesh *dm,
|
||||||
DMSetDrawOptions setDrawOptions,
|
DMSetDrawOptions setDrawOptions,
|
||||||
@@ -928,6 +1182,7 @@ static void emDM_drawMappedFaces(
|
|||||||
BMEditMesh *em = bmdm->em;
|
BMEditMesh *em = bmdm->em;
|
||||||
BMesh *bm = em->bm;
|
BMesh *bm = em->bm;
|
||||||
BMFace *efa;
|
BMFace *efa;
|
||||||
|
bool skip_hidden = (flag & DM_DRAW_SKIP_HIDDEN) != 0;
|
||||||
struct BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
struct BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
||||||
const int tottri = bmdm->em->tottri;
|
const int tottri = bmdm->em->tottri;
|
||||||
DMDrawOption draw_option;
|
DMDrawOption draw_option;
|
||||||
@@ -940,6 +1195,7 @@ static void emDM_drawMappedFaces(
|
|||||||
bool has_vcol_preview = (color_vert_array != NULL) && !skip_normals;
|
bool has_vcol_preview = (color_vert_array != NULL) && !skip_normals;
|
||||||
bool has_fcol_preview = (color_face_array != NULL) && !skip_normals;
|
bool has_fcol_preview = (color_face_array != NULL) && !skip_normals;
|
||||||
bool has_vcol_any = has_vcol_preview;
|
bool has_vcol_any = has_vcol_preview;
|
||||||
|
GPUBuffer *findex_buffer = NULL;
|
||||||
|
|
||||||
/* GL_ZERO is used to detect if drawing has started or not */
|
/* GL_ZERO is used to detect if drawing has started or not */
|
||||||
GLenum poly_prev = GL_ZERO;
|
GLenum poly_prev = GL_ZERO;
|
||||||
@@ -958,7 +1214,61 @@ static void emDM_drawMappedFaces(
|
|||||||
/* weak, this logic should really be moved higher up */
|
/* weak, this logic should really be moved higher up */
|
||||||
setMaterial = NULL;
|
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) {
|
if (bmdm->vertexCos) {
|
||||||
short prev_mat_nr = -1;
|
short prev_mat_nr = -1;
|
||||||
|
|
||||||
@@ -2282,6 +2592,9 @@ DerivedMesh *getEditDerivedBMesh(
|
|||||||
bmdm->dm.drawFacesGLSL = emDM_drawFacesGLSL;
|
bmdm->dm.drawFacesGLSL = emDM_drawFacesGLSL;
|
||||||
bmdm->dm.drawUVEdges = emDM_drawUVEdges;
|
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->dm.release = emDM_release;
|
||||||
|
|
||||||
bmdm->vertexCos = (const float (*)[3])vertexCos;
|
bmdm->vertexCos = (const float (*)[3])vertexCos;
|
||||||
|
@@ -1834,7 +1834,7 @@ static void ccgDM_drawEdges(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEd
|
|||||||
|
|
||||||
GPU_edge_setup(dm);
|
GPU_edge_setup(dm);
|
||||||
gdo = dm->drawObject;
|
gdo = dm->drawObject;
|
||||||
if (gdo->edges && gdo->points) {
|
if (gdo->edges && gdo->vertices) {
|
||||||
if (drawAllEdges && drawLooseEdges) {
|
if (drawAllEdges && drawLooseEdges) {
|
||||||
GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, (gdo->totedge - gdo->totinterior) * 2);
|
GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, (gdo->totedge - gdo->totinterior) * 2);
|
||||||
}
|
}
|
||||||
|
@@ -66,6 +66,7 @@ typedef struct GPUBufferMaterial {
|
|||||||
unsigned int *polys; /* array of polygons for this material */
|
unsigned int *polys; /* array of polygons for this material */
|
||||||
unsigned int totpolys; /* total polygons in polys */
|
unsigned int totpolys; /* total polygons in polys */
|
||||||
unsigned int totvisiblepolys; /* total visible polygons */
|
unsigned int totvisiblepolys; /* total visible polygons */
|
||||||
|
unsigned int totvisibleelems; /* total visible elements */
|
||||||
|
|
||||||
/* original material index */
|
/* original material index */
|
||||||
short mat_nr;
|
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.
|
* for MFaces are referred to as triangles rather than faces.
|
||||||
*/
|
*/
|
||||||
typedef struct GPUDrawObject {
|
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 *normals;
|
||||||
GPUBuffer *uv;
|
GPUBuffer *uv;
|
||||||
GPUBuffer *uv_tex;
|
GPUBuffer *uv_tex;
|
||||||
GPUBuffer *colors;
|
GPUBuffer *colors;
|
||||||
|
|
||||||
|
/* index buffers */
|
||||||
GPUBuffer *edges;
|
GPUBuffer *edges;
|
||||||
GPUBuffer *uvedges;
|
GPUBuffer *uvedges;
|
||||||
GPUBuffer *triangles; /* triangle index buffer */
|
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 */
|
/* for each original vertex, the list of related points */
|
||||||
struct GPUVertPointLink *vert_points;
|
struct GPUVertPointLink *vert_points;
|
||||||
|
|
||||||
@@ -144,7 +161,6 @@ typedef struct GPUVertPointLink {
|
|||||||
} GPUVertPointLink;
|
} GPUVertPointLink;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* used for GLSL materials */
|
/* used for GLSL materials */
|
||||||
typedef struct GPUAttrib {
|
typedef struct GPUAttrib {
|
||||||
int index;
|
int index;
|
||||||
@@ -153,6 +169,43 @@ typedef struct GPUAttrib {
|
|||||||
int type;
|
int type;
|
||||||
} GPUAttrib;
|
} 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(void);
|
||||||
void GPU_global_buffer_pool_free_unused(void);
|
void GPU_global_buffer_pool_free_unused(void);
|
||||||
|
|
||||||
@@ -170,7 +223,7 @@ typedef enum {
|
|||||||
GPU_BUFFER_UV_TEXPAINT,
|
GPU_BUFFER_UV_TEXPAINT,
|
||||||
GPU_BUFFER_EDGE,
|
GPU_BUFFER_EDGE,
|
||||||
GPU_BUFFER_UVEDGE,
|
GPU_BUFFER_UVEDGE,
|
||||||
GPU_BUFFER_TRIANGLES
|
GPU_BUFFER_TRIANGLES,
|
||||||
} GPUBufferType;
|
} GPUBufferType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@@ -93,6 +93,8 @@ const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
|
|||||||
{GL_ELEMENT_ARRAY_BUFFER, 4},
|
{GL_ELEMENT_ARRAY_BUFFER, 4},
|
||||||
/* triangles, 1 point since we are allocating from tottriangle points, which account for all points */
|
/* triangles, 1 point since we are allocating from tottriangle points, which account for all points */
|
||||||
{GL_ELEMENT_ARRAY_BUFFER, 1},
|
{GL_ELEMENT_ARRAY_BUFFER, 1},
|
||||||
|
/* editface colors */
|
||||||
|
{GL_ARRAY_BUFFER, 4},
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_GPU_ATTRIB_DATA 32
|
#define MAX_GPU_ATTRIB_DATA 32
|
||||||
@@ -426,7 +428,7 @@ void GPU_drawobject_free(DerivedMesh *dm)
|
|||||||
#ifdef USE_GPU_POINT_LINK
|
#ifdef USE_GPU_POINT_LINK
|
||||||
MEM_freeN(gdo->vert_points_mem);
|
MEM_freeN(gdo->vert_points_mem);
|
||||||
#endif
|
#endif
|
||||||
GPU_buffer_free(gdo->points);
|
GPU_buffer_free(gdo->vertices);
|
||||||
GPU_buffer_free(gdo->normals);
|
GPU_buffer_free(gdo->normals);
|
||||||
GPU_buffer_free(gdo->uv);
|
GPU_buffer_free(gdo->uv);
|
||||||
GPU_buffer_free(gdo->uv_tex);
|
GPU_buffer_free(gdo->uv_tex);
|
||||||
@@ -529,7 +531,7 @@ static GPUBuffer **gpu_drawobject_buffer_from_type(GPUDrawObject *gdo, GPUBuffer
|
|||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GPU_BUFFER_VERTEX:
|
case GPU_BUFFER_VERTEX:
|
||||||
return &gdo->points;
|
return &gdo->vertices;
|
||||||
case GPU_BUFFER_NORMAL:
|
case GPU_BUFFER_NORMAL:
|
||||||
return &gdo->normals;
|
return &gdo->normals;
|
||||||
case GPU_BUFFER_COLOR:
|
case GPU_BUFFER_COLOR:
|
||||||
@@ -619,7 +621,7 @@ void GPU_vertex_setup(DerivedMesh *dm)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
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);
|
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||||
|
|
||||||
GLStates |= GPU_BUFFER_VERTEX_STATE;
|
GLStates |= GPU_BUFFER_VERTEX_STATE;
|
||||||
@@ -714,7 +716,7 @@ void GPU_edge_setup(DerivedMesh *dm)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
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);
|
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->edges->id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->edges->id);
|
||||||
|
Reference in New Issue
Block a user