aboutsummaryrefslogtreecommitdiff
path: root/include/RenderBackend/OpenGL/DeviceMemory.hpp
blob: 163b0ad2188a20b0cebd3b5dc10217cda9cf2988 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include "../../DataView.hpp"
#include "../../utils.hpp"
#include <stdexcept>

namespace amalgine
{
    class DeviceMemoryEmpty : public std::runtime_error
    {
    public:
        DeviceMemoryEmpty(const std::string &errMsg) : std::runtime_error(errMsg) {}
    };
    
    class DeviceMemory
    {
        DISABLE_COPY(DeviceMemory)
        friend class DeviceFrame;
        friend class ShaderInputVec4;
    public:
        enum class StorageType
        {
            // Uploaded once, drawn many times
            STATIC,
            
            // Created once, changed from time to time but drawn many times more than that
            DYNAMIC,
            
            // Uploaded once, drawn once (for example data that is changed every frame)
            STREAM
        };
        
        enum class PrimitiveType
        {
            TRIANGLE
        };
        
        ~DeviceMemory();
        void copy(const DataView<f32> &data, StorageType storageType, PrimitiveType primitiveType = PrimitiveType::TRIANGLE);
        void draw();
    private:
        DeviceMemory();
        void operator delete(void *data);
        void use() const;
    private:
        u32 vertexBufferObjectId;
        u32 primitiveType;
        u32 numVertices;
    };
}