Blender  V2.93
gl_vertex_buffer.hh
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 #pragma once
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "glew-mx.h"
29 
31 
32 namespace blender {
33 namespace gpu {
34 
35 class GLVertBuf : public VertBuf {
36  friend class GLTexture; /* For buffer texture. */
37  friend class GLShader; /* For transform feedback. */
38 
39  private:
41  GLuint vbo_id_ = 0;
43  size_t vbo_size_ = 0;
44 
45  public:
46  void bind(void);
47 
48  void update_sub(uint start, uint len, void *data) override;
49 
50  protected:
51  void acquire_data(void) override;
52  void resize_data(void) override;
53  void release_data(void) override;
54  void upload_data(void) override;
55  void duplicate_data(VertBuf *dst) override;
56 
58 };
59 
60 static inline GLenum to_gl(GPUUsageType type)
61 {
62  switch (type) {
63  case GPU_USAGE_STREAM:
64  return GL_STREAM_DRAW;
65  case GPU_USAGE_DYNAMIC:
66  return GL_DYNAMIC_DRAW;
67  case GPU_USAGE_STATIC:
68  return GL_STATIC_DRAW;
69  default:
70  BLI_assert(0);
71  return GL_STATIC_DRAW;
72  }
73 }
74 
75 static inline GLenum to_gl(GPUVertCompType type)
76 {
77  switch (type) {
78  case GPU_COMP_I8:
79  return GL_BYTE;
80  case GPU_COMP_U8:
81  return GL_UNSIGNED_BYTE;
82  case GPU_COMP_I16:
83  return GL_SHORT;
84  case GPU_COMP_U16:
85  return GL_UNSIGNED_SHORT;
86  case GPU_COMP_I32:
87  return GL_INT;
88  case GPU_COMP_U32:
89  return GL_UNSIGNED_INT;
90  case GPU_COMP_F32:
91  return GL_FLOAT;
92  case GPU_COMP_I10:
93  return GL_INT_2_10_10_10_REV;
94  default:
95  BLI_assert(0);
96  return GL_FLOAT;
97  }
98 }
99 
100 } // namespace gpu
101 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:58
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
GPUUsageType
@ GPU_USAGE_STATIC
@ GPU_USAGE_STREAM
@ GPU_USAGE_DYNAMIC
GPUVertCompType
@ GPU_COMP_U16
@ GPU_COMP_I10
@ GPU_COMP_F32
@ GPU_COMP_I32
@ GPU_COMP_I8
@ GPU_COMP_U32
@ GPU_COMP_I16
@ GPU_COMP_U8
Read Guarded memory(de)allocation.
void resize_data(void) override
void duplicate_data(VertBuf *dst) override
void acquire_data(void) override
void release_data(void) override
MEM_CXX_CLASS_ALLOC_FUNCS("GLVertBuf")
void upload_data(void) override
void update_sub(uint start, uint len, void *data) override
static GLenum to_gl(const GPUAttachmentType type)
uint len