1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 07:43:01 +01:00

Add Shader Palette Lookup

This commit is contained in:
Ted John
2016-06-15 17:53:26 +01:00
committed by GitHub
parent d0dead085a
commit 19cd56b9c2
23 changed files with 146 additions and 87 deletions

View File

@@ -1,11 +1,11 @@
#version 330
#version 150
uniform sampler2D uTexture;
in vec2 fPosition;
in vec2 fTextureCoordinate;
layout (location = 0) out vec4 oColour;
out vec4 oColour;
void main()
{

View File

@@ -1,10 +1,10 @@
#version 330
#version 150
uniform ivec2 uScreenSize;
uniform ivec4 uBounds;
uniform ivec4 uTextureCoordinates;
in int vIndex;
in uint vIndex;
out vec2 fPosition;
out vec2 fTextureCoordinate;
@@ -13,22 +13,22 @@ void main()
{
vec2 pos;
switch (vIndex) {
case 0:
case 0u:
pos = uBounds.xy;
fTextureCoordinate = uTextureCoordinates.xy;
break;
case 1:
case 1u:
pos = uBounds.zy;
fTextureCoordinate = uTextureCoordinates.zy;
break;
case 2:
pos = uBounds.zw;
fTextureCoordinate = uTextureCoordinates.zw;
break;
case 3:
case 2u:
pos = uBounds.xw;
fTextureCoordinate = uTextureCoordinates.xw;
break;
case 3u:
pos = uBounds.zw;
fTextureCoordinate = uTextureCoordinates.zw;
break;
}
fPosition = pos;

View File

@@ -1,14 +1,15 @@
#version 330
#version 150
uniform ivec4 uClip;
uniform int uFlags;
uniform vec4 uColour;
uniform sampler2D uTexture;
uniform usampler2D uTexture;
uniform vec4 uPalette[256];
in vec2 fPosition;
in vec2 fTextureCoordinate;
layout (location = 0) out vec4 oColour;
out vec4 oColour;
void main()
{
@@ -18,7 +19,7 @@ void main()
discard;
}
vec4 texel = texture(uTexture, fTextureCoordinate);
vec4 texel = uPalette[texture(uTexture, fTextureCoordinate).r];
if ((uFlags & 1) != 0)
{
oColour = vec4(uColour.rgb, uColour.a * texel.a);

View File

@@ -1,10 +1,10 @@
#version 330
#version 150
uniform ivec2 uScreenSize;
uniform ivec4 uBounds;
uniform ivec4 uTextureCoordinates;
in int vIndex;
in uint vIndex;
out vec2 fPosition;
out vec2 fTextureCoordinate;
@@ -13,22 +13,22 @@ void main()
{
vec2 pos;
switch (vIndex) {
case 0:
case 0u:
pos = uBounds.xy;
fTextureCoordinate = uTextureCoordinates.xy;
break;
case 1:
case 1u:
pos = uBounds.zy;
fTextureCoordinate = uTextureCoordinates.zy;
break;
case 2:
pos = uBounds.zw;
fTextureCoordinate = uTextureCoordinates.zw;
break;
case 3:
case 2u:
pos = uBounds.xw;
fTextureCoordinate = uTextureCoordinates.xw;
break;
case 3u:
pos = uBounds.zw;
fTextureCoordinate = uTextureCoordinates.zw;
break;
}
fPosition = pos;

View File

@@ -1,13 +1,14 @@
#version 330
#version 150
uniform ivec4 uClip;
uniform sampler2D uTextureMask;
uniform sampler2D uTextureColour;
uniform usampler2D uTextureMask;
uniform usampler2D uTextureColour;
uniform vec4 uPalette[256];
in vec2 fPosition;
in vec2 fTextureCoordinate;
layout (location = 0) out vec4 oColour;
out vec4 oColour;
void main()
{
@@ -17,7 +18,7 @@ void main()
discard;
}
vec4 mask = texture(uTextureMask, fTextureCoordinate);
vec4 colour = texture(uTextureColour, fTextureCoordinate);
vec4 mask = uPalette[texture(uTextureMask, fTextureCoordinate).r];
vec4 colour = uPalette[texture(uTextureColour, fTextureCoordinate).r];
oColour = colour * mask;
}

View File

@@ -1,9 +1,9 @@
#version 330
#version 150
uniform ivec2 uScreenSize;
uniform ivec4 uBounds;
in int vIndex;
in uint vIndex;
out vec2 fPosition;
out vec2 fTextureCoordinate;
@@ -12,22 +12,22 @@ void main()
{
vec2 pos;
switch (vIndex) {
case 0:
case 0u:
pos = uBounds.xy;
fTextureCoordinate = vec2(0, 0);
break;
case 1:
case 1u:
pos = uBounds.zy;
fTextureCoordinate = vec2(1, 0);
break;
case 2:
pos = uBounds.zw;
fTextureCoordinate = vec2(1, 1);
break;
case 3:
case 2u:
pos = uBounds.xw;
fTextureCoordinate = vec2(0, 1);
break;
case 3u:
pos = uBounds.zw;
fTextureCoordinate = vec2(1, 1);
break;
}
fPosition = pos;

View File

@@ -1,4 +1,4 @@
#version 330
#version 150
uniform ivec2 uScreenSize;
uniform ivec4 uClip;
@@ -6,7 +6,7 @@ uniform vec4 uColour;
in vec2 fPosition;
layout (location = 0) out vec4 oColour;
out vec4 oColour;
void main()
{

View File

@@ -1,16 +1,16 @@
#version 330
#version 150
uniform ivec2 uScreenSize;
uniform ivec4 uBounds;
in int vIndex;
in uint vIndex;
out vec2 fPosition;
void main()
{
vec2 pos;
if (vIndex == 0)
if (vIndex == 0u)
{
pos = uBounds.xy;
}

View File

@@ -1,4 +1,4 @@
#version 330
#version 150
uniform ivec2 uScreenSize;
uniform ivec4 uClip;
@@ -9,7 +9,7 @@ uniform ivec4 uBounds;
in vec2 fPosition;
layout (location = 0) out vec4 oColour;
out vec4 oColour;
float getluma(vec3 colour)
{

View File

@@ -1,9 +1,9 @@
#version 330
#version 150
uniform ivec2 uScreenSize;
uniform ivec4 uBounds;
in int vIndex;
in uint vIndex;
out vec2 fPosition;
@@ -11,18 +11,18 @@ void main()
{
vec2 pos;
switch (vIndex) {
case 0:
case 0u:
pos = uBounds.xy;
break;
case 1:
case 1u:
pos = uBounds.zy;
break;
case 2:
pos = uBounds.zw;
break;
case 3:
case 2u:
pos = uBounds.xw;
break;
case 3u:
pos = uBounds.zw;
break;
}
fPosition = pos;

View File

@@ -25,7 +25,7 @@ CopyFramebufferShader::CopyFramebufferShader() : OpenGLShaderProgram("copyframeb
glGenBuffers(1, &_vbo);
glGenVertexArrays(1, &_vao);
vec2i vertices[] = { 0, 1, 2, 3 };
GLuint vertices[] = { 0, 1, 2, 2, 1, 3 };
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -77,7 +77,7 @@ void CopyFramebufferShader::SetTexture(GLuint texture)
void CopyFramebufferShader::Draw()
{
glBindVertexArray(_vao);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
#endif /* DISABLE_OPENGL */

View File

@@ -25,7 +25,7 @@ DrawImageMaskedShader::DrawImageMaskedShader() : OpenGLShaderProgram("drawimagem
glGenBuffers(1, &_vbo);
glGenVertexArrays(1, &_vao);
vec2i vertices[] = { 0, 1, 2, 3 };
GLuint vertices[] = { 0, 1, 2, 2, 1, 3 };
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -53,6 +53,7 @@ void DrawImageMaskedShader::GetLocations()
uBounds = GetUniformLocation("uBounds");
uTextureMask = GetUniformLocation("uTextureMask");
uTextureColour = GetUniformLocation("uTextureColour");
uPalette = GetUniformLocation("uPalette");
vIndex = GetAttributeLocation("vIndex");
}
@@ -82,12 +83,17 @@ void DrawImageMaskedShader::SetTextureColour(GLuint texture)
OpenGLAPI::SetTexture2D(1, texture);
}
void DrawImageMaskedShader::SetPalette(const vec4f *glPalette)
{
glUniform4fv(uPalette, 256, (const GLfloat *) glPalette);
}
void DrawImageMaskedShader::Draw(sint32 left, sint32 top, sint32 right, sint32 bottom)
{
SetBounds(left, top, right, bottom);
glBindVertexArray(_vao);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
#endif /* DISABLE_OPENGL */

View File

@@ -18,6 +18,7 @@
#include "GLSLTypes.h"
#include "OpenGLShaderProgram.h"
#include <SDL_pixels.h>
class DrawImageMaskedShader : public OpenGLShaderProgram
{
@@ -27,6 +28,7 @@ private:
GLuint uBounds;
GLuint uTextureMask;
GLuint uTextureColour;
GLuint uPalette;
GLuint vIndex;
@@ -42,6 +44,7 @@ public:
void SetBounds(sint32 left, sint32 top, sint32 right, sint32 bottom);
void SetTextureMask(GLuint texture);
void SetTextureColour(GLuint texture);
void SetPalette(const vec4f *glPalette);
void Draw(sint32 left, sint32 top, sint32 right, sint32 bottom);
private:

View File

@@ -25,7 +25,7 @@ DrawImageShader::DrawImageShader() : OpenGLShaderProgram("drawimage")
glGenBuffers(1, &_vbo);
glGenVertexArrays(1, &_vao);
vec2i vertices[] = { 0, 1, 2, 3 };
GLuint vertices[] = { 0, 1, 2, 2, 1, 3 };
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -56,6 +56,7 @@ void DrawImageShader::GetLocations()
uTexture = GetUniformLocation("uTexture");
uColour = GetUniformLocation("uColour");
uFlags = GetUniformLocation("uFlags");
uPalette = GetUniformLocation("uPalette");
vIndex = GetAttributeLocation("vIndex");
}
@@ -95,12 +96,17 @@ void DrawImageShader::SetFlags(uint32 flags)
glUniform1i(uFlags, flags);
}
void DrawImageShader::SetPalette(const vec4f *glPalette)
{
glUniform4fv(uPalette, 256, (const GLfloat *) glPalette);
}
void DrawImageShader::Draw(sint32 left, sint32 top, sint32 right, sint32 bottom)
{
SetBounds(left, top, right, bottom);
glBindVertexArray(_vao);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
#endif /* DISABLE_OPENGL */

View File

@@ -18,6 +18,7 @@
#include "GLSLTypes.h"
#include "OpenGLShaderProgram.h"
#include <SDL_pixels.h>
class DrawImageShader : public OpenGLShaderProgram
{
@@ -29,12 +30,15 @@ private:
GLuint uTexture;
GLuint uColour;
GLuint uFlags;
GLuint uPalette;
GLuint vIndex;
GLuint _vbo;
GLuint _vao;
SDL_Color _palette[256];
public:
DrawImageShader();
~DrawImageShader() override;
@@ -46,7 +50,7 @@ public:
void SetTexture(GLuint texture);
void SetColour(vec4f colour);
void SetFlags(uint32 flags);
void SetPalette(const vec4f *glPalette);
void Draw(sint32 left, sint32 top, sint32 right, sint32 bottom);
private:

View File

@@ -26,7 +26,7 @@ DrawLineShader::DrawLineShader() : OpenGLShaderProgram("drawline")
glGenBuffers(1, &_vbo);
glGenVertexArrays(1, &_vao);
vec2i vertices[] = { 0, 1 };
GLuint vertices[] = { 0, 1 };
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

View File

@@ -26,7 +26,7 @@ FillRectShader::FillRectShader() : OpenGLShaderProgram("fillrect")
glGenBuffers(1, &_vbo);
glGenVertexArrays(1, &_vao);
vec2i vertices[] = { 0, 1, 2, 3 };
GLuint vertices[] = { 0, 1, 2, 2, 1, 3 };
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -95,7 +95,7 @@ void FillRectShader::Draw(sint32 left, sint32 top, sint32 right, sint32 bottom)
SetBounds(left, top, right, bottom);
glBindVertexArray(_vao);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
#endif /* DISABLE_OPENGL */

View File

@@ -63,6 +63,7 @@ static const char * TryLoadAllProcAddresses()
SetupOpenGLFunction(glEnd);
SetupOpenGLFunction(glGenTextures);
SetupOpenGLFunction(glGetError);
SetupOpenGLFunction(glPixelStorei);
SetupOpenGLFunction(glReadPixels);
SetupOpenGLFunction(glTexImage2D);
SetupOpenGLFunction(glTexParameteri);
@@ -101,6 +102,7 @@ static const char * TryLoadAllProcAddresses()
SetupOpenGLFunction(glUniform2i);
SetupOpenGLFunction(glUniform4f);
SetupOpenGLFunction(glUniform4i);
SetupOpenGLFunction(glUniform4fv);
SetupOpenGLFunction(glUseProgram);
SetupOpenGLFunction(glVertexAttribIPointer);
SetupOpenGLFunction(glVertexAttribPointer);

View File

@@ -35,6 +35,7 @@
#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
@@ -61,6 +62,7 @@
#undef glEnd
#undef glGenTextures
#undef glGetError
#undef glPixelStorei
#undef glReadPixels
#undef glTexImage2D
#undef glTexParameteri
@@ -80,6 +82,7 @@ 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);
@@ -110,6 +113,7 @@ GLAPI_DECL PFNGLENABLEPROC glEnable GLAP
GLAPI_DECL PFNGLENDPROC glEnd GLAPI_SET;
GLAPI_DECL PFNGLGENTEXTURESPROC glGenTextures GLAPI_SET;
GLAPI_DECL PFNGLGETERRORPROC glGetError GLAPI_SET;
GLAPI_DECL PFNGLPIXELSTOREIPROC glPixelStorei GLAPI_SET;
GLAPI_DECL PFNGLREADPIXELSPROC glReadPixels GLAPI_SET;
GLAPI_DECL PFNGLTEXIMAGE2DPROC glTexImage2D GLAPI_SET;
GLAPI_DECL PFNGLTEXPARAMETERIPROC glTexParameteri GLAPI_SET;
@@ -148,6 +152,7 @@ GLAPI_DECL PFNGLUNIFORM1IPROC glUniform1i GLAP
GLAPI_DECL PFNGLUNIFORM2IPROC glUniform2i GLAPI_SET;
GLAPI_DECL PFNGLUNIFORM4FPROC glUniform4f GLAPI_SET;
GLAPI_DECL PFNGLUNIFORM4IPROC glUniform4i GLAPI_SET;
GLAPI_DECL PFNGLUNIFORM4FVPROC glUniform4fv GLAPI_SET;
GLAPI_DECL PFNGLUSEPROGRAMPROC glUseProgram GLAPI_SET;
GLAPI_DECL PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer GLAPI_SET;
GLAPI_DECL PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer GLAPI_SET;

View File

@@ -192,6 +192,7 @@ public:
void Initialise();
void Resize(sint32 width, sint32 height);
void ResetPalette();
void Clear(uint32 colour) override;
void FillRect(uint32 colour, sint32 x, sint32 y, sint32 w, sint32 h) override;
@@ -250,8 +251,9 @@ public:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
_context = SDL_GL_CreateContext(_window);
if(_context == nullptr) throw Exception("OpenGL 3.2 Not Available");
SDL_GL_MakeCurrent(_window, _context);
if (!OpenGLAPI::Initialise())
@@ -264,10 +266,6 @@ public:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Do not draw the unseen side of the primitives
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
_copyFramebufferShader = new CopyFramebufferShader();
}
@@ -291,8 +289,7 @@ public:
colour.b / 255.0f,
colour.a / 255.0f };
}
_drawingContext->GetTextureCache()
->SetPalette(Palette);
_drawingContext->ResetPalette();
}
void Invalidate(sint32 left, sint32 top, sint32 right, sint32 bottom) override
@@ -502,6 +499,15 @@ void OpenGLDrawingContext::Resize(sint32 width, sint32 height)
_fillRectShader->SetScreenSize(width, height);
}
void OpenGLDrawingContext::ResetPalette()
{
_textureCache->SetPalette(_engine->Palette);
_drawImageShader->Use();
_drawImageShader->SetPalette(_engine->GLPalette);
_drawImageMaskedShader->Use();
_drawImageMaskedShader->SetPalette(_engine->GLPalette);
}
void OpenGLDrawingContext::Clear(uint32 colour)
{
FillRect(colour, _clipLeft - _offsetX, _clipTop - _offsetY, _clipRight, _clipBottom);

View File

@@ -107,6 +107,7 @@ OpenGLShaderProgram::OpenGLShaderProgram(const char * name)
_id = glCreateProgram();
glAttachShader(_id, _vertexShader->GetShaderId());
glAttachShader(_id, _fragmentShader->GetShaderId());
glBindFragDataLocation(_id, 0, "oColour");
if (!Link())
{

View File

@@ -1,4 +1,4 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
@@ -53,14 +53,14 @@ void TextureCache::InvalidateImage(uint32 image)
GLuint TextureCache::GetOrLoadImageTexture(uint32 image)
{
auto kvp = _imageTextureMap.find(image);
auto kvp = _imageTextureMap.find(image & 0x7FFFF);
if (kvp != _imageTextureMap.end())
{
return kvp->second;
}
GLuint texture = LoadImageTexture(image);
_imageTextureMap[image] = texture;
_imageTextureMap[image & 0x7FFFF] = texture;
return texture;
}
@@ -88,15 +88,15 @@ GLuint TextureCache::LoadImageTexture(uint32 image)
GLuint texture;
glGenTextures(1, &texture);
uint32 width, height;
void * pixels32 = GetImageAsARGB(image, 0, &width, &height);
rct_drawpixelinfo * dpi = GetImageAsDPI(image, 0);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels32);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, dpi->width, dpi->height, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, dpi->bits);
Memory::Free(pixels32);
DeleteDPI(dpi);
return texture;
}
@@ -106,15 +106,15 @@ GLuint TextureCache::LoadGlyphTexture(uint32 image, uint8 * palette)
GLuint texture;
glGenTextures(1, &texture);
uint32 width, height;
void * pixels32 = GetGlyphAsARGB(image, palette, &width, &height);
rct_drawpixelinfo * dpi = GetGlyphAsDPI(image, palette);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels32);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, dpi->width, dpi->height, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, dpi->bits);
Memory::Free(pixels32);
DeleteDPI(dpi);
return texture;
}
@@ -135,6 +135,17 @@ void * TextureCache::GetImageAsARGB(uint32 image, uint32 tertiaryColour, uint32
return pixels32;
}
rct_drawpixelinfo * TextureCache::GetImageAsDPI(uint32 image, uint32 tertiaryColour)
{
rct_g1_element * g1Element = gfx_get_g1_element(image & 0x7FFFF);
sint32 width = g1Element->width;
sint32 height = g1Element->height;
rct_drawpixelinfo * dpi = CreateDPI(width, height);
gfx_draw_sprite_software(dpi, image, -g1Element->x_offset, -g1Element->y_offset, tertiaryColour);
return dpi;
}
void * TextureCache::GetGlyphAsARGB(uint32 image, uint8 * palette, uint32 * outWidth, uint32 * outHeight)
{
rct_g1_element * g1Element = gfx_get_g1_element(image & 0x7FFFF);
@@ -151,6 +162,17 @@ void * TextureCache::GetGlyphAsARGB(uint32 image, uint8 * palette, uint32 * outW
return pixels32;
}
rct_drawpixelinfo * TextureCache::GetGlyphAsDPI(uint32 image, uint8 * palette)
{
rct_g1_element * g1Element = gfx_get_g1_element(image & 0x7FFFF);
sint32 width = g1Element->width;
sint32 height = g1Element->height;
rct_drawpixelinfo * dpi = CreateDPI(width, height);
gfx_draw_sprite_palette_set_software(dpi, image, -g1Element->x_offset, -g1Element->y_offset, palette, nullptr);
return dpi;
}
void * TextureCache::ConvertDPIto32bpp(const rct_drawpixelinfo * dpi)
{
size_t numPixels = dpi->width * dpi->height;

View File

@@ -69,7 +69,9 @@ private:
GLuint LoadImageTexture(uint32 image);
GLuint LoadGlyphTexture(uint32 image, uint8 * palette);
void * GetImageAsARGB(uint32 image, uint32 tertiaryColour, uint32 * outWidth, uint32 * outHeight);
rct_drawpixelinfo * GetImageAsDPI(uint32 image, uint32 tertiaryColour);
void * GetGlyphAsARGB(uint32 image, uint8 * palette, uint32 * outWidth, uint32 * outHeight);
rct_drawpixelinfo * GetGlyphAsDPI(uint32 image, uint8 * palette);
void * ConvertDPIto32bpp(const rct_drawpixelinfo * dpi);
void FreeTextures();