Overlay-Next: Initial implementation #107045
105
source/blender/draw/engines/overlay/overlay_background.hh
Normal file
105
source/blender/draw/engines/overlay/overlay_background.hh
Normal file
@ -0,0 +1,105 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup overlay
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "ED_view3d.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
#include "draw_cache.h"
|
||||
#include "draw_pass.hh"
|
||||
#include "overlay_private.hh"
|
||||
#include "overlay_shader_shared.h"
|
||||
|
||||
namespace blender::draw::overlay {
|
||||
|
||||
class Background {
|
||||
private:
|
||||
PassSimple bg_ps_ = {"Background"};
|
||||
|
||||
public:
|
||||
void begin_sync(Resources &res, const State &state)
|
||||
{
|
||||
DRWState pass_state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_BACKGROUND;
|
||||
float4 color_override(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
int background_type;
|
||||
|
||||
if (DRW_state_is_opengl_render() && !DRW_state_draw_background()) {
|
||||
background_type = BG_SOLID;
|
||||
color_override[3] = 1.0f;
|
||||
}
|
||||
/*
|
||||
else if (pd->space_type == SPACE_IMAGE) {
|
||||
background_type = BG_SOLID_CHECKER;
|
||||
}
|
||||
else if (pd->space_type == SPACE_NODE) {
|
||||
background_type = BG_MASK;
|
||||
pass_state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_MUL;
|
||||
}
|
||||
*/
|
||||
else if (!DRW_state_draw_background()) {
|
||||
background_type = BG_CHECKER;
|
||||
}
|
||||
else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_WORLD &&
|
||||
state.scene->world) {
|
||||
background_type = BG_SOLID;
|
||||
/* TODO(fclem): this is a scene referred linear color. we should convert
|
||||
* it to display linear here. */
|
||||
color_override = float4(UNPACK3(&state.scene->world->horr), 1.0f);
|
||||
}
|
||||
else if (state.v3d->shading.background_type == V3D_SHADING_BACKGROUND_VIEWPORT &&
|
||||
state.v3d->shading.type <= OB_SOLID) {
|
||||
background_type = BG_SOLID;
|
||||
color_override = float4(UNPACK3(state.v3d->shading.background_color), 1.0f);
|
||||
}
|
||||
else {
|
||||
switch (UI_GetThemeValue(TH_BACKGROUND_TYPE)) {
|
||||
case TH_BACKGROUND_GRADIENT_LINEAR:
|
||||
background_type = BG_GRADIENT;
|
||||
break;
|
||||
case TH_BACKGROUND_GRADIENT_RADIAL:
|
||||
background_type = BG_RADIAL;
|
||||
break;
|
||||
default:
|
||||
case TH_BACKGROUND_SINGLE_COLOR:
|
||||
background_type = BG_SOLID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bg_ps_.init();
|
||||
bg_ps_.clear_color(float4());
|
||||
bg_ps_.state_set(pass_state);
|
||||
bg_ps_.shader_set(OVERLAY_shader_background());
|
||||
bg_ps_.bind_ubo("globalsBlock", &res.globals_buf);
|
||||
bg_ps_.bind_texture("colorBuffer", &res.color_render_tx);
|
||||
bg_ps_.bind_texture("depthBuffer", &res.depth_tx);
|
||||
bg_ps_.push_constant("colorOverride", color_override);
|
||||
bg_ps_.push_constant("bgType", background_type);
|
||||
bg_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
|
||||
if (state.clipping_state != 0 && state.rv3d != nullptr && state.rv3d->clipbb != nullptr) {
|
||||
bg_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA | DRW_STATE_CULL_BACK);
|
||||
bg_ps_.shader_set(OVERLAY_shader_clipbound());
|
||||
bg_ps_.push_constant("ucolor", res.theme_settings.color_clipping_border);
|
||||
bg_ps_.push_constant("boundbox", &state.rv3d->clipbb->vec[0][0], 8);
|
||||
bg_ps_.draw(DRW_cache_cube_get());
|
||||
}
|
||||
}
|
||||
|
||||
void draw(Resources &res, Manager &manager)
|
||||
{
|
||||
if (DRW_state_is_fbo()) {
|
||||
GPU_framebuffer_bind(res.overlay_color_only_fb);
|
||||
}
|
||||
manager.submit(bg_ps_);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blender::draw::overlay
|
@ -19,7 +19,6 @@
|
||||
namespace blender::draw::overlay {
|
||||
|
||||
class Grid {
|
||||
public:
|
||||
private:
|
||||
UniformBuffer<OVERLAY_GridData> data_;
|
||||
|
||||
@ -175,7 +174,6 @@ class Grid {
|
||||
|
||||
grid_ps_.init();
|
||||
grid_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA);
|
||||
grid_ps_.clear_color(float4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
grid_ps_.shader_set(OVERLAY_shader_grid());
|
||||
grid_ps_.bind_ubo("grid_buf", &data_);
|
||||
grid_ps_.bind_ubo("globalsBlock", &res.globals_buf);
|
||||
|
@ -5,13 +5,15 @@
|
||||
*/
|
||||
|
||||
#include "overlay_instance.hh"
|
||||
#include "draw_debug.hh"
|
||||
|
||||
namespace blender::draw::overlay {
|
||||
|
||||
void Instance::init()
|
||||
{
|
||||
resources.depth_tx.wrap(DRW_viewport_texture_list_get()->depth);
|
||||
resources.color_tx.wrap(DRW_viewport_texture_list_get()->color_overlay);
|
||||
resources.color_overlay_tx.wrap(DRW_viewport_texture_list_get()->color_overlay);
|
||||
resources.color_render_tx.wrap(DRW_viewport_texture_list_get()->color);
|
||||
|
||||
/* TODO(fclem): Remove DRW global usage. */
|
||||
const DRWContextState *ctx = DRW_context_state_get();
|
||||
@ -53,6 +55,7 @@ void Instance::init()
|
||||
|
||||
/* TODO(fclem): Remove DRW global usage. */
|
||||
resources.globals_buf = G_draw.block_ubo;
|
||||
resources.theme_settings = G_draw.block;
|
||||
}
|
||||
|
||||
void Instance::begin_sync()
|
||||
@ -60,6 +63,7 @@ void Instance::begin_sync()
|
||||
const DRWView *view_legacy = DRW_view_default_get();
|
||||
View view("OverlayView", view_legacy);
|
||||
|
||||
background.begin_sync(resources, state);
|
||||
grid.begin_sync(resources, state, view);
|
||||
}
|
||||
|
||||
@ -74,19 +78,31 @@ void Instance::end_sync()
|
||||
|
||||
void Instance::draw(Manager &manager)
|
||||
{
|
||||
/* WORKAROUND: This is to prevent crashes when using depth picking or selection.
|
||||
* The selection engine should handle theses cases instead. */
|
||||
if (!DRW_state_is_fbo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const DRWView *view_legacy = DRW_view_default_get();
|
||||
View view("OverlayView", view_legacy);
|
||||
|
||||
resources.line_tx.acquire(int2(resources.depth_tx.size()), GPU_RGBA8);
|
||||
|
||||
resources.overlay_color_only_fb.ensure(GPU_ATTACHMENT_NONE,
|
||||
GPU_ATTACHMENT_TEXTURE(resources.color_tx));
|
||||
GPU_ATTACHMENT_TEXTURE(resources.color_overlay_tx));
|
||||
resources.overlay_fb.ensure(GPU_ATTACHMENT_TEXTURE(resources.depth_tx),
|
||||
GPU_ATTACHMENT_TEXTURE(resources.color_tx));
|
||||
GPU_ATTACHMENT_TEXTURE(resources.color_overlay_tx));
|
||||
resources.overlay_line_fb.ensure(GPU_ATTACHMENT_TEXTURE(resources.depth_tx),
|
||||
GPU_ATTACHMENT_TEXTURE(resources.color_tx),
|
||||
GPU_ATTACHMENT_TEXTURE(resources.color_overlay_tx),
|
||||
GPU_ATTACHMENT_TEXTURE(resources.line_tx));
|
||||
|
||||
GPU_framebuffer_bind(resources.overlay_color_only_fb);
|
||||
|
||||
float4 clear_color(0.0f);
|
||||
GPU_framebuffer_clear_color(resources.overlay_color_only_fb, clear_color);
|
||||
|
||||
background.draw(resources, manager);
|
||||
grid.draw(resources, manager, view);
|
||||
|
||||
// anti_aliasing.draw(resources, manager, view);
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "draw_manager.hh"
|
||||
|
||||
#include "overlay_background.hh"
|
||||
#include "overlay_grid.hh"
|
||||
|
||||
namespace blender::draw::overlay {
|
||||
@ -51,8 +52,12 @@ class Instance {
|
||||
/* WORKAROUND: Legacy. Move to grid pass. */
|
||||
GPUUniformBuf *grid_ubo = nullptr;
|
||||
|
||||
/** Global types. */
|
||||
Resources resources;
|
||||
State state;
|
||||
|
||||
/** Overlay types. */
|
||||
Background background;
|
||||
Grid grid;
|
||||
|
||||
~Instance()
|
||||
|
@ -66,10 +66,14 @@ struct Resources {
|
||||
|
||||
TextureFromPool line_tx = {"line_tx"};
|
||||
|
||||
/** TODO(fclem): Copy of G_data.block that should become theme colors only and managed by the
|
||||
* engine. */
|
||||
GlobalsUboStorage theme_settings;
|
||||
/* References, not owned. */
|
||||
GPUUniformBuf *globals_buf;
|
||||
TextureRef depth_tx;
|
||||
TextureRef color_tx;
|
||||
TextureRef color_overlay_tx;
|
||||
TextureRef color_render_tx;
|
||||
};
|
||||
|
||||
} // namespace blender::draw::overlay
|
||||
|
Loading…
Reference in New Issue
Block a user