diff --git a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp index 83f24daa03..0ec31d029a 100644 --- a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp @@ -14,18 +14,17 @@ *****************************************************************************/ #pragma endregion +#include #include #include #include #include -#include #include #include +#include #include #include "DrawingEngines.h" -#include - using namespace OpenRCT2; using namespace OpenRCT2::Drawing; using namespace OpenRCT2::Ui; @@ -121,7 +120,7 @@ private: } // Copy pixels from the virtual screen buffer to the surface - Memory::Copy(_surface->pixels, _bits, _surface->pitch * _surface->h); + std::copy_n(_bits, _surface->pitch * _surface->h, (uint8 *)_surface->pixels); // Unlock the surface if (SDL_MUSTLOCK(_surface)) diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp index 4a8d18f3be..2bc989f59c 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp @@ -16,29 +16,28 @@ #ifndef DISABLE_OPENGL +#include #include #include -#include #include #include +#include #include "OpenGLShaderProgram.h" -#include +using namespace OpenRCT2; OpenGLShader::OpenGLShader(const char * name, GLenum type) { _type = type; - utf8 path[MAX_PATH]; - GetPath(path, sizeof(path), name); - char * sourceCode = ReadSourceCode(path); + auto path = GetPath(name); + auto sourceCode = ReadSourceCode(path); + auto sourceCodeStr = sourceCode.c_str(); _id = glCreateShader(type); - glShaderSource(_id, 1, (const GLchar**)&sourceCode, nullptr); + glShaderSource(_id, 1, (const GLchar * *)&sourceCodeStr, nullptr); glCompileShader(_id); - Memory::Free(sourceCode); - GLint status; glGetShaderiv(_id, GL_COMPILE_STATUS, &status); if (status != GL_TRUE) @@ -47,7 +46,7 @@ OpenGLShader::OpenGLShader(const char * name, GLenum type) glGetShaderInfoLog(_id, sizeof(buffer), nullptr, buffer); glDeleteShader(_id); - Console::Error::WriteLine("Error compiling %s", path); + Console::Error::WriteLine("Error compiling %s", path.c_str()); Console::Error::WriteLine(buffer); throw std::runtime_error("Error compiling shader."); @@ -64,22 +63,23 @@ GLuint OpenGLShader::GetShaderId() return _id; } -void OpenGLShader::GetPath(char * buffer, size_t bufferSize, const char * name) +std::string OpenGLShader::GetPath(const std::string &name) { - platform_get_openrct_data_path(buffer, bufferSize); - Path::Append(buffer, bufferSize, "shaders"); - Path::Append(buffer, bufferSize, name); + auto env = GetContext()->GetPlatformEnvironment(); + auto shadersPath = env->GetDirectoryPath(DIRBASE::OPENRCT2, DIRID::SHADER); + auto path = Path::Combine(shadersPath, name); if (_type == GL_VERTEX_SHADER) { - String::Append(buffer, bufferSize, ".vert"); + path += ".vert"; } else { - String::Append(buffer, bufferSize, ".frag"); + path += ".frag"; } + return path; } -char * OpenGLShader::ReadSourceCode(const utf8 * path) +std::string OpenGLShader::ReadSourceCode(const std::string &path) { auto fs = FileStream(path, FILE_MODE_OPEN); @@ -89,9 +89,8 @@ char * OpenGLShader::ReadSourceCode(const utf8 * path) throw IOException("Shader source too large."); } - utf8 * fileData = Memory::Allocate((size_t)fileLength + 1); - fs.Read(fileData, fileLength); - fileData[fileLength] = '\0'; + auto fileData = std::string((size_t)fileLength + 1, '\0'); + fs.Read(fileData.data(), fileLength); return fileData; } diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.h b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.h index 16cf496693..1740d9897c 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.h +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include "OpenGLAPI.h" @@ -34,8 +35,8 @@ public: GLuint GetShaderId(); private: - void GetPath(char * buffer, size_t bufferSize, const char * name); - static char * ReadSourceCode(const utf8 * path); + std::string GetPath(const std::string &name); + static std::string ReadSourceCode(const std::string &path); }; class OpenGLShaderProgram diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 40b865ebc8..060fb00e81 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -214,7 +214,7 @@ const char * PlatformEnvironment::DirectoryNamesOpenRCT2[] = "scenario", // SCENARIO "screenshot", // SCREENSHOT "sequence", // SEQUENCE - "shader", // SHADER + "shaders", // SHADER "themes", // THEME "track", // TRACK };