mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Added protected function to create Texture2D from raw data
This commit is contained in:
@@ -5,6 +5,8 @@ using DirectXTK;
|
||||
|
||||
using internal GlitchyEngine.Renderer;
|
||||
|
||||
typealias NativeTex2DDesc = DirectX.D3D11.Texture2DDescription;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
extension Texture
|
||||
@@ -18,10 +20,35 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
extension Texture2DDesc
|
||||
{
|
||||
public NativeTex2DDesc ToNative()
|
||||
{
|
||||
NativeTex2DDesc desc;
|
||||
|
||||
desc.Width = Width;
|
||||
desc.Height = Height;
|
||||
desc.MipLevels = MipLevels;
|
||||
desc.ArraySize = ArraySize;
|
||||
desc.Format = Format;
|
||||
|
||||
// TODO: missing options
|
||||
desc.SampleDesc = .(1, 0);
|
||||
desc.Usage = .Immutable;
|
||||
desc.BindFlags = .ShaderResource;
|
||||
desc.CpuAccessFlags = .None;
|
||||
desc.MiscFlags = .None;
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static implicit operator NativeTex2DDesc(Self desc) => desc.ToNative();
|
||||
}
|
||||
|
||||
extension Texture2D
|
||||
{
|
||||
internal ID3D11Texture2D* nativeTexture ~ _?.Release();
|
||||
internal Texture2DDescription nativeDesc;
|
||||
protected internal ID3D11Texture2D* nativeTexture ~ _?.Release();
|
||||
protected internal NativeTex2DDesc nativeDesc;
|
||||
|
||||
public override uint32 Width => nativeDesc.Width;
|
||||
public override uint32 Height => nativeDesc.Height;
|
||||
@@ -48,5 +75,22 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
nativeTexture.GetDescription(out nativeDesc);
|
||||
}
|
||||
|
||||
protected override void CreateTexturePlatform(Texture2DDesc desc, void* data, uint32 linePitch)
|
||||
{
|
||||
nativeTexture?.Release();
|
||||
nativeView?.Release();
|
||||
|
||||
nativeDesc = desc;
|
||||
SubresourceData resData = .(data, linePitch, 0);
|
||||
|
||||
var result = _context.[Friend]nativeDevice.CreateTexture2D(ref nativeDesc, &resData, &nativeTexture);
|
||||
|
||||
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture 2D. Error ({result.Underlying}): {result}");
|
||||
|
||||
result = _context.[Friend]nativeDevice.CreateShaderResourceView(nativeTexture, null, &nativeView);
|
||||
|
||||
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture view. Error ({result.Underlying}): {result}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,15 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
public struct Texture2DDesc
|
||||
{
|
||||
public uint32 Width;
|
||||
public uint32 Height;
|
||||
public uint32 ArraySize;
|
||||
public uint32 MipLevels;
|
||||
public Format Format;
|
||||
}
|
||||
|
||||
public class Texture2D : Texture
|
||||
{
|
||||
protected String _path ~ delete _;
|
||||
@@ -55,6 +64,8 @@ namespace GlitchyEngine.Renderer
|
||||
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)
|
||||
{
|
||||
@@ -63,5 +74,7 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
|
||||
protected extern void LoadTexturePlatform();
|
||||
|
||||
protected extern void CreateTexturePlatform(Texture2DDesc desc, void* data, uint32 linePitch);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user