Changed some variables names and debug logging info for the OpenGL renderer.

Also simplified a pixel conversion in the core.glsl shader.
This commit is contained in:
Leon Styhre 2022-03-15 17:14:55 +01:00
parent 1abfc06038
commit 29501af68f
5 changed files with 19 additions and 21 deletions

View file

@ -363,8 +363,8 @@ void Renderer::drawRect(const float x,
bool horizontalGradient, bool horizontalGradient,
const float opacity, const float opacity,
const float dimming, const float dimming,
const BlendFactor srcBlendFactorFactor, const BlendFactor srcBlendFactor,
const BlendFactor dstBlendFactorFactor) const BlendFactor dstBlendFactor)
{ {
Vertex vertices[4]; Vertex vertices[4];
@ -393,5 +393,5 @@ void Renderer::drawRect(const float x,
vertices->dimming = dimming; vertices->dimming = dimming;
bindTexture(0); bindTexture(0);
drawTriangleStrips(vertices, 4, srcBlendFactorFactor, dstBlendFactorFactor); drawTriangleStrips(vertices, 4, srcBlendFactor, dstBlendFactor);
} }

View file

@ -87,10 +87,10 @@ bool RendererOpenGL::loadShaders()
return true; return true;
} }
GLenum RendererOpenGL::convertBlendFactor(const BlendFactor BlendFactorFactor) GLenum RendererOpenGL::convertBlendFactor(const BlendFactor BlendFactor)
{ {
// clang-format off // clang-format off
switch (BlendFactorFactor) { switch (BlendFactor) {
case BlendFactor::ZERO: { return GL_ZERO; } break; case BlendFactor::ZERO: { return GL_ZERO; } break;
case BlendFactor::ONE: { return GL_ONE; } break; case BlendFactor::ONE: { return GL_ONE; } break;
case BlendFactor::SRC_COLOR: { return GL_SRC_COLOR; } break; case BlendFactor::SRC_COLOR: { return GL_SRC_COLOR; } break;
@ -168,13 +168,11 @@ bool RendererOpenGL::createContext()
LOG(LogInfo) << "GL version: " << version; LOG(LogInfo) << "GL version: " << version;
#if defined(_WIN64) #if defined(_WIN64)
LOG(LogInfo) << "EmulationStation renderer: OpenGL 3.3 with GLEW"; LOG(LogInfo) << "EmulationStation renderer: OpenGL 3.3 with GLEW";
#else #elif defined(USE_OPENGLES)
#if defined(USE_OPENGLES)
LOG(LogInfo) << "EmulationStation renderer: OpenGL ES 3.0"; LOG(LogInfo) << "EmulationStation renderer: OpenGL ES 3.0";
#else #else
LOG(LogInfo) << "EmulationStation renderer: OpenGL 3.3"; LOG(LogInfo) << "EmulationStation renderer: OpenGL 3.3";
#endif #endif
#endif
#if !defined(USE_OPENGLES) #if !defined(USE_OPENGLES)
// TODO: Fix the issue that causes the first glClearColor function call to fail. // TODO: Fix the issue that causes the first glClearColor function call to fail.
@ -356,14 +354,14 @@ void RendererOpenGL::bindTexture(const unsigned int texture)
void RendererOpenGL::drawTriangleStrips(const Vertex* vertices, void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
const unsigned int numVertices, const unsigned int numVertices,
const BlendFactor srcBlendFactorFactor, const BlendFactor srcBlendFactor,
const BlendFactor dstBlendFactorFactor) const BlendFactor dstBlendFactor)
{ {
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(convertBlendFactor(srcBlendFactorFactor), GL_CHECK_ERROR(
convertBlendFactor(dstBlendFactorFactor))); glBlendFunc(convertBlendFactor(srcBlendFactor), convertBlendFactor(dstBlendFactor)));
if (vertices->shaders == 0 || vertices->shaders & Shader::CORE) { if (vertices->shaders == 0 || vertices->shaders & Shader::CORE) {
if (mCoreShader == nullptr) if (mCoreShader == nullptr)

View file

@ -31,7 +31,7 @@ public:
ShaderOpenGL* getShaderProgram(unsigned int shaderID); ShaderOpenGL* getShaderProgram(unsigned int shaderID);
bool loadShaders() override; bool loadShaders() override;
GLenum convertBlendFactor(const BlendFactor BlendFactorFactor); GLenum convertBlendFactor(const BlendFactor BlendFactor);
GLenum convertTextureType(const TextureType type); GLenum convertTextureType(const TextureType type);
void setup() override; void setup() override;

View file

@ -75,8 +75,8 @@ bool ShaderOpenGL::createProgram()
glGetShaderiv(currentShader, GL_COMPILE_STATUS, &shaderCompiled); glGetShaderiv(currentShader, GL_COMPILE_STATUS, &shaderCompiled);
if (shaderCompiled != GL_TRUE) { if (shaderCompiled != GL_TRUE) {
LOG(LogError) << "OpenGL error: Unable to compile shader " << currentShader << " (" LOG(LogError) << "ShaderOpenGL::createProgram(): Unable to compile shader "
<< std::get<0>(*it) << ")."; << currentShader << " (" << std::get<0>(*it) << ")";
printShaderInfoLog(currentShader, std::get<2>(*it), true); printShaderInfoLog(currentShader, std::get<2>(*it), true);
return false; return false;
} }
@ -91,7 +91,7 @@ bool ShaderOpenGL::createProgram()
glGetProgramiv(mProgramID, GL_LINK_STATUS, &programSuccess); glGetProgramiv(mProgramID, GL_LINK_STATUS, &programSuccess);
if (programSuccess != GL_TRUE) { if (programSuccess != GL_TRUE) {
LOG(LogError) << "OpenGL error: Unable to link program " << mProgramID << "."; LOG(LogError) << "ShaderOpenGL::createProgram(): Unable to link program " << mProgramID;
printProgramInfoLog(mProgramID); printProgramInfoLog(mProgramID);
return false; return false;
} }
@ -204,12 +204,12 @@ void ShaderOpenGL::printProgramInfoLog(GLuint programID)
glGetProgramInfoLog(programID, maxLength, &logLength, &infoLog.front()); glGetProgramInfoLog(programID, maxLength, &logLength, &infoLog.front());
if (logLength > 0) { if (logLength > 0) {
LOG(LogDebug) << "Renderer_GL21::printProgramInfoLog():\n" LOG(LogDebug) << "ShaderOpenGL::createProgram()::\n"
<< std::string(infoLog.begin(), infoLog.end()); << std::string(infoLog.begin(), infoLog.end());
} }
} }
else { else {
LOG(LogError) << "OpenGL error: " << programID << " is not a program."; LOG(LogError) << "ShaderOpenGL::createProgram(): " << programID << " is not a program";
} }
} }
@ -228,7 +228,7 @@ void ShaderOpenGL::printShaderInfoLog(GLuint shaderID, GLenum shaderType, bool e
glGetShaderInfoLog(shaderID, maxLength, &logLength, &infoLog.front()); glGetShaderInfoLog(shaderID, maxLength, &logLength, &infoLog.front());
if (logLength > 0) { if (logLength > 0) {
LOG(LogDebug) << "Shader_GL21::printShaderInfoLog(): " << (error ? "Error" : "Warning") LOG(LogDebug) << "ShaderOpenGL::createProgram(): " << (error ? "Error" : "Warning")
<< " in " << " in "
<< (shaderType == GL_VERTEX_SHADER ? "VERTEX section:\n" : << (shaderType == GL_VERTEX_SHADER ? "VERTEX section:\n" :
"FRAGMENT section:\n") "FRAGMENT section:\n")
@ -236,6 +236,6 @@ void ShaderOpenGL::printShaderInfoLog(GLuint shaderID, GLenum shaderType, bool e
} }
} }
else { else {
LOG(LogError) << "OpenGL error: " << shaderID << " is not a shader."; LOG(LogError) << "ShaderOpenGL::createProgram():: " << shaderID << " is not a shader";
} }
} }

View file

@ -81,7 +81,7 @@ void main()
// BGRA to RGBA conversion. // BGRA to RGBA conversion.
if (0u != (shaderFlags & 1u)) if (0u != (shaderFlags & 1u))
sampledColor = vec4(sampledColor.bgr, sampledColor.a); sampledColor = sampledColor.bgra;
FragColor = sampledColor; FragColor = sampledColor;
} }