Blender V5.0
draw_view_data.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <memory>
10
11#include "BLI_listbase.h"
12#include "BLI_math_vector.h"
13#include "BLI_vector.hh"
14
15#include "GPU_viewport.hh"
16
17#include "DRW_gpu_wrapper.hh"
18#include "DRW_render.hh"
19
20#include "draw_manager_text.hh"
21
23#include "draw_manager.hh"
24#include "draw_view_data.hh"
25
26using namespace blender;
27
32
34{
35 this->clear(true);
36 delete manager;
37};
38
40{
41 int active_view = GPU_viewport_active_view_get(viewport);
42 view_data->from_viewport = true;
43
44 DefaultFramebufferList *dfbl = &view_data->dfbl;
45 DefaultTextureList *dtxl = &view_data->dtxl;
46 /* Depth texture is shared between both stereo views. */
47 dtxl->depth = GPU_viewport_depth_texture(viewport);
48 dtxl->color = GPU_viewport_color_texture(viewport, active_view);
49 dtxl->color_overlay = GPU_viewport_overlay_texture(viewport, active_view);
50
52 {
53 GPU_ATTACHMENT_TEXTURE(dtxl->depth),
54 GPU_ATTACHMENT_TEXTURE(dtxl->color),
55 });
57 {
58 GPU_ATTACHMENT_TEXTURE(dtxl->depth),
59 GPU_ATTACHMENT_TEXTURE(dtxl->color_overlay),
60 });
62 {
63 GPU_ATTACHMENT_TEXTURE(dtxl->depth),
64 GPU_ATTACHMENT_NONE,
65 });
67 {
68 GPU_ATTACHMENT_NONE,
69 GPU_ATTACHMENT_TEXTURE(dtxl->color),
70 });
72 {
73 GPU_ATTACHMENT_NONE,
74 GPU_ATTACHMENT_TEXTURE(dtxl->color_overlay),
75 });
76}
77
78void DRWViewData::clear(bool free_instance_data)
79{
80 GPU_FRAMEBUFFER_FREE_SAFE(this->dfbl.default_fb);
81 GPU_FRAMEBUFFER_FREE_SAFE(this->dfbl.overlay_fb);
82 GPU_FRAMEBUFFER_FREE_SAFE(this->dfbl.in_front_fb);
83 GPU_FRAMEBUFFER_FREE_SAFE(this->dfbl.color_only_fb);
84 GPU_FRAMEBUFFER_FREE_SAFE(this->dfbl.depth_only_fb);
85 GPU_FRAMEBUFFER_FREE_SAFE(this->dfbl.overlay_only_fb);
86
87 if (!this->from_viewport) {
88 GPU_TEXTURE_FREE_SAFE(this->dtxl.color);
89 GPU_TEXTURE_FREE_SAFE(this->dtxl.color_overlay);
90 GPU_TEXTURE_FREE_SAFE(this->dtxl.depth);
91 }
92 GPU_TEXTURE_FREE_SAFE(this->dtxl.depth_in_front);
93
94 if (free_instance_data) {
95 foreach_engine([&](DrawEngine::Pointer &ptr) {
96 if (ptr.instance) {
97 ptr.free_instance();
98 }
99 });
100 }
101}
102
104{
105 if (this->texture_list_size != size) {
106 this->clear(false);
108 }
109}
110
112{
113 view_data->foreach_enabled_engine([&](DrawEngine &instance) { instance.used = false; });
114
115 for (std::unique_ptr<draw::TextureFromPool> &texture :
117 {
118 texture->release();
119 }
121}
122
124{
125 view_data->foreach_engine([&](DrawEngine::Pointer &ptr) {
126 if (ptr.instance && ptr.instance->used == false) {
127 ptr.free_instance();
128 }
129 });
130}
131
133{
134 BLI_assert(drw_get().view_data_active->manager);
136}
#define BLI_assert(a)
Definition BLI_assert.h:46
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
#define GPU_FRAMEBUFFER_FREE_SAFE(fb)
#define GPU_framebuffer_ensure_config(_fb,...)
#define GPU_TEXTURE_FREE_SAFE(texture)
int GPU_viewport_active_view_get(GPUViewport *viewport)
blender::gpu::Texture * GPU_viewport_overlay_texture(GPUViewport *viewport, int view)
blender::gpu::Texture * GPU_viewport_color_texture(GPUViewport *viewport, int view)
blender::gpu::Texture * GPU_viewport_depth_texture(GPUViewport *viewport)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void clear()
Definition BLI_map.hh:1038
ValueIterator values() const &
Definition BLI_map.hh:884
DRWContext & drw_get()
void DRW_view_data_default_lists_from_viewport(DRWViewData *view_data, GPUViewport *viewport)
draw::Manager * DRW_manager_get()
void DRW_view_data_reset(DRWViewData *view_data)
void DRW_view_data_free_unused(DRWViewData *view_data)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
VecBase< int32_t, 2 > int2
DRWViewData * view_data_active
void foreach_engine(CallbackT callback)
DefaultTextureList dtxl
blender::Map< std::string, std::unique_ptr< blender::draw::TextureFromPool > > viewport_compositor_passes
DefaultFramebufferList dfbl
blender::draw::Manager * manager
void foreach_enabled_engine(CallbackT callback)
void texture_list_size_validate(const blender::int2 &size)
blender::int2 texture_list_size
blender::gpu::FrameBuffer * overlay_only_fb
blender::gpu::FrameBuffer * default_fb
blender::gpu::FrameBuffer * color_only_fb
blender::gpu::FrameBuffer * overlay_fb
blender::gpu::FrameBuffer * depth_only_fb
blender::gpu::Texture * depth
blender::gpu::Texture * color
blender::gpu::Texture * color_overlay
PointerRNA * ptr
Definition wm_files.cc:4238