[Bf-blender-cvs] [8249e1ce5e2] blender2.8: DRWCache: Add a new regular Quad buffer.

Clément Foucault noreply at git.blender.org
Sat Sep 30 19:37:58 CEST 2017


Commit: 8249e1ce5e279b97e60cc847fe715a0e1a58a9f1
Author: Clément Foucault
Date:   Sat Sep 30 18:54:28 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB8249e1ce5e279b97e60cc847fe715a0e1a58a9f1

DRWCache: Add a new regular Quad buffer.

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

M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index bf65d8f879d..8bf7aff555e 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -44,6 +44,7 @@
 static struct DRWShapeCache {
 	Gwn_Batch *drw_single_vertice;
 	Gwn_Batch *drw_fullscreen_quad;
+	Gwn_Batch *drw_quad;
 	Gwn_Batch *drw_screenspace_circle;
 	Gwn_Batch *drw_plain_axes;
 	Gwn_Batch *drw_single_arrow;
@@ -229,6 +230,7 @@ static Gwn_VertBuf *sphere_wire_vbo(const float rad)
 }
 
 /* Quads */
+/* Use this one for rendering fullscreen passes. For 3D objects use DRW_cache_quad_get(). */
 Gwn_Batch *DRW_cache_fullscreen_quad_get(void)
 {
 	if (!SHC.drw_fullscreen_quad) {
@@ -258,6 +260,35 @@ Gwn_Batch *DRW_cache_fullscreen_quad_get(void)
 	return SHC.drw_fullscreen_quad;
 }
 
+/* Just a regular quad with 4 vertices. */
+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}};
+
+		/* Position Only 2D format */
+		static Gwn_VertFormat format = { 0 };
+		static struct { uint pos, uvs; } attr_id;
+		if (format.attrib_ct == 0) {
+			attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+			attr_id.uvs = GWN_vertformat_attr_add(&format, "uvs", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+		}
+
+		Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+		GWN_vertbuf_data_alloc(vbo, 4);
+
+		for (int i = 0; i < 4; ++i)	{
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, i, pos[i]);
+			GWN_vertbuf_attr_set(vbo, attr_id.uvs, i, uvs[i]);
+		}
+
+		SHC.drw_quad = GWN_batch_create_ex(GWN_PRIM_TRI_FAN, vbo, NULL, GWN_BATCH_OWNS_VBO);
+	}
+	return SHC.drw_quad;
+}
+
 /* Sphere */
 Gwn_Batch *DRW_cache_sphere_get(void)
 {
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index ac7062b3cc8..54b840edfe6 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -35,6 +35,7 @@ void DRW_shape_cache_free(void);
 
 /* Common Shapes */
 struct Gwn_Batch *DRW_cache_fullscreen_quad_get(void);
+struct Gwn_Batch *DRW_cache_quad_get(void);
 struct Gwn_Batch *DRW_cache_sphere_get(void);
 struct Gwn_Batch *DRW_cache_single_vert_get(void);
 struct Gwn_Batch *DRW_cache_single_line_get(void);



More information about the Bf-blender-cvs mailing list