2020-09-16 20:14:35 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-08-30 20:19:37 +00:00
|
|
|
//
|
2020-09-16 20:14:35 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2022-03-14 19:14:18 +00:00
|
|
|
// ShaderOpenGL.h
|
2020-08-30 20:19:37 +00:00
|
|
|
//
|
2022-03-14 19:14:18 +00:00
|
|
|
// OpenGL / OpenGL ES shader functions.
|
2020-08-30 20:19:37 +00:00
|
|
|
//
|
|
|
|
|
2022-03-14 19:14:18 +00:00
|
|
|
#ifndef ES_CORE_RENDERER_SHADER_OPENGL_H
|
|
|
|
#define ES_CORE_RENDERER_SHADER_OPENGL_H
|
2020-08-30 20:19:37 +00:00
|
|
|
|
|
|
|
#define GL_GLEXT_PROTOTYPES
|
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
#include "renderers/Renderer.h"
|
2021-08-17 20:11:16 +00:00
|
|
|
#include "utils/MathUtil.h"
|
2020-09-12 10:14:48 +00:00
|
|
|
|
2020-09-16 20:14:35 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#endif
|
|
|
|
|
2020-08-30 20:19:37 +00:00
|
|
|
#include <SDL2/SDL.h>
|
2022-03-13 22:52:32 +00:00
|
|
|
#if defined(USE_OPENGLES)
|
|
|
|
#include <GLES3/gl3.h>
|
2021-07-08 16:08:43 +00:00
|
|
|
#include <SDL2/SDL_opengles.h>
|
2022-03-13 22:52:32 +00:00
|
|
|
#else
|
|
|
|
#include <SDL2/SDL_opengl.h>
|
2021-07-08 16:08:43 +00:00
|
|
|
#endif
|
2020-08-30 20:19:37 +00:00
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
#if !defined(NDEBUG)
|
|
|
|
#define GL_CHECK_ERROR(Function) (Function, _GLCheckError(#Function))
|
|
|
|
static inline void _GLCheckError(const std::string& funcName)
|
2020-08-30 20:19:37 +00:00
|
|
|
{
|
2022-03-14 18:51:48 +00:00
|
|
|
const GLenum errorCode = glGetError();
|
2020-08-30 20:19:37 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
if (errorCode != GL_NO_ERROR) {
|
|
|
|
#if defined(USE_OPENGLES)
|
|
|
|
LOG(LogError) << "OpenGL ES error: " << funcName << " failed with error code: 0x"
|
|
|
|
<< std::hex << errorCode;
|
|
|
|
#else
|
|
|
|
LOG(LogError) << "OpenGL error: " << funcName << " failed with error code: 0x" << std::hex
|
|
|
|
<< errorCode;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define GL_CHECK_ERROR(Function) (Function)
|
|
|
|
#endif
|
|
|
|
|
2022-03-14 19:14:18 +00:00
|
|
|
class ShaderOpenGL
|
2022-03-14 18:51:48 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-03-14 19:14:18 +00:00
|
|
|
ShaderOpenGL();
|
|
|
|
~ShaderOpenGL();
|
2021-08-15 17:30:31 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
// 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.
|
|
|
|
void setModelViewProjectionMatrix(glm::mat4 mvpMatrix);
|
2020-08-30 20:19:37 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
void setAttribPointers();
|
|
|
|
void setTextureSize(std::array<GLfloat, 2> shaderVec2);
|
|
|
|
void setOpacity(GLfloat opacity);
|
|
|
|
void setSaturation(GLfloat saturation);
|
|
|
|
void setDimming(GLfloat dimming);
|
2022-03-14 21:30:24 +00:00
|
|
|
void setFlags(GLuint flags);
|
2022-03-14 18:51:48 +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() { return mProgramID; }
|
|
|
|
// Only used for error logging if the shaders fail to compile or link.
|
|
|
|
void printProgramInfoLog(GLuint programID);
|
|
|
|
void printShaderInfoLog(GLuint shaderID, GLenum shaderType, bool error);
|
2020-08-30 20:19:37 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
private:
|
|
|
|
GLuint mProgramID;
|
|
|
|
std::vector<std::tuple<std::string, std::string, GLenum>> mShaderVector;
|
2020-09-04 16:59:19 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
// Variables used for communication with the compiled shaders.
|
|
|
|
GLint mShaderMVPMatrix;
|
|
|
|
GLint mShaderPosition;
|
|
|
|
GLint mShaderTextureCoord;
|
|
|
|
GLint mShaderColor;
|
|
|
|
GLint mShaderTextureSize;
|
|
|
|
GLint mShaderOpacity;
|
|
|
|
GLint mShaderSaturation;
|
|
|
|
GLint mShaderDimming;
|
2022-03-14 21:30:24 +00:00
|
|
|
GLint mShaderFlags;
|
2022-03-14 18:51:48 +00:00
|
|
|
};
|
2020-08-30 20:19:37 +00:00
|
|
|
|
2022-03-14 19:14:18 +00:00
|
|
|
#endif // ES_CORE_RENDERER_SHADER_OPENGL_H
|