Commit: 608b96c49b93cad8a9b68592c00863a84d857d1b
Author: Clément Foucault
Date:   Sat Mar 4 00:09:22 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB608b96c49b93cad8a9b68592c00863a84d857d1b

Clay Engine: camera 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
M       source/blender/draw/intern/draw_mode_pass.h
M       source/blender/draw/modes/edit_armature_mode.c
M       source/blender/draw/modes/edit_mesh_mode.c
M       source/blender/draw/modes/object_mode.c
M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_shader.c
A       source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
A       source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
M       source/blender/makesdna/DNA_camera_types.h
M       source/blender/makesdna/DNA_world_types.h

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

diff --git a/source/blender/draw/intern/draw_cache.c 
b/source/blender/draw/intern/draw_cache.c
index c16e7c23f0..399ed1032c 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -45,6 +45,7 @@ static struct DRWShapeCache {
        Batch *drw_cube;
        Batch *drw_circle;
        Batch *drw_line;
+       Batch *drw_line_endpoints;
        Batch *drw_empty_sphere;
        Batch *drw_empty_cone;
        Batch *drw_arrows;
@@ -57,6 +58,9 @@ static struct DRWShapeCache {
        Batch *drw_bone_point;
        Batch *drw_bone_point_wire;
        Batch *drw_bone_arrows;
+       Batch *drw_camera;
+       Batch *drw_camera_tria;
+       Batch *drw_camera_focus;
 } SHC = {NULL};
 
 void DRW_shape_cache_free(void)
@@ -75,6 +79,8 @@ void DRW_shape_cache_free(void)
                Batch_discard_all(SHC.drw_circle);
        if (SHC.drw_line)
                Batch_discard_all(SHC.drw_line);
+       if (SHC.drw_line_endpoints)
+               Batch_discard_all(SHC.drw_line_endpoints);
        if (SHC.drw_empty_sphere)
                Batch_discard_all(SHC.drw_empty_sphere);
        if (SHC.drw_empty_cone)
@@ -99,6 +105,12 @@ void DRW_shape_cache_free(void)
                Batch_discard_all(SHC.drw_bone_point_wire);
        if (SHC.drw_bone_arrows)
                Batch_discard_all(SHC.drw_bone_arrows);
+       if (SHC.drw_camera)
+               Batch_discard_all(SHC.drw_camera);
+       if (SHC.drw_camera_tria)
+               Batch_discard_all(SHC.drw_camera_tria);
+       if (SHC.drw_camera_focus)
+               Batch_discard_all(SHC.drw_camera_focus);
 }
 
 /* Helper functions */
@@ -348,6 +360,32 @@ Batch *DRW_cache_single_line_get(void)
        return SHC.drw_line;
 }
 
