mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Adapted Editor to new RenderTarget api
This commit is contained in:
@@ -12,7 +12,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
private bool _open = true;
|
private bool _open = true;
|
||||||
|
|
||||||
private Texture2D _texture ~ _?.ReleaseRef();
|
private RenderTarget2D _renderTarget ~ _?.ReleaseRef();
|
||||||
|
|
||||||
private bool _hasFocus;
|
private bool _hasFocus;
|
||||||
|
|
||||||
@@ -29,17 +29,15 @@ namespace GlitchyEditor.EditWindows
|
|||||||
get => _hasFocus;
|
get => _hasFocus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture2D Texture
|
public RenderTarget2D RenderTarget
|
||||||
{
|
{
|
||||||
get => _texture;
|
get => _renderTarget;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if(_texture == value)
|
if(_renderTarget == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_texture?.ReleaseRef();
|
SetReference!(_renderTarget, value);
|
||||||
_texture = value;
|
|
||||||
_texture?.AddRef();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,17 +46,10 @@ namespace GlitchyEditor.EditWindows
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ImGui.Vec2 oldViewportSize;
|
private ImGui.Vec2 oldViewportSize;
|
||||||
|
private bool viewPortChanged;
|
||||||
Texture2D _lastTexture;
|
|
||||||
|
|
||||||
public void Show()
|
public void Show()
|
||||||
{
|
{
|
||||||
// Hold a reference to the texture until the next frame.
|
|
||||||
// This is a workaround for the issue that changing the window size will release the texture
|
|
||||||
_lastTexture?.ReleaseRef();
|
|
||||||
_lastTexture = _texture;
|
|
||||||
_lastTexture.AddRef();
|
|
||||||
|
|
||||||
if(!_open)
|
if(!_open)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -80,20 +71,20 @@ namespace GlitchyEditor.EditWindows
|
|||||||
_hasFocus = ImGui.IsWindowFocused();
|
_hasFocus = ImGui.IsWindowFocused();
|
||||||
|
|
||||||
var viewportSize = ImGui.GetContentRegionAvail();
|
var viewportSize = ImGui.GetContentRegionAvail();
|
||||||
|
|
||||||
if(_lastTexture != null)
|
|
||||||
{
|
|
||||||
ImGui.Image(_lastTexture, viewportSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui.End();
|
|
||||||
|
|
||||||
if(oldViewportSize != viewportSize)
|
if(oldViewportSize != viewportSize)
|
||||||
{
|
{
|
||||||
ViewportSizeChangedEvent.Invoke(this, *(Vector2*)&viewportSize);
|
ViewportSizeChangedEvent.Invoke(this, *(Vector2*)&oldViewportSize);
|
||||||
|
viewPortChanged = true;
|
||||||
oldViewportSize = viewportSize;
|
oldViewportSize = viewportSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(_renderTarget != null)
|
||||||
|
{
|
||||||
|
ImGui.Image(_renderTarget, viewportSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ namespace GlitchyEditor
|
|||||||
PerspectiveCameraController _cameraController ~ delete _;
|
PerspectiveCameraController _cameraController ~ delete _;
|
||||||
|
|
||||||
RenderTarget2D _renderTarget2D ~ _?.ReleaseRef();
|
RenderTarget2D _renderTarget2D ~ _?.ReleaseRef();
|
||||||
DepthStencilTarget _depthTarget ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
public this() : base("Example")
|
public this() : base("Example")
|
||||||
{
|
{
|
||||||
@@ -57,8 +56,7 @@ namespace GlitchyEditor
|
|||||||
_alphaBlendState = new BlendState(_context, blendDesc);
|
_alphaBlendState = new BlendState(_context, blendDesc);
|
||||||
_opaqueBlendState = new BlendState(_context, .Default);
|
_opaqueBlendState = new BlendState(_context, .Default);
|
||||||
|
|
||||||
_renderTarget2D = new RenderTarget2D(_context, 100, 100, .R8G8B8A8_UNorm);
|
_renderTarget2D = new RenderTarget2D(_context, RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100) {DepthStencilFormat = .D32_Float});
|
||||||
_depthTarget = new DepthStencilTarget(_context, 100, 100, .D32_Float);
|
|
||||||
|
|
||||||
SamplerStateDescription desc = .();
|
SamplerStateDescription desc = .();
|
||||||
|
|
||||||
@@ -103,10 +101,9 @@ namespace GlitchyEditor
|
|||||||
TransformSystem.Update(_world);
|
TransformSystem.Update(_world);
|
||||||
|
|
||||||
RenderCommand.Clear(_renderTarget2D, .(0.2f, 0.2f, 0.2f));
|
RenderCommand.Clear(_renderTarget2D, .(0.2f, 0.2f, 0.2f));
|
||||||
_depthTarget.Clear(1.0f, 0, .Depth);
|
RenderCommand.Clear(_renderTarget2D, 1.0f, 0, .Depth);
|
||||||
|
|
||||||
_context.SetRenderTarget(_renderTarget2D);
|
_context.SetRenderTarget(_renderTarget2D);
|
||||||
_depthTarget.Bind();
|
|
||||||
_context.BindRenderTargets();
|
_context.BindRenderTargets();
|
||||||
|
|
||||||
RenderCommand.SetViewport(Viewport(0, 0, _renderTarget2D.Width, _renderTarget2D.Height));
|
RenderCommand.SetViewport(Viewport(0, 0, _renderTarget2D.Width, _renderTarget2D.Height));
|
||||||
@@ -148,7 +145,7 @@ namespace GlitchyEditor
|
|||||||
|
|
||||||
DrawMainMenuBar();
|
DrawMainMenuBar();
|
||||||
|
|
||||||
_editor.SceneViewportWindow.Texture = _renderTarget2D;
|
_editor.SceneViewportWindow.RenderTarget = _renderTarget2D;
|
||||||
|
|
||||||
_editor.Update();
|
_editor.Update();
|
||||||
|
|
||||||
@@ -204,20 +201,9 @@ namespace GlitchyEditor
|
|||||||
if(sizeX == 0 || sizeY == 0)
|
if(sizeX == 0 || sizeY == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var sampler = _renderTarget2D.SamplerState;
|
_renderTarget2D.Resize(sizeX, sizeY);
|
||||||
|
|
||||||
_renderTarget2D.ReleaseRef();
|
|
||||||
_depthTarget.ReleaseRef();
|
|
||||||
|
|
||||||
_renderTarget2D = new RenderTarget2D(_context, sizeX, sizeY, .R8G8B8A8_UNorm);
|
|
||||||
_editor.SceneViewportWindow.Texture = _renderTarget2D;
|
|
||||||
|
|
||||||
_depthTarget = new DepthStencilTarget(_context, sizeX, sizeY, .D32_Float);
|
|
||||||
|
|
||||||
_cameraController.AspectRatio = (float)sizeX / (float)sizeY;
|
_cameraController.AspectRatio = (float)sizeX / (float)sizeY;
|
||||||
|
|
||||||
|
|
||||||
_renderTarget2D.SamplerState = sampler;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ namespace Sandbox
|
|||||||
if(_target == null || viewportSize.x != _target.Width || viewportSize.y != _target.Height)
|
if(_target == null || viewportSize.x != _target.Width || viewportSize.y != _target.Height)
|
||||||
{
|
{
|
||||||
_target?.ReleaseRef();
|
_target?.ReleaseRef();
|
||||||
_target = new RenderTarget2D(_context, (.)viewportSize.x, (.)viewportSize.y, .R8G8B8A8_UNorm);
|
_target = new RenderTarget2D(_context, .(.R8G8B8A8_UNorm, (.)viewportSize.x, (.)viewportSize.y));
|
||||||
_depth?.ReleaseRef();
|
_depth?.ReleaseRef();
|
||||||
_depth = new DepthStencilTarget(_context, (.)viewportSize.x, (.)viewportSize.y, .D16_UNorm);
|
_depth = new DepthStencilTarget(_context, (.)viewportSize.x, (.)viewportSize.y, .D16_UNorm);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user