Renamed Renderer_GL21 and Shader_GL21 to RendererOpenGL and ShaderOpenGL.

This commit is contained in:
Leon Styhre 2022-03-14 20:14:18 +01:00
parent f0c35d8509
commit 6ff0ff1c47
6 changed files with 60 additions and 60 deletions

View file

@ -74,8 +74,8 @@ set(CORE_HEADERS
# Renderers # Renderers
${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Renderer.h ${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Renderer.h
${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Renderer_GL21.h ${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/RendererOpenGL.h
${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Shader_GL21.h ${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/ShaderOpenGL.h
# Resources # Resources
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.h ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.h
@ -150,8 +150,8 @@ set(CORE_SOURCES
# Renderer # Renderer
${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Renderer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Renderer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Renderer_GL21.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/RendererOpenGL.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/Shader_GL21.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/renderers/ShaderOpenGL.cpp
# Resources # Resources
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.cpp

View file

@ -11,8 +11,8 @@
#include "ImageIO.h" #include "ImageIO.h"
#include "Log.h" #include "Log.h"
#include "Settings.h" #include "Settings.h"
#include "Shader_GL21.h" #include "renderers/RendererOpenGL.h"
#include "renderers/Renderer_GL21.h" #include "renderers/ShaderOpenGL.h"
#include "resources/ResourceManager.h" #include "resources/ResourceManager.h"
#if defined(_WIN64) #if defined(_WIN64)

View file

@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// Renderer_GL21.cpp // RendererOpenGL.cpp
// //
// OpenGL / OpenGL ES renderering functions. // OpenGL / OpenGL ES renderering functions.
// //
#include "renderers/Renderer_GL21.h" #include "renderers/RendererOpenGL.h"
#include "Settings.h" #include "Settings.h"
@ -43,7 +43,7 @@ RendererOpenGL* RendererOpenGL::getInstance()
return &instance; return &instance;
} }
Shader* RendererOpenGL::getShaderProgram(unsigned int shaderID) ShaderOpenGL* RendererOpenGL::getShaderProgram(unsigned int shaderID)
{ {
unsigned int index {0}; unsigned int index {0};
@ -71,7 +71,7 @@ bool RendererOpenGL::loadShaders()
shaderFiles.push_back(":/shaders/glsl/scanlines.glsl"); shaderFiles.push_back(":/shaders/glsl/scanlines.glsl");
for (auto it = shaderFiles.cbegin(); it != shaderFiles.cend(); ++it) { for (auto it = shaderFiles.cbegin(); it != shaderFiles.cend(); ++it) {
Shader* loadShader = new Shader(); ShaderOpenGL* loadShader = new ShaderOpenGL();
loadShader->loadShaderFile(*it, GL_VERTEX_SHADER); loadShader->loadShaderFile(*it, GL_VERTEX_SHADER);
loadShader->loadShaderFile(*it, GL_FRAGMENT_SHADER); loadShader->loadShaderFile(*it, GL_FRAGMENT_SHADER);
@ -300,7 +300,7 @@ unsigned int RendererOpenGL::createTexture(const TextureType type,
const unsigned int height, const unsigned int height,
void* data) void* data)
{ {
const GLenum textureType {RendererOpenGL::convertTextureType(type)}; const GLenum textureType {convertTextureType(type)};
unsigned int texture; unsigned int texture;
GL_CHECK_ERROR(glGenTextures(1, &texture)); GL_CHECK_ERROR(glGenTextures(1, &texture));
@ -337,7 +337,7 @@ void RendererOpenGL::updateTexture(const unsigned int texture,
const unsigned int height, const unsigned int height,
void* data) void* data)
{ {
const GLenum textureType {RendererOpenGL::convertTextureType(type)}; const GLenum textureType {convertTextureType(type)};
GL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); GL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
GL_CHECK_ERROR(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, textureType, GL_CHECK_ERROR(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, textureType,
@ -362,12 +362,12 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
const float width {vertices[3].position[0]}; const float width {vertices[3].position[0]};
const float height {vertices[3].position[1]}; const float height {vertices[3].position[1]};
GL_CHECK_ERROR(glBlendFunc(RendererOpenGL::convertBlendFactor(srcBlendFactorFactor), GL_CHECK_ERROR(glBlendFunc(convertBlendFactor(srcBlendFactorFactor),
RendererOpenGL::convertBlendFactor(dstBlendFactorFactor))); convertBlendFactor(dstBlendFactorFactor)));
if (vertices->shaders == 0 || vertices->shaders & SHADER_CORE) { if (vertices->shaders == 0 || vertices->shaders & SHADER_CORE) {
if (mCoreShader == nullptr) if (mCoreShader == nullptr)
mCoreShader = RendererOpenGL::getShaderProgram(SHADER_CORE); mCoreShader = getShaderProgram(SHADER_CORE);
if (mCoreShader) { if (mCoreShader) {
if (mLastShader != mCoreShader) if (mLastShader != mCoreShader)
mCoreShader->activateShaders(); mCoreShader->activateShaders();
@ -388,7 +388,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
} }
else if (vertices->shaders & SHADER_BLUR_HORIZONTAL) { else if (vertices->shaders & SHADER_BLUR_HORIZONTAL) {
if (mBlurHorizontalShader == nullptr) if (mBlurHorizontalShader == nullptr)
mBlurHorizontalShader = RendererOpenGL::getShaderProgram(SHADER_BLUR_HORIZONTAL); mBlurHorizontalShader = getShaderProgram(SHADER_BLUR_HORIZONTAL);
if (mBlurHorizontalShader) { if (mBlurHorizontalShader) {
if (mLastShader != mBlurHorizontalShader) if (mLastShader != mBlurHorizontalShader)
mBlurHorizontalShader->activateShaders(); mBlurHorizontalShader->activateShaders();
@ -405,7 +405,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
} }
else if (vertices->shaders & SHADER_BLUR_VERTICAL) { else if (vertices->shaders & SHADER_BLUR_VERTICAL) {
if (mBlurVerticalShader == nullptr) if (mBlurVerticalShader == nullptr)
mBlurVerticalShader = RendererOpenGL::getShaderProgram(SHADER_BLUR_VERTICAL); mBlurVerticalShader = getShaderProgram(SHADER_BLUR_VERTICAL);
if (mBlurVerticalShader) { if (mBlurVerticalShader) {
if (mLastShader != mBlurVerticalShader) if (mLastShader != mBlurVerticalShader)
mBlurVerticalShader->activateShaders(); mBlurVerticalShader->activateShaders();
@ -422,7 +422,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
} }
else if (vertices->shaders & SHADER_SCANLINES) { else if (vertices->shaders & SHADER_SCANLINES) {
if (mScanlinelShader == nullptr) if (mScanlinelShader == nullptr)
mScanlinelShader = RendererOpenGL::getShaderProgram(SHADER_SCANLINES); mScanlinelShader = getShaderProgram(SHADER_SCANLINES);
float shaderWidth {width * 1.2f}; float shaderWidth {width * 1.2f};
// Scale the scanlines relative to screen resolution. // Scale the scanlines relative to screen resolution.
float screenHeightModifier {getScreenHeightModifier()}; float screenHeightModifier {getScreenHeightModifier()};

View file

@ -1,16 +1,16 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// Renderer_GL21.h // RendererOpenGL.h
// //
// OpenGL / OpenGL ES renderering functions. // OpenGL / OpenGL ES renderering functions.
// //
#ifndef ES_CORE_RENDERER_RENDERER_GL21_H #ifndef ES_CORE_RENDERER_RENDERER_OPENGL_H
#define ES_CORE_RENDERER_RENDERER_GL21_H #define ES_CORE_RENDERER_RENDERER_OPENGL_H
#include "Shader_GL21.h"
#include "renderers/Renderer.h" #include "renderers/Renderer.h"
#include "renderers/ShaderOpenGL.h"
#if defined(USE_OPENGLES) #if defined(USE_OPENGLES)
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
@ -28,7 +28,7 @@ public:
static RendererOpenGL* getInstance(); static RendererOpenGL* getInstance();
Shader* getShaderProgram(unsigned int shaderID); ShaderOpenGL* getShaderProgram(unsigned int shaderID);
bool loadShaders() override; bool loadShaders() override;
GLenum convertBlendFactor(const BlendFactor BlendFactorFactor); GLenum convertBlendFactor(const BlendFactor BlendFactorFactor);
@ -72,7 +72,7 @@ public:
unsigned char* textureRGBA = nullptr) override; unsigned char* textureRGBA = nullptr) override;
private: private:
std::vector<Shader*> mShaderProgramVector; std::vector<ShaderOpenGL*> mShaderProgramVector;
GLuint mShaderFBO1; GLuint mShaderFBO1;
GLuint mShaderFBO2; GLuint mShaderFBO2;
GLuint mVertexBuffer1; GLuint mVertexBuffer1;
@ -82,11 +82,11 @@ private:
GLuint mWhiteTexture; GLuint mWhiteTexture;
GLuint mPostProcTexture1; GLuint mPostProcTexture1;
GLuint mPostProcTexture2; GLuint mPostProcTexture2;
Shader* mCoreShader; ShaderOpenGL* mCoreShader;
Shader* mBlurHorizontalShader; ShaderOpenGL* mBlurHorizontalShader;
Shader* mBlurVerticalShader; ShaderOpenGL* mBlurVerticalShader;
Shader* mScanlinelShader; ShaderOpenGL* mScanlinelShader;
Shader* mLastShader; ShaderOpenGL* mLastShader;
}; };
#endif // ES_CORE_RENDERER_RENDERER_GL21_H #endif // ES_CORE_RENDERER_RENDERER_OPENGL_H

View file

@ -1,18 +1,18 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// Shader_GL21.cpp // ShaderOpenGL.cpp
// //
// OpenGL 2.1 GLSL shader functions. // OpenGL / OpenGL ES shader functions.
// //
#include "Shader_GL21.h" #include "ShaderOpenGL.h"
#include "Log.h" #include "Log.h"
#include "renderers/Renderer.h" #include "renderers/Renderer.h"
#include "resources/ResourceManager.h" #include "resources/ResourceManager.h"
Shader::Shader() ShaderOpenGL::ShaderOpenGL()
: mProgramID {0} : mProgramID {0}
, mShaderMVPMatrix {0} , mShaderMVPMatrix {0}
, mShaderPosition {0} , mShaderPosition {0}
@ -28,13 +28,13 @@ Shader::Shader()
{ {
} }
Shader::~Shader() ShaderOpenGL::~ShaderOpenGL()
{ {
// Delete the shader program when destroyed. // Delete the shader program when destroyed.
deleteProgram(mProgramID); deleteProgram(mProgramID);
} }
void Shader::loadShaderFile(const std::string& path, GLenum shaderType) void ShaderOpenGL::loadShaderFile(const std::string& path, GLenum shaderType)
{ {
std::string preprocessorDefines; std::string preprocessorDefines;
std::string shaderCode; std::string shaderCode;
@ -59,7 +59,7 @@ void Shader::loadShaderFile(const std::string& path, GLenum shaderType)
mShaderVector.push_back(std::make_tuple(path, preprocessorDefines + shaderCode, shaderType)); mShaderVector.push_back(std::make_tuple(path, preprocessorDefines + shaderCode, shaderType));
} }
bool Shader::createProgram() bool ShaderOpenGL::createProgram()
{ {
GLint programSuccess; GLint programSuccess;
@ -112,9 +112,9 @@ bool Shader::createProgram()
return true; return true;
} }
void Shader::deleteProgram(GLuint programID) { GL_CHECK_ERROR(glDeleteProgram(programID)); } void ShaderOpenGL::deleteProgram(GLuint programID) { GL_CHECK_ERROR(glDeleteProgram(programID)); }
void Shader::getVariableLocations(GLuint programID) void ShaderOpenGL::getVariableLocations(GLuint programID)
{ {
// Some of the variable names are chosen to be compatible with the RetroArch GLSL shaders. // Some of the variable names are chosen to be compatible with the RetroArch GLSL shaders.
mShaderMVPMatrix = glGetUniformLocation(mProgramID, "MVPMatrix"); mShaderMVPMatrix = glGetUniformLocation(mProgramID, "MVPMatrix");
@ -130,14 +130,14 @@ void Shader::getVariableLocations(GLuint programID)
mShaderPostProcessing = glGetUniformLocation(mProgramID, "postProcessing"); mShaderPostProcessing = glGetUniformLocation(mProgramID, "postProcessing");
} }
void Shader::setModelViewProjectionMatrix(glm::mat4 mvpMatrix) void ShaderOpenGL::setModelViewProjectionMatrix(glm::mat4 mvpMatrix)
{ {
if (mShaderMVPMatrix != GL_INVALID_VALUE && mShaderMVPMatrix != GL_INVALID_OPERATION) if (mShaderMVPMatrix != GL_INVALID_VALUE && mShaderMVPMatrix != GL_INVALID_OPERATION)
GL_CHECK_ERROR(glUniformMatrix4fv(mShaderMVPMatrix, 1, GL_FALSE, GL_CHECK_ERROR(glUniformMatrix4fv(mShaderMVPMatrix, 1, GL_FALSE,
reinterpret_cast<GLfloat*>(&mvpMatrix))); reinterpret_cast<GLfloat*>(&mvpMatrix)));
} }
void Shader::setAttribPointers() void ShaderOpenGL::setAttribPointers()
{ {
if (mShaderPosition != -1) if (mShaderPosition != -1)
GL_CHECK_ERROR(glVertexAttribPointer( GL_CHECK_ERROR(glVertexAttribPointer(
@ -154,61 +154,61 @@ void Shader::setAttribPointers()
reinterpret_cast<const void*>(offsetof(Renderer::Vertex, color)))); reinterpret_cast<const void*>(offsetof(Renderer::Vertex, color))));
} }
void Shader::setTextureSize(std::array<GLfloat, 2> shaderVec2) void ShaderOpenGL::setTextureSize(std::array<GLfloat, 2> shaderVec2)
{ {
if (mShaderTextureSize != -1) if (mShaderTextureSize != -1)
GL_CHECK_ERROR(glUniform2f(mShaderTextureSize, shaderVec2[0], shaderVec2[1])); GL_CHECK_ERROR(glUniform2f(mShaderTextureSize, shaderVec2[0], shaderVec2[1]));
} }
void Shader::setOpacity(GLfloat opacity) void ShaderOpenGL::setOpacity(GLfloat opacity)
{ {
if (mShaderOpacity != -1) if (mShaderOpacity != -1)
GL_CHECK_ERROR(glUniform1f(mShaderOpacity, opacity)); GL_CHECK_ERROR(glUniform1f(mShaderOpacity, opacity));
} }
void Shader::setSaturation(GLfloat saturation) void ShaderOpenGL::setSaturation(GLfloat saturation)
{ {
if (mShaderSaturation != -1) if (mShaderSaturation != -1)
GL_CHECK_ERROR(glUniform1f(mShaderSaturation, saturation)); GL_CHECK_ERROR(glUniform1f(mShaderSaturation, saturation));
} }
void Shader::setDimming(GLfloat dimming) void ShaderOpenGL::setDimming(GLfloat dimming)
{ {
if (mShaderDimming != -1) if (mShaderDimming != -1)
GL_CHECK_ERROR(glUniform1f(mShaderDimming, dimming)); GL_CHECK_ERROR(glUniform1f(mShaderDimming, dimming));
} }
void Shader::setBGRAToRGBA(GLboolean BGRAToRGBA) void ShaderOpenGL::setBGRAToRGBA(GLboolean BGRAToRGBA)
{ {
if (mShaderBGRAToRGBA != -1) if (mShaderBGRAToRGBA != -1)
GL_CHECK_ERROR(glUniform1i(mShaderBGRAToRGBA, BGRAToRGBA ? 1 : 0)); GL_CHECK_ERROR(glUniform1i(mShaderBGRAToRGBA, BGRAToRGBA ? 1 : 0));
} }
void Shader::setFont(GLboolean font) void ShaderOpenGL::setFont(GLboolean font)
{ {
if (mShaderFont != -1) if (mShaderFont != -1)
GL_CHECK_ERROR(glUniform1i(mShaderFont, font ? 1 : 0)); GL_CHECK_ERROR(glUniform1i(mShaderFont, font ? 1 : 0));
} }
void Shader::setPostProcessing(GLboolean postProcessing) void ShaderOpenGL::setPostProcessing(GLboolean postProcessing)
{ {
if (mShaderPostProcessing != -1) if (mShaderPostProcessing != -1)
GL_CHECK_ERROR(glUniform1i(mShaderPostProcessing, postProcessing ? 1 : 0)); GL_CHECK_ERROR(glUniform1i(mShaderPostProcessing, postProcessing ? 1 : 0));
} }
void Shader::activateShaders() void ShaderOpenGL::activateShaders()
{ {
// Install the shader program. // Install the shader program.
GL_CHECK_ERROR(glUseProgram(mProgramID)); GL_CHECK_ERROR(glUseProgram(mProgramID));
} }
void Shader::deactivateShaders() void ShaderOpenGL::deactivateShaders()
{ {
// Remove the shader program. // Remove the shader program.
GL_CHECK_ERROR(glUseProgram(0)); GL_CHECK_ERROR(glUseProgram(0));
} }
void Shader::printProgramInfoLog(GLuint programID) void ShaderOpenGL::printProgramInfoLog(GLuint programID)
{ {
if (glIsProgram(programID)) { if (glIsProgram(programID)) {
int logLength; int logLength;
@ -229,7 +229,7 @@ void Shader::printProgramInfoLog(GLuint programID)
} }
} }
void Shader::printShaderInfoLog(GLuint shaderID, GLenum shaderType, bool error) void ShaderOpenGL::printShaderInfoLog(GLuint shaderID, GLenum shaderType, bool error)
{ {
if (glIsShader(shaderID)) { if (glIsShader(shaderID)) {
int logLength; int logLength;

View file

@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// Shader_GL21.h // ShaderOpenGL.h
// //
// OpenGL 2.1 GLSL shader functions. // OpenGL / OpenGL ES shader functions.
// //
#ifndef ES_CORE_RENDERER_SHADER_GL21_H #ifndef ES_CORE_RENDERER_SHADER_OPENGL_H
#define ES_CORE_RENDERER_SHADER_GL21_H #define ES_CORE_RENDERER_SHADER_OPENGL_H
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
@ -49,11 +49,11 @@ static inline void _GLCheckError(const std::string& funcName)
#define GL_CHECK_ERROR(Function) (Function) #define GL_CHECK_ERROR(Function) (Function)
#endif #endif
class Shader class ShaderOpenGL
{ {
public: public:
Shader(); ShaderOpenGL();
~Shader(); ~ShaderOpenGL();
// Loads the shader source code only, no compilation done at this point. // Loads the shader source code only, no compilation done at this point.
void loadShaderFile(const std::string& path, GLenum shaderType); void loadShaderFile(const std::string& path, GLenum shaderType);
@ -102,4 +102,4 @@ private:
GLint mShaderPostProcessing; GLint mShaderPostProcessing;
}; };
#endif // ES_CORE_RENDERER_SHADER_GL21_H #endif // ES_CORE_RENDERER_SHADER_OPENGL_H