diff options
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/solid_flat_frag.glsl (renamed from source/blender/draw/engines/workbench/shaders/solid_frag.glsl) | 0 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/solid_flat_mode.c | 116 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_materials_solid.c | 143 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 21 |
5 files changed, 106 insertions, 177 deletions
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index b22c97e352c..9fae5a6c3af 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -104,7 +104,6 @@ set(SRC engines/eevee/eevee_subsurface.c engines/eevee/eevee_temporal_sampling.c engines/eevee/eevee_volumes.c - engines/workbench/workbench_materials_solid.c engines/workbench/workbench_engine.c engines/workbench/solid_flat_mode.c engines/external/external_engine.c @@ -206,7 +205,7 @@ data_to_c_simple(engines/eevee/shaders/volumetric_resolve_frag.glsl SRC) data_to_c_simple(engines/eevee/shaders/volumetric_scatter_frag.glsl SRC) data_to_c_simple(engines/eevee/shaders/volumetric_integration_frag.glsl SRC) -data_to_c_simple(engines/workbench/shaders/solid_frag.glsl SRC) +data_to_c_simple(engines/workbench/shaders/solid_flat_frag.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_vert.glsl SRC) data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC) diff --git a/source/blender/draw/engines/workbench/shaders/solid_frag.glsl b/source/blender/draw/engines/workbench/shaders/solid_flat_frag.glsl index 3a6700bdadc..3a6700bdadc 100644 --- a/source/blender/draw/engines/workbench/shaders/solid_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/solid_flat_frag.glsl diff --git a/source/blender/draw/engines/workbench/solid_flat_mode.c b/source/blender/draw/engines/workbench/solid_flat_mode.c index 79f1fbd170d..e8d2c61152e 100644 --- a/source/blender/draw/engines/workbench/solid_flat_mode.c +++ b/source/blender/draw/engines/workbench/solid_flat_mode.c @@ -19,7 +19,7 @@ * */ -/** \file workbench_engine.c +/** \file solid_flat_mode.c * \ingroup draw_engine * * Simple engine for drawing color and/or depth. @@ -28,49 +28,112 @@ #include "DRW_render.h" -#include "BKE_icons.h" -#include "BKE_idprop.h" -#include "BKE_main.h" - #include "GPU_shader.h" -#include "workbench_engine.h" #include "workbench_private.h" /* Shaders */ -#define WORKBENCH_ENGINE "BLENDER_WORKBENCH" +extern char datatoc_solid_flat_frag_glsl[]; +extern char datatoc_workbench_vert_glsl[]; + +/* *********** STATIC *********** */ +static struct { + struct GPUShader *depth_sh; + + /* Shading Pass */ + struct GPUShader *solid_sh; + +} e_data = {NULL}; /* Functions */ -static void workbench_engine_init(void *UNUSED(vedata)) +static void workbench_solid_flat_engine_init(void *UNUSED(vedata)) { - workbench_solid_materials_init(); + if (!e_data.depth_sh) { + /* Depth pass */ + e_data.depth_sh = DRW_shader_create_3D_depth_only(); + + /* Shading pass */ + e_data.solid_sh = DRW_shader_create( + datatoc_workbench_vert_glsl, NULL, datatoc_solid_flat_frag_glsl, "\n"); + } } -static void workbench_cache_init(void *vedata) +static void workbench_solid_flat_cache_init(void *vedata) { - workbench_solid_materials_cache_init((WORKBENCH_Data *)vedata); + + WORKBENCH_Data * data = (WORKBENCH_Data *)vedata; + WORKBENCH_PassList *psl = data->psl; + WORKBENCH_StorageList *stl = data->stl; + + if (!stl->g_data) { + /* Alloc transient pointers */ + stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__); + } + + /* Depth Pass */ + { + int state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS; + psl->depth_pass = DRW_pass_create("Depth Pass", state); + stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass); + } + + /* Solid Pass */ + { + int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL; + psl->solid_pass = DRW_pass_create("Solid Pass", state); + } + + /* Flat Lighting Pass */ + { + int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL; + psl->lighting_pass = DRW_pass_create("Lighting Pass", state); + } } -static void workbench_cache_populate(void *vedata, Object *ob) +static void workbench_solid_flat_cache_populate(void *vedata, Object *ob) { - workbench_solid_materials_cache_populate((WORKBENCH_Data *)vedata, ob); + WORKBENCH_Data * data = (WORKBENCH_Data *)vedata; + + WORKBENCH_PassList *psl = data->psl; + WORKBENCH_StorageList *stl = data->stl; + + IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_WORKBENCH); + const float* color = BKE_collection_engine_property_value_get_float_array(props, "object_color"); + + if (!DRW_object_is_renderable(ob)) + return; + + struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob); + DRWShadingGroup *grp; + if (geom) { + /* Depth */ + DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat); + + /* Solid */ + grp = DRW_shgroup_create(e_data.solid_sh, psl->solid_pass); + DRW_shgroup_uniform_vec3(grp, "color", color, 1); + DRW_shgroup_call_add(grp, geom, ob->obmat); + } } -static void workbench_cache_finish(void *vedata) +static void workbench_solid_flat_cache_finish(void *UNUSED(vedata)) { - workbench_solid_materials_cache_finish((WORKBENCH_Data *)vedata); } -static void workbench_draw_scene(void *vedata) +static void workbench_solid_flat_draw_scene(void *vedata) { - workbench_solid_materials_draw_scene((WORKBENCH_Data *)vedata); + WORKBENCH_Data * data = (WORKBENCH_Data *)vedata; + WORKBENCH_PassList *psl = ((WORKBENCH_Data *)vedata)->psl; + + DRW_draw_pass(psl->depth_pass); + DRW_draw_pass(psl->solid_pass); } -static void workbench_engine_free(void) +static void workbench_solid_flat_engine_free(void) { - workbench_solid_materials_free(); + DRW_SHADER_FREE_SAFE(e_data.solid_sh); } static const DrawEngineDataSize workbench_data_size = DRW_VIEWPORT_DATA_SIZE(WORKBENCH_Data); @@ -79,17 +142,14 @@ DrawEngineType draw_engine_workbench_solid_flat = { NULL, NULL, N_("Workbench"), &workbench_data_size, - &workbench_engine_init, - &workbench_engine_free, - &workbench_cache_init, - &workbench_cache_populate, - &workbench_cache_finish, + &workbench_solid_flat_engine_init, + &workbench_solid_flat_engine_free, + &workbench_solid_flat_cache_init, + &workbench_solid_flat_cache_populate, + &workbench_solid_flat_cache_finish, NULL, - &workbench_draw_scene, + &workbench_solid_flat_draw_scene, NULL, NULL, NULL, }; - - -#undef WORKBENCH_ENGINE diff --git a/source/blender/draw/engines/workbench/workbench_materials_solid.c b/source/blender/draw/engines/workbench/workbench_materials_solid.c deleted file mode 100644 index 6fb26609e90..00000000000 --- a/source/blender/draw/engines/workbench/workbench_materials_solid.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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 workbench_materials.c - * \ingroup draw_engine - */ - -#include "workbench_private.h" -#include "GPU_shader.h" - -extern char datatoc_solid_frag_glsl[]; -extern char datatoc_flat_lighting_frag_glsl[]; -extern char datatoc_workbench_vert_glsl[]; - -/* *********** STATIC *********** */ -static struct { - struct GPUShader *depth_sh; - - /* Shading Pass */ - struct GPUShader *solid_sh; - -} e_data = {NULL}; - - -void workbench_solid_materials_init() { - if (!e_data.depth_sh) { - /* Depth pass */ - e_data.depth_sh = DRW_shader_create_3D_depth_only(); - - /* Shading pass */ - e_data.solid_sh = DRW_shader_create( - datatoc_workbench_vert_glsl, NULL, datatoc_solid_frag_glsl, "\n"); - } -} - -void workbench_solid_materials_cache_init(WORKBENCH_Data* vedata) -{ - WORKBENCH_PassList *psl = vedata->psl; - WORKBENCH_StorageList *stl = vedata->stl; - - if (!stl->g_data) { - /* Alloc transient pointers */ - stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__); - } - - /* Depth Pass */ - { - int state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS; - psl->depth_pass = DRW_pass_create("Depth Pass", state); - stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass); - } - - /* Solid Pass */ - { - int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL; - psl->solid_pass = DRW_pass_create("Solid Pass", state); - } - - /* Flat Lighting Pass */ - { - int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL; - psl->lighting_pass = DRW_pass_create("Lighting Pass", state); - } -} - - void workbench_solid_materials_cache_populate(WORKBENCH_Data* vedata, Object *ob) -{ - WORKBENCH_PassList *psl = vedata->psl; - WORKBENCH_StorageList *stl = vedata->stl; - - IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_WORKBENCH); - const float* color = BKE_collection_engine_property_value_get_float_array(props, "object_color"); - - if (!DRW_object_is_renderable(ob)) - return; - - struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob); - DRWShadingGroup *grp; - if (geom) { - /* Depth */ - DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat); - - /* Solid */ - grp = DRW_shgroup_create(e_data.solid_sh, psl->solid_pass); - DRW_shgroup_uniform_vec3(grp, "color", color, 1); - DRW_shgroup_call_add(grp, geom, ob->obmat); - - /* Lighting */ - // if studio lighting - - } -} - -void workbench_solid_materials_cache_finish(WORKBENCH_Data *vedata) -{ - WORKBENCH_StorageList *stl = ((WORKBENCH_Data *)vedata)->stl; - - UNUSED_VARS(stl); -} - -void workbench_solid_materials_draw_scene(WORKBENCH_Data *vedata) -{ - - WORKBENCH_PassList *psl = ((WORKBENCH_Data *)vedata)->psl; -// DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); - - DRW_draw_pass(psl->depth_pass); -// if (studio lighting) { -// DRW_draw_pass(psl->lighting_pass); -// DRW_draw_pass(psl->solid_pass); -// TODO: COMPOSITE -// } - -// if (flat lighting) { - DRW_draw_pass(psl->solid_pass); -// } -} - -void workbench_solid_materials_free(void) -{ - DRW_SHADER_FREE_SAFE(e_data.solid_sh); -} - - - diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index c0a5b7e41fc..84aff8be786 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -895,11 +895,20 @@ static void drw_engines_enable_external(void) /* TODO revisit this when proper layering is implemented */ /* Gather all draw engines needed and store them in DST.enabled_engines * That also define the rendering order of engines */ -static void drw_engines_enable_from_engine(RenderEngineType *engine_type, int draw_mode) +static void drw_engines_enable_from_engine(RenderEngineType *engine_type, int draw_mode, + int UNUSED(draw_mode_wireframe), int draw_mode_solid, int UNUSED(draw_mode_texture)) { switch (draw_mode) { + case OB_WIRE: + break; + case OB_SOLID: - use_drw_engine(&draw_engine_workbench_solid_flat); + if (draw_mode_solid == OB_LIGHTING_FLAT) { + use_drw_engine(&draw_engine_workbench_solid_flat); + } + break; + + case OB_TEXTURE: break; default: @@ -984,9 +993,13 @@ static void drw_engines_enable(ViewLayer *view_layer, RenderEngineType *engine_t { Object *obact = OBACT(view_layer); const int mode = CTX_data_mode_enum_ex(DST.draw_ctx.object_edit, obact, DST.draw_ctx.object_mode); - const int draw_mode = DST.draw_ctx.v3d->drawtype; + View3D * v3d = DST.draw_ctx.v3d; + const int draw_mode = v3d->drawtype; + const int draw_mode_wireframe = v3d->drawtype_wireframe; + const int draw_mode_solid = v3d->drawtype_solid; + const int draw_mode_texture = v3d->drawtype_texture; - drw_engines_enable_from_engine(engine_type, draw_mode); + drw_engines_enable_from_engine(engine_type, draw_mode, draw_mode_wireframe, draw_mode_solid, draw_mode_texture); if (DRW_state_draw_support()) { drw_engines_enable_from_object_mode(); |