2017-03-12 21:16:03 +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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/draw/modes/paint_vertex_mode.c
|
|
|
|
* \ingroup draw
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DRW_engine.h"
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
|
|
/* If builtin shaders are needed */
|
|
|
|
#include "GPU_shader.h"
|
|
|
|
|
|
|
|
#include "draw_common.h"
|
|
|
|
|
|
|
|
#include "draw_mode_engines.h"
|
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
2017-03-18 22:14:53 +01:00
|
|
|
extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
|
|
|
|
extern struct GlobalsUboStorage ts; /* draw_common.c */
|
|
|
|
|
2017-05-05 14:25:43 +02:00
|
|
|
extern char datatoc_paint_wire_vert_glsl[];
|
|
|
|
extern char datatoc_paint_wire_frag_glsl[];
|
|
|
|
extern char datatoc_common_globals_lib_glsl[];
|
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
/* *********** LISTS *********** */
|
|
|
|
|
|
|
|
typedef struct PAINT_VERTEX_PassList {
|
2017-05-04 19:59:27 +02:00
|
|
|
struct DRWPass *vcolor_faces;
|
|
|
|
struct DRWPass *wire_overlay;
|
2017-05-05 14:25:43 +02:00
|
|
|
struct DRWPass *face_overlay;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PAINT_VERTEX_PassList;
|
|
|
|
|
|
|
|
typedef struct PAINT_VERTEX_StorageList {
|
2017-04-29 16:52:12 +10:00
|
|
|
struct PAINT_VERTEX_PrivateData *g_data;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PAINT_VERTEX_StorageList;
|
|
|
|
|
|
|
|
typedef struct PAINT_VERTEX_Data {
|
2017-04-03 19:32:05 +02:00
|
|
|
void *engine_type; /* Required */
|
2017-05-05 11:38:15 +02:00
|
|
|
DRWViewportEmptyList *fbl;
|
|
|
|
DRWViewportEmptyList *txl;
|
2017-03-12 21:16:03 +01:00
|
|
|
PAINT_VERTEX_PassList *psl;
|
|
|
|
PAINT_VERTEX_StorageList *stl;
|
|
|
|
} PAINT_VERTEX_Data;
|
|
|
|
|
|
|
|
/* *********** STATIC *********** */
|
|
|
|
|
2017-03-18 22:14:53 +01:00
|
|
|
static struct {
|
2017-05-04 19:59:27 +02:00
|
|
|
struct GPUShader *vcolor_face_shader;
|
|
|
|
struct GPUShader *wire_overlay_shader;
|
2017-05-05 14:25:43 +02:00
|
|
|
struct GPUShader *face_overlay_shader;
|
2017-03-18 22:14:53 +01:00
|
|
|
} e_data = {NULL}; /* Engine data */
|
|
|
|
|
2017-04-29 16:52:12 +10:00
|
|
|
typedef struct PAINT_VERTEX_PrivateData {
|
2017-05-04 19:59:27 +02:00
|
|
|
DRWShadingGroup *fvcolor_shgrp;
|
|
|
|
DRWShadingGroup *lwire_shgrp;
|
2017-05-05 14:25:43 +02:00
|
|
|
DRWShadingGroup *face_shgrp;
|
2017-04-29 16:52:12 +10:00
|
|
|
} PAINT_VERTEX_PrivateData; /* Transient data */
|
2017-03-12 21:16:03 +01:00
|
|
|
|
|
|
|
/* *********** FUNCTIONS *********** */
|
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-05-04 19:59:27 +02:00
|
|
|
if (!e_data.vcolor_face_shader) {
|
|
|
|
e_data.vcolor_face_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR_ALPHA);
|
|
|
|
}
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
if (!e_data.wire_overlay_shader) {
|
2017-05-05 14:25:43 +02:00
|
|
|
e_data.wire_overlay_shader = DRW_shader_create_with_lib(
|
|
|
|
datatoc_paint_wire_vert_glsl, NULL,
|
|
|
|
datatoc_paint_wire_frag_glsl,
|
|
|
|
datatoc_common_globals_lib_glsl, "#define VERTEX_MODE\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e_data.face_overlay_shader) {
|
|
|
|
e_data.face_overlay_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
static float world_light;
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void PAINT_VERTEX_cache_init(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl;
|
|
|
|
PAINT_VERTEX_StorageList *stl = ((PAINT_VERTEX_Data *)vedata)->stl;
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
if (!stl->g_data) {
|
|
|
|
/* Alloc transient pointers */
|
2017-04-29 16:52:12 +10:00
|
|
|
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
2017-03-26 20:13:34 +02:00
|
|
|
}
|
2017-03-14 18:40:23 +11:00
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
|
|
|
/* Create a pass */
|
2017-05-04 19:59:27 +02:00
|
|
|
psl->vcolor_faces = DRW_pass_create("Vert Color Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
|
|
|
|
|
|
|
|
stl->g_data->fvcolor_shgrp = DRW_shgroup_create(e_data.vcolor_face_shader, psl->vcolor_faces);
|
|
|
|
|
|
|
|
static float light[3] = {-0.3f, 0.5f, 1.0f};
|
|
|
|
static float alpha = 1.0f;
|
|
|
|
DRW_shgroup_uniform_vec3(stl->g_data->fvcolor_shgrp, "light", light, 1);
|
|
|
|
DRW_shgroup_uniform_float(stl->g_data->fvcolor_shgrp, "alpha", &alpha, 1);
|
|
|
|
DRW_shgroup_uniform_float(stl->g_data->fvcolor_shgrp, "global", &world_light, 1);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
{
|
|
|
|
psl->wire_overlay = DRW_pass_create("Wire Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
|
|
|
|
|
|
|
|
stl->g_data->lwire_shgrp = DRW_shgroup_create(e_data.wire_overlay_shader, psl->wire_overlay);
|
|
|
|
}
|
2017-05-05 14:25:43 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
psl->face_overlay = DRW_pass_create("Face Mask Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
|
|
|
|
|
|
|
|
stl->g_data->face_shgrp = DRW_shgroup_create(e_data.face_overlay_shader, psl->face_overlay);
|
|
|
|
|
|
|
|
static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
|
|
|
|
DRW_shgroup_uniform_vec4(stl->g_data->face_shgrp, "color", col, 1);
|
|
|
|
}
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void PAINT_VERTEX_cache_populate(void *vedata, Object *ob)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
PAINT_VERTEX_StorageList *stl = ((PAINT_VERTEX_Data *)vedata)->stl;
|
2017-05-04 19:59:27 +02:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2017-05-17 16:08:36 +10:00
|
|
|
if ((ob->type == OB_MESH) && (ob == draw_ctx->obact)) {
|
2017-05-05 16:27:31 +02:00
|
|
|
IDProperty *ces_mode_pw = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_PAINT_VERTEX, "");
|
2017-05-04 19:59:27 +02:00
|
|
|
bool use_wire = BKE_collection_engine_property_value_get_bool(ces_mode_pw, "use_wire");
|
|
|
|
char flag = ((Mesh *)ob->data)->editflag;
|
|
|
|
struct Batch *geom;
|
2017-03-14 18:40:23 +11:00
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
world_light = BKE_collection_engine_property_value_get_bool(ces_mode_pw, "use_shading") ? 0.5f : 1.0f;
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
geom = DRW_cache_mesh_surface_vert_colors_get(ob);
|
|
|
|
DRW_shgroup_call_add(stl->g_data->fvcolor_shgrp, geom, ob->obmat);
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
if (flag & ME_EDIT_PAINT_FACE_SEL || use_wire) {
|
2017-05-05 14:25:43 +02:00
|
|
|
geom = DRW_cache_mesh_edges_paint_overlay_get(ob, use_wire, flag & ME_EDIT_PAINT_FACE_SEL);
|
2017-05-04 19:59:27 +02:00
|
|
|
DRW_shgroup_call_add(stl->g_data->lwire_shgrp, geom, ob->obmat);
|
|
|
|
}
|
2017-05-05 14:25:43 +02:00
|
|
|
|
|
|
|
if (flag & ME_EDIT_PAINT_FACE_SEL) {
|
|
|
|
geom = DRW_cache_mesh_faces_weight_overlay_get(ob);
|
|
|
|
DRW_shgroup_call_add(stl->g_data->face_shgrp, geom, ob->obmat);
|
|
|
|
}
|
2017-05-04 19:59:27 +02:00
|
|
|
}
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void PAINT_VERTEX_draw_scene(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl;
|
2017-03-14 18:40:23 +11:00
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
DRW_draw_pass(psl->vcolor_faces);
|
2017-05-05 14:25:43 +02:00
|
|
|
DRW_draw_pass(psl->face_overlay);
|
2017-05-04 19:59:27 +02:00
|
|
|
DRW_draw_pass(psl->wire_overlay);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PAINT_VERTEX_engine_free(void)
|
|
|
|
{
|
2017-05-05 14:25:43 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.wire_overlay_shader);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
2017-05-04 19:59:27 +02:00
|
|
|
void PAINT_VERTEX_collection_settings_create(IDProperty *properties)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2017-05-04 19:59:27 +02:00
|
|
|
BLI_assert(properties &&
|
|
|
|
properties->type == IDP_GROUP &&
|
|
|
|
properties->subtype == IDP_GROUP_SUB_MODE_PAINT_VERTEX);
|
|
|
|
|
|
|
|
BKE_collection_engine_property_add_bool(properties, "use_shading", true);
|
|
|
|
BKE_collection_engine_property_add_bool(properties, "use_wire", false);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 19:49:19 +10:00
|
|
|
static const DrawEngineDataSize PAINT_VERTEX_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_VERTEX_Data);
|
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
DrawEngineType draw_engine_paint_vertex_type = {
|
|
|
|
NULL, NULL,
|
|
|
|
N_("PaintVertexMode"),
|
2017-04-12 19:49:19 +10:00
|
|
|
&PAINT_VERTEX_data_size,
|
2017-03-12 21:16:03 +01:00
|
|
|
&PAINT_VERTEX_engine_init,
|
|
|
|
&PAINT_VERTEX_engine_free,
|
|
|
|
&PAINT_VERTEX_cache_init,
|
|
|
|
&PAINT_VERTEX_cache_populate,
|
2017-05-04 19:59:27 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2017-03-12 21:16:03 +01:00
|
|
|
&PAINT_VERTEX_draw_scene
|
|
|
|
};
|