Otclient  14/8/2020
hardwarebuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 
24 #ifndef HARDWAREBUFFER_H
25 #define HARDWAREBUFFER_H
26 
27 #include "declarations.h"
28 
30 {
31 public:
32  enum Type {
33  VertexBuffer = GL_ARRAY_BUFFER,
34  IndexBuffer = GL_ELEMENT_ARRAY_BUFFER
35  };
36 
37  enum UsagePattern {
38  StreamDraw = GL_STREAM_DRAW,
39  StaticDraw = GL_STATIC_DRAW,
40  DynamicDraw = GL_DYNAMIC_DRAW
41  };
42 
43  HardwareBuffer(Type type);
45 
46  void bind() { glBindBuffer(m_type, m_id); }
47  static void unbind(Type type) { glBindBuffer(type, 0); }
48  void write(void *data, int count, UsagePattern usage) { glBufferData(m_type, count, data, usage); }
49 
50 private:
51  Type m_type;
52  uint m_id;
53 };
54 
55 #endif
HardwareBuffer::DynamicDraw
@ DynamicDraw
Definition: hardwarebuffer.h:40
HardwareBuffer::bind
void bind()
Definition: hardwarebuffer.h:46
HardwareBuffer::StaticDraw
@ StaticDraw
Definition: hardwarebuffer.h:39
HardwareBuffer::write
void write(void *data, int count, UsagePattern usage)
Definition: hardwarebuffer.h:48
HardwareBuffer::unbind
static void unbind(Type type)
Definition: hardwarebuffer.h:47
HardwareBuffer::VertexBuffer
@ VertexBuffer
Definition: hardwarebuffer.h:33
HardwareBuffer::HardwareBuffer
HardwareBuffer(Type type)
Definition: hardwarebuffer.cpp:29
HardwareBuffer::UsagePattern
UsagePattern
Definition: hardwarebuffer.h:37
HardwareBuffer
Definition: hardwarebuffer.h:29
HardwareBuffer::StreamDraw
@ StreamDraw
Definition: hardwarebuffer.h:38
uint
unsigned int uint
Definition: types.h:31
HardwareBuffer::Type
Type
Definition: hardwarebuffer.h:32
HardwareBuffer::IndexBuffer
@ IndexBuffer
Definition: hardwarebuffer.h:34
declarations.h
HardwareBuffer::~HardwareBuffer
~HardwareBuffer()
Definition: hardwarebuffer.cpp:38