Blender V5.3
draw_cache_inline.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#pragma once
10
11#include "GPU_batch.hh"
12#include "GPU_ray_tracing.hh"
13
14namespace blender {
15
16/* Common */
17// #define DRW_DEBUG_MESH_CACHE_REQUEST
18
19#ifdef DRW_DEBUG_MESH_CACHE_REQUEST
20# define DRW_ADD_FLAG_FROM_VBO_REQUEST(flag, vbo, value) \
21 (flag |= DRW_vbo_requested(vbo) ? (printf(" VBO requested " #vbo "\n") ? value : value) : 0)
22# define DRW_ADD_FLAG_FROM_IBO_REQUEST(flag, ibo, value) \
23 (flag |= DRW_ibo_requested(ibo) ? (printf(" IBO requested " #ibo "\n") ? value : value) : 0)
24#else
25# define DRW_ADD_FLAG_FROM_VBO_REQUEST(flag, vbo, value) \
26 (flag |= DRW_vbo_requested(vbo) ? (value) : 0)
27# define DRW_ADD_FLAG_FROM_IBO_REQUEST(flag, ibo, value) \
28 (flag |= DRW_ibo_requested(ibo) ? (value) : 0)
29#endif
30
31inline gpu::Batch *DRW_batch_request(gpu::Batch **batch)
32{
33 /* XXX TODO(fclem): We are writing to batch cache here. Need to make this thread safe. */
34 if (*batch == nullptr) {
35 *batch = GPU_batch_calloc();
36 }
37 return *batch;
38}
39
40inline bool DRW_batch_requested(gpu::Batch *batch, GPUPrimType prim_type)
41{
42 /* Batch has been requested if it has been created but not initialized. */
43 if (batch != nullptr && batch->verts[0] == nullptr) {
44 /* HACK. We init without a valid VBO and let the first vbo binding
45 * fill verts[0]. */
47 batch, prim_type, reinterpret_cast<gpu::VertBuf *>(1), nullptr, GPUBatchFlag(0));
48 batch->verts[0] = nullptr;
49 return true;
50 }
51 return false;
52}
53
54inline void DRW_ibo_request(gpu::Batch *batch, gpu::IndexBuf **ibo)
55{
56 if (*ibo == nullptr) {
57 *ibo = GPU_indexbuf_calloc();
58 }
59 if (batch != nullptr) {
60 GPU_batch_elembuf_set(batch, *ibo, false);
61 }
62}
63
65{
66 /* TODO: do not rely on data uploaded. This prevents multi-threading.
67 * (need access to a GPU context). */
68 return (ibo != nullptr && !GPU_indexbuf_is_init(ibo));
69}
70
71inline void DRW_vbo_request(gpu::Batch *batch, gpu::VertBuf **vbo)
72{
73 if (*vbo == nullptr) {
74 *vbo = GPU_vertbuf_calloc();
75 }
76 if (batch != nullptr) {
77 BLI_assert_msg(batch->procedural_vertices == -1,
78 "Request of vertex buffer for procedural batch is not valid operation.");
79 /* HACK we set VBO's that may not yet be valid. */
80 GPU_batch_vertbuf_add(batch, *vbo, false);
81 }
82}
83
85{
86 return (vbo != nullptr && (GPU_vertbuf_get_status(vbo) & GPU_VERTBUF_INIT) == 0);
87}
88
90{
91 if (*blas == nullptr) {
92 *blas = GPU_ray_tracing_blas_alloc(__func__);
93 }
94}
95
96} // namespace blender
blender::gpu::BottomLevelAS * GPU_ray_tracing_blas_alloc(const char *name)
#define BLI_assert_msg(a, msg)
BMesh Iterators.
bool GPU_indexbuf_is_init(gpu::IndexBuf *elem)
bool DRW_vbo_requested(gpu::VertBuf *vbo)
gpu::Batch * GPU_batch_calloc()
Definition gpu_batch.cc:46
bool DRW_batch_requested(gpu::Batch *batch, GPUPrimType prim_type)
void DRW_blas_request(gpu::BottomLevelAS **blas)
GPUVertBufStatus GPU_vertbuf_get_status(const gpu::VertBuf *verts)
void DRW_ibo_request(gpu::Batch *batch, gpu::IndexBuf **ibo)
gpu::VertBuf * GPU_vertbuf_calloc()
void GPU_batch_init_ex(gpu::Batch *batch, GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
gpu::IndexBuf * GPU_indexbuf_calloc()
gpu::Batch * DRW_batch_request(gpu::Batch **batch)
void GPU_batch_elembuf_set(gpu::Batch *batch, gpu::IndexBuf *index_buf, bool own_ibo)
void DRW_vbo_request(gpu::Batch *batch, gpu::VertBuf **vbo)
int GPU_batch_vertbuf_add(gpu::Batch *batch, gpu::VertBuf *vertex_buf, bool own_vbo)
bool DRW_ibo_requested(gpu::IndexBuf *ibo)