[Bf-blender-cvs] [95e8a522333] temp-drawcontext: GPU/DRW: Make sphere batch local to DrawManager.

Clément Foucault noreply at git.blender.org
Fri Feb 9 21:05:21 CET 2018


Commit: 95e8a5223337c128437d259ef5f0987526c1ec2e
Author: Clément Foucault
Date:   Fri Feb 9 20:39:44 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rB95e8a5223337c128437d259ef5f0987526c1ec2e

GPU/DRW: Make sphere batch local to DrawManager.

Because it won't be possible to use batches created outside DrawManager in the DrawManager if it has its own context.

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

M	source/blender/draw/intern/draw_cache.c
M	source/blender/gpu/GPU_batch.h
M	source/blender/gpu/intern/gpu_batch_presets.c

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 3b4180c0375..6b1a3356b51 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -45,6 +45,7 @@ static struct DRWShapeCache {
 	Gwn_Batch *drw_single_vertice;
 	Gwn_Batch *drw_fullscreen_quad;
 	Gwn_Batch *drw_quad;
+	Gwn_Batch *drw_sphere;
 	Gwn_Batch *drw_screenspace_circle;
 	Gwn_Batch *drw_plain_axes;
 	Gwn_Batch *drw_single_arrow;
@@ -266,7 +267,6 @@ Gwn_Batch *DRW_cache_fullscreen_quad_get(void)
 Gwn_Batch *DRW_cache_quad_get(void)
 {
 	if (!SHC.drw_quad) {
-		/* Use a triangle instead of a real quad */
 		float pos[4][2] = {{-1.0f, -1.0f}, { 1.0f, -1.0f}, {1.0f,  1.0f}, {-1.0f,  1.0f}};
 		float uvs[4][2] = {{ 0.0f,  0.0f}, { 1.0f,  0.0f}, {1.0f,  1.0f}, { 0.0f,  1.0f}};
 
@@ -294,7 +294,10 @@ Gwn_Batch *DRW_cache_quad_get(void)
 /* Sphere */
 Gwn_Batch *DRW_cache_sphere_get(void)
 {
-	return GPU_batch_preset_sphere(2);
+	if (!SHC.drw_sphere) {
+		SHC.drw_sphere = gpu_batch_sphere(32, 24);
+	}
+	return SHC.drw_sphere;
 }
 
 /** \} */
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index d2f3409dc07..5807af7b359 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -58,6 +58,8 @@ void gpu_batch_init(void);
 void gpu_batch_exit(void);
 
 /* gpu_batch_presets.c */
+/* Only use by draw manager. Use the presets function instead for interface. */
+Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res) ATTR_WARN_UNUSED_RESULT;
 /* Replacement for gluSphere */
 Gwn_Batch *GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT;
 Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/gpu/intern/gpu_batch_presets.c b/source/blender/gpu/intern/gpu_batch_presets.c
index 9db04832a51..21d6906083a 100644
--- a/source/blender/gpu/intern/gpu_batch_presets.c
+++ b/source/blender/gpu/intern/gpu_batch_presets.c
@@ -31,6 +31,7 @@
 
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
+#include "BLI_threads.h"
 
 #include "GPU_batch.h"
 #include "gpu_shader_private.h"
@@ -71,7 +72,7 @@ static void batch_sphere_lat_lon_vert(
 }
 
 /* Replacement for gluSphere */
-static Gwn_Batch *batch_sphere(int lat_res, int lon_res)
+Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res)
 {
 	const float lon_inc = 2 * M_PI / lon_res;
 	const float lat_inc = M_PI / lat_res;
@@ -146,6 +147,7 @@ static Gwn_Batch *batch_sphere_wire(int lat_res, int lon_res)
 Gwn_Batch *GPU_batch_preset_sphere(int lod)
 {
 	BLI_assert(lod >= 0 && lod <= 2);
+	BLI_assert(BLI_thread_is_main());
 
 	if (lod == 0) {
 		return g_presets_3d.batch.sphere_low;
@@ -161,6 +163,7 @@ Gwn_Batch *GPU_batch_preset_sphere(int lod)
 Gwn_Batch *GPU_batch_preset_sphere_wire(int lod)
 {
 	BLI_assert(lod >= 0 && lod <= 1);
+	BLI_assert(BLI_thread_is_main());
 
 	if (lod == 0) {
 		return g_presets_3d.batch.sphere_wire_low;
@@ -182,9 +185,9 @@ void gpu_batch_presets_init(void)
 	}
 
 	/* Hard coded resolution */
-	g_presets_3d.batch.sphere_low = batch_sphere(8, 16);
-	g_presets_3d.batch.sphere_med = batch_sphere(16, 10);
-	g_presets_3d.batch.sphere_high = batch_sphere(32, 24);
+	g_presets_3d.batch.sphere_low = gpu_batch_sphere(8, 16);
+	g_presets_3d.batch.sphere_med = gpu_batch_sphere(16, 10);
+	g_presets_3d.batch.sphere_high = gpu_batch_sphere(32, 24);
 
 	g_presets_3d.batch.sphere_wire_low = batch_sphere_wire(6, 8);
 	g_presets_3d.batch.sphere_wire_med = batch_sphere_wire(8, 16);



More information about the Bf-blender-cvs mailing list