From 796c25b056d19cca4154b1d8f6da4367f607bb02 Mon Sep 17 00:00:00 2001 From: drfrag Date: Tue, 9 Jun 2020 18:42:52 +0200 Subject: [PATCH] - Add missing DrawTextureTags. DTA_FlipY, DTA_SrcX, DTA_SrcY, DTA_SrcWidth and DTA_SrcHeight. --- src/gl/renderer/gl_2ddrawer.cpp | 10 ++++++---- src/gl/system/gl_swframebuffer.cpp | 4 ++++ src/swrenderer/r_swcanvas.cpp | 6 ++++++ src/v_draw.cpp | 25 +++++++++++++++++++++++++ src/v_video.h | 8 ++++++++ src/win32/fb_d3d9.cpp | 4 ++++ wadsrc/static/zscript/base.zs | 5 +++++ 7 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/gl/renderer/gl_2ddrawer.cpp b/src/gl/renderer/gl_2ddrawer.cpp index 66f816d5c..d1676baab 100644 --- a/src/gl/renderer/gl_2ddrawer.cpp +++ b/src/gl/renderer/gl_2ddrawer.cpp @@ -101,10 +101,10 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) if (pal) dg.mTranslation = -pal->GetIndex(); } } - u1 = gltex->GetUL(); - v1 = gltex->GetVT(); - u2 = gltex->GetUR(); - v2 = gltex->GetVB(); + u1 = parms.srcx; + v1 = parms.srcy; + u2 = parms.srcx + parms.srcwidth; + v2 = parms.srcy + parms.srcheight; } else @@ -119,6 +119,8 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) if (parms.flipX) std::swap(u1, u2); + if (parms.flipY) + std::swap(v1, v2); if (parms.windowleft > 0 || parms.windowright < parms.texwidth) { diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index 821c6cdf5..ef5412914 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -2778,6 +2778,10 @@ void OpenGLSWFrameBuffer::DrawTextureParms(FTexture *img, DrawParms &parms) { swapvalues(u0, u1); } + if (parms.flipY) + { + swapvalues(v0, v1); + } if (parms.windowleft > 0 || parms.windowright < parms.texwidth) { double wi = MIN(parms.windowright, parms.texwidth); diff --git a/src/swrenderer/r_swcanvas.cpp b/src/swrenderer/r_swcanvas.cpp index 5b1fa89ec..27f26ca9b 100644 --- a/src/swrenderer/r_swcanvas.cpp +++ b/src/swrenderer/r_swcanvas.cpp @@ -170,6 +170,12 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms) xiscale = -xiscale; } + if (parms.flipY) + { + frac = (img->GetHeight() << FRACBITS) - 1; + iyscale = -iyscale; + } + if (parms.windowleft > 0 || parms.windowright < parms.texwidth) { double wi = MIN(parms.windowright, parms.texwidth); diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 96b643dcd..25675b51e 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -622,6 +622,7 @@ bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t t parms->colorOverlay = 0; parms->alphaChannel = false; parms->flipX = false; + parms->flipY = false; parms->color = 0xffffffff; //parms->shadowAlpha = 0; parms->shadowColor = 0; @@ -638,6 +639,10 @@ bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t t parms->cellx = parms->celly = 0; parms->maxstrlen = INT_MAX; parms->virtBottom = false; + parms->srcx = 0.; + parms->srcy = 0.; + parms->srcwidth = 1.; + parms->srcheight = 1.; parms->monospace = EMonospacing::MOff; parms->spacing = 0; parms->fsscalemode = -1; @@ -834,6 +839,26 @@ bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t t parms->flipX = ListGetInt(tags); break; + case DTA_FlipY: + parms->flipY = ListGetInt(tags); + break; + + case DTA_SrcX: + parms->srcx = ListGetDouble(tags) / img->GetScaledWidthDouble(); + break; + + case DTA_SrcY: + parms->srcy = ListGetDouble(tags) / img->GetScaledHeightDouble(); + break; + + case DTA_SrcWidth: + parms->srcwidth = ListGetDouble(tags) / img->GetScaledWidthDouble(); + break; + + case DTA_SrcHeight: + parms->srcheight = ListGetDouble(tags) / img->GetScaledHeightDouble(); + break; + case DTA_TopOffset: assert(fortext == false); if (fortext) return false; diff --git a/src/v_video.h b/src/v_video.h index 942c5a352..fb7bc75ce 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -149,6 +149,11 @@ enum // New additions. DTA_Color, + DTA_FlipY, // bool: flip image vertically + DTA_SrcX, // specify a source rectangle (this supersedes the poorly implemented DTA_WindowLeft/Right + DTA_SrcY, + DTA_SrcWidth, + DTA_SrcHeight, DTA_LegacyRenderStyle, // takes an old-style STYLE_* constant instead of an FRenderStyle DTA_Spacing, // Strings only: Additional spacing between characters DTA_Monospace, // Fonts only: Use a fixed distance between characters. @@ -202,6 +207,7 @@ struct DrawParms PalEntry color; INTBOOL alphaChannel; INTBOOL flipX; + INTBOOL flipY; //float shadowAlpha; int shadowColor; INTBOOL keepratio; @@ -217,6 +223,8 @@ struct DrawParms int maxstrlen; bool fortext; bool virtBottom; + double srcx, srcy; + double srcwidth, srcheight; bool burn; int8_t fsscalemode; }; diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 52c844e16..286f237bd 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -2829,6 +2829,10 @@ void D3DFB::DrawTextureParms (FTexture *img, DrawParms &parms) { swapvalues(u0, u1); } + if (parms.flipY) + { + swapvalues(v0, v1); + } if (parms.windowleft > 0 || parms.windowright < parms.texwidth) { double wi = MIN(parms.windowright, parms.texwidth); diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index 6419cde3a..7812fef4c 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -175,6 +175,11 @@ enum DrawTextureTags DTA_CellY, // vertical size of character cell DTA_Color, + DTA_FlipY, // bool: flip image vertically + DTA_SrcX, // specify a source rectangle (this supersedes the poorly implemented DTA_WindowLeft/Right + DTA_SrcY, + DTA_SrcWidth, + DTA_SrcHeight, DTA_LegacyRenderStyle, // takes an old-style STYLE_* constant instead of an FRenderStyle DTA_Spacing, // Strings only: Additional spacing between characters DTA_Monospace, // Strings only: Use a fixed distance between characters.