Revision: 37124
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37124
Author:   jwilkins
Date:     2011-06-03 14:04:58 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Revision: 29264
Author: nicholasbishop
Date: 2:07:58 AM, Sunday, June 06, 2010
Message:
Preparing VBO drawing code for colors.
* Added functions to load paintmask data into the color buffer
* Drawing is enabled, but no visible effect since I haven't set up any 
paintmask layers yet.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c

Property Changed:
----------------
    branches/soc-2011-onion/


Property changes on: branches/soc-2011-onion
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29261,29263,29324,29350
/trunk/blender:36833-37054
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29264,29324,29350
/trunk/blender:36833-37054

Modified: branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c     
2011-06-03 13:53:28 UTC (rev 37123)
+++ branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c     
2011-06-03 14:04:58 UTC (rev 37124)
@@ -413,7 +413,7 @@
 
 typedef struct {
        /* opengl buffer handles */
-       GLuint vert_buf, index_buf;
+       GLuint vert_buf, index_buf, color_buf;
        GLenum index_type;
 
        /* mesh pointers in case buffer allocation fails */
@@ -431,6 +431,54 @@
        unsigned int tot_tri, tot_quad;
 } GPU_Buffers;
 
+static void delete_buffer(GLuint *buf)
+{
+       glDeleteBuffersARB(1, buf);
+       *buf = 0;
+}
+
+/* For purposes of displaying the mask on the mesh,
+   convert the mask strength to RGB-bytes */
+static void mask_to_gpu_colors(unsigned char out[3], float mask_strength)
+{
+       unsigned char v = (unsigned char)(mask_strength * 128.0f) + 64;
+       out[0] = v;
+       out[1] = v;
+       out[2] = v;
+}
+
+/* For now this looks for just a single mask layer, eventually might include
+   other color layers like vertex colors or weights */
+static void update_mesh_color_buffers(GPU_Buffers *buffers, CustomData 
*vert_customdata, int totvert)
+{
+       unsigned char *color_data = NULL;
+       int i;
+       float *pmask;
+
+       /* Make a color buffer if there's a mask layer and
+          get rid of any color buffer if there's no mask layer */
+       pmask = CustomData_get_layer(vert_customdata, CD_PAINTMASK);
+       if(pmask && !buffers->color_buf)
+               glGenBuffersARB(1, &buffers->color_buf);
+       else if(!pmask && buffers->color_buf)
+               delete_buffer(&buffers->color_buf);
+
+       if(pmask && buffers->color_buf) {
+               glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->color_buf);
+               glBufferDataARB(GL_ARRAY_BUFFER_ARB,
+                               sizeof(char) * 3 * totvert,
+                               NULL, GL_STATIC_DRAW_ARB);
+               color_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, 
GL_WRITE_ONLY_ARB);
+               if(color_data) {
+                       for(i = 0; i < totvert; ++i)
+                               mask_to_gpu_colors(color_data + i*3, pmask[i]);
+                       glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+               }
+               else
+                       delete_buffer(&buffers->color_buf);
+       }
+}
+
 void GPU_update_mesh_buffers(void *buffers_v, MVert *mvert,
                        int *vert_indices, int totvert)
 {
@@ -457,10 +505,8 @@
 
                        glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
                }
-               else {
-                       glDeleteBuffersARB(1, &buffers->vert_buf);
-                       buffers->vert_buf = 0;
-               }
+               else
+                       delete_buffer(&buffers->vert_buf);
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
        }
@@ -527,10 +573,8 @@
                        }
                        glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
                }
-               else {
-                       glDeleteBuffersARB(1, &buffers->index_buf);
-                       buffers->index_buf = 0;
-               }
+               else
+                       delete_buffer(&buffers->index_buf);
 
                glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
        }
@@ -590,10 +634,9 @@
                        }
                        glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
                }
-               else {
-                       glDeleteBuffersARB(1, &buffers->vert_buf);
-                       buffers->vert_buf = 0;
-               }
+               else
+                       delete_buffer(&buffers->vert_buf);
+
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
        }
 
@@ -647,10 +690,8 @@
                                }
                                glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
                        }
-                       else {
-                               glDeleteBuffersARB(1, &buffers->index_buf);
-                               buffers->index_buf = 0;
-                       }
+                       else
+                               delete_buffer(&buffers->index_buf);
                }
                else {
                        unsigned int *quad_data;
@@ -677,10 +718,8 @@
                                }
                                glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
                        }
-                       else {
-                               glDeleteBuffersARB(1, &buffers->index_buf);
-                               buffers->index_buf = 0;
-                       }
+                       else
+                               delete_buffer(&buffers->index_buf);
                }
 
                glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
@@ -700,30 +739,51 @@
        GPU_Buffers *buffers = buffers_v;
 
        if(buffers->vert_buf && buffers->index_buf) {
+               GLboolean colmat;
+
                glEnableClientState(GL_VERTEX_ARRAY);
                glEnableClientState(GL_NORMAL_ARRAY);
+               if(buffers->color_buf)
+                       glEnableClientState(GL_COLOR_ARRAY);
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
                glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 
buffers->index_buf);
 
+               if(buffers->color_buf) {
+                       glGetBooleanv(GL_COLOR_MATERIAL, &colmat);
+                       glEnable(GL_COLOR_MATERIAL);
+               }
+
                if(buffers->tot_quad) {
                        glVertexPointer(3, GL_FLOAT, sizeof(DMGridData), 
(void*)offsetof(DMGridData, co));
                        glNormalPointer(GL_FLOAT, sizeof(DMGridData), 
(void*)offsetof(DMGridData, no));
+                       if(buffers->color_buf) {
+                               glBindBufferARB(GL_ARRAY_BUFFER_ARB, 
buffers->color_buf);
+                               glVertexPointer(3, GL_UNSIGNED_BYTE, 
sizeof(char)*3, (void*)0);
+                       }
 
                        glDrawElements(GL_QUADS, buffers->tot_quad * 4, 
buffers->index_type, 0);
                }
                else {
                        glVertexPointer(3, GL_FLOAT, 
sizeof(VertexBufferFormat), (void*)offsetof(VertexBufferFormat, co));
                        glNormalPointer(GL_SHORT, sizeof(VertexBufferFormat), 
(void*)offsetof(VertexBufferFormat, no));
+                       if(buffers->color_buf) {
+                               glBindBufferARB(GL_ARRAY_BUFFER_ARB, 
buffers->color_buf);
+                               glVertexPointer(3, GL_UNSIGNED_BYTE, 
sizeof(char)*3, (void*)0);
+                       }
 
                        glDrawElements(GL_TRIANGLES, buffers->tot_tri * 3, 
buffers->index_type, 0);
                }
 
+               if(buffers->color_buf && !colmat)
+                       glDisable(GL_COLOR_MATERIAL);
+
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
                glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
 
                glDisableClientState(GL_VERTEX_ARRAY);
                glDisableClientState(GL_NORMAL_ARRAY);
+               glDisableClientState(GL_COLOR_ARRAY);
        }
        else if(buffers->totface) {
                /* fallback if we are out of memory */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to