[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21075] branches/soc-2009-imbusy/source/ blender: vertex arrays work and a few bugs fixed
Lukas Steiblys
imbusy at imbusy.org
Mon Jun 22 11:22:33 CEST 2009
Revision: 21075
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21075
Author: imbusy
Date: 2009-06-22 11:22:31 +0200 (Mon, 22 Jun 2009)
Log Message:
-----------
vertex arrays work and a few bugs fixed
Modified Paths:
--------------
branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c
branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c
Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c 2009-06-22 04:39:35 UTC (rev 21074)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c 2009-06-22 09:22:31 UTC (rev 21075)
@@ -83,6 +83,7 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "gpu_buffers.h"
#include "GPU_draw.h"
#include "GPU_extensions.h"
#include "GPU_material.h"
@@ -217,7 +218,7 @@
{
if (dm->needsFree) {
bvhcache_free(&dm->bvhCache);
-
+ GPU_buffer_release(dm);
CustomData_free(&dm->vertData, dm->numVertData);
CustomData_free(&dm->edgeData, dm->numEdgeData);
CustomData_free(&dm->faceData, dm->numFaceData);
Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c 2009-06-22 04:39:35 UTC (rev 21074)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c 2009-06-22 09:22:31 UTC (rev 21075)
@@ -60,7 +60,7 @@
#include "MEM_guardedalloc.h"
-#include "GPU_buffers.h"
+#include "gpu_buffers.h"
#include "GPU_draw.h"
#include "GPU_extensions.h"
#include "GPU_material.h"
Modified: branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h 2009-06-22 04:39:35 UTC (rev 21074)
+++ branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h 2009-06-22 09:22:31 UTC (rev 21075)
@@ -95,4 +95,7 @@
/* called after drawing */
void GPU_buffer_unbind();
+/* called when destroying DerivedMesh */
+void GPU_buffer_release( struct DerivedMesh *dm );
+
#endif
Modified: branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c 2009-06-22 04:39:35 UTC (rev 21074)
+++ branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c 2009-06-22 09:22:31 UTC (rev 21075)
@@ -46,6 +46,8 @@
#define GPU_BUFFER_TEXCOORD_STATE 4
#define GPU_BUFFER_COLOR_STATE 8
+#define DEBUG_VBO(X) printf(X)
+
/* -1 - undefined, 0 - vertex arrays, 1 - VBOs */
int useVBOs = -1;
GPUBufferPool *globalPool = 0;
@@ -55,9 +57,11 @@
{
GPUBufferPool *pool;
+ DEBUG_VBO("GPU_buffer_pool_new\n");
+
if( useVBOs < 0 ) {
if( GL_ARB_vertex_buffer_object )
- useVBOs = 1;
+ useVBOs = 0;
else
useVBOs = 0;
}
@@ -71,6 +75,8 @@
{
int i;
+ DEBUG_VBO("GPU_buffer_pool_free\n");
+
while( pool->start < 0 )
pool->start += MAX_FREE_GPU_BUFFERS;
@@ -87,6 +93,9 @@
void GPU_buffer_pool_remove( int index, GPUBufferPool *pool )
{
int i;
+
+ DEBUG_VBO("GPU_buffer_pool_remove\n");
+
while( pool->start < 0 )
pool->start += MAX_FREE_GPU_BUFFERS;
for( i = index; i < pool->size-1; i++ ) {
@@ -99,10 +108,13 @@
{
int last;
- while( pool->start < 0 )
- pool->start += MAX_FREE_GPU_BUFFERS;
- last = (pool->start+pool->size)%MAX_FREE_GPU_BUFFERS;
+ DEBUG_VBO("GPU_buffer_pool_delete_last\n");
+ last = pool->start+pool->size-1;
+ while( last < 0 )
+ last += MAX_FREE_GPU_BUFFERS;
+ last = (last+MAX_FREE_GPU_BUFFERS)%MAX_FREE_GPU_BUFFERS;
+
if( useVBOs ) {
glDeleteBuffersARB(1,&pool->buffers[last]->id);
MEM_freeN( pool->buffers[last] );
@@ -116,11 +128,14 @@
GPUBuffer *GPU_buffer_alloc( int size, GPUBufferPool *pool )
{
+ char buffer[60];
int i;
int cursize;
GPUBuffer *allocated;
int bestfit = -1;
+ DEBUG_VBO("GPU_buffer_alloc\n");
+
while( pool->start < 0 )
pool->start += MAX_FREE_GPU_BUFFERS;
@@ -129,6 +144,7 @@
if( cursize == size ) {
allocated = pool->buffers[pool->start+i];
GPU_buffer_pool_remove(i,pool);
+ DEBUG_VBO("free buffer of exact size found\n");
return allocated;
}
/* smaller buffers won't fit data and buffers at least twice as big are a waste of memory */
@@ -140,6 +156,8 @@
}
}
if( bestfit == -1 ) {
+ DEBUG_VBO("allocating a new buffer\n");
+
allocated = MEM_mallocN(sizeof(GPUBuffer), "GPU_buffer_alloc");
allocated->size = size;
if( useVBOs == 1 ) {
@@ -160,6 +178,9 @@
}
}
else {
+ sprintf(buffer,"free buffer found. Wasted %d bytes\n", pool->buffers[pool->start+bestfit]->size-size);
+ DEBUG_VBO(buffer);
+
allocated = pool->buffers[pool->start+bestfit];
GPU_buffer_pool_remove(bestfit,pool);
}
@@ -170,6 +191,8 @@
{
int place;
+ DEBUG_VBO("GPU_buffer_free\n");
+
if( buffer == 0 )
return;
@@ -182,6 +205,7 @@
GPU_buffer_pool_delete_last( pool );
}
+ pool->size++;
pool->start = place;
pool->buffers[place] = buffer;
}
@@ -195,6 +219,8 @@
int i;
int curmat, curverts;
+ DEBUG_VBO("GPU_drawobject_new\n");
+
object = MEM_callocN(sizeof(GPUDrawObject),"GPU_drawobject_new");
memset(numverts,0,sizeof(int)*256);
@@ -236,6 +262,8 @@
if( object == 0 )
return;
+ DEBUG_VBO("GPU_drawobject_free\n");
+
MEM_freeN(object->materials);
GPU_buffer_free( object->vertices, globalPool );
@@ -255,6 +283,8 @@
int i;
GLboolean uploaded;
+ DEBUG_VBO("GPU_buffer_setup\n");
+
index = MEM_mallocN(sizeof(int)*object->nmaterials,"GPU_buffer_setup");
for( i = 0; i < object->nmaterials; i++ ) {
index[i] = object->materials[i].start;
@@ -297,6 +327,8 @@
MVert *mvert;
MFace *mface;
+ DEBUG_VBO("GPU_buffer_copy_vertex\n");
+
mvert = dm->getVertArray(dm);
mface = dm->getFaceArray(dm);
@@ -323,6 +355,8 @@
GPUBuffer *GPU_buffer_vertex( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_vertex\n");
+
return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*dm->drawObject->nelements, GPU_buffer_copy_vertex);
}
@@ -335,6 +369,8 @@
MVert *mvert;
MFace *mface;
+ DEBUG_VBO("GPU_buffer_copy_normal\n");
+
mvert = dm->getVertArray(dm);
mface = dm->getFaceArray(dm);
@@ -379,6 +415,8 @@
GPUBuffer *GPU_buffer_normal( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_normal\n");
+
return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*dm->drawObject->nelements, GPU_buffer_copy_normal);
}
@@ -390,11 +428,13 @@
MTFace *mtface;
MFace *mface;
+ DEBUG_VBO("GPU_buffer_copy_uv\n");
+
mface = dm->getFaceArray(dm);
mtface = DM_get_face_data_layer(dm, CD_MTFACE);
if( mtface == 0 ) {
- printf("Texture coordinates do not exist for this mesh");
+ DEBUG_VBO("Texture coordinates do not exist for this mesh");
return;
}
@@ -421,6 +461,8 @@
GPUBuffer *GPU_buffer_uv( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_uv\n");
+
return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*2*dm->drawObject->nelements, GPU_buffer_copy_uv);
}
@@ -433,6 +475,8 @@
MFace *mface;
MCol *mcol;
+ DEBUG_VBO("GPU_buffer_copy_color\n");
+
varray = (char *)varray_;
mface = dm->getFaceArray(dm);
@@ -475,63 +519,93 @@
GPUBuffer *GPU_buffer_color( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_color\n");
+
return GPU_buffer_setup( dm, dm->drawObject, sizeof(char)*3*dm->drawObject->nelements, GPU_buffer_copy_color );
}
void GPU_vertex_setup( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_vertex_setup\n");
if( dm->drawObject == 0 )
dm->drawObject = GPU_drawobject_new( dm );
if( dm->drawObject->vertices == 0 )
dm->drawObject->vertices = GPU_buffer_vertex( dm );
- glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->vertices->id );
+
glEnableClientState( GL_VERTEX_ARRAY );
- glVertexPointer( 3, GL_FLOAT, 0, 0 );
+ if( useVBOs ) {
+ glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->vertices->id );
+ glVertexPointer( 3, GL_FLOAT, 0, 0 );
+ }
+ else {
+ glVertexPointer( 3, GL_FLOAT, 0, dm->drawObject->vertices->pointer );
+ }
GLStates |= GPU_BUFFER_VERTEX_STATE;
}
void GPU_normal_setup( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_normal_setup\n");
if( dm->drawObject == 0 )
dm->drawObject = GPU_drawobject_new( dm );
if( dm->drawObject->normals == 0 )
dm->drawObject->normals = GPU_buffer_normal( dm );
- glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->normals->id );
+
glEnableClientState( GL_NORMAL_ARRAY );
- glNormalPointer( GL_FLOAT, 0, 0 );
+ if( useVBOs ) {
+ glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->normals->id );
+ glNormalPointer( GL_FLOAT, 0, 0 );
+ }
+ else {
+ glNormalPointer( GL_FLOAT, 0, dm->drawObject->normals->pointer );
+ }
GLStates |= GPU_BUFFER_NORMAL_STATE;
}
void GPU_uv_setup( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_uv_setup\n");
if( dm->drawObject == 0 )
dm->drawObject = GPU_drawobject_new( dm );
if( dm->drawObject->uv == 0 )
dm->drawObject->uv = GPU_buffer_uv( dm );
- glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->uv->id );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
- glTexCoordPointer( 2, GL_FLOAT, 0, 0 );
+ if( useVBOs ) {
+ glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->uv->id );
+ glTexCoordPointer( 2, GL_FLOAT, 0, 0 );
+ }
+ else {
+ glTexCoordPointer( 2, GL_FLOAT, 0, dm->drawObject->uv->pointer );
+ }
GLStates |= GPU_BUFFER_TEXCOORD_STATE;
}
void GPU_color_setup( DerivedMesh *dm )
{
+ DEBUG_VBO("GPU_buffer_color_setup\n");
if( dm->drawObject == 0 )
dm->drawObject = GPU_drawobject_new( dm );
if( dm->drawObject->colors == 0 )
dm->drawObject->colors = GPU_buffer_uv( dm );
- glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->colors->id );
glEnableClientState( GL_COLOR_ARRAY );
- glColorPointer( 3, GL_UNSIGNED_BYTE, 0, 0 );
+ if( useVBOs ) {
+ glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->colors->id );
+ glColorPointer( 3, GL_UNSIGNED_BYTE, 0, 0 );
+ }
+ else {
+ glColorPointer( 3, GL_UNSIGNED_BYTE, 0, dm->drawObject->colors->pointer );
+ }
GLStates |= GPU_BUFFER_COLOR_STATE;
}
void GPU_buffer_unbind()
{
+ DEBUG_VBO("GPU_buffer_unbind\n");
+
if( GLStates & GPU_BUFFER_VERTEX_STATE )
glDisableClientState( GL_VERTEX_ARRAY );
if( GLStates & GPU_BUFFER_NORMAL_STATE )
@@ -541,5 +615,12 @@
if( GLStates & GPU_BUFFER_COLOR_STATE )
glDisableClientState( GL_COLOR_ARRAY );
GLStates &= !(GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_NORMAL_STATE | GPU_BUFFER_TEXCOORD_STATE | GPU_BUFFER_COLOR_STATE );
- glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+
+ if( useVBOs )
+ glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+}
+
+void GPU_buffer_release( DerivedMesh *dm )
+{
+ GPU_drawobject_free( dm->drawObject );
}
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list