2017-02-14 17:48:16 +01:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-02-22 18:52:07 +01:00
|
|
|
/** \file blender/draw/intern/draw_view.c
|
2017-02-14 17:48:16 +01:00
|
|
|
* \ingroup draw
|
|
|
|
*
|
|
|
|
* Contains dynamic drawing using immediate mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DNA_brush_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
2018-06-01 08:15:50 +02:00
|
|
|
#include "DNA_world_types.h"
|
2017-02-14 17:48:16 +01:00
|
|
|
#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"
|
|
|
|
|
2017-04-07 00:35:57 +10:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2017-02-14 17:48:16 +01:00
|
|
|
#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)
|
|
|
|
{
|
2017-04-26 00:35:08 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
ARegion *ar = draw_ctx->ar;
|
2017-02-14 17:48:16 +01:00
|
|
|
|
|
|
|
DRW_draw_cursor();
|
2017-05-04 15:46:09 +02:00
|
|
|
|
2018-10-25 11:47:37 +02:00
|
|
|
view3d_draw_region_info(draw_ctx->evil_C, ar);
|
2017-02-14 17:48:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************* Background ************************** */
|
|
|
|
|
|
|
|
void DRW_draw_background(void)
|
|
|
|
{
|
|
|
|
/* Just to make sure */
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2017-03-18 01:55:41 +01:00
|
|
|
glStencilMask(0xFF);
|
2017-02-14 17:48:16 +01:00
|
|
|
|
2018-07-27 15:05:46 +02:00
|
|
|
if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
|
2017-04-19 18:07:58 +02:00
|
|
|
float m[4][4];
|
|
|
|
unit_m4(m);
|
|
|
|
|
2017-02-14 17:48:16 +01:00
|
|
|
/* Gradient background Color */
|
2017-03-25 18:56:19 +01:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2017-02-14 17:48:16 +01:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
GPUVertFormat *format = immVertexFormat();
|
|
|
|
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
|
|
|
uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
2018-07-08 12:47:13 +02:00
|
|
|
uchar col_hi[3], col_lo[3];
|
2017-02-14 17:48:16 +01:00
|
|
|
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_push();
|
|
|
|
GPU_matrix_identity_set();
|
|
|
|
GPU_matrix_projection_set(m);
|
2017-04-19 18:07:58 +02:00
|
|
|
|
2018-04-21 16:45:47 +02:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR_DITHER);
|
2017-02-14 17:48:16 +01:00
|
|
|
|
|
|
|
UI_GetThemeColor3ubv(TH_LOW_GRAD, col_lo);
|
|
|
|
UI_GetThemeColor3ubv(TH_HIGH_GRAD, col_hi);
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_TRI_FAN, 4);
|
2018-10-09 11:01:50 +11:00
|
|
|
immAttr3ubv(color, col_lo);
|
2017-02-14 17:48:16 +01:00
|
|
|
immVertex2f(pos, -1.0f, -1.0f);
|
|
|
|
immVertex2f(pos, 1.0f, -1.0f);
|
|
|
|
|
2018-10-09 11:01:50 +11:00
|
|
|
immAttr3ubv(color, col_hi);
|
2017-02-14 17:48:16 +01:00
|
|
|
immVertex2f(pos, 1.0f, 1.0f);
|
|
|
|
immVertex2f(pos, -1.0f, 1.0f);
|
|
|
|
immEnd();
|
|
|
|
|
|
|
|
immUnbindProgram();
|
|
|
|
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_pop();
|
2017-04-19 18:07:58 +02:00
|
|
|
|
2017-03-25 18:56:19 +01:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2017-05-03 08:20:11 +10:00
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2017-02-14 17:48:16 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Solid background Color */
|
|
|
|
UI_ThemeClearColorAlpha(TH_HIGH_GRAD, 1.0f);
|
2017-03-18 01:55:41 +01:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2017-02-14 17:48:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* **************************** 3D Cursor ******************************** */
|
|
|
|
|
2018-02-06 16:10:03 +11:00
|
|
|
static bool is_cursor_visible(const DRWContextState *draw_ctx, Scene *scene, ViewLayer *view_layer)
|
2017-02-14 17:48:16 +01:00
|
|
|
{
|
2018-05-03 10:55:28 +02:00
|
|
|
View3D *v3d = draw_ctx->v3d;
|
2018-06-18 17:39:19 +02:00
|
|
|
if ((v3d->flag2 & V3D_RENDER_OVERRIDE) || (v3d->overlay.flag & V3D_OVERLAY_HIDE_CURSOR)) {
|
2018-05-03 10:55:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-02-14 17:48:16 +01:00
|
|
|
|
|
|
|
/* don't draw cursor in paint modes, but with a few exceptions */
|
2018-10-04 09:24:35 +10:00
|
|
|
if (draw_ctx->object_mode & OB_MODE_ALL_PAINT) {
|
2017-02-14 17:48:16 +01:00
|
|
|
/* exception: object is in weight paint and has deforming armature in pose mode */
|
2018-02-06 16:10:03 +11:00
|
|
|
if (draw_ctx->object_mode & OB_MODE_WEIGHT_PAINT) {
|
2018-10-04 09:24:35 +10:00
|
|
|
if (BKE_object_pose_armature_get(draw_ctx->obact) != NULL) {
|
2017-02-14 17:48:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* exception: object in texture paint mode, clone brush, use_clone_layer disabled */
|
2018-02-06 16:10:03 +11:00
|
|
|
else if (draw_ctx->object_mode & OB_MODE_TEXTURE_PAINT) {
|
2018-04-05 18:20:27 +02:00
|
|
|
const Paint *p = BKE_paint_get_active(scene, view_layer);
|
2017-02-14 17:48:16 +01:00
|
|
|
|
|
|
|
if (p && p->brush && p->brush->imagepaint_tool == PAINT_TOOL_CLONE) {
|
|
|
|
if ((scene->toolsettings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no exception met? then don't draw cursor! */
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-04 09:24:35 +10:00
|
|
|
else if (draw_ctx->object_mode & OB_MODE_GPENCIL_WEIGHT) {
|
|
|
|
/* grease pencil hide always in some modes */
|
2018-10-03 20:25:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-14 17:48:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_draw_cursor(void)
|
|
|
|
{
|
2017-04-26 00:35:08 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
View3D *v3d = draw_ctx->v3d;
|
2018-03-27 23:50:26 +02:00
|
|
|
ARegion *ar = draw_ctx->ar;
|
2017-04-26 00:35:08 +10:00
|
|
|
Scene *scene = draw_ctx->scene;
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = draw_ctx->view_layer;
|
2017-02-14 17:48:16 +01:00
|
|
|
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
2018-02-06 16:10:03 +11:00
|
|
|
if (is_cursor_visible(draw_ctx, scene, view_layer)) {
|
2018-03-27 23:50:26 +02:00
|
|
|
int co[2];
|
2018-05-08 14:18:09 +02:00
|
|
|
const View3DCursor *cursor = ED_view3d_cursor3d_get(scene, v3d);
|
|
|
|
if (ED_view3d_project_int_global(
|
2018-05-22 14:32:48 +02:00
|
|
|
ar, cursor->location, co, V3D_PROJ_TEST_NOP | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
|
2018-05-08 14:18:09 +02:00
|
|
|
{
|
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
|
|
|
/* Draw nice Anti Aliased cursor. */
|
|
|
|
glLineWidth(1.0f);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
|
|
|
|
float eps = 1e-5f;
|
|
|
|
rv3d->viewquat[0] = -rv3d->viewquat[0];
|
|
|
|
const bool is_aligned = compare_v4v4(cursor->rotation, rv3d->viewquat, eps);
|
|
|
|
rv3d->viewquat[0] = -rv3d->viewquat[0];
|
|
|
|
|
|
|
|
/* Draw lines */
|
|
|
|
if (is_aligned == false) {
|
2018-07-18 00:12:21 +02:00
|
|
|
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
|
2018-05-08 14:18:09 +02:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
|
|
|
immUniformThemeColor3(TH_VIEW_OVERLAY);
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 12);
|
2018-05-08 14:18:09 +02:00
|
|
|
|
2018-05-25 10:07:28 +02:00
|
|
|
const float scale = ED_view3d_pixel_size_no_ui_scale(rv3d, cursor->location) * U.widget_unit;
|
2018-05-08 14:18:09 +02:00
|
|
|
|
|
|
|
#define CURSOR_VERT(axis_vec, axis, fac) \
|
|
|
|
immVertex3f( \
|
|
|
|
pos, \
|
|
|
|
cursor->location[0] + axis_vec[0] * (fac), \
|
|
|
|
cursor->location[1] + axis_vec[1] * (fac), \
|
|
|
|
cursor->location[2] + axis_vec[2] * (fac))
|
|
|
|
|
|
|
|
#define CURSOR_EDGE(axis_vec, axis, sign) { \
|
|
|
|
CURSOR_VERT(axis_vec, axis, sign 1.0f); \
|
2018-05-21 14:51:10 +02:00
|
|
|
CURSOR_VERT(axis_vec, axis, sign 0.25f); \
|
2018-05-08 14:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int axis = 0; axis < 3; axis++) {
|
|
|
|
float axis_vec[3] = {0};
|
|
|
|
axis_vec[axis] = scale;
|
|
|
|
mul_qt_v3(cursor->rotation, axis_vec);
|
|
|
|
CURSOR_EDGE(axis_vec, axis, +);
|
|
|
|
CURSOR_EDGE(axis_vec, axis, -);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CURSOR_VERT
|
|
|
|
#undef CURSOR_EDGE
|
|
|
|
|
|
|
|
immEnd();
|
|
|
|
immUnbindProgram();
|
|
|
|
}
|
2017-02-14 17:48:16 +01:00
|
|
|
|
2018-03-27 23:50:26 +02:00
|
|
|
ED_region_pixelspace(ar);
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_translate_2f(co[0] + 0.5f, co[1] + 0.5f);
|
|
|
|
GPU_matrix_scale_2f(U.widget_unit, U.widget_unit);
|
2017-02-14 17:48:16 +01:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
GPUBatch *cursor_batch = DRW_cache_cursor_get(is_aligned);
|
2018-03-27 23:50:26 +02:00
|
|
|
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_FLAT_COLOR);
|
2018-07-18 00:12:21 +02:00
|
|
|
GPU_batch_program_set(cursor_batch, GPU_shader_get_program(shader), GPU_shader_get_interface(shader));
|
2018-04-23 12:48:54 +02:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
GPU_batch_draw(cursor_batch);
|
2018-06-17 14:43:31 +02:00
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_LINE_SMOOTH);
|
2017-02-14 17:48:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-14 23:49:00 +02:00
|
|
|
/* **************************** 3D Gizmo ******************************** */
|
2017-02-14 17:48:16 +01:00
|
|
|
|
2018-07-14 23:49:00 +02:00
|
|
|
void DRW_draw_gizmo_3d(void)
|
2017-02-14 17:48:16 +01:00
|
|
|
{
|
2017-04-26 00:35:08 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
ARegion *ar = draw_ctx->ar;
|
2017-04-07 00:35:57 +10:00
|
|
|
|
2018-07-14 23:49:00 +02:00
|
|
|
/* draw depth culled gizmos - gizmos need to be updated *after* view matrix was set up */
|
|
|
|
/* TODO depth culling gizmos is not yet supported, just drawing _3D here, should
|
2017-04-07 00:35:57 +10:00
|
|
|
* later become _IN_SCENE (and draw _3D separate) */
|
2018-07-14 23:49:00 +02:00
|
|
|
WM_gizmomap_draw(
|
|
|
|
ar->gizmo_map, draw_ctx->evil_C,
|
|
|
|
WM_GIZMOMAP_DRAWSTEP_3D);
|
2017-08-03 15:12:47 +10:00
|
|
|
|
2017-12-16 18:55:42 +11:00
|
|
|
}
|
2017-08-03 15:12:47 +10:00
|
|
|
|
2018-07-14 23:49:00 +02:00
|
|
|
void DRW_draw_gizmo_2d(void)
|
2017-12-16 18:55:42 +11:00
|
|
|
{
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
ARegion *ar = draw_ctx->ar;
|
2017-08-03 15:12:47 +10:00
|
|
|
|
2018-07-14 23:49:00 +02:00
|
|
|
WM_gizmomap_draw(
|
|
|
|
ar->gizmo_map, draw_ctx->evil_C,
|
|
|
|
WM_GIZMOMAP_DRAWSTEP_2D);
|
2017-08-03 15:12:47 +10:00
|
|
|
|
2017-12-16 18:55:42 +11:00
|
|
|
glDepthMask(GL_TRUE);
|
2017-02-14 17:48:16 +01:00
|
|
|
}
|