sculpto
Public Member Functions | List of all members
scl::gl_shader_program Class Reference

#include <gl_shader.h>

Inheritance diagram for scl::gl_shader_program:
scl::shader_program

Public Member Functions

render_primitive::handle GetHandle () const override
 
 gl_shader_program (const std::vector< shader_props > &Shaders, const std::string &DebugName)
 
 ~gl_shader_program ()
 
bool SetBool (const std::string &Name, bool Value) const override
 
bool SetFloat (const std::string &Name, float Value) const override
 
bool SetFloat2 (const std::string &Name, const vec2 &Value) const override
 
bool SetFloat3 (const std::string &Name, const vec3 &Value) const override
 
bool SetFloat4 (const std::string &Name, const vec4 &Value) const override
 
bool SetInt (const std::string &Name, int Value) const override
 
bool SetInt2 (const std::string &Name, const ivec2 &Value) const override
 
bool SetInt3 (const std::string &Name, const ivec3 &Value) const override
 
bool SetInt4 (const std::string &Name, const ivec4 &Value) const override
 
bool SetUInt (const std::string &Name, u32 Value) const override
 
bool SetUInt2 (const std::string &Name, const uvec2 &Value) const override
 
bool SetUInt3 (const std::string &Name, const uvec3 &Value) const override
 
bool SetUInt4 (const std::string &Name, const uvec4 &Value) const override
 
bool SetMatr3 (const std::string &Name, const matr3 &Value) const override
 
bool SetMatr4 (const std::string &Name, const matr4 &Value) const override
 
bool SetBool (int Location, bool Value) const override
 
bool SetFloat (int Location, float Value) const
 
bool SetFloat2 (int Location, const vec2 &Value) const
 
bool SetFloat3 (int Location, const vec3 &Value) const
 
bool SetFloat4 (int Location, const vec4 &Value) const
 
bool SetInt (int Location, int Value) const
 
bool SetInt2 (int Location, const ivec2 &Value) const
 
bool SetInt3 (int Location, const ivec3 &Value) const
 
bool SetInt4 (int Location, const ivec4 &Value) const
 
bool SetUInt (int Location, u32 Value) const
 
bool SetUInt2 (int Location, const uvec2 &Value) const
 
bool SetUInt3 (int Location, const uvec3 &Value) const
 
bool SetUInt4 (int Location, const uvec4 &Value) const
 
bool SetMatr3 (int Location, const matr3 &Value) const
 
bool SetMatr4 (int Location, const matr4 &Value) const
 
void Bind () const override
 
void Unbind () const override
 
void Update (const std::vector< shader_props > &Shaders) override
 
void Free () override
 
- Public Member Functions inherited from scl::shader_program
virtual bool SetBool (const std::string &Name, bool Value) const =0
 
virtual bool SetFloat (const std::string &Name, float Value) const =0
 
virtual bool SetFloat2 (const std::string &Name, const vec2 &Value) const =0
 
virtual bool SetFloat3 (const std::string &Name, const vec3 &Value) const =0
 
virtual bool SetFloat4 (const std::string &Name, const vec4 &Value) const =0
 
virtual bool SetInt (const std::string &Name, int Value) const =0
 
virtual bool SetInt2 (const std::string &Name, const ivec2 &Value) const =0
 
virtual bool SetInt3 (const std::string &Name, const ivec3 &Value) const =0
 
virtual bool SetInt4 (const std::string &Name, const ivec4 &Value) const =0
 
virtual bool SetUInt (const std::string &Name, u32 Value) const =0
 
virtual bool SetUInt2 (const std::string &Name, const uvec2 &Value) const =0
 
virtual bool SetUInt3 (const std::string &Name, const uvec3 &Value) const =0
 
virtual bool SetUInt4 (const std::string &Name, const uvec4 &Value) const =0
 
virtual bool SetMatr3 (const std::string &Name, const matr3 &Value) const =0
 
virtual bool SetMatr4 (const std::string &Name, const matr4 &Value) const =0
 
virtual bool SetBool (int Location, bool Value) const =0
 
virtual bool SetFloat (int Location, float Value) const =0
 
