aboutsummaryrefslogtreecommitdiff
path: root/include/RenderBackend/OpenGL/ShaderVec.hpp
blob: 4353dd7e175a866be62d72cee5384302a65f00a4 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once

#include "../../types.hpp"
#include "../../RenderBackend/OpenGL/DeviceMemory.hpp"
#include <string>

namespace amalgine
{
    class Shader;
    class ShaderProgram;
    
    enum class AttributeType
    {
        NONE,
        VEC2,
        VEC3,
        VEC4
    };
    
    AttributeType getAttributeTypeByName(const char *attributeName);
    
    class ShaderGlobalVec
    {
        friend class Shader;
        friend class ShaderGlobalVec3;
    public:
        ShaderGlobalVec() : attributeType(AttributeType::NONE) {}
        const std::string& getName() const { return name; }
        AttributeType getAttributeType() const { return attributeType; }
    protected:
        ShaderGlobalVec(const std::string &_name, AttributeType _attributeType) : name(_name), attributeType(_attributeType) {}
    private:
        std::string name;
        AttributeType attributeType;
    };
    
    class ShaderGlobalVec3
    {
        friend class Shader;
    public:
        const std::string& getName() const { return globalVec.getName(); }
        AttributeType getAttributeType() const { return globalVec.getAttributeType(); }
        ShaderGlobalVec getVecObject() const { return globalVec; }
    private:
        ShaderGlobalVec3(const std::string &_name) : globalVec(_name, AttributeType::VEC3) {}
    private:
        ShaderGlobalVec globalVec;
    };
    
    class ShaderProgramGlobalVec3
    {
        friend class ShaderProgram;
    public:
        void set(f32 x = 0.0f, f32 y = 0.0f, f32 z = 0.0f);
    private:
        ShaderProgramGlobalVec3(ShaderProgram *_shaderProgram, i32 _uniformId) : shaderProgram(_shaderProgram), uniformId(_uniformId){}
    private:
        ShaderProgram *shaderProgram;
        i32 uniformId;
    };
    
    class ShaderInputVec2
    {
        friend class Shader;
    public:
        const std::string& getName() const;
        void setData(const DeviceMemory &data);
    private:
        ShaderInputVec2(Shader *_shader, i32 _attributeIndex) : 
            shader(_shader), 
            attributeIndex(_attributeIndex)
        {
            
        }
    private:
        Shader *shader;
        i32 attributeIndex;
    };
    
    class ShaderVec4
    {
    public:
        ShaderVec4(f32 x = 0.0f, f32 y = 0.0f, f32 z = 0.0f, f32 w = 0.0f)
        {
            result = "vec4(";
            result += std::to_string(x);
            result += ", ";
            result += std::to_string(y);
            result += ", ";
            result += std::to_string(z);
            result += ", ";
            result += std::to_string(w);
            result += ")";
        }
        
        ShaderVec4(const ShaderInputVec2 &vec2, f32 z = 0.0f, f32 w = 0.0f)
        {
            result = "vec4(";
            result += vec2.getName();
            result += ", ";
            result += std::to_string(z);
            result += ", ";
            result += std::to_string(w);
            result += ")";
        }
        
        ShaderVec4(const ShaderGlobalVec3 &vec3, f32 w = 0.0f)
        {
            result = "vec4(";
            result += vec3.getName();
            result += ", ";
            result += std::to_string(w);
            result += ")";
        }
        
        const std::string& getOutput() const
        {
            return result;
        }
    private:
        std::string result;
    };
    
    class ShaderOutputVec4
    {
        friend class Shader;
    public:
        const std::string& getName() const;
        
        void operator=(const ShaderVec4 &shaderVec4);
    private:
        ShaderOutputVec4(Shader *_shader, i32 _attributeIndex) : 
            shader(_shader), 
            attributeIndex(_attributeIndex)
        {
            
        }
    private:
        Shader *shader;
        i32 attributeIndex;
    };
}