Renderer2D cleanup

This commit is contained in:
Simon Lübeß
2021-10-15 22:39:24 +02:00
parent adaf62de62
commit 90e654b750
2 changed files with 25 additions and 94 deletions
+11 -38
View File
@@ -108,7 +108,6 @@ namespace GlitchyEngine.Renderer
private static bool s_sceneRunning; private static bool s_sceneRunning;
#endif #endif
private static Effect s_textureColorEffect;
private static Effect s_batchEffect; private static Effect s_batchEffect;
private static Effect s_circleBatchEffect; private static Effect s_circleBatchEffect;
@@ -136,17 +135,17 @@ namespace GlitchyEngine.Renderer
private static void InitEffect() private static void InitEffect()
{ {
s_textureColorEffect = new Effect("content\\Shaders\\textureColor.hlsl");
s_batchEffect = new Effect("content\\Shaders\\spritebatch.hlsl"); s_batchEffect = new Effect("content\\Shaders\\spritebatch.hlsl");
s_circleBatchEffect = new Effect("content\\Shaders\\circlebatch.hlsl"); s_circleBatchEffect = new Effect("content\\Shaders\\circlebatch.hlsl");
} }
private static void InitGeometry() private static void InitGeometry()
{ {
VertexLayout layout = new VertexLayout(QuadVertex.VertexElements, false, s_textureColorEffect.VertexShader); s_quadGeometry = new GeometryBinding();
s_quadGeometry.SetPrimitiveTopology(.TriangleList);
VertexBuffer quadVertices = new VertexBuffer(typeof(QuadVertex), 4, .Immutable);
using(var quadVertices = new VertexBuffer(typeof(QuadVertex), 4, .Immutable))
{
QuadVertex[4] vertices = .( QuadVertex[4] vertices = .(
.(-0.5f,-0.5f, 0, 1), .(-0.5f,-0.5f, 0, 1),
.(-0.5f, 0.5f, 0, 0), .(-0.5f, 0.5f, 0, 0),
@@ -155,24 +154,19 @@ namespace GlitchyEngine.Renderer
); );
quadVertices.SetData(vertices); quadVertices.SetData(vertices);
s_quadGeometry.SetVertexBufferSlot(quadVertices, 0);
}
IndexBuffer quadIndices = new IndexBuffer(6, .Immutable); using(var quadIndices = new IndexBuffer(6, .Immutable))
{
uint16[6] indices = .( uint16[6] indices = .(
0, 1, 2, 0, 1, 2,
2, 3, 0 2, 3, 0
); );
quadIndices.SetData(indices); quadIndices.SetData(indices);
s_quadGeometry = new GeometryBinding();
s_quadGeometry.SetVertexLayout(layout..ReleaseRefNoDelete());
s_quadGeometry.SetPrimitiveTopology(.TriangleList);
s_quadGeometry.SetVertexBufferSlot(quadVertices, 0);
s_quadGeometry.SetIndexBuffer(quadIndices); s_quadGeometry.SetIndexBuffer(quadIndices);
}
quadVertices.ReleaseRef();
quadIndices.ReleaseRef();
} }
private static void InitInstancingGeometry() private static void InitInstancingGeometry()
@@ -290,7 +284,6 @@ namespace GlitchyEngine.Renderer
FontRenderer.Deinit(); FontRenderer.Deinit();
s_textureColorEffect.ReleaseRef();
s_batchEffect.ReleaseRef(); s_batchEffect.ReleaseRef();
s_circleBatchEffect.ReleaseRef(); s_circleBatchEffect.ReleaseRef();
@@ -345,7 +338,6 @@ namespace GlitchyEngine.Renderer
s_currentEffect.Variables["ViewProjection"].SetData(camera.ViewProjection); s_currentEffect.Variables["ViewProjection"].SetData(camera.ViewProjection);
s_currentCircleEffect.Variables["ViewProjection"].SetData(camera.ViewProjection); s_currentCircleEffect.Variables["ViewProjection"].SetData(camera.ViewProjection);
s_textureColorEffect.Variables["ViewProjection"].SetData(camera.ViewProjection);
s_drawOrder = drawOrder; s_drawOrder = drawOrder;
@@ -546,20 +538,6 @@ namespace GlitchyEngine.Renderer
s_circleInstanceQueue.Clear(); s_circleInstanceQueue.Clear();
} }
private static void DrawImmediate(Matrix transform, ColorRGBA color, Texture2D texture, Vector4 uvTransform)
{
s_textureColorEffect.SetTexture("Texture", texture ?? s_whiteTexture);
s_textureColorEffect.Variables["World"].SetData(transform);
s_textureColorEffect.Variables["Color"].SetData(color);
s_textureColorEffect.Variables["UVTransform"].SetData(uvTransform);
s_textureColorEffect.Bind(Renderer._context);
s_quadGeometry.Bind();
RenderCommand.DrawIndexed(s_quadGeometry);
}
// Primitives // Primitives
// Quad // Quad
@@ -601,16 +579,11 @@ namespace GlitchyEngine.Renderer
Matrix transform = Matrix.Translation(position) * Matrix.RotationZ(rotation) * Matrix.Scaling(size.X, size.Y, 1.0f); Matrix transform = Matrix.Translation(position) * Matrix.RotationZ(rotation) * Matrix.Scaling(size.X, size.Y, 1.0f);
QueueQuadInstance(transform, color, texture, position.Z, uvTransform);
if(s_drawOrder == .Immediate) if(s_drawOrder == .Immediate)
{ {
//DrawImmediate(transform, color, texture, uvTransform);
QueueQuadInstance(transform, color, texture, position.Z, uvTransform);
DrawDeferred(); DrawDeferred();
//Flush();
}
else
{
QueueQuadInstance(transform, color, texture, position.Z, uvTransform);
} }
} }
-42
View File
@@ -1,42 +0,0 @@
Texture2D Texture : register(t0);
SamplerState Sampler : register(s0);
cbuffer Constants : register(b0)
{
float4x4 World;
// TODO: move ViewProjection to seperate cbuffer
float4x4 ViewProjection;
float4 Color;
float4 UVTransform;
};
struct VS_Input
{
float2 Position : POSITION;
float2 Texcoord : TEXCOORD;
};
struct PS_Input
{
float4 Position : SV_Position;
float2 Texcoord : TEXCOORD;
};
PS_Input VS(VS_Input input)
{
PS_Input output;
output.Position = mul(ViewProjection, mul(World, float4(input.Position, 0.0f, 1.0f)));
output.Texcoord = UVTransform.xy + UVTransform.zw * input.Texcoord;
return output;
}
float4 PS(PS_Input input) : SV_Target0
{
return Texture.Sample(Sampler, input.Texcoord) * Color;
}
#effect[VS=VS, PS=PS]