- pass clip rect as pointer to F2DDrawer::AddLine.

This commit is contained in:
Christoph Oelckers 2022-08-04 09:24:36 +02:00
parent 931211b9db
commit 735c2a9545
5 changed files with 32 additions and 11 deletions

View file

@ -1745,7 +1745,7 @@ void DAutomap::drawMline (mline_t *ml, const AMColor &color)
twod->AddThickLine(x1, y1, x2, y2, am_linethickness, color.RGB, uint8_t(am_linealpha * 255)); twod->AddThickLine(x1, y1, x2, y2, am_linethickness, color.RGB, uint8_t(am_linealpha * 255));
} else { } else {
// Use more efficient thin line drawing routine. // Use more efficient thin line drawing routine.
twod->AddLine(x1, y1, x2, y2, -1, -1, INT_MAX, INT_MAX, color.RGB, uint8_t(am_linealpha * 255)); twod->AddLine(x1, y1, x2, y2, nullptr, color.RGB, uint8_t(am_linealpha * 255));
} }
} }
} }

View file

@ -1040,19 +1040,19 @@ void F2DDrawer::ClearScreen(PalEntry color)
// //
//========================================================================== //==========================================================================
void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, int clipx1, int clipy1, int clipx2, int clipy2, uint32_t color, uint8_t alpha) void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha)
{ {
PalEntry p = (PalEntry)color; PalEntry p = (PalEntry)color;
p.a = alpha; p.a = alpha;
RenderCommand dg; RenderCommand dg;
if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth()- 1 || clipy2 < GetHeight() - 1) if (clip != nullptr)
{ {
dg.mScissor[0] = clipx1 + int(offset.X); dg.mScissor[0] = clip->Left() + int(offset.X);
dg.mScissor[1] = clipy1 + int(offset.Y); dg.mScissor[1] = clip->Top() + int(offset.Y);
dg.mScissor[2] = clipx2 + 1 + int(offset.X); dg.mScissor[2] = clip->Right() + int(offset.X);
dg.mScissor[3] = clipy2 + 1 + int(offset.Y); dg.mScissor[3] = clip->Bottom() + int(offset.Y);
dg.mFlags |= DTF_Scissor; dg.mFlags |= DTF_Scissor;
} }

View file

@ -11,6 +11,7 @@
struct DrawParms; struct DrawParms;
struct FColormap; struct FColormap;
struct IntRect;
class DShape2DTransform : public DObject class DShape2DTransform : public DObject
{ {
@ -226,7 +227,7 @@ public:
void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color); void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color);
void AddLine(double x1, double y1, double x2, double y2, int cx, int cy, int cx2, int cy2, uint32_t color, uint8_t alpha = 255); void AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha = 255);
void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255); void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255);
void AddPixel(int x1, int y1, uint32_t color); void AddPixel(int x1, int y1, uint32_t color);

View file

@ -1564,7 +1564,7 @@ void VirtualToRealCoordsInt(F2DDrawer *drawer, int &x, int &y, int &w, int &h,
static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha) static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha)
{ {
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, -1, -1, INT_MAX, INT_MAX, realcolor | MAKEARGB(255, 0, 0, 0), alpha); twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine) DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine)
@ -1589,7 +1589,7 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawLine)
PARAM_INT(y1); PARAM_INT(y1);
PARAM_INT(color); PARAM_INT(color);
PARAM_INT(alpha); PARAM_INT(alpha);
self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, -1, -1, INT_MAX, INT_MAX, color | MAKEARGB(255, 0, 0, 0), alpha); self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, color | MAKEARGB(255, 0, 0, 0), alpha);
self->Tex->NeedUpdate(); self->Tex->NeedUpdate();
return 0; return 0;
} }

View file

@ -6,7 +6,6 @@ struct IntRect
int left, top; int left, top;
int width, height; int width, height;
void Offset(int xofs, int yofs) void Offset(int xofs, int yofs)
{ {
left += xofs; left += xofs;
@ -26,6 +25,27 @@ struct IntRect
height = y - top; height = y - top;
} }
int Left() const
{
return left;
}
int Top() const
{
return top;
}
int Right() const
{
return left + width;
}
int Bottom() const
{
return top + height;
}
}; };