Commit: 160c643131bafcf0b117bd03e6dd3b2a301e8a2f
Author: Clément Foucault
Date:   Wed Feb 1 13:58:10 2017 +0100
Branches: clay-engine
https://developer.blender.org/rB160c643131bafcf0b117bd03e6dd3b2a301e8a2f

Implemented All Empties type drawing

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

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

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

diff --git a/source/blender/draw/intern/draw_cache.c 
b/source/blender/draw/intern/draw_cache.c
index 5889410db6..de171df511 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -41,12 +41,13 @@ static struct DRWShapeCache{
        Batch *drw_single_vertice;
        Batch *drw_fullscreen_quad;
        Batch *drw_plain_axes;
-       Batch *drw_circle_ball;
-       // Batch drw_cube;
-       // Batch drw_circle;
-       // Batch drw_sphere;
-       // Batch drw_cone;
-       // Batch drw_arrows;
+       Batch *drw_single_arrow;
+       Batch *drw_single_arrow_line;
+       Batch *drw_cube;
+       Batch *drw_circle;
+       Batch *drw_empty_sphere;
+       Batch *drw_empty_cone;
+       Batch *drw_arrows;
 } SHC = {NULL};
 
 /* Quads */
@@ -82,11 +83,47 @@ Batch *DRW_cache_fullscreen_quad_get(void)
 }
 
 /* Common */
-#define CIRCLE_RESOL 32
 
-Batch *DRW_cache_circle_ball_get(void)
+Batch *DRW_cache_cube_get(void)
+{
+       if (!SHC.drw_cube) {
+               const GLfloat verts[8][3] = {
+                       {-1.0f, -1.0f, -1.0f},
+                       {-1.0f, -1.0f,  1.0f},
+                       {-1.0f,  1.0f, -1.0f},
+                       {-1.0f,  1.0f,  1.0f},
+                       { 1.0f, -1.0f, -1.0f},
+                       { 1.0f, -1.0f,  1.0f},
+                       { 1.0f,  1.0f, -1.0f},
+                       { 1.0f,  1.0f,  1.0f}
+               };
+
+               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, 24);
+
+               for (int i = 0; i < 24; ++i) {
+                       setAttrib(vbo, pos_id, i, verts[indices[i]]);
+               }
+
+               SHC.drw_cube = Batch_create(GL_LINES, vbo, NULL);
+       }
+       return SHC.drw_cube;
+}
+
+
+Batch *DRW_cache_circle_get(void)
 {
-       if (!SHC.drw_circle_ball) {
+#define CIRCLE_RESOL 32
+       if (!SHC.drw_circle) {
                float v[3] = {0.0f, 0.0f, 0.0f};
 
                /* Position Only 3D format */
@@ -103,12 +140,13 @@ Batch *DRW_cache_circle_ball_get(void)
                        v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
                        v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
                        v[2] = 0.0f;
-                       setAttrib(vbo, pos_id, 0, v);
+                       setAttrib(vbo, pos_id, a, v);
                }
 
-               SHC.drw_circle_ball = Batch_create(GL_LINE_LOOP, vbo, NULL);
+               SHC.drw_circle = Batch_create(GL_LINE_LOOP, vbo, NULL);
        }
-       return SHC.drw_circle_ball;
+       return SHC.drw_circle;
+#undef CIRCLE_RESOL
 }
 
 /* Empties */
@@ -145,6 +183,195 @@ Batch *DRW_cache_plain_axes_get(void)
        return SHC.drw_plain_axes;
 }
 
