- fix alpha (and other parameter properties) not reuploading the buffer on Shape2D

This commit is contained in:
Gutawer 2021-01-15 02:29:01 +00:00 committed by Rachael Alexanderson
parent d71b03f75e
commit aad50cb218
4 changed files with 75 additions and 28 deletions

View file

@ -527,6 +527,10 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms)
offset = osave; offset = osave;
} }
DShape2D::~DShape2D() {
delete lastParms;
}
//========================================================================== //==========================================================================
// //
// //
@ -553,6 +557,20 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
dg.mTranslationId = 0; dg.mTranslationId = 0;
SetStyle(img, parms, vertexcolor, dg); 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) if (!img->isHardwareCanvas() && parms.TranslationId != -1)
dg.mTranslationId = parms.TranslationId; dg.mTranslationId = parms.TranslationId;
@ -605,6 +623,7 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
shape->bufIndex += 1; shape->bufIndex += 1;
shape->buffers.Reserve(1); shape->buffers.Reserve(1);
auto buf = &shape->buffers[shape->bufIndex]; auto buf = &shape->buffers[shape->bufIndex];
auto verts = TArray<TwoDVertex>(dg.mVertCount, true); auto verts = TArray<TwoDVertex>(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()); buf->UploadData(&verts[0], dg.mVertCount, &shape->mIndices[0], shape->mIndices.Size());
shape->needsVertexUpload = false; shape->needsVertexUpload = false;
shape->uploadedOnce = true;
} }
dg.shape2DBufIndex = shape->bufIndex; 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; offset = osave;
} }

View file

@ -34,32 +34,6 @@ enum EClearWhich
class F2DVertexBuffer; class F2DVertexBuffer;
class DShape2D : public DObject
{
DECLARE_CLASS(DShape2D,DObject)
public:
DShape2D()
{
transform.Identity();
}
TArray<int> mIndices;
TArray<DVector2> mVertices;
TArray<DVector2> mCoords;
double minx = 0.0;
double maxx = 0.0;
double miny = 0.0;
double maxy = 0.0;
DMatrix3x3 transform;
TArray<F2DVertexBuffer> buffers;
bool needsVertexUpload = true;
int bufIndex = -1;
};
struct F2DPolygons struct F2DPolygons
{ {
TArray<FVector4> vertices; TArray<FVector4> vertices;
@ -74,6 +48,7 @@ struct F2DPolygons
}; };
class DShape2D;
class F2DDrawer class F2DDrawer
{ {
@ -150,6 +125,7 @@ public:
DShape2D* shape2D; DShape2D* shape2D;
int shape2DBufIndex; int shape2DBufIndex;
int shape2DIndexCount; int shape2DIndexCount;
bool shapeLastCmd;
RenderCommand() RenderCommand()
{ {
@ -262,6 +238,39 @@ public:
bool mIsFirstPass = true; bool mIsFirstPass = true;
}; };
class DShape2D : public DObject
{
DECLARE_CLASS(DShape2D,DObject)
public:
DShape2D()
{
transform.Identity();
}
TArray<int> mIndices;
TArray<DVector2> mVertices;
TArray<DVector2> mCoords;
double minx = 0.0;
double maxx = 0.0;
double miny = 0.0;
double maxy = 0.0;
DMatrix3x3 transform;
TArray<F2DVertexBuffer> buffers;
bool needsVertexUpload = true;
int bufIndex = -1;
F2DDrawer::RenderCommand* lastCommand = nullptr;
bool uploadedOnce = false;
DrawParms* lastParms;
~DShape2D();
};
//=========================================================================== //===========================================================================
// //
// Vertex buffer for 2D drawer // Vertex buffer for 2D drawer

View file

@ -206,6 +206,17 @@ struct DrawParms
double patchscalex, patchscaley; double patchscalex, patchscaley;
double rotateangle; double rotateangle;
IntRect viewport; 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 struct Va_List

View file

@ -183,12 +183,14 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state)
state.SetVertexBuffer(&cmd.shape2D->buffers[cmd.shape2DBufIndex]); state.SetVertexBuffer(&cmd.shape2D->buffers[cmd.shape2DBufIndex]);
state.DrawIndexed(DT_Triangles, 0, cmd.shape2DIndexCount); state.DrawIndexed(DT_Triangles, 0, cmd.shape2DIndexCount);
state.SetVertexBuffer(&vb); 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->needsVertexUpload = true;
cmd.shape2D->buffers.Clear(); cmd.shape2D->buffers.Clear();
cmd.shape2D->lastCommand = nullptr;
cmd.shape2D->bufIndex = -1; cmd.shape2D->bufIndex = -1;
} }
cmd.shape2D->uploadedOnce = false;
} }
else else
{ {