- floatified the entire 2D coordinate interface.

Also added some initial preparations for scaling from a global virtual screen size
This commit is contained in:
Christoph Oelckers 2019-03-27 00:17:37 +01:00
parent f4401d1525
commit ac5d8bca46
8 changed files with 212 additions and 134 deletions

View file

@ -168,7 +168,7 @@ void DIntermissionScreen::Drawer ()
} }
else else
{ {
screen->FlatFill (0,0, SCREENWIDTH, SCREENHEIGHT, TexMan.GetTexture(mBackground)); screen->FlatFill (0,0, SCREENWIDTH, SCREENHEIGHT, TexMan.GetTexture(mBackground), false, true);
} }
} }
else else

View file

@ -273,6 +273,28 @@ void F2DDrawer::SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcol
// The real color gets multiplied into vertexcolor later. // The real color gets multiplied into vertexcolor later.
} }
//==========================================================================
//
// Scales the content of the DrawParms structure
//
//==========================================================================
void F2DDrawer::ApplyScale(DrawParms &parms)
{
// This scales all the coordinates which are in screen space.
// It does nothing with any coordinate in texture space!
parms.x = ScaleToScreen(parms.x);
parms.y = ScaleToScreen(parms.y);
parms.destwidth = ScaleToScreen(parms.destwidth);
parms.destheight = ScaleToScreen(parms.destheight);
parms.dClip = ScaleToScreen(parms.dClip);
parms.uClip = ScaleToScreen(parms.uClip);
parms.lClip = ScaleToScreen(parms.lClip);
parms.rClip = ScaleToScreen(parms.rClip);
parms.cellX = ScaleToScreen(parms.cellX);
parms.cellY = ScaleToScreen(parms.cellY);
}
//========================================================================== //==========================================================================
// //
// Draws a texture // Draws a texture
@ -283,6 +305,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
{ {
if (parms.style.BlendOp == STYLEOP_None) return; // not supposed to be drawn. if (parms.style.BlendOp == STYLEOP_None) return; // not supposed to be drawn.
if (mVirtualScale != 1.) ApplyScale(parms);
double xscale = parms.destwidth / parms.texwidth; double xscale = parms.destwidth / parms.texwidth;
double yscale = parms.destheight / parms.texheight; double yscale = parms.destheight / parms.texheight;
double x = parms.x - parms.left * xscale; double x = parms.x - parms.left * xscale;
@ -329,12 +352,12 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
u2 = float(u2 - (parms.texwidth - wi) / parms.texwidth); u2 = float(u2 - (parms.texwidth - wi) / parms.texwidth);
} }
if (x < (double)parms.lclip || y < (double)parms.uclip || x + w >(double)parms.rclip || y + h >(double)parms.dclip) if (x < parms.lClip || y < parms.uClip || x + w >parms.rClip || y + h > parms.dClip)
{ {
dg.mScissor[0] = parms.lclip; dg.mScissor[0] = xs_RoundToInt(parms.lClip);
dg.mScissor[1] = parms.uclip; dg.mScissor[1] = xs_RoundToInt(parms.uClip);
dg.mScissor[2] = parms.rclip; dg.mScissor[2] = xs_RoundToInt(parms.rClip);
dg.mScissor[3] = parms.dclip; dg.mScissor[3] = xs_RoundToInt(parms.dClip);
dg.mFlags |= DTF_Scissor; dg.mFlags |= DTF_Scissor;
} }
else else
@ -388,21 +411,23 @@ void F2DDrawer::AddShape( FTexture *img, DShape2D *shape, DrawParms &parms )
if ( shape->mVertices[i].X > maxx ) maxx = shape->mVertices[i].X; if ( shape->mVertices[i].X > maxx ) maxx = shape->mVertices[i].X;
if ( shape->mVertices[i].Y > maxy ) maxy = shape->mVertices[i].Y; if ( shape->mVertices[i].Y > maxy ) maxy = shape->mVertices[i].Y;
} }
if (minx < (double)parms.lclip || miny < (double)parms.uclip || maxx >(double)parms.rclip || maxy >(double)parms.dclip) if (minx < parms.lClip || miny < parms.uClip || maxx >parms.rClip || maxy > parms.dClip)
{ {
dg.mScissor[0] = parms.lclip; dg.mScissor[0] = xs_RoundToInt(ScaleToScreen(parms.lClip));
dg.mScissor[1] = parms.uclip; dg.mScissor[1] = xs_RoundToInt(ScaleToScreen(parms.uClip));
dg.mScissor[2] = parms.rclip; dg.mScissor[2] = xs_RoundToInt(ScaleToScreen(parms.rClip));
dg.mScissor[3] = parms.dclip; dg.mScissor[3] = xs_RoundToInt(ScaleToScreen(parms.dClip));
dg.mFlags |= DTF_Scissor; dg.mFlags |= DTF_Scissor;
} }
else else
{
memset(dg.mScissor, 0, sizeof(dg.mScissor)); memset(dg.mScissor, 0, sizeof(dg.mScissor));
}
dg.mVertIndex = (int)mVertices.Reserve(dg.mVertCount); dg.mVertIndex = (int)mVertices.Reserve(dg.mVertCount);
TwoDVertex *ptr = &mVertices[dg.mVertIndex]; TwoDVertex *ptr = &mVertices[dg.mVertIndex];
for ( int i=0; i<dg.mVertCount; i++ ) for ( int i=0; i<dg.mVertCount; i++ )
ptr[i].Set(shape->mVertices[i].X, shape->mVertices[i].Y, 0, shape->mCoords[i].X, shape->mCoords[i].Y, vertexcolor); ptr[i].Set(ScaleToScreen(shape->mVertices[i].X), ScaleToScreen(shape->mVertices[i].Y), 0, shape->mCoords[i].X, shape->mCoords[i].Y, vertexcolor);
dg.mIndexIndex = mIndices.Size(); dg.mIndexIndex = mIndices.Size();
dg.mIndexCount += shape->mIndices.Size(); dg.mIndexCount += shape->mIndices.Size();
for ( int i=0; i<int(shape->mIndices.Size()); i+=3 ) for ( int i=0; i<int(shape->mIndices.Size()); i+=3 )
@ -482,7 +507,7 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints,
u = t * cosrot - v * sinrot; u = t * cosrot - v * sinrot;
v = v * cosrot + t * sinrot; v = v * cosrot + t * sinrot;
} }
mVertices[poly.mVertIndex+i].Set(points[i].X, points[i].Y, 0, u*uscale, v*vscale, color0); mVertices[poly.mVertIndex+i].Set(ScaleToScreen(points[i].X), ScaleToScreen(points[i].Y), 0, u*uscale, v*vscale, color0);
} }
poly.mIndexIndex = mIndices.Size(); poly.mIndexIndex = mIndices.Size();
poly.mIndexCount += (npoints - 2) * 3; poly.mIndexCount += (npoints - 2) * 3;
@ -512,7 +537,7 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints,
// //
//========================================================================== //==========================================================================
void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin) void F2DDrawer::AddFlatFill(double left, double top, double right, double bottom, FTexture *src, bool local_origin, bool scaleto320x200)
{ {
float fU1, fU2, fV1, fV2; float fU1, fU2, fV1, fV2;
@ -525,21 +550,40 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture *
dg.mTexture = src; dg.mTexture = src;
dg.mFlags = DTF_Wrap; dg.mFlags = DTF_Wrap;
float factor = 1.f;
if (scaleto320x200)
{
float myratio = ActiveRatio (screen->GetWidth(), screen->GetHeight());
if (!AspectTallerThanWide(myratio))
{
factor = 240 / screen->GetHeight();
}
else
{
factor = 320 / screen->GetWidth();
}
}
// scaling is not used here. // scaling is not used here.
if (!local_origin) if (!local_origin)
{ {
fU1 = float(left) / src->GetDisplayWidth(); fU1 = float(ScaleToScreen(left)) * factor / src->GetDisplayWidth();
fV1 = float(top) / src->GetDisplayHeight(); fV1 = float(ScaleToScreen(top)) * factor / src->GetDisplayHeight();
fU2 = float(right) / src->GetDisplayWidth(); fU2 = float(ScaleToScreen(right)) * factor / src->GetDisplayWidth();
fV2 = float(bottom) / src->GetDisplayHeight(); fV2 = float(ScaleToScreen(bottom)) * factor / src->GetDisplayHeight();
} }
else else
{ {
fU1 = 0; fU1 = 0;
fV1 = 0; fV1 = 0;
fU2 = float(right - left) / src->GetDisplayWidth(); fU2 = float(ScaleToScreen(right - left)) * factor / src->GetDisplayWidth();
fV2 = float(bottom - top) / src->GetDisplayHeight(); fV2 = float(ScaleToScreen(bottom - top)) * factor / src->GetDisplayHeight();
} }
dg.mVertIndex = (int)mVertices.Reserve(4); dg.mVertIndex = (int)mVertices.Reserve(4);
auto ptr = &mVertices[dg.mVertIndex]; auto ptr = &mVertices[dg.mVertIndex];
@ -560,7 +604,7 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture *
// //
//=========================================================================== //===========================================================================
void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, FRenderStyle *style) void F2DDrawer::AddColorOnlyQuad(double x1, double y1, double w, double h, PalEntry color, FRenderStyle *style)
{ {
RenderCommand dg; RenderCommand dg;
@ -569,6 +613,10 @@ void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, F
dg.mVertIndex = (int)mVertices.Reserve(4); dg.mVertIndex = (int)mVertices.Reserve(4);
dg.mRenderStyle = style? *style : LegacyRenderStyles[STYLE_Translucent]; dg.mRenderStyle = style? *style : LegacyRenderStyles[STYLE_Translucent];
auto ptr = &mVertices[dg.mVertIndex]; auto ptr = &mVertices[dg.mVertIndex];
x1 = ScaleToScreen(x1);
y1 = ScaleToScreen(y1);
w = ScaleToScreen(w);
h = ScaleToScreen(h);
ptr->Set(x1, y1, 0, 0, 0, color); ptr++; ptr->Set(x1, y1, 0, 0, 0, color); ptr++;
ptr->Set(x1, y1 + h, 0, 0, 0, color); ptr++; ptr->Set(x1, y1 + h, 0, 0, 0, color); ptr++;
ptr->Set(x1 + w, y1, 0, 0, 0, color); ptr++; ptr->Set(x1 + w, y1, 0, 0, 0, color); ptr++;
@ -585,7 +633,7 @@ void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, F
// //
//========================================================================== //==========================================================================
void F2DDrawer::AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t color, uint8_t alpha) void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, int palcolor, uint32_t color, uint8_t alpha)
{ {
PalEntry p = color ? (PalEntry)color : GPalette.BaseColors[palcolor]; PalEntry p = color ? (PalEntry)color : GPalette.BaseColors[palcolor];
p.a = alpha; p.a = alpha;
@ -596,8 +644,8 @@ void F2DDrawer::AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t c
dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent]; dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent];
dg.mVertCount = 2; dg.mVertCount = 2;
dg.mVertIndex = (int)mVertices.Reserve(2); dg.mVertIndex = (int)mVertices.Reserve(2);
mVertices[dg.mVertIndex].Set(x1, y1, 0, 0, 0, p); mVertices[dg.mVertIndex].Set(ScaleToScreen(x1), ScaleToScreen(y1), 0, 0, 0, p);
mVertices[dg.mVertIndex+1].Set(x2, y2, 0, 0, 0, p); mVertices[dg.mVertIndex+1].Set(ScaleToScreen(x2), ScaleToScreen(y2), 0, 0, 0, p);
AddCommand(&dg); AddCommand(&dg);
} }
@ -607,13 +655,13 @@ void F2DDrawer::AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t c
// //
//========================================================================== //==========================================================================
void F2DDrawer::AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha) void F2DDrawer::AddThickLine(double x1, double y1, double x2, double y2, double thickness, uint32_t color, uint8_t alpha)
{ {
PalEntry p = (PalEntry)color; PalEntry p = (PalEntry)color;
p.a = alpha; p.a = alpha;
DVector2 point0(x1, y1); DVector2 point0(ScaleToScreen(x1), ScaleToScreen(y1));
DVector2 point1(x2, y2); DVector2 point1(ScaleToScreen(x2), ScaleToScreen(y2));
DVector2 delta = point1 - point0; DVector2 delta = point1 - point0;
DVector2 perp(-delta.Y, delta.X); DVector2 perp(-delta.Y, delta.X);
@ -648,7 +696,7 @@ void F2DDrawer::AddThickLine(int x1, int y1, int x2, int y2, double thickness, u
// //
//========================================================================== //==========================================================================
void F2DDrawer::AddPixel(int x1, int y1, int palcolor, uint32_t color) void F2DDrawer::AddPixel(double x1, double y1, int palcolor, uint32_t color)
{ {
PalEntry p = color ? (PalEntry)color : GPalette.BaseColors[palcolor]; PalEntry p = color ? (PalEntry)color : GPalette.BaseColors[palcolor];
p.a = 255; p.a = 255;
@ -659,7 +707,7 @@ void F2DDrawer::AddPixel(int x1, int y1, int palcolor, uint32_t color)
dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent]; dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent];
dg.mVertCount = 1; dg.mVertCount = 1;
dg.mVertIndex = (int)mVertices.Reserve(1); dg.mVertIndex = (int)mVertices.Reserve(1);
mVertices[dg.mVertIndex].Set(x1, y1, 0, 0, 0, p); mVertices[dg.mVertIndex].Set(ScaleToScreen(x1), ScaleToScreen(y1), 0, 0, 0, p);
AddCommand(&dg); AddCommand(&dg);
} }

View file

@ -119,29 +119,40 @@ public:
TArray<int> mIndices; TArray<int> mIndices;
TArray<TwoDVertex> mVertices; TArray<TwoDVertex> mVertices;
TArray<RenderCommand> mData; TArray<RenderCommand> mData;
double mVirtualScale = 1.;
int AddCommand(const RenderCommand *data); int AddCommand(const RenderCommand *data);
void AddIndices(int firstvert, int count, ...); void AddIndices(int firstvert, int count, ...);
bool SetStyle(FTexture *tex, DrawParms &parms, PalEntry &color0, RenderCommand &quad); bool SetStyle(FTexture *tex, DrawParms &parms, PalEntry &color0, RenderCommand &quad);
void SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcolor, PalEntry &overlaycolor); void SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcolor, PalEntry &overlaycolor);
void SetVirtualScale(double h)
{
mVirtualScale = h;
}
double ScaleToScreen(double x)
{
return x * mVirtualScale;
}
void ApplyScale(DrawParms &parms);
public: public:
void AddTexture(FTexture *img, DrawParms &parms); void AddTexture(FTexture *img, DrawParms &parms);
void AddShape(FTexture *img, DShape2D *shape, DrawParms &parms); void AddShape(FTexture *img, DShape2D *shape, DrawParms &parms);
void AddPoly(FTexture *texture, FVector2 *points, int npoints, void AddPoly(FTexture *texture, FVector2 *points, int npoints,
double originx, double originy, double scalex, double scaley, double originx, double originy, double scalex, double scaley,
DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, uint32_t *indices, size_t indexcount); DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, uint32_t *indices, size_t indexcount);
void AddFlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin); void AddFlatFill(double left, double top, double right, double bottom, FTexture *src, bool local_origin, bool scaleto320x200 = false);
void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style); void AddColorOnlyQuad(double left, double top, double width, double height, PalEntry color, FRenderStyle *style);
void AddDim(PalEntry color, float damount, int x1, int y1, int w, int h); void AddDim(PalEntry color, float damount, double x1, double y1, double w, double h);
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 palcolor, uint32_t color, uint8_t alpha = 255);
void AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t color, uint8_t alpha = 255); void AddThickLine(double x1, double y1, double x2, double 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(double x1, double y1, int palcolor, uint32_t color);
void AddPixel(int x1, int y1, int palcolor, uint32_t color);
void Clear(); void Clear();

View file

@ -509,10 +509,10 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
parms->fortext = fortext; parms->fortext = fortext;
parms->windowleft = 0; parms->windowleft = 0;
parms->windowright = INT_MAX; parms->windowright = INT_MAX;
parms->dclip = this->GetHeight(); parms->dClip = this->GetHeight();
parms->uclip = 0; parms->uClip = 0;
parms->lclip = 0; parms->lClip = 0;
parms->rclip = this->GetWidth(); parms->rClip = this->GetWidth();
parms->left = INT_MAX; parms->left = INT_MAX;
parms->top = INT_MAX; parms->top = INT_MAX;
parms->destwidth = INT_MAX; parms->destwidth = INT_MAX;
@ -537,7 +537,7 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
parms->desaturate = 0; parms->desaturate = 0;
parms->cleanmode = DTA_Base; parms->cleanmode = DTA_Base;
parms->scalex = parms->scaley = 1; parms->scalex = parms->scaley = 1;
parms->cellx = parms->celly = 0; parms->cellX = parms->cellY = 0;
parms->maxstrlen = INT_MAX; parms->maxstrlen = INT_MAX;
parms->virtBottom = false; parms->virtBottom = false;
parms->srcx = 0.; parms->srcx = 0.;
@ -803,35 +803,35 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
break; break;
case DTA_ClipTop: case DTA_ClipTop:
parms->uclip = ListGetInt(tags); parms->uClip = MAX(0, ListGetInt(tags));
if (parms->uclip < 0)
{
parms->uclip = 0;
}
break; break;
case DTA_ClipBottom: case DTA_ClipBottom:
parms->dclip = ListGetInt(tags); parms->dClip = MIN(this->GetHeight(), ListGetInt(tags));
if (parms->dclip > this->GetHeight())
{
parms->dclip = this->GetHeight();
}
break; break;
case DTA_ClipLeft: case DTA_ClipLeft:
parms->lclip = ListGetInt(tags); parms->lClip = MAX(0, ListGetInt(tags));
if (parms->lclip < 0)
{
parms->lclip = 0;
}
break; break;
case DTA_ClipRight: case DTA_ClipRight:
parms->rclip = ListGetInt(tags); parms->rClip = MIN(this->GetWidth(), ListGetInt(tags));
if (parms->rclip > this->GetWidth()) break;
{
parms->rclip = this->GetWidth(); case DTA_ClipTopF:
} parms->uClip = MAX(0., ListGetDouble(tags));
break;
case DTA_ClipBottomF:
parms->dClip = MIN<double>(this->GetHeight(), ListGetDouble(tags));
break;
case DTA_ClipLeftF:
parms->lClip = MAX(0., ListGetDouble(tags));
break;
case DTA_ClipRightF:
parms->rClip = MIN<double>(this->GetWidth(), ListGetDouble(tags));
break; break;
case DTA_ShadowAlpha: case DTA_ShadowAlpha:
@ -890,11 +890,19 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
break; break;
case DTA_CellX: case DTA_CellX:
parms->cellx = ListGetInt(tags); parms->cellX = ListGetInt(tags);
break; break;
case DTA_CellY: case DTA_CellY:
parms->celly = ListGetInt(tags); parms->cellY = ListGetInt(tags);
break;
case DTA_CellXF:
parms->cellX = ListGetDouble(tags);
break;
case DTA_CellYF:
parms->cellY = ListGetDouble(tags);
break; break;
case DTA_Burn: case DTA_Burn:
@ -914,13 +922,13 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
// intersect with the canvas's clipping rectangle. // intersect with the canvas's clipping rectangle.
if (clipwidth >= 0 && clipheight >= 0) if (clipwidth >= 0 && clipheight >= 0)
{ {
if (parms->lclip < clipleft) parms->lclip = clipleft; if (parms->lClip < clipleft) parms->lClip = clipleft;
if (parms->rclip > clipleft + clipwidth) parms->rclip = clipleft + clipwidth; if (parms->rClip > clipleft + clipwidth) parms->rClip = clipleft + clipwidth;
if (parms->uclip < cliptop) parms->uclip = cliptop; if (parms->uClip < cliptop) parms->uClip = cliptop;
if (parms->dclip > cliptop + clipheight) parms->dclip = cliptop + clipheight; if (parms->dClip > cliptop + clipheight) parms->dClip = cliptop + clipheight;
} }
if (parms->uclip >= parms->dclip || parms->lclip >= parms->rclip) if (parms->uClip >= parms->dClip || parms->lClip >= parms->rClip)
{ {
return false; return false;
} }
@ -1108,7 +1116,7 @@ void DFrameBuffer::FillBorder (FTexture *img)
// //
//========================================================================== //==========================================================================
void DFrameBuffer::DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32_t realcolor, uint8_t alpha) void DFrameBuffer::DrawLine(double x0, double y0, double x1, double y1, int palColor, uint32_t realcolor, uint8_t alpha)
{ {
m2DDrawer.AddLine(x0, y0, x1, y1, palColor, realcolor, alpha); m2DDrawer.AddLine(x0, y0, x1, y1, palColor, realcolor, alpha);
} }
@ -1116,10 +1124,10 @@ void DFrameBuffer::DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32
DEFINE_ACTION_FUNCTION(_Screen, DrawLine) DEFINE_ACTION_FUNCTION(_Screen, DrawLine)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(x0); PARAM_FLOAT(x0);
PARAM_INT(y0); PARAM_FLOAT(y0);
PARAM_INT(x1); PARAM_FLOAT(x1);
PARAM_INT(y1); PARAM_FLOAT(y1);
PARAM_INT(color); PARAM_INT(color);
PARAM_INT(alpha); PARAM_INT(alpha);
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
@ -1127,17 +1135,17 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawLine)
return 0; return 0;
} }
void DFrameBuffer::DrawThickLine(int x0, int y0, int x1, int y1, double thickness, uint32_t realcolor, uint8_t alpha) { void DFrameBuffer::DrawThickLine(double x0, double y0, double x1, double y1, double thickness, uint32_t realcolor, uint8_t alpha) {
m2DDrawer.AddThickLine(x0, y0, x1, y1, thickness, realcolor, alpha); m2DDrawer.AddThickLine(x0, y0, x1, y1, thickness, realcolor, alpha);
} }
DEFINE_ACTION_FUNCTION(_Screen, DrawThickLine) DEFINE_ACTION_FUNCTION(_Screen, DrawThickLine)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(x0); PARAM_FLOAT(x0);
PARAM_INT(y0); PARAM_FLOAT(y0);
PARAM_INT(x1); PARAM_FLOAT(x1);
PARAM_INT(y1); PARAM_FLOAT(y1);
PARAM_FLOAT(thickness); PARAM_FLOAT(thickness);
PARAM_INT(color); PARAM_INT(color);
PARAM_INT(alpha); PARAM_INT(alpha);
@ -1152,7 +1160,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawThickLine)
// //
//========================================================================== //==========================================================================
void DFrameBuffer::DrawPixel(int x, int y, int palColor, uint32_t realcolor) void DFrameBuffer::DrawPixel(double x, double y, int palColor, uint32_t realcolor)
{ {
m2DDrawer.AddPixel(x, y, palColor, realcolor); m2DDrawer.AddPixel(x, y, palColor, realcolor);
} }
@ -1165,12 +1173,12 @@ void DFrameBuffer::DrawPixel(int x, int y, int palColor, uint32_t realcolor)
// //
//========================================================================== //==========================================================================
void DFrameBuffer::Clear(int left, int top, int right, int bottom, int palcolor, uint32_t color) void DFrameBuffer::Clear(double left, double top, double right, double bottom, int palcolor, uint32_t color)
{ {
if (clipwidth >= 0 && clipheight >= 0) if (clipwidth >= 0 && clipheight >= 0)
{ {
int w = right - left; double w = right - left;
int h = bottom - top; double h = bottom - top;
if (left < clipleft) if (left < clipleft)
{ {
w -= (clipleft - left); w -= (clipleft - left);
@ -1200,10 +1208,10 @@ void DFrameBuffer::Clear(int left, int top, int right, int bottom, int palcolor,
DEFINE_ACTION_FUNCTION(_Screen, Clear) DEFINE_ACTION_FUNCTION(_Screen, Clear)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(x1); PARAM_FLOAT(x1);
PARAM_INT(y1); PARAM_FLOAT(y1);
PARAM_INT(x2); PARAM_FLOAT(x2);
PARAM_INT(y2); PARAM_FLOAT(y2);
PARAM_INT(color); PARAM_INT(color);
PARAM_INT(palcol); PARAM_INT(palcol);
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
@ -1219,7 +1227,7 @@ DEFINE_ACTION_FUNCTION(_Screen, Clear)
// //
//========================================================================== //==========================================================================
void DFrameBuffer::DoDim(PalEntry color, float amount, int x1, int y1, int w, int h, FRenderStyle *style) void DFrameBuffer::DoDim(PalEntry color, float amount, double x1, double y1, double w, double h, FRenderStyle *style)
{ {
if (amount <= 0) if (amount <= 0)
{ {
@ -1232,7 +1240,7 @@ void DFrameBuffer::DoDim(PalEntry color, float amount, int x1, int y1, int w, in
m2DDrawer.AddColorOnlyQuad(x1, y1, w, h, (color.d & 0xffffff) | (int(amount * 255) << 24), style); m2DDrawer.AddColorOnlyQuad(x1, y1, w, h, (color.d & 0xffffff) | (int(amount * 255) << 24), style);
} }
void DFrameBuffer::Dim(PalEntry color, float damount, int x1, int y1, int w, int h, FRenderStyle *style) void DFrameBuffer::Dim(PalEntry color, float damount, double x1, double y1, double w, double h, FRenderStyle *style)
{ {
if (clipwidth >= 0 && clipheight >= 0) if (clipwidth >= 0 && clipheight >= 0)
{ {
@ -1260,10 +1268,10 @@ DEFINE_ACTION_FUNCTION(_Screen, Dim)
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(color); PARAM_INT(color);
PARAM_FLOAT(amount); PARAM_FLOAT(amount);
PARAM_INT(x1); PARAM_FLOAT(x1);
PARAM_INT(y1); PARAM_FLOAT(y1);
PARAM_INT(w); PARAM_FLOAT(w);
PARAM_INT(h); PARAM_FLOAT(h);
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
screen->Dim(color, float(amount), x1, y1, w, h); screen->Dim(color, float(amount), x1, y1, w, h);
return 0; return 0;
@ -1300,9 +1308,9 @@ void DFrameBuffer::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
// //
//========================================================================== //==========================================================================
void DFrameBuffer::FlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin) void DFrameBuffer::FlatFill(double left, double top, double right, double bottom, FTexture *src, bool local_origin, bool scaleto320x200)
{ {
m2DDrawer.AddFlatFill(left, top, right, bottom, src, local_origin); m2DDrawer.AddFlatFill(left, top, right, bottom, src, local_origin, scaleto320x200);
} }
//========================================================================== //==========================================================================
@ -1314,7 +1322,7 @@ void DFrameBuffer::FlatFill(int left, int top, int right, int bottom, FTexture *
// //
//========================================================================== //==========================================================================
void DFrameBuffer::DrawFrame (int left, int top, int width, int height) void DFrameBuffer::DrawFrame (double left, double top, double width, double height)
{ {
FTexture *p; FTexture *p;
const gameborder_t *border = &gameinfo.Border; const gameborder_t *border = &gameinfo.Border;
@ -1322,8 +1330,8 @@ void DFrameBuffer::DrawFrame (int left, int top, int width, int height)
if (border == NULL) if (border == NULL)
return; return;
int offset = border->offset; int offset = border->offset;
int right = left + width; double right = left + width;
int bottom = top + height; double bottom = top + height;
// Draw top and bottom sides. // Draw top and bottom sides.
p = TexMan.GetTextureByName(border->t); p = TexMan.GetTextureByName(border->t);
@ -1347,10 +1355,10 @@ void DFrameBuffer::DrawFrame (int left, int top, int width, int height)
DEFINE_ACTION_FUNCTION(_Screen, DrawFrame) DEFINE_ACTION_FUNCTION(_Screen, DrawFrame)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(x); PARAM_FLOAT(x);
PARAM_INT(y); PARAM_FLOAT(y);
PARAM_INT(w); PARAM_FLOAT(w);
PARAM_INT(h); PARAM_FLOAT(h);
screen->DrawFrame(x, y, w, h); screen->DrawFrame(x, y, w, h);
return 0; return 0;
} }
@ -1361,7 +1369,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawFrame)
// //
//========================================================================== //==========================================================================
void DFrameBuffer::DrawBorder (FTextureID picnum, int x1, int y1, int x2, int y2) void DFrameBuffer::DrawBorder (FTextureID picnum, double x1, double y1, double x2, double y2)
{ {
if (picnum.isValid()) if (picnum.isValid())
{ {

View file

@ -255,7 +255,7 @@ EColorRange V_ParseFontColor(const char32_t *&color_value, int normalcolor, int
template<class chartype> template<class chartype>
void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double y, const chartype *string, DrawParms &parms) void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double y, const chartype *string, DrawParms &parms)
{ {
int w; double w;
const chartype *ch; const chartype *ch;
int c; int c;
double cx; double cx;
@ -265,8 +265,8 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
int kerning; int kerning;
FTexture *pic; FTexture *pic;
if (parms.celly == 0) parms.celly = font->GetHeight() + 1; if (parms.cellY == 0) parms.cellY = font->GetHeight() + 1;
parms.celly *= parms.scaley; parms.cellY *= parms.scaley;
if (normalcolor >= NumTextColors) if (normalcolor >= NumTextColors)
normalcolor = CR_UNTRANSLATED; normalcolor = CR_UNTRANSLATED;
@ -306,20 +306,23 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
if (c == '\n') if (c == '\n')
{ {
cx = x; cx = x;
cy += parms.celly; cy += parms.cellY;
continue; continue;
} }
bool redirected = false; bool redirected = false;
if (NULL != (pic = font->GetChar(c, currentcolor, &w, &redirected))) int ww;
pic = font->GetChar(c, currentcolor, &ww, &redirected);
w = ww;
if (pic)
{ {
parms.remap = redirected? nullptr : range; parms.remap = redirected? nullptr : range;
SetTextureParms(&parms, pic, cx, cy); SetTextureParms(&parms, pic, cx, cy);
if (parms.cellx) if (parms.cellX)
{ {
w = parms.cellx; w = parms.cellX;
parms.destwidth = parms.cellx; parms.destwidth = parms.cellX;
parms.destheight = parms.celly; parms.destheight = parms.cellX;
} }
DrawTextureParms(pic, parms); DrawTextureParms(pic, parms);
} }

View file

@ -233,6 +233,14 @@ enum
DTA_SrcHeight, DTA_SrcHeight,
DTA_LegacyRenderStyle, // takes an old-style STYLE_* constant instead of an FRenderStyle DTA_LegacyRenderStyle, // takes an old-style STYLE_* constant instead of an FRenderStyle
DTA_Burn, // activates the burn shader for this element DTA_Burn, // activates the burn shader for this element
DTA_ClipTopF, // don't draw anything above this row (on dest, not source)
DTA_ClipBottomF, // don't draw anything at or below this row (on dest, not source)
DTA_ClipLeftF, // don't draw anything to the left of this column (on dest, not source)
DTA_ClipRightF, // don't draw anything at or to the right of this column (on dest, not source)
DTA_CellXF, // horizontal size of character cell
DTA_CellYF, // vertical size of character cell
}; };
enum enum
@ -259,10 +267,10 @@ struct DrawParms
double windowleft; double windowleft;
double windowright; double windowright;
int cleanmode; int cleanmode;
int dclip; double dClip;
int uclip; double uClip;
int lclip; double lClip;
int rclip; double rClip;
double top; double top;
double left; double left;
float Alpha; float Alpha;
@ -281,8 +289,8 @@ struct DrawParms
FRenderStyle style; FRenderStyle style;
struct FSpecialColormap *specialcolormap; struct FSpecialColormap *specialcolormap;
int desaturate; int desaturate;
int scalex, scaley; int scalex, scaley; // may not be needed anymore, once the scaling refactor is done.
int cellx, celly; double cellX, cellY;
int maxstrlen; int maxstrlen;
bool fortext; bool fortext;
bool virtBottom; bool virtBottom;
@ -483,13 +491,13 @@ public:
void Clear2D() { m2DDrawer.Clear(); } void Clear2D() { m2DDrawer.Clear(); }
// Dim part of the canvas // Dim part of the canvas
void Dim(PalEntry color, float amount, int x1, int y1, int w, int h, FRenderStyle *style = nullptr); void Dim(PalEntry color, float amount, double x1, double y1, double w, double h, FRenderStyle *style = nullptr);
void DoDim(PalEntry color, float amount, int x1, int y1, int w, int h, FRenderStyle *style = nullptr); void DoDim(PalEntry color, float amount, double x1, double y1, double w, double h, FRenderStyle *style = nullptr);
FVector4 CalcBlend(sector_t * viewsector, PalEntry *modulateColor); FVector4 CalcBlend(sector_t * viewsector, PalEntry *modulateColor);
void DrawBlend(sector_t * viewsector); void DrawBlend(sector_t * viewsector);
// Fill an area with a texture // Fill an area with a texture
void FlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin = false); void FlatFill(double left, double top, double right, double bottom, FTexture *src, bool local_origin = false, bool scaleto320x200 = false);
// Fill a simple polygon with a texture // Fill a simple polygon with a texture
void FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, void FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
@ -497,16 +505,16 @@ public:
const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip, uint32_t *indices, size_t indexcount); const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip, uint32_t *indices, size_t indexcount);
// Set an area to a specified color // Set an area to a specified color
void Clear(int left, int top, int right, int bottom, int palcolor, uint32_t color); void Clear(double left, double top, double right, double bottom, int palcolor, uint32_t color);
// Draws a line // Draws a line
void DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32_t realcolor, uint8_t alpha = 255); void DrawLine(double x0, double y0, double x1, double y1, int palColor, uint32_t realcolor, uint8_t alpha = 255);
// Draws a line with thickness // Draws a line with thickness
void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, uint32_t realcolor, uint8_t alpha = 255); void DrawThickLine(double x0, double y0, double x1, double y1, double thickness, uint32_t realcolor, uint8_t alpha = 255);
// Draws a single pixel // Draws a single pixel
void DrawPixel(int x, int y, int palcolor, uint32_t rgbcolor); void DrawPixel(double x, double y, int palcolor, uint32_t rgbcolor);
bool SetTextureParms(DrawParms *parms, FTexture *img, double x, double y) const; bool SetTextureParms(DrawParms *parms, FTexture *img, double x, double y) const;
@ -532,8 +540,8 @@ public:
void DrawChar(FFont *font, int normalcolor, double x, double y, int character, VMVa_List &args); void DrawChar(FFont *font, int normalcolor, double x, double y, int character, VMVa_List &args);
void DrawText(FFont *font, int normalcolor, double x, double y, const char32_t *string, int tag_first, ...); void DrawText(FFont *font, int normalcolor, double x, double y, const char32_t *string, int tag_first, ...);
void DrawFrame(int left, int top, int width, int height); void DrawFrame(double left, double top, double width, double height);
void DrawBorder(FTextureID, int x1, int y1, int x2, int y2); void DrawBorder(FTextureID, double x1, double y1, double x2, double y2);
// Calculate gamma table // Calculate gamma table
void CalcGamma(float gamma, uint8_t gammalookup[256]); void CalcGamma(float gamma, uint8_t gammalookup[256]);

View file

@ -604,7 +604,7 @@ void DInterBackground::drawBackground(int state, bool drawsplat, bool snl_pointe
} }
else else
{ {
screen->FlatFill(0, 0, SCREENWIDTH, SCREENHEIGHT, background); screen->FlatFill(0, 0, SCREENWIDTH, SCREENHEIGHT, background, false, true);
} }
} }
else else

View file

@ -207,16 +207,16 @@ struct Screen native
native static Color PaletteColor(int index); native static Color PaletteColor(int index);
native static int GetWidth(); native static int GetWidth();
native static int GetHeight(); native static int GetHeight();
native static void Clear(int left, int top, int right, int bottom, Color color, int palcolor = -1); native static void Clear(double left, double top, double right, double bottom, Color color, int palcolor = -1);
native static void Dim(Color col, double amount, int x, int y, int w, int h); native static void Dim(Color col, double amount, double x, double y, double w, double h);
native static vararg void DrawTexture(TextureID tex, bool animate, double x, double y, ...); native static vararg void DrawTexture(TextureID tex, bool animate, double x, double y, ...);
native static vararg void DrawShape(TextureID tex, bool animate, Shape2D s, ...); native static vararg void DrawShape(TextureID tex, bool animate, Shape2D s, ...);
native static vararg void DrawChar(Font font, int normalcolor, double x, double y, int character, ...); native static vararg void DrawChar(Font font, int normalcolor, double x, double y, int character, ...);
native static vararg void DrawText(Font font, int normalcolor, double x, double y, String text, ...); native static vararg void DrawText(Font font, int normalcolor, double x, double y, String text, ...);
native static void DrawLine(int x0, int y0, int x1, int y1, Color color, int alpha = 255); native static void DrawLine(double x0, double y0, double x1, double y1, Color color, int alpha = 255);
native static void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, Color color, int alpha = 255); native static void DrawThickLine(double x0, double y0, double x1, double y1, double thickness, Color color, int alpha = 255);
native static void DrawFrame(int x, int y, int w, int h); native static void DrawFrame(double x, double y, double w, double h);
native static Vector2, Vector2 VirtualToRealCoords(Vector2 pos, Vector2 size, Vector2 vsize, bool vbottom=false, bool handleaspect=true); native static Vector2, Vector2 VirtualToRealCoords(Vector2 pos, Vector2 size, Vector2 vsize, bool vbottom=false, bool handleaspect=true);
native static double GetAspectRatio(); native static double GetAspectRatio();
native static void SetClipRect(int x, int y, int w, int h); native static void SetClipRect(int x, int y, int w, int h);