diff --git a/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf b/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf index ae4c04d..78744a8 100644 --- a/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf +++ b/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf @@ -14,7 +14,7 @@ namespace ImGui public static override void Image(Texture2D texture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero) { - var view = texture.nativeResourceView..AddRef(); + var view = texture._nativeResourceView..AddRef(); _resourceViews.Add(view); ImGui.Image(view, size, uv0, uv1, tint_col, border_col); diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RenderTarget.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RenderTarget.bf index 755a8a7..387d54f 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RenderTarget.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RenderTarget.bf @@ -14,7 +14,6 @@ namespace GlitchyEngine.Renderer extension RenderTarget2D { protected internal ID3D11Texture2D* _nativeTexture ~ _?.Release(); - protected internal ID3D11ShaderResourceView* _nativeResourceView ~ _?.Release(); protected internal ID3D11RenderTargetView* _nativeRenderTargetView ~ _?.Release(); private void ReleaseAndNullify() diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf index fcab3fa..09fd531 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf @@ -18,7 +18,7 @@ namespace GlitchyEngine.Renderer extension Texture { - protected internal ID3D11ShaderResourceView* nativeResourceView ~ _?.Release(); + protected internal ID3D11ShaderResourceView* _nativeResourceView ~ _?.Release(); /** \brief Loads the texture from the specified path. * @param path The path of the texture to load. @@ -39,17 +39,17 @@ namespace GlitchyEngine.Renderer } ((ID3D11Resource*)texture)?.Release(); - nativeResourceView?.Release(); + _nativeResourceView?.Release(); HResult loadResult = DDSTextureLoader.CreateDDSTextureFromMemory(NativeDevice, - ddsData.Ptr, (uint)ddsData.Count, (.)&texture, &nativeResourceView); + ddsData.Ptr, (uint)ddsData.Count, (.)&texture, &_nativeResourceView); if(loadResult.Failed) { Log.EngineLogger.Error($"Failed to load texture. Error({(int)loadResult}): {loadResult}"); ReleaseAndNullify!(texture); - ReleaseAndNullify!(nativeResourceView); + ReleaseAndNullify!(_nativeResourceView); return false; } @@ -126,7 +126,7 @@ namespace GlitchyEngine.Renderer var result = NativeDevice.CreateTexture2D(ref nativeDesc, resDataPtr, &nativeTexture); Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture 2D. Error ({result.Underlying}): {result}"); - result = NativeDevice.CreateShaderResourceView(nativeTexture, null, &nativeResourceView); + result = NativeDevice.CreateShaderResourceView(nativeTexture, null, &_nativeResourceView); Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture view. Error ({result.Underlying}): {result}"); } @@ -136,8 +136,8 @@ namespace GlitchyEngine.Renderer nativeTexture?.Release(); nativeTexture = null; - nativeResourceView?.Release(); - nativeResourceView = null; + _nativeResourceView?.Release(); + _nativeResourceView = null; nativeDesc = (NativeTex2DDesc)desc; diff --git a/GlitchyEngine/src/Renderer/RenderTarget.bf b/GlitchyEngine/src/Renderer/RenderTarget.bf index 9b50c8c..c2898d5 100644 --- a/GlitchyEngine/src/Renderer/RenderTarget.bf +++ b/GlitchyEngine/src/Renderer/RenderTarget.bf @@ -33,34 +33,23 @@ namespace GlitchyEngine.Renderer } } - public class RenderTarget2D : RefCounter + public class RenderTarget2D : Texture { private RenderTarget2DDescription _description; public RenderTarget2DDescription Description => _description; - public uint32 Width => _description.Width; - public uint32 Height => _description.Height; - + public override uint32 Width => _description.Width; + public override uint32 Height => _description.Height; + public override uint32 Depth => 1; + public override uint32 ArraySize => _description.ArraySize; + public override uint32 MipLevels => _description.MipLevels; + protected internal DepthStencilTarget _depthStenilTarget ~ _?.ReleaseRef(); // TODO: DepthStencilTarget is just a renderTarget public DepthStencilTarget DepthStencilTarget => _depthStenilTarget; - protected SamplerState _samplerState ~ _?.ReleaseRef(); - - public SamplerState SamplerState - { - get => _samplerState; - set - { - if(_samplerState == value) - return; - - SetReference!(_samplerState, value); - } - } - public this(RenderTarget2DDescription description) { Debug.Profiler.ProfileResourceFunction!(); diff --git a/GlitchyEngine/src/Renderer/Renderer2D.bf b/GlitchyEngine/src/Renderer/Renderer2D.bf index 989611d..e425d4e 100644 --- a/GlitchyEngine/src/Renderer/Renderer2D.bf +++ b/GlitchyEngine/src/Renderer/Renderer2D.bf @@ -91,13 +91,13 @@ namespace GlitchyEngine.Renderer FrontToBack } - struct QueueQuad: this(Matrix Transform, ColorRGBA Color, Texture2D Texture, float Depth, Vector4 uvTransform) { } + struct QueueQuad: this(Matrix Transform, ColorRGBA Color, Texture Texture, float Depth, Vector4 uvTransform) { } struct QueueCircle : QueueQuad { public float InnerRadius; - public this(Matrix Transform, ColorRGBA Color, Texture2D Texture, float Depth, Vector4 uvTransform, float innerRadius) + public this(Matrix Transform, ColorRGBA Color, Texture Texture, float Depth, Vector4 uvTransform, float innerRadius) : base(Transform, Color, Texture, Depth, uvTransform) { InnerRadius = innerRadius; @@ -472,7 +472,7 @@ namespace GlitchyEngine.Renderer /// Adds a quad instance to the instance queue. [Inline] - private static void QueueQuadInstance(Matrix transform, ColorRGBA color, Texture2D texture, float depth, Vector4 uvTransform) + private static void QueueQuadInstance(Matrix transform, ColorRGBA color, Texture texture, float depth, Vector4 uvTransform) { s_QuadinstanceQueue.Add(QueueQuad(transform, color, texture ?? s_whiteTexture, depth, uvTransform)); s_statistics.QuadCount++; @@ -593,7 +593,7 @@ namespace GlitchyEngine.Renderer if(s_QuadinstanceQueue.IsEmpty) return; - Texture2D texture = s_QuadinstanceQueue[0].Texture; + Texture texture = s_QuadinstanceQueue[0].Texture; s_currentEffect.SetTexture("Texture", texture); s_setInstances = 0; @@ -631,7 +631,7 @@ namespace GlitchyEngine.Renderer if(s_circleInstanceQueue.IsEmpty) return; - Texture2D texture = s_circleInstanceQueue[0].Texture; + Texture texture = s_circleInstanceQueue[0].Texture; s_currentCircleEffect.SetTexture("Texture", texture); s_setInstances = 0; @@ -764,19 +764,19 @@ namespace GlitchyEngine.Renderer // Textured Quad - public static void DrawQuad(Vector2 position, Vector2 size, float rotation, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1)) + public static void DrawQuad(Vector2 position, Vector2 size, float rotation, Texture texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1)) { DrawQuad(Vector3(position, 0.0f), size, rotation, texture, color, uvTransform); } - public static void DrawQuad(Vector3 position, Vector2 size, float rotation, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1)) + public static void DrawQuad(Vector3 position, Vector2 size, float rotation, Texture texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1)) { Matrix transform = Calculate2DTransform(position, size, rotation); DrawQuad(transform, texture, color, uvTransform); } - public static void DrawQuad(Matrix transform, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1)) + public static void DrawQuad(Matrix transform, Texture texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1)) { Debug.Profiler.ProfileRendererFunction!(); diff --git a/GlitchyEngine/src/Renderer/Texture.bf b/GlitchyEngine/src/Renderer/Texture.bf index 052a407..51a1129 100644 --- a/GlitchyEngine/src/Renderer/Texture.bf +++ b/GlitchyEngine/src/Renderer/Texture.bf @@ -17,10 +17,8 @@ namespace GlitchyEngine.Renderer { if(_samplerState == value) return; - - _samplerState?.ReleaseRef(); - _samplerState = value; - _samplerState?.AddRef(); + + SetReference!(_samplerState, value); } }