Blender V4.5
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 /* TODO Move where it belongs. */
98 DRW_text_cache_destroy(ptr.instance->text_draw_cache);
99 ptr.free_instance();
100 }
101 });
102 }
103}
104
106{
107 if (this->texture_list_size != size) {
108 this->clear(false);
110 }
111}
112
114{
115 view_data->foreach_enabled_engine([&](DrawEngine &instance) { instance.used = false; });
116
117 for (std::unique_ptr<draw::TextureFromPool> &texture :
119 {
120 texture->release();
121 }
123}
124
126{
127 view_data->foreach_engine([&](DrawEngine::Pointer &ptr) {
128 if (ptr.instance && ptr.instance->used == false) {
129 /* TODO Move where it belongs. */
130 DRW_text_cache_destroy(ptr.instance->text_draw_cache);
131 ptr.free_instance();
132 }
133 });
134}
135
137{
138 BLI_assert(drw_get().view_data_active->manager);
140}
#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)
GPUTexture * GPU_viewport_color_texture(GPUViewport *viewport, int view)
int GPU_viewport_active_view_get(GPUViewport *viewport)
GPUTexture * GPU_viewport_depth_texture(GPUViewport *viewport)
GPUTexture * GPU_viewport_overlay_texture(GPUViewport *viewport, int view)
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_text_cache_destroy(DRWTextStore *dt)
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
GPUFrameBuffer * depth_only_fb
GPUFrameBuffer * overlay_fb
GPUFrameBuffer * color_only_fb
GPUFrameBuffer * overlay_only_fb
GPUFrameBuffer * default_fb
GPUTexture * color_overlay
PointerRNA * ptr
Definition wm_files.cc:4226