Added Textures

This commit is contained in:
Simon Lübeß
2021-02-08 12:37:30 +01:00
parent 1055712ec1
commit 2adb138f72
8 changed files with 691 additions and 516 deletions
@@ -0,0 +1,48 @@
using System;
using DirectX.D3D11;
using DirectX.Common;
using DirectXTK;
using internal GlitchyEngine.Renderer;
namespace GlitchyEngine.Renderer
{
extension Texture2D
{
internal ID3D11Texture2D* nativeTexture ~ _?.Release();
internal ID3D11ShaderResourceView* nativeView ~ _?.Release();
internal Texture2DDescription nativeDesc;
public override uint32 Width => nativeDesc.Width;
public override uint32 Height => nativeDesc.Height;
public override uint32 ArraySize => nativeDesc.ArraySize;
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
}
nativeTexture.GetDescription(out nativeDesc);
}
public override void Bind(uint32 slot)
{
_context.nativeContext.VertexShader.SetShaderResources(slot, 1, &nativeView);
_context.nativeContext.PixelShader.SetShaderResources(slot, 1, &nativeView);
}
}
}