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 };
39
41 GLint Position = HANDLE_NULL;
42 GLint Color = HANDLE_NULL;
43 GLint Normal = HANDLE_NULL;
44// GLint DiffuseMaterial = HANDLE_NULL;
45 GLint TextureCoord = HANDLE_NULL;
46 GLint Weight = HANDLE_NULL;
47 GLint JointId = HANDLE_NULL;
48 };
49
50 class GLProgramHandle : public SResource {
51 public:
52 struct Element {
53 GLenum type = 0;
54 int id = HANDLE_NULL;
55 };
56
57 typedef std::map<std::string, GLProgramHandle::Element*> GLElementList;
58 public:
60
61 ~GLProgramHandle() override;
62
63 void Exterminate() override;
64
65 void SetProgram(GLuint program) {
66 Program = program;
67 }
68
69 Element* AttributeLocation(const char* location) const {
70 auto pair = AttributesList.find(location);
71 return pair == AttributesList.end() ? nullptr : pair->second;
72 }
73
74 Element* UniformLocation(const char* location) const {
75 auto pair = UniformsList.find(location);
76 return pair == UniformsList.end() ? nullptr : pair->second;
77 }
78
79 void SetAttribVec3(const std::string& location, vec3& value);
80
81 void SetAttribVec4(const std::string& location, vec4& value);
82
83 void SetUniformInt(const std::string& location, int value);
84
85 void SetUniformFloat(const std::string& location, float value);
86
87 void SetUniformMat4(const std::string& location, mat4& value);
88
89 void SetUniformMat3(const std::string& location, mat3& value);
90
91 void SetAttributesList(std::map<std::string, std::string>& vert, std::map<std::string, std::string>& frag);
92
93 void SetUniformsList(std::map<std::string, std::string>& vert, std::map<std::string, std::string>& frag);
94
95 GLElementList GetAttributesList() const;
96
97 GLElementList GetUniformsList() const;
98
99 void SaveShader(const std::string& path);
100
101 protected:
102 void Init(const AssetMgr::AssetReference* asset) override;
103
104 private:
105 static std::string getImplementName(std::map<std::string, std::string>& list, const std::string& name);
106
107 public:
108 GLuint Program;
109 GLAttributeHandles Attributes;
110 GLUniformHandles Uniforms;
111
112 GLElementList AttributesList;
113 GLElementList UniformsList;
114 private:
115 std::string m_fragShaderName;
116 std::string m_vertShaderName;
117 };
118}