clang-format UI drawing

This commit is contained in:
clang-format 2018-06-22 23:20:09 +02:00 committed by Hielke Morsink
parent ebb17929a7
commit 16720f0182
28 changed files with 778 additions and 566 deletions

View File

@ -7,14 +7,15 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <stdexcept>
#include <cstring>
#include <SDL2/SDL.h>
#include <openrct2/core/Imaging.h>
#include "BitmapReader.h"
static std::vector<uint8_t> ReadToVector(std::istream &stream)
#include <SDL2/SDL.h>
#include <algorithm>
#include <cstring>
#include <openrct2/core/Imaging.h>
#include <stdexcept>
static std::vector<uint8_t> ReadToVector(std::istream& stream)
{
std::vector<uint8_t> result;
if (!stream.eof() && !stream.fail())
@ -23,14 +24,14 @@ static std::vector<uint8_t> ReadToVector(std::istream &stream)
auto size = stream.tellg();
result.resize(size);
stream.seekg(0, std::ios_base::beg);
stream.read((char *)result.data(), size);
stream.read((char*)result.data(), size);
}
return result;
}
// TODO Bitmaps aren't very complicated to read so we should probably just write our
// own implementation in libopenrct2 and spare the AOT implementation registration.
static Image ReadBitmap(std::istream &istream, IMAGE_FORMAT format)
static Image ReadBitmap(std::istream& istream, IMAGE_FORMAT format)
{
auto buffer = ReadToVector(istream);
auto sdlStream = SDL_RWFromConstMem(buffer.data(), (int)buffer.size());
@ -58,7 +59,7 @@ static Image ReadBitmap(std::istream &istream, IMAGE_FORMAT format)
std::fill(image.Pixels.begin(), image.Pixels.end(), 0xFF);
// Copy pixels over
auto src = (const uint8_t *)bitmap->pixels;
auto src = (const uint8_t*)bitmap->pixels;
auto dst = image.Pixels.data();
if (numChannels == 4)
{

View File

@ -30,21 +30,23 @@ namespace OpenRCT2
class DrawingEngineFactory final : public IDrawingEngineFactory
{
public:
std::unique_ptr<IDrawingEngine> Create(DRAWING_ENGINE_TYPE type, const std::shared_ptr<IUiContext>& uiContext) override
std::unique_ptr<IDrawingEngine>
Create(DRAWING_ENGINE_TYPE type, const std::shared_ptr<IUiContext>& uiContext) override
{
switch ((int32_t)type) {
case DRAWING_ENGINE_SOFTWARE:
return CreateSoftwareDrawingEngine(uiContext);
case DRAWING_ENGINE_SOFTWARE_WITH_HARDWARE_DISPLAY:
return CreateHardwareDisplayDrawingEngine(uiContext);
switch ((int32_t)type)
{
case DRAWING_ENGINE_SOFTWARE:
return CreateSoftwareDrawingEngine(uiContext);
case DRAWING_ENGINE_SOFTWARE_WITH_HARDWARE_DISPLAY:
return CreateHardwareDisplayDrawingEngine(uiContext);
#ifndef DISABLE_OPENGL
case DRAWING_ENGINE_OPENGL:
return CreateOpenGLDrawingEngine(uiContext);
case DRAWING_ENGINE_OPENGL:
return CreateOpenGLDrawingEngine(uiContext);
#endif
default:
return nullptr;
default:
return nullptr;
}
}
};
}
}
} // namespace Ui
} // namespace OpenRCT2

View File

