[Bf-blender-cvs] [b1ac7571a81] blender2.8: Cleanup: split GPU_batch_presets into own file

Campbell Barton noreply at git.blender.org
Mon Jan 15 06:16:53 CET 2018


Commit: b1ac7571a81e13fb61e16738c1bc196ebb1a6eeb
Author: Campbell Barton
Date:   Mon Jan 15 16:21:23 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBb1ac7571a81e13fb61e16738c1bc196ebb1a6eeb

Cleanup: split GPU_batch_presets into own file

Mixing other batch code in this file easily shadowed existing variables.
Keep presets separate (we may have more, 2D & 3D presets)

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

M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_batch.h
M	source/blender/gpu/intern/gpu_batch.c

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

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 18a1ef36bdc..0ac842d90a0 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -52,6 +52,7 @@ set(INC_SYS
 set(SRC
 	intern/gpu_basic_shader.c
 	intern/gpu_batch.c
+	intern/gpu_batch_presets.c
 	intern/gpu_buffers.c
 	intern/gpu_codegen.c
 	intern/gpu_compositing.c
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index 6d16092996e..a6aa529fd2d 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -39,13 +39,19 @@
 #include "GPU_shader.h"
 
 /* Extend GWN_batch_program_set to use Blender’s library of built-in shader programs. */
+
+/* gpu_batch.c */
 void GWN_batch_program_set_builtin(Gwn_Batch *, GPUBuiltinShader);
 
+void gpu_batch_init(void);
+void gpu_batch_exit(void);
+
+/* gpu_batch_presets.c */
 /* Replacement for gluSphere */
 Gwn_Batch *GPU_batch_preset_sphere(int lod);
 Gwn_Batch *GPU_batch_preset_sphere_wire(int lod);
 
-void gpu_batch_init(void);
-void gpu_batch_exit(void);
+void gpu_batch_presets_init(void);
+void gpu_batch_presets_exit(void);
 
 #endif  /* __GPU_BATCH_H__ */
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index 5d347fc80e8..fcc7110e0aa 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -25,147 +25,34 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/gpu/intern/gpu_basic_shader.c
+ *  \ingroup gpu
+ */
+
 #include "BLI_utildefines.h"
-#include "BLI_math.h"
 
-#include "GPU_batch.h"
+#include "GPU_batch.h"  /* own include */
 #include "gpu_shader_private.h"
 
+/* -------------------------------------------------------------------- */
+/** \name Utilities
+ * \{ */
+
 void GWN_batch_program_set_builtin(Gwn_Batch *batch, GPUBuiltinShader shader_id)
 {
 	GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
 	GWN_batch_program_set(batch, shader->program, shader->interface);
 }
 
-static Gwn_Batch *sphere_high = NULL;
-static Gwn_Batch *sphere_med = NULL;
-static Gwn_Batch *sphere_low = NULL;
-static Gwn_Batch *sphere_wire_low = NULL;
-static Gwn_Batch *sphere_wire_med = NULL;
-
-static Gwn_VertBuf *vbo;
-static Gwn_VertFormat format = {0};
-static unsigned int pos_id, nor_id;
-static unsigned int vert;
-
-static void batch_sphere_lat_lon_vert(float lat, float lon)
-{
-	float pos[3];
-	pos[0] = sinf(lat) * cosf(lon);
-	pos[1] = cosf(lat);
-	pos[2] = sinf(lat) * sinf(lon);
-
-	GWN_vertbuf_attr_set(vbo, nor_id, vert, pos);
-	GWN_vertbuf_attr_set(vbo, pos_id, vert++, pos);
-}
-
-/* Replacement for gluSphere */
-static Gwn_Batch *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;
-	float lon, lat;
-
-	if (format.attrib_ct == 0) {
-		pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-		nor_id = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-	}
-
-	vbo = GWN_vertbuf_create_with_format(&format);
-	GWN_vertbuf_data_alloc(vbo, (lat_res - 1) * lon_res * 6);
-	vert = 0;
-
-	lon = 0.0f;
-	for (int i = 0; i < lon_res; i++, lon += lon_inc) {
-		lat = 0.0f;
-		for (int j = 0; j < lat_res; j++, lat += lat_inc) {
-			if (j != lat_res - 1) { /* Pole */
-				batch_sphere_lat_lon_vert(lat + lat_inc, lon + lon_inc);
-				batch_sphere_lat_lon_vert(lat + lat_inc, lon);
-				batch_sphere_lat_lon_vert(lat,           lon);
-			}
-
-			if (j != 0) { /* Pole */
-				batch_sphere_lat_lon_vert(lat,           lon + lon_inc);
-				batch_sphere_lat_lon_vert(lat + lat_inc, lon + lon_inc);
-				batch_sphere_lat_lon_vert(lat,           lon);
-			}
-		}
-	}
-
-	return GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, NULL, GWN_BATCH_OWNS_VBO);
-}
-
-static Gwn_Batch *batch_sphere_wire(int lat_res, int lon_res)
-{
-	const float lon_inc = 2 * M_PI / lon_res;
-	const float lat_inc = M_PI / lat_res;
-	float lon, lat;
-
-	if (format.attrib_ct == 0) {
-		pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-		nor_id = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-	}
-
-	vbo = GWN_vertbuf_create_with_format(&format);
-	GWN_vertbuf_data_alloc(vbo, (lat_res * lon_res * 2) + ((lat_res - 1) * lon_res * 2));
-	vert = 0;
-
-	lon = 0.0f;
-	for (int i = 0; i < lon_res; i++, lon += lon_inc) {
-		lat = 0.0f;
-		for (int j = 0; j < lat_res; j++, lat += lat_inc) {
-			batch_sphere_lat_lon_vert(lat + lat_inc, lon);
-			batch_sphere_lat_lon_vert(lat,           lon);
-
-			if (j != lat_res - 1) { /* Pole */
-				batch_sphere_lat_lon_vert(lat + lat_inc, lon + lon_inc);
-				batch_sphere_lat_lon_vert(lat + lat_inc, lon);
-			}
-		}
-	}
-
-	return GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
-}
-
-Gwn_Batch *GPU_batch_preset_sphere(int lod)
-{
-	BLI_assert(lod >= 0 && lod <= 2);
-
-	if (lod == 0)
-		return sphere_low;
-	else if (lod == 1)
-		return sphere_med;
-	else
-		return sphere_high;
-}
-
-Gwn_Batch *GPU_batch_preset_sphere_wire(int lod)
-{
-	BLI_assert(lod >= 0 && lod <= 1);
-
-	if (lod == 0)
-		return sphere_wire_low;
-	else
-		return sphere_wire_med;
-}
-
 void gpu_batch_init(void)
 {
-	/* Hard coded resolution */
-	sphere_low = batch_sphere(8, 16);
-	sphere_med = batch_sphere(16, 10);
-	sphere_high = batch_sphere(32, 24);
-
-	sphere_wire_low = batch_sphere_wire(6, 8);
-	sphere_wire_med = batch_sphere_wire(8, 16);
+	gpu_batch_presets_init();
 }
 
 void gpu_batch_exit(void)
 {
-	GWN_batch_discard(sphere_low);
-	GWN_batch_discard(sphere_med);
-	GWN_batch_discard(sphere_high);
-	GWN_batch_discard(sphere_wire_low);
-	GWN_batch_discard(sphere_wire_med);
+	gpu_batch_presets_exit();
 }
+
+/** \} */
+



More information about the Bf-blender-cvs mailing list