mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Renderer2D: render Null-Texture and custom UV-Coordinates
This commit is contained in:
@@ -41,11 +41,13 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
public Matrix Transform;
|
public Matrix Transform;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
public Vector4 UVTransform;
|
||||||
|
|
||||||
public this(Matrix transform, Color color)
|
public this(Matrix transform, Color color, Vector4 uvTransform)
|
||||||
{
|
{
|
||||||
Transform = transform;
|
Transform = transform;
|
||||||
Color = color;
|
Color = color;
|
||||||
|
UVTransform = uvTransform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +64,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
private GeometryBinding instancingBinding ~ _?.ReleaseRef();
|
private GeometryBinding instancingBinding ~ _?.ReleaseRef();
|
||||||
private VertexBuffer instanceBuffer ~ _?.ReleaseRef();
|
private VertexBuffer instanceBuffer ~ _?.ReleaseRef();
|
||||||
|
|
||||||
|
private Texture2D whiteTexture ~ _.ReleaseRef();
|
||||||
|
|
||||||
private BatchVertex[] _rawInstances = new BatchVertex[1024] ~ delete _;
|
private BatchVertex[] _rawInstances = new BatchVertex[1024] ~ delete _;
|
||||||
private uint32 _setInstances = 0;
|
private uint32 _setInstances = 0;
|
||||||
|
|
||||||
@@ -106,6 +110,19 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
quadVertices.ReleaseRef();
|
quadVertices.ReleaseRef();
|
||||||
quadIndices.ReleaseRef();
|
quadIndices.ReleaseRef();
|
||||||
|
|
||||||
|
Texture2DDesc tex2Ddesc;
|
||||||
|
tex2Ddesc.Format = .R8G8B8A8_UNorm;
|
||||||
|
tex2Ddesc.Width = 1;
|
||||||
|
tex2Ddesc.Height = 1;
|
||||||
|
tex2Ddesc.MipLevels = 1;
|
||||||
|
tex2Ddesc.ArraySize = 1;
|
||||||
|
tex2Ddesc.Usage = .Immutable;
|
||||||
|
tex2Ddesc.CpuAccess = .None;
|
||||||
|
whiteTexture = new Texture2D(_context, tex2Ddesc);
|
||||||
|
|
||||||
|
Color color = .White;
|
||||||
|
whiteTexture.SetData(&color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitInstancing(EffectLibrary effectLibrary)
|
void InitInstancing(EffectLibrary effectLibrary)
|
||||||
@@ -122,7 +139,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
VertexElement(.R32G32B32A32_Float, "TRANSFORM", 1, 1, (.)-1, .PerInstanceData, 1),
|
VertexElement(.R32G32B32A32_Float, "TRANSFORM", 1, 1, (.)-1, .PerInstanceData, 1),
|
||||||
VertexElement(.R32G32B32A32_Float, "TRANSFORM", 2, 1, (.)-1, .PerInstanceData, 1),
|
VertexElement(.R32G32B32A32_Float, "TRANSFORM", 2, 1, (.)-1, .PerInstanceData, 1),
|
||||||
VertexElement(.R32G32B32A32_Float, "TRANSFORM", 3, 1, (.)-1, .PerInstanceData, 1),
|
VertexElement(.R32G32B32A32_Float, "TRANSFORM", 3, 1, (.)-1, .PerInstanceData, 1),
|
||||||
VertexElement( .R8G8B8A8_UNorm, "COLOR", 0, 1, (.)-1, .PerInstanceData, 1)
|
VertexElement( .R8G8B8A8_UNorm, "COLOR", 0, 1, (.)-1, .PerInstanceData, 1),
|
||||||
|
VertexElement(.R32G32B32A32_Float, "TEXCOORD", 0, 1, (.)-1, .PerInstanceData, 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
instancingLayout = new VertexLayout(_context, vertexElements, instancingEffect.VertexShader);
|
instancingLayout = new VertexLayout(_context, vertexElements, instancingEffect.VertexShader);
|
||||||
@@ -183,11 +201,11 @@ namespace GlitchyEngine.Renderer
|
|||||||
-1, 1, 0, 1);
|
-1, 1, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct QueuedQuad: this(Matrix Transform, Color Color, Texture2D Texture, float Depth) { }
|
struct QueuedQuad: this(Matrix Transform, Color Color, Texture2D Texture, float Depth, Vector4 uvTransform) { }
|
||||||
|
|
||||||
List<QueuedQuad> _quads = new .(128) ~ delete _;
|
List<QueuedQuad> _quads = new .(128) ~ delete _;
|
||||||
|
|
||||||
public void Draw(Texture2D texture, float x, float y, float width, float height, Color color = .White, float depth = 0.0f)
|
public void Draw(Texture2D texture, float x, float y, float width, float height, Color color = .White, float depth = 0.0f, Vector4 uvTransform = .(0, 0, 1, 1))
|
||||||
{
|
{
|
||||||
Matrix transform = .(width, 0, 0, 0,
|
Matrix transform = .(width, 0, 0, 0,
|
||||||
0, height, 0, 0,
|
0, height, 0, 0,
|
||||||
@@ -196,6 +214,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
if(_drawOrder == .Immediate)
|
if(_drawOrder == .Immediate)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
texture.Bind();
|
texture.Bind();
|
||||||
|
|
||||||
quadEffect.Variables["World"].SetData(transform);
|
quadEffect.Variables["World"].SetData(transform);
|
||||||
@@ -205,10 +224,13 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
quadBinding.Bind(_context);
|
quadBinding.Bind(_context);
|
||||||
RenderCommand.DrawIndexed(quadBinding);
|
RenderCommand.DrawIndexed(quadBinding);
|
||||||
|
*/
|
||||||
|
_quads.Add(.(transform, color, texture ?? whiteTexture, depth, uvTransform));
|
||||||
|
DrawDeferred();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_quads.Add(.(transform, color, texture, depth));
|
_quads.Add(.(transform, color, texture ?? whiteTexture, depth, uvTransform));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +309,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
texture.Bind();
|
texture.Bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
_rawInstances[_setInstances++] = .(quad.Transform, quad.Color);
|
_rawInstances[_setInstances++] = .(quad.Transform, quad.Color, quad.uvTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
FlushInstances();
|
FlushInstances();
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ SamplerState Sampler : register(s0);
|
|||||||
|
|
||||||
struct VS_Input
|
struct VS_Input
|
||||||
{
|
{
|
||||||
float2 Position : POSITION;
|
float2 Position : POSITION;
|
||||||
float4x4 Tranform : TRANSFORM;
|
float4x4 Tranform : TRANSFORM;
|
||||||
float4 Color : COLOR;
|
float4 Color : COLOR;
|
||||||
|
float4 UVTransform : TEXCOORD;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PS_Input
|
struct PS_Input
|
||||||
@@ -20,7 +21,7 @@ PS_Input VS(VS_Input input)
|
|||||||
PS_Input output;
|
PS_Input output;
|
||||||
|
|
||||||
output.Position = mul(float4(input.Position, 0.0f, 1.0f), input.Tranform);
|
output.Position = mul(float4(input.Position, 0.0f, 1.0f), input.Tranform);
|
||||||
output.TexCoord = input.Position;
|
output.TexCoord = input.UVTransform.xy + input.UVTransform.zw * input.Position;
|
||||||
output.Color = input.Color;
|
output.Color = input.Color;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
Reference in New Issue
Block a user