2020-08-30 20:19:37 +00:00
|
|
|
//
|
|
|
|
// Shader_GL21.h
|
|
|
|
//
|
|
|
|
// OpenGL 2.1 GLSL shader functions.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ES_CORE_RENDERER_SHADER_GL21_H
|
|
|
|
#define ES_CORE_RENDERER_SHADER_GL21_H
|
|
|
|
|
|
|
|
#define GL_GLEXT_PROTOTYPES
|
|
|
|
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <SDL2/SDL_opengl.h>
|
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Renderer
|
|
|
|
{
|
|
|
|
class Shader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Shader();
|
|
|
|
~Shader();
|
|
|
|
|
|
|
|
// Loads the shader source code only, no compilation done at this point.
|
|
|
|
void loadShaderFile(const std::string& path, GLenum shaderType);
|
|
|
|
// Compilation, shader attachment and linking.
|
|
|
|
bool createProgram();
|
|
|
|
// Only used for a clean shutdown.
|
|
|
|
void deleteProgram(GLuint programID);
|
|
|
|
// Get references to the variables inside the compiled shaders.
|
|
|
|
void getVariableLocations(GLuint programID);
|
|
|
|
// One-way communication with the compiled shaders.
|
2020-09-04 16:59:19 +00:00
|
|
|
void setTextureSize(std::array<GLfloat, 2> shaderVec2);
|
|
|
|
void setTextureCoordinates(std::array<GLfloat, 4> shaderVec4);
|
|
|
|
void setColor(std::array<GLfloat, 4> shaderVec4);
|
|
|
|
void setSaturation(GLfloat saturation);
|
2020-08-30 20:19:37 +00:00
|
|
|
// Sets the shader program to use the loaded shaders.
|
|
|
|
void activateShaders();
|
|
|
|
// Sets the shader program to 0 which reverts to the fixed function pipeline.
|
|
|
|
void deactivateShaders();
|
|
|
|
// Returns the program ID that was generated by glCreateProgram().
|
|
|
|
GLuint getProgramID();
|
|
|
|
// Only used for error logging if the shaders fail to compile or link.
|
|
|
|
void printProgramInfoLog(GLuint programID);
|
2020-09-04 16:59:19 +00:00
|
|
|
void printShaderInfoLog(GLuint shaderID, GLenum shaderType);
|
2020-08-30 20:19:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
GLuint mProgramID;
|
|
|
|
std::vector<std::tuple<std::string, std::string, GLenum>> shaderVector;
|
|
|
|
|
|
|
|
// Variables used for communication with the compiled shaders.
|
2020-09-04 16:59:19 +00:00
|
|
|
GLint shaderTextureSize;
|
|
|
|
GLint shaderTextureCoord;
|
|
|
|
GLint shaderColor;
|
|
|
|
GLint shaderSaturation;
|
2020-08-30 20:19:37 +00:00
|
|
|
};
|
2020-09-04 16:59:19 +00:00
|
|
|
|
2020-08-30 20:19:37 +00:00
|
|
|
} // Renderer
|
|
|
|
|
|
|
|
#endif // ES_CORE_RENDERER_SHADER_GL21_H
|