mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-17 22:55:38 +00:00
Some refactoring of the OpenGL renderer and TextureDataManager.
This commit is contained in:
parent
11b035affa
commit
7e923cb9b6
|
@ -52,7 +52,7 @@ void Renderer::setIcon()
|
|||
// Try creating SDL surface from logo data.
|
||||
SDL_Surface* logoSurface {SDL_CreateRGBSurfaceFrom(
|
||||
static_cast<void*>(rawData.data()), static_cast<int>(width), static_cast<int>(height),
|
||||
32, static_cast<int>((width * 4)), rmask, gmask, bmask, amask)};
|
||||
32, static_cast<int>(width * 4), rmask, gmask, bmask, amask)};
|
||||
|
||||
if (logoSurface != nullptr) {
|
||||
SDL_SetWindowIcon(mSDLWindow, logoSurface);
|
||||
|
@ -147,7 +147,7 @@ bool Renderer::createWindow()
|
|||
if (mWindowWidth != displayMode.w || mWindowHeight != displayMode.h)
|
||||
userResolution = true;
|
||||
|
||||
unsigned int windowFlags;
|
||||
unsigned int windowFlags {0};
|
||||
setup();
|
||||
|
||||
#if defined(_WIN64)
|
||||
|
@ -201,7 +201,7 @@ bool Renderer::createWindow()
|
|||
// instead we simply indicate the physical pixel dimensions in parenthesis in the log
|
||||
// file and make sure to double the window and screen sizes in case of a high DPI
|
||||
// display so that the full application window is used for rendering.
|
||||
int width = 0;
|
||||
int width {0};
|
||||
SDL_GL_GetDrawableSize(mSDLWindow, &width, nullptr);
|
||||
int scaleFactor = static_cast<int>(width / mWindowWidth);
|
||||
|
||||
|
@ -309,11 +309,11 @@ void Renderer::pushClipRect(const glm::ivec2& pos, const glm::ivec2& size)
|
|||
box.h = sScreenHeight - box.y;
|
||||
|
||||
if (mScreenRotated) {
|
||||
box = Rect(mWindowWidth - mScreenOffsetX - box.x - box.w,
|
||||
mWindowHeight - mScreenOffsetY - box.y - box.h, box.w, box.h);
|
||||
box = Rect {mWindowWidth - mScreenOffsetX - box.x - box.w,
|
||||
mWindowHeight - mScreenOffsetY - box.y - box.h, box.w, box.h};
|
||||
}
|
||||
else {
|
||||
box = Rect(mScreenOffsetX + box.x, mScreenOffsetY + box.y, box.w, box.h);
|
||||
box = Rect {mScreenOffsetX + box.x, mScreenOffsetY + box.y, box.w, box.h};
|
||||
}
|
||||
|
||||
// Make sure the box fits within mClipStack.top(), and clip further accordingly.
|
||||
|
@ -349,7 +349,7 @@ void Renderer::popClipRect()
|
|||
mClipStack.pop();
|
||||
|
||||
if (mClipStack.empty())
|
||||
setScissor(Rect(0, 0, 0, 0));
|
||||
setScissor(Rect {0, 0, 0, 0});
|
||||
else
|
||||
setScissor(mClipStack.top());
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ void Renderer::drawRect(const float x,
|
|||
const float h,
|
||||
const unsigned int color,
|
||||
const unsigned int colorEnd,
|
||||
bool horizontalGradient,
|
||||
const bool horizontalGradient,
|
||||
const float opacity,
|
||||
const float dimming,
|
||||
const BlendFactor srcBlendFactor,
|
||||
|
|
|
@ -146,7 +146,7 @@ public:
|
|||
const float h,
|
||||
const unsigned int color,
|
||||
const unsigned int colorEnd,
|
||||
bool horizontalGradient = false,
|
||||
const bool horizontalGradient = false,
|
||||
const float opacity = 1.0,
|
||||
const float dimming = 1.0,
|
||||
const BlendFactor srcBlendFactor = BlendFactor::SRC_ALPHA,
|
||||
|
|
|
@ -33,19 +33,13 @@ RendererOpenGL::RendererOpenGL() noexcept
|
|||
{
|
||||
}
|
||||
|
||||
RendererOpenGL::~RendererOpenGL()
|
||||
{
|
||||
for (auto it = mShaderProgramVector.cbegin(); it != mShaderProgramVector.cend(); ++it)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
RendererOpenGL* RendererOpenGL::getInstance()
|
||||
{
|
||||
static RendererOpenGL instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
ShaderOpenGL* RendererOpenGL::getShaderProgram(unsigned int shaderID)
|
||||
std::shared_ptr<ShaderOpenGL> RendererOpenGL::getShaderProgram(unsigned int shaderID)
|
||||
{
|
||||
unsigned int index {0};
|
||||
|
||||
|
@ -67,13 +61,13 @@ bool RendererOpenGL::loadShaders()
|
|||
LOG(LogInfo) << "Loading shaders...";
|
||||
|
||||
std::vector<std::string> shaderFiles;
|
||||
shaderFiles.push_back(":/shaders/glsl/core.glsl");
|
||||
shaderFiles.push_back(":/shaders/glsl/blur_horizontal.glsl");
|
||||
shaderFiles.push_back(":/shaders/glsl/blur_vertical.glsl");
|
||||
shaderFiles.push_back(":/shaders/glsl/scanlines.glsl");
|
||||
shaderFiles.emplace_back(":/shaders/glsl/core.glsl");
|
||||
shaderFiles.emplace_back(":/shaders/glsl/blur_horizontal.glsl");
|
||||
shaderFiles.emplace_back(":/shaders/glsl/blur_vertical.glsl");
|
||||
shaderFiles.emplace_back(":/shaders/glsl/scanlines.glsl");
|
||||
|
||||
for (auto it = shaderFiles.cbegin(); it != shaderFiles.cend(); ++it) {
|
||||
ShaderOpenGL* loadShader = new ShaderOpenGL();
|
||||
auto loadShader = std::make_shared<ShaderOpenGL>();
|
||||
|
||||
loadShader->loadShaderFile(*it, GL_VERTEX_SHADER);
|
||||
loadShader->loadShaderFile(*it, GL_FRAGMENT_SHADER);
|
||||
|
@ -83,7 +77,7 @@ bool RendererOpenGL::loadShaders()
|
|||
return false;
|
||||
}
|
||||
|
||||
mShaderProgramVector.push_back(loadShader);
|
||||
mShaderProgramVector.emplace_back(std::move(loadShader));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -576,7 +570,7 @@ void RendererOpenGL::shaderPostprocessing(unsigned int shaders,
|
|||
|
||||
for (size_t i = 0; i < shaderList.size(); ++i) {
|
||||
vertices->shaders = shaderList[i];
|
||||
int shaderPasses = 1;
|
||||
int shaderPasses {1};
|
||||
// For the blur shaders there is an optional variable to set the number of passes
|
||||
// to execute, which proportionally affects the blur amount.
|
||||
if (shaderList[i] == Renderer::Shader::BLUR_HORIZONTAL ||
|
||||
|
|
|
@ -20,15 +20,14 @@
|
|||
#include <SDL2/SDL_opengl.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
class RendererOpenGL : public Renderer
|
||||
{
|
||||
public:
|
||||
RendererOpenGL() noexcept;
|
||||
~RendererOpenGL();
|
||||
|
||||
static RendererOpenGL* getInstance();
|
||||
|
||||
ShaderOpenGL* getShaderProgram(unsigned int shaderID);
|
||||
std::shared_ptr<ShaderOpenGL> getShaderProgram(unsigned int shaderID);
|
||||
bool loadShaders() override;
|
||||
|
||||
GLenum convertBlendFactor(const BlendFactor BlendFactor);
|
||||
|
@ -73,7 +72,9 @@ public:
|
|||
unsigned char* textureRGBA = nullptr) override;
|
||||
|
||||
private:
|
||||
std::vector<ShaderOpenGL*> mShaderProgramVector;
|
||||
RendererOpenGL() noexcept;
|
||||
|
||||
std::vector<std::shared_ptr<ShaderOpenGL>> mShaderProgramVector;
|
||||
GLuint mShaderFBO1;
|
||||
GLuint mShaderFBO2;
|
||||
GLuint mVertexBuffer1;
|
||||
|
@ -83,14 +84,16 @@ private:
|
|||
GLuint mWhiteTexture;
|
||||
GLuint mPostProcTexture1;
|
||||
GLuint mPostProcTexture2;
|
||||
ShaderOpenGL* mCoreShader;
|
||||
ShaderOpenGL* mBlurHorizontalShader;
|
||||
ShaderOpenGL* mBlurVerticalShader;
|
||||
ShaderOpenGL* mScanlinelShader;
|
||||
ShaderOpenGL* mLastShader;
|
||||
std::shared_ptr<ShaderOpenGL> mCoreShader;
|
||||
std::shared_ptr<ShaderOpenGL> mBlurHorizontalShader;
|
||||
std::shared_ptr<ShaderOpenGL> mBlurVerticalShader;
|
||||
std::shared_ptr<ShaderOpenGL> mScanlinelShader;
|
||||
std::shared_ptr<ShaderOpenGL> mLastShader;
|
||||
|
||||
int mMajorGLVersion;
|
||||
int mMinorGLVersion;
|
||||
|
||||
friend Renderer;
|
||||
};
|
||||
|
||||
#endif // ES_CORE_RENDERER_RENDERER_OPENGL_H
|
||||
|
|
|
@ -24,13 +24,7 @@ TextureDataManager::TextureDataManager()
|
|||
data[i * 4 + 3] = 0;
|
||||
}
|
||||
mBlank->initFromRGBA(data, 5, 5);
|
||||
mLoader = new TextureLoader;
|
||||
}
|
||||
|
||||
TextureDataManager::~TextureDataManager()
|
||||
{
|
||||
// Delete TextureLoader object when destroyed.
|
||||
delete mLoader;
|
||||
mLoader = std::make_unique<TextureLoader>();
|
||||
}
|
||||
|
||||
std::shared_ptr<TextureData> TextureDataManager::add(const TextureResource* key, bool tiled)
|
||||
|
|
|
@ -63,7 +63,6 @@ class TextureDataManager
|
|||
{
|
||||
public:
|
||||
TextureDataManager();
|
||||
~TextureDataManager();
|
||||
|
||||
std::shared_ptr<TextureData> add(const TextureResource* key, bool tiled);
|
||||
|
||||
|
@ -90,7 +89,7 @@ private:
|
|||
std::map<const TextureResource*, std::list<std::shared_ptr<TextureData>>::const_iterator>
|
||||
mTextureLookup;
|
||||
std::shared_ptr<TextureData> mBlank;
|
||||
TextureLoader* mLoader;
|
||||
std::unique_ptr<TextureLoader> mLoader;
|
||||
};
|
||||
|
||||
#endif // ES_CORE_RESOURCES_TEXTURE_DATA_MANAGER_H
|
||||
|
|
Loading…
Reference in a new issue