Blender V5.3
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
15#include "BKE_mesh_wrapper.hh"
18#include "DNA_object_enums.h"
19#include "DNA_object_types.h"
20
21#include "GPU_material.hh"
22
23namespace blender {
24
25namespace gpu {
26class Batch;
27class Shader;
28class Texture;
29class UniformBuf;
30class FrameBuffer;
31} // namespace gpu
32struct ARegion;
33struct bContext;
36struct Depsgraph;
37struct DupliObject;
38struct GPUMaterial;
39struct Mesh;
40struct Object;
41struct ParticleSystem;
42struct rcti;
43struct RegionView3D;
44struct RenderEngine;
45struct RenderEngineType;
46struct RenderLayer;
47struct RenderResult;
48struct SpaceLink;
49struct TaskGraph;
50struct View3D;
51struct ViewLayer;
52struct DRWContext;
53struct World;
54struct DRWData;
55struct DRWViewData;
56struct GPUViewport;
57struct DRWTextStore;
58struct GPUViewport;
59struct bToolRef;
60namespace draw {
61class TextureFromPool;
62class ObjectRef;
63class Manager;
64} // namespace draw
65
66/* TODO: Put it somewhere else? */
68 float center[3], radius;
69};
70
71struct DrawEngine {
72 static constexpr int GPU_INFO_SIZE = 512; /* IMA_MAX_RENDER_TEXT_SIZE */
73
74 char info[GPU_INFO_SIZE] = {'\0'};
75
76 bool used = false;
77
78 virtual ~DrawEngine() = default;
79
80 virtual StringRefNull name_get() = 0;
81
83 virtual bool uses_render_border() const
84 {
85 return false;
86 }
87
88 /* Functions called for viewport. */
89
91 virtual void init() = 0;
93 virtual void begin_sync() = 0;
94 virtual void object_sync(draw::ObjectRef &ob_ref, draw::Manager &manager) = 0;
95 virtual void end_sync() = 0;
97 virtual void draw(draw::Manager &manager) = 0;
98
99 /* Called when closing blender.
100 * Cleanup all lazily initialized static members that have GPU resources.
101 * Implemented on a case by case basis and called directly. */
102 // static void exit(){};
103
104 struct Pointer {
106
108 {
110 }
111
113 {
114 delete instance;
115 instance = nullptr;
116 }
117
118 void set_used(bool used)
119 {
120 if (used) {
121 if (instance == nullptr) {
123 }
124 instance->used = true;
125 }
126 else if (instance) {
127 instance->used = false;
128 }
129 }
130
132 };
133};
134
135/* Viewport. */
136
144
148bool DRW_viewport_pass_texture_exists(const char *pass_name);
149
151
153 RenderEngine *engine,
154 Depsgraph *depsgraph,
155 ::std::function<void(RenderEngine *, RenderLayer *, const rcti)> render_view_cb,
156 ::std::function<void(RenderResult *)> store_metadata_cb);
157
159 Depsgraph *depsgraph,
160 ::std::function<void(draw::ObjectRef &, RenderEngine *, Depsgraph *)>);
161
162void DRW_render_set_time(RenderEngine *engine, Depsgraph *depsgraph, int frame, float subframe);
163
169void DRW_custom_pipeline_begin(DRWContext &draw_ctx, Depsgraph *depsgraph);
170void DRW_custom_pipeline_end(DRWContext &draw_ctx);
171
176void DRW_cache_restart();
177
178/* Settings. */
179
180bool DRW_object_is_renderable(const Object *ob);
188bool DRW_object_is_in_edit_mode(const Object *ob);
194bool DRW_object_use_hide_faces(const Object *ob);
195
197 const ParticleSystem *psys);
198
203template<typename T> T &DRW_object_get_data_for_drawing(const Object &object)
204{
205 return *id_cast<T *>(object.data);
206}
207
209{
210 /* For drawing we want either the base mesh if GPU subdivision is enabled, or the
211 * tessellated mesh if GPU subdivision is disabled. */
213 return mesh;
214 }
216}
217
218template<> inline Mesh &DRW_object_get_data_for_drawing(const Object &object)
219{
220 BLI_assert(object.type == OB_MESH);
221 return DRW_mesh_get_for_drawing(*id_cast<Mesh *>(object.data));
222}
223
229
230/* Draw State. */
231
232/* -------------------------------------------------------------------- */
235
237 private:
239 static thread_local DRWContext *g_context;
241 float last_sync_time_;
242 float last_submission_time_;
243
244 /* TODO(fclem): Private? */
245 public:
246 /* TODO: clean up this struct a bit. */
248 DRWData *data = nullptr;
251
255 float2 size = {0, 0};
256 float2 inv_size = {0, 0};
257
264
265 const enum Mode {
268
269 /* These viewport modes will render without some overlays (i.e. no text). */
270
280
287
291
297
298 struct {
299 bool draw_background = false;
301
304
307
308 /* TODO(fclem): Public. */
309
311
313 Depsgraph *depsgraph = nullptr;
315 Scene *scene = nullptr;
318
323 const bContext *evil_C = nullptr;
325 ARegion *region = nullptr;
329 RegionView3D *rv3d = nullptr;
331 View3D *v3d = nullptr;
332 /* Active tool in the current context. Might be nullptr. */
335 Object *obact = nullptr;
336 Object *object_pose = nullptr;
337 Object *object_edit = nullptr;
338
340
341 public:
349 Depsgraph *depsgraph,
351 const bContext *C = nullptr,
352 ARegion *region = nullptr,
353 View3D *v3d = nullptr);
355 Depsgraph *depsgraph,
356 const int2 size = {1, 1},
357 const bContext *C = nullptr,
358 ARegion *region = nullptr,
359 View3D *v3d = nullptr);
360
361 ~DRWContext();
362
369 void acquire_data();
370
376 void release_data();
377
384 void enable_engines(bool gpencil_engine_needed = false,
385 RenderEngineType *render_engine_type = nullptr);
386
389
391 ::std::function<void(struct DupliCacheManager &, struct ExtractionGraph &)>;
392
394 void sync(iter_callback_t iter_callback);
396 void engines_init_and_sync(iter_callback_t iter_callback);
398 void engines_draw_scene();
399
401 {
402 return *g_context;
403 }
404
406 {
407 return size;
408 }
409
411 static bool is_active()
412 {
413 return g_context != nullptr;
414 }
415
416 bool is_select() const
417 {
419 }
421 {
423 }
424 bool is_depth() const
425 {
427 }
428 bool is_image_render() const
429 {
431 }
432 bool is_scene_render() const
433 {
434 return ELEM(mode, RENDER);
435 }
437 {
438 return ELEM(mode, VIEWPORT_RENDER);
439 }
440 bool is_viewport_xr() const
441 {
442 return ELEM(mode, VIEWPORT_XR);
443 }
444 float last_sync_time() const
445 {
446 return last_sync_time_;
447 }
449 {
450 return last_submission_time_;
451 }
452
454 bool is_playback() const;
456 bool is_navigating() const;
458 bool is_painting() const;
460 bool is_transforming() const;
462 bool is_viewport_compositor_used() const;
463};
464
466
467const DRWContext *DRW_context_get();
468
469} // namespace blender
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define ELEM(...)
CCL_NAMESPACE_BEGIN struct Options options
#define T
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
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)
void DRW_custom_pipeline_end(DRWContext &draw_ctx)
draw::TextureFromPool & DRW_viewport_pass_texture_get(const char *pass_name)
bool BKE_subsurf_modifier_has_gpu_subdiv(const Mesh *mesh)
bool DRW_object_is_renderable(const Object *ob)
void DRW_cache_restart()
Mesh & DRW_mesh_get_for_drawing(Mesh &mesh)
int DRW_object_visibility_in_active_context(const Object *ob)
void DRW_render_object_iter(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(draw::ObjectRef &, RenderEngine *, Depsgraph *)> callback)
void DRW_render_set_time(RenderEngine *engine, Depsgraph *depsgraph, int frame, float subframe)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
T & DRW_object_get_data_for_drawing(const Object &object)
BMesh const char void * data
bool DRW_object_is_visible_psys_in_active_context(const Object *object, const ParticleSystem *psys)
bool DRW_object_use_hide_faces(const Object *ob)
void DRW_custom_pipeline_begin(DRWContext &draw_ctx, Depsgraph *)
const DRWContext * DRW_context_get()
const Mesh * DRW_object_get_editmesh_cage_for_drawing(const Object &object)
bool DRW_object_is_in_edit_mode(const Object *ob)
bool DRW_viewport_pass_texture_exists(const char *pass_name)
Mesh * BKE_mesh_wrapper_ensure_subdivision(Mesh *mesh)
void DRW_viewport_request_redraw()
bool is_depth() const
bool is_transforming() const
bool is_viewport_xr() const
void sync(iter_callback_t iter_callback)
DefaultTextureList * viewport_texture_list_get() const
RegionView3D * rv3d
gpu::FrameBuffer * default_framebuffer()
Set< Object * > delayed_extraction
bool is_navigating() const
ViewLayer * view_layer
DRWContext(Mode mode, Depsgraph *depsgraph, GPUViewport *viewport, const bContext *C=nullptr, ARegion *region=nullptr, View3D *v3d=nullptr)
GPUViewport * viewport
bool is_painting() const
const bContext * evil_C
void engines_init_and_sync(iter_callback_t iter_callback)
Depsgraph * depsgraph
bool is_select() const
DRWTextStore ** text_store_p
bool is_playback() const
::std::function< void(struct DupliCacheManager &, struct ExtractionGraph &)> iter_callback_t
bool is_image_render() const
eObjectMode object_mode
float2 viewport_size_get() const
bToolRef * active_tool
float last_submission_time() const
bool is_material_select() const
float last_sync_time() const
static DRWContext & get_active()
DefaultFramebufferList * viewport_framebuffer_list_get() const
bool is_viewport_compositor_used() const
bool is_viewport_image_render() const
enum blender::DRWContext::Mode mode
void enable_engines(bool gpencil_engine_needed=false, RenderEngineType *render_engine_type=nullptr)
bool is_scene_render() const
DRWViewData * view_data_active
static bool is_active()
SpaceLink * space_data
virtual DrawEngine * create_instance()=0
char info[GPU_INFO_SIZE]
Definition DRW_render.hh:74
virtual void object_sync(draw::ObjectRef &ob_ref, draw::Manager &manager)=0
virtual void init()=0
virtual StringRefNull name_get()=0
static constexpr int GPU_INFO_SIZE
Definition DRW_render.hh:72
virtual bool uses_render_border() const
Definition DRW_render.hh:83
virtual void draw(draw::Manager &manager)=0
virtual void end_sync()=0
virtual ~DrawEngine()=default
virtual void begin_sync()=0