[Bf-blender-cvs] [277d0891ffb] greasepencil-object: Add new draw manager symbol for new ob_gpencil object type

Antonio Vazquez noreply at git.blender.org
Wed Apr 5 16:52:11 CEST 2017


Commit: 277d0891ffbcee7d008905373afc6643c7d40367
Author: Antonio Vazquez
Date:   Wed Apr 5 16:50:12 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB277d0891ffbcee7d008905373afc6643c7d40367

Add new draw manager symbol for new ob_gpencil object type

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

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

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 0d79011d267..1c4217c1840 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -66,6 +66,7 @@ static struct DRWShapeCache {
 	Batch *drw_camera;
 	Batch *drw_camera_tria;
 	Batch *drw_camera_focus;
+	Batch *drw_gpencil_axes;
 } SHC = {NULL};
 
 void DRW_shape_cache_free(void)
@@ -425,6 +426,60 @@ Batch *DRW_cache_single_line_endpoints_get(void)
 	return SHC.drw_line_endpoints;
 }
 
+/* Grease Pencil object */
+Batch *DRW_cache_gpencil_axes_get(void)
+{
+	if (!SHC.drw_gpencil_axes) {
+		int axis;
+		float v1[3] = { 0.0f, 0.0f, 0.0f };
+		float v2[3] = { 0.0f, 0.0f, 0.0f };
+		
+		/* cube data */
+		const GLfloat verts[8][3] = {
+			{ -0.25f, -0.25f, -0.25f },
+			{ -0.25f, -0.25f,  0.25f },
+			{ -0.25f,  0.25f, -0.25f },
+			{ -0.25f,  0.25f,  0.25f },
+			{ 0.25f, -0.25f, -0.25f },
+			{ 0.25f, -0.25f,  0.25f },
+			{ 0.25f,  0.25f, -0.25f },
+			{ 0.25f,  0.25f,  0.25f }
+		};
+
+		const GLubyte indices[24] = { 0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 4, 5, 5, 7, 7, 6, 6, 4, 1, 5, 3, 7, 2, 6 };
+
+		/* Position Only 3D format */
+		static VertexFormat format = { 0 };
+		static unsigned pos_id;
+		if (format.attrib_ct == 0) {
+			pos_id = add_attrib(&format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+		}
+
+		VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+		VertexBuffer_allocate_data(vbo, 30);
+
+		/* draw axis */
+		for (axis = 0; axis < 3; axis++) {
+			v1[axis] = 1.0f;
+			v2[axis] = -1.0f;
+
+			setAttrib(vbo, pos_id, axis * 2, v1);
+			setAttrib(vbo, pos_id, axis * 2 + 1, v2);
+
+			/* reset v1 & v2 to zero for next axis */
+			v1[axis] = v2[axis] = 0.0f;
+		}
+
+		/* draw cube */
+		for (int i = 0; i < 24; ++i) {
+			setAttrib(vbo, pos_id, i + 6, verts[indices[i]]);
+		}
+
+		SHC.drw_gpencil_axes = Batch_create(GL_LINES, vbo, NULL);
+	}
+	return SHC.drw_gpencil_axes;
+}
+
 /* Empties */
 Batch *DRW_cache_plain_axes_get(void)
 {
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 0af7f3d08b1..c9c9f17586b 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -48,6 +48,9 @@ struct Batch *DRW_cache_empty_cone_get(void);
 struct Batch *DRW_cache_arrows_get(void);
 struct Batch *DRW_cache_axis_names_get(void);
 
+/* Grease Pencil */
+struct Batch *DRW_cache_gpencil_axes_get(void);
+
 /* Lamps */
 struct Batch *DRW_cache_lamp_get(void);
 struct Batch *DRW_cache_lamp_sunrays_get(void);
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index e301c3e4e8a..ff6d5799d4e 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -114,6 +114,9 @@ typedef struct g_data{
 	DRWShadingGroup *arrows;
 	DRWShadingGroup *axis_names;
 
+	/* Grease Pencil */
+	DRWShadingGroup *gpencil_axes;
+
 	/* Speaker */
 	DRWShadingGroup *speaker;
 
@@ -570,6 +573,10 @@ static void OBJECT_cache_init(void *vedata)
 		geom = DRW_cache_axis_names_get();
 		stl->g_data->axis_names = shgroup_instance_axis_names(psl->non_meshes, geom);
 
+		/* Grease Pencil */
+		geom = DRW_cache_gpencil_axes_get();
+		stl->g_data->gpencil_axes = shgroup_instance(psl->non_meshes, geom);
+
 		/* Speaker */
 		geom = DRW_cache_speaker_get();
 		stl->g_data->speaker = shgroup_instance(psl->non_meshes, geom);
@@ -878,6 +885,14 @@ static void DRW_shgroup_empty(OBJECT_StorageList *stl, Object *ob, SceneLayer *s
 	}
 }
 
+static void DRW_shgroup_gpencil(OBJECT_StorageList *stl, Object *ob, SceneLayer *sl)
+{
+	float *color;
+	DRW_object_wire_theme_get(ob, sl, &color);
+
+	DRW_shgroup_dynamic_call_add(stl->g_data->gpencil_axes, color, &ob->empty_drawsize, ob->obmat);
+}
+
 static void DRW_shgroup_speaker(OBJECT_StorageList *stl, Object *ob, SceneLayer *sl)
 {
 	float *color;
@@ -952,6 +967,9 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
 		case OB_EMPTY:
 			DRW_shgroup_empty(stl, ob, sl);
 			break;
+		case OB_GPENCIL:
+			DRW_shgroup_gpencil(stl, ob, sl);
+			break;
 		case OB_SPEAKER:
 			DRW_shgroup_speaker(stl, ob, sl);
 			break;




More information about the Bf-blender-cvs mailing list