mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-10 09:32:29 +01:00
Line drawing code now supports all zoom levels.
This commit is contained in:
@@ -7,7 +7,6 @@ uniform ivec2 uScreenSize;
|
||||
|
||||
// clang-format off
|
||||
in ivec4 vBounds;
|
||||
in ivec4 vClip;
|
||||
in uint vColour;
|
||||
in int vDepth;
|
||||
// clang-format on
|
||||
@@ -18,7 +17,7 @@ flat out uint fColour;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos = clamp(vVertMat * vec4(vBounds), vec2(vClip.xy), vec2(vClip.zw));
|
||||
vec2 pos = vVertMat * vec4(vBounds);
|
||||
|
||||
// Transform screen coordinates to viewport coordinates
|
||||
pos = (pos * (2.0 / vec2(uScreenSize))) - 1.0;
|
||||
|
||||
@@ -93,7 +93,6 @@ namespace OpenRCT2::Ui
|
||||
|
||||
struct DrawLineCommand
|
||||
{
|
||||
ivec4 clip;
|
||||
ivec4 bounds;
|
||||
GLuint colour;
|
||||
GLint depth;
|
||||
|
||||
@@ -51,7 +51,6 @@ DrawLineShader::DrawLineShader()
|
||||
vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[3])));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboInstances);
|
||||
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast<void*>(offsetof(DrawLineCommand, clip)));
|
||||
glVertexAttribIPointer(
|
||||
vBounds, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast<void*>(offsetof(DrawLineCommand, bounds)));
|
||||
glVertexAttribIPointer(
|
||||
@@ -69,7 +68,6 @@ DrawLineShader::DrawLineShader()
|
||||
glEnableVertexAttribArray(vColour);
|
||||
glEnableVertexAttribArray(vDepth);
|
||||
|
||||
glVertexAttribDivisor(vClip, 1);
|
||||
glVertexAttribDivisor(vBounds, 1);
|
||||
glVertexAttribDivisor(vColour, 1);
|
||||
glVertexAttribDivisor(vDepth, 1);
|
||||
@@ -87,7 +85,6 @@ void DrawLineShader::GetLocations()
|
||||
{
|
||||
uScreenSize = GetUniformLocation("uScreenSize");
|
||||
|
||||
vClip = GetAttributeLocation("vClip");
|
||||
vBounds = GetAttributeLocation("vBounds");
|
||||
vColour = GetAttributeLocation("vColour");
|
||||
vDepth = GetAttributeLocation("vDepth");
|
||||
|
||||
@@ -578,12 +578,17 @@ void OpenGLDrawingContext::FilterRect(
|
||||
|
||||
void OpenGLDrawingContext::DrawLine(DrawPixelInfo& dpi, uint32_t colour, const ScreenLine& line)
|
||||
{
|
||||
// Note: this function does not respect DPI bounds.
|
||||
CalculcateClipping(dpi);
|
||||
|
||||
DrawLineCommand& command = _commandBuffers.lines.allocate();
|
||||
|
||||
command.clip = { _clipLeft, _clipTop, _clipRight, _clipBottom };
|
||||
command.bounds = { line.GetX1() + _offsetX, line.GetY1() + _offsetY, line.GetX2() + _offsetX, line.GetY2() + _offsetY };
|
||||
const int32_t x1 = dpi.zoom_level.ApplyInversedTo(line.GetX1() - dpi.x) + _clipLeft;
|
||||
const int32_t y1 = dpi.zoom_level.ApplyInversedTo(line.GetY1() - dpi.y) + _clipTop;
|
||||
const int32_t x2 = dpi.zoom_level.ApplyInversedTo(line.GetX2() - dpi.x) + _clipLeft;
|
||||
const int32_t y2 = dpi.zoom_level.ApplyInversedTo(line.GetY2() - dpi.y) + _clipTop;
|
||||
|
||||
command.bounds = { x1, y1, x2, y2 };
|
||||
command.colour = colour & 0xFF;
|
||||
command.depth = _drawCount++;
|
||||
}
|
||||
|
||||
@@ -20,10 +20,16 @@ static void GfxDrawLineOnBuffer(DrawPixelInfo& dpi, char colour, const ScreenCoo
|
||||
{
|
||||
ScreenCoordsXY offset{ coords.x - dpi.x, coords.y - dpi.y };
|
||||
|
||||
offset.x = dpi.zoom_level.ApplyInversedTo(offset.x);
|
||||
offset.y = dpi.zoom_level.ApplyInversedTo(offset.y);
|
||||
no_pixels = dpi.zoom_level.ApplyInversedTo(no_pixels);
|
||||
const int32_t width = dpi.zoom_level.ApplyInversedTo(dpi.width);
|
||||
const int32_t height = dpi.zoom_level.ApplyInversedTo(dpi.height);
|
||||
|
||||
// Check to make sure point is in the y range
|
||||
if (offset.y < 0)
|
||||
return;
|
||||
if (offset.y >= dpi.height)
|
||||
if (offset.y >= height)
|
||||
return;
|
||||
// Check to make sure we are drawing at least a pixel
|
||||
if (!no_pixels)
|
||||
@@ -41,18 +47,17 @@ static void GfxDrawLineOnBuffer(DrawPixelInfo& dpi, char colour, const ScreenCoo
|
||||
}
|
||||
|
||||
// Ensure that the end point of the line is within range
|
||||
if (offset.x + no_pixels - dpi.width > 0)
|
||||
if (offset.x + no_pixels - width > 0)
|
||||
{
|
||||
// If the end point has any pixels outside range
|
||||
// cut them off. If there are now no pixels return.
|
||||
no_pixels -= offset.x + no_pixels - dpi.width;
|
||||
no_pixels -= offset.x + no_pixels - width;
|
||||
if (no_pixels <= 0)
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the buffer we are drawing to and move to the first coordinate.
|
||||
uint8_t* bits_pointer = dpi.bits
|
||||
+ offset.y * (static_cast<int64_t>(static_cast<int64_t>(dpi.pitch) + static_cast<int64_t>(dpi.width))) + offset.x;
|
||||
uint8_t* bits_pointer = dpi.bits + offset.y * (static_cast<int64_t>(dpi.pitch) + static_cast<int64_t>(width)) + offset.x;
|
||||
|
||||
// Draw the line to the specified colour
|
||||
for (; no_pixels > 0; --no_pixels, ++bits_pointer)
|
||||
|
||||
@@ -536,7 +536,7 @@ static void PaintDrawStruct(PaintSession& session, PaintStruct* ps)
|
||||
}
|
||||
|
||||
auto imageId = PaintPSColourifyImage(ps, ps->image_id, session.ViewFlags);
|
||||
if (gPaintBoundingBoxes && session.DPI.zoom_level == ZoomLevel{ 0 })
|
||||
if (gPaintBoundingBoxes)
|
||||
{
|
||||
PaintPSImageWithBoundingBoxes(session, ps, imageId, screenPos.x, screenPos.y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user