From 1890df98f95ae79cb33e90a39018e4ffe2647875 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 31 Dec 2019 19:02:55 +0100 Subject: [PATCH] - process lines through the 2D drawer. --- source/CMakeLists.txt | 1 - source/build/include/palette.h | 1 - source/build/src/2d.cpp | 107 -------------------------------- source/build/src/engine.cpp | 8 +-- source/build/src/palette.cpp | 56 ----------------- source/common/2d/v_2ddrawer.cpp | 29 +++++++-- source/common/2d/v_2ddrawer.h | 3 +- source/glbackend/glbackend.cpp | 6 +- source/glbackend/hw_draw2d.cpp | 2 +- 9 files changed, 36 insertions(+), 177 deletions(-) delete mode 100644 source/build/src/2d.cpp diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 61c6c5233..517d6b3b0 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -681,7 +681,6 @@ set (PCH_SOURCES #thirdparty/imgui/imgui_widgets.cpp # Todo: Split out the license-safe code from this. - build/src/2d.cpp build/src/a-c.cpp build/src/animvpx.cpp build/src/baselayer.cpp diff --git a/source/build/include/palette.h b/source/build/include/palette.h index d3d92a26d..94df7d90b 100644 --- a/source/build/include/palette.h +++ b/source/build/include/palette.h @@ -52,7 +52,6 @@ typedef struct { extern palette_t curpalette[256], curpalettefaded[256], palfadergb; extern char palfadedelta; -extern void videoFadeToBlack(int32_t moreopaquep); void paletteMakeLookupTable(int32_t palnum, const char *remapbuf, uint8_t r, uint8_t g, uint8_t b, char noFloorPal); void paletteSetColorTable(int32_t id, uint8_t const *table, bool transient = false); void paletteFreeColorTable(int32_t id); diff --git a/source/build/src/2d.cpp b/source/build/src/2d.cpp deleted file mode 100644 index 3da494211..000000000 --- a/source/build/src/2d.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file has been modified from Ken Silverman's original release -// by Jonathon Fowler (jf@jonof.id.au) -// by the EDuke32 team (development@voidpoint.com) - -#include "build.h" -#include "compat.h" -#include "baselayer.h" -#include "matrix.h" -#include "../../glbackend/glbackend.h" - - - -// -// drawline256 -// -#ifdef USE_OPENGL -static void drawlinegl(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t p) -{ - // setpolymost2dview(); // JBF 20040205: more efficient setup - - int const dx = x2-x1; - int const dy = y2-y1; - - if (dx >= 0) - { - if ((x1 >= wx2) || (x2 < wx1)) return; - if (x1 < wx1) y1 += scale(wx1-x1, dy, dx), x1 = wx1; - if (x2 > wx2) y2 += scale(wx2-x2, dy, dx), x2 = wx2; - } - else - { - if ((x2 >= wx2) || (x1 < wx1)) return; - if (x2 < wx1) y2 += scale(wx1-x2, dy, dx), x2 = wx1; - if (x1 > wx2) y1 += scale(wx2-x1, dy, dx), x1 = wx2; - } - if (dy >= 0) - { - if ((y1 >= wy2) || (y2 < wy1)) return; - if (y1 < wy1) x1 += scale(wy1-y1, dx, dy), y1 = wy1; - if (y2 > wy2) x2 += scale(wy2-y2, dx, dy), y2 = wy2; - } - else - { - if ((y2 >= wy2) || (y1 < wy1)) return; - if (y2 < wy1) x2 += scale(wy1-y2, dx, dy), y2 = wy1; - if (y1 > wy2) x1 += scale(wy2-y1, dx, dy), y1 = wy2; - } - - GLInterface.SetViewport(0, 0, xdim, ydim); - VSMatrix proj(0); - proj.ortho(0, xdim, ydim, 0, -1, 1); - GLInterface.SetMatrix(Matrix_Projection, &proj); - - gloy1 = -1; - GLInterface.EnableAlphaTest(false); - GLInterface.EnableDepthTest(false); - GLInterface.EnableBlend(true); // When using line antialiasing, this is needed - - GLInterface.UseColorOnly(true); - GLInterface.SetColorub(p.r, p.g, p.b, 255); - - auto data = GLInterface.AllocVertices(2); - data.second[0].Set((float) x1 * (1.f/4096.f), (float) y1 * (1.f/4096.f)); - data.second[1].Set((float) x2 * (1.f/4096.f), (float) y2 * (1.f/4096.f)); - GLInterface.Draw(DT_LINES, data.first, 2); - - GLInterface.UseColorOnly(false); -} -#endif - - -void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t p) -{ -#ifdef USE_OPENGL - if (videoGetRenderMode() >= REND_POLYMOST) - { - drawlinegl(x1, y1, x2, y2, p); - return; - } -#endif - - //char const col = palookup[0][p.f]; - //drawlinepixels(x1, y1, x2, y2, col); -} - -void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t col) -{ - col = palookup[0][col]; - -#ifdef USE_OPENGL - if (videoGetRenderMode() >= REND_POLYMOST) - { - palette_t p = paletteGetColor(col); - p.f = col; - drawlinegl(x1, y1, x2, y2, p); - return; - } -#endif - - //drawlinepixels(x1, y1, x2, y2, col); -} - - diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index d15e4a5fa..d77932b99 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -10495,10 +10495,10 @@ void videoSetCorrectedAspect() // void videoSetViewableArea(int32_t x1, int32_t y1, int32_t x2, int32_t y2) { - windowxy1.x = x1; wx1 = (x1<<12); - windowxy1.y = y1; wy1 = (y1<<12); - windowxy2.x = x2; wx2 = ((x2+1)<<12); - windowxy2.y = y2; wy2 = ((y2+1)<<12); + windowxy1.x = x1; + windowxy1.y = y1; + windowxy2.x = x2; + windowxy2.y = y2; xdimen = (x2-x1)+1; halfxdimen = (xdimen>>1); xdimenrecip = divscale32(1L,xdimen); diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index f5204034c..51dc280bc 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -63,67 +63,14 @@ int DetermineTranslucency(const uint8_t *table) if (newcolor2.r == 255) // if black on white results in white it's either // fully transparent or additive { - /* - if (developer >= DMSG_NOTIFY) - { - char lumpname[9]; - lumpname[8] = 0; - Wads.GetLumpName(lumpname, lumpnum); - Printf("%s appears to be additive translucency %d (%d%%)\n", lumpname, newcolor.r, - newcolor.r * 100 / 255); - } - */ return -newcolor.r; } - /* - if (developer >= DMSG_NOTIFY) - { - char lumpname[9]; - lumpname[8] = 0; - Wads.GetLumpName(lumpname, lumpnum); - Printf("%s appears to be translucency %d (%d%%)\n", lumpname, newcolor.r, - newcolor.r * 100 / 255); - } - */ return newcolor.r; } void fullscreen_tint_gl(PalEntry pe); -void videoFadeToBlack(int32_t moreopaquep) -{ -#ifdef USE_OPENGL - if (videoGetRenderMode() >= REND_POLYMOST) - fullscreen_tint_gl(moreopaquep? PalEntry(168, 0, 0, 0) : PalEntry(84, 0, 0, 0)); - else -#endif - { - Bassert(!offscreenrendering); - - videoBeginDrawing(); - char *const p = (char *) frameplace; - const char *const trans = paletteGetBlendTable(0); - const int32_t shiftamnt = ((!!moreopaquep)*8); - const int32_t dimprod = xdim*ydim; - int32_t i = 0; - -#ifdef CLASSIC_SLICE_BY_4 - for (; i 0 || clipy1 > 0 || clipx2 < screen->GetWidth()- 1 || clipy2 < screen->GetHeight() - 1) + { + dg.mScissor[0] = clipx1; + dg.mScissor[1] = clipy1; + dg.mScissor[2] = clipx2 + 1; + dg.mScissor[3] = clipy2 + 1; + dg.mFlags |= DTF_Scissor; + } + dg.mType = DrawTypeLines; dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent]; dg.mVertCount = 2; @@ -619,7 +628,7 @@ void F2DDrawer::rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 int method = 0; dg.mType = DrawTypeRotateSprite; - if (clipx1 > 0 || clipy1 > 0 || clipx2 < xdim - 1 || clipy2 < ydim - 1) + if (clipx1 > 0 || clipy1 > 0 || clipx2 < screen->GetWidth() - 1 || clipy2 < screen->GetHeight() - 1) { dg.mScissor[0] = clipx1; dg.mScissor[1] = clipy1; @@ -714,7 +723,7 @@ void F2DDrawer::AddPoly(FTexture* img, FVector4* vt, size_t vtcount, unsigned in dg.mType = DrawTypeRotateSprite; #if 0 - if (clipx1 > 0 || clipy1 > 0 || clipx2 < xdim - 1 || clipy2 < ydim - 1) + if (clipx1 > 0 || clipy1 > 0 || clipx2 < screen->GetWidth() - 1 || clipy2 < screen->GetHeight() - 1) { dg.mScissor[0] = clipx1; dg.mScissor[1] = clipy1; @@ -816,4 +825,14 @@ void F2DDrawer::FillPolygon(int *rx1, int *ry1, int *xb1, int32_t npoints, int p } +void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t p) +{ + twod->AddLine(x1 / 4096.f, y1 / 4096.f, x2 / 4096.f, y2 / 4096.f, windowxy1.x, windowxy1.y, windowxy2.x, windowxy2.y, PalEntry(p.r, p.g, p.b)); +} + +void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t col) +{ + drawlinergb(x1, y1, x2, y2, paletteGetColor(palookup[0][col])); +} + diff --git a/source/common/2d/v_2ddrawer.h b/source/common/2d/v_2ddrawer.h index f81643866..ea937f9fb 100644 --- a/source/common/2d/v_2ddrawer.h +++ b/source/common/2d/v_2ddrawer.h @@ -134,7 +134,8 @@ public: void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr); - void AddLine(int x1, int y1, int x2, int y2, uint32_t color, uint8_t alpha = 255); + void AddLine(float x1, float y1, float x2, float y2, uint32_t color, uint8_t alpha = 255); + void AddLine(float x1, float y1, float x2, float y2, int cx, int cy, int cx2, int cy2, 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); diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 6baf89807..84143e76f 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -259,10 +259,14 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) } glEnd(); } - else + else if (type != DT_LINES) { glDrawElements(primtypes[type], count, GL_UNSIGNED_INT, (void*)(intptr_t)(start * sizeof(uint32_t))); } + else + { + glDrawArrays(primtypes[type], start, count); + } if (MatrixChange) RestoreTextureProps(); } diff --git a/source/glbackend/hw_draw2d.cpp b/source/glbackend/hw_draw2d.cpp index 7b086b4c2..982b5385f 100644 --- a/source/glbackend/hw_draw2d.cpp +++ b/source/glbackend/hw_draw2d.cpp @@ -189,7 +189,7 @@ void GLInstance::Draw2D(F2DDrawer *drawer) break; case F2DDrawer::DrawTypeLines: - //Draw(DT_LINES, cmd.mVertIndex, cmd.mVertCount); + Draw(DT_LINES, cmd.mVertIndex, cmd.mVertCount); break; case F2DDrawer::DrawTypePoints: