Fixes for Render2D

This commit is contained in:
Wojtek Figat
2021-02-03 21:52:49 +01:00
parent ba0f07b57e
commit 6ffa497c0a

View File

@@ -182,41 +182,44 @@ struct ClipMask
Render2D::RenderingFeatures Render2D::Features = RenderingFeatures::VertexSnapping; Render2D::RenderingFeatures Render2D::Features = RenderingFeatures::VertexSnapping;
// Private Stuff namespace
GPUContext* Context = nullptr; {
GPUTextureView* Output = nullptr; // Private Stuff
GPUTextureView* DepthBuffer = nullptr; GPUContext* Context = nullptr;
Viewport View; GPUTextureView* Output = nullptr;
Matrix ViewProjection; GPUTextureView* DepthBuffer = nullptr;
Viewport View;
Matrix ViewProjection;
// Drawing // Drawing
Array<Render2DDrawCall> DrawCalls; Array<Render2DDrawCall> DrawCalls;
Array<FontLineCache> Lines; Array<FontLineCache> Lines;
Array<Vector2> Lines2; Array<Vector2> Lines2;
bool IsScissorsRectEmpty; bool IsScissorsRectEmpty;
bool IsScissorsRectEnabled; bool IsScissorsRectEnabled;
// Transform // Transform
// Note: we use Matrix3x3 instead of Matrix because we use only 2D transformations on CPU side // Note: we use Matrix3x3 instead of Matrix because we use only 2D transformations on CPU side
// Matrix layout: // Matrix layout:
// [ m1, m2, 0 ] // [ m1, m2, 0 ]
// [ m3, m4, 0 ] // [ m3, m4, 0 ]
// [ t1, t2, 1 ] // [ t1, t2, 1 ]
// where 'm' is 2D transformation (scale, shear and rotate), 't' is translation // where 'm' is 2D transformation (scale, shear and rotate), 't' is translation
Array<Matrix3x3, InlinedAllocation<64>> TransformLayersStack; Array<Matrix3x3, InlinedAllocation<64>> TransformLayersStack;
Matrix3x3 TransformCached; Matrix3x3 TransformCached;
Array<ClipMask, InlinedAllocation<64>> ClipLayersStack; Array<ClipMask, InlinedAllocation<64>> ClipLayersStack;
// Shader // Shader
AssetReference<Shader> GUIShader; AssetReference<Shader> GUIShader;
CachedPSO PsoDepth; CachedPSO PsoDepth;
CachedPSO PsoNoDepth; CachedPSO PsoNoDepth;
CachedPSO* CurrentPso = nullptr; CachedPSO* CurrentPso = nullptr;
DynamicVertexBuffer VB(RENDER2D_INITIAL_VB_CAPACITY, (uint32)sizeof(Render2DVertex), TEXT("Render2D.VB")); DynamicVertexBuffer VB(RENDER2D_INITIAL_VB_CAPACITY, (uint32)sizeof(Render2DVertex), TEXT("Render2D.VB"));
DynamicIndexBuffer IB(RENDER2D_INITIAL_IB_CAPACITY, sizeof(uint32), TEXT("Render2D.IB")); DynamicIndexBuffer IB(RENDER2D_INITIAL_IB_CAPACITY, sizeof(uint32), TEXT("Render2D.IB"));
uint32 VBIndex = 0; uint32 VBIndex = 0;
uint32 IBIndex = 0; uint32 IBIndex = 0;
}
#define RENDER2D_WRITE_IB_QUAD(indices) \ #define RENDER2D_WRITE_IB_QUAD(indices) \
indices[0] = VBIndex + 0; \ indices[0] = VBIndex + 0; \
@@ -957,8 +960,8 @@ void DrawBatch(int32 startIndex, int32 count)
data.Bounds.Y = bounds.Y; data.Bounds.Y = bounds.Y;
data.Bounds.Z = bounds.Z - bounds.X; data.Bounds.Z = bounds.Z - bounds.X;
data.Bounds.W = bounds.W - bounds.Y; data.Bounds.W = bounds.W - bounds.Y;
data.InvBufferSize.X = 1.0f / renderTargetWidth; data.InvBufferSize.X = 1.0f / (float)renderTargetWidth;
data.InvBufferSize.Y = 1.0f / renderTargetHeight; data.InvBufferSize.Y = 1.0f / (float)renderTargetHeight;
data.SampleCount = ComputeBlurWeights(kernelSize, blurStrength, data.WeightAndOffsets); data.SampleCount = ComputeBlurWeights(kernelSize, blurStrength, data.WeightAndOffsets);
const auto cb = GUIShader->GetShader()->GetCB(1); const auto cb = GUIShader->GetShader()->GetCB(1);
Context->UpdateCB(cb, &data); Context->UpdateCB(cb, &data);
@@ -1003,11 +1006,8 @@ void DrawBatch(int32 startIndex, int32 count)
break; break;
} }
case DrawCallType::ClipScissors: case DrawCallType::ClipScissors:
{ Context->SetScissor(*(Rectangle*)&d.AsClipScissors.X);
Rectangle* scissorsRect = (Rectangle*)&d.AsClipScissors.X;
Context->SetScissor(*scissorsRect);
return; return;
}
case DrawCallType::LineAA: case DrawCallType::LineAA:
Context->SetState(CurrentPso->PS_LineAA); Context->SetState(CurrentPso->PS_LineAA);
break; break;