virtual bool SetFloat2 (int Location, const vec2 &Value) const =0
 
virtual bool SetFloat3 (int Location, const vec3 &Value) const =0
 
virtual bool SetFloat4 (int Location, const vec4 &Value) const =0
 
virtual bool SetInt (int Location, int Value) const =0
 
virtual bool SetInt2 (int Location, const ivec2 &Value) const =0
 
virtual bool SetInt3 (int Location, const ivec3 &Value) const =0
 
virtual bool SetInt4 (int Location, const ivec4 &Value) const =0
 
virtual bool SetUInt (int Location, u32 Value) const =0
 
virtual bool SetUInt2 (int Location, const uvec2 &Value) const =0
 
virtual bool SetUInt3 (int Location, const uvec3 &Value) const =0
 
virtual bool SetUInt4 (int Location, const uvec4 &Value) const =0
 
virtual bool SetMatr3 (int Location, const matr3 &Value) const =0
 
virtual bool SetMatr4 (int Location, const matr4 &Value) const =0
 
 shader_program (const std::string &DebugName)
 
virtual ~shader_program ()=default
 
virtual void Bind () const =0
 
virtual void Unbind () const =0
 
virtual void Update (const std::vector< shader_props > &Shaders)=0
 
virtual void Free ()=0
 

Additional Inherited Members

- Static Public Member Functions inherited from scl::shader_program
static shared< shader_programCreate (const std::vector< shader_props > &Shaders, const std::string &DebugName)
 
- Public Attributes inherited from scl::shader_program
std::string SingleSourceFileName {}
 
std::string VertexShadersourceFileName {}
 
std::string GeometryShadersourceFileName {}
 
std::string PixelShadersourceFileName {}
 
std::string DebugName {}
 

Detailed Description

OpenGL shader_props program class.

Definition at line 17 of file gl_shader.h.

Constructor & Destructor Documentation

◆ gl_shader_program()

scl::gl_shader_program::gl_shader_program ( const std::vector< shader_props > &  Shaders,
const std::string &  DebugName 
)
  • Shader program default constructor.
Parameters
Shaders- shaders array.
DubugName- shader program debug name.

Definition at line 129 of file gl_shader.cpp.

129 :
131{
132 Create(Shaders);
133}
std::string DebugName
Definition: shader.h:50
shader_program(const std::string &DebugName)
Definition: shader.cpp:13

◆ ~gl_shader_program()

scl::gl_shader_program::~gl_shader_program ( )

Default destructor.

Definition at line 135 of file gl_shader.cpp.

136{
137 Free();
138}
void Free() override
Definition: gl_shader.cpp:162

Member Function Documentation

◆ Bind()

void scl::gl_shader_program::Bind ( ) const
overridevirtual
  • Bind buffer to current render stage function.
Parameters
None.
Returns
None.

Implements scl::shader_program.

Definition at line 140 of file gl_shader.cpp.

141{
142 if (glIsProgram(Id))
143 {
144 glUseProgram(Id);
145 gl_shader_program::CurrentlyBoundShaderId = Id;
146 }
147}

◆ Free()

void scl::gl_shader_program::Free ( )
overridevirtual
Parameters
None.
Returns
None.

Implements scl::shader_program.

Definition at line 162 of file gl_shader.cpp.

163{
164 VariablesLocations.clear();
165 ShaderNotBindedErrorAlreadyShown = false;
166
167 if (Id == 0) return;
168
169 int shaders_count {};
170 GLuint shaders_ids[5] {};
171 glGetAttachedShaders(Id, 5, &shaders_count, shaders_ids);
172
173 for (int i = 0; i < shaders_count; i++)
174 {
175 glDetachShader(Id, shaders_ids[i]);
176 glDeleteShader(shaders_ids[i]);
177 }
178 glDeleteProgram(Id);
179 SCL_CORE_INFO("OpenGL Shader with id {} freed.", Id);
180 Id = 0;
181}
#define SCL_CORE_INFO(...)
Definition: log.h:41

◆ GetHandle()

render_primitive::handle scl::gl_shader_program::GetHandle ( ) const
inlineoverride

