[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31489] branches/soc-2010-nicolasbishop/ source/blender: == Ptex ==
Nicholas Bishop
nicholasbishop at gmail.com
Sat Aug 21 02:31:08 CEST 2010
Revision: 31489
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31489
Author: nicholasbishop
Date: 2010-08-21 02:31:08 +0200 (Sat, 21 Aug 2010)
Log Message:
-----------
== Ptex ==
Enabled VBO drawing for ptex paint
Modified Paths:
--------------
branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h
branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c 2010-08-20 23:55:34 UTC (rev 31488)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c 2010-08-21 00:31:08 UTC (rev 31489)
@@ -1171,8 +1171,13 @@
if(node->flag & PBVH_UpdateColorBuffers) {
if(bvh->grids) {
- if(flags & DM_DRAW_PTEX)
+ if(flags & DM_DRAW_PTEX) {
GPU_update_ptex(node->draw_buffers, bvh, node);
+ /* TODO: should only do this after ptex
+ res change */
+ GPU_update_grid_uv_buffer(node->draw_buffers,
+ bvh, node, flags);
+ }
else if(flags & DM_DRAW_PAINT_MASK) {
GPU_update_grid_color_buffers(node->draw_buffers,
bvh->grids,
@@ -1185,9 +1190,7 @@
}
}
else {
- if(flags & DM_DRAW_PTEX)
- GPU_update_ptex(node->draw_buffers, bvh, node);
- else if(flags & DM_DRAW_PAINT_MASK) {
+ if(flags & DM_DRAW_PAINT_MASK) {
GPU_update_mesh_color_buffers(node->draw_buffers,
bvh, node, flags);
}
Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h 2010-08-20 23:55:34 UTC (rev 31488)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h 2010-08-21 00:31:08 UTC (rev 31489)
@@ -157,6 +157,10 @@
int *grid_indices, int totgrid,
int gridsize, struct GridKey *gridkey,
struct CustomData *vdata, enum DMDrawFlags flags);
+void GPU_update_grid_uv_buffer(GPU_Buffers *buffers,
+ struct PBVH *pbvh,
+ struct PBVHNode *node,
+ enum DMDrawFlags flags);
void GPU_update_ptex(GPU_Buffers *buffers, struct PBVH *bvh, struct PBVHNode *node);
void GPU_draw_buffers(GPU_Buffers *buffers, struct PBVH *bvh,
Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c 2010-08-20 23:55:34 UTC (rev 31488)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c 2010-08-21 00:31:08 UTC (rev 31489)
@@ -421,7 +421,7 @@
struct GPU_Buffers {
/* opengl buffer handles */
- GLuint vert_buf, index_buf, color_buf;
+ GLuint vert_buf, index_buf, color_buf, uv_buf;
GLenum index_type;
GLuint *ptex;
@@ -449,30 +449,40 @@
out[2] = fcol[2] * mask_strength * 255;
}
-/* Create or destroy the color buffer as needed, return a pointer to the color buffer data.
- If the return value is not null, it must be freed with glUnmapBuffer */
-static unsigned char *map_color_buffer(GPU_Buffers *buffers, int have_colors, int totelem)
+/* create or destroy a buffer as needed, return a pointer to the buffer data.
+ if the return value is not null, it must be freed with glUnmapBuffer */
+static void *map_buffer(GPU_Buffers *buffers, GLuint *id, int needed, int totelem, int elemsize)
{
- unsigned char *color_data = NULL;
+ void *data = NULL;
- if(have_colors && !buffers->color_buf)
- glGenBuffersARB(1, &buffers->color_buf);
- else if(!have_colors && buffers->color_buf)
- delete_buffer(&buffers->color_buf);
+ if(needed && !(*id))
+ glGenBuffersARB(1, id);
+ else if(!needed && (*id))
+ delete_buffer(id);
- if(have_colors && buffers->color_buf) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->color_buf);
+ if(needed && (*id)) {
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, *id);
glBufferDataARB(GL_ARRAY_BUFFER_ARB,
- sizeof(char) * 3 * totelem,
+ elemsize * totelem,
NULL, GL_STATIC_DRAW_ARB);
- color_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
- if(!color_data)
- delete_buffer(&buffers->color_buf);
+ data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ if(!data)
+ delete_buffer(id);
}
- return color_data;
+ return data;
}
+static unsigned char *map_color_buffer(GPU_Buffers *buffers, int have_colors, int totelem)
+{
+ return map_buffer(buffers, &buffers->color_buf, have_colors, totelem, sizeof(char) * 3);
+}
+
+static void *map_uv_buffer(GPU_Buffers *buffers, int need_uvs, int totelem)
+{
+ return map_buffer(buffers, &buffers->uv_buf, need_uvs, totelem, sizeof(float) * 2);
+}
+
static void color_from_face_corner(CustomData *fdata, int mcol_first_layer,
int mcol_totlayer, int cndx, float v[3])
{
@@ -730,6 +740,36 @@
}
}
+void GPU_update_grid_uv_buffer(GPU_Buffers *buffers, PBVH *pbvh, PBVHNode *node, DMDrawFlags flags)
+{
+ float (*uv_data)[2];
+ int *grid_indices, totgrid, gridsize, totvert;
+
+ if(!buffers->vert_buf)
+ return;
+
+ BLI_pbvh_node_get_grids(pbvh, node,
+ &grid_indices, &totgrid, NULL, &gridsize,
+ NULL, NULL, NULL);
+ /* for now, pbvh is required to give one node per subface in ptex mode */
+ assert(totgrid == 1);
+
+ totvert= gridsize*gridsize*totgrid;
+ uv_data= map_uv_buffer(buffers, (flags & DM_DRAW_PTEX), totvert);
+
+ if(uv_data) {
+ int u, v;
+ for(v = 0; v < gridsize; ++v) {
+ for(u = 0; u < gridsize; ++u, ++uv_data) {
+ uv_data[0][0] = u / (gridsize - 1.0f);
+ uv_data[0][1] = v / (gridsize - 1.0f);
+ }
+ }
+
+ glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+ }
+}
+
GLenum gl_type_from_ptex(MPtex *pt)
{
switch(pt->type) {
@@ -1127,11 +1167,6 @@
glEnd();
}
}
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
-
}
else {
MFace *mface;
@@ -1195,6 +1230,8 @@
glEnableClientState(GL_NORMAL_ARRAY);
if(buffers->color_buf)
glEnableClientState(GL_COLOR_ARRAY);
+ if(buffers->uv_buf)
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
@@ -1212,6 +1249,12 @@
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->color_buf);
glColorPointer(3, GL_UNSIGNED_BYTE, 0, (void*)0);
}
+ if(buffers->uv_buf) {
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, buffers->ptex[0]);
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->uv_buf);
+ glTexCoordPointer(2, GL_FLOAT, 0, (void*)0);
+ }
glDrawElements(GL_QUADS, buffers->tot_quad * 4, buffers->index_type, 0);
}
@@ -1239,6 +1282,7 @@
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
else {
/* fallback to regular drawing if out of memory or if VBO is switched off */
More information about the Bf-blender-cvs
mailing list