Blender  V2.93
gl_index_buffer.cc
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  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "gl_context.hh"
25 #include "gl_debug.hh"
26 
27 #include "gl_index_buffer.hh"
28 
29 namespace blender::gpu {
30 
32 {
33  GLContext::buf_free(ibo_id_);
34 }
35 
37 {
38  if (is_subrange_) {
39  static_cast<GLIndexBuf *>(src_)->bind();
40  return;
41  }
42 
43  if (ibo_id_ == 0) {
44  glGenBuffers(1, &ibo_id_);
45 
46  if (data_ == nullptr) {
47  debug::raise_gl_error("Trying to use Index Buffer but the buffer contains no data");
48  }
49  }
50 
51  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id_);
52 
53  if (data_ != nullptr) {
54  size_t size = this->size_get();
55  /* Sends data to GPU. */
56  glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data_, GL_STATIC_DRAW);
57  /* No need to keep copy of data in system memory. */
59  }
60 }
61 
62 } // namespace blender::gpu
#define MEM_SAFE_FREE(v)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
static void buf_free(GLuint buf_id)
Definition: gl_context.cc:257
void raise_gl_error(const char *info)
Definition: gl_debug.cc:282