2017-03-12 21:16:03 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2016, Blender Foundation.
|
2017-03-12 21:16:03 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup draw
|
2017-03-12 21:16:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DRW_engine.h"
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
2017-05-22 23:31:46 +10:00
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
|
2018-12-23 16:26:21 +01:00
|
|
|
#include "BKE_node.h"
|
|
|
|
|
|
2019-05-10 01:57:42 +02:00
|
|
|
#include "BLI_string_utils.h"
|
|
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
/* If builtin shaders are needed */
|
|
|
|
|
#include "GPU_shader.h"
|
2017-05-22 23:31:46 +10:00
|
|
|
#include "GPU_texture.h"
|
2017-03-12 21:16:03 +01:00
|
|
|
|
|
|
|
|
#include "draw_common.h"
|
2019-02-23 18:31:45 +11:00
|
|
|
#include "draw_mode_engines.h"
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2017-05-22 23:31:46 +10:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
|
2018-12-01 13:20:18 +03:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
|
2019-04-02 16:05:22 +02:00
|
|
|
extern char datatoc_common_colormanagement_lib_glsl[];
|
2017-05-22 23:31:46 +10:00
|
|
|
extern char datatoc_common_globals_lib_glsl[];
|
2019-05-10 01:57:42 +02:00
|
|
|
extern char datatoc_common_view_lib_glsl[];
|
2017-05-22 23:31:46 +10:00
|
|
|
extern char datatoc_paint_texture_vert_glsl[];
|
|
|
|
|
extern char datatoc_paint_texture_frag_glsl[];
|
|
|
|
|
extern char datatoc_paint_wire_vert_glsl[];
|
|
|
|
|
extern char datatoc_paint_wire_frag_glsl[];
|
2018-12-17 17:01:06 +01:00
|
|
|
extern char datatoc_paint_face_vert_glsl[];
|
2019-06-04 11:28:21 +02:00
|
|
|
extern char datatoc_paint_face_selection_vert_glsl[];
|
2018-12-17 17:01:06 +01:00
|
|
|
|
|
|
|
|
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
|
2017-05-22 23:31:46 +10:00
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
/* *********** LISTS *********** */
|
|
|
|
|
/* All lists are per viewport specific datas.
|
|
|
|
|
* They are all free when viewport changes engines
|
|
|
|
|
* or is free itself. Use PAINT_TEXTURE_engine_init() to
|
|
|
|
|
* initialize most of them and PAINT_TEXTURE_cache_init()
|
|
|
|
|
* for PAINT_TEXTURE_PassList */
|
|
|
|
|
|
|
|
|
|
typedef struct PAINT_TEXTURE_PassList {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Declare all passes here and init them in
|
|
|
|
|
* PAINT_TEXTURE_cache_init().
|
|
|
|
|
* Only contains (DRWPass *) */
|
|
|
|
|
struct DRWPass *image_faces;
|
2017-05-22 23:31:46 +10:00
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
struct DRWPass *wire_select_overlay;
|
|
|
|
|
struct DRWPass *face_select_overlay;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PAINT_TEXTURE_PassList;
|
|
|
|
|
|
|
|
|
|
typedef struct PAINT_TEXTURE_FramebufferList {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Contains all framebuffer objects needed by this engine.
|
|
|
|
|
* Only contains (GPUFrameBuffer *) */
|
|
|
|
|
struct GPUFrameBuffer *fb;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PAINT_TEXTURE_FramebufferList;
|
|
|
|
|
|
|
|
|
|
typedef struct PAINT_TEXTURE_TextureList {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Contains all framebuffer textures / utility textures
|
|
|
|
|
* needed by this engine. Only viewport specific textures
|
|
|
|
|
* (not per object). Only contains (GPUTexture *) */
|
|
|
|
|
struct GPUTexture *texture;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PAINT_TEXTURE_TextureList;
|
|
|
|
|
|
|
|
|
|
typedef struct PAINT_TEXTURE_StorageList {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Contains any other memory block that the engine needs.
|
|
|
|
|
* Only directly MEM_(m/c)allocN'ed blocks because they are
|
|
|
|
|
* free with MEM_freeN() when viewport is freed.
|
|
|
|
|
* (not per object) */
|
|
|
|
|
struct CustomStruct *block;
|
|
|
|
|
struct PAINT_TEXTURE_PrivateData *g_data;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PAINT_TEXTURE_StorageList;
|
|
|
|
|
|
|
|
|
|
typedef struct PAINT_TEXTURE_Data {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Struct returned by DRW_viewport_engine_data_ensure.
|
|
|
|
|
* If you don't use one of these, just make it a (void *) */
|
|
|
|
|
// void *fbl;
|
|
|
|
|
void *engine_type; /* Required */
|
|
|
|
|
PAINT_TEXTURE_FramebufferList *fbl;
|
|
|
|
|
PAINT_TEXTURE_TextureList *txl;
|
|
|
|
|
PAINT_TEXTURE_PassList *psl;
|
|
|
|
|
PAINT_TEXTURE_StorageList *stl;
|
2017-03-12 21:16:03 +01:00
|
|
|
} PAINT_TEXTURE_Data;
|
|
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
typedef struct PAINT_TEXTURE_Shaders {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Custom shaders :
|
|
|
|
|
* Add sources to source/blender/draw/modes/shaders
|
|
|
|
|
* init in PAINT_TEXTURE_engine_init();
|
|
|
|
|
* free in PAINT_TEXTURE_engine_free(); */
|
2019-05-17 14:02:52 +10:00
|
|
|
struct GPUShader *fallback;
|
|
|
|
|
struct GPUShader *image;
|
|
|
|
|
struct GPUShader *image_mask;
|
|
|
|
|
|
|
|
|
|
struct GPUShader *wire_select_overlay;
|
|
|
|
|
struct GPUShader *face_select_overlay;
|
|
|
|
|
} PAINT_TEXTURE_Shaders;
|
|
|
|
|
|
|
|
|
|
/* *********** STATIC *********** */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
static struct {
|
|
|
|
|
PAINT_TEXTURE_Shaders sh_data[GPU_SHADER_CFG_LEN];
|
|
|
|
|
} e_data = {{{NULL}}}; /* Engine data */
|
2017-03-18 22:14:53 +01:00
|
|
|
|
2017-04-29 16:52:12 +10:00
|
|
|
typedef struct PAINT_TEXTURE_PrivateData {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* This keeps the references of the shading groups for
|
|
|
|
|
* easy access in PAINT_TEXTURE_cache_populate() */
|
|
|
|
|
DRWShadingGroup *shgroup_fallback;
|
|
|
|
|
DRWShadingGroup **shgroup_image_array;
|
|
|
|
|
|
|
|
|
|
/* face-mask */
|
2019-05-17 14:02:52 +10:00
|
|
|
DRWShadingGroup *lwire_select_shgrp;
|
|
|
|
|
DRWShadingGroup *face_select_shgrp;
|
2019-05-26 01:42:36 +02:00
|
|
|
|
|
|
|
|
DRWView *view_wires;
|
2017-04-29 16:52:12 +10:00
|
|
|
} PAINT_TEXTURE_PrivateData; /* Transient data */
|
2017-03-12 21:16:03 +01:00
|
|
|
|
|
|
|
|
/* *********** FUNCTIONS *********** */
|
|
|
|
|
|
|
|
|
|
/* Init Textures, Framebuffers, Storage and Shaders.
|
2018-12-17 17:01:06 +01:00
|
|
|
* It is called for every frames. */
|
2019-05-26 01:42:36 +02:00
|
|
|
static void PAINT_TEXTURE_engine_init(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2019-05-26 01:42:36 +02:00
|
|
|
PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
|
2019-05-17 14:02:52 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
PAINT_TEXTURE_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
|
|
|
|
|
|
|
|
|
|
if (!sh_data->fallback) {
|
|
|
|
|
const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
|
2019-06-04 11:28:21 +02:00
|
|
|
sh_data->fallback = GPU_shader_create_from_arrays({
|
|
|
|
|
.vert = (const char *[]){sh_cfg_data->lib,
|
|
|
|
|
datatoc_common_view_lib_glsl,
|
|
|
|
|
datatoc_paint_face_vert_glsl,
|
|
|
|
|
NULL},
|
|
|
|
|
.frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
|
|
|
|
|
.defs = (const char *[]){sh_cfg_data->def, NULL},
|
|
|
|
|
});
|
2019-05-17 14:02:52 +10:00
|
|
|
|
|
|
|
|
sh_data->image = GPU_shader_create_from_arrays({
|
|
|
|
|
.vert = (const char *[]){sh_cfg_data->lib,
|
|
|
|
|
datatoc_common_globals_lib_glsl,
|
|
|
|
|
datatoc_common_view_lib_glsl,
|
|
|
|
|
datatoc_paint_texture_vert_glsl,
|
|
|
|
|
NULL},
|
2019-04-02 16:05:22 +02:00
|
|
|
.frag = (const char *[]){datatoc_common_colormanagement_lib_glsl,
|
|
|
|
|
datatoc_paint_texture_frag_glsl,
|
|
|
|
|
NULL},
|
2019-05-17 14:02:52 +10:00
|
|
|
.defs = (const char *[]){sh_cfg_data->def, NULL},
|
|
|
|
|
});
|
|
|
|
|
|
2019-05-22 09:59:52 +02:00
|
|
|
sh_data->image_mask = GPU_shader_create_from_arrays({
|
|
|
|
|
.vert = (const char *[]){sh_cfg_data->lib,
|
|
|
|
|
datatoc_common_globals_lib_glsl,
|
|
|
|
|
datatoc_common_view_lib_glsl,
|
|
|
|
|
datatoc_paint_texture_vert_glsl,
|
|
|
|
|
NULL},
|
2019-06-25 08:07:50 +02:00
|
|
|
.frag = (const char *[]){datatoc_common_colormanagement_lib_glsl,
|
|
|
|
|
datatoc_paint_texture_frag_glsl,
|
|
|
|
|
NULL},
|
2019-05-22 09:59:52 +02:00
|
|
|
.defs = (const char *[]){sh_cfg_data->def, "#define TEXTURE_PAINT_MASK\n", NULL},
|
|
|
|
|
});
|
|
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
sh_data->wire_select_overlay = GPU_shader_create_from_arrays({
|
|
|
|
|
.vert = (const char *[]){sh_cfg_data->lib,
|
|
|
|
|
datatoc_common_globals_lib_glsl,
|
|
|
|
|
datatoc_common_view_lib_glsl,
|
|
|
|
|
datatoc_paint_wire_vert_glsl,
|
|
|
|
|
NULL},
|
|
|
|
|
.frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
|
2019-05-17 14:11:22 +10:00
|
|
|
.defs = (const char *[]){sh_cfg_data->def, "#define USE_SELECT\n", NULL},
|
2019-05-17 14:02:52 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sh_data->face_select_overlay = GPU_shader_create_from_arrays({
|
|
|
|
|
.vert = (const char *[]){sh_cfg_data->lib,
|
|
|
|
|
datatoc_common_view_lib_glsl,
|
2019-06-04 11:28:21 +02:00
|
|
|
datatoc_paint_face_selection_vert_glsl,
|
2019-05-17 14:02:52 +10:00
|
|
|
NULL},
|
|
|
|
|
.frag = (const char *[]){datatoc_common_view_lib_glsl,
|
|
|
|
|
datatoc_gpu_shader_uniform_color_frag_glsl,
|
|
|
|
|
NULL},
|
|
|
|
|
.defs = (const char *[]){sh_cfg_data->def, NULL},
|
|
|
|
|
});
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-05-26 01:42:36 +02:00
|
|
|
|
|
|
|
|
if (!stl->g_data) {
|
|
|
|
|
/* Alloc transient pointers */
|
|
|
|
|
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
|
|
|
|
stl->g_data->shgroup_image_array = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stl->g_data->view_wires = DRW_view_create_with_zoffset(draw_ctx->rv3d, 1.0f);
|
2017-05-22 23:31:46 +10:00
|
|
|
}
|
2017-07-13 00:27:06 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static DRWShadingGroup *create_texture_paint_shading_group(PAINT_TEXTURE_PassList *psl,
|
2019-06-07 17:49:58 +02:00
|
|
|
const Image *image,
|
2019-04-17 06:17:24 +02:00
|
|
|
const struct GPUTexture *texture,
|
|
|
|
|
const DRWContextState *draw_ctx,
|
|
|
|
|
const bool nearest_interp)
|
2019-03-21 16:44:01 +01:00
|
|
|
{
|
2019-05-17 14:02:52 +10:00
|
|
|
PAINT_TEXTURE_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = draw_ctx->scene;
|
|
|
|
|
const ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
|
|
|
|
|
const bool masking_enabled = imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL &&
|
|
|
|
|
imapaint->stencil != NULL;
|
|
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(masking_enabled ? sh_data->image_mask : sh_data->image,
|
|
|
|
|
psl->image_faces);
|
2019-04-17 06:17:24 +02:00
|
|
|
DRW_shgroup_uniform_texture(grp, "image", texture);
|
2019-06-07 17:49:58 +02:00
|
|
|
DRW_shgroup_uniform_bool_copy(
|
|
|
|
|
grp, "imagePremultiplied", (image->alpha_mode == IMA_ALPHA_PREMUL));
|
2019-04-17 06:17:24 +02:00
|
|
|
DRW_shgroup_uniform_float(grp, "alpha", &draw_ctx->v3d->overlay.texture_paint_mode_opacity, 1);
|
|
|
|
|
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
|
|
|
|
|
DRW_shgroup_uniform_bool_copy(grp, "nearestInterp", nearest_interp);
|
|
|
|
|
|
|
|
|
|
if (masking_enabled) {
|
|
|
|
|
const bool masking_inverted = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) > 0;
|
2019-04-23 13:56:30 +02:00
|
|
|
GPUTexture *stencil = GPU_texture_from_blender(imapaint->stencil, NULL, GL_TEXTURE_2D);
|
2019-04-17 06:17:24 +02:00
|
|
|
DRW_shgroup_uniform_texture(grp, "maskingImage", stencil);
|
2019-06-07 17:49:58 +02:00
|
|
|
DRW_shgroup_uniform_bool_copy(
|
|
|
|
|
grp, "maskingImagePremultiplied", (imapaint->stencil->alpha_mode == IMA_ALPHA_PREMUL));
|
2019-04-17 06:17:24 +02:00
|
|
|
DRW_shgroup_uniform_vec3(grp, "maskingColor", imapaint->stencil_col, 1);
|
|
|
|
|
DRW_shgroup_uniform_bool_copy(grp, "maskingInvertStencil", masking_inverted);
|
|
|
|
|
}
|
|
|
|
|
return grp;
|
2019-03-21 16:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
/* Here init all passes and shading groups
|
|
|
|
|
* Assume that all Passes are NULL */
|
2017-03-26 19:10:53 +02:00
|
|
|
static void PAINT_TEXTURE_cache_init(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
|
|
|
|
|
PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
|
|
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
PAINT_TEXTURE_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
/* Create a pass */
|
|
|
|
|
{
|
|
|
|
|
DRWPass *pass = DRW_pass_create(
|
2019-05-27 23:21:39 +02:00
|
|
|
"Image Color Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA);
|
2019-05-17 14:02:52 +10:00
|
|
|
DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->fallback, pass);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* Uniforms need a pointer to it's value so be sure it's accessible at
|
|
|
|
|
* any given time (i.e. use static vars) */
|
2019-06-03 23:58:10 +10:00
|
|
|
static const float color[4] = {1.0f, 0.0f, 1.0f, 1.0};
|
2019-05-17 14:02:52 +10:00
|
|
|
DRW_shgroup_uniform_vec4(shgrp, "color", color, 1);
|
|
|
|
|
|
|
|
|
|
if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
2019-05-26 20:36:24 +02:00
|
|
|
DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES);
|
2019-05-17 14:02:52 +10:00
|
|
|
}
|
|
|
|
|
psl->image_faces = pass;
|
|
|
|
|
stl->g_data->shgroup_fallback = shgrp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(stl->g_data->shgroup_image_array);
|
|
|
|
|
|
|
|
|
|
Object *ob = draw_ctx->obact;
|
|
|
|
|
if (ob && ob->type == OB_MESH) {
|
|
|
|
|
Scene *scene = draw_ctx->scene;
|
|
|
|
|
const ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
|
|
|
|
|
const bool use_material_slots = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL);
|
|
|
|
|
const Mesh *me = ob->data;
|
|
|
|
|
const int mat_nr = max_ii(1, me->totcol);
|
|
|
|
|
|
|
|
|
|
stl->g_data->shgroup_image_array = MEM_mallocN(
|
|
|
|
|
sizeof(*stl->g_data->shgroup_image_array) * (use_material_slots ? mat_nr : 1), __func__);
|
|
|
|
|
|
|
|
|
|
if (use_material_slots) {
|
|
|
|
|
for (int i = 0; i < mat_nr; i++) {
|
|
|
|
|
Material *ma = give_current_material(ob, i + 1);
|
|
|
|
|
Image *ima = (ma && ma->texpaintslot) ? ma->texpaintslot[ma->paint_active_slot].ima : NULL;
|
|
|
|
|
int interp = (ma && ma->texpaintslot) ? ma->texpaintslot[ma->paint_active_slot].interp : 0;
|
2019-04-23 13:56:30 +02:00
|
|
|
GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (tex) {
|
|
|
|
|
DRWShadingGroup *grp = create_texture_paint_shading_group(
|
2019-06-07 17:49:58 +02:00
|
|
|
psl, ima, tex, draw_ctx, interp == SHD_INTERP_CLOSEST);
|
2019-05-17 14:02:52 +10:00
|
|
|
stl->g_data->shgroup_image_array[i] = grp;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-05-17 14:02:52 +10:00
|
|
|
stl->g_data->shgroup_image_array[i] = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-17 14:02:52 +10:00
|
|
|
else {
|
|
|
|
|
Image *ima = imapaint->canvas;
|
|
|
|
|
GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
|
|
if (tex) {
|
|
|
|
|
DRWShadingGroup *grp = create_texture_paint_shading_group(
|
2019-06-07 17:49:58 +02:00
|
|
|
psl, ima, tex, draw_ctx, imapaint->interp == IMAGEPAINT_INTERP_CLOSEST);
|
2019-05-17 14:02:52 +10:00
|
|
|
stl->g_data->shgroup_image_array[0] = grp;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stl->g_data->shgroup_image_array[0] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Face Mask */
|
|
|
|
|
{
|
2019-05-26 01:42:36 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
|
|
|
|
|
DRWPass *pass = DRW_pass_create("Wire Mask Pass", state);
|
2019-05-17 14:02:52 +10:00
|
|
|
DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->wire_select_overlay, pass);
|
|
|
|
|
|
|
|
|
|
DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
2019-05-26 20:36:24 +02:00
|
|
|
DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES);
|
2019-05-17 14:02:52 +10:00
|
|
|
}
|
|
|
|
|
psl->wire_select_overlay = pass;
|
|
|
|
|
stl->g_data->lwire_select_shgrp = shgrp;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2019-05-26 01:42:36 +02:00
|
|
|
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL |
|
2019-05-27 23:21:39 +02:00
|
|
|
DRW_STATE_BLEND_ALPHA;
|
2019-05-26 01:42:36 +02:00
|
|
|
DRWPass *pass = DRW_pass_create("Face Mask Pass", state);
|
2019-05-17 14:02:52 +10:00
|
|
|
DRWShadingGroup *shgrp = DRW_shgroup_create(sh_data->face_select_overlay, pass);
|
2019-06-03 23:58:10 +10:00
|
|
|
static const float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
|
2019-05-17 14:02:52 +10:00
|
|
|
DRW_shgroup_uniform_vec4(shgrp, "color", col, 1);
|
|
|
|
|
|
|
|
|
|
if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
2019-05-26 20:36:24 +02:00
|
|
|
DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES);
|
2019-05-17 14:02:52 +10:00
|
|
|
}
|
|
|
|
|
psl->face_select_overlay = pass;
|
|
|
|
|
stl->g_data->face_select_shgrp = shgrp;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add geometry to shadingGroups. Execute for each objects */
|
2017-03-26 19:10:53 +02:00
|
|
|
static void PAINT_TEXTURE_cache_populate(void *vedata, Object *ob)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
|
|
|
|
|
PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
|
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
|
|
|
|
|
UNUSED_VARS(psl, stl);
|
|
|
|
|
|
|
|
|
|
if ((ob->type == OB_MESH) && (draw_ctx->obact == ob)) {
|
|
|
|
|
/* Get geometry cache */
|
|
|
|
|
const Mesh *me = ob->data;
|
|
|
|
|
const Mesh *me_orig = DEG_get_original_object(ob)->data;
|
|
|
|
|
Scene *scene = draw_ctx->scene;
|
|
|
|
|
const bool use_surface = draw_ctx->v3d->overlay.texture_paint_mode_opacity !=
|
2019-05-01 10:35:46 +10:00
|
|
|
0.0; // DRW_object_is_mode_shade(ob) == true;
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool use_material_slots = (scene->toolsettings->imapaint.mode ==
|
|
|
|
|
IMAGEPAINT_MODE_MATERIAL);
|
|
|
|
|
const bool use_face_sel = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
|
|
|
|
|
|
|
|
|
|
if (use_surface) {
|
|
|
|
|
if (me->mloopuv != NULL) {
|
|
|
|
|
if (use_material_slots) {
|
|
|
|
|
int mat_nr = max_ii(1, me->totcol);
|
|
|
|
|
struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < mat_nr; i++) {
|
|
|
|
|
const int index = use_material_slots ? i : 0;
|
|
|
|
|
if ((i < me->totcol) && stl->g_data->shgroup_image_array[index]) {
|
2019-05-29 23:52:37 +02:00
|
|
|
DRW_shgroup_call(stl->g_data->shgroup_image_array[index], geom_array[i], ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-05-29 23:52:37 +02:00
|
|
|
DRW_shgroup_call(stl->g_data->shgroup_fallback, geom_array[i], ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (stl->g_data->shgroup_image_array[0]) {
|
|
|
|
|
struct GPUBatch *geom = DRW_cache_mesh_surface_texpaint_single_get(ob);
|
2019-05-29 23:52:37 +02:00
|
|
|
DRW_shgroup_call(stl->g_data->shgroup_image_array[0], geom, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
struct GPUBatch *geom = DRW_cache_mesh_surface_get(ob);
|
2019-05-29 23:52:37 +02:00
|
|
|
DRW_shgroup_call(stl->g_data->shgroup_fallback, geom, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Face Mask */
|
|
|
|
|
if (use_face_sel) {
|
|
|
|
|
struct GPUBatch *geom;
|
|
|
|
|
geom = DRW_cache_mesh_surface_edges_get(ob);
|
2019-05-29 23:52:37 +02:00
|
|
|
DRW_shgroup_call(stl->g_data->lwire_select_shgrp, geom, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
geom = DRW_cache_mesh_surface_get(ob);
|
2019-05-29 23:52:37 +02:00
|
|
|
DRW_shgroup_call(stl->g_data->face_select_shgrp, geom, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-14 18:40:23 +11:00
|
|
|
/* Optional: Post-cache_populate callback */
|
2017-03-26 19:10:53 +02:00
|
|
|
static void PAINT_TEXTURE_cache_finish(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
|
|
|
|
|
PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Do something here! dependent on the objects gathered */
|
|
|
|
|
UNUSED_VARS(psl);
|
2017-05-22 23:31:46 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_SAFE_FREE(stl->g_data->shgroup_image_array);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Draw time ! Control rendering pipeline from here */
|
2017-03-26 19:10:53 +02:00
|
|
|
static void PAINT_TEXTURE_draw_scene(void *vedata)
|
2017-03-12 21:16:03 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
|
|
|
|
|
PAINT_TEXTURE_FramebufferList *fbl = ((PAINT_TEXTURE_Data *)vedata)->fbl;
|
2019-05-26 01:42:36 +02:00
|
|
|
PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Default framebuffer and texture */
|
|
|
|
|
DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
|
|
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UNUSED_VARS(fbl, dfbl, dtxl);
|
2017-03-14 18:40:23 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
DRW_draw_pass(psl->image_faces);
|
2017-03-12 21:16:03 +01:00
|
|
|
|
2019-05-17 14:02:52 +10:00
|
|
|
DRW_draw_pass(psl->face_select_overlay);
|
2019-05-26 01:42:36 +02:00
|
|
|
|
|
|
|
|
DRW_view_set_active(stl->g_data->view_wires);
|
2019-05-17 14:02:52 +10:00
|
|
|
DRW_draw_pass(psl->wire_select_overlay);
|
2019-05-26 01:42:36 +02:00
|
|
|
|
|
|
|
|
DRW_view_set_active(NULL);
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Cleanup when destroying the engine.
|
|
|
|
|
* This is not per viewport ! only when quitting blender.
|
|
|
|
|
* Mostly used for freeing shaders */
|
|
|
|
|
static void PAINT_TEXTURE_engine_free(void)
|
|
|
|
|
{
|
2019-05-17 14:02:52 +10:00
|
|
|
for (int sh_data_index = 0; sh_data_index < ARRAY_SIZE(e_data.sh_data); sh_data_index++) {
|
|
|
|
|
PAINT_TEXTURE_Shaders *sh_data = &e_data.sh_data[sh_data_index];
|
|
|
|
|
GPUShader **sh_data_as_array = (GPUShader **)sh_data;
|
|
|
|
|
for (int i = 0; i < (sizeof(PAINT_TEXTURE_Shaders) / sizeof(GPUShader *)); i++) {
|
|
|
|
|
DRW_SHADER_FREE_SAFE(sh_data_as_array[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-12 21:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static const DrawEngineDataSize PAINT_TEXTURE_data_size = DRW_VIEWPORT_DATA_SIZE(
|
|
|
|
|
PAINT_TEXTURE_Data);
|
2017-04-12 19:49:19 +10:00
|
|
|
|
2017-03-12 21:16:03 +01:00
|
|
|
DrawEngineType draw_engine_paint_texture_type = {
|
2019-04-17 06:17:24 +02:00
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
N_("PaintTextureMode"),
|
|
|
|
|
&PAINT_TEXTURE_data_size,
|
|
|
|
|
&PAINT_TEXTURE_engine_init,
|
|
|
|
|
&PAINT_TEXTURE_engine_free,
|
|
|
|
|
&PAINT_TEXTURE_cache_init,
|
|
|
|
|
&PAINT_TEXTURE_cache_populate,
|
|
|
|
|
&PAINT_TEXTURE_cache_finish,
|
|
|
|
|
NULL, /* draw_background but not needed by mode engines */
|
|
|
|
|
&PAINT_TEXTURE_draw_scene,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
2017-03-12 21:16:03 +01:00
|
|
|
};
|