[Bf-blender-cvs] [3e3e7ee] master: Sculpt draw code:

Antony Riakiotakis noreply at git.blender.org
Thu Jul 16 17:13:58 CEST 2015


Commit: 3e3e7ee41c9c04ef1630eef46c71434d152c55dc
Author: Antony Riakiotakis
Date:   Thu Jul 16 16:22:28 2015 +0200
Branches: master
https://developer.blender.org/rB3e3e7ee41c9c04ef1630eef46c71434d152c55dc

Sculpt draw code:

Remove legacy code completely, now dyntopo, multires et al even work on
GL 1.1 for really hardcore users :p

Real purpose here though is to be able to have fast multires drawing
even with VBO off, since it requires using indices for vertex buffers.

Also made own code elf puke an eaten normal update function which
made multires not update normals in solid mode...sorry.

===================================================================

M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/gpu/intern/gpu_init_exit.c
M	source/blender/makesrna/intern/rna_userdef.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 5b25a32..c16af7c 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -666,7 +666,7 @@ static void cdDM_drawMappedFaces(
 		unsigned int *fi_map;
 
 		findex_buffer = GPU_buffer_alloc(dm->drawObject->tot_loop_verts * sizeof(int), false);
-		fi_map = GPU_buffer_lock(findex_buffer);
+		fi_map = GPU_buffer_lock(findex_buffer, GPU_BINDING_ARRAY);
 
 		if (fi_map) {
 			for (i = 0; i < dm->numTessFaceData; i++, mf++) {
@@ -689,7 +689,7 @@ static void cdDM_drawMappedFaces(
 			start_element = 0;
 			mf = cddm->mface;
 
-			GPU_buffer_unlock(findex_buffer);
+			GPU_buffer_unlock(findex_buffer, GPU_BINDING_ARRAY);
 			GPU_buffer_bind_as_color(findex_buffer);
 		}
 	}
@@ -1034,7 +1034,7 @@ static void cdDM_drawMappedFacesGLSL(
 			if (buffer == NULL) {
 				buffer = GPU_buffer_alloc(max_element_size * dm->drawObject->tot_loop_verts, true);
 			}
-			varray = GPU_buffer_lock_stream(buffer);
+			varray = GPU_buffer_lock_stream(buffer, GPU_BINDING_ARRAY);
 			if (varray == NULL) {
 				GPU_buffer_unbind();
 				GPU_buffer_free(buffer);
@@ -1114,7 +1114,7 @@ static void cdDM_drawMappedFacesGLSL(
 					tot_loops += 3;
 				}
 			}
-			GPU_buffer_unlock(buffer);
+			GPU_buffer_unlock(buffer, GPU_BINDING_ARRAY);
 		}
 
 		for (a = 0; a < tot_active_mat; a++) {
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index e5e36b2..edeba9f 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1087,7 +1087,8 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
 						GPU_build_grid_pbvh_buffers(node->prim_indices,
 					                           node->totprim,
 					                           bvh->grid_hidden,
-					                           bvh->gridkey.grid_size);
+					                           bvh->gridkey.grid_size,
+					                           &bvh->gridkey);
 					break;
 				case PBVH_FACES:
 					node->draw_buffers =
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 0b0c011..aaf631a 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -2246,6 +2246,8 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
 	int a;
 	CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
 
+	ccgdm_pbvh_update(ccgdm);
+
 	if (ccgdm->pbvh && ccgdm->multires.mmd) {
 		if (BKE_pbvh_has_faces(ccgdm->pbvh)) {
 			BKE_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL,
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 8586728..9c2ca6c 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -47,6 +47,7 @@ struct DerivedMesh;
 struct GSet;
 struct GPUVertPointLink;
 struct PBVH;
+struct MVert;
 
 typedef struct GPUBuffer {
 	int size;        /* in bytes */
@@ -152,6 +153,9 @@ void GPU_buffer_free(GPUBuffer *buffer);
 
 void GPU_drawobject_free(struct DerivedMesh *dm);
 
+/* free special global multires grid buffer */
+void GPU_buffer_multires_free(bool force);
+
 /* flag that controls data type to fill buffer with, a modifier will prepare. */
 typedef enum {
 	GPU_BUFFER_VERTEX = 0,
@@ -164,6 +168,10 @@ typedef enum {
 	GPU_BUFFER_TRIANGLES
 } GPUBufferType;
 
+typedef enum {
+	GPU_BINDING_ARRAY = 0,
+	GPU_BINDING_INDEX = 1,
+} GPUBindingType;
 
 /* called before drawing */
 void GPU_vertex_setup(struct DerivedMesh *dm);
@@ -181,10 +189,12 @@ void GPU_triangle_setup(struct DerivedMesh *dm);
 int GPU_attrib_element_size(GPUAttrib data[], int numdata);
 void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numdata, int element_size);
 
+void GPU_buffer_bind(GPUBuffer *buffer, GPUBindingType binding);
+
 /* can't lock more than one buffer at once */
-void *GPU_buffer_lock(GPUBuffer *buffer);
-void *GPU_buffer_lock_stream(GPUBuffer *buffer);
-void GPU_buffer_unlock(GPUBuffer *buffer);
+void *GPU_buffer_lock(GPUBuffer *buffer, GPUBindingType binding);
+void *GPU_buffer_lock_stream(GPUBuffer *buffer, GPUBindingType binding);
+void GPU_buffer_unlock(GPUBuffer *buffer, GPUBindingType binding);
 
 /* switch color rendering on=1/off=0 */
 void GPU_color_switch(int mode);
@@ -202,20 +212,19 @@ void GPU_interleaved_attrib_unbind(void);
 typedef struct GPU_PBVH_Buffers GPU_PBVH_Buffers;
 
 /* build */
-GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(
-        const int (*face_vert_indices)[4],
+GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(const int (*face_vert_indices)[4],
         const struct MFace *mface, const struct MVert *mvert,
         const int *face_indices, int totface);
 
 GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
-                                    unsigned int **grid_hidden, int gridsize);
+                                    unsigned int **grid_hidden, int gridsize, const struct CCGKey *key);
 
 GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(int smooth_shading);
 
 /* update */
 
 void GPU_update_mesh_pbvh_buffers(
-        GPU_PBVH_Buffers *buffers, const MVert *mvert,
+        GPU_PBVH_Buffers *buffers, const struct MVert *mvert,
         const int *vert_indices, int totvert, const float *vmask,
         const int (*face_vert_indices)[4], bool show_diffuse_color);
 
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 9b58851..d30ca9f 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -108,6 +108,13 @@ static GPUAttrib attribData[MAX_GPU_ATTRIB_DATA] = { { -1, 0, 0 } };
 
 static ThreadMutex buffer_mutex = BLI_MUTEX_INITIALIZER;
 
+/* multires global buffer, can be used for many grids having the same grid size */
+static GPUBuffer *mres_glob_buffer = NULL;
+static int mres_prev_gridsize = -1;
+static GLenum mres_prev_index_type = 0;
+static unsigned mres_prev_totquad = 0;
+
+
 /* stores recently-deleted buffers so that new buffers won't have to
  * be recreated as often
  *
@@ -122,15 +129,11 @@ static ThreadMutex buffer_mutex = BLI_MUTEX_INITIALIZER;
 typedef struct GPUBufferPool {
 	/* number of allocated buffers stored */
 	int totbuf;
-	int totpbvhbufids;
 	/* actual allocated length of the arrays */
 	int maxsize;
-	int maxpbvhsize;
 	GPUBuffer **buffers;
-	GLuint *pbvhbufids;
 } GPUBufferPool;
 #define MAX_FREE_GPU_BUFFERS 8
-#define MAX_FREE_GPU_BUFF_IDS 100
 
 /* create a new GPUBufferPool */
 static GPUBufferPool *gpu_buffer_pool_new(void)
@@ -140,11 +143,8 @@ static GPUBufferPool *gpu_buffer_pool_new(void)
 	pool = MEM_callocN(sizeof(GPUBufferPool), "GPUBuffer_Pool");
 
 	pool->maxsize = MAX_FREE_GPU_BUFFERS;
-	pool->maxpbvhsize = MAX_FREE_GPU_BUFF_IDS;
 	pool->buffers = MEM_mallocN(sizeof(*pool->buffers) * pool->maxsize,
 	                            "GPUBufferPool.buffers");
-	pool->pbvhbufids = MEM_mallocN(sizeof(*pool->pbvhbufids) * pool->maxpbvhsize,
-	                               "GPUBufferPool.pbvhbuffers");
 	return pool;
 }
 
@@ -202,7 +202,6 @@ static void gpu_buffer_pool_free(GPUBufferPool *pool)
 		gpu_buffer_pool_delete_last(pool);
 
 	MEM_freeN(pool->buffers);
-	MEM_freeN(pool->pbvhbufids);
 	MEM_freeN(pool);
 }
 
@@ -216,11 +215,6 @@ static void gpu_buffer_pool_free_unused(GPUBufferPool *pool)
 	while (pool->totbuf)
 		gpu_buffer_pool_delete_last(pool);
 
-	if (pool->totpbvhbufids > 0) {
-		glDeleteBuffersARB(pool->totpbvhbufids, pool->pbvhbufids);
-		pool->totpbvhbufids = 0;
-	}
-
 	BLI_mutex_unlock(&buffer_mutex);
 }
 
