[Bf-blender-cvs] [e813ebab71] blender2.8: Clay Engine: new draw_view.c containing all dynamic drawing routines.
Clément Foucault
noreply at git.blender.org
Wed Feb 15 12:30:29 CET 2017
Commit: e813ebab710174eaa0f3dec0b7ba848783b44bd8
Author: Clément Foucault
Date: Tue Feb 14 17:48:16 2017 +0100
Branches: blender2.8
https://developer.blender.org/rBe813ebab710174eaa0f3dec0b7ba848783b44bd8
Clay Engine: new draw_view.c containing all dynamic drawing routines.
===================================================================
M source/blender/draw/CMakeLists.txt
M source/blender/draw/engines/clay/clay.c
M source/blender/draw/intern/DRW_render.h
M source/blender/draw/intern/draw_manager.c
M source/blender/draw/intern/draw_mode_pass.c
M source/blender/draw/intern/draw_mode_pass.h
A source/blender/draw/intern/draw_view.c
A source/blender/draw/intern/draw_view.h
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index d5b54e8a74..006fb0fbc2 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -53,11 +53,13 @@ set(SRC
intern/draw_manager.c
intern/draw_mode_pass.c
intern/draw_cache.c
+ intern/draw_view.c
engines/clay/clay.c
intern/DRW_render.h
intern/draw_mode_pass.h
intern/draw_cache.h
+ intern/draw_view.h
engines/clay/clay.h
./DRW_engine.h
diff --git a/source/blender/draw/engines/clay/clay.c b/source/blender/draw/engines/clay/clay.c
index 779fd1a6a1..b06d8c3497 100644
--- a/source/blender/draw/engines/clay/clay.c
+++ b/source/blender/draw/engines/clay/clay.c
@@ -718,11 +718,16 @@ static void CLAY_view_draw(RenderEngine *UNUSED(engine), const bContext *context
/* Pass 4 : Overlays */
DRW_framebuffer_texture_attach(buffers->default_fb, textures->depth, 0);
+
+ DRW_draw_grid();
//DRW_draw_pass(passes->wire_overlay_pass);
//DRW_draw_pass(passes->wire_outline_pass);
DRW_draw_pass(passes->non_meshes_pass);
DRW_draw_pass(passes->ob_center_pass);
+ DRW_draw_manipulator();
+ DRW_draw_region_info();
+
/* Always finish by this */
DRW_state_reset();
}
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 78edae803b..775ae1c6e3 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -46,6 +46,7 @@
#include "draw_mode_pass.h"
#include "draw_cache.h"
+#include "draw_view.h"
#include "MEM_guardedalloc.h"
@@ -53,6 +54,7 @@
//#define WITH_VIEWPORT_CACHE_TEST
+struct bContext;
struct GPUFrameBuffer;
struct GPUShader;
struct GPUTexture;
@@ -209,13 +211,12 @@ void *DRW_render_settings_get(Scene *scene, const char *engine_name);
#endif /* __DRW_ENGINE_H__ */
/* Draw commands */
-void DRW_draw_background(void);
-void DRW_centercircle(const float co[3]);
void DRW_draw_pass(DRWPass *pass);
void DRW_state_reset(void);
/* Other */
void DRW_get_dfdy_factors(float dfdyfac[2]);
+const struct bContext *DRW_get_context(void);
#endif /* __DRW_RENDER_H__ */
\ No newline at end of file
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 970bd2f6de..18bd26daf8 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -40,13 +40,10 @@
#include "DNA_view3d_types.h"
-#include "GPU_basic_shader.h"
#include "GPU_batch.h"
#include "GPU_draw.h"
#include "GPU_extensions.h"
#include "GPU_framebuffer.h"
-#include "GPU_immediate.h"
-#include "GPU_matrix.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "GPU_uniformbuffer.h"
@@ -705,48 +702,6 @@ void DRW_pass_free(DRWPass *pass)
/* ****************************************** DRAW ******************************************/
-void DRW_draw_background(void)
-{
- /* Just to make sure */
- glDepthMask(GL_TRUE);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
- if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
- /* Gradient background Color */
- gpuMatrixBegin3D(); /* TODO: finish 2D API */
-
- glClear(GL_DEPTH_BUFFER_BIT);
-
- VertexFormat *format = immVertexFormat();
- unsigned pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
- unsigned color = add_attrib(format, "color", COMP_U8, 3, NORMALIZE_INT_TO_FLOAT);
- unsigned char col_hi[3], col_lo[3];
-
- immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
-
- UI_GetThemeColor3ubv(TH_LOW_GRAD, col_lo);
- UI_GetThemeColor3ubv(TH_HIGH_GRAD, col_hi);
-
- immBegin(GL_QUADS, 4);
- immAttrib3ubv(color, col_lo);
- immVertex2f(pos, -1.0f, -1.0f);
- immVertex2f(pos, 1.0f, -1.0f);
-
- immAttrib3ubv(color, col_hi);
- immVertex2f(pos, 1.0f, 1.0f);
- immVertex2f(pos, -1.0f, 1.0f);
- immEnd();
-
- immUnbindProgram();
-
- gpuMatrixEnd();
- }
- else {
- /* Solid background Color */
- UI_ThemeClearColorAlpha(TH_HIGH_GRAD, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
-}
#ifdef WITH_CLAY_ENGINE
/* Only alter the state (does not reset it like set_state() ) */
static void shgroup_set_state(DRWShadingGroup *shgroup)
@@ -1251,7 +1206,14 @@ bool DRW_viewport_cache_is_dirty(void)
return (DST.current_psl->passes[0] == NULL);
}
-/* ****************************************** INIT ******************************************/
+/* ****************************************** OTHER ***************************************** */
+
+const bContext *DRW_get_context(void)
+{
+ return DST.context;
+}
+
+/* ****************************************** INIT ***************************************** */
void DRW_engines_init(void)
{
diff --git a/source/blender/draw/intern/draw_mode_pass.c b/source/blender/draw/intern/draw_mode_pass.c
index 0298db1a5c..4e04bf5f87 100644
--- a/source/blender/draw/intern/draw_mode_pass.c
+++ b/source/blender/draw/intern/draw_mode_pass.c
@@ -31,6 +31,8 @@
#include "BKE_global.h"
+#include "DRW_render.h"
+
#include "draw_mode_pass.h"
/* ************************** OBJECT MODE ******************************* */
@@ -115,8 +117,7 @@ static DRWShadingGroup *shgroup_groundpoints_uniform_color(DRWPass *pass, float
static DRWShadingGroup *shgroup_instance_screenspace(DRWPass *pass, struct Batch *geom, float *size)
{
- GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR
-);
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR);
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom);
DRW_shgroup_attrib_float(grp, "world_pos", 3);
diff --git a/source/blender/draw/intern/draw_mode_pass.h b/source/blender/draw/intern/draw_mode_pass.h
index d11213ec8a..6e260dac7a 100644
--- a/source/blender/draw/intern/draw_mode_pass.h
+++ b/source/blender/draw/intern/draw_mode_pass.h
@@ -26,8 +26,6 @@
#ifndef __DRAW_MODE_PASS_H__
#define __DRAW_MODE_PASS_H__
-#include "DRW_render.h"
-
struct DRWPass;
struct Batch;
struct Object;
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c
new file mode 100644
index 0000000000..9846bd1b0a
--- /dev/null
+++ b/source/blender/draw/intern/draw_view.c
@@ -0,0 +1,704 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/draw_view.c
+ * \ingroup draw
+ *
+ * Contains dynamic drawing using immediate mode
+ */
+
+#include "DNA_brush_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+
+#include "ED_screen.h"
+#include "ED_transform.h"
+#include "ED_view3d.h"
+
+#include "GPU_draw.h"
+#include "GPU_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
+#include "UI_resources.h"
+
+#include "BKE_global.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_unit.h"
+
+#include "DRW_render.h"
+
+#include "view3d_intern.h"
+
+#include "draw_view.h"
+
+/* ******************** region info ***************** */
+
+void DRW_draw_region_info(void)
+{
+ const bContext *C = DRW_get_context();
+ ARegion *ar = CTX_wm_region(C);
+
+ DRW_draw_cursor();
+ view3d_draw_region_info(C, ar);
+}
+
+/* ************************* Grid ************************** */
+
+static void gridline_range(double x0, double dx, double max, int* first_out, int* count_out)
+{
+ /* determine range of gridlines that appear in this Area -- similar calc but separate ranges for x & y
+ * x0 is gridline 0, the axis in screen space
+ * Area covers [0 .. max) pixels */
+
+ int first = (int)ceil(-x0 / dx);
+ int last = (int)floor((max - x0) / dx);
+
+ if (first <= last) {
+ *first_out = first;
+ *count_out = last - first + 1;
+ }
+ else {
+ *first_out = 0;
+ *count_out = 0;
+ }
+}
+
+static int gridline_count(ARegion *ar, double x0, double y0, double dx)
+{
+ /* x0 & y0 establish the "phase" of the grid within this 2D region
+ * dx is the frequency, shared by x & y directions
+ * pass in dx of smallest (highest precision) grid we want to draw */
+
+ int first, x_ct, y_ct;
+
+ gridline_range(x0, dx, ar->winx, &first, &x_ct);
+ gridline_range(y0, dx, ar->winy, &first, &y_ct);
+
+ int total_ct = x_ct + y_ct;
+
+ return total_ct;
+}
+
+static bool drawgrid_draw(ARegion *ar, double x0, double y0, double dx, int skip_mod, unsigned pos, unsigned col, GLubyte col_value[3])
+{
+ /* skip every skip_mod lines relative to each axis; they will be overlaid by another drawgrid_draw
+ * always skip exact x0 & y0 axes; they will be drawn later in color
+ *
+ * set grid color once, just before the first line is drawn
+ * it's harmless to set same color for every line, or every vertex
+ * but if no lines are drawn, color must not be set! */
+
+ const float x_max = (float)ar->winx;
+ const float y_max = (float)ar->winy;
+
+ int first, ct;
+ int x_ct = 0, y_ct = 0; /* count of lines actually drawn */
+ int lines_skipped_for_next_unit = 0;
+
+ /* draw vertical lines */
+ gridline_range(x0, dx, x_max, &first, &ct);
+
+ for (int i = first; i < first + ct; ++i) {
+ if (i == 0)
+ continue;
+ else if (skip_mod && (i % skip_mod) == 0) {
+ ++lines_skipped_for_next_unit;
+ continue;
+ }
+
+ if (x_ct == 0)
+ immAttrib3ub(col, col_value[0], col_value[1], col_value[2]);
+
+ float x = (float)(x0 + i * dx);
+ immVertex2f(pos, x, 0.0f);
+ immVertex2f(pos, x, y_max);
+ ++x_ct;
+ }
+
+ /* draw horizontal lines */
+ gridline_range(y0, dx, y_max, &first, &ct);
+
+ for (int i = first; i < first + ct; ++i) {
+ if
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list