@ -7,19 +7,19 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <cmath>
#include <vector>
#include <openrct2/common.h>
#include <SDL2/SDL.h>
#include <openrct2/config/Config.h>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/drawing/X8DrawingEngine.h>
#include <openrct2/ui/UiContext.h>
#include "DrawingEngineFactory.hpp"
#include <openrct2/drawing/LightFX.h>
#include <SDL2/SDL.h>
#include <cmath>
#include <openrct2/Game.h>
#include <openrct2/common.h>
#include <openrct2/config/Config.h>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/drawing/LightFX.h>
#include <openrct2/drawing/X8DrawingEngine.h>
#include <openrct2/paint/Paint.h>
#include <openrct2/ui/UiContext.h>
#include <vector>
using namespace OpenRCT2;
using namespace OpenRCT2::Drawing;
@ -31,33 +31,33 @@ private:
constexpr static uint32_t DIRTY_VISUAL_TIME = 32;
std::shared_ptr<IUiContext> const _uiContext;
SDL_Window * _window = nullptr;
SDL_Renderer * _sdlRenderer = nullptr;
SDL_Texture * _screenTexture = nullptr;
SDL_Texture * _scaledScreenTexture = nullptr;
SDL_PixelFormat * _screenTextureFormat = nullptr;
uint32_t _paletteHWMapped[256] = { 0 };
SDL_Window* _window = nullptr;
SDL_Renderer* _sdlRenderer = nullptr;
SDL_Texture* _screenTexture = nullptr;
SDL_Texture* _scaledScreenTexture = nullptr;
SDL_PixelFormat* _screenTextureFormat = nullptr;
uint32_t _paletteHWMapped[256] = { 0 };
#ifdef __ENABLE_LIGHTFX__
uint32_t _lightPaletteHWMapped[256] = { 0 };
uint32_t _lightPaletteHWMapped[256] = { 0 };
#endif
// Steam overlay checking
uint32_t _pixelBeforeOverlay = 0;
uint32_t _pixelAfterOverlay = 0;
bool _overlayActive = false;
bool _pausedBeforeOverlay = false;
bool _useVsync = true;
uint32_t _pixelBeforeOverlay = 0;
uint32_t _pixelAfterOverlay = 0;
bool _overlayActive = false;
bool _pausedBeforeOverlay = false;
bool _useVsync = true;
std::vector<uint32_t> _dirtyVisualsTime;
bool smoothNN = false;
bool smoothNN = false;
public:
explicit HardwareDisplayDrawingEngine(const std::shared_ptr<IUiContext>& uiContext)
: X8DrawingEngine(uiContext),
_uiContext(uiContext)
: X8DrawingEngine(uiContext)
, _uiContext(uiContext)
{
_window = (SDL_Window *)_uiContext->GetWindow();
_window = (SDL_Window*)_uiContext->GetWindow();
}
~HardwareDisplayDrawingEngine() override
@ -109,9 +109,8 @@ public:
for (uint32_t i = 0; i < rendererInfo.num_texture_formats; i++)
{
uint32_t format = rendererInfo.texture_formats[i];
if (!SDL_ISPIXELFORMAT_FOURCC(format) &&
!SDL_ISPIXELFORMAT_INDEXED(format) &&
(pixelFormat == SDL_PIXELFORMAT_UNKNOWN || SDL_BYTESPERPIXEL(format) < SDL_BYTESPERPIXEL(pixelFormat)))
if (!SDL_ISPIXELFORMAT_FOURCC(format) && !SDL_ISPIXELFORMAT_INDEXED(format)
&& (pixelFormat == SDL_PIXELFORMAT_UNKNOWN || SDL_BYTESPERPIXEL(format) < SDL_BYTESPERPIXEL(pixelFormat)))
{
pixelFormat = format;
}
@ -142,13 +141,13 @@ public:
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaleQualityBuffer);
uint32_t scale = std::ceil(gConfigGeneral.window_scale);
_scaledScreenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_TARGET,
width * scale, height * scale);
_scaledScreenTexture
= SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_TARGET, width * scale, height * scale);
}
else
{
_screenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_STREAMING,width, height);
}
_screenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_STREAMING, width, height);
}
uint32_t format;
SDL_QueryTexture(_screenTexture, &format, nullptr, nullptr, nullptr);
@ -157,7 +156,7 @@ public:
ConfigureBits(width, height, width);
}
void SetPalette(const rct_palette_entry * palette) override
void SetPalette(const rct_palette_entry* palette) override
{
if (_screenTextureFormat != nullptr)
{
@ -212,7 +211,7 @@ private:
#ifdef __ENABLE_LIGHTFX__
if (gConfigGeneral.enable_light_fx)
{
void * pixels;
void* pixels;
int32_t pitch;
if (SDL_LockTexture(_screenTexture, nullptr, &pixels, &pitch) == 0)
{
@ -229,7 +228,7 @@ private:
{
SDL_SetRenderTarget(_sdlRenderer, _scaledScreenTexture);
SDL_RenderCopy(_sdlRenderer, _screenTexture, nullptr, nullptr);
SDL_SetRenderTarget(_sdlRenderer, nullptr);
SDL_RenderCopy(_sdlRenderer, _scaledScreenTexture, nullptr, nullptr);
}
@ -257,16 +256,16 @@ private:
}
}
void CopyBitsToTexture(SDL_Texture * texture, uint8_t * src, int32_t width, int32_t height, const uint32_t * palette)
void CopyBitsToTexture(SDL_Texture* texture, uint8_t* src, int32_t width, int32_t height, const uint32_t* palette)
{
void * pixels;
int32_t pitch;
void* pixels;
int32_t pitch;
if (SDL_LockTexture(texture, nullptr, &pixels, &pitch) == 0)
{
int32_t padding = pitch - (width * 4);
if (pitch == width * 4)
{
uint32_t * dst = (uint32_t *)pixels;
uint32_t* dst = (uint32_t*)pixels;
for (int32_t i = width * height; i > 0; i--)
{
*dst++ = palette[*src++];
@ -276,26 +275,26 @@ private:
{
if (pitch == (width * 2) + padding)
{
uint16_t * dst = (uint16_t *)pixels;
uint16_t* dst = (uint16_t*)pixels;
for (int32_t y = height; y > 0; y--)
{
for (int32_t x = width; x > 0; x--)
{
const uint8_t lower = *(uint8_t *)(&palette[*src++]);
const uint8_t upper = *(uint8_t *)(&palette[*src++]);
const uint8_t lower = *(uint8_t*)(&palette[*src++]);
const uint8_t upper = *(uint8_t*)(&palette[*src++]);
*dst++ = (lower << 8) | upper;
}
dst = (uint16_t*)(((uint8_t *)dst) + padding);
dst = (uint16_t*)(((uint8_t*)dst) + padding);
}
}
else if (pitch == width + padding)
{
uint8_t * dst = (uint8_t *)pixels;
uint8_t* dst = (uint8_t*)pixels;
for (int32_t y = height; y > 0; y--)
{
for (int32_t x = width; x > 0; x--)
{
*dst++ = *(uint8_t *)(&palette[*src++]);
*dst++ = *(uint8_t*)(&palette[*src++]);
}
dst += padding;
}
@ -369,7 +368,7 @@ private:
}
}
void ReadCentrePixel(uint32_t * pixel)
void ReadCentrePixel(uint32_t* pixel)
{
SDL_Rect centrePixelRegion = { (int32_t)(_width / 2), (int32_t)(_height / 2), 1, 1 };
SDL_RenderReadPixels(_sdlRenderer, &centrePixelRegion, SDL_PIXELFORMAT_RGBA8888, pixel, sizeof(uint32_t));

View File

@ -7,16 +7,17 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2/common.h>
#include "DrawingEngineFactory.hpp"
#include <SDL2/SDL.h>
#include <algorithm>
#include <openrct2/Game.h>
#include <openrct2/common.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/drawing/X8DrawingEngine.h>
#include <openrct2/Game.h>
#include <openrct2/ui/UiContext.h>
#include "DrawingEngineFactory.hpp"
using namespace OpenRCT2;
using namespace OpenRCT2::Drawing;
@ -26,17 +27,17 @@ class SoftwareDrawingEngine final : public X8DrawingEngine
{
private:
std::shared_ptr<IUiContext> const _uiContext;
SDL_Window * _window = nullptr;
SDL_Surface * _surface = nullptr;
SDL_Surface * _RGBASurface = nullptr;
SDL_Palette * _palette = nullptr;
SDL_Window* _window = nullptr;
SDL_Surface* _surface = nullptr;
SDL_Surface* _RGBASurface = nullptr;
SDL_Palette* _palette = nullptr;
public:
explicit SoftwareDrawingEngine(const std::shared_ptr<IUiContext>& uiContext)
: X8DrawingEngine(uiContext),
_uiContext(uiContext)
: X8DrawingEngine(uiContext)
, _uiContext(uiContext)
{
_window = (SDL_Window *)_uiContext->GetWindow();
_window = (SDL_Window*)_uiContext->GetWindow();
}
~SoftwareDrawingEngine() override
@ -61,9 +62,7 @@ public:
SDL_SetSurfaceBlendMode(_RGBASurface, SDL_BLENDMODE_NONE);
_palette = SDL_AllocPalette(256);
if (_surface == nullptr ||
_palette == nullptr ||
_RGBASurface == nullptr)
if (_surface == nullptr || _palette == nullptr || _RGBASurface == nullptr)
{
log_fatal("%p || %p || %p == nullptr %s", _surface, _palette, _RGBASurface, SDL_GetError());
exit(-1);
@ -78,13 +77,14 @@ public:
ConfigureBits(width, height, _surface->pitch);
}
void SetPalette(const rct_palette_entry * palette) override
void SetPalette(const rct_palette_entry* palette) override
{
SDL_Surface * windowSurface = SDL_GetWindowSurface(_window);
SDL_Surface* windowSurface = SDL_GetWindowSurface(_window);
if (windowSurface != nullptr && _palette != nullptr)
{
SDL_Colour colours[256];
for (int32_t i = 0; i < 256; i++) {
for (int32_t i = 0; i < 256; i++)
{
colours[i].r = palette[i].red;
colours[i].g = palette[i].green;
colours[i].b = palette[i].blue;
@ -113,7 +113,7 @@ private:
}
// Copy pixels from the virtual screen buffer to the surface
std::copy_n(_bits, _surface->pitch * _surface->h, (uint8_t *)_surface->pixels);
std::copy_n(_bits, _surface->pitch * _surface->h, (uint8_t*)_surface->pixels);
// Unlock the surface
if (SDL_MUSTLOCK(_surface))
@ -124,7 +124,7 @@ private:
// Copy the surface to the window
if (gConfigGeneral.window_scale == 1 || gConfigGeneral.window_scale <= 0)
{
SDL_Surface * windowSurface = SDL_GetWindowSurface(_window);
SDL_Surface* windowSurface = SDL_GetWindowSurface(_window);
if (SDL_BlitSurface(_surface, nullptr, windowSurface, nullptr))
{
log_fatal("SDL_BlitSurface %s", SDL_GetError());

View File

@ -18,17 +18,17 @@ namespace
GLfloat position[2];
GLfloat texturecoordinate[2];
};
}
} // namespace
constexpr VDStruct VertexData[4] =
{
constexpr VDStruct VertexData[4] = {
{ -1.0f, -1.0f, 0.0f, 0.0f },
{ 1.0f, -1.0f, 1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f },
{ 1.0f, -1.0f, 1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f },
};
ApplyPaletteShader::ApplyPaletteShader() : OpenGLShaderProgram("applypalette")
ApplyPaletteShader::ApplyPaletteShader()
: OpenGLShaderProgram("applypalette")
{
GetLocations();
@ -39,8 +39,9 @@ ApplyPaletteShader::ApplyPaletteShader() : OpenGLShaderProgram("applypalette")
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW);
glBindVertexArray(_vao);
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, position));
glVertexAttribPointer(vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, texturecoordinate));
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position));
glVertexAttribPointer(
vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate));
glEnableVertexAttribArray(vPosition);
glEnableVertexAttribArray(vTextureCoordinate);
@ -57,11 +58,11 @@ ApplyPaletteShader::~ApplyPaletteShader()
void ApplyPaletteShader::GetLocations()
{
uTexture = GetUniformLocation("uTexture");
uPalette = GetUniformLocation("uPalette");
uTexture = GetUniformLocation("uTexture");
uPalette = GetUniformLocation("uPalette");
vPosition = GetAttributeLocation("vPosition");
vTextureCoordinate = GetAttributeLocation("vTextureCoordinate");
vPosition = GetAttributeLocation("vPosition");
vTextureCoordinate = GetAttributeLocation("vTextureCoordinate");
}
void ApplyPaletteShader::SetTexture(GLuint texture)
@ -69,9 +70,9 @@ void ApplyPaletteShader::SetTexture(GLuint texture)
OpenGLAPI::SetTexture(0, GL_TEXTURE_2D, texture);
}
void ApplyPaletteShader::SetPalette(const vec4 * glPalette)
void ApplyPaletteShader::SetPalette(const vec4* glPalette)
{
glUniform4fv(uPalette, 256, (const GLfloat *)glPalette);
glUniform4fv(uPalette, 256, (const GLfloat*)glPalette);
}
void ApplyPaletteShader::Draw()

View File

@ -29,7 +29,7 @@ public:
~ApplyPaletteShader() override;
void SetTexture(GLuint texture);
void SetPalette(const vec4 * glPalette);
void SetPalette(const vec4* glPalette);
void Draw();

View File

@ -18,17 +18,17 @@ namespace
GLfloat position[2];
GLfloat texturecoordinate[2];
};
}
} // namespace
constexpr VDStruct VertexData[4] =
{
constexpr VDStruct VertexData[4] = {
{ -1.0f, -1.0f, 0.0f, 0.0f },
{ 1.0f, -1.0f, 1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f },
{ 1.0f, -1.0f, 1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f },
};
ApplyTransparencyShader::ApplyTransparencyShader() : OpenGLShaderProgram("applytransparency")
ApplyTransparencyShader::ApplyTransparencyShader()
: OpenGLShaderProgram("applytransparency")
{
GetLocations();
@ -39,8 +39,9 @@ ApplyTransparencyShader::ApplyTransparencyShader() : OpenGLShaderProgram("applyt
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW);
glBindVertexArray(_vao);
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, position));
glVertexAttribPointer(vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, texturecoordinate));
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position));
glVertexAttribPointer(
vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate));
glEnableVertexAttribArray(vPosition);
glEnableVertexAttribArray(vTextureCoordinate);
@ -61,19 +62,18 @@ ApplyTransparencyShader::~ApplyTransparencyShader()
void ApplyTransparencyShader::GetLocations()
{
uOpaqueTex = GetUniformLocation("uOpaqueTex");
uOpaqueDepth = GetUniformLocation("uOpaqueDepth");
uTransparentTex = GetUniformLocation("uTransparentTex");
uTransparentDepth = GetUniformLocation("uTransparentDepth");
uPaletteTex = GetUniformLocation("uPaletteTex");
uOpaqueTex = GetUniformLocation("uOpaqueTex");
uOpaqueDepth = GetUniformLocation("uOpaqueDepth");
uTransparentTex = GetUniformLocation("uTransparentTex");
uTransparentDepth = GetUniformLocation("uTransparentDepth");
uPaletteTex = GetUniformLocation("uPaletteTex");
vPosition = GetAttributeLocation("vPosition");
vTextureCoordinate = GetAttributeLocation("vTextureCoordinate");
vPosition = GetAttributeLocation("vPosition");
vTextureCoordinate = GetAttributeLocation("vTextureCoordinate");
}
void ApplyTransparencyShader::SetTextures(GLuint opaqueTex, GLuint opaqueDepth,
GLuint transparentTex, GLuint transparentDepth,
GLuint paletteTex)
void ApplyTransparencyShader::SetTextures(
GLuint opaqueTex, GLuint opaqueDepth, GLuint transparentTex, GLuint transparentDepth, GLuint paletteTex)
{
OpenGLAPI::SetTexture(0, GL_TEXTURE_2D, opaqueTex);
OpenGLAPI::SetTexture(1, GL_TEXTURE_2D, opaqueDepth);

View File

@ -31,9 +31,7 @@ public:
ApplyTransparencyShader();
~ApplyTransparencyShader() override;
void SetTextures(GLuint opaqueTex, GLuint opaqueDepth,
GLuint transparentTex, GLuint transparentDepth,
GLuint paletteTex);
void SetTextures(GLuint opaqueTex, GLuint opaqueDepth, GLuint transparentTex, GLuint transparentDepth, GLuint paletteTex);
void Draw();
private:

View File

@ -9,14 +9,14 @@
#pragma once
#include <openrct2/common.h>
#include <vector>
#include "OpenGLAPI.h"
#include "GLSLTypes.h"
#include "OpenGLAPI.h"
#include "TextureCache.h"
template<typename T>
class CommandBatch
#include <openrct2/common.h>
#include <vector>
template<typename T> class CommandBatch
{
private:
std::vector<T> _instances;
@ -43,7 +43,7 @@ public:
}
return _instances[_numInstances++];
}
T& insert(const T &value)
T& insert(const T& value)
{
if (_numInstances + 1 > _instances.size())
{

View File

@ -10,6 +10,7 @@
#ifndef DISABLE_OPENGL
#include "DrawLineShader.h"
#include "OpenGLFramebuffer.h"
namespace
@ -18,15 +19,15 @@ namespace
{
GLfloat mat[4][2];
};
}
} // namespace
constexpr VDStruct VertexData[2] =
{
constexpr VDStruct VertexData[2] = {
{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
};
DrawLineShader::DrawLineShader() : OpenGLShaderProgram("drawline")
DrawLineShader::DrawLineShader()
: OpenGLShaderProgram("drawline")
{
GetLocations();
@ -38,21 +39,21 @@ DrawLineShader::DrawLineShader() : OpenGLShaderProgram("drawline")
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW);
glBindVertexArray(_vao);
glVertexAttribPointer(vVertMat+0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[0]));
glVertexAttribPointer(vVertMat+1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[1]));
glVertexAttribPointer(vVertMat+2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[2]));
glVertexAttribPointer(vVertMat+3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[3]));
glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0]));
glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1]));
glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2]));
glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3]));
glBindBuffer(GL_ARRAY_BUFFER, _vboInstances);
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), (void*) offsetof(DrawLineCommand, clip));
glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawLineCommand), (void*) offsetof(DrawLineCommand, bounds));
glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), (void*) offsetof(DrawLineCommand, colour));
glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawLineCommand), (void*) offsetof(DrawLineCommand, depth));
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, clip));
glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, bounds));
glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, colour));
glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, depth));
glEnableVertexAttribArray(vVertMat+0);
glEnableVertexAttribArray(vVertMat+1);
glEnableVertexAttribArray(vVertMat+2);
glEnableVertexAttribArray(vVertMat+3);
glEnableVertexAttribArray(vVertMat + 0);
glEnableVertexAttribArray(vVertMat + 1);
glEnableVertexAttribArray(vVertMat + 2);
glEnableVertexAttribArray(vVertMat + 3);
glEnableVertexAttribArray(vClip);
glEnableVertexAttribArray(vBounds);
@ -77,12 +78,12 @@ void DrawLineShader::GetLocations()
{
uScreenSize = GetUniformLocation("uScreenSize");
vClip = GetAttributeLocation("vClip");
vBounds = GetAttributeLocation("vBounds");
vColour = GetAttributeLocation("vColour");
vDepth = GetAttributeLocation("vDepth");
vClip = GetAttributeLocation("vClip");
vBounds = GetAttributeLocation("vBounds");
vColour = GetAttributeLocation("vColour");
vDepth = GetAttributeLocation("vDepth");
vVertMat = GetAttributeLocation("vVertMat");
vVertMat = GetAttributeLocation("vVertMat");
}
void DrawLineShader::SetScreenSize(int32_t width, int32_t height)

View File