@@ -416,6 +410,35 @@ void GPU_buffer_free(GPUBuffer *buffer)
 	BLI_mutex_unlock(&buffer_mutex);
 }
 
+void GPU_buffer_multires_free(bool force)
+{
+	if (!mres_glob_buffer) {
+		/* Early output, no need to lock in this case, */
+		return;
+	}
+
+	if (force && BLI_thread_is_main()) {
+		if (mres_glob_buffer) {
+			if (mres_glob_buffer->id)
+				glDeleteBuffersARB(1, &mres_glob_buffer->id);
+			else if (mres_glob_buffer->pointer)
+				MEM_freeN(mres_glob_buffer->pointer);
+			MEM_freeN(mres_glob_buffer);
+		}
+	}
+	else {
+		BLI_mutex_lock(&buffer_mutex);
+		gpu_buffer_free_intern(mres_glob_buffer);
+		BLI_mutex_unlock(&buffer_mutex);
+	}
+
+	mres_glob_buffer = NULL;
+	mres_prev_gridsize = -1;
+	mres_prev_index_type = 0;
+	mres_prev_totquad = 0;
+}
+
+
 void GPU_drawobject_free(DerivedMesh *dm)
 {
 	GPUDrawObject *gdo;
@@ -972,7 +995,13 @@ void GPU_color_switch(int mode)
 	}
 }
 
