2018-06-16 21:31:29 +00:00
|
|
|
#ifndef _GLSLSHADER_H_
|
|
|
|
#define _GLSLSHADER_H_
|
|
|
|
|
2020-07-31 19:18:51 +00:00
|
|
|
#include <GL/glew.h>
|
2022-10-16 20:03:41 +00:00
|
|
|
#include <map>
|
2022-10-17 08:34:11 +00:00
|
|
|
#include <cstring>
|
2018-06-16 21:31:29 +00:00
|
|
|
|
|
|
|
class GLSLShader {
|
|
|
|
|
|
|
|
public:
|
|
|
|
GLSLShader();
|
2022-10-16 20:03:41 +00:00
|
|
|
~GLSLShader();
|
2018-06-16 21:31:29 +00:00
|
|
|
|
2022-10-16 20:03:41 +00:00
|
|
|
GLSLShader(GLSLShader&& other) noexcept;
|
|
|
|
GLSLShader(const GLSLShader&) = delete;
|
|
|
|
GLSLShader& operator=(const GLSLShader&) = delete;
|
|
|
|
GLSLShader& operator=(GLSLShader&& other) noexcept;
|
|
|
|
|
|
|
|
bool LoadShaders(const char* vertexShader, const char* fragmentShader);
|
2018-06-16 21:31:29 +00:00
|
|
|
void UnloadShaders();
|
|
|
|
|
|
|
|
void EnableShader();
|
|
|
|
void DisableShader();
|
|
|
|
|
2022-10-16 20:03:41 +00:00
|
|
|
int GetUniformLocation(const char* str);
|
|
|
|
void GetUniformLocationMap(const char* str);
|
|
|
|
int GetAttributeLocation(const char* str);
|
|
|
|
void GetAttributeLocationMap(const char* str);
|
2018-06-16 21:31:29 +00:00
|
|
|
|
|
|
|
int uniformLoc[64];
|
|
|
|
int attribLoc[16];
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2022-10-16 20:03:41 +00:00
|
|
|
struct cmp_str
|
|
|
|
{
|
|
|
|
bool operator()(char const* a, char const* b) const
|
|
|
|
{
|
|
|
|
return std::strcmp(a, b) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
std::map<const char*, int, cmp_str> uniformLocMap;
|
|
|
|
std::map<const char*, int, cmp_str> attribLocMap;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
2018-06-16 21:31:29 +00:00
|
|
|
void PrintShaderInfoLog(GLuint obj);
|
|
|
|
void PrintProgramInfoLog(GLuint obj);
|
|
|
|
|
|
|
|
GLuint m_program;
|
|
|
|
GLuint m_vShader;
|
|
|
|
GLuint m_fShader;
|
|
|
|
};
|
|
|
|
|
2022-10-16 20:03:41 +00:00
|
|
|
|
2018-06-16 21:31:29 +00:00
|
|
|
#endif
|