mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21: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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user