@ -9,9 +9,9 @@
#pragma once
#include "DrawCommands.h"
#include "GLSLTypes.h"
#include "OpenGLShaderProgram.h"
#include "DrawCommands.h"
class DrawLineShader final : public OpenGLShaderProgram
{

View File

@ -18,17 +18,17 @@ namespace
GLfloat mat[4][2];
GLfloat vec[2];
};
}
} // namespace
constexpr VDStruct VertexData[4] =
{
constexpr VDStruct VertexData[4] = {
{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
{ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
};
DrawRectShader::DrawRectShader() : OpenGLShaderProgram("drawrect")
DrawRectShader::DrawRectShader()
: OpenGLShaderProgram("drawrect")
{
GetLocations();
@ -41,28 +41,31 @@ DrawRectShader::DrawRectShader() : OpenGLShaderProgram("drawrect")
glBindVertexArray(_vao);
glVertexAttribPointer(vVertMat+0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[0]));
glVertexAttribPointer(vVertMat+1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[1]));
glVertexAttribPointer(vVertMat+2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[2]));
glVertexAttribPointer(vVertMat+3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, mat[3]));
glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*) offsetof(VDStruct, vec) );
glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0]));
glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1]));
glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2]));
glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3]));
glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, vec));
glBindBuffer(GL_ARRAY_BUFFER, _vboInstances);
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, clip));
glVertexAttribIPointer(vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, texColourAtlas));
glVertexAttribPointer(vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, texColourBounds));
glVertexAttribIPointer(vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, texMaskAtlas));
glVertexAttribPointer(vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, texMaskBounds));
glVertexAttribIPointer(vPalettes, 3, GL_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, palettes));
glVertexAttribIPointer(vFlags, 1, GL_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, flags));
glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, colour));
glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, bounds));
glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawRectCommand), (void*) offsetof(DrawRectCommand, depth));
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, clip));
glVertexAttribIPointer(
vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourAtlas));
glVertexAttribPointer(
vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourBounds));
glVertexAttribIPointer(vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskAtlas));
glVertexAttribPointer(
vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskBounds));
glVertexAttribIPointer(vPalettes, 3, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, palettes));
glVertexAttribIPointer(vFlags, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, flags));
glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, colour));
glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, bounds));
glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, depth));
glEnableVertexAttribArray(vVertMat+0);
glEnableVertexAttribArray(vVertMat+1);
glEnableVertexAttribArray(vVertMat+2);
glEnableVertexAttribArray(vVertMat+3);
glEnableVertexAttribArray(vVertMat + 0);
glEnableVertexAttribArray(vVertMat + 1);
glEnableVertexAttribArray(vVertMat + 2);
glEnableVertexAttribArray(vVertMat + 3);
glEnableVertexAttribArray(vVertVec);
glEnableVertexAttribArray(vClip);
@ -104,26 +107,26 @@ DrawRectShader::~DrawRectShader()
void DrawRectShader::GetLocations()
{
uScreenSize = GetUniformLocation("uScreenSize");
uTexture = GetUniformLocation("uTexture");
uPaletteTex = GetUniformLocation("uPaletteTex");
uScreenSize = GetUniformLocation("uScreenSize");
uTexture = GetUniformLocation("uTexture");
uPaletteTex = GetUniformLocation("uPaletteTex");
uPeelingTex = GetUniformLocation("uPeelingTex");
uPeeling = GetUniformLocation("uPeeling");
uPeelingTex = GetUniformLocation("uPeelingTex");
uPeeling = GetUniformLocation("uPeeling");
vClip = GetAttributeLocation("vClip");
vTexColourAtlas = GetAttributeLocation("vTexColourAtlas");
vTexColourBounds = GetAttributeLocation("vTexColourBounds");
vTexMaskAtlas = GetAttributeLocation("vTexMaskAtlas");
vTexMaskBounds = GetAttributeLocation("vTexMaskBounds");
vPalettes = GetAttributeLocation("vPalettes");
vFlags = GetAttributeLocation("vFlags");
vColour = GetAttributeLocation("vColour");
vBounds = GetAttributeLocation("vBounds");
vDepth = GetAttributeLocation("vDepth");
vClip = GetAttributeLocation("vClip");
vTexColourAtlas = GetAttributeLocation("vTexColourAtlas");
vTexColourBounds = GetAttributeLocation("vTexColourBounds");
vTexMaskAtlas = GetAttributeLocation("vTexMaskAtlas");
vTexMaskBounds = GetAttributeLocation("vTexMaskBounds");
vPalettes = GetAttributeLocation("vPalettes");
vFlags = GetAttributeLocation("vFlags");
vColour = GetAttributeLocation("vColour");
vBounds = GetAttributeLocation("vBounds");
vDepth = GetAttributeLocation("vDepth");
vVertMat = GetAttributeLocation("vVertMat");
vVertVec = GetAttributeLocation("vVertVec");
vVertMat = GetAttributeLocation("vVertMat");
vVertVec = GetAttributeLocation("vVertVec");
}
void DrawRectShader::SetScreenSize(int32_t width, int32_t height)
@ -142,7 +145,7 @@ void DrawRectShader::DisablePeeling()
glUniform1i(uPeeling, 0);
}
void DrawRectShader::SetInstances(const RectCommandBatch &instances)
void DrawRectShader::SetInstances(const RectCommandBatch& instances)
{
glBindVertexArray(_vao);

View File

@ -9,9 +9,10 @@
#pragma once
#include "DrawCommands.h"
#include "GLSLTypes.h"
#include "OpenGLShaderProgram.h"
#include "DrawCommands.h"
#include <SDL2/SDL_pixels.h>
#include <vector>

View File

@ -9,51 +9,142 @@
#pragma once
#include <openrct2/common.h>
#include "OpenGLAPI.h"
#include <openrct2/common.h>
#pragma pack(push, 1)
struct ivec2
{
union { GLint x; GLint s; GLint r; };
union { GLint y; GLint t; GLint g; };
union
{
GLint x;
GLint s;
GLint r;
};
union
{
GLint y;
GLint t;
GLint g;
};
};
struct vec2
{
union { GLfloat x; GLfloat s; GLfloat r; };
union { GLfloat y; GLfloat t; GLfloat g; };
union
{
GLfloat x;
GLfloat s;
GLfloat r;
};
union
{
GLfloat y;
GLfloat t;
GLfloat g;
};
};
struct ivec3
{
union { GLint x; GLint s; GLint r; };
union { GLint y; GLint t; GLint g; };
union { GLint z; GLint p; GLint b; };
union
{
GLint x;
GLint s;
GLint r;
};
union
{
GLint y;
GLint t;
GLint g;
};
union
{
GLint z;
GLint p;
GLint b;
};
};
struct vec3f
{
union { GLfloat x; GLfloat s; GLfloat r; };
union { GLfloat y; GLfloat t; GLfloat g; };
union { GLfloat z; GLfloat p; GLfloat b; };
union
{
GLfloat x;
GLfloat s;
GLfloat r;
};
union
{
GLfloat y;
GLfloat t;
GLfloat g;
};
union
{
GLfloat z;
GLfloat p;
GLfloat b;
};
};
struct ivec4
{
union { GLint x; GLint s; GLint r; };
union { GLint y; GLint t; GLint g; };
union { GLint z; GLint p; GLint b; };
union { GLint w; GLint q; GLint a; };
union
{
GLint x;
GLint s;
GLint r;
};
union
{
GLint y;
GLint t;
GLint g;
};
union
{
GLint z;
GLint p;
GLint b;
};
union
{
GLint w;
GLint q;
GLint a;
};
};
struct vec4
{
union { GLfloat x; GLfloat s; GLfloat r; };
union { GLfloat y; GLfloat t; GLfloat g; };
union { GLfloat z; GLfloat p; GLfloat b; };
union { GLfloat w; GLfloat q; GLfloat a; };
union
{
GLfloat x;
GLfloat s;
GLfloat r;
};
union
{
GLfloat y;
GLfloat t;
GLfloat g;
};
union
{
GLfloat z;
GLfloat p;
GLfloat b;
};
union
{
GLfloat w;
GLfloat q;
GLfloat a;
};
};
#pragma pack(pop)

View File

@ -18,18 +18,17 @@
#undef OPENGL_PROC
#include <SDL2/SDL_video.h>
#include <openrct2/core/Console.hpp>
static const char * TryLoadAllProcAddresses()
static const char* TryLoadAllProcAddresses()
{
#define OPENGL_PROC(TYPE, PROC) \
{ \
PROC = (TYPE)SDL_GL_GetProcAddress(#PROC); \
if (PROC == nullptr) \
{ \
return #PROC; \
} \
#define OPENGL_PROC(TYPE, PROC) \
{ \
PROC = (TYPE)SDL_GL_GetProcAddress(#PROC); \
if (PROC == nullptr) \
{ \
return #PROC; \
} \
}
#include "OpenGLAPIProc.h"
#undef OPENGL_PROC
@ -49,7 +48,7 @@ namespace OpenGLState
ActiveTexture = UINT16_MAX;
CurrentProgram = UINT32_MAX;
}
}
} // namespace OpenGLState
void OpenGLAPI::SetTexture(uint16_t index, GLenum type, GLuint texture)
{
@ -65,7 +64,7 @@ bool OpenGLAPI::Initialise()
OpenGLState::Reset();
#ifdef OPENGL_NO_LINK
const char * failedProcName = TryLoadAllProcAddresses();
const char* failedProcName = TryLoadAllProcAddresses();
if (failedProcName != nullptr)
{
Console::Error::WriteLine("Failed to load %s.", failedProcName);

View File

@ -14,30 +14,30 @@
#ifdef OPENGL_NO_LINK
// BEGIN [Do not define 1.1 function signatures]
#define glActiveTexture __static__glActiveTexture
#define glBegin __static__glBegin
#define glBindTexture __static__glBindTexture
#define glBlendFunc __static__glBlendFunc
#define glClear __static__glClear
#define glClearColor __static__glClearColor
#define glCullFace __static__glCullFace
#define glDeleteTextures __static__glDeleteTextures
#define glDepthFunc __static__glDepthFunc
#define glDisable __static__glDisable
#define glDrawArrays __static__glDrawArrays
#define glEnable __static__glEnable
#define glEnd __static__glEnd
#define glGenTextures __static__glGenTextures
#define glGetError __static__glGetError
#define glPixelStorei __static__glPixelStorei
#define glReadPixels __static__glReadPixels
#define glTexImage2D __static__glTexImage2D
#define glTexParameteri __static__glTexParameteri
#define glViewport __static__glViewport
#define glTexSubImage3D __static__glTexSubImage3D
#define glTexImage3D __static__glTexImage3D
#define glGetIntegerv __static__glGetIntegerv
#define glGetTexImage __static__glGetTexImage
#define glActiveTexture __static__glActiveTexture
#define glBegin __static__glBegin
#define glBindTexture __static__glBindTexture
#define glBlendFunc __static__glBlendFunc
#define glClear __static__glClear
#define glClearColor __static__glClearColor
#define glCullFace __static__glCullFace
#define glDeleteTextures __static__glDeleteTextures
#define glDepthFunc __static__glDepthFunc
#define glDisable __static__glDisable
#define glDrawArrays __static__glDrawArrays
#define glEnable __static__glEnable
#define glEnd __static__glEnd
#define glGenTextures __static__glGenTextures
#define glGetError __static__glGetError
#define glPixelStorei __static__glPixelStorei
#define glReadPixels __static__glReadPixels
#define glTexImage2D __static__glTexImage2D
#define glTexParameteri __static__glTexParameteri
#define glViewport __static__glViewport
#define glTexSubImage3D __static__glTexSubImage3D
#define glTexImage3D __static__glTexImage3D
#define glGetIntegerv __static__glGetIntegerv
#define glGetTexImage __static__glGetTexImage
#endif
@ -74,29 +74,60 @@
#undef glGetTexImage
// 1.1 function signatures
typedef void (APIENTRYP PFNGLBEGINPROC )(GLenum mode);
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC )(GLenum target, GLuint texture);
typedef void (APIENTRYP PFNGLBLENDFUNCPROC )(GLenum sfactor, GLenum dfactor);
typedef void (APIENTRYP PFNGLCLEARPROC )(GLbitfield mask);
typedef void (APIENTRYP PFNGLCLEARCOLORPROC )(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
typedef void (APIENTRYP PFNGLCULLFACEPROC )(GLenum mode);
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC)(GLsizei n, const GLuint *textures);
typedef void (APIENTRYP PFNGLDEPTHFUNCPROC )(GLenum func);
typedef void (APIENTRYP PFNGLDISABLEPROC )(GLenum cap);
typedef void (APIENTRYP PFNGLDRAWARRAYSPROC )(GLenum mode, GLint first, GLsizei count);
typedef void (APIENTRYP PFNGLENABLEPROC )(GLenum cap);
typedef void (APIENTRYP PFNGLENDPROC )(void);
typedef GLenum (APIENTRYP PFNGLGETERRORPROC )(void);
typedef void (APIENTRYP PFNGLGENTEXTURESPROC )(GLsizei n, GLuint *textures);
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC )(GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLREADPIXELSPROC )(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels);
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC )(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC )(GLenum target, GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLVIEWPORTPROC )(GLint x, GLint y, GLsizei width, GLsizei height);
typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* data);
typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC )(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * data);
typedef void (APIENTRYP PFNGLGETINTERGERVPROC )(GLenum pname, GLint * data);
typedef void (APIENTRYP PFNGLGETTEXIMAGEPROC )(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img);
typedef void(APIENTRYP PFNGLBEGINPROC)(GLenum mode);
typedef void(APIENTRYP PFNGLBINDTEXTUREPROC)(GLenum target, GLuint texture);
typedef void(APIENTRYP PFNGLBLENDFUNCPROC)(GLenum sfactor, GLenum dfactor);
typedef void(APIENTRYP PFNGLCLEARPROC)(GLbitfield mask);
typedef void(APIENTRYP PFNGLCLEARCOLORPROC)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode);
typedef void(APIENTRYP PFNGLDELETETEXTURESPROC)(GLsizei n, const GLuint* textures);
typedef void(APIENTRYP PFNGLDEPTHFUNCPROC)(GLenum func);
typedef void(APIENTRYP PFNGLDISABLEPROC)(GLenum cap);
typedef void(APIENTRYP PFNGLDRAWARRAYSPROC)(GLenum mode, GLint first, GLsizei count);
typedef void(APIENTRYP PFNGLENABLEPROC)(GLenum cap);
typedef void(APIENTRYP PFNGLENDPROC)(void);
typedef GLenum(APIENTRYP PFNGLGETERRORPROC)(void);
typedef void(APIENTRYP PFNGLGENTEXTURESPROC)(GLsizei n, GLuint* textures);
typedef void(APIENTRYP PFNGLPIXELSTOREIPROC)(GLenum pname, GLint param);
typedef void(APIENTRYP PFNGLREADPIXELSPROC)(
GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
typedef void(APIENTRYP PFNGLTEXIMAGE2DPROC)(
GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid* pixels);
typedef void(APIENTRYP PFNGLTEXPARAMETERIPROC)(GLenum target, GLenum pname, GLint param);
typedef void(APIENTRYP PFNGLVIEWPORTPROC)(GLint x, GLint y, GLsizei width, GLsizei height);
typedef void(APIENTRYP PFNGLTEXSUBIMAGE3DPROC)(
GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLint zoffset,
GLsizei width,
GLsizei height,
GLsizei depth,
GLenum format,
GLenum type,
const GLvoid* data);
typedef void(APIENTRYP PFNGLTEXIMAGE3DPROC)(
GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border,
GLenum format,
GLenum type,
const GLvoid* data);
typedef void(APIENTRYP PFNGLGETINTERGERVPROC)(GLenum pname, GLint* data);
typedef void(APIENTRYP PFNGLGETTEXIMAGEPROC)(GLenum target, GLint level, GLenum format, GLenum type, GLvoid* img);
#define OPENGL_PROC(TYPE, PROC) extern TYPE PROC;
#include "OpenGLAPIProc.h"
@ -118,7 +149,7 @@ namespace OpenGLAPI
{
bool Initialise();
void SetTexture(uint16_t index, GLenum type, GLuint texture);
}
} // namespace OpenGLAPI
namespace OpenGLState
{
@ -126,4 +157,4 @@ namespace OpenGLState
extern GLuint CurrentProgram;
void Reset();
}
} // namespace OpenGLState

