diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 1571011600..fb4c63656c 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -527,6 +527,10 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms) offset = osave; } +DShape2D::~DShape2D() { + delete lastParms; +} + //========================================================================== // // @@ -553,6 +557,20 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms) dg.mTranslationId = 0; SetStyle(img, parms, vertexcolor, dg); + if (shape->lastParms == nullptr) { + shape->lastParms = new DrawParms(parms); + } + else if (shape->lastParms->vertexColorChange(parms)) { + shape->needsVertexUpload = true; + if (!shape->uploadedOnce) { + shape->bufIndex = -1; + shape->buffers.Clear(); + shape->lastCommand = nullptr; + } + delete shape->lastParms; + shape->lastParms = new DrawParms(parms); + } + if (!img->isHardwareCanvas() && parms.TranslationId != -1) dg.mTranslationId = parms.TranslationId; @@ -605,6 +623,7 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms) shape->bufIndex += 1; shape->buffers.Reserve(1); + auto buf = &shape->buffers[shape->bufIndex]; auto verts = TArray(dg.mVertCount, true); @@ -625,9 +644,15 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms) buf->UploadData(&verts[0], dg.mVertCount, &shape->mIndices[0], shape->mIndices.Size()); shape->needsVertexUpload = false; + shape->uploadedOnce = true; } dg.shape2DBufIndex = shape->bufIndex; - AddCommand(&dg); + dg.shapeLastCmd = true; + if (shape->lastCommand != nullptr) { + shape->lastCommand->shapeLastCmd = false; + } + auto c = AddCommand(&dg); + shape->lastCommand = &mData[c]; offset = osave; } diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index ce94c42337..ef571f8950 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -34,32 +34,6 @@ enum EClearWhich class F2DVertexBuffer; -class DShape2D : public DObject -{ - - DECLARE_CLASS(DShape2D,DObject) -public: - DShape2D() - { - transform.Identity(); - } - - TArray mIndices; - TArray mVertices; - TArray mCoords; - - double minx = 0.0; - double maxx = 0.0; - double miny = 0.0; - double maxy = 0.0; - - DMatrix3x3 transform; - - TArray buffers; - bool needsVertexUpload = true; - int bufIndex = -1; -}; - struct F2DPolygons { TArray vertices; @@ -74,6 +48,7 @@ struct F2DPolygons }; +class DShape2D; class F2DDrawer { @@ -150,6 +125,7 @@ public: DShape2D* shape2D; int shape2DBufIndex; int shape2DIndexCount; + bool shapeLastCmd; RenderCommand() { @@ -262,6 +238,39 @@ public: bool mIsFirstPass = true; }; +class DShape2D : public DObject +{ + + DECLARE_CLASS(DShape2D,DObject) +public: + DShape2D() + { + transform.Identity(); + } + + TArray mIndices; + TArray mVertices; + TArray mCoords; + + double minx = 0.0; + double maxx = 0.0; + double miny = 0.0; + double maxy = 0.0; + + DMatrix3x3 transform; + + TArray buffers; + bool needsVertexUpload = true; + int bufIndex = -1; + F2DDrawer::RenderCommand* lastCommand = nullptr; + + bool uploadedOnce = false; + DrawParms* lastParms; + + ~DShape2D(); +}; + + //=========================================================================== // // Vertex buffer for 2D drawer diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index 49ca81ed39..a0407179e0 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -206,6 +206,17 @@ struct DrawParms double patchscalex, patchscaley; double rotateangle; IntRect viewport; + + bool vertexColorChange(const DrawParms& other) { + return + this->Alpha != other.Alpha || + this->fillcolor != other.fillcolor || + this->colorOverlay != other.colorOverlay || + this->color != other.color || + this->style.Flags != other.style.Flags || + this->style.BlendOp != other.style.BlendOp || + this->desaturate != other.desaturate; + } }; struct Va_List diff --git a/src/common/rendering/hwrenderer/hw_draw2d.cpp b/src/common/rendering/hwrenderer/hw_draw2d.cpp index 21b7f5afc1..a7031171ff 100644 --- a/src/common/rendering/hwrenderer/hw_draw2d.cpp +++ b/src/common/rendering/hwrenderer/hw_draw2d.cpp @@ -183,12 +183,14 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) state.SetVertexBuffer(&cmd.shape2D->buffers[cmd.shape2DBufIndex]); state.DrawIndexed(DT_Triangles, 0, cmd.shape2DIndexCount); state.SetVertexBuffer(&vb); - if (cmd.shape2D->bufIndex > 0 && cmd.shape2DBufIndex == cmd.shape2D->bufIndex) + if (cmd.shape2D->bufIndex > 0 && cmd.shapeLastCmd) { cmd.shape2D->needsVertexUpload = true; cmd.shape2D->buffers.Clear(); + cmd.shape2D->lastCommand = nullptr; cmd.shape2D->bufIndex = -1; } + cmd.shape2D->uploadedOnce = false; } else {