+Batch *DRW_cache_single_arrow_get(Batch **line)
+{
+       if (!SHC.drw_single_arrow_line || !SHC.drw_single_arrow) {
+               float v1[3] = {0.0f, 0.0f, 0.0f}, v2[3], v3[3];
+
+               /* 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);
+               }
+
+               /* Line */
+               VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+               VertexBuffer_allocate_data(vbo, 2);
+
+               setAttrib(vbo, pos_id, 0, v1);
+               v1[2] = 1.0f;
+               setAttrib(vbo, pos_id, 1, v1);
+
+               SHC.drw_single_arrow_line = Batch_create(GL_LINES, vbo, NULL);
+
+               /* Square Pyramid */
+               vbo = VertexBuffer_create_with_format(&format);
+               VertexBuffer_allocate_data(vbo, 12);
+
+               v2[0] = 0.035f; v2[1] = 0.035f;
+               v3[0] = -0.035f; v3[1] = 0.035f;
+               v2[2] = v3[2] = 0.75f;
+
+               for (int sides = 0; sides < 4; sides++) {
+                       if (sides % 2 == 1) {
+                               v2[0] = -v2[0];
+                               v3[1] = -v3[1];
+                       }
+                       else {
+                               v2[1] = -v2[1];
+                               v3[0] = -v3[0];
+                       }
+
+                       setAttrib(vbo, pos_id, sides * 3 + 0, v1);
+                       setAttrib(vbo, pos_id, sides * 3 + 1, v2);
+                       setAttrib(vbo, pos_id, sides * 3 + 2, v3);
+               }
+
+               SHC.drw_single_arrow = Batch_create(GL_TRIANGLES, vbo, NULL);
+       }
+       *line = SHC.drw_single_arrow_line;
+       return SHC.drw_single_arrow;
+}
+
+Batch *DRW_cache_empty_sphere_get(void)
+{
+#define NSEGMENTS 16
+       if (!SHC.drw_empty_sphere) {
+               /* a single ring of vertices */
+               float p[NSEGMENTS][2];
+               for (int i = 0; i < NSEGMENTS; ++i) {
+                       float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
+                       p[i][0] = cosf(angle);
+                       p[i][1] = sinf(angle);
+               }
+
+               /* 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, NSEGMENTS * 2 * 3);
+
+               for (int axis = 0; axis < 3; ++axis) {
+                       for (int i = 0; i < NSEGMENTS; ++i) {
+                               for (int j = 0; j < 2; ++j) {
+                                       float cv[2], v[3];
+
+                                       cv[0] = p[(i+j) % NSEGMENTS][0];
+                                       cv[1] = p[(i+j) % NSEGMENTS][1];
+
+                                       if (axis == 0)
+                                               v[0] = cv[0], v[1] = cv[1], 
v[2] = 0.0f;
+                                       else if (axis == 1)
+                                               v[0] = cv[0], v[1] = 0.0f,  
v[2] = cv[1];
+                                       else
+                                               v[0] = 0.0f,  v[1] = cv[0], 
v[2] = cv[1];
+
+                                       setAttrib(vbo, pos_id, i*2 + j + 
(NSEGMENTS * 2 * axis), v);
+                               }
+                       }
+               }
+
+               SHC.drw_empty_sphere = Batch_create(GL_LINES, vbo, NULL);
+       }
+       return SHC.drw_empty_sphere;
+#undef NSEGMENTS
+}
+
+Batch *DRW_cache_empty_cone_get(void)
+{
+#define NSEGMENTS 8
+       if (!SHC.drw_empty_cone) {
+               /* a single ring of vertices */
+               float p[NSEGMENTS][2];
+               for (int i = 0; i < NSEGMENTS; ++i) {
+                       float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
+                       p[i][0] = cosf(angle);
+                       p[i][1] = sinf(angle);
+               }
+
+               /* 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, NSEGMENTS * 4);
+
+               for (int i = 0; i < NSEGMENTS; ++i) {
+                       float cv[2], v[3];
+                       cv[0] = p[(i) % NSEGMENTS][0];
+                       cv[1] = p[(i) % NSEGMENTS][1];
+
+                       /* cone sides */
+                       v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
+                       setAttrib(vbo, pos_id, i*4, v);
+                       v[0] = 0.0f, v[1] = 2.0f, v[2] = 0.0f;
+                       setAttrib(vbo, pos_id, i*4 + 1, v);
+
+                       /* end ring */
+                       v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
+                       setAttrib(vbo, pos_id, i*4 + 2, v);
+                       cv[0] = p[(i+1) % NSEGMENTS][0];
+                       cv[1] = p[(i+1) % NSEGMENTS][1];
+                       v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
+                       setAttrib(vbo, pos_id, i*4 + 3, v);
+               }
+
+               SHC.drw_empty_cone = Batch_create(GL_LINES, vbo, NULL);
+       }
+       return SHC.drw_empty_cone;
+#undef NSEGMENTS
+}
+
+Batch *DRW_cache_arrows_get(void)
+{
+       if (!SHC.drw_arrows) {
+               float v1[3] = {0.0, 0.0, 0.0};
+               float v2[3] = {0.0, 0.0, 0.0};
+
+               /* 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);
+               }
+
+               /* Line */
+               VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+               VertexBuffer_allocate_data(vbo, 6 * 3);
+
+               for (int axis = 0; axis < 3; axis++) {
+                       const int arrow_axis = (axis == 0) ? 1 : 0;
+
+                       v2[axis] = 1.0f;
+                       setAttrib(vbo, pos_id, axis * 6 + 0, v1);
+                       setAttrib(vbo, pos_id, axis * 6 + 1, v2);
+
+                       v1[axis] = 0.85f;
+                       v1[arrow_axis] = -0.08f;
+                       setAttrib(vbo, pos_id, axis * 6 + 2, v1);
+                       setAttrib(vbo, pos_id, axis * 6 + 3, v2);
+
+                       v1[arrow_axis] = 0.08f;
+                       setAttrib(vbo, pos_id, axis * 6 + 4, v1);
+                       setAttrib(vbo, pos_id, axis * 6 + 5, v2);
+
+                       /* reset v1 & v2 to zero */
+                       v1[arrow_axis] = v1[axis] = v2[axis] = 0.0f;
+               }
+
+               SHC.drw_arrows = Batch_create(GL_LINES, vbo, NULL);
+       }
+       return SHC.drw_arrows;
+}
+
 /* Object Center */
 Batch *DRW_cache_single_vert_get(void)
 {
diff --git a/source/blender/draw/intern/draw_cache.h 
b/source/blender/draw/intern/draw_cache.h
index 54abccdd47..abe3ee7e77 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -31,9 +31,17 @@ struct Object;
 
 /* Common Shapes */
 struct Batch *DRW_cache_fullscreen_quad_get(void);
-struct Batch *DRW_cache_circle_ball_get(void);
 struct Batch *DRW_cache_single_vert_get(void);
+
+/* Empties */
 struct Batch *DRW_cache_plain_axes_get(void);
+struct Batch *DRW_cache_single_arrow_get(struct Batch **line);
+struct Batch *DRW_cache_cube_get(void);
+struct Batch *DRW_cache_circle_get(void);
+struct Batch *DRW_cache_empty_sphere_get(void);
+struct Batch *DRW_cache_empty_cone_get(void);
+struct Batch *DRW_cache_arrows_get(void);
+
 /* Meshes */
 struct Batch *DRW_cache_wire_overlay_get(struct Object *ob);
 struct Batch *DRW_cache_wire_outline_get(struct Object *ob);
diff --git a/source/blender/draw/intern/draw_mode_pass.c 
b/source/blender/draw/intern/draw_mode_pass.c
index 0d5ea5ea6c..b6876d0a1c 100644
--- a/source/blender/draw/intern/draw_mode_pass.c
+++ b/source/blender/draw/intern/draw_mode_pass.c
@@ -45,6 +45,55 @@ static DRWShadingGroup *plain_axes_transform;
 static DRWShadingGroup *plain_axes_group;
 static DRWShadingGroup *plain_axes_group_active;
 
+static DRWShadingGroup *cube_wire;
+static DRWShadingGroup *cube_active;
+static DRWShadingGroup *cube_select;
+static DRWShadingGroup *cube_transform;
+static DRWShadingGroup *cube_group;
+static DRWShadingGroup *cube_group_active;
+
+static DRWShadingGroup *circle_wire;
+static DRWShadingGroup *circle_active;
+static DRWShadingGroup *circle_select;
+static DRWShadingGroup *circle_transform;
+static DRWShadingGroup *circle_group;
+static DRWShadingGroup *circle_group_active;
+
+static DRWShadingGroup *sphere_wire;
+static DRWShadingGroup *sphere_active;
+static DRWShadingGroup *sphere_select;
+static DRWShadingGroup *sphere_transform;
+static DRWShadingGroup *sphere_group;
+static DRWShadingGroup *sphere_group_active;
+
+static DRWShadingGroup *cone_wire;
+static DRWShadingGroup *cone_active;
+static DRWShadingGroup *cone_select;
+static DRWShadingGroup *cone_transform;
+static DRWShadingGroup *cone_group;
+static DRWShadingGroup *cone_group_active;
+
+static DRWShadingGroup *single_arrow_wire;
+static DRWShadingGroup *single_arrow_active;
+static DRWShadingGroup *single_arrow_select;
+static DRWShadingGroup *single_arrow_transform;
+static DRWShadingGroup *single_arrow_group;
+static DRWShadingGroup *single_arrow_group_active;
+
+static DRWShadingGro

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to