Blender  V3.3
draw_cache_inline.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 Blender Foundation. */
3 
8 #pragma once
9 
10 #include "GPU_batch.h"
11 #include "MEM_guardedalloc.h"
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 
29 {
30  /* XXX TODO(fclem): We are writing to batch cache here. Need to make this thread safe. */
31  if (*batch == NULL) {
33  }
34  return *batch;
35 }
36 
38 {
39  /* Batch has been requested if it has been created but not initialized. */
40  if (batch != NULL && batch->verts[0] == NULL) {
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, (GPUVertBuf *)1, NULL, (eGPUBatchFlag)0);
44  batch->verts[0] = NULL;
45  return true;
46  }
47  return false;
48 }
49 
51 {
52  if (*ibo == NULL) {
53  *ibo = GPU_indexbuf_calloc();
54  }
55  if (batch != NULL) {
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 OpenGL context). */
64  return (ibo != NULL && !GPU_indexbuf_is_init(ibo));
65 }
66 
68 {
69  if (*vbo == NULL) {
70  *vbo = GPU_vertbuf_calloc();
71  }
72  if (batch != NULL) {
73  /* HACK we set VBO's that may not yet be valid. */
75  }
76 }
77 
79 {
80  return (vbo != NULL && (GPU_vertbuf_get_status(vbo) & GPU_VERTBUF_INIT) == 0);
81 }
#define BLI_INLINE
GPUBatch * GPU_batch_calloc(void)
Definition: gpu_batch.cc:36
GPUBatch
Definition: GPU_batch.h:78
void GPU_batch_init_ex(GPUBatch *batch, GPUPrimType prim, GPUVertBuf *vert, GPUIndexBuf *elem, eGPUBatchFlag owns_flag)
Definition: gpu_batch.cc:53
void GPU_batch_elembuf_set(GPUBatch *batch, GPUIndexBuf *elem, bool own_ibo)
Definition: gpu_batch.cc:135
#define GPU_batch_vertbuf_add(batch, verts)
Definition: GPU_batch.h:124
eGPUBatchFlag
Definition: GPU_batch.h:25
struct GPUIndexBuf GPUIndexBuf
GPUIndexBuf * GPU_indexbuf_calloc(void)
bool GPU_indexbuf_is_init(GPUIndexBuf *elem)
GPUPrimType
Definition: GPU_primitive.h:18
struct GPUVertBuf GPUVertBuf
GPUVertBuf * GPU_vertbuf_calloc(void)
@ GPU_VERTBUF_INIT
GPUVertBufStatus GPU_vertbuf_get_status(const GPUVertBuf *verts)
Read Guarded memory(de)allocation.
BLI_INLINE void DRW_vbo_request(GPUBatch *batch, GPUVertBuf **vbo)
BLI_INLINE bool DRW_vbo_requested(GPUVertBuf *vbo)
BLI_INLINE void DRW_ibo_request(GPUBatch *batch, GPUIndexBuf **ibo)
BLI_INLINE bool DRW_ibo_requested(GPUIndexBuf *ibo)
BLI_INLINE bool DRW_batch_requested(GPUBatch *batch, GPUPrimType prim_type)
BLI_INLINE GPUBatch * DRW_batch_request(GPUBatch **batch)
struct @653::@655 batch