2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * Copyright 2016, Blender Foundation.
19 /** \file \ingroup draw
22 /* This is the Render Functions used by Realtime engines to draw with OpenGL */
24 #ifndef __DRW_RENDER_H__
25 #define __DRW_RENDER_H__
27 #include "BLI_listbase.h"
28 #include "BLI_math_matrix.h"
29 #include "BLI_math_vector.h"
30 #include "BLI_string.h"
32 #include "BKE_context.h"
33 #include "BKE_layer.h"
34 #include "BKE_material.h"
35 #include "BKE_scene.h"
37 #include "BLT_translation.h"
39 #include "DNA_object_types.h"
40 #include "DNA_lamp_types.h"
41 #include "DNA_material_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_world_types.h"
45 #include "GPU_framebuffer.h"
46 #include "GPU_texture.h"
47 #include "GPU_shader.h"
49 #include "draw_common.h"
50 #include "draw_cache.h"
51 #include "draw_view.h"
53 #include "draw_manager_profiling.h"
54 #include "draw_debug.h"
56 #include "MEM_guardedalloc.h"
58 #include "RE_engine.h"
60 #include "DEG_depsgraph.h"
63 struct DefaultFramebufferList;
64 struct DefaultTextureList;
66 struct GPUFrameBuffer;
70 struct GPUUniformBuffer;
71 struct LampEngineData;
73 struct ParticleSystem;
74 struct RenderEngineType;
75 struct ViewportEngineData;
76 struct ViewportEngineData_Info;
80 typedef struct DRWInterface DRWInterface;
81 typedef struct DRWPass DRWPass;
82 typedef struct DRWShadingGroup DRWShadingGroup;
83 typedef struct DRWUniform DRWUniform;
85 /* TODO Put it somewhere else? */
86 typedef struct BoundSphere {
87 float center[3], radius;
90 /* declare members as empty (unused) */
91 typedef char DRWViewportEmptyList;
93 #define DRW_VIEWPORT_LIST_SIZE(list) \
94 (sizeof(list) == sizeof(DRWViewportEmptyList) ? 0 : ((sizeof(list)) / sizeof(void *)))
96 /* Unused members must be either pass list or 'char *' when not usd. */
97 #define DRW_VIEWPORT_DATA_SIZE(ty) { \
98 DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->fbl)), \
99 DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->txl)), \
100 DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->psl)), \
101 DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->stl)) \
104 /* Use of multisample framebuffers. */
105 #define MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl) { \
106 if (dfbl->multisample_fb != NULL) { \
107 DRW_stats_query_start("Multisample Blit"); \
108 GPU_framebuffer_bind(dfbl->multisample_fb); \
109 /* TODO clear only depth but need to do alpha to coverage for transparencies. */ \
110 GPU_framebuffer_clear_color_depth(dfbl->multisample_fb, (const float[4]){0.0f}, 1.0f); \
111 DRW_stats_query_end(); \
115 #define MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl) { \
116 if (dfbl->multisample_fb != NULL) { \
117 DRW_stats_query_start("Multisample Resolve"); \
118 GPU_framebuffer_bind(dfbl->default_fb); \
119 DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color, true); \
120 DRW_stats_query_end(); \
124 #define MULTISAMPLE_SYNC_DISABLE_NO_DEPTH(dfbl, dtxl) { \
125 if (dfbl->multisample_fb != NULL) { \
126 DRW_stats_query_start("Multisample Resolve"); \
127 GPU_framebuffer_bind(dfbl->default_fb); \
128 DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color, false); \
129 DRW_stats_query_end(); \
136 typedef struct DrawEngineDataSize {
141 } DrawEngineDataSize;
143 typedef struct DrawEngineType {
144 struct DrawEngineType *next, *prev;
148 const DrawEngineDataSize *vedata_size;
150 void (*engine_init)(void *vedata);
151 void (*engine_free)(void);
153 void (*cache_init)(void *vedata);
154 void (*cache_populate)(void *vedata, struct Object *ob);
155 void (*cache_finish)(void *vedata);
157 void (*draw_background)(void *vedata);
158 void (*draw_scene)(void *vedata);
160 void (*view_update)(void *vedata);
161 void (*id_update)(void *vedata, struct ID *id);
163 void (*render_to_image)(
164 void *vedata, struct RenderEngine *engine,
165 struct RenderLayer *layer, const struct rcti *rect);
168 #ifndef __DRW_ENGINE_H__
169 /* Buffer and textures used by the viewport by default */
170 typedef struct DefaultFramebufferList {
171 struct GPUFrameBuffer *default_fb;
172 struct GPUFrameBuffer *color_only_fb;
173 struct GPUFrameBuffer *depth_only_fb;
174 struct GPUFrameBuffer *multisample_fb;
175 } DefaultFramebufferList;
177 typedef struct DefaultTextureList {
178 struct GPUTexture *color;
179 struct GPUTexture *depth;
180 struct GPUTexture *multisample_color;
181 struct GPUTexture *multisample_depth;
182 } DefaultTextureList;
187 DRW_TEX_FILTER = (1 << 0),
188 DRW_TEX_WRAP = (1 << 1),
189 DRW_TEX_COMPARE = (1 << 2),
190 DRW_TEX_MIPMAP = (1 << 3),
193 /* Textures from DRW_texture_pool_query_* have the options
194 * DRW_TEX_FILTER for color float textures, and no options
195 * for depth textures and integer textures. */
196 struct GPUTexture *DRW_texture_pool_query_2D(int w, int h, eGPUTextureFormat format, DrawEngineType *engine_type);
198 struct GPUTexture *DRW_texture_create_1D(
199 int w, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
200 struct GPUTexture *DRW_texture_create_2D(
201 int w, int h, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
202 struct GPUTexture *DRW_texture_create_2D_array(
203 int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
204 struct GPUTexture *DRW_texture_create_3D(
205 int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
206 struct GPUTexture *DRW_texture_create_cube(
207 int w, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
209 void DRW_texture_ensure_fullscreen_2D(
210 struct GPUTexture **tex, eGPUTextureFormat format, DRWTextureFlag flags);
211 void DRW_texture_ensure_2D(
212 struct GPUTexture **tex, int w, int h, eGPUTextureFormat format, DRWTextureFlag flags);
214 void DRW_texture_generate_mipmaps(struct GPUTexture *tex);
215 void DRW_texture_free(struct GPUTexture *tex);
216 #define DRW_TEXTURE_FREE_SAFE(tex) do { \
218 DRW_texture_free(tex); \
224 struct GPUUniformBuffer *DRW_uniformbuffer_create(int size, const void *data);
225 void DRW_uniformbuffer_update(struct GPUUniformBuffer *ubo, const void *data);
226 void DRW_uniformbuffer_free(struct GPUUniformBuffer *ubo);
227 #define DRW_UBO_FREE_SAFE(ubo) do { \
229 DRW_uniformbuffer_free(ubo); \
234 void DRW_transform_to_display(struct GPUTexture *tex, bool use_view_transform, bool use_render_settings);
235 void DRW_transform_none(struct GPUTexture *tex);
236 void DRW_multisamples_resolve(
237 struct GPUTexture *src_depth, struct GPUTexture *src_color, bool use_depth);
240 struct GPUShader *DRW_shader_create(
241 const char *vert, const char *geom, const char *frag, const char *defines);
242 struct GPUShader *DRW_shader_create_with_lib(
243 const char *vert, const char *geom, const char *frag, const char *lib, const char *defines);
244 struct GPUShader *DRW_shader_create_with_transform_feedback(
245 const char *vert, const char *geom, const char *defines,
246 const eGPUShaderTFBType prim_type, const char **varying_names, const int varying_count);
247 struct GPUShader *DRW_shader_create_2D(const char *frag, const char *defines);
248 struct GPUShader *DRW_shader_create_3D(const char *frag, const char *defines);
249 struct GPUShader *DRW_shader_create_fullscreen(const char *frag, const char *defines);
250 struct GPUShader *DRW_shader_create_3D_depth_only(eGPUShaderConfig slot);
251 struct GPUMaterial *DRW_shader_find_from_world(struct World *wo, const void *engine_type, int options, bool deferred);
252 struct GPUMaterial *DRW_shader_find_from_material(struct Material *ma, const void *engine_type, int options, bool deferred);
253 struct GPUMaterial *DRW_shader_create_from_world(
254 struct Scene *scene, struct World *wo, const void *engine_type, int options,
255 const char *vert, const char *geom, const char *frag_lib, const char *defines, bool deferred);
256 struct GPUMaterial *DRW_shader_create_from_material(
257 struct Scene *scene, struct Material *ma, const void *engine_type, int options,
258 const char *vert, const char *geom, const char *frag_lib, const char *defines, bool deferred);
259 void DRW_shader_free(struct GPUShader *shader);
260 #define DRW_SHADER_FREE_SAFE(shader) do { \
261 if (shader != NULL) { \
262 DRW_shader_free(shader); \
270 DRW_STATE_WRITE_DEPTH = (1 << 0),
271 DRW_STATE_WRITE_COLOR = (1 << 1),
272 DRW_STATE_DEPTH_ALWAYS = (1 << 2),
273 DRW_STATE_DEPTH_LESS = (1 << 3),
274 DRW_STATE_DEPTH_LESS_EQUAL = (1 << 4),
275 DRW_STATE_DEPTH_EQUAL = (1 << 5),
276 DRW_STATE_DEPTH_GREATER = (1 << 6),
277 DRW_STATE_DEPTH_GREATER_EQUAL = (1 << 7),
278 DRW_STATE_CULL_BACK = (1 << 8),
279 DRW_STATE_CULL_FRONT = (1 << 9),
280 DRW_STATE_WIRE = (1 << 10),
281 DRW_STATE_POINT = (1 << 11),
282 /** Polygon offset. Does not work with lines and points. */
283 DRW_STATE_OFFSET_POSITIVE = (1 << 12),
284 /** Polygon offset. Does not work with lines and points. */
285 DRW_STATE_OFFSET_NEGATIVE = (1 << 13),
286 DRW_STATE_WIRE_WIDE = (1 << 14),
287 DRW_STATE_BLEND = (1 << 15),
288 DRW_STATE_ADDITIVE = (1 << 16),
289 DRW_STATE_MULTIPLY = (1 << 17),
290 /* DRW_STATE_TRANSMISSION = (1 << 18), */ /* Not used */
291 DRW_STATE_CLIP_PLANES = (1 << 19),
292 /** Same as DRW_STATE_ADDITIVE but let alpha accumulate without premult. */
293 DRW_STATE_ADDITIVE_FULL = (1 << 20),
294 /** Use that if color is already premult by alpha. */
295 DRW_STATE_BLEND_PREMUL = (1 << 21),
296 DRW_STATE_WIRE_SMOOTH = (1 << 22),
297 DRW_STATE_TRANS_FEEDBACK = (1 << 23),
298 DRW_STATE_BLEND_OIT = (1 << 24),
299 DRW_STATE_FIRST_VERTEX_CONVENTION = (1 << 25),
301 DRW_STATE_WRITE_STENCIL = (1 << 27),
302 DRW_STATE_WRITE_STENCIL_SHADOW_PASS = (1 << 28),
303 DRW_STATE_WRITE_STENCIL_SHADOW_FAIL = (1 << 29),
304 DRW_STATE_STENCIL_EQUAL = (1 << 30),
305 DRW_STATE_STENCIL_NEQUAL = (1 << 31),
307 #define DRW_STATE_DEFAULT (DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL)
314 typedef struct DRWInstanceAttrFormat {
318 } DRWInstanceAttrFormat;
320 struct GPUVertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttrFormat attrs[], int arraysize);
321 #define DRW_shgroup_instance_format(format, ...) do { \
322 if (format == NULL) { \
323 DRWInstanceAttrFormat drw_format[] = __VA_ARGS__;\
324 format = DRW_shgroup_instance_format_array(drw_format, (sizeof(drw_format) / sizeof(DRWInstanceAttrFormat))); \
328 DRWShadingGroup *DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass);
329 DRWShadingGroup *DRW_shgroup_create_sub(DRWShadingGroup *shgroup);
330 DRWShadingGroup *DRW_shgroup_material_create(struct GPUMaterial *material, DRWPass *pass);
331 DRWShadingGroup *DRW_shgroup_material_instance_create(
332 struct GPUMaterial *material, DRWPass *pass, struct GPUBatch *geom, struct Object *ob,
333 struct GPUVertFormat *format);
334 DRWShadingGroup *DRW_shgroup_material_empty_tri_batch_create(struct GPUMaterial *material, DRWPass *pass, int size);
335 DRWShadingGroup *DRW_shgroup_instance_create(
336 struct GPUShader *shader, DRWPass *pass, struct GPUBatch *geom, struct GPUVertFormat *format);
337 DRWShadingGroup *DRW_shgroup_point_batch_create(struct GPUShader *shader, DRWPass *pass);
338 DRWShadingGroup *DRW_shgroup_line_batch_create_with_format(
339 struct GPUShader *shader, DRWPass *pass, struct GPUVertFormat *format);
340 DRWShadingGroup *DRW_shgroup_line_batch_create(
341 struct GPUShader *shader, DRWPass *pass);
342 DRWShadingGroup *DRW_shgroup_empty_tri_batch_create(
343 struct GPUShader *shader, DRWPass *pass, int size);
344 DRWShadingGroup *DRW_shgroup_transform_feedback_create(
345 struct GPUShader *shader, DRWPass *pass, struct GPUVertBuf *tf_target);
348 typedef void (DRWCallGenerateFn)(
349 DRWShadingGroup *shgroup,
350 void (*draw_fn)(DRWShadingGroup *shgroup, struct GPUBatch *geom),
353 /* return final visibility */
354 typedef bool (DRWCallVisibilityFn)(
358 void DRW_shgroup_instance_batch(DRWShadingGroup *shgroup, struct GPUBatch *batch);
360 void DRW_shgroup_call_add(DRWShadingGroup *shgroup, struct GPUBatch *geom, float (*obmat)[4]);
361 void DRW_shgroup_call_range_add(
362 DRWShadingGroup *shgroup, struct GPUBatch *geom, float (*obmat)[4], uint v_sta, uint v_count);
363 void DRW_shgroup_call_procedural_points_add(DRWShadingGroup *shgroup, uint point_len, float (*obmat)[4]);
364 void DRW_shgroup_call_procedural_lines_add(DRWShadingGroup *shgroup, uint line_count, float (*obmat)[4]);
365 void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup, uint tria_count, float (*obmat)[4]);
366 void DRW_shgroup_call_object_procedural_triangles_culled_add(DRWShadingGroup *shgroup, uint tria_count, struct Object *ob);
367 void DRW_shgroup_call_object_add_ex(
368 DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, struct Material *ma, bool bypass_culling);
369 #define DRW_shgroup_call_object_add(shgroup, geom, ob) DRW_shgroup_call_object_add_ex(shgroup, geom, ob, NULL, false)
370 #define DRW_shgroup_call_object_add_no_cull(shgroup, geom, ob) DRW_shgroup_call_object_add_ex(shgroup, geom, ob, NULL, true)
371 void DRW_shgroup_call_object_add_with_callback(
372 DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, struct Material *ma,
373 DRWCallVisibilityFn *callback, void *user_data);
374 /* Used for drawing a batch with instancing without instance attributes. */
375 void DRW_shgroup_call_instances_add(
376 DRWShadingGroup *shgroup, struct GPUBatch *geom, float (*obmat)[4], uint *count);
377 void DRW_shgroup_call_object_instances_add(
378 DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, uint *count);
379 void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shgroup, struct Object *ob, float (*obmat)[4]);
380 void DRW_shgroup_call_generate_add(
381 DRWShadingGroup *shgroup, DRWCallGenerateFn *geometry_fn, void *user_data, float (*obmat)[4]);
382 void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *attr[], uint attr_len);
383 #define DRW_shgroup_call_dynamic_add(shgroup, ...) do { \
384 const void *array[] = {__VA_ARGS__}; \
385 DRW_shgroup_call_dynamic_add_array(shgroup, array, (sizeof(array) / sizeof(*array))); \
388 uint DRW_shgroup_get_instance_count(const DRWShadingGroup *shgroup);
390 void DRW_shgroup_state_enable(DRWShadingGroup *shgroup, DRWState state);
391 void DRW_shgroup_state_disable(DRWShadingGroup *shgroup, DRWState state);
392 void DRW_shgroup_stencil_mask(DRWShadingGroup *shgroup, uint mask);
394 void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const struct GPUTexture *tex);
395 void DRW_shgroup_uniform_texture_persistent(DRWShadingGroup *shgroup, const char *name, const struct GPUTexture *tex);
396 void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const struct GPUUniformBuffer *ubo);
397 void DRW_shgroup_uniform_block_persistent(DRWShadingGroup *shgroup, const char *name, const struct GPUUniformBuffer *ubo);
398 void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, struct GPUTexture **tex);
399 void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
400 void DRW_shgroup_uniform_vec2(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
401 void DRW_shgroup_uniform_vec3(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
402 void DRW_shgroup_uniform_vec4(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
403 void DRW_shgroup_uniform_short_to_int(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize);
404 void DRW_shgroup_uniform_short_to_float(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize);
405 /* Boolean are expected to be 4bytes longs for opengl! */
406 void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
407 void DRW_shgroup_uniform_int(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
408 void DRW_shgroup_uniform_ivec2(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
409 void DRW_shgroup_uniform_ivec3(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
410 void DRW_shgroup_uniform_ivec4(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
411 void DRW_shgroup_uniform_mat3(DRWShadingGroup *shgroup, const char *name, const float (*value)[3]);
412 void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const float (*value)[4]);
413 /* Store value instead of referencing it. */
414 void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value);
415 void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value);
416 void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value);
418 bool DRW_shgroup_is_empty(DRWShadingGroup *shgroup);
421 DRWPass *DRW_pass_create(const char *name, DRWState state);
422 void DRW_pass_state_set(DRWPass *pass, DRWState state);
423 void DRW_pass_state_add(DRWPass *pass, DRWState state);
424 void DRW_pass_state_remove(DRWPass *pass, DRWState state);
425 void DRW_pass_foreach_shgroup(DRWPass *pass, void (*callback)(void *userData, DRWShadingGroup *shgrp), void *userData);
426 void DRW_pass_sort_shgroup_z(DRWPass *pass);
428 bool DRW_pass_is_empty(DRWPass *pass);
432 /* keep in sync with the union struct DRWMatrixState. */
440 DRW_MAT_COUNT, // Don't use this.
441 } DRWViewportMatrixType;
443 typedef struct DRWMatrixState {
445 float mat[DRW_MAT_COUNT][4][4];
447 /* keep in sync with the enum DRWViewportMatrixType. */
458 void DRW_viewport_matrix_get(float mat[4][4], DRWViewportMatrixType type);
459 void DRW_viewport_matrix_get_all(DRWMatrixState *state);
460 void DRW_viewport_matrix_override_set(const float mat[4][4], DRWViewportMatrixType type);
461 void DRW_viewport_matrix_override_set_all(DRWMatrixState *state);
462 void DRW_viewport_matrix_override_unset(DRWViewportMatrixType type);
463 void DRW_viewport_matrix_override_unset_all(void);
465 /* These are in view-space so negative if in perspective.
466 * Extract near and far clip distance from the projection matrix. */
467 float DRW_viewport_near_distance_get(void);
468 float DRW_viewport_far_distance_get(void);
470 const float *DRW_viewport_size_get(void);
471 const float *DRW_viewport_invert_size_get(void);
472 const float *DRW_viewport_screenvecs_get(void);
473 const float *DRW_viewport_pixelsize_get(void);
474 bool DRW_viewport_is_persp_get(void);
476 struct DefaultFramebufferList *DRW_viewport_framebuffer_list_get(void);
477 struct DefaultTextureList *DRW_viewport_texture_list_get(void);
479 void DRW_viewport_request_redraw(void);
481 void DRW_render_to_image(struct RenderEngine *engine, struct Depsgraph *depsgraph);
482 void DRW_render_object_iter(
483 void *vedata, struct RenderEngine *engine, struct Depsgraph *depsgraph,
484 void (*callback)(void *vedata, struct Object *ob, struct RenderEngine *engine, struct Depsgraph *depsgraph));
485 void DRW_render_instance_buffer_finish(void);
486 void DRW_render_viewport_size_set(int size[2]);
488 void DRW_custom_pipeline(
489 DrawEngineType *draw_engine_type,
490 struct Depsgraph *depsgraph,
491 void (*callback)(void *vedata, void *user_data),
495 void *DRW_view_layer_engine_data_get(DrawEngineType *engine_type);
496 void **DRW_view_layer_engine_data_ensure_ex(
497 struct ViewLayer *view_layer, DrawEngineType *engine_type, void (*callback)(void *storage));
498 void **DRW_view_layer_engine_data_ensure(
499 DrawEngineType *engine_type, void (*callback)(void *storage));
502 DrawData *DRW_drawdata_get(ID *ib, DrawEngineType *engine_type);
503 DrawData *DRW_drawdata_ensure(
505 DrawEngineType *engine_type,
507 DrawDataInitCb init_cb,
508 DrawDataFreeCb free_cb);
511 bool DRW_object_is_renderable(const struct Object *ob);
512 int DRW_object_visibility_in_active_context(const struct Object *ob);
513 bool DRW_object_is_flat_normal(const struct Object *ob);
514 bool DRW_object_use_hide_faces(const struct Object *ob);
516 bool DRW_object_is_visible_psys_in_active_context(const struct Object *object, const struct ParticleSystem *psys);
518 struct Object *DRW_object_get_dupli_parent(const struct Object *ob);
519 struct DupliObject *DRW_object_get_dupli(const struct Object *ob);
522 void DRW_draw_pass(DRWPass *pass);
523 void DRW_draw_pass_subset(DRWPass *pass, DRWShadingGroup *start_group, DRWShadingGroup *end_group);
525 void DRW_draw_callbacks_pre_scene(void);
526 void DRW_draw_callbacks_post_scene(void);
528 void DRW_state_reset_ex(DRWState state);
529 void DRW_state_reset(void);
530 void DRW_state_lock(DRWState state);
532 void DRW_state_invert_facing(void);
534 void DRW_state_clip_planes_len_set(uint plane_len);
535 void DRW_state_clip_planes_reset(void);
536 void DRW_state_clip_planes_set_from_rv3d(struct RegionView3D *rv3d);
538 /* Culling, return true if object is inside view frustum. */
539 bool DRW_culling_sphere_test(BoundSphere *bsphere);
540 bool DRW_culling_box_test(BoundBox *bbox);
541 bool DRW_culling_plane_test(float plane[4]);
543 void DRW_culling_frustum_corners_get(BoundBox *corners);
544 void DRW_culling_frustum_planes_get(float planes[6][4]);
547 void DRW_select_load_id(uint id);
550 void DRW_state_dfdy_factors_get(float dfdyfac[2]);
551 bool DRW_state_is_fbo(void);
552 bool DRW_state_is_select(void);
553 bool DRW_state_is_depth(void);
554 bool DRW_state_is_image_render(void);
555 bool DRW_state_is_scene_render(void);
556 bool DRW_state_is_opengl_render(void);
557 bool DRW_state_is_playback(void);
558 bool DRW_state_show_text(void);
559 bool DRW_state_draw_support(void);
560 bool DRW_state_draw_background(void);
562 /* Avoid too many lookups while drawing */
563 typedef struct DRWContextState {
565 struct ARegion *ar; /* 'CTX_wm_region(C)' */
566 struct RegionView3D *rv3d; /* 'CTX_wm_region_view3d(C)' */
567 struct View3D *v3d; /* 'CTX_wm_view3d(C)' */
569 struct Scene *scene; /* 'CTX_data_scene(C)' */
570 struct ViewLayer *view_layer; /* 'CTX_data_view_layer(C)' */
572 /* Use 'object_edit' for edit-mode */
573 struct Object *obact; /* 'OBACT' */
575 struct RenderEngineType *engine_type;
577 struct Depsgraph *depsgraph;
579 eObjectMode object_mode;
581 eGPUShaderConfig sh_cfg;
583 /** Last resort (some functions take this as an arg so we can't easily avoid).
584 * May be NULL when used for selection or depth buffer. */
585 const struct bContext *evil_C;
589 /* Cache: initialized by 'drw_context_state_init'. */
590 struct Object *object_pose;
591 struct Object *object_edit;
595 const DRWContextState *DRW_context_state_get(void);
597 #define XRAY_ALPHA(v3d) (((v3d)->shading.type == OB_WIRE) ? (v3d)->shading.xray_alpha_wire : (v3d)->shading.xray_alpha)
598 #define XRAY_FLAG(v3d) (((v3d)->shading.type == OB_WIRE) ? V3D_SHADING_XRAY_BONE : V3D_SHADING_XRAY)
599 #define XRAY_ENABLED(v3d) ((((v3d)->shading.flag & XRAY_FLAG(v3d)) != 0) && (XRAY_ALPHA(v3d) < 1.0f))
601 #endif /* __DRW_RENDER_H__ */