mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Unified texture loading, updated DirectX-beef
This commit is contained in:
@@ -3,6 +3,7 @@ using DirectX.D3D11;
|
|||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
using DirectXTK;
|
using DirectXTK;
|
||||||
using GlitchyEngine.Math;
|
using GlitchyEngine.Math;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
|
||||||
@@ -19,6 +20,32 @@ namespace GlitchyEngine.Renderer
|
|||||||
_context.nativeContext.VertexShader.SetShaderResources(slot, 1, &nativeView);
|
_context.nativeContext.VertexShader.SetShaderResources(slot, 1, &nativeView);
|
||||||
_context.nativeContext.PixelShader.SetShaderResources(slot, 1, &nativeView);
|
_context.nativeContext.PixelShader.SetShaderResources(slot, 1, &nativeView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** \brief Loads the texture from the specified path.
|
||||||
|
* @param path The path of the texture to load.
|
||||||
|
* @param texture The reference to the pointer that will hold the texture.
|
||||||
|
* @returns true if the texture was loaded successfully; false otherwise.
|
||||||
|
*/
|
||||||
|
protected bool LoadResourcePlatform<T>(StringView path, ref T* texture) where T : ID3D11Resource
|
||||||
|
{
|
||||||
|
((ID3D11Resource*)texture)?.Release();
|
||||||
|
nativeView?.Release();
|
||||||
|
|
||||||
|
HResult loadResult = DDSTextureLoader.CreateDDSTextureFromFile(_context.nativeDevice, path.ToScopedNativeWChar!(),
|
||||||
|
(.)&texture, &nativeView);
|
||||||
|
|
||||||
|
if(loadResult.Failed)
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error($"Failed to load texture \"{path}\". Error({(int)loadResult}): {loadResult}");
|
||||||
|
|
||||||
|
ReleaseAndNullify!(texture);
|
||||||
|
ReleaseAndNullify!(nativeView);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Texture2DDesc
|
extension Texture2DDesc
|
||||||
@@ -58,21 +85,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
protected override void LoadTexturePlatform()
|
protected override void LoadTexturePlatform()
|
||||||
{
|
{
|
||||||
nativeTexture?.Release();
|
LoadResourcePlatform(_path, ref nativeTexture);
|
||||||
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();
|
let resType = nativeTexture.GetResourceType();
|
||||||
Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a 2D texture (it is {resType}).");
|
Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a 2D texture (it is {resType}).");
|
||||||
@@ -239,21 +252,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
protected override void LoadTexturePlatform()
|
protected override void LoadTexturePlatform()
|
||||||
{
|
{
|
||||||
nativeTexture?.Release();
|
LoadResourcePlatform(_path, ref nativeTexture);
|
||||||
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();
|
let resType = nativeTexture.GetResourceType();
|
||||||
Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a texture cube (it is {resType}).");
|
Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a texture cube (it is {resType}).");
|
||||||
|
|||||||
Vendored
+1
-1
Submodule GlitchyEngine/vendor/directx updated: 0399d40bf8...1bc6b78ee4
Reference in New Issue
Block a user