diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf index f23f355..93a4578 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf @@ -62,7 +62,7 @@ namespace GlitchyEngine.Renderer HResult loadResult = DDSTextureLoader.CreateDDSTextureFromFile(_context.nativeDevice, _path.ToScopedNativeWChar!(), (.)&nativeTexture, &nativeView); - + if(loadResult.Failed) { Log.EngineLogger.Error($"Failed to load texture \"{_path}\". Error({(int)loadResult}): {loadResult}"); @@ -72,6 +72,9 @@ namespace GlitchyEngine.Renderer // TODO: load fallback texture } + + let resType = nativeTexture.GetResourceType(); + Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a 2D texture (it is {resType})."); nativeTexture.GetDescription(out nativeDesc); } @@ -93,4 +96,42 @@ namespace GlitchyEngine.Renderer Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture view. Error ({result.Underlying}): {result}"); } } + + extension TextureCube + { + protected internal ID3D11Texture2D* nativeTexture ~ _?.Release(); + protected internal NativeTex2DDesc nativeDesc; + + public override uint32 Width => nativeDesc.Width; + public override uint32 Height => nativeDesc.Height; + public override uint32 ArraySize => nativeDesc.ArraySize / 6; + public override uint32 MipLevels => nativeDesc.MipLevels; + + protected override void LoadTexturePlatform() + { + nativeTexture?.Release(); + nativeView?.Release(); + + HResult loadResult = DDSTextureLoader.CreateDDSTextureFromFile(_context.nativeDevice, _path.ToScopedNativeWChar!(), + (.)&nativeTexture, &nativeView); + + if(loadResult.Failed) + { + Log.EngineLogger.Error($"Failed to load texture \"{_path}\". Error({(int)loadResult}): {loadResult}"); + + nativeTexture?.Release(); + nativeView?.Release(); + + // TODO: load fallback texture + } + + let resType = nativeTexture.GetResourceType(); + Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a texture cube (it is {resType})."); + + nativeTexture.GetDescription(out nativeDesc); + + Log.EngineLogger.Assert(nativeDesc.MiscFlags.HasFlag(.TextureCube), scope $"The texture \"{_path}\" is not a texture cube."); + // TODO: load fallback texture + } + } } diff --git a/GlitchyEngine/src/Renderer/Texture.bf b/GlitchyEngine/src/Renderer/Texture.bf index 11cf489..6a1db07 100644 --- a/GlitchyEngine/src/Renderer/Texture.bf +++ b/GlitchyEngine/src/Renderer/Texture.bf @@ -77,4 +77,25 @@ namespace GlitchyEngine.Renderer protected extern void CreateTexturePlatform(Texture2DDesc desc, void* data, uint32 linePitch); } + + public class TextureCube : Texture + { + protected String _path ~ delete _; + + public override extern uint32 Width {get;} + public override extern uint32 Height {get;} + public override uint32 Depth => 1; + public override extern uint32 ArraySize {get;} + public override extern uint32 MipLevels {get;} + + protected this(GraphicsContext context) : base(context) {} + + public this(GraphicsContext context, String path) : base(context) + { + this._path = new String(path); + LoadTexturePlatform(); + } + + protected extern void LoadTexturePlatform(); + } }