CSEngine
Loading...
Searching...
No Matches
GLProgramHandle.h
1#pragma once
2
3#include "../OGLDef.h"
4#include "../Object/SResource.h"
5#include "../Manager/ResMgr.h"
6#include "Matrix.h"
7
8#include <map>
9
10#define HANDLE_NULL -1
11
12namespace CSE {
14 GLint ViewMatrix = HANDLE_NULL;
15 GLint ModelMatrix = HANDLE_NULL;
16 GLint ProjectionMatrix = HANDLE_NULL;
17 GLint ViewInvMatrix = HANDLE_NULL;
18 GLint ProjectionInvMatrix = HANDLE_NULL;
19 GLint CameraPosition = HANDLE_NULL;
20 // Light
21 GLint LightPosition = HANDLE_NULL;
22 GLint LightType = HANDLE_NULL;
23 GLint LightRadius = HANDLE_NULL;
24 GLint LightColor = HANDLE_NULL;
25 GLint LightShadowMap = HANDLE_NULL;
26 GLint LightMatrix = HANDLE_NULL;
27 GLint LightShadowMode = HANDLE_NULL;
28 GLint LightSize = HANDLE_NULL;
29 GLint LightIrradiance = HANDLE_NULL;
30 GLint LightPrefilter = HANDLE_NULL;
31 GLint LightBrdfLut = HANDLE_NULL;
32 // Skinning
33 GLint JointMatrix = HANDLE_NULL;
34 GLint SkinningMode = HANDLE_NULL;
35 // Buffers
36 GLint SourceBuffer = HANDLE_NULL;
37 GLint SourceBufferSize = HANDLE_NULL;
38 // SDFs
39 GLint SdfEnvSize = HANDLE_NULL;
40 GLint SdfCellSize = HANDLE_NULL;
41 GLint SdfNodeSize = HANDLE_NULL;
42 GLint SdfNodeSpace = HANDLE_NULL;
43 GLint SdfFrameCount = HANDLE_NULL;
44 GLint SdfMap = HANDLE_NULL;
45 };
46
48 GLint Position = HANDLE_NULL;
49 GLint Color = HANDLE_NULL;
50 GLint Normal = HANDLE_NULL;
51// GLint DiffuseMaterial = HANDLE_NULL;
52 GLint TextureCoord = HANDLE_NULL;
53 GLint Weight = HANDLE_NULL;
54 GLint JointId = HANDLE_NULL;
55 };
56
57 class GLProgramHandle : public SResource {
58 public:
59 struct Element {
60 GLenum type = 0;
61 int id = HANDLE_NULL;
62 };
63
64 typedef std::map<std::string, GLProgramHandle::Element*> GLElementList;
65 public:
66 RESOURCE_DEFINE_CONSTRUCTOR(GLProgramHandle);
67
68 ~GLProgramHandle() override;
69
70 void Exterminate() override;
71
72 void SetProgram(GLuint program) {
73 Program = program;
74 }
75
76 Element* AttributeLocation(const char* location) const {
77 auto pair = AttributesList.find(location);
78 return pair == AttributesList.end() ? nullptr : pair->second;
79 }
80
81 Element* UniformLocation(const char* location) const {
82 auto pair = UniformsList.find(location);
83 return pair == UniformsList.end() ? nullptr : pair->second;
84 }
85
86 void SetAttribVec3(const std::string& location, vec3& value);
87
88 void SetAttribVec4(const std::string& location, vec4& value);
89
90 void SetUniformInt(const std::string& location, int value);
91
92 void SetUniformFloat(const std::string& location, float value);
93
94 void SetUniformMat4(const std::string& location, mat4& value);
95
96 void SetUniformMat3(const std::string& location, mat3& value);
97
98 void SetAttributesList(std::map<std::string, std::string>& vert, std::map<std::string, std::string>& frag);
99
100 void SetUniformsList(std::map<std::string, std::string>& vert, std::map<std::string, std::string>& frag);
101
102 GLElementList GetAttributesList() const;
103
104 GLElementList GetUniformsList() const;
105
106 void SaveShader(const std::string& path);
107
108 void SetValue(std::string name_str, Arguments value) override;
109
110 std::string PrintValue() const override;
111
112 protected:
113 void Init(const AssetMgr::AssetReference* asset) override;
114
115 private:
116 static std::string getImplementName(std::map<std::string, std::string>& list, const std::string& name);
117
118 public:
119 GLuint Program;
120 GLAttributeHandles Attributes;
121 GLUniformHandles Uniforms;
122
123 GLElementList AttributesList;
124 GLElementList UniformsList;
125
126 GLuint CullFace = GL_BACK;
127 private:
128 std::string m_fragShaderName;
129 std::string m_vertShaderName;
130 };
131}
void SetValue(std::string name_str, Arguments value) override