Added TextureCube

This commit is contained in:
Simon Lübeß
2021-04-09 19:35:13 +02:00
parent ad4933a1f9
commit 1f687f9b96
2 changed files with 63 additions and 1 deletions
@@ -73,6 +73,9 @@ namespace GlitchyEngine.Renderer
// TODO: load fallback texture // 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); 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}"); 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
}
}
} }
+21
View File
@@ -77,4 +77,25 @@ namespace GlitchyEngine.Renderer
protected extern void CreateTexturePlatform(Texture2DDesc desc, void* data, uint32 linePitch); 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();
}
} }