+
+Batch *DRW_cache_single_line_endpoints_get(void)
+{
+       /* Z axis line */
+       if (!SHC.drw_line_endpoints) {
+               float v1[3] = {0.0f, 0.0f, 0.0f};
+               float v2[3] = {0.0f, 0.0f, 1.0f};
+
+               /* 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, 2);
+
+               setAttrib(vbo, pos_id, 0, v1);
+               setAttrib(vbo, pos_id, 1, v2);
+
+               SHC.drw_line_endpoints = Batch_create(GL_POINTS, vbo, NULL);
+       }
+       return SHC.drw_line_endpoints;
+}
+
 /* Empties */
 Batch *DRW_cache_plain_axes_get(void)
 {
@@ -842,6 +880,104 @@ Batch *DRW_cache_bone_arrows_get(void)
        return SHC.drw_bone_arrows;
 }
 
+/* Camera */
+Batch *DRW_cache_camera_get(void)
+{
+       if (!SHC.drw_camera) {
+               float v0 = 0.0f; /* Center point */
+               float v1 = 1.0f; /* + X + Y */
+               float v2 = 2.0f; /* + X - Y */
+               float v3 = 3.0f; /* - X - Y */
+               float v4 = 4.0f; /* - X + Y */
+               float v5 = 5.0f; /* tria + X */
+               float v6 = 6.0f; /* tria - X */
+               float v7 = 7.0f; /* tria + Y */
+               int v_idx = 0;
+
+               static VertexFormat format = { 0 };
+               static unsigned pos_id;
+               if (format.attrib_ct == 0) {
+                       /* use x coordinate to identify the vertex
+                        * the vertex shader take care to place it
+                        * appropriatelly */
+                       pos_id = add_attrib(&format, "pos", GL_FLOAT, 1, 
KEEP_FLOAT);
+               }
+
+               /* Vertices */
+               VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+               VertexBuffer_allocate_data(vbo, 22);
+
+               setAttrib(vbo, pos_id, v_idx++, &v0);
+               setAttrib(vbo, pos_id, v_idx++, &v1);
+
+               setAttrib(vbo, pos_id, v_idx++, &v0);
+               setAttrib(vbo, pos_id, v_idx++, &v2);
+
+               setAttrib(vbo, pos_id, v_idx++, &v0);
+               setAttrib(vbo, pos_id, v_idx++, &v3);
+
+               setAttrib(vbo, pos_id, v_idx++, &v0);
+               setAttrib(vbo, pos_id, v_idx++, &v4);
+
+               /* camera frame */
+               setAttrib(vbo, pos_id, v_idx++, &v1);
+               setAttrib(vbo, pos_id, v_idx++, &v2);
+
+               setAttrib(vbo, pos_id, v_idx++, &v2);
+               setAttrib(vbo, pos_id, v_idx++, &v3);
+
+               setAttrib(vbo, pos_id, v_idx++, &v3);
+               setAttrib(vbo, pos_id, v_idx++, &v4);
+
+               setAttrib(vbo, pos_id, v_idx++, &v4);
+               setAttrib(vbo, pos_id, v_idx++, &v1);
+
+               /* tria */
+               setAttrib(vbo, pos_id, v_idx++, &v5);
+               setAttrib(vbo, pos_id, v_idx++, &v6);
+
+               setAttrib(vbo, pos_id, v_idx++, &v6);
+               setAttrib(vbo, pos_id, v_idx++, &v7);
+
+               setAttrib(vbo, pos_id, v_idx++, &v7);
+               setAttrib(vbo, pos_id, v_idx++, &v5);
+
+               SHC.drw_camera = Batch_create(GL_LINES, vbo, NULL);
+       }
+       return SHC.drw_camera;
+}
+
+Batch *DRW_cache_camera_tria_get(void)
+{
+       if (!SHC.drw_camera_tria) {
+               float v5 = 5.0f; /* tria + X */
+               float v6 = 6.0f; /* tria - X */
+               float v7 = 7.0f; /* tria + Y */
+               int v_idx = 0;
+
+               static VertexFormat format = { 0 };
+               static unsigned pos_id;
+               if (format.attrib_ct == 0) {
+                       /* use x coordinate to identify the vertex
+                        * the vertex shader take care to place it
+                        * appropriatelly */
+                       pos_id = add_attrib(&format, "pos", GL_FLOAT, 1, 
KEEP_FLOAT);
+               }
+
+               /* Vertices */
+               VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+               VertexBuffer_allocate_data(vbo, 6);
+
+               /* tria */
+               setAttrib(vbo, pos_id, v_idx++, &v5);
+               setAttrib(vbo, pos_id, v_idx++, &v6);
+               setAttrib(vbo, pos_id, v_idx++, &v7);
+
+               SHC.drw_camera_tria = Batch_create(GL_TRIANGLES, vbo, NULL);
+       }
+       return SHC.drw_camera_tria;
+}
+
 /* 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 042bc65b17..bfab441bee 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);
 struct Batch *DRW_cache_fullscreen_quad_get(void);
 struct Batch *DRW_cache_single_vert_get(void);
 struct Batch *DRW_cache_single_line_get(void);
+struct Batch *DRW_cache_single_line_endpoints_get(void);
 
 /* Empties */
 struct Batch *DRW_cache_plain_axes_get(void);
@@ -50,6 +51,10 @@ struct Batch *DRW_cache_axis_names_get(void);
 struct Batch *DRW_cache_lamp_get(void);
 struct Batch *DRW_cache_lamp_sunrays_get(void);
 
+/* Camera */
+struct Batch *DRW_cache_camera_get(void);
+struct Batch *DRW_cache_camera_tria_get(void);
+
 /* Speaker */
 struct Batch *DRW_cache_speaker_get(void);
 
diff --git a/source/blender/draw/intern/draw_mode_pass.c 
b/source/blender/draw/intern/draw_mode_pass.c
index 7bf34c4a9b..a066f8ce4f 100644
--- a/source/blender/draw/intern/draw_mode_pass.c
+++ b/source/blender/draw/intern/draw_mode_pass.c
@@ -23,13 +23,17 @@
  *  \ingroup draw
  */
 
+#include "DNA_camera_types.h"
 #include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_world_types.h"
 
 #include "GPU_shader.h"
 
 #include "UI_resources.h"
 
 #include "BKE_global.h"
+#include "BKE_camera.h"
 
 #include "DRW_render.h"
 
@@ -70,6 +74,15 @@ static DRWShadingGroup *center_active;
 static DRWShadingGroup *center_selected;
 static DRWShadingGroup *center_deselected;
 
+/* Camera */
+static DRWShadingGroup *camera;
+static DRWShadingGroup *camera_tria;
+static DRWShadingGroup *camera_focus;
+static DRWShadingGroup *camera_clip;
+static DRWShadingGroup *camera_clip_points;
+static DRWShadingGroup *camera_mist;
+static DRWShadingGroup *camera_mist_points;
+
 /* Colors & Constant */
 GlobalsUboStorage ts;
 struct GPUUniformBuffer *globals_ubo = NULL;
@@ -244,6 +257,36 @@ static DRWShadingGroup *shgroup_instance(DRWPass *pass, 
struct Batch *geom)
        return grp;
 }
 
+static DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct Batch 
*geom)
+{
+       GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_CAMERA);
+
+       DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom);
+       DRW_shgroup_attrib_float(grp, "color", 3);
+       DRW_shgroup_attrib_float(grp, "corners", 8);
+       DRW_shgroup_attrib_float(grp, "depth", 1);
+       DRW_shgroup_attrib_float(grp, "tria", 4);
+       DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
+
+       return grp;
+}
+
+
+static DRWShadingGroup *shgroup_distance_lines_instance(DRWPass *pass, struct 
Batch *geom)
+{
+       GPUShader *sh_inst = 
GPU_shader_get_builtin_shader(GPU_SHADER_DISTANCE_LINES);
+       static float point_size = 4.0f;
+
+       DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom);
+       DRW_shgroup_attrib_float(grp, "color", 3);
+       DRW_shgroup_attrib_float(grp, "start", 1);
+       DRW_shgroup_attrib_float(grp, "end", 1);
+       DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
+       DRW_shgroup_uniform_float(grp, "size", &point_size, 1);
+
+       return grp;
+}
+
 /* This Function setup the passes needed for the mode rendering.
  * The passes are populated by the rendering engines using the DRW_shgroup_* 
functions.
  * If a pass is not needed use NULL instead of the pass pointer */
