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:
@@ -3,9 +3,9 @@
|
||||
uniform ivec4 uClip;
|
||||
|
||||
uniform int uFlags;
|
||||
uniform vec4 uColour;
|
||||
uniform vec4 uColour[2];
|
||||
|
||||
flat in ivec2 fPosition;
|
||||
in vec2 fPosition;
|
||||
|
||||
layout (location = 0) out vec4 oColour;
|
||||
|
||||
@@ -16,6 +16,14 @@ void main()
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
oColour = uColour;
|
||||
|
||||
int posSum = int(fPosition.x) + int(fPosition.y);
|
||||
if ((posSum % 2) == 0)
|
||||
{
|
||||
oColour = uColour[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
oColour = uColour[1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ uniform ivec2 uScreenSize;
|
||||
|
||||
in ivec2 vPosition;
|
||||
|
||||
flat out ivec2 fPosition;
|
||||
out vec2 fPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
fPosition = vPosition;
|
||||
|
||||
// Transform screen coordinates to viewport
|
||||
vec2 pos = vec2(vPosition);
|
||||
vec2 pos = vPosition;
|
||||
pos.x = (pos.x * (2.0 / uScreenSize.x)) - 1.0;
|
||||
pos.y = (pos.y * (2.0 / uScreenSize.y)) - 1.0;
|
||||
pos.y *= -1;
|
||||
|
||||
@@ -45,7 +45,8 @@ void FillRectShader::GetLocations()
|
||||
uScreenSize = GetUniformLocation("uScreenSize");
|
||||
uClip = GetUniformLocation("uClip");
|
||||
uFlags = GetUniformLocation("uFlags");
|
||||
uColour = GetUniformLocation("uColour");
|
||||
uColour[0] = GetUniformLocation("uColour[0]");
|
||||
uColour[1] = GetUniformLocation("uColour[1]");
|
||||
|
||||
vPosition = GetAttributeLocation("vPosition");
|
||||
}
|
||||
@@ -65,9 +66,9 @@ void FillRectShader::SetFlags(uint32 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)
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
GLuint uScreenSize;
|
||||
GLuint uClip;
|
||||
GLuint uFlags;
|
||||
GLuint uColour;
|
||||
GLuint uColour[2];
|
||||
|
||||
GLuint vPosition;
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
void SetScreenSize(sint32 width, sint32 height);
|
||||
void SetClip(sint32 left, sint32 top, sint32 right, sint32 bottom);
|
||||
void SetFlags(uint32 flags);
|
||||
void SetColour(vec4f colour);
|
||||
void SetColour(int index, vec4f colour);
|
||||
|
||||
void Draw(sint32 left, sint32 top, sint32 right, sint32 bottom);
|
||||
|
||||
|
||||
@@ -142,8 +142,8 @@ public:
|
||||
|
||||
_drawingContext->Initialise();
|
||||
|
||||
// glEnable(GL_BLEND);
|
||||
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
void Resize(uint32 width, uint32 height) override
|
||||
@@ -158,6 +158,8 @@ public:
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
SDL_Color colour = palette[i];
|
||||
colour.a = 255;
|
||||
|
||||
Palette[i] = colour;
|
||||
GLPalette[i] = { colour.r / 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)
|
||||
{
|
||||
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->SetScreenSize(gScreenWidth, gScreenHeight);
|
||||
_fillRectShader->SetColour(paletteColour);
|
||||
_fillRectShader->SetColour(0, paletteColour[0]);
|
||||
_fillRectShader->SetColour(1, paletteColour[1]);
|
||||
_fillRectShader->SetClip(_clipLeft, _clipTop, _clipRight, _clipBottom);
|
||||
_fillRectShader->Draw(left, top, right, bottom);
|
||||
|
||||
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();
|
||||
_fillRectShader->Draw(left, top, right + 1, bottom + 1);
|
||||
}
|
||||
|
||||
void OpenGLDrawingContext::DrawLine(uint32 colour, sint32 x1, sint32 y1, sint32 x2, sint32 y2)
|
||||
|
||||
Reference in New Issue
Block a user