View File

@ -12,75 +12,75 @@
#endif
// 1.1 function pointers
OPENGL_PROC(PFNGLACTIVETEXTUREPROC, glActiveTexture)
OPENGL_PROC(PFNGLBEGINPROC, glBegin)
OPENGL_PROC(PFNGLBINDTEXTUREPROC, glBindTexture)
OPENGL_PROC(PFNGLBLENDFUNCPROC, glBlendFunc)
OPENGL_PROC(PFNGLCLEARPROC, glClear)
OPENGL_PROC(PFNGLCLEARCOLORPROC, glClearColor)
OPENGL_PROC(PFNGLCULLFACEPROC, glCullFace)
OPENGL_PROC(PFNGLDELETETEXTURESPROC, glDeleteTextures)
OPENGL_PROC(PFNGLDEPTHFUNCPROC, glDepthFunc)
OPENGL_PROC(PFNGLDISABLEPROC, glDisable)
OPENGL_PROC(PFNGLDRAWARRAYSPROC, glDrawArrays)
OPENGL_PROC(PFNGLENABLEPROC, glEnable)
OPENGL_PROC(PFNGLENDPROC, glEnd)
OPENGL_PROC(PFNGLGENTEXTURESPROC, glGenTextures)
OPENGL_PROC(PFNGLGETERRORPROC, glGetError)
OPENGL_PROC(PFNGLPIXELSTOREIPROC, glPixelStorei)
OPENGL_PROC(PFNGLREADPIXELSPROC, glReadPixels)
OPENGL_PROC(PFNGLTEXIMAGE2DPROC, glTexImage2D)
OPENGL_PROC(PFNGLTEXPARAMETERIPROC, glTexParameteri)
OPENGL_PROC(PFNGLVIEWPORTPROC, glViewport)
OPENGL_PROC(PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D)
OPENGL_PROC(PFNGLTEXIMAGE3DPROC, glTexImage3D)
OPENGL_PROC(PFNGLGETINTERGERVPROC, glGetIntegerv)
OPENGL_PROC(PFNGLGETTEXIMAGEPROC, glGetTexImage)
OPENGL_PROC(PFNGLACTIVETEXTUREPROC, glActiveTexture)
OPENGL_PROC(PFNGLBEGINPROC, glBegin)
OPENGL_PROC(PFNGLBINDTEXTUREPROC, glBindTexture)
OPENGL_PROC(PFNGLBLENDFUNCPROC, glBlendFunc)
OPENGL_PROC(PFNGLCLEARPROC, glClear)
OPENGL_PROC(PFNGLCLEARCOLORPROC, glClearColor)
OPENGL_PROC(PFNGLCULLFACEPROC, glCullFace)
OPENGL_PROC(PFNGLDELETETEXTURESPROC, glDeleteTextures)
OPENGL_PROC(PFNGLDEPTHFUNCPROC, glDepthFunc)
OPENGL_PROC(PFNGLDISABLEPROC, glDisable)
OPENGL_PROC(PFNGLDRAWARRAYSPROC, glDrawArrays)
OPENGL_PROC(PFNGLENABLEPROC, glEnable)
OPENGL_PROC(PFNGLENDPROC, glEnd)
OPENGL_PROC(PFNGLGENTEXTURESPROC, glGenTextures)
OPENGL_PROC(PFNGLGETERRORPROC, glGetError)
OPENGL_PROC(PFNGLPIXELSTOREIPROC, glPixelStorei)
OPENGL_PROC(PFNGLREADPIXELSPROC, glReadPixels)
OPENGL_PROC(PFNGLTEXIMAGE2DPROC, glTexImage2D)
OPENGL_PROC(PFNGLTEXPARAMETERIPROC, glTexParameteri)
OPENGL_PROC(PFNGLVIEWPORTPROC, glViewport)
OPENGL_PROC(PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D)
OPENGL_PROC(PFNGLTEXIMAGE3DPROC, glTexImage3D)
OPENGL_PROC(PFNGLGETINTERGERVPROC, glGetIntegerv)
OPENGL_PROC(PFNGLGETTEXIMAGEPROC, glGetTexImage)
// 2.0+ function pointers
OPENGL_PROC(PFNGLATTACHSHADERPROC, glAttachShader)
OPENGL_PROC(PFNGLBINDBUFFERPROC, glBindBuffer)
OPENGL_PROC(PFNGLBINDFRAGDATALOCATIONPROC, glBindFragDataLocation)
OPENGL_PROC(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer)
OPENGL_PROC(PFNGLBINDVERTEXARRAYPROC, glBindVertexArray)
OPENGL_PROC(PFNGLBLITFRAMEBUFFERPROC, glBlitFramebuffer)
OPENGL_PROC(PFNGLBUFFERDATAPROC, glBufferData)
OPENGL_PROC(PFNGLCLEARBUFFERFVPROC, glClearBufferfv)
OPENGL_PROC(PFNGLCLEARBUFFERUIVPROC, glClearBufferuiv)
OPENGL_PROC(PFNGLCOMPILESHADERPROC, glCompileShader)
OPENGL_PROC(PFNGLCREATEPROGRAMPROC, glCreateProgram)
OPENGL_PROC(PFNGLCREATESHADERPROC, glCreateShader)
OPENGL_PROC(PFNGLDELETEBUFFERSPROC, glDeleteBuffers)
OPENGL_PROC(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers)
OPENGL_PROC(PFNGLDELETEPROGRAMPROC, glDeleteProgram)
OPENGL_PROC(PFNGLDELETESHADERPROC, glDeleteShader)
OPENGL_PROC(PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays)
OPENGL_PROC(PFNGLDETACHSHADERPROC, glDetachShader)
OPENGL_PROC(PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray)
OPENGL_PROC(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D)
OPENGL_PROC(PFNGLGETATTRIBLOCATIONPROC, glGetAttribLocation)
OPENGL_PROC(PFNGLGENBUFFERSPROC, glGenBuffers)
OPENGL_PROC(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers)
OPENGL_PROC(PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog)
OPENGL_PROC(PFNGLGETPROGRAMIVPROC, glGetProgramiv)
OPENGL_PROC(PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog)
OPENGL_PROC(PFNGLGETSHADERIVPROC, glGetShaderiv)
OPENGL_PROC(PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation)
OPENGL_PROC(PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays)
OPENGL_PROC(PFNGLLINKPROGRAMPROC, glLinkProgram)
OPENGL_PROC(PFNGLSHADERSOURCEPROC, glShaderSource)
OPENGL_PROC(PFNGLUNIFORM1IPROC, glUniform1i)
OPENGL_PROC(PFNGLUNIFORM1IVPROC, glUniform1iv)
OPENGL_PROC(PFNGLUNIFORM1UIPROC, glUniform1ui);
OPENGL_PROC(PFNGLUNIFORM1UIVPROC, glUniform1uiv);
OPENGL_PROC(PFNGLUNIFORM2IPROC, glUniform2i)
OPENGL_PROC(PFNGLUNIFORM2FPROC, glUniform2f)
OPENGL_PROC(PFNGLUNIFORM4FPROC, glUniform4f)
OPENGL_PROC(PFNGLUNIFORM4IPROC, glUniform4i)
OPENGL_PROC(PFNGLUNIFORM4FVPROC, glUniform4fv)
OPENGL_PROC(PFNGLUSEPROGRAMPROC, glUseProgram)
OPENGL_PROC(PFNGLVERTEXATTRIBIPOINTERPROC, glVertexAttribIPointer)
OPENGL_PROC(PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer)
OPENGL_PROC(PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstanced)
OPENGL_PROC(PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttribDivisor)
OPENGL_PROC(PFNGLBLENDFUNCSEPARATEPROC, glBlendFuncSeparate)
OPENGL_PROC(PFNGLATTACHSHADERPROC, glAttachShader)
OPENGL_PROC(PFNGLBINDBUFFERPROC, glBindBuffer)
OPENGL_PROC(PFNGLBINDFRAGDATALOCATIONPROC, glBindFragDataLocation)
OPENGL_PROC(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer)
OPENGL_PROC(PFNGLBINDVERTEXARRAYPROC, glBindVertexArray)
OPENGL_PROC(PFNGLBLITFRAMEBUFFERPROC, glBlitFramebuffer)
OPENGL_PROC(PFNGLBUFFERDATAPROC, glBufferData)
OPENGL_PROC(PFNGLCLEARBUFFERFVPROC, glClearBufferfv)
OPENGL_PROC(PFNGLCLEARBUFFERUIVPROC, glClearBufferuiv)
OPENGL_PROC(PFNGLCOMPILESHADERPROC, glCompileShader)
OPENGL_PROC(PFNGLCREATEPROGRAMPROC, glCreateProgram)
OPENGL_PROC(PFNGLCREATESHADERPROC, glCreateShader)
OPENGL_PROC(PFNGLDELETEBUFFERSPROC, glDeleteBuffers)
OPENGL_PROC(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers)
OPENGL_PROC(PFNGLDELETEPROGRAMPROC, glDeleteProgram)
OPENGL_PROC(PFNGLDELETESHADERPROC, glDeleteShader)
OPENGL_PROC(PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays)
OPENGL_PROC(PFNGLDETACHSHADERPROC, glDetachShader)
OPENGL_PROC(PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray)
OPENGL_PROC(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D)
OPENGL_PROC(PFNGLGETATTRIBLOCATIONPROC, glGetAttribLocation)
OPENGL_PROC(PFNGLGENBUFFERSPROC, glGenBuffers)
OPENGL_PROC(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers)
OPENGL_PROC(PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog)
OPENGL_PROC(PFNGLGETPROGRAMIVPROC, glGetProgramiv)
OPENGL_PROC(PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog)
OPENGL_PROC(PFNGLGETSHADERIVPROC, glGetShaderiv)
OPENGL_PROC(PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation)
OPENGL_PROC(PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays)
OPENGL_PROC(PFNGLLINKPROGRAMPROC, glLinkProgram)
OPENGL_PROC(PFNGLSHADERSOURCEPROC, glShaderSource)
OPENGL_PROC(PFNGLUNIFORM1IPROC, glUniform1i)
OPENGL_PROC(PFNGLUNIFORM1IVPROC, glUniform1iv)
OPENGL_PROC(PFNGLUNIFORM1UIPROC, glUniform1ui);
OPENGL_PROC(PFNGLUNIFORM1UIVPROC, glUniform1uiv);
OPENGL_PROC(PFNGLUNIFORM2IPROC, glUniform2i)
OPENGL_PROC(PFNGLUNIFORM2FPROC, glUniform2f)
OPENGL_PROC(PFNGLUNIFORM4FPROC, glUniform4f)
OPENGL_PROC(PFNGLUNIFORM4IPROC, glUniform4i)
OPENGL_PROC(PFNGLUNIFORM4FVPROC, glUniform4fv)
OPENGL_PROC(PFNGLUSEPROGRAMPROC, glUseProgram)
OPENGL_PROC(PFNGLVERTEXATTRIBIPOINTERPROC, glVertexAttribIPointer)
OPENGL_PROC(PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer)
OPENGL_PROC(PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstanced)
OPENGL_PROC(PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttribDivisor)
OPENGL_PROC(PFNGLBLENDFUNCSEPARATEPROC, glBlendFuncSeparate)

