[Bf-blender-cvs] [ee54a6f] blender2.8: viewport: draw non-mesh objects for a starter
Dalai Felinto
noreply at git.blender.org
Fri Oct 14 23:54:21 CEST 2016
Commit: ee54a6f130765341bb4a235e09509d271f219a73
Author: Dalai Felinto
Date: Fri Oct 14 05:17:06 2016 +0000
Branches: blender2.8
https://developer.blender.org/rBee54a6f130765341bb4a235e09509d271f219a73
viewport: draw non-mesh objects for a starter
This starts to decouple non-mesh objects and the legacy draw pipeline.
It shows how we can mix e.g., Cycles and lamps and empties.
===================================================================
M source/blender/editors/space_view3d/drawobject.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/editors/space_view3d/view3d_intern.h
===================================================================
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index af11136..c365105 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -1169,8 +1169,8 @@ static void draw_transp_sun_volume(Lamp *la)
}
#endif
-static void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
- const char dt, const short dflag, const unsigned char ob_wire_col[4], const bool is_obact)
+void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
+ const char dt, const short dflag, const unsigned char ob_wire_col[4], const bool is_obact)
{
Object *ob = base->object;
const float pixsize = ED_view3d_pixel_size(rv3d, ob->obmat[3]);
@@ -3929,7 +3929,7 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d,
/* Mesh drawing routines */
-static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
+void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
{
if ((v3d->transp == false) && /* not when we draw the transparent pass */
(ob->mode & OB_MODE_ALL_PAINT) == false) /* not when painting (its distracting) - campbell */
@@ -6540,6 +6540,13 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
}
}
+ /* TODO Viewport: draw only depth here, for selection */
+ if (!IS_VIEWPORT_LEGACY(v3d)) {
+ if (ELEM(ob->type, OB_EMPTY, OB_LAMP)) {
+ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ }
+ }
+
switch (ob->type) {
case OB_MESH:
empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
@@ -6668,6 +6675,11 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
break;
}
+ /* TODO Viewport: some eleemnts are being drawn for depth only */
+ if (!IS_VIEWPORT_LEGACY(v3d)) {
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ }
+
if (!render_override) {
if (ob->soft /*&& dflag & OB_SBMOTION*/) {
float mrt[3][3], msc[3][3], mtr[3][3];
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 5ae655f..05dd937 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1300,6 +1300,41 @@ static void view3d_draw_grid(const bContext *C, ARegion *ar)
glDisable(GL_DEPTH_TEST);
}
+/* ******************** non-meshes ***************** */
+
+static void view3d_draw_non_mesh(
+Object *ob, Base *base, View3D *v3d,
+RegionView3D *rv3d, const unsigned char color[4])
+{
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ /* multiply view with object matrix.
+ * local viewmat and persmat, to calculate projections */
+ ED_view3d_init_mats_rv3d_gl(ob, rv3d);
+
+ switch (ob->type) {
+ case OB_EMPTY:
+ drawaxes(rv3d->viewmatob, ob->empty_drawsize, ob->empty_drawtype);
+ break;
+ case OB_LAMP:
+ drawlamp(v3d, rv3d, base, OB_SOLID, DRAW_CONSTCOLOR, color, false);
+ break;
+ default:
+ /* TODO Viewport: handle the other cases*/
+ break;
+ }
+
+ ED_view3d_clear_mats_rv3d(rv3d);
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+}
+
/* ******************** info ***************** */
/**
@@ -1432,8 +1467,59 @@ static void view3d_draw_geometry_overlay(const bContext *C)
view3d_draw_outline_plates(C);
}
+/* drawing cameras, lamps, ... */
+static void view3d_draw_non_meshes(const bContext *C, ARegion *ar)
+{
+ /* TODO viewport
+ * for now we draw them all, in the near future
+ * we filter them based on the plates/layers
+ */
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ RegionView3D *rv3d = ar->regiondata;
+ Object *ob_act = CTX_data_active_object(C);
+ Base *base;
+
+ unsigned char *color, *color_prev = NULL;
+ unsigned char color_active[4], color_select[4], color_normal[4];
+
+ UI_GetThemeColor4ubv(TH_ACTIVE, color_active);
+ UI_GetThemeColor4ubv(TH_SELECT, color_select);
+ UI_GetThemeColor4ubv(TH_WIRE, color_normal);
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE); /* disable write in zbuffer */
+ /* TODO Viewport
+ * we are already temporarily writing to zbuffer in draw_object()
+ * for now let's avoid writing again to zbuffer to prevent glitches
+ */
+
+ for (base = scene->base.first; base; base = base->next) {
+ if (v3d->lay & base->lay) {
+ Object *ob = base->object;
+
+ if (ob == ob_act)
+ color = color_active;
+ else if (ob->flag & SELECT)
+ color = color_select;
+ else
+ color = color_normal;
+
+ if (color != color_prev) {
+ glColor4ubv(color);
+ color_prev = color;
+ }
+
+ view3d_draw_non_mesh(ob, base, v3d, rv3d, color);
+ }
+ }
+
+ glDepthMask(GL_TRUE);
+ glDisable(GL_DEPTH_TEST);
+}
+
/**
-* Empties, lamps, parent lines, grid, ...
+* Parent lines, grid, ...
*/
static void view3d_draw_other_elements(const bContext *C, ARegion *ar)
{
@@ -1502,6 +1588,7 @@ static void view3d_draw_view(const bContext *C, ARegion *ar, DrawData *draw_data
view3d_draw_prerender_buffers(C, ar, draw_data);
view3d_draw_solid_plates(C, ar, draw_data);
view3d_draw_geometry_overlay(C);
+ view3d_draw_non_meshes(C, ar);
view3d_draw_other_elements(C, ar);
view3d_draw_tool_ui(C);
view3d_draw_reference_images(C);
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index a5a5aab..92658af 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -143,10 +143,15 @@ void draw_motion_paths_cleanup(View3D *v3d);
/* drawobject.c */
void draw_object(Scene *scene, struct ARegion *ar, View3D *v3d, Base *base, const short dflag);
+void draw_mesh_object_outline(View3D *v3d, Object *ob, struct DerivedMesh *dm);
+
bool draw_glsl_material(Scene *scene, struct Object *ob, View3D *v3d, const char dt);
void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob, const char dt, int outline);
void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob);
void drawaxes(const float viewmat_local[4][4], float size, char drawtype);
+void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
+ const char dt, const short dflag, const unsigned char ob_wire_col[4],
+ const bool is_obact);
void view3d_cached_text_draw_begin(void);
void view3d_cached_text_draw_add(const float co[3],
More information about the Bf-blender-cvs
mailing list