Backend api render primitive hadnle getter function.

Definition at line 77 of file gl_shader.h.

77{ return Id; }

◆ SetBool() [1/2]

bool scl::gl_shader_program::SetBool ( const std::string &  Name,
bool  Value 
) const
overridevirtual
Parameters
Name- unifrom variable name.
Value- unifrom variable name.
Returns
success flag.

Implements scl::shader_program.

Definition at line 183 of file gl_shader.cpp.

184{
185 if (!CheckIfShaderBinded()) return false;
186 int location = GetOrCacheLocation(Name);
187 if (location == -1) return false;
188
189 glUniform1i(location, Value);
190 return true;
191}

◆ SetBool() [2/2]

bool scl::gl_shader_program::SetBool ( int  Location,
bool  Value 
) const
overridevirtual
Parameters
Location- platform specific shader variable location identifier.
Value- unifrom variable value.
Returns
success flag.

Implements scl::shader_program.

Definition at line 333 of file gl_shader.cpp.

334{
335 if (!CheckIfShaderBinded()) return false;
336 glUniform1i(Location, Value);
337 return true;
338}

◆ SetFloat() [1/2]

bool scl::gl_shader_program::SetFloat ( const std::string &  Name,
float  Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 193 of file gl_shader.cpp.

194{
195 if (!CheckIfShaderBinded()) return false;
196 int location = GetOrCacheLocation(Name);
197 if (location == -1) return false;
198
199 glUniform1f(location, Value);
200 return true;
201}

◆ SetFloat() [2/2]

bool scl::gl_shader_program::SetFloat ( int  Location,
float  Value 
) const
virtual

Implements scl::shader_program.

Definition at line 340 of file gl_shader.cpp.

341{
342 if (!CheckIfShaderBinded()) return false;
343 glUniform1f(Location, Value);
344 return true;
345}

◆ SetFloat2() [1/2]

bool scl::gl_shader_program::SetFloat2 ( const std::string &  Name,
const vec2 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 203 of file gl_shader.cpp.

204{
205 if (!CheckIfShaderBinded()) return false;
206 int location = GetOrCacheLocation(Name);
207 if (location == -1) return false;
208
209 glUniform2fv(location, 1, (float *)&Value);
210 return true;
211}

◆ SetFloat2() [2/2]

bool scl::gl_shader_program::SetFloat2 ( int  Location,
const vec2 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 347 of file gl_shader.cpp.

348{
349 if (!CheckIfShaderBinded()) return false;
350 glUniform2fv(Location, 1, (float *)&Value);
351 return true;
352}

◆ SetFloat3() [1/2]

bool scl::gl_shader_program::SetFloat3 ( const std::string &  Name,
const vec3 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 213 of file gl_shader.cpp.

214{
215 if (!CheckIfShaderBinded()) return false;
216 int location = GetOrCacheLocation(Name);
217 if (location == -1) return false;
218
219 glUniform3fv(location, 1, (float *)&Value);
220 return true;
221}

◆ SetFloat3() [2/2]

bool scl::gl_shader_program::SetFloat3 ( int  Location,
const vec3 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 354 of file gl_shader.cpp.

355{
356 if (!CheckIfShaderBinded()) return false;
357 glUniform3fv(Location, 1, (float *)&Value);
358 return true;
359}

◆ SetFloat4() [1/2]

bool scl::gl_shader_program::SetFloat4 ( const std::string &  Name,
const vec4 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 223 of file gl_shader.cpp.

224{
225 if (!CheckIfShaderBinded()) return false;
226 int location = GetOrCacheLocation(Name);
227 if (location == -1) return false;
228
229 glUniform4fv(location, 1, (float *)&Value);
230 return true;
231}

◆ SetFloat4() [2/2]

bool scl::gl_shader_program::SetFloat4 ( int  Location,
const vec4 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 361 of file gl_shader.cpp.

362{
363 if (!CheckIfShaderBinded()) return false;
364 glUniform4fv(Location, 1, (float *)&Value);
365 return true;
366}

◆ SetInt() [1/2]

bool scl::gl_shader_program::SetInt ( const std::string &  Name,
int  Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 233 of file gl_shader.cpp.

234{
235 if (!CheckIfShaderBinded()) return false;
236 int location = GetOrCacheLocation(Name);
237 if (location == -1) return false;
238
239 glUniform1i(location, Value);
240 return true;
241}

◆ SetInt() [2/2]

bool scl::gl_shader_program::SetInt ( int  Location,
int  Value 
) const
virtual

Implements scl::shader_program.

Definition at line 368 of file gl_shader.cpp.

369{
370 if (!CheckIfShaderBinded()) return false;
371 glUniform1i(Location, Value);
372 return true;
373}

◆ SetInt2() [1/2]

bool scl::gl_shader_program::SetInt2 ( const std::string &  Name,
const ivec2 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 243 of file gl_shader.cpp.

244{
245 if (!CheckIfShaderBinded()) return false;
246 int location = GetOrCacheLocation(Name);
247 if (location == -1) return false;
248
249 glUniform2iv(location, 1, (int *)&Value);
250 return true;
251}

◆ SetInt2() [2/2]

bool scl::gl_shader_program::SetInt2 ( int  Location,
const ivec2 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 375 of file gl_shader.cpp.

376{
377 if (!CheckIfShaderBinded()) return false;
378 glUniform2iv(Location, 1, (int *)&Value);
379 return true;
380}

◆ SetInt3() [1/2]

bool scl::gl_shader_program::SetInt3 ( const std::string &  Name,
const ivec3 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 253 of file gl_shader.cpp.

254{
255 if (!CheckIfShaderBinded()) return false;
256 int location = GetOrCacheLocation(Name);
257 if (location == -1) return false;
258
259 glUniform3iv(location, 1, (int *)&Value);
260 return true;
261}

◆ SetInt3() [2/2]

bool scl::gl_shader_program::SetInt3 ( int  Location,
const ivec3 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 382 of file gl_shader.cpp.

383{
384 if (!CheckIfShaderBinded()) return false;
385 glUniform3iv(Location, 1, (int *)&Value);
386 return true;
387}

◆ SetInt4() [1/2]

bool scl::gl_shader_program::SetInt4 ( const std::string &  Name,
const ivec4 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 263 of file gl_shader.cpp.

264{
265 if (!CheckIfShaderBinded()) return false;
266 int location = GetOrCacheLocation(Name);
267 if (location == -1) return false;
268
269 glUniform4iv(location, 1, (int *)&Value);
270 return true;
271}

◆ SetInt4() [2/2]

bool scl::gl_shader_program::SetInt4 ( int  Location,
const ivec4 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 389 of file gl_shader.cpp.

390{
391 if (!CheckIfShaderBinded()) return false;
392 glUniform4iv(Location, 1, (int *)&Value);
393 return true;
394}

◆ SetMatr3() [1/2]

bool scl::gl_shader_program::SetMatr3 ( const std::string &  Name,
const matr3 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 313 of file gl_shader.cpp.

314{
315 if (!CheckIfShaderBinded()) return false;
316 int location = GetOrCacheLocation(Name);
317 if (location == -1) return false;
318
319 glUniformMatrix3fv(location, 1, FALSE, (float *)&Value);
320 return true;
321}

◆ SetMatr3() [2/2]

bool scl::gl_shader_program::SetMatr3 ( int  Location,
const matr3 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 424 of file gl_shader.cpp.

425{
426 if (!CheckIfShaderBinded()) return false;
427 glUniformMatrix3fv(Location, 1, FALSE, (float *)&Value);
428 return true;
429}

◆ SetMatr4() [1/2]

bool scl::gl_shader_program::SetMatr4 ( const std::string &  Name,
const matr4 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 323 of file gl_shader.cpp.

324{
325 if (!CheckIfShaderBinded()) return false;
326 int location = GetOrCacheLocation(Name);
327 if (location == -1) return false;
328
329 glUniformMatrix4fv(location, 1, FALSE, (float *)&Value);
330 return true;
331}

◆ SetMatr4() [2/2]

bool scl::gl_shader_program::SetMatr4 ( int  Location,
const matr4 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 431 of file gl_shader.cpp.

432{
433 if (!CheckIfShaderBinded()) return false;
434 glUniformMatrix4fv(Location, 1, FALSE, (float *)&Value);
435 return true;
436}

◆ SetUInt() [1/2]

bool scl::gl_shader_program::SetUInt ( const std::string &  Name,
u32  Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 273 of file gl_shader.cpp.

274{
275 if (!CheckIfShaderBinded()) return false;
276 int location = GetOrCacheLocation(Name);
277 if (location == -1) return false;
278
279 glUniform1ui(location, Value);
280 return true;
281}

◆ SetUInt() [2/2]

bool scl::gl_shader_program::SetUInt ( int  Location,
u32  Value 
) const
virtual

Implements scl::shader_program.

Definition at line 396 of file gl_shader.cpp.

397{
398 if (!CheckIfShaderBinded()) return false;
399 glUniform1ui(Location, Value);
400 return true;
401}

◆ SetUInt2() [1/2]

bool scl::gl_shader_program::SetUInt2 ( const std::string &  Name,
const uvec2 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 283 of file gl_shader.cpp.

284{
285 if (!CheckIfShaderBinded()) return false;
286 int location = GetOrCacheLocation(Name);
287 if (location == -1) return false;
288
289 glUniform2uiv(location, 1, (u32 *)&Value);
290 return true;
291}
uint32_t u32
Definition: math_common.h:21

◆ SetUInt2() [2/2]

bool scl::gl_shader_program::SetUInt2 ( int  Location,
const uvec2 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 403 of file gl_shader.cpp.

404{
405 if (!CheckIfShaderBinded()) return false;
406 glUniform2uiv(Location, 1, (u32 *)&Value);
407 return true;
408}

◆ SetUInt3() [1/2]

bool scl::gl_shader_program::SetUInt3 ( const std::string &  Name,
const uvec3 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 293 of file gl_shader.cpp.

294{
295 if (!CheckIfShaderBinded()) return false;
296 int location = GetOrCacheLocation(Name);
297 if (location == -1) return false;
298
299 glUniform3uiv(location, 1, (u32 *)&Value);
300 return true;
301}

◆ SetUInt3() [2/2]

bool scl::gl_shader_program::SetUInt3 ( int  Location,
const uvec3 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 410 of file gl_shader.cpp.

411{
412 if (!CheckIfShaderBinded()) return false;
413 glUniform3uiv(Location, 1, (u32 *)&Value);
414 return true;
415}

◆ SetUInt4() [1/2]

bool scl::gl_shader_program::SetUInt4 ( const std::string &  Name,
const uvec4 Value 
) const
overridevirtual

Implements scl::shader_program.

Definition at line 303 of file gl_shader.cpp.

304{
305 if (!CheckIfShaderBinded()) return false;
306 int location = GetOrCacheLocation(Name);
307 if (location == -1) return false;
308
309 glUniform4uiv(location, 1, (u32 *)&Value);
310 return true;
311}

◆ SetUInt4() [2/2]

bool scl::gl_shader_program::SetUInt4 ( int  Location,
const uvec4 Value 
) const
virtual

Implements scl::shader_program.

Definition at line 417 of file gl_shader.cpp.

418{
419 if (!CheckIfShaderBinded()) return false;
420 glUniform4uiv(Location, 1, (u32 *)&Value);
421 return true;
422}

◆ Unbind()

void scl::gl_shader_program::Unbind ( ) const
overridevirtual
  • Unbind buffer from current render stage function.
Parameters
None.
Returns
None.

Implements scl::shader_program.

Definition at line 149 of file gl_shader.cpp.

150{
151 glUseProgram(0);
152 CurrentlyBoundShaderId = 0;
153}

◆ Update()

void scl::gl_shader_program::Update ( const std::vector< shader_props > &  Shaders)
overridevirtual
  • Update (recompile from dource file).

Implements scl::shader_program.

Definition at line 155 of file gl_shader.cpp.

156{
157 Free();
158 Create(Shaders);
159 SCL_CORE_INFO("OpenGL Shader with id {} updated.", Id);
160}

The documentation for this class was generated from the following files: