@@ -83,6 +83,89 @@ struct GLHeader {
8383 }
8484};
8585
86+ struct ShaderEntry {
87+ std::string name;
88+ uint32_t macro;
89+ GLuint type;
90+
91+ bool operator ==( const ShaderEntry& other ) const {
92+ return name == other.name && macro == other.macro && type == other.type ;
93+ }
94+
95+ bool operator !=( const ShaderEntry& other ) const {
96+ return !( *this == other );
97+ }
98+ };
99+
100+ struct ShaderDescriptor {
101+ std::string name;
102+
103+ std::string macros;
104+ uint32_t macro;
105+
106+ GLenum type;
107+ bool main = false ;
108+
109+ GLuint id = 0 ;
110+
111+ std::string shaderSource;
112+ };
113+
114+ static const uint32_t MAX_SHADER_PROGRAM_SHADERS = 16 ;
115+
116+ struct ShaderProgramDescriptor {
117+ GLuint id = 0 ;
118+
119+ bool hasMain = false ;
120+ GLuint type;
121+
122+ uint32_t macro = 0 ;
123+
124+ GLuint shaders[MAX_SHADER_PROGRAM_SHADERS] {};
125+ ShaderEntry shaderNames[MAX_SHADER_PROGRAM_SHADERS] {};
126+ std::string mainShader;
127+ uint32_t shaderCount = 0 ;
128+
129+ GLint* uniformLocations;
130+ GLuint* uniformBlockIndexes = nullptr ;
131+ byte* uniformFirewall;
132+
133+ uint32_t checkSum;
134+
135+ void AttachShader ( ShaderDescriptor* descriptor ) {
136+ if ( shaderCount == MAX_SHADER_PROGRAM_SHADERS ) {
137+ Log::Warn ( " Tried to attach too many shaders to program: skipping shader %s %s" , descriptor->name , descriptor->macros );
138+ return ;
139+ }
140+
141+ if ( !shaderCount ) {
142+ type = descriptor->type ;
143+ } else if ( type != descriptor->type ) {
144+ type = 0 ;
145+ }
146+
147+ if ( descriptor->main ) {
148+ if ( hasMain && mainShader != descriptor->name ) {
149+ Log::Warn ( " More than one shader specified as main, current: %s, new: %s, using current" ,
150+ mainShader, descriptor->name );
151+ } else {
152+ mainShader = descriptor->name ;
153+ hasMain = true ;
154+ }
155+ }
156+
157+ shaders[shaderCount] = descriptor->id ;
158+
159+ shaderNames[shaderCount].name = descriptor->name ;
160+ shaderNames[shaderCount].macro = descriptor->macro ;
161+ shaderNames[shaderCount].type = descriptor->type ;
162+
163+ macro |= descriptor->macro ;
164+
165+ shaderCount++;
166+ };
167+ };
168+
86169class GLShader {
87170 friend class GLShaderManager ;
88171public:
@@ -229,89 +312,6 @@ class GLShader {
229312 void WriteUniformsToBuffer ( uint32_t * buffer );
230313};
231314
232- struct ShaderEntry {
233- std::string name;
234- uint32_t macro;
235- GLuint type;
236-
237- bool operator ==( const ShaderEntry& other ) const {
238- return name == other.name && macro == other.macro && type == other.type ;
239- }
240-
241- bool operator !=( const ShaderEntry& other ) const {
242- return !( *this == other );
243- }
244- };
245-
246- struct ShaderDescriptor {
247- std::string name;
248-
249- std::string macros;
250- uint32_t macro;
251-
252- GLenum type;
253- bool main = false ;
254-
255- GLuint id = 0 ;
256-
257- std::string shaderSource;
258- };
259-
260- static const uint32_t MAX_SHADER_PROGRAM_SHADERS = 16 ;
261-
262- struct ShaderProgramDescriptor {
263- GLuint id = 0 ;
264-
265- bool hasMain = false ;
266- GLuint type;
267-
268- uint32_t macro = 0 ;
269-
270- GLuint shaders[MAX_SHADER_PROGRAM_SHADERS] {};
271- ShaderEntry shaderNames[MAX_SHADER_PROGRAM_SHADERS] {};
272- std::string mainShader;
273- uint32_t shaderCount = 0 ;
274-
275- GLint* uniformLocations;
276- GLuint* uniformBlockIndexes = nullptr ;
277- byte* uniformFirewall;
278-
279- uint32_t checkSum;
280-
281- void AttachShader ( ShaderDescriptor* descriptor ) {
282- if ( shaderCount == MAX_SHADER_PROGRAM_SHADERS ) {
283- Log::Warn ( " Tried to attach too many shaders to program: skipping shader %s %s" , descriptor->name , descriptor->macros );
284- return ;
285- }
286-
287- if ( !shaderCount ) {
288- type = descriptor->type ;
289- } else if ( type != descriptor->type ) {
290- type = 0 ;
291- }
292-
293- if ( descriptor->main ) {
294- if ( hasMain && mainShader != descriptor->name ) {
295- Log::Warn ( " More than one shader specified as main, current: %s, new: %s, using current" ,
296- mainShader, descriptor->name );
297- } else {
298- mainShader = descriptor->name ;
299- hasMain = true ;
300- }
301- }
302-
303- shaders[shaderCount] = descriptor->id ;
304-
305- shaderNames[shaderCount].name = descriptor->name ;
306- shaderNames[shaderCount].macro = descriptor->macro ;
307- shaderNames[shaderCount].type = descriptor->type ;
308-
309- macro |= descriptor->macro ;
310-
311- shaderCount++;
312- };
313- };
314-
315315class GLUniform {
316316 public:
317317 const std::string _name;
0 commit comments