Blender V4.5
DRW_render.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9/* This is the Render Functions used by Realtime engines to draw with OpenGL */
10
11#pragma once
12
13#include <functional>
14
16#include "DNA_object_enums.h"
17#include "DNA_object_types.h"
18
19#include "GPU_material.hh"
20
21namespace blender::gpu {
22class Batch;
23}
24struct ARegion;
25struct bContext;
26struct Depsgraph;
29struct DupliObject;
30struct GPUMaterial;
31struct GPUShader;
32struct GPUTexture;
33struct GPUUniformBuf;
34struct Mesh;
35struct Object;
36struct ParticleSystem;
37struct rcti;
38struct RegionView3D;
39struct RenderEngine;
40struct RenderEngineType;
41struct RenderLayer;
42struct RenderResult;
43struct SpaceLink;
44struct TaskGraph;
45struct View3D;
46struct ViewLayer;
47struct DRWContext;
48struct World;
49struct DRWData;
50struct DRWViewData;
51struct GPUViewport;
52struct GPUFrameBuffer;
53struct DRWTextStore;
54struct GSet;
55struct GPUViewport;
56namespace blender::draw {
57class TextureFromPool;
58struct ObjectRef;
59class Manager;
60} // namespace blender::draw
61
62/* TODO: Put it somewhere else? */
64 float center[3], radius;
65};
66
67struct DrawEngine {
68 static constexpr int GPU_INFO_SIZE = 512; /* IMA_MAX_RENDER_TEXT_SIZE */
69
70 char info[GPU_INFO_SIZE] = {'\0'};
72
73 bool used = false;
74
75 virtual ~DrawEngine() = default;
76
78
79 /* Functions called for viewport. */
80
82 virtual void init() = 0;
84 virtual void begin_sync() = 0;
85 virtual void object_sync(blender::draw::ObjectRef &ob_ref, blender::draw::Manager &manager) = 0;
86 virtual void end_sync() = 0;
88 virtual void draw(blender::draw::Manager &manager) = 0;
89
90 /* Called when closing blender.
91 * Cleanup all lazily initialized static members that have GPU resources.
92 * Implemented on a case by case basis and called directly. */
93 // static void exit(){};
94
95 struct Pointer {
96 DrawEngine *instance = nullptr;
97
99 {
101 }
102
104 {
105 delete instance;
106 instance = nullptr;
107 }
108
109 void set_used(bool used)
110 {
111 if (used) {
112 if (instance == nullptr) {
114 }
115 instance->used = true;
116 }
117 else if (instance) {
118 instance->used = false;
119 }
120 }
121
123 };
124};
125
126/* Viewport. */
127
135
137
139 RenderEngine *engine,
140 Depsgraph *depsgraph,
141 std::function<void(RenderEngine *, RenderLayer *, const rcti)> render_view_cb,
142 std::function<void(RenderResult *)> store_metadata_cb);
143
145 RenderEngine *engine,
146 Depsgraph *depsgraph,
147 std::function<void(blender::draw::ObjectRef &, RenderEngine *, Depsgraph *)>);
148
149void DRW_render_set_time(RenderEngine *engine, Depsgraph *depsgraph, int frame, float subframe);
150
156void DRW_custom_pipeline_begin(DRWContext &draw_ctx, Depsgraph *depsgraph);
157void DRW_custom_pipeline_end(DRWContext &draw_ctx);
158
163void DRW_cache_restart();
164
165/* Settings. */
166
167bool DRW_object_is_renderable(const Object *ob);
175bool DRW_object_is_in_edit_mode(const Object *ob);
181bool DRW_object_use_hide_faces(const Object *ob);
182
184 const ParticleSystem *psys);
185
190template<typename T> T &DRW_object_get_data_for_drawing(const Object &object)
191{
192 return *static_cast<T *>(object.data);
193}
194
195template<> Mesh &DRW_object_get_data_for_drawing(const Object &object);
196
202
203/* Draw State. */
204
205/* -------------------------------------------------------------------- */
208
210 private:
212 static thread_local DRWContext *g_context;
213
214 /* TODO(fclem): Private? */
215 public:
216 /* TODO: clean up this struct a bit. */
218 DRWData *data = nullptr;
221
227
229 GPUFrameBuffer *default_framebuffer();
234
235 const enum Mode {
238
239 /* These viewport modes will render without some overlays (i.e. no text). */
240
247
254
258
264
265 struct {
266 bool draw_background = false;
267 bool draw_text = false;
269
272
275
276 /* TODO(fclem): Public. */
277
279
281 Depsgraph *depsgraph = nullptr;
283 Scene *scene = nullptr;
286
289 const bContext *evil_C = nullptr;
291 ARegion *region = nullptr;
295 RegionView3D *rv3d = nullptr;
297 View3D *v3d = nullptr;
299 Object *obact = nullptr;
300 Object *object_pose = nullptr;
301 Object *object_edit = nullptr;
302
304
305 public:
313 Depsgraph *depsgraph,
315 const bContext *C = nullptr,
316 ARegion *region = nullptr,
317 View3D *v3d = nullptr);
319 Depsgraph *depsgraph,
320 const blender::int2 size = {1, 1},
321 const bContext *C = nullptr,
322 ARegion *region = nullptr,
323 View3D *v3d = nullptr);
324
325 ~DRWContext();
326
333 void acquire_data();
334
340 void release_data();
341
348 void enable_engines(bool gpencil_engine_needed = false,
349 RenderEngineType *render_engine_type = nullptr);
350
353
355 std::function<void(struct DupliCacheManager &, struct ExtractionGraph &)>;
356
358 void sync(iter_callback_t iter_callback);
360 void engines_init_and_sync(iter_callback_t iter_callback);
362 void engines_draw_scene();
363
365 {
366 return *g_context;
367 }
368
370 {
371 return size;
372 }
373
375 static bool is_active()
376 {
377 return g_context != nullptr;
378 }
379
380 bool is_select() const
381 {
383 }
385 {
387 }
388 bool is_depth() const
389 {
391 }
392 bool is_image_render() const
393 {
395 }
396 bool is_scene_render() const
397 {
398 return ELEM(mode, RENDER);
399 }
401 {
402 return ELEM(mode, VIEWPORT_RENDER);
403 }
404
406 bool is_playback() const;
408 bool is_navigating() const;
410 bool is_painting() const;
412 bool is_transforming() const;
415};
416
418
struct GSet GSet
Definition BLI_ghash.h:337
#define ELEM(...)
eObjectMode
@ OB_MODE_OBJECT
Object is a sort of wrapper for general info.
const DRWContext * DRW_context_get()
void DRW_cache_restart()
bool DRW_object_is_in_edit_mode(const Object *ob)
blender::draw::TextureFromPool & DRW_viewport_pass_texture_get(const char *pass_name)
void DRW_render_to_image(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(RenderEngine *, RenderLayer *, const rcti)> render_view_cb, std::function< void(RenderResult *)> store_metadata_cb)
bool DRW_object_use_hide_faces(const Object *ob)
bool DRW_object_is_renderable(const Object *ob)
T & DRW_object_get_data_for_drawing(const Object &object)
int DRW_object_visibility_in_active_context(const Object *ob)
void DRW_custom_pipeline_begin(DRWContext &draw_ctx, Depsgraph *depsgraph)
bool DRW_object_is_visible_psys_in_active_context(const Object *object, const ParticleSystem *psys)
const Mesh * DRW_object_get_editmesh_cage_for_drawing(const Object &object)
void DRW_render_set_time(RenderEngine *engine, Depsgraph *depsgraph, int frame, float subframe)
void DRW_custom_pipeline_end(DRWContext &draw_ctx)
void DRW_viewport_request_redraw()
void DRW_render_object_iter(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(blender::draw::ObjectRef &, RenderEngine *, Depsgraph *)>)
#define C
Definition RandGen.cpp:29
BPy_StructRNA * depsgraph
CCL_NAMESPACE_BEGIN struct Options options
#define T
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
float center[3]
Definition DRW_render.hh:64
bool is_image_render() const
DRWContext(Mode mode, Depsgraph *depsgraph, GPUViewport *viewport, const bContext *C=nullptr, ARegion *region=nullptr, View3D *v3d=nullptr)
bool is_playback() const
DRWViewData * view_data_active
static bool is_active()
Object * object_edit
GSet * delayed_extraction
bool draw_background
void sync(iter_callback_t iter_callback)
DefaultFramebufferList * viewport_framebuffer_list_get() const
DRWData * data
View3D * v3d
Depsgraph * depsgraph
bool is_scene_render() const
DRWTextStore ** text_store_p
void enable_engines(bool gpencil_engine_needed=false, RenderEngineType *render_engine_type=nullptr)
RegionView3D * rv3d
blender::float2 inv_size
@ DEPTH_ACTIVE_OBJECT
@ SELECT_OBJECT_MATERIAL
blender::float2 size
static DRWContext & get_active()
Object * obact
enum DRWContext::Mode mode
blender::float2 viewport_size_get() const
void engines_draw_scene()
Scene * scene
Object * object_pose
void acquire_data()
const bContext * evil_C
bool is_depth() const
bool is_painting() const
bool is_viewport_image_render() const
eObjectMode object_mode
void release_data()
ARegion * region
DRWContext(Mode mode, Depsgraph *depsgraph, const blender::int2 size={1, 1}, const bContext *C=nullptr, ARegion *region=nullptr, View3D *v3d=nullptr)
void engines_init_and_sync(iter_callback_t iter_callback)
SpaceLink * space_data
GPUFrameBuffer * default_framebuffer()
bool is_transforming() const
DefaultTextureList * viewport_texture_list_get() const
GPUViewport * viewport
bool is_select() const
ViewLayer * view_layer
void engines_data_validate()
std::function< void(struct DupliCacheManager &, struct ExtractionGraph &)> iter_callback_t
bool is_navigating() const
bool is_viewport_compositor_enabled() const
bool is_material_select() const
void set_used(bool used)
DrawEngine * instance
Definition DRW_render.hh:96
virtual DrawEngine * create_instance()=0
virtual void begin_sync()=0
virtual void object_sync(blender::draw::ObjectRef &ob_ref, blender::draw::Manager &manager)=0
virtual void draw(blender::draw::Manager &manager)=0
virtual void init()=0
static constexpr int GPU_INFO_SIZE
Definition DRW_render.hh:68
char info[GPU_INFO_SIZE]
Definition DRW_render.hh:70
virtual blender::StringRefNull name_get()=0
virtual ~DrawEngine()=default
DRWTextStore * text_draw_cache
Definition DRW_render.hh:71
virtual void end_sync()=0