- backported all new scaling and rotation options for the 2D drawer from Raze.

With proper scaling and viewport support, things should become a lot easier now. The 2D drawer now also can rotate content by arbitrary angles.
This commit is contained in:
Christoph Oelckers 2020-09-27 09:17:41 +02:00
commit dbf2d4d7d7
7 changed files with 341 additions and 81 deletions

View file

@ -401,10 +401,6 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms)
double xscale = parms.destwidth / parms.texwidth;
double yscale = parms.destheight / parms.texheight;
double x = parms.x - parms.left * xscale;
double y = parms.y - parms.top * yscale;
double w = parms.destwidth;
double h = parms.destheight;
double u1, v1, u2, v2;
PalEntry vertexcolor;
@ -414,9 +410,15 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms)
dg.mVertCount = 4;
dg.mTexture = img;
if (img->isWarped()) dg.mFlags |= DTF_Wrap;
if (parms.indexed) dg.mFlags |= DTF_Indexed;
dg.mTranslationId = 0;
SetStyle(img, parms, vertexcolor, dg);
if (parms.indexed)
{
dg.mLightLevel = vertexcolor.Luminance();
vertexcolor = 0xffffffff;
}
if (!img->isHardwareCanvas() && parms.TranslationId != -1)
{
@ -427,44 +429,94 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms)
u2 = parms.srcx + parms.srcwidth;
v2 = parms.srcy + parms.srcheight;
if (parms.flipX)
std::swap(u1, u2);
if (parms.flipY)
std::swap(v1, v2);
// This is crap. Only kept for backwards compatibility with scripts that may have used it.
// Note that this only works for unflipped full textures.
if (parms.windowleft > 0 || parms.windowright < parms.texwidth)
if (parms.flipX)
{
double wi = std::min(parms.windowright, parms.texwidth);
x += parms.windowleft * xscale;
w -= (parms.texwidth - wi + parms.windowleft) * xscale;
u1 = float(u1 + parms.windowleft / parms.texwidth);
u2 = float(u2 - (parms.texwidth - wi) / parms.texwidth);
std::swap(u1, u2);
}
if (x < (double)parms.lclip || y < (double)parms.uclip || x + w >(double)parms.rclip || y + h >(double)parms.dclip)
if (parms.flipY)
{
std::swap(v1, v2);
}
if (parms.rotateangle == 0)
{
double x = parms.x - parms.left * xscale;
double y = parms.y - parms.top * yscale;
double w = parms.destwidth;
double h = parms.destheight;
// This is crap. Only kept for backwards compatibility with scripts that may have used it.
// Note that this only works for unflipped and unrotated full textures.
if (parms.windowleft > 0 || parms.windowright < parms.texwidth)
{
double wi = std::min(parms.windowright, parms.texwidth);
x += parms.windowleft * xscale;
w -= (parms.texwidth - wi + parms.windowleft) * xscale;
u1 = float(u1 + parms.windowleft / 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)
{
dg.mScissor[0] = parms.lclip;
dg.mScissor[1] = parms.uclip;
dg.mScissor[2] = parms.rclip;
dg.mScissor[3] = parms.dclip;
dg.mFlags |= DTF_Scissor;
}
else
{
memset(dg.mScissor, 0, sizeof(dg.mScissor));
}
dg.mVertCount = 4;
dg.mVertIndex = (int)mVertices.Reserve(4);
TwoDVertex* ptr = &mVertices[dg.mVertIndex];
ptr->Set(x, y, 0, u1, v1, vertexcolor); ptr++;
ptr->Set(x, y + h, 0, u1, v2, vertexcolor); ptr++;
ptr->Set(x + w, y, 0, u2, v1, vertexcolor); ptr++;
ptr->Set(x + w, y + h, 0, u2, v2, vertexcolor); ptr++;
}
else
{
double radang = parms.rotateangle * (pi::pi() / 180.);
double cosang = cos(radang);
double sinang = sin(radang);
double xd1 = -parms.left;
double yd1 = -parms.top;
double xd2 = xd1 + parms.texwidth;
double yd2 = yd1 + parms.texheight;
double x1 = parms.x + xscale * (xd1 * cosang + yd1 * sinang);
double y1 = parms.y - yscale * (xd1 * sinang - yd1 * cosang);
double x2 = parms.x + xscale * (xd1 * cosang + yd2 * sinang);
double y2 = parms.y - yscale * (xd1 * sinang - yd2 * cosang);
double x3 = parms.x + xscale * (xd2 * cosang + yd1 * sinang);
double y3 = parms.y - yscale * (xd2 * sinang - yd1 * cosang);
double x4 = parms.x + xscale * (xd2 * cosang + yd2 * sinang);
double y4 = parms.y - yscale * (xd2 * sinang - yd2 * cosang);
dg.mScissor[0] = parms.lclip;
dg.mScissor[1] = parms.uclip;
dg.mScissor[2] = parms.rclip;
dg.mScissor[3] = parms.dclip;
dg.mFlags |= DTF_Scissor;
}
else
{
memset(dg.mScissor, 0, sizeof(dg.mScissor));
}
dg.mVertCount = 4;
dg.mVertIndex = (int)mVertices.Reserve(4);
TwoDVertex *ptr = &mVertices[dg.mVertIndex];
ptr->Set(x, y, 0, u1, v1, vertexcolor); ptr++;
ptr->Set(x, y + h, 0, u1, v2, vertexcolor); ptr++;
ptr->Set(x + w, y, 0, u2, v1, vertexcolor); ptr++;
ptr->Set(x + w, y + h, 0, u2, v2, vertexcolor); ptr++;
dg.mVertCount = 4;
dg.mVertIndex = (int)mVertices.Reserve(4);
TwoDVertex* ptr = &mVertices[dg.mVertIndex];
ptr->Set(x1, y1, 0, u1, v1, vertexcolor); ptr++;
ptr->Set(x2, y2, 0, u1, v2, vertexcolor); ptr++;
ptr->Set(x3, y3, 0, u2, v1, vertexcolor); ptr++;
ptr->Set(x4, y4, 0, u2, v2, vertexcolor); ptr++;
}
dg.mIndexIndex = mIndices.Size();
dg.mIndexCount += 6;
AddIndices(dg.mVertIndex, 6, 0, 1, 2, 1, 3, 2);
@ -693,7 +745,7 @@ float F2DDrawer::GetClassicFlatScalarHeight()
return sh;
}
void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin, double flatscale)
void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin, double flatscale, PalEntry color)
{
float fU1, fU2, fV1, fV2;
@ -789,18 +841,18 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu
dg.mVertIndex = (int)mVertices.Reserve(4);
auto ptr = &mVertices[dg.mVertIndex];
ptr->Set(left, top, 0, fU1, fV1, 0xffffffff); ptr++;
ptr->Set(left, top, 0, fU1, fV1, color); ptr++;
if (local_origin < 4)
{
ptr->Set(left, bottom, 0, fU1, fV2, 0xffffffff); ptr++;
ptr->Set(right, top, 0, fU2, fV1, 0xffffffff); ptr++;
ptr->Set(left, bottom, 0, fU1, fV2, color); ptr++;
ptr->Set(right, top, 0, fU2, fV1, color); ptr++;
}
else
{
ptr->Set(left, bottom, 0, fU2, fV1, 0xffffffff); ptr++;
ptr->Set(right, top, 0, fU1, fV2, 0xffffffff); ptr++;
ptr->Set(left, bottom, 0, fU2, fV1, color); ptr++;
ptr->Set(right, top, 0, fU1, fV2, color); ptr++;
}
ptr->Set(right, bottom, 0, fU2, fV2, 0xffffffff); ptr++;
ptr->Set(right, bottom, 0, fU2, fV2, color); ptr++;
dg.mIndexIndex = mIndices.Size();
dg.mIndexCount += 6;
AddIndices(dg.mVertIndex, 6, 0, 1, 2, 1, 3, 2);
@ -945,8 +997,12 @@ void F2DDrawer::AddPixel(int x1, int y1, uint32_t color)
void F2DDrawer::Clear()
{
mVertices.Clear();
mIndices.Clear();
mData.Clear();
mIsFirstPass = true;
if (!locked)
{
mVertices.Clear();
mIndices.Clear();
mData.Clear();
mIsFirstPass = true;
}
screenFade = 1.f;
}