@@ -293,7 +336,7 @@ void DRW_mode_passes_setup(DRWPass **psl_wire_overlay,
                /* Non Meshes Pass (Camera, empties, lamps ...) */
                struct Batch *geom;
 
-               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH 
| DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND;
+               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH 
| DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_POINT;
                state |= DRW_STATE_WIRE;
                *psl_non_meshes = DRW_pass_create("Non Meshes Pass", state);
 
@@ -329,6 +372,24 @@ void DRW_mode_passes_setup(DRWPass **psl_wire_overlay,
                geom = DRW_cache_speaker_get();
                speaker = shgroup_instance(*psl_non_meshes, geom);
 
+               /* Camera */
+               geom = DRW_cache_camera_get();
+               camera = shgroup_camera_instance(*psl_non_meshes, geom);
+
+               geom = DRW_cache_camera_tria_get();
+               camera_tria = shgroup_camera_instance(*psl_non_meshes, geom);
+
+               geom = DRW_cache_plain_axes_get();
+               camera_focus = shgroup_instance(*psl_non_meshes, geom);
+
+               geom = DRW_cache_single_line_get();
+               camera_clip = shgroup_distance_lines_instance(*psl_non_meshes, 
geom);
+               camera_mist = shgroup_distance_lines_instance(*psl_non_meshes, 
geom);
+
+               geom = DRW_cache_single_line_endpoints_get();
+               camera_clip_points = 
shgroup_distance_lines_instance(*psl_non_meshes, geom);
+               camera_mist_points = 
shgroup_distance_lines_instance(*psl_non_meshes, geom);
+
                /* Lamps */
                /* TODO
                 * for now we create 3 times the same VBO with only lamp center 
coordinates
@@ -555,6 +616,80 @@ void DRW_shgroup_lamp(Object *ob)
        DRW_shgroup_dynamic_call_add(lamp_groundpoint, ob->obmat[3]);
 }
 
+void DRW_shgroup_camera(Object *ob)
+{
+       const struct bContext *C = DRW_get_context();
+       View3D *v3d = CTX_wm_view3d(C);
+       Scene *scene = CTX_data_scene(C);
+
+       Camera *cam = ob->data;
+       const bool is_active = (ob == v3d->cam

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to