1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

add cross pattern support for fillrect shader

This commit is contained in:
Ted John
2016-06-08 22:05:20 +01:00
parent c48031581b
commit a9d49838fa
5 changed files with 34 additions and 64 deletions

View File

@@ -3,9 +3,9 @@
uniform ivec4 uClip; uniform ivec4 uClip;
uniform int uFlags; uniform int uFlags;
uniform vec4 uColour; uniform vec4 uColour[2];
flat in ivec2 fPosition; in vec2 fPosition;
layout (location = 0) out vec4 oColour; layout (location = 0) out vec4 oColour;
@@ -17,5 +17,13 @@ void main()
discard; discard;
} }
oColour = uColour; int posSum = int(fPosition.x) + int(fPosition.y);
if ((posSum % 2) == 0)
{
oColour = uColour[0];
}
else
{
oColour = uColour[1];
}
} }

View File

@@ -4,14 +4,14 @@ uniform ivec2 uScreenSize;
in ivec2 vPosition; in ivec2 vPosition;
flat out ivec2 fPosition; out vec2 fPosition;
void main() void main()
{ {
fPosition = vPosition; fPosition = vPosition;
// Transform screen coordinates to viewport // Transform screen coordinates to viewport
vec2 pos = vec2(vPosition); vec2 pos = vPosition;
pos.x = (pos.x * (2.0 / uScreenSize.x)) - 1.0; pos.x = (pos.x * (2.0 / uScreenSize.x)) - 1.0;
pos.y = (pos.y * (2.0 / uScreenSize.y)) - 1.0; pos.y = (pos.y * (2.0 / uScreenSize.y)) - 1.0;
pos.y *= -1; pos.y *= -1;

View File

@@ -45,7 +45,8 @@ void FillRectShader::GetLocations()
uScreenSize = GetUniformLocation("uScreenSize"); uScreenSize = GetUniformLocation("uScreenSize");
uClip = GetUniformLocation("uClip"); uClip = GetUniformLocation("uClip");
uFlags = GetUniformLocation("uFlags"); uFlags = GetUniformLocation("uFlags");
uColour = GetUniformLocation("uColour"); uColour[0] = GetUniformLocation("uColour[0]");
uColour[1] = GetUniformLocation("uColour[1]");
vPosition = GetAttributeLocation("vPosition"); vPosition = GetAttributeLocation("vPosition");
} }
@@ -65,9 +66,9 @@ void FillRectShader::SetFlags(uint32 flags)
glUniform1i(uFlags, flags); glUniform1i(uFlags, flags);
} }
void FillRectShader::SetColour(vec4f colour) void FillRectShader::SetColour(int index, vec4f colour)
{ {
glUniform4f(uColour, colour.r, colour.g, colour.b, colour.a); glUniform4f(uColour[index], colour.r, colour.g, colour.b, colour.a);
} }
void FillRectShader::Draw(sint32 left, sint32 top, sint32 right, sint32 bottom) void FillRectShader::Draw(sint32 left, sint32 top, sint32 right, sint32 bottom)

View File

@@ -25,7 +25,7 @@ private:
GLuint uScreenSize; GLuint uScreenSize;
GLuint uClip; GLuint uClip;
GLuint uFlags; GLuint uFlags;
GLuint uColour; GLuint uColour[2];
GLuint vPosition; GLuint vPosition;
@@ -39,7 +39,7 @@ public:
void SetScreenSize(sint32 width, sint32 height); void SetScreenSize(sint32 width, sint32 height);
void SetClip(sint32 left, sint32 top, sint32 right, sint32 bottom); void SetClip(sint32 left, sint32 top, sint32 right, sint32 bottom);
void SetFlags(uint32 flags); void SetFlags(uint32 flags);
void SetColour(vec4f colour); void SetColour(int index, vec4f colour);
void Draw(sint32 left, sint32 top, sint32 right, sint32 bottom); void Draw(sint32 left, sint32 top, sint32 right, sint32 bottom);

View File

@@ -142,8 +142,8 @@ public:
_drawingContext->Initialise(); _drawingContext->Initialise();
// glEnable(GL_BLEND); glEnable(GL_BLEND);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
void Resize(uint32 width, uint32 height) override void Resize(uint32 width, uint32 height) override
@@ -158,6 +158,8 @@ public:
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
{ {
SDL_Color colour = palette[i]; SDL_Color colour = palette[i];
colour.a = 255;
Palette[i] = colour; Palette[i] = colour;
GLPalette[i] = { colour.r / 255.0f, GLPalette[i] = { colour.r / 255.0f,
colour.g / 255.0f, colour.g / 255.0f,
@@ -326,61 +328,20 @@ void OpenGLDrawingContext::Clear(uint32 colour)
void OpenGLDrawingContext::FillRect(uint32 colour, sint32 left, sint32 top, sint32 right, sint32 bottom) void OpenGLDrawingContext::FillRect(uint32 colour, sint32 left, sint32 top, sint32 right, sint32 bottom)
{ {
vec4f paletteColour = _engine->GLPalette[colour & 0xFF]; vec4f paletteColour[2];
paletteColour[0] = _engine->GLPalette[(colour >> 0) & 0xFF];
paletteColour[1] = paletteColour[0];
if (colour & 0x1000000)
{
paletteColour[1].a = 0;
}
_fillRectShader->Use(); _fillRectShader->Use();
_fillRectShader->SetScreenSize(gScreenWidth, gScreenHeight); _fillRectShader->SetScreenSize(gScreenWidth, gScreenHeight);
_fillRectShader->SetColour(paletteColour); _fillRectShader->SetColour(0, paletteColour[0]);
_fillRectShader->SetColour(1, paletteColour[1]);
_fillRectShader->SetClip(_clipLeft, _clipTop, _clipRight, _clipBottom); _fillRectShader->SetClip(_clipLeft, _clipTop, _clipRight, _clipBottom);
_fillRectShader->Draw(left, top, right, bottom); _fillRectShader->Draw(left, top, right + 1, bottom + 1);
return;
if (left > right)
{
left ^= right;
right ^= left;
left ^= right;
}
if (top > bottom)
{
top ^= bottom;
bottom ^= top;
top ^= bottom;
}
left += _offsetX;
top += _offsetY;
right += _offsetX;
bottom += _offsetY;
left = Math::Max(left, _clipLeft);
top = Math::Max(top, _clipTop);
right = Math::Min(right, _clipRight);
bottom = Math::Min(bottom, _clipBottom);
if (right < left || bottom < top)
{
return;
}
glDisable(GL_TEXTURE_2D);
if (colour & 0x2000000)
{
glColor4f(paletteColour.r, paletteColour.g, paletteColour.b, 0.4f);
}
else
{
glColor3f(paletteColour.r, paletteColour.g, paletteColour.b);
}
glBegin(GL_QUADS);
glVertex2i(left, top);
glVertex2i(left, bottom + 1);
glVertex2i(right + 1, bottom + 1);
glVertex2i(right + 1, top);
glEnd();
} }
void OpenGLDrawingContext::DrawLine(uint32 colour, sint32 x1, sint32 y1, sint32 x2, sint32 y2) void OpenGLDrawingContext::DrawLine(uint32 colour, sint32 x1, sint32 y1, sint32 x2, sint32 y2)