Blender  V2.93
draw_cache_inline.h
Go to the documentation of this file.
1 /*
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.
6  *
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.
11  *
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.
15  *
16  * Copyright 2016, Blender Foundation.
17  */
18 
23 #pragma once
24 
25 #include "GPU_batch.h"
26 #include "MEM_guardedalloc.h"
27 
28 /* Common */
29 // #define DRW_DEBUG_MESH_CACHE_REQUEST
30 
31 #ifdef DRW_DEBUG_MESH_CACHE_REQUEST
32 # define DRW_ADD_FLAG_FROM_VBO_REQUEST(flag, vbo, value) \
33  (flag |= DRW_vbo_requested(vbo) ? (printf(" VBO requested " #vbo "\n") ? value : value) : 0)
34 # define DRW_ADD_FLAG_FROM_IBO_REQUEST(flag, ibo, value) \
35  (flag |= DRW_ibo_requested(ibo) ? (printf(" IBO requested " #ibo "\n") ? value : value) : 0)
36 #else
37 # define DRW_ADD_FLAG_FROM_VBO_REQUEST(flag, vbo, value) \
38  (flag |= DRW_vbo_requested(vbo) ? (value) : 0)
39 # define DRW_ADD_FLAG_FROM_IBO_REQUEST(flag, ibo, value) \
40  (flag |= DRW_ibo_requested(ibo) ? (value) : 0)
41 #endif
42 
43 /* Test and assign NULL if test fails */
44 #define DRW_TEST_ASSIGN_VBO(v) (v = (DRW_vbo_requested(v) ? (v) : NULL))
45 #define DRW_TEST_ASSIGN_IBO(v) (v = (DRW_ibo_requested(v) ? (v) : NULL))
46 
48 {
49  /* XXX TODO(fclem): We are writing to batch cache here. Need to make this thread safe. */
50  if (*batch == NULL) {
52  }
53  return *batch;
54 }
55 
57 {
58  /* Batch has been requested if it has been created but not initialized. */
59  if (batch != NULL && batch->verts[0] == NULL) {
60  /* HACK. We init without a valid VBO and let the first vbo binding
61  * fill verts[0]. */
62  GPU_batch_init_ex(batch, prim_type, (GPUVertBuf *)1, NULL, 0);
63  batch->verts[0] = NULL;
64  return true;
65  }
66  return false;
67 }
68 
70 {
71  if (*ibo == NULL) {
72  *ibo = GPU_indexbuf_calloc();
73  }
74  if (batch != NULL) {
75  GPU_batch_elembuf_set(batch, *ibo, false);
76  }
77 }
78 
80 {
81  /* TODO do not rely on data uploaded. This prevents multithreading.
82  * (need access to a gl context) */
83  return (ibo != NULL && !GPU_indexbuf_is_init(ibo));
84 }
85 
87 {
88  if (*vbo == NULL) {
89  *vbo = GPU_vertbuf_calloc();
90  }
91  if (batch != NULL) {
92  /* HACK we set vbos that may not yet be valid. */
94  }
95 }
96 
98 {
99  return (vbo != NULL && (GPU_vertbuf_get_status(vbo) & GPU_VERTBUF_INIT) == 0);
100 }
#define BLI_INLINE
GPUBatch * GPU_batch_calloc(void)
Definition: gpu_batch.cc:53
GPUBatch
Definition: GPU_batch.h:93
void GPU_batch_init_ex(GPUBatch *batch, GPUPrimType prim, GPUVertBuf *vert, GPUIndexBuf *elem, eGPUBatchFlag owns_flag)
Definition: gpu_batch.cc:70
void GPU_batch_elembuf_set(GPUBatch *batch, GPUIndexBuf *elem, bool own_ibo)
Definition: gpu_batch.cc:155
#define GPU_batch_vertbuf_add(batch, verts)
Definition: GPU_batch.h:121
struct GPUIndexBuf GPUIndexBuf
GPUIndexBuf * GPU_indexbuf_calloc(void)
bool GPU_indexbuf_is_init(GPUIndexBuf *elem)
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 bool DRW_batch_requested(GPUBatch *batch, int prim_type)
BLI_INLINE void DRW_ibo_request(GPUBatch *batch, GPUIndexBuf **ibo)
BLI_INLINE bool DRW_ibo_requested(GPUIndexBuf *ibo)
BLI_INLINE GPUBatch * DRW_batch_request(GPUBatch **batch)
GPUBatch * batch
Definition: drawnode.c:3779