View File

@ -9,21 +9,6 @@
#ifndef DISABLE_OPENGL
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <SDL2/SDL.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Console.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/IDrawingContext.h>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/drawing/LightFX.h>
#include <openrct2/drawing/Rain.h>
#include <openrct2/interface/Screenshot.h>
#include <openrct2/Intro.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2/ui/UiContext.h>
#include "../DrawingEngineFactory.hpp"
#include "ApplyPaletteShader.h"
#include "DrawCommands.h"
@ -36,6 +21,22 @@
#include "TextureCache.h"
#include "TransparencyDepth.h"
#include <SDL2/SDL.h>
#include <algorithm>
#include <cmath>
#include <openrct2-ui/interface/Window.h>
#include <openrct2/Intro.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Console.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/IDrawingContext.h>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/drawing/LightFX.h>
#include <openrct2/drawing/Rain.h>
#include <openrct2/interface/Screenshot.h>
#include <openrct2/ui/UiContext.h>
#include <unordered_map>
using namespace OpenRCT2;
using namespace OpenRCT2::Drawing;
using namespace OpenRCT2::Ui;
@ -53,40 +54,45 @@ class OpenGLDrawingEngine;
class OpenGLDrawingContext final : public IDrawingContext
{
private:
OpenGLDrawingEngine * _engine = nullptr;
rct_drawpixelinfo * _dpi = nullptr;
OpenGLDrawingEngine* _engine = nullptr;
rct_drawpixelinfo* _dpi = nullptr;
ApplyTransparencyShader * _applyTransparencyShader = nullptr;
DrawLineShader * _drawLineShader = nullptr;
DrawRectShader * _drawRectShader = nullptr;
SwapFramebuffer * _swapFramebuffer = nullptr;
ApplyTransparencyShader* _applyTransparencyShader = nullptr;
DrawLineShader* _drawLineShader = nullptr;
DrawRectShader* _drawRectShader = nullptr;
SwapFramebuffer* _swapFramebuffer = nullptr;
TextureCache * _textureCache = nullptr;
TextureCache* _textureCache = nullptr;
int32_t _offsetX = 0;
int32_t _offsetY = 0;
int32_t _clipLeft = 0;
int32_t _clipTop = 0;
int32_t _clipRight = 0;
int32_t _offsetX = 0;
int32_t _offsetY = 0;
int32_t _clipLeft = 0;
int32_t _clipTop = 0;
int32_t _clipRight = 0;
int32_t _clipBottom = 0;
int32_t _drawCount = 0;
int32_t _drawCount = 0;
struct
{
LineCommandBatch lines;
RectCommandBatch rects;
RectCommandBatch transparent;
}
_commandBuffers;
} _commandBuffers;
public:
explicit OpenGLDrawingContext(OpenGLDrawingEngine * engine);
explicit OpenGLDrawingContext(OpenGLDrawingEngine* engine);
~OpenGLDrawingContext() override;
IDrawingEngine * GetEngine() override;
TextureCache * GetTextureCache() const { return _textureCache; }
const OpenGLFramebuffer & GetFinalFramebuffer() const { return _swapFramebuffer->GetFinalFramebuffer(); }
IDrawingEngine* GetEngine() override;
TextureCache* GetTextureCache() const
{
return _textureCache;
}
const OpenGLFramebuffer& GetFinalFramebuffer() const
{
return _swapFramebuffer->GetFinalFramebuffer();
}
void Initialise();
void Resize(int32_t width, int32_t height);
@ -100,7 +106,7 @@ public:
void DrawSprite(uint32_t image, int32_t x, int32_t y, uint32_t tertiaryColour) override;
void DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskImage, uint32_t colourImage) override;
void DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour) override;
void DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t * palette) override;
void DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t* palette) override;
void FlushCommandBuffers();
@ -108,39 +114,39 @@ public:
void FlushRectangles();
void HandleTransparency();
void SetDPI(rct_drawpixelinfo * dpi);
void SetDPI(rct_drawpixelinfo* dpi);
};
class OpenGLDrawingEngine : public IDrawingEngine
{
private:
std::shared_ptr<IUiContext> const _uiContext;
SDL_Window * _window = nullptr;
SDL_GLContext _context = nullptr;
SDL_Window* _window = nullptr;
SDL_GLContext _context = nullptr;
uint32_t _width = 0;
uint32_t _height = 0;
uint32_t _pitch = 0;
size_t _bitsSize = 0;
uint8_t * _bits = nullptr;
uint32_t _width = 0;
uint32_t _height = 0;
uint32_t _pitch = 0;
size_t _bitsSize = 0;
uint8_t* _bits = nullptr;
rct_drawpixelinfo _bitsDPI = {};
rct_drawpixelinfo _bitsDPI = {};
OpenGLDrawingContext * _drawingContext;
OpenGLDrawingContext* _drawingContext;
ApplyPaletteShader * _applyPaletteShader = nullptr;
OpenGLFramebuffer * _screenFramebuffer = nullptr;
OpenGLFramebuffer * _scaleFramebuffer = nullptr;
OpenGLFramebuffer * _smoothScaleFramebuffer = nullptr;
ApplyPaletteShader* _applyPaletteShader = nullptr;
OpenGLFramebuffer* _screenFramebuffer = nullptr;
OpenGLFramebuffer* _scaleFramebuffer = nullptr;
OpenGLFramebuffer* _smoothScaleFramebuffer = nullptr;
public:
SDL_Color Palette[256];
vec4 GLPalette[256];
vec4 GLPalette[256];
explicit OpenGLDrawingEngine(const std::shared_ptr<IUiContext>& uiContext)
: _uiContext(uiContext)
{
_window = (SDL_Window *)_uiContext->GetWindow();
_window = (SDL_Window*)_uiContext->GetWindow();
_drawingContext = new OpenGLDrawingContext(this);
#ifdef __ENABLE_LIGHTFX__
lightfx_set_available(false);
@ -153,7 +159,7 @@ public:
delete _screenFramebuffer;
delete _drawingContext;
delete [] _bits;
delete[] _bits;
SDL_GL_DeleteContext(_context);
}
@ -191,7 +197,7 @@ public:
_drawingContext->Resize(width, height);
}
void SetPalette(const rct_palette_entry * palette) override
void SetPalette(const rct_palette_entry* palette) override
{
for (int32_t i = 0; i < 256; i++)
{
@ -202,10 +208,7 @@ public:
colour.a = i == 0 ? 0 : 255;
Palette[i] = colour;
GLPalette[i] = { colour.r / 255.0f,
colour.g / 255.0f,
colour.b / 255.0f,
colour.a / 255.0f };
GLPalette[i] = { colour.r / 255.0f, colour.g / 255.0f, colour.b / 255.0f, colour.a / 255.0f };
}
_applyPaletteShader->Use();
@ -278,7 +281,7 @@ public:
int32_t Screenshot() override
{
const OpenGLFramebuffer & framebuffer = _drawingContext->GetFinalFramebuffer();
const OpenGLFramebuffer& framebuffer = _drawingContext->GetFinalFramebuffer();
framebuffer.Bind();
framebuffer.GetPixels(_bitsDPI);
int32_t result = screenshot_dump_png(&_bitsDPI);
@ -290,13 +293,13 @@ public:
// Not applicable for this engine
}
IDrawingContext * GetDrawingContext(rct_drawpixelinfo * dpi) override
IDrawingContext* GetDrawingContext(rct_drawpixelinfo* dpi) override
{
_drawingContext->SetDPI(dpi);
return _drawingContext;
}
rct_drawpixelinfo * GetDrawingPixelInfo() override
rct_drawpixelinfo* GetDrawingPixelInfo() override
{
return &_bitsDPI;
}
@ -308,11 +311,10 @@ public:
void InvalidateImage(uint32_t image) override
{
_drawingContext->GetTextureCache()
->InvalidateImage(image);
_drawingContext->GetTextureCache()->InvalidateImage(image);
}
rct_drawpixelinfo * GetDPI()
rct_drawpixelinfo* GetDPI()
{
return &_bitsDPI;
}
@ -323,16 +325,18 @@ private:
CheckGLError(); // Clear Any Errors
OpenGLVersion version = { 0, 0 };
glGetIntegerv(GL_MAJOR_VERSION, &version.Major);
if (glGetError() != GL_NO_ERROR) return { 0, 0 };
if (glGetError() != GL_NO_ERROR)
return { 0, 0 };
glGetIntegerv(GL_MINOR_VERSION, &version.Minor);
if (glGetError() != GL_NO_ERROR) return { 0, 0 };
if (glGetError() != GL_NO_ERROR)
return { 0, 0 };
return version;
}
void ConfigureBits(uint32_t width, uint32_t height, uint32_t pitch)
{
size_t newBitsSize = pitch * height;
uint8_t * newBits = new uint8_t[newBitsSize];
size_t newBitsSize = pitch * height;
uint8_t* newBits = new uint8_t[newBitsSize];
if (_bits == nullptr)
{
std::fill_n(newBits, newBitsSize, 0);
@ -345,8 +349,8 @@ private:
}
else
{
uint8_t * src = _bits;
uint8_t * dst = newBits;
uint8_t* src = _bits;
uint8_t* dst = newBits;
uint32_t minWidth = std::min(_width, width);
uint32_t minHeight = std::min(_height, height);
@ -361,7 +365,7 @@ private:
dst += pitch;
}
}
delete [] _bits;
delete[] _bits;
}
_bits = newBits;
@ -370,7 +374,7 @@ private:
_height = height;
_pitch = pitch;
rct_drawpixelinfo * dpi = &_bitsDPI;
rct_drawpixelinfo* dpi = &_bitsDPI;
dpi->bits = _bits;
dpi->x = 0;
dpi->y = 0;
@ -417,7 +421,7 @@ std::unique_ptr<IDrawingEngine> OpenRCT2::Ui::CreateOpenGLDrawingEngine(const st
return std::make_unique<OpenGLDrawingEngine>(uiContext);
}
OpenGLDrawingContext::OpenGLDrawingContext(OpenGLDrawingEngine * engine)
OpenGLDrawingContext::OpenGLDrawingContext(OpenGLDrawingEngine* engine)
{
_engine = engine;
}
@ -432,7 +436,7 @@ OpenGLDrawingContext::~OpenGLDrawingContext()
delete _textureCache;
}
IDrawingEngine * OpenGLDrawingContext::GetEngine()
IDrawingEngine* OpenGLDrawingContext::GetEngine()
{
return _engine;
}
@ -462,7 +466,7 @@ void OpenGLDrawingContext::Resize(int32_t width, int32_t height)
void OpenGLDrawingContext::ResetPalette()
{
//FlushCommandBuffers();
// FlushCommandBuffers();
}
void OpenGLDrawingContext::StartNewDraw()
@ -581,11 +585,13 @@ void OpenGLDrawingContext::DrawSprite(uint32_t image, int32_t x, int32_t y, uint
int32_t top = y + g1Element->y_offset;
int32_t zoom_mask = 0xFFFFFFFF << _dpi->zoom_level;
if (_dpi->zoom_level && g1Element->flags & G1_FLAG_RLE_COMPRESSION){
if (_dpi->zoom_level && g1Element->flags & G1_FLAG_RLE_COMPRESSION)
{
top -= ~zoom_mask;
}
if (!(g1Element->flags & G1_FLAG_RLE_COMPRESSION)) {
if (!(g1Element->flags & G1_FLAG_RLE_COMPRESSION))
{
top &= zoom_mask;
left += ~zoom_mask;
}
@ -595,7 +601,8 @@ void OpenGLDrawingContext::DrawSprite(uint32_t image, int32_t x, int32_t y, uint
int32_t right = left + g1Element->width;
int32_t bottom = top + g1Element->height;
if (_dpi->zoom_level && g1Element->flags & G1_FLAG_RLE_COMPRESSION) {
if (_dpi->zoom_level && g1Element->flags & G1_FLAG_RLE_COMPRESSION)
{
bottom += top & ~zoom_mask;
}
@ -802,7 +809,7 @@ void OpenGLDrawingContext::DrawSpriteSolid(uint32_t image, int32_t x, int32_t y,
command.depth = _drawCount++;
}
void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t * palette)
void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t* palette)
{
auto g1Element = gfx_get_g1_element(image & 0x7FFFF);
if (g1Element == nullptr)
@ -867,7 +874,8 @@ void OpenGLDrawingContext::FlushCommandBuffers()
void OpenGLDrawingContext::FlushLines()
{
if (_commandBuffers.lines.size() == 0) return;
if (_commandBuffers.lines.size() == 0)
return;
_drawLineShader->Use();
_drawLineShader->DrawInstances(_commandBuffers.lines);
@ -877,7 +885,8 @@ void OpenGLDrawingContext::FlushLines()
void OpenGLDrawingContext::FlushRectangles()
{
if (_commandBuffers.rects.size() == 0) return;
if (_commandBuffers.rects.size() == 0)
return;
OpenGLAPI::SetTexture(0, GL_TEXTURE_2D_ARRAY, _textureCache->GetAtlasesTexture());
OpenGLAPI::SetTexture(1, GL_TEXTURE_RECTANGLE, _textureCache->GetPaletteTexture());
@ -900,7 +909,7 @@ void OpenGLDrawingContext::HandleTransparency()
_drawRectShader->SetInstances(_commandBuffers.transparent);
int32_t max_depth = MaxTransparencyDepth(_commandBuffers.transparent);
for (int32_t i=0; i < max_depth; ++i)
for (int32_t i = 0; i < max_depth; ++i)
{
_swapFramebuffer->BindTransparent();
@ -924,9 +933,9 @@ void OpenGLDrawingContext::HandleTransparency()
_commandBuffers.transparent.clear();
}
void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo * dpi)
void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo* dpi)
{
rct_drawpixelinfo * screenDPI = _engine->GetDPI();
rct_drawpixelinfo* screenDPI = _engine->GetDPI();
#ifndef NDEBUG
size_t bitsSize = (size_t)screenDPI->height * (size_t)(screenDPI->width + screenDPI->pitch);
#endif

View File

@ -9,15 +9,16 @@
#ifndef DISABLE_OPENGL
#include "OpenGLFramebuffer.h"
#include <SDL2/SDL_video.h>
#include <algorithm>
#include <memory>
#include <openrct2/common.h>
#include <SDL2/SDL_video.h>
#include "OpenGLFramebuffer.h"
constexpr GLuint BACKBUFFER_ID = 0;
OpenGLFramebuffer::OpenGLFramebuffer(SDL_Window * window)
OpenGLFramebuffer::OpenGLFramebuffer(SDL_Window* window)
{
_id = BACKBUFFER_ID;
_texture = 0;
@ -84,7 +85,7 @@ void OpenGLFramebuffer::BindRead() const
glBindFramebuffer(GL_READ_FRAMEBUFFER, _id);
}
void OpenGLFramebuffer::GetPixels(rct_drawpixelinfo &dpi) const
void OpenGLFramebuffer::GetPixels(rct_drawpixelinfo& dpi) const
{
assert(dpi.width == _width && dpi.height == _height);
@ -94,8 +95,8 @@ void OpenGLFramebuffer::GetPixels(rct_drawpixelinfo &dpi) const
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, pixels.get());
// Flip pixels vertically on copy
uint8_t * src = pixels.get() + ((_height - 1) * _width);
uint8_t * dst = dpi.bits;
uint8_t* src = pixels.get() + ((_height - 1) * _width);
uint8_t* dst = dpi.bits;
for (int32_t y = 0; y < _height; y++)
{
std::copy_n(src, _width, dst);
@ -104,7 +105,7 @@ void OpenGLFramebuffer::GetPixels(rct_drawpixelinfo &dpi) const
}
}
void OpenGLFramebuffer::SwapColourBuffer(OpenGLFramebuffer &other)
void OpenGLFramebuffer::SwapColourBuffer(OpenGLFramebuffer& other)
{
std::swap(_texture, other._texture);
@ -125,14 +126,11 @@ GLuint OpenGLFramebuffer::SwapDepthTexture(GLuint depth)
return depth;
}
void OpenGLFramebuffer::Copy(OpenGLFramebuffer &src, GLenum filter)
void OpenGLFramebuffer::Copy(OpenGLFramebuffer& src, GLenum filter)
{
BindDraw();
src.BindRead();
glBlitFramebuffer(
0, 0, src.GetWidth(), src.GetHeight(),
0, 0, _width, _height, GL_COLOR_BUFFER_BIT, filter
);
glBlitFramebuffer(0, 0, src.GetWidth(), src.GetHeight(), 0, 0, _width, _height, GL_COLOR_BUFFER_BIT, filter);
Bind();
}

View File

@ -9,10 +9,10 @@
#pragma once
#include <openrct2/common.h>
#include <openrct2/drawing/Drawing.h>
#include "OpenGLAPI.h"
#include <openrct2/common.h>
#include <openrct2/drawing/Drawing.h>
#include <vector>
struct SDL_Window;
@ -27,26 +27,38 @@ private:
int32_t _height;
public:
explicit OpenGLFramebuffer(SDL_Window * window);
explicit OpenGLFramebuffer(SDL_Window* window);
OpenGLFramebuffer(int32_t width, int32_t height, bool depth = true, bool integer = true);
~OpenGLFramebuffer();
OpenGLFramebuffer(const OpenGLFramebuffer &) = delete;
OpenGLFramebuffer &operator=(const OpenGLFramebuffer &) = delete;
OpenGLFramebuffer(const OpenGLFramebuffer&) = delete;
OpenGLFramebuffer& operator=(const OpenGLFramebuffer&) = delete;
GLuint GetWidth() const { return _width; }
GLuint GetHeight() const { return _height; }
GLuint GetTexture() const { return _texture; }
GLuint GetDepthTexture() const { return _depth; }
GLuint GetWidth() const
{
return _width;
}
GLuint GetHeight() const
{
return _height;
}
GLuint GetTexture() const
{
return _texture;
}
GLuint GetDepthTexture() const
{
return _depth;
}
void Bind() const;
void BindDraw() const;
void BindRead() const;
void GetPixels(rct_drawpixelinfo &dpi) const;
void GetPixels(rct_drawpixelinfo& dpi) const;
void SwapColourBuffer(OpenGLFramebuffer &other);
void SwapColourBuffer(OpenGLFramebuffer& other);
GLuint SwapDepthTexture(GLuint depth);
void Copy(OpenGLFramebuffer &src, GLenum filter);
void Copy(OpenGLFramebuffer& src, GLenum filter);
static GLuint CreateDepthTexture(int32_t width, int32_t height);
};

View File

@ -9,17 +9,18 @@
#ifndef DISABLE_OPENGL
#include "OpenGLShaderProgram.h"
#include <openrct2/Context.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/core/Console.hpp>
#include <openrct2/core/FileStream.hpp>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/PlatformEnvironment.h>
#include "OpenGLShaderProgram.h"
using namespace OpenRCT2;
OpenGLShader::OpenGLShader(const char * name, GLenum type)
OpenGLShader::OpenGLShader(const char* name, GLenum type)
{
_type = type;
@ -28,7 +29,7 @@ OpenGLShader::OpenGLShader(const char * name, GLenum type)
auto sourceCodeStr = sourceCode.c_str();
_id = glCreateShader(type);
glShaderSource(_id, 1, (const GLchar * *)&sourceCodeStr, nullptr);
glShaderSource(_id, 1, (const GLchar**)&sourceCodeStr, nullptr);
glCompileShader(_id);
GLint status;
@ -56,7 +57,7 @@ GLuint OpenGLShader::GetShaderId()
return _id;
}
std::string OpenGLShader::GetPath(const std::string &name)
std::string OpenGLShader::GetPath(const std::string& name)
{
auto env = GetContext()->GetPlatformEnvironment();
auto shadersPath = env->GetDirectoryPath(DIRBASE::OPENRCT2, DIRID::SHADER);
@ -72,7 +73,7 @@ std::string OpenGLShader::GetPath(const std::string &name)
return path;
}
std::string OpenGLShader::ReadSourceCode(const std::string &path)
std::string OpenGLShader::ReadSourceCode(const std::string& path)
{
auto fs = FileStream(path, FILE_MODE_OPEN);
@ -83,11 +84,11 @@ std::string OpenGLShader::ReadSourceCode(const std::string &path)
}
auto fileData = std::string((size_t)fileLength + 1, '\0');
fs.Read((void *)fileData.data(), fileLength);
fs.Read((void*)fileData.data(), fileLength);
return fileData;
}
OpenGLShaderProgram::OpenGLShaderProgram(const char * name)
OpenGLShaderProgram::OpenGLShaderProgram(const char* name)
{
_vertexShader = new OpenGLShader(name, GL_VERTEX_SHADER);
_fragmentShader = new OpenGLShader(name, GL_FRAGMENT_SHADER);
@ -125,12 +126,12 @@ OpenGLShaderProgram::~OpenGLShaderProgram()
glDeleteProgram(_id);
}
GLuint OpenGLShaderProgram::GetAttributeLocation(const char * name)
GLuint OpenGLShaderProgram::GetAttributeLocation(const char* name)
{
return glGetAttribLocation(_id, name);
}
GLuint OpenGLShaderProgram::GetUniformLocation(const char * name)
GLuint OpenGLShaderProgram::GetUniformLocation(const char* name)
{
return glGetUniformLocation(_id, name);
}

View File

@ -9,44 +9,45 @@
#pragma once
#include <string>
#include <openrct2/common.h>
#include "OpenGLAPI.h"
#include <openrct2/common.h>
#include <string>
class OpenGLShader final
{
private:
static constexpr uint64_t MaxSourceSize = 8 * 1024 * 1024; // 8 MiB
GLenum _type;
GLuint _id = 0;
GLuint _id = 0;
public:
OpenGLShader(const char * name, GLenum type);
OpenGLShader(const char* name, GLenum type);
~OpenGLShader();
GLuint GetShaderId();
private:
std::string GetPath(const std::string &name);
static std::string ReadSourceCode(const std::string &path);
std::string GetPath(const std::string& name);
static std::string ReadSourceCode(const std::string& path);
};
class OpenGLShaderProgram
{
private:
GLuint _id = 0;
OpenGLShader * _vertexShader = nullptr;
OpenGLShader * _fragmentShader = nullptr;
GLuint _id = 0;
OpenGLShader* _vertexShader = nullptr;
OpenGLShader* _fragmentShader = nullptr;
public:
explicit OpenGLShaderProgram(const char * name);
explicit OpenGLShaderProgram(const char* name);
explicit OpenGLShaderProgram(const OpenGLShaderProgram&) = default;
virtual ~OpenGLShaderProgram();
GLuint GetAttributeLocation(const char * name);
GLuint GetUniformLocation(const char * name);
void Use();
GLuint GetAttributeLocation(const char* name);
GLuint GetUniformLocation(const char* name);
void Use();
private:
bool Link();

View File

@ -9,22 +9,25 @@
#ifndef DISABLE_OPENGL
#include "OpenGLFramebuffer.h"
#include "SwapFramebuffer.h"
#include "OpenGLFramebuffer.h"
constexpr GLfloat depthValue[1] = { 1.0f };
constexpr GLfloat depthValueTransparent[1] = { 0.0f };
constexpr GLuint indexValue[4] = { 0, 0, 0, 0 };
SwapFramebuffer::SwapFramebuffer(int32_t width, int32_t height) :
_opaqueFramebuffer(width, height), _transparentFramebuffer(width, height),
_mixFramebuffer(width, height, false), _backDepth(OpenGLFramebuffer::CreateDepthTexture(width, height))
SwapFramebuffer::SwapFramebuffer(int32_t width, int32_t height)
: _opaqueFramebuffer(width, height)
, _transparentFramebuffer(width, height)
, _mixFramebuffer(width, height, false)
, _backDepth(OpenGLFramebuffer::CreateDepthTexture(width, height))
{
_transparentFramebuffer.Bind();
glClearBufferfv(GL_DEPTH, 0, depthValueTransparent);
}
void SwapFramebuffer::ApplyTransparency(ApplyTransparencyShader &shader, GLuint paletteTex)
void SwapFramebuffer::ApplyTransparency(ApplyTransparencyShader& shader, GLuint paletteTex)
{
_mixFramebuffer.Bind();
glDisable(GL_DEPTH_TEST);
@ -34,8 +37,7 @@ void SwapFramebuffer::ApplyTransparency(ApplyTransparencyShader &shader, GLuint
_opaqueFramebuffer.GetDepthTexture(),
_transparentFramebuffer.GetTexture(),
_transparentFramebuffer.GetDepthTexture(),
paletteTex
);
paletteTex);
shader.Draw();
_backDepth = _transparentFramebuffer.SwapDepthTexture(_backDepth);
@ -46,7 +48,7 @@ void SwapFramebuffer::ApplyTransparency(ApplyTransparencyShader &shader, GLuint
glClearBufferfv(GL_DEPTH, 0, depthValueTransparent);
_opaqueFramebuffer.SwapColourBuffer(_mixFramebuffer);
//Change binding to guaruntee no undefined behavior
// Change binding to guaruntee no undefined behavior
_opaqueFramebuffer.Bind();
}

View File

@ -9,11 +9,12 @@
#pragma once
#include <openrct2/common.h>
#include "ApplyTransparencyShader.h"
#include "OpenGLAPI.h"
#include "OpenGLFramebuffer.h"
#include <openrct2/common.h>
/**
* Class to maintain two different framebuffers where the active framebuffer
* will swap between the two, copying the other's pixels in the process for
@ -25,19 +26,31 @@
class SwapFramebuffer final
{
private:
OpenGLFramebuffer _opaqueFramebuffer;
OpenGLFramebuffer _transparentFramebuffer;
OpenGLFramebuffer _mixFramebuffer;
GLuint _backDepth;
OpenGLFramebuffer _opaqueFramebuffer;
OpenGLFramebuffer _transparentFramebuffer;
OpenGLFramebuffer _mixFramebuffer;
GLuint _backDepth;
public:
SwapFramebuffer(int32_t width, int32_t height);
const OpenGLFramebuffer &GetFinalFramebuffer() const { return _opaqueFramebuffer; }
GLuint GetBackDepthTexture() const { return _backDepth; }
void BindOpaque() { _opaqueFramebuffer.Bind(); }
void BindTransparent() { _transparentFramebuffer.Bind(); }
const OpenGLFramebuffer& GetFinalFramebuffer() const
{
return _opaqueFramebuffer;
}
GLuint GetBackDepthTexture() const
{
return _backDepth;
}
void BindOpaque()
{
_opaqueFramebuffer.Bind();
}
void BindTransparent()
{
_transparentFramebuffer.Bind();
}
void ApplyTransparency(ApplyTransparencyShader &shader, GLuint paletteTex);
void ApplyTransparency(ApplyTransparencyShader& shader, GLuint paletteTex);
void Clear();
};

View File

@ -9,11 +9,12 @@
#ifndef DISABLE_OPENGL
#include "TextureCache.h"
#include <algorithm>
#include <openrct2/drawing/Drawing.h>
#include <stdexcept>
#include <vector>
#include <openrct2/drawing/Drawing.h>
#include "TextureCache.h"
constexpr uint32_t UNUSED_INDEX = 0xFFFFFFFF;
@ -66,8 +67,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image)
if (index != UNUSED_INDEX)
{
const auto& info = _textureCache[index];
return
{
return {
info.index,
info.normalizedBounds,
};
@ -83,18 +83,17 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image)
return info;
}
BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t * palette)
BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* palette)
{
GlyphId glyphId;
glyphId.Image = image;
std::copy_n(palette, sizeof(glyphId.Palette), (uint8_t *)&glyphId.Palette);
std::copy_n(palette, sizeof(glyphId.Palette), (uint8_t*)&glyphId.Palette);
auto kvp = _glyphTextureMap.find(glyphId);
if (kvp != _glyphTextureMap.end())
{
const auto& info = kvp->second;
return
{
return {
info.index,
info.normalizedBounds,
};
@ -112,13 +111,15 @@ void TextureCache::CreateTextures()
{
// Determine width and height to use for texture atlases
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_atlasesTextureDimensions);
if (_atlasesTextureDimensions > TEXTURE_CACHE_MAX_ATLAS_SIZE) {
if (_atlasesTextureDimensions > TEXTURE_CACHE_MAX_ATLAS_SIZE)
{
_atlasesTextureDimensions = TEXTURE_CACHE_MAX_ATLAS_SIZE;
}
// Determine maximum number of atlases (minimum of size and array limit)
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &_atlasesTextureIndicesLimit);
if (_atlasesTextureDimensions < _atlasesTextureIndicesLimit) _atlasesTextureIndicesLimit = _atlasesTextureDimensions;
if (_atlasesTextureDimensions < _atlasesTextureIndicesLimit)
_atlasesTextureIndicesLimit = _atlasesTextureDimensions;
glGenTextures(1, &_atlasesTexture);
glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture);
@ -143,12 +144,12 @@ void TextureCache::GeneratePaletteTexture()
rct_drawpixelinfo dpi = CreateDPI(256, PALETTE_TO_G1_OFFSET_COUNT + 5);
// Init no-op palette
for (int i=0; i < 256; ++i)
for (int i = 0; i < 256; ++i)
{
dpi.bits[i] = i;
}
for (int i=0; i < PALETTE_TO_G1_OFFSET_COUNT; ++i)
for (int i = 0; i < PALETTE_TO_G1_OFFSET_COUNT; ++i)
{
GLint y = PaletteToY(i);
uint16_t image = palette_to_g1_offset[i];
@ -157,7 +158,8 @@ void TextureCache::GeneratePaletteTexture()
}
glBindTexture(GL_TEXTURE_RECTANGLE, _paletteTexture);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_R8UI, 256, PALETTE_TO_G1_OFFSET_COUNT + 5, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, dpi.bits);
glTexImage2D(
GL_TEXTURE_RECTANGLE, 0, GL_R8UI, 256, PALETTE_TO_G1_OFFSET_COUNT + 5, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, dpi.bits);
DeleteDPI(dpi);
}
@ -175,10 +177,31 @@ void TextureCache::EnlargeAtlasesTexture(GLuint newEntries)
}
glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8UI, _atlasesTextureDimensions, _atlasesTextureDimensions, newIndices, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, nullptr);
glTexImage3D(
GL_TEXTURE_2D_ARRAY,
0,
GL_R8UI,
_atlasesTextureDimensions,
_atlasesTextureDimensions,
newIndices,
0,
GL_RED_INTEGER,
GL_UNSIGNED_BYTE,
nullptr);
// Restore old data
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _atlasesTextureDimensions, _atlasesTextureDimensions, _atlasesTextureIndices, GL_RED_INTEGER, GL_UNSIGNED_BYTE, oldPixels.data());
glTexSubImage3D(
GL_TEXTURE_2D_ARRAY,
0,
0,
0,
0,
_atlasesTextureDimensions,
_atlasesTextureDimensions,
_atlasesTextureIndices,
GL_RED_INTEGER,
GL_UNSIGNED_BYTE,
oldPixels.data());
_atlasesTextureIndices = newIndices;
}
@ -191,14 +214,25 @@ AtlasTextureInfo TextureCache::LoadImageTexture(uint32_t image)
cacheInfo.image = image;
glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, cacheInfo.bounds.x, cacheInfo.bounds.y, cacheInfo.index, dpi.width, dpi.height, 1, GL_RED_INTEGER, GL_UNSIGNED_BYTE, dpi.bits);
glTexSubImage3D(
GL_TEXTURE_2D_ARRAY,
0,
cacheInfo.bounds.x,
cacheInfo.bounds.y,
cacheInfo.index,
dpi.width,
dpi.height,
1,
GL_RED_INTEGER,
GL_UNSIGNED_BYTE,
dpi.bits);
DeleteDPI(dpi);
return cacheInfo;
}
AtlasTextureInfo TextureCache::LoadGlyphTexture(uint32_t image, uint8_t * palette)
AtlasTextureInfo TextureCache::LoadGlyphTexture(uint32_t image, uint8_t* palette)
{
rct_drawpixelinfo dpi = GetGlyphAsDPI(image, palette);
@ -206,7 +240,18 @@ AtlasTextureInfo TextureCache::LoadGlyphTexture(uint32_t image, uint8_t * palett
cacheInfo.image = image;
glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, cacheInfo.bounds.x, cacheInfo.bounds.y, cacheInfo.index, dpi.width, dpi.height, 1, GL_RED_INTEGER, GL_UNSIGNED_BYTE, dpi.bits);
glTexSubImage3D(
GL_TEXTURE_2D_ARRAY,
0,
cacheInfo.bounds.x,
cacheInfo.bounds.y,
cacheInfo.index,
dpi.width,
dpi.height,
1,
GL_RED_INTEGER,
GL_UNSIGNED_BYTE,
dpi.bits);
DeleteDPI(dpi);
@ -227,13 +272,13 @@ AtlasTextureInfo TextureCache::AllocateImage(int32_t imageWidth, int32_t imageHe
}
// If there is no such atlas, then create a new one
if ((int32_t) _atlases.size() >= _atlasesTextureIndicesLimit)
if ((int32_t)_atlases.size() >= _atlasesTextureIndicesLimit)
{
throw std::runtime_error("more texture atlases required, but device limit reached!");
}
int32_t atlasIndex = (int32_t) _atlases.size();
int32_t atlasSize = (int32_t) powf(2, (float) Atlas::CalculateImageSizeOrder(imageWidth, imageHeight));
int32_t atlasIndex = (int32_t)_atlases.size();
int32_t atlasSize = (int32_t)powf(2, (float)Atlas::CalculateImageSizeOrder(imageWidth, imageHeight));
#ifdef DEBUG
log_verbose("new texture atlas #%d (size %d) allocated\n", atlasIndex, atlasSize);
@ -260,7 +305,7 @@ rct_drawpixelinfo TextureCache::GetImageAsDPI(uint32_t image, uint32_t tertiaryC
return dpi;
}
rct_drawpixelinfo TextureCache::GetGlyphAsDPI(uint32_t image, uint8_t * palette)
rct_drawpixelinfo TextureCache::GetGlyphAsDPI(uint32_t image, uint8_t* palette)
{
auto g1Element = gfx_get_g1_element(image & 0x7FFFF);
int32_t width = g1Element->width;
@ -298,7 +343,7 @@ rct_drawpixelinfo TextureCache::CreateDPI(int32_t width, int32_t height)
void TextureCache::DeleteDPI(rct_drawpixelinfo dpi)
{
delete [] dpi.bits;
delete[] dpi.bits;
}
GLuint TextureCache::GetAtlasesTexture()

View File

@ -9,13 +9,14 @@
#pragma once
#include "GLSLTypes.h"
#include "OpenGLAPI.h"
#include <SDL2/SDL_pixels.h>
#include <array>
#include <openrct2/common.h>
#include <unordered_map>
#include <vector>
#include <array>
#include <SDL2/SDL_pixels.h>
#include <openrct2/common.h>
#include "OpenGLAPI.h"
#include "GLSLTypes.h"
struct rct_drawpixelinfo;
@ -26,7 +27,7 @@ struct GlyphId
struct Hash
{
size_t operator()(const GlyphId &k) const
size_t operator()(const GlyphId& k) const
{
size_t hash = k.Image * 7;
hash += (k.Palette & 0xFFFFFFFF) * 13;
@ -37,10 +38,9 @@ struct GlyphId
struct Equal
{
bool operator()(const GlyphId &lhs, const GlyphId &rhs) const
bool operator()(const GlyphId& lhs, const GlyphId& rhs) const
{
return lhs.Image == rhs.Image &&
lhs.Palette == rhs.Palette;
return lhs.Image == rhs.Image && lhs.Palette == rhs.Palette;
}
};
};
@ -73,9 +73,9 @@ struct AtlasTextureInfo : public BasicTextureInfo
class Atlas final
{
private:
GLuint _index = 0;
int32_t _imageSize = 0;
int32_t _atlasWidth = 0;
GLuint _index = 0;
int32_t _imageSize = 0;
int32_t _atlasWidth = 0;
int32_t _atlasHeight = 0;
std::vector<GLuint> _freeSlots;
@ -134,25 +134,26 @@ public:
bool IsImageSuitable(int32_t actualWidth, int32_t actualHeight) const
{
int32_t imageOrder = CalculateImageSizeOrder(actualWidth, actualHeight);
int32_t atlasOrder = (int32_t) log2(_imageSize);
int32_t atlasOrder = (int32_t)log2(_imageSize);
return imageOrder == atlasOrder;
}
int32_t GetFreeSlots() const
{
return (int32_t) _freeSlots.size();
return (int32_t)_freeSlots.size();
}
static int32_t CalculateImageSizeOrder(int32_t actualWidth, int32_t actualHeight)
{
int32_t actualSize = std::max(actualWidth, actualHeight);
if (actualSize < TEXTURE_CACHE_SMALLEST_SLOT) {
if (actualSize < TEXTURE_CACHE_SMALLEST_SLOT)
{
actualSize = TEXTURE_CACHE_SMALLEST_SLOT;
}
return (int32_t) ceil(log2f((float) actualSize));
return (int32_t)ceil(log2f((float)actualSize));
}
private:
@ -161,8 +162,7 @@ private:
int32_t row = slot / _cols;
int32_t col = slot % _cols;
return ivec4
{
return ivec4{
_imageSize * col,
_imageSize * row,
_imageSize * col + actualWidth,
@ -172,12 +172,11 @@ private:
vec4 NormalizeCoordinates(const ivec4& coords) const
{
return vec4
{
coords.x / (float) _atlasWidth,
coords.y / (float) _atlasHeight,
coords.z / (float) _atlasWidth,
coords.w / (float) _atlasHeight,
return vec4{
coords.x / (float)_atlasWidth,
coords.y / (float)_atlasHeight,
coords.z / (float)_atlasWidth,
coords.w / (float)_atlasHeight,
};
}
};
@ -185,25 +184,25 @@ private:
class TextureCache final
{
private:
bool _initialized = false;
bool _initialized = false;
GLuint _atlasesTexture = 0;
GLint _atlasesTextureDimensions = 0;
GLuint _atlasesTextureIndices = 0;
GLuint _atlasesTexture = 0;
GLint _atlasesTextureDimensions = 0;
GLuint _atlasesTextureIndices = 0;
GLint _atlasesTextureIndicesLimit = 0;
std::vector<Atlas> _atlases;
std::unordered_map<GlyphId, AtlasTextureInfo, GlyphId::Hash, GlyphId::Equal> _glyphTextureMap;
std::vector<AtlasTextureInfo> _textureCache;
std::array<uint32_t, 0x7FFFF> _indexMap;
GLuint _paletteTexture = 0;
GLuint _paletteTexture = 0;
public:
TextureCache();
~TextureCache();
void InvalidateImage(uint32_t image);
BasicTextureInfo GetOrLoadImageTexture(uint32_t image);
BasicTextureInfo GetOrLoadGlyphTexture(uint32_t image, uint8_t * palette);
BasicTextureInfo GetOrLoadGlyphTexture(uint32_t image, uint8_t* palette);
GLuint GetAtlasesTexture();
GLuint GetPaletteTexture();
@ -214,10 +213,10 @@ private:
void GeneratePaletteTexture();
void EnlargeAtlasesTexture(GLuint newEntries);
AtlasTextureInfo LoadImageTexture(uint32_t image);
AtlasTextureInfo LoadGlyphTexture(uint32_t image, uint8_t * palette);
AtlasTextureInfo LoadGlyphTexture(uint32_t image, uint8_t* palette);
AtlasTextureInfo AllocateImage(int32_t imageWidth, int32_t imageHeight);
rct_drawpixelinfo GetImageAsDPI(uint32_t image, uint32_t tertiaryColour);
rct_drawpixelinfo GetGlyphAsDPI(uint32_t image, uint8_t * palette);
rct_drawpixelinfo GetGlyphAsDPI(uint32_t image, uint8_t* palette);
void FreeTextures();
static rct_drawpixelinfo CreateDPI(int32_t width, int32_t height);

View File

@ -31,12 +31,12 @@ typedef std::vector<XData> SweepLine;
* from left to right. If multiple edges are at the same x coordinate, Then
* edges for boxes to the left will appear before edges for boxes to the right.
*/
static inline SweepLine CreateXList(const RectCommandBatch &transparent)
static inline SweepLine CreateXList(const RectCommandBatch& transparent)
{
SweepLine x_sweep;
x_sweep.reserve(transparent.size() * 2);
for (const DrawRectCommand &command : transparent)
for (const DrawRectCommand& command : transparent)
{
int32_t left = std::min(std::max(command.bounds.x, command.clip.x), command.clip.z);
int32_t top = std::min(std::max(command.bounds.y, command.clip.y), command.clip.w);
@ -45,16 +45,20 @@ static inline SweepLine CreateXList(const RectCommandBatch &transparent)
assert(left <= right);
assert(top <= bottom);
if (left == right) continue;
if (top == bottom) continue;
if (left == right)
continue;
if (top == bottom)
continue;
x_sweep.push_back({left, true, top, bottom});
x_sweep.push_back({right, false, top, bottom});
x_sweep.push_back({ left, true, top, bottom });
x_sweep.push_back({ right, false, top, bottom });
}
std::sort(x_sweep.begin(), x_sweep.end(), [](const XData &a, const XData &b) -> bool {
if (a.xposition != b.xposition) return a.xposition < b.xposition;
else return !a.begin && b.begin;
std::sort(x_sweep.begin(), x_sweep.end(), [](const XData& a, const XData& b) -> bool {
if (a.xposition != b.xposition)
return a.xposition < b.xposition;
else
return !a.begin && b.begin;
});
return x_sweep;
@ -78,9 +82,9 @@ typedef std::map<int32_t, YData> IntervalTree;
* Inserts the interval's top endpoint into the interval tree. If the endpoint
* already exists in the interval tree, it stacks the endpoints.
*/
static inline IntervalTree::iterator InsertTopEndpoint(IntervalTree &y_intersect, int32_t top)
static inline IntervalTree::iterator InsertTopEndpoint(IntervalTree& y_intersect, int32_t top)
{
auto top_in = y_intersect.insert({top, {1, 0}});
auto top_in = y_intersect.insert({ top, { 1, 0 } });
IntervalTree::iterator top_it = top_in.first;
if (top_in.second)
{
@ -102,9 +106,9 @@ static inline IntervalTree::iterator InsertTopEndpoint(IntervalTree &y_intersect
* endpoint already exists in the interval tree, it stacks the endpoint.
* This function can produce a new maximum depth.
*/
static inline IntervalTree::iterator InsertBottomEndpoint(IntervalTree &y_intersect, int32_t bottom)
static inline IntervalTree::iterator InsertBottomEndpoint(IntervalTree& y_intersect, int32_t bottom)
{
auto bottom_in = y_intersect.insert({bottom, {1, 1}});
auto bottom_in = y_intersect.insert({ bottom, { 1, 1 } });
IntervalTree::iterator bottom_it = bottom_in.first;
if (bottom_in.second)
{
@ -125,7 +129,7 @@ static inline IntervalTree::iterator InsertBottomEndpoint(IntervalTree &y_inters
/*
* Removes the interval's top endpoint, handling stacked endpoints.
*/
static inline void RemoveTopEndpoint(IntervalTree &y_intersect, IntervalTree::iterator top_it)
static inline void RemoveTopEndpoint(IntervalTree& y_intersect, IntervalTree::iterator top_it)
{
if (top_it->second.count == 1)
{
@ -140,7 +144,7 @@ static inline void RemoveTopEndpoint(IntervalTree &y_intersect, IntervalTree::it
/*
* Removes the interval's bottom endpoint, handling stacked endpoints.
*/
static inline void RemoveBottomEndpoint(IntervalTree &y_intersect, IntervalTree::iterator bottom_it)
static inline void RemoveBottomEndpoint(IntervalTree& y_intersect, IntervalTree::iterator bottom_it)
{
if (bottom_it->second.count == 1)
{
@ -158,13 +162,13 @@ static inline void RemoveBottomEndpoint(IntervalTree &y_intersect, IntervalTree:
* to render the command batch. It will never underestimate the number of
* iterations, but it can overestimate, usually by no more than +2.
*/
int32_t MaxTransparencyDepth(const RectCommandBatch &transparent)
int32_t MaxTransparencyDepth(const RectCommandBatch& transparent)
{
int32_t max_depth = 1;
SweepLine x_sweep = CreateXList(transparent);
IntervalTree y_intersect{};
for (const XData &x : x_sweep)
for (const XData& x : x_sweep)
{
if (x.begin)
{

View File

@ -9,12 +9,13 @@
#pragma once
#include <openrct2/common.h>
#include "DrawCommands.h"
#include <openrct2/common.h>
/*
* Determines an aproximation of the number of depth peeling iterations needed
* to render the command batch. It will never underestimate the number of
* iterations, but it can overestimate, usually by no more than +2.
*/
int32_t MaxTransparencyDepth(const RectCommandBatch &transparent);
int32_t MaxTransparencyDepth(const RectCommandBatch& transparent);