mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Clean up OpenGL engine.
Code de-duplication and improved namespacing.
This commit is contained in:
committed by
Aaron van Geffen
parent
91f91d4388
commit
efea8856ed
@@ -28,7 +28,7 @@ public:
|
||||
ApplyPaletteShader();
|
||||
~ApplyPaletteShader() override;
|
||||
|
||||
void SetTexture(GLuint texture);
|
||||
static void SetTexture(GLuint texture);
|
||||
void SetPalette(const vec4* glPalette);
|
||||
|
||||
void Draw();
|
||||
|
||||
@@ -31,7 +31,8 @@ public:
|
||||
ApplyTransparencyShader();
|
||||
~ApplyTransparencyShader() override;
|
||||
|
||||
void SetTextures(GLuint opaqueTex, GLuint opaqueDepth, GLuint transparentTex, GLuint transparentDepth, GLuint paletteTex);
|
||||
static void SetTextures(
|
||||
GLuint opaqueTex, GLuint opaqueDepth, GLuint transparentTex, GLuint transparentDepth, GLuint paletteTex);
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
: _numInstances(0)
|
||||
{
|
||||
}
|
||||
bool empty() const
|
||||
[[nodiscard]] bool empty() const
|
||||
{
|
||||
return _numInstances == 0;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
}
|
||||
return _instances[_numInstances++] = value;
|
||||
}
|
||||
size_t size() const
|
||||
[[nodiscard]] size_t size() const
|
||||
{
|
||||
return _numInstances;
|
||||
}
|
||||
@@ -114,9 +114,9 @@ struct DrawRectCommand
|
||||
|
||||
enum
|
||||
{
|
||||
FLAG_NO_TEXTURE = (1 << 2),
|
||||
FLAG_MASK = (1 << 3),
|
||||
FLAG_CROSS_HATCH = (1 << 4),
|
||||
FLAG_NO_TEXTURE = (1U << 2U),
|
||||
FLAG_MASK = (1U << 3U),
|
||||
FLAG_CROSS_HATCH = (1U << 4U),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "OpenGLShaderProgram.h"
|
||||
|
||||
#include <SDL_pixels.h>
|
||||
#include <vector>
|
||||
|
||||
class DrawRectShader final : public OpenGLShaderProgram
|
||||
{
|
||||
|
||||
@@ -15,136 +15,98 @@
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct ivec2
|
||||
namespace detail
|
||||
{
|
||||
union
|
||||
template<typename T_> struct vec2
|
||||
{
|
||||
GLint x;
|
||||
GLint s;
|
||||
GLint r;
|
||||
};
|
||||
union
|
||||
{
|
||||
GLint y;
|
||||
GLint t;
|
||||
GLint g;
|
||||
};
|
||||
};
|
||||
using ValueType = T_;
|
||||
|
||||
struct vec2
|
||||
{
|
||||
union
|
||||
{
|
||||
GLfloat x;
|
||||
GLfloat s;
|
||||
GLfloat r;
|
||||
union
|
||||
{
|
||||
ValueType x;
|
||||
ValueType s;
|
||||
ValueType r;
|
||||
};
|
||||
union
|
||||
{
|
||||
ValueType y;
|
||||
ValueType t;
|
||||
ValueType g;
|
||||
};
|
||||
};
|
||||
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;
|
||||
};
|
||||
};
|
||||
template struct vec2<GLfloat>;
|
||||
template struct vec2<GLint>;
|
||||
|
||||
struct vec3f
|
||||
{
|
||||
union
|
||||
template<typename T_> struct vec3
|
||||
{
|
||||
GLfloat x;
|
||||
GLfloat s;
|
||||
GLfloat r;
|
||||
};
|
||||
union
|
||||
{
|
||||
GLfloat y;
|
||||
GLfloat t;
|
||||
GLfloat g;
|
||||
};
|
||||
union
|
||||
{
|
||||
GLfloat z;
|
||||
GLfloat p;
|
||||
GLfloat b;
|
||||
};
|
||||
};
|
||||
using ValueType = T_;
|
||||
|
||||
struct ivec4
|
||||
{
|
||||
union
|
||||
{
|
||||
GLint x;
|
||||
GLint s;
|
||||
GLint r;
|
||||
union
|
||||
{
|
||||
ValueType x;
|
||||
ValueType s;
|
||||
ValueType r;
|
||||
};
|
||||
union
|
||||
{
|
||||
ValueType y;
|
||||
ValueType t;
|
||||
ValueType g;
|
||||
};
|
||||
union
|
||||
{
|
||||
ValueType z;
|
||||
ValueType p;
|
||||
ValueType b;
|
||||
};
|
||||
};
|
||||
union
|
||||
{
|
||||
GLint y;
|
||||
GLint t;
|
||||
GLint g;
|
||||
};
|
||||
union
|
||||
{
|
||||
GLint z;
|
||||
GLint p;
|
||||
GLint b;
|
||||
};
|
||||
union
|
||||
{
|
||||
GLint w;
|
||||
GLint q;
|
||||
GLint a;
|
||||
};
|
||||
};
|
||||
|
||||
struct vec4
|
||||
{
|
||||
union
|
||||
template struct vec3<GLfloat>;
|
||||
template struct vec3<GLint>;
|
||||
|
||||
template<typename T_> struct vec4
|
||||
{
|
||||
GLfloat x;
|
||||
GLfloat s;
|
||||
GLfloat r;
|
||||
using ValueType = T_;
|
||||
|
||||
union
|
||||
{
|
||||
ValueType x;
|
||||
ValueType s;
|
||||
ValueType r;
|
||||
};
|
||||
union
|
||||
{
|
||||
ValueType y;
|
||||
ValueType t;
|
||||
ValueType g;
|
||||
};
|
||||
union
|
||||
{
|
||||
ValueType z;
|
||||
ValueType p;
|
||||
ValueType b;
|
||||
};
|
||||
union
|
||||
{
|
||||
ValueType w;
|
||||
ValueType q;
|
||||
ValueType a;
|
||||
};
|
||||
};
|
||||
union
|
||||
{
|
||||
GLfloat y;
|
||||
GLfloat t;
|
||||
GLfloat g;
|
||||
};
|
||||
union
|
||||
{
|
||||
GLfloat z;
|
||||
GLfloat p;
|
||||
GLfloat b;
|
||||
};
|
||||
union
|
||||
{
|
||||
GLfloat w;
|
||||
GLfloat q;
|
||||
GLfloat a;
|
||||
};
|
||||
};
|
||||
|
||||
template struct vec4<GLfloat>;
|
||||
template struct vec4<GLint>;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using vec2 = detail::vec2<GLfloat>;
|
||||
using ivec2 = detail::vec2<GLint>;
|
||||
|
||||
using vec3 = detail::vec3<GLfloat>;
|
||||
using ivec3 = detail::vec3<GLint>;
|
||||
|
||||
using vec4 = detail::vec4<GLfloat>;
|
||||
using ivec4 = detail::vec4<GLint>;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
@@ -65,7 +65,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image)
|
||||
{
|
||||
uint32_t index;
|
||||
|
||||
image &= 0x7FFFF;
|
||||
image &= 0x7FFFFUL;
|
||||
|
||||
// Try to read cached texture first.
|
||||
{
|
||||
@@ -97,7 +97,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image)
|
||||
|
||||
BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* palette)
|
||||
{
|
||||
GlyphId glyphId;
|
||||
GlyphId glyphId{};
|
||||
glyphId.Image = image;
|
||||
|
||||
// Try to read cached texture first.
|
||||
@@ -203,7 +203,7 @@ void TextureCache::EnlargeAtlasesTexture(GLuint newEntries)
|
||||
}
|
||||
|
||||
// Initial capacity will be 12 which covers most cases of a fully visible park.
|
||||
_atlasesTextureCapacity = (_atlasesTextureCapacity + 6) << 1;
|
||||
_atlasesTextureCapacity = (_atlasesTextureCapacity + 6) << 1UL;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture);
|
||||
@@ -275,8 +275,8 @@ AtlasTextureInfo TextureCache::AllocateImage(int32_t imageWidth, int32_t imageHe
|
||||
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));
|
||||
auto atlasIndex = static_cast<int32_t>(_atlases.size());
|
||||
int32_t atlasSize = powf(2, (float)Atlas::CalculateImageSizeOrder(imageWidth, imageHeight));
|
||||
|
||||
# ifdef DEBUG
|
||||
log_verbose("new texture atlas #%d (size %d) allocated", atlasIndex, atlasSize);
|
||||
@@ -294,7 +294,7 @@ AtlasTextureInfo TextureCache::AllocateImage(int32_t imageWidth, int32_t imageHe
|
||||
|
||||
rct_drawpixelinfo TextureCache::GetImageAsDPI(uint32_t image, uint32_t tertiaryColour)
|
||||
{
|
||||
auto g1Element = gfx_get_g1_element(image & 0x7FFFF);
|
||||
auto g1Element = gfx_get_g1_element(image & 0x7FFFFUL);
|
||||
int32_t width = g1Element->width;
|
||||
int32_t height = g1Element->height;
|
||||
|
||||
@@ -305,7 +305,7 @@ rct_drawpixelinfo TextureCache::GetImageAsDPI(uint32_t image, uint32_t tertiaryC
|
||||
|
||||
rct_drawpixelinfo TextureCache::GetGlyphAsDPI(uint32_t image, uint8_t* palette)
|
||||
{
|
||||
auto g1Element = gfx_get_g1_element(image & 0x7FFFF);
|
||||
auto g1Element = gfx_get_g1_element(image & 0x7FFFFUL);
|
||||
int32_t width = g1Element->width;
|
||||
int32_t height = g1Element->height;
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ struct GlyphId
|
||||
size_t operator()(const GlyphId& k) const
|
||||
{
|
||||
size_t hash = k.Image * 7;
|
||||
hash += (k.Palette & 0xFFFFFFFF) * 13;
|
||||
hash += (k.Palette >> 32) * 23;
|
||||
hash += (k.Palette & 0xFFFFFFFFUL) * 13;
|
||||
hash += (k.Palette >> 32UL) * 23;
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
@@ -111,14 +111,14 @@ public:
|
||||
|
||||
AtlasTextureInfo Allocate(int32_t actualWidth, int32_t actualHeight)
|
||||
{
|
||||
assert(_freeSlots.size() > 0);
|
||||
assert(!_freeSlots.empty());
|
||||
|
||||
GLuint slot = _freeSlots.back();
|
||||
_freeSlots.pop_back();
|
||||
|
||||
auto bounds = GetSlotCoordinates(slot, actualWidth, actualHeight);
|
||||
|
||||
AtlasTextureInfo info;
|
||||
AtlasTextureInfo info{};
|
||||
info.index = _index;
|
||||
info.slot = slot;
|
||||
info.bounds = bounds;
|
||||
@@ -136,15 +136,15 @@ public:
|
||||
|
||||
// Checks if specified image would be tightly packed in this atlas
|
||||
// by checking if it is within the right power of 2 range
|
||||
bool IsImageSuitable(int32_t actualWidth, int32_t actualHeight) const
|
||||
[[nodiscard]] 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 = log2(_imageSize);
|
||||
|
||||
return imageOrder == atlasOrder;
|
||||
}
|
||||
|
||||
int32_t GetFreeSlots() const
|
||||
[[nodiscard]] int32_t GetFreeSlots() const
|
||||
{
|
||||
return (int32_t)_freeSlots.size();
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
ivec4 GetSlotCoordinates(GLuint slot, int32_t actualWidth, int32_t actualHeight) const
|
||||
[[nodiscard]] ivec4 GetSlotCoordinates(GLuint slot, int32_t actualWidth, int32_t actualHeight) const
|
||||
{
|
||||
int32_t row = slot / _cols;
|
||||
int32_t col = slot % _cols;
|
||||
@@ -175,7 +175,7 @@ private:
|
||||
};
|
||||
}
|
||||
|
||||
vec4 NormalizeCoordinates(const ivec4& coords) const
|
||||
[[nodiscard]] vec4 NormalizeCoordinates(const ivec4& coords) const
|
||||
{
|
||||
return vec4{
|
||||
coords.x / (float)_atlasWidth,
|
||||
@@ -231,8 +231,8 @@ private:
|
||||
AtlasTextureInfo LoadImageTexture(uint32_t image);
|
||||
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);
|
||||
static rct_drawpixelinfo GetImageAsDPI(uint32_t image, uint32_t tertiaryColour);
|
||||
static rct_drawpixelinfo GetGlyphAsDPI(uint32_t image, uint8_t* palette);
|
||||
void FreeTextures();
|
||||
|
||||
static rct_drawpixelinfo CreateDPI(int32_t width, int32_t height);
|
||||
|
||||
Reference in New Issue
Block a user