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