SpriteRenderer Editor, enabled alpha-blending and depth

This commit is contained in:
Simon Lübeß
2022-04-02 00:10:00 +02:00
parent c13b0a26d1
commit d47bc37886
3 changed files with 31 additions and 7 deletions
@@ -39,6 +39,7 @@ namespace GlitchyEditor.EditWindows
ShowNameComponentEditor(entity); ShowNameComponentEditor(entity);
ShowTransformComponentEditor(entity); ShowTransformComponentEditor(entity);
ShowCameraComponentEditor(entity); ShowCameraComponentEditor(entity);
ShowSpriteRendererComponentEditor(entity);
} }
private static void ShowNameComponentEditor(Entity entity) private static void ShowNameComponentEditor(Entity entity)
@@ -279,5 +280,20 @@ namespace GlitchyEditor.EditWindows
ImGui.TreePop(); ImGui.TreePop();
} }
} }
private static void ShowSpriteRendererComponentEditor(Entity entity)
{
if (!entity.HasComponent<SpriterRendererComponent>())
return;
var spriterRendererComponent = entity.GetComponent<SpriterRendererComponent>();
if(ImGui.TreeNodeEx("Sprite Renderer", .DefaultOpen))
{
ImGui.ColorEdit4("Color", ref spriterRendererComponent.Color);
ImGui.TreePop();
}
}
} }
} }
+11 -6
View File
@@ -15,10 +15,11 @@ namespace GlitchyEditor
RasterizerState _rasterizerState ~ _?.ReleaseRef(); RasterizerState _rasterizerState ~ _?.ReleaseRef();
RasterizerState _rasterizerStateClockWise ~ _?.ReleaseRef(); RasterizerState _rasterizerStateClockWise ~ _?.ReleaseRef();
GraphicsContext _context ~ _?.ReleaseRef(); GraphicsContext _context ~ _.ReleaseRef();
BlendState _alphaBlendState ~ _?.ReleaseRef(); BlendState _alphaBlendState ~ _.ReleaseRef();
BlendState _opaqueBlendState ~ _?.ReleaseRef(); BlendState _opaqueBlendState ~ _.ReleaseRef();
DepthStencilState _depthStencilState ~ _.ReleaseRef();
Scene _scene = new Scene() ~ delete _; Scene _scene = new Scene() ~ delete _;
@@ -116,6 +117,9 @@ namespace GlitchyEditor
_alphaBlendState = new BlendState(blendDesc); _alphaBlendState = new BlendState(blendDesc);
_opaqueBlendState = new BlendState(.Default); _opaqueBlendState = new BlendState(.Default);
DepthStencilStateDescription dsDesc = .();
_depthStencilState = new DepthStencilState(dsDesc);
_viewportTarget = new RenderTarget2D(RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100) {DepthStencilFormat = .D32_Float}); _viewportTarget = new RenderTarget2D(RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100) {DepthStencilFormat = .D32_Float});
_viewportTarget.SamplerState = SamplerStateManager.LinearClamp; _viewportTarget.SamplerState = SamplerStateManager.LinearClamp;
} }
@@ -143,12 +147,13 @@ namespace GlitchyEditor
RenderCommand.Clear(_viewportTarget, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0); RenderCommand.Clear(_viewportTarget, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0);
RenderCommand.SetRenderTarget(_viewportTarget); RenderCommand.SetRenderTarget(_viewportTarget, 0, true);
RenderCommand.BindRenderTargets(); RenderCommand.BindRenderTargets();
RenderCommand.SetViewport(Viewport(0, 0, _viewportTarget.Width, _viewportTarget.Height)); RenderCommand.SetViewport(Viewport(0, 0, _viewportTarget.Width, _viewportTarget.Height));
RenderCommand.SetBlendState(_opaqueBlendState); RenderCommand.SetBlendState(_alphaBlendState);
RenderCommand.SetDepthStencilState(_depthStencilState);
//Renderer.BeginScene(_cameraController.Camera); //Renderer.BeginScene(_cameraController.Camera);
@@ -160,7 +165,7 @@ namespace GlitchyEditor
RenderCommand.Clear(null, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0); RenderCommand.Clear(null, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0);
RenderCommand.SetRenderTarget(null); RenderCommand.SetRenderTarget(null, 0, true);
RenderCommand.BindRenderTargets(); RenderCommand.BindRenderTargets();
RenderCommand.SetViewport(_context.SwapChain.BackbufferViewport); RenderCommand.SetViewport(_context.SwapChain.BackbufferViewport);
+4 -1
View File
@@ -12,8 +12,11 @@ namespace GlitchyEngine.World
public this() public this()
{ {
Entity entity = CreateEntity(); Entity entity = CreateEntity("Green Quad");
entity.AddComponent<SpriterRendererComponent>(.(ColorRGBA(0.2f, 0.9f, 0.15f))); entity.AddComponent<SpriterRendererComponent>(.(ColorRGBA(0.2f, 0.9f, 0.15f)));
Entity entity2 = CreateEntity("Red Square");
entity2.AddComponent<SpriterRendererComponent>(.(ColorRGBA(0.95f, 0.1f, 0.3f)));
} }
public ~this() public ~this()