-void *GPU_buffer_lock(GPUBuffer *buffer)
+static int gpu_binding_type_gl[] =
+{
+	GL_ARRAY_BUFFER_ARB,
+	GL_ELEMENT_ARRAY_BUFFER_ARB
+};
+
+void *GPU_buffer_lock(GPUBuffer *buffer, GPUBindingType binding)
 {
 	float *varray;
 
@@ -980,8 +1009,9 @@ void *GPU_buffer_lock(GPUBuffer *buffer)
 		return 0;
 
 	if (buffer->use_vbo) {
-		glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
-		varray = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+		int bindtypegl = gpu_binding_type_gl[binding];
+		glBindBufferARB(bindtypegl, buffer->id);
+		varray = glMapBufferARB(bindtypegl, GL_WRITE_ONLY_ARB);
 		return varray;
 	}
 	else {
@@ -989,7 +1019,7 @@ void *GPU_buffer_lock(GPUBuffer *buffer)
 	}
 }
 
-void *GPU_buffer_lock_stream(GPUBuffer *buffer)
+void *GPU_buffer_lock_stream(GPUBuffer *buffer, GPUBindingType binding)
 {
 	float *varray;
 
@@ -997,10 +1027,11 @@ void *GPU_buffer_lock_stream(GPUBuffer *buffer)
 		return 0;
 
 	if (buffer->use_vbo) {
-		glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
+		int bindtypegl = gpu_binding_type_gl[binding];
+		glBindBufferARB(bindtypegl, buffer->id);
 		/* discard previous data, avoid stalling gpu */
-		glBufferDataARB(GL_ARRAY_BUFFER_ARB, buffer->size, 0, GL_STREAM_DRAW_ARB);
-		varray = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+		glBufferDataARB(bindtypegl, buffer->size, 0, GL_STREAM_DRAW_ARB);
+		varray = glMapBufferARB(bindtypegl, GL_WRITE_ONLY_ARB);
 		return varray;
 	}
 	else {
@@ -1008,16 +1039,24 @@ void *GPU_buffer_lock_stream(GPUBuffer *buffer)
 	}
 }
 
-void GPU_buffer_unlock(GPUBuffer *buffer)
+void GPU_buffer_unlock(GPUBuf

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list