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