OpenBarnyard
 
Loading...
Searching...
No Matches
T2Shader_GL.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef TRENDERINTERFACE_GL
4
5# include "Toshi/TPString8.h"
6# include "Toshi/T2Map.h"
7# include "Math/TMatrix44.h"
8# include "Math/TVector4.h"
9# include "Math/TVector3.h"
10
11# include <GL/glew.h>
12# include <glm/ext.hpp>
13
14# include <immintrin.h>
15# include <intrin.h>
16
18
19//-----------------------------------------------------------------------------
20// Note: This is a custom class which is not the same as the one used in TOSHI 2.0
21// since it was never actually used in any games but in some tools like TXSViewer which
22// is not publicly available, so it's not possible to match this class.
23//-----------------------------------------------------------------------------
24
25class T2CompiledShader
26{
27public:
28 constexpr T2CompiledShader()
29 : m_uiId( 0 )
30 {}
31
32 constexpr T2CompiledShader( GLuint a_uiId )
33 : m_uiId( a_uiId )
34 {}
35
36 constexpr T2CompiledShader( const T2CompiledShader& a_rOther )
37 : m_uiId( a_rOther.m_uiId )
38 {}
39
40 constexpr GLuint GetId() const { return m_uiId; }
41
42 constexpr operator TBOOL() const { return m_uiId != 0; }
43
44private:
45 GLuint m_uiId;
46};
47
48//-----------------------------------------------------------------------------
49// Purpose: Holds references to vertex and fragment shaders forming OpenGL
50// shader program.
51//-----------------------------------------------------------------------------
52class T2Shader
53{
54public:
55 struct UniformMeta
56 {
57 GLint id;
58
59 union
60 {
61 TINT integer;
62 TUINT uInteger;
63 TMatrix44 mat44;
64 __m128 vec4;
65 TVector3 vec3;
66 FLOAT fp;
67 };
68
69 UniformMeta()
70 {}
71
72 UniformMeta( GLint a_iId )
73 : id( a_iId )
74 {}
75
76 UniformMeta( const UniformMeta& a_rcOther )
77 : id( a_rcOther.id )
78 , mat44( a_rcOther.mat44 )
79 {}
80 };
81
82public:
83 T2Shader()
84 : m_uiProgram( 0 ), m_VShader( 0 ), m_FShader( 0 )
85 {}
86
87 T2Shader( const T2CompiledShader& a_VShader, const T2CompiledShader& a_FShader )
88 : m_uiProgram( 0 ), m_VShader( a_VShader ), m_FShader( a_FShader )
89 {}
90
91 T2Shader( const T2Shader& a_rOther )
92 : m_uiProgram( a_rOther.m_uiProgram ), m_VShader( a_rOther.m_VShader ), m_FShader( a_rOther.m_FShader )
93 {}
94
95 TBOOL Create();
96 void Destroy( TBOOL a_bDeleteShaders );
97
98 UniformMeta& GetUniformSlotId( const TCHAR* a_szSlotName );
99 UniformMeta& GetUniformSlotId( const TPString8& a_strSlotName );
100
101 TBOOL SetUniform( const TPString8& a_strSlotName, const TMatrix44& a_rMatrix );
102 TBOOL SetUniform( const TPString8& a_strSlotName, const TMatrix44* a_pMatrix, TUINT a_uiNumItems );
103 TBOOL SetUniform( const TPString8& a_strSlotName, const glm::mat4& a_rMatrix );
104 TBOOL SetUniform( const TPString8& a_strSlotName, const glm::mat4* a_pMatrix, TUINT a_uiNumItems );
105 TBOOL SetUniform( const TPString8& a_strSlotName, const TVector4& a_rVector );
106 TBOOL SetUniform( const TPString8& a_strSlotName, const TVector4* a_pVector, TUINT a_uiNumItems );
107 TBOOL SetUniform( const TPString8& a_strSlotName, const glm::vec4& a_rVector );
108 TBOOL SetUniform( const TPString8& a_strSlotName, const glm::vec4* a_pVector, TUINT a_uiNumItems );
109 TBOOL SetUniform( const TPString8& a_strSlotName, const TVector3& a_rVector );
110 TBOOL SetUniform( const TPString8& a_strSlotName, const TVector3* a_pVector, TUINT a_uiNumItems );
111 TBOOL SetUniform( const TPString8& a_strSlotName, TFLOAT a_fValue );
112 TBOOL SetUniform( const TPString8& a_strSlotName, const TFLOAT* a_pValue, TUINT a_uiNumItems );
113 TBOOL SetUniform( const TPString8& a_strSlotName, TINT a_iValue );
114 TBOOL SetUniform( const TPString8& a_strSlotName, const TINT* a_pValue, TUINT a_uiNumItems );
115 TBOOL SetUniform( const TPString8& a_strSlotName, TUINT a_uiValue );
116 TBOOL SetUniform( const TPString8& a_strSlotName, const TUINT* a_pValue, TUINT a_uiNumItems );
117
118 GLuint GetProgram() const { return m_uiProgram; }
119 T2CompiledShader GetVertexShader() const { return m_VShader; }
120 T2CompiledShader GetFragmentShader() const { return m_FShader; }
121
122 T2Shader& operator=( const T2Shader& a_rOther );
123
124private:
125 friend class T2Render;
126 friend class T2RenderContext;
127 void Use() const;
128
129private:
130 GLuint m_uiProgram;
131 T2CompiledShader m_VShader;
132 T2CompiledShader m_FShader;
133
134 T2Map<TPString8, UniformMeta, TPString8::Comparator> m_UniformToSlotId;
135};
136
138
139#endif // TRENDERINTERFACE_GL
4x4 matrix implementation for the Toshi engine
3D vector implementation for the Toshi engine
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
float TFLOAT
Definition Typedefs.h:4
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6