aboutsummaryrefslogtreecommitdiff
path: root/src/RenderBackend/OpenGL/DeviceMemory.cpp
blob: 9e33ac9999b81b037fc1d61d1ffdee15fd4825c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "../../../include/RenderBackend/OpenGL/DeviceMemory.hpp"
#include "../../../include/RenderBackend/OpenGL/opengl.hpp"

namespace amalgine
{
    DeviceMemory::DeviceMemory()
    {
        glGenBuffers(1, &vertexBufferObjectId);
    }
    
    DeviceMemory::~DeviceMemory()
    {
        glDeleteBuffers(1, &vertexBufferObjectId);
    }
    
    void DeviceMemory::copyAsStatic(const DataView<f32> &data)
    {
        copy(data, GL_STATIC_DRAW);
    }
    
    void DeviceMemory::copyAsDynamic(const DataView<f32> &data)
    {
        copy(data, GL_DYNAMIC_DRAW);
    }
    
    void DeviceMemory::copyAsStream(const DataView<f32> &data)
    {
        copy(data, GL_STREAM_DRAW);
    }
    
    void DeviceMemory::copy(const DataView<f32> &data, i32 storageType)
    {
        glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId);
        glBufferData(GL_ARRAY_BUFFER, data.getByteSize(), data.data, storageType);
    }
}