[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31490] branches/soc-2010-nicolasbishop/ source/blender: == Ptex ==
Nicholas Bishop
nicholasbishop at gmail.com
Sat Aug 21 05:09:31 CEST 2010
Revision: 31490
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31490
Author: nicholasbishop
Date: 2010-08-21 05:09:20 +0200 (Sat, 21 Aug 2010)
Log Message:
-----------
== Ptex ==
Resolution editing works now with VBO enabled
Modified Paths:
--------------
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ptex.c
branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ptex.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ptex.c 2010-08-21 00:31:08 UTC (rev 31489)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ptex.c 2010-08-21 03:09:20 UTC (rev 31490)
@@ -872,6 +872,31 @@
}
}
+static void ptex_redraw_selected(PBVHNode *node, void *data)
+{
+ PBVH *pbvh = data;
+ MPtex *mptex;
+ GridToFace *grid_face_map;
+ CustomData *fdata;
+ int totgrid, *grid_indices, i;
+
+ BLI_pbvh_get_customdata(pbvh, NULL, &fdata);
+ mptex = CustomData_get_layer(fdata, CD_MPTEX);
+ grid_face_map = BLI_pbvh_get_grid_face_map(pbvh);
+ BLI_pbvh_node_get_grids(pbvh, node,
+ &grid_indices, &totgrid, NULL, NULL,
+ NULL, NULL, NULL);
+
+ for(i = 0; i < totgrid; ++i) {
+ GridToFace *gtf = &grid_face_map[grid_indices[i]];
+ if(mptex[gtf->face].subfaces[gtf->offset].flag & MPTEX_SUBFACE_SELECTED) {
+ BLI_pbvh_node_set_flags(node,
+ SET_INT_IN_POINTER(PBVH_UpdateColorBuffers|
+ PBVH_UpdateRedraw));
+ }
+ }
+}
+
static int ptex_face_resolution_set_exec(bContext *C, wmOperator *op)
{
ToolSettings *ts = CTX_data_tool_settings(C);
@@ -891,6 +916,8 @@
}
}
+ BLI_pbvh_search_callback(ob->paint->pbvh, NULL, NULL, ptex_redraw_selected, ob->paint->pbvh);
+
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return OPERATOR_FINISHED;
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-21 00:31:08 UTC (rev 31489)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c 2010-08-21 03:09:20 UTC (rev 31490)
@@ -742,15 +742,22 @@
void GPU_update_grid_uv_buffer(GPU_Buffers *buffers, PBVH *pbvh, PBVHNode *node, DMDrawFlags flags)
{
+ CustomData *fdata;
+ GridToFace *grid_face_map;
+ MPtex *mptex;
float (*uv_data)[2];
int *grid_indices, totgrid, gridsize, totvert;
if(!buffers->vert_buf)
return;
+ BLI_pbvh_get_customdata(pbvh, NULL, &fdata);
+ mptex = CustomData_get_layer(fdata, CD_MPTEX);
+ grid_face_map = BLI_pbvh_get_grid_face_map(pbvh);
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);
@@ -758,11 +765,31 @@
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);
+ GridToFace *gtf = &grid_face_map[grid_indices[0]];
+ MPtex *pt = &mptex[gtf->face];
+ MPtexSubface *subface = &pt->subfaces[gtf->offset];
+ float u, v, ustep, vstep, vstart = 0;
+ int x, y;
+
+ if(flags & DM_DRAW_PTEX_TEXELS) {
+ ustep = subface->res[0] >> 1;
+ vstep = subface->res[1] >> 1;
+ /* make quad texel pattern appear uniform across all four subfaces */
+ if(gtf->offset % 2)
+ vstart = 0.5;
+ }
+ else {
+ ustep = 1;
+ vstep = 1;
+ }
+
+ ustep /= gridsize - 1.0f;
+ vstep /= gridsize - 1.0f;
+
+ for(y = 0, v = vstart; y < gridsize; ++y, v += vstep) {
+ for(x = 0, u = 0; x < gridsize; ++x, u += ustep, ++uv_data) {
+ uv_data[0][0] = u;
+ uv_data[0][1] = v;
}
}
@@ -1126,7 +1153,7 @@
if(ptex_edit) {
if(subface->flag & MPTEX_SUBFACE_SELECTED)
- glColor3ub(255, 255, 255);
+ glColor3ub(255, 255, 255);
else
glColor3ub(128, 128, 128);
}
@@ -1224,7 +1251,7 @@
glShadeModel((flags & DM_DRAW_FULLY_SMOOTH) ? GL_SMOOTH: GL_FLAT);
if(buffers->vert_buf && buffers->index_buf) {
- GLboolean colmat;
+ GLboolean use_colmat, colmat;
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
@@ -1236,7 +1263,8 @@
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
- if(buffers->color_buf) {
+ use_colmat = buffers->color_buf || (flags & DM_DRAW_PTEX_TEXELS);
+ if(use_colmat) {
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glGetBooleanv(GL_COLOR_MATERIAL, &colmat);
glEnable(GL_COLOR_MATERIAL);
@@ -1251,7 +1279,33 @@
}
if(buffers->uv_buf) {
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, buffers->ptex[0]);
+ if(flags & DM_DRAW_PTEX_TEXELS) {
+ int *grid_indices;
+ CustomData *fdata;
+ GridToFace *gtf;
+ MPtex *mptex, *pt;
+ MPtexSubface *subface;
+ GridToFace *grid_face_map;
+
+ BLI_pbvh_get_customdata(pbvh, NULL, &fdata);
+ mptex = CustomData_get_layer(fdata, CD_MPTEX);
+ grid_face_map = BLI_pbvh_get_grid_face_map(pbvh);
+ BLI_pbvh_node_get_grids(pbvh, node,
+ &grid_indices, NULL, NULL, NULL,
+ NULL, NULL, NULL);
+
+ gtf = &grid_face_map[grid_indices[0]];
+ pt = &mptex[gtf->face];
+ subface = &pt->subfaces[gtf->offset];
+
+ gpu_bind_ptex_pattern();
+ if(subface->flag & MPTEX_SUBFACE_SELECTED)
+ glColor3ub(255, 255, 255);
+ else
+ glColor3ub(128, 128, 128);
+ }
+ else
+ glBindTexture(GL_TEXTURE_2D, buffers->ptex[0]);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->uv_buf);
glTexCoordPointer(2, GL_FLOAT, 0, (void*)0);
}
@@ -1273,7 +1327,7 @@
glDrawElements(GL_TRIANGLES, buffers->tot_tri * 3, buffers->index_type, 0);
}
- if(buffers->color_buf && !colmat)
+ if(use_colmat && !colmat)
glDisable(GL_COLOR_MATERIAL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
More information about the Bf-blender-cvs
mailing list