aboutsummaryrefslogtreecommitdiff
path: root/src/RenderBackend/OpenGL/DeviceFrame.cpp
blob: 2132f830b3514e742db080159e7656f889b4dc96 (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
#include "../../../include/RenderBackend/OpenGL/DeviceFrame.hpp"
#include "../../../include/RenderBackend/OpenGL/DeviceMemory.hpp"
#include "../../../include/RenderBackend/OpenGL/opengl.hpp"
#include "../../../include/RenderBackend/OpenGL/ShaderProgram.hpp"

namespace amalgine
{
    DeviceFrame::DeviceFrame()
    {
        glGenVertexArrays(1, &vertexArrayObjectId);
    }
    
    DeviceFrame::~DeviceFrame()
    {
        for(DeviceMemory *deviceMemory : buffers)
        {
            delete deviceMemory;
        }
        glDeleteVertexArrays(1, &vertexArrayObjectId);
    }
    
    DeviceMemory* DeviceFrame::alloc()
    {
        glBindVertexArray(vertexArrayObjectId);
        DeviceMemory *deviceMemory = new DeviceMemory();
        buffers.push_back(deviceMemory);
        return deviceMemory;
    }
    
    void DeviceFrame::draw(ShaderProgram *shader) {
        shader->use();
        //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        for(DeviceMemory *deviceMemory : buffers)
        {
            deviceMemory->draw();
        }
        //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }
}