aboutsummaryrefslogtreecommitdiff
path: root/src/RenderBackend/OpenGL/ShaderVec.cpp
blob: dd3bbe530ca6e7af7a3364bbd5010306bc630ecb (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
51
52
53
54
55
56
57
58
59
60
61
#include "../../../include/RenderBackend/OpenGL/ShaderVec.hpp"
#include "../../../include/RenderBackend/OpenGL/VertexShader.hpp"
#include "../../../include/RenderBackend/OpenGL/PixelShader.hpp"
#include "../../../include/RenderBackend/OpenGL/ShaderProgram.hpp"
#include "../../../include/RenderBackend/OpenGL/opengl.hpp"
#include <cstring>
#include <cassert>

using namespace std;

namespace amalgine
{    
    AttributeType getAttributeTypeByName(const char *attributeName)
    {
        if(strncmp(attributeName, "vec2", 4) == 0)
        {
            return AttributeType::VEC2;
        }
        
        return AttributeType::NONE;
    }
    
    void ShaderProgramGlobalVec3::set(f32 x, f32 y, f32 z)
    {
        shaderProgram->use();
        glUniform3f(uniformId, x, y, z);
    }
    
    const string& ShaderInputVec2::getName() const
    {
        return vertexShader->getInputAttributeName(attributeIndex);
    }
    
    void ShaderInputVec2::setData(const DeviceMemory &data)
    {
        data.use();
        AttributeType attributeType = vertexShader->getInputAttributeType(attributeIndex);
        switch(attributeType)
        {
            case AttributeType::VEC2:
            {
                glVertexAttribPointer(attributeIndex, 2, GL_FLOAT, GL_FALSE, 0, 0);
                break;
            }
            default:
                assert(false);
                break;
        }
        glEnableVertexAttribArray(attributeIndex);
    }
    
    const string& ShaderOutputVec4::getName() const
    {
        return pixelShader->getOutputAttributeName(attributeIndex);
    }
    
    void ShaderOutputVec4::operator=(const ShaderVec4 &shaderVec4)
    {
        pixelShader->assign(*this, shaderVec4);
    }
}