mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Added DirectXTK to GlitchyEngineHelper
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
FileVersion = 1
|
||||
Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", DirectXTK = "*", FreeType = "*", cgltf-beef = "*", msdfgen-beef = "*", ImGui = "*", ImGuiImplDX11 = "*", ImGuiImplWin32 = "*", ImGuizmo = "*", Beefy2D = "*", LodePng = "*", GlitchyEngineHelper = "*", bon = "*"}
|
||||
Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", FreeType = "*", cgltf-beef = "*", msdfgen-beef = "*", ImGui = "*", ImGuiImplDX11 = "*", ImGuiImplWin32 = "*", ImGuizmo = "*", Beefy2D = "*", LodePng = "*", GlitchyEngineHelper = "*", bon = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "GlitchyEngine"
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#if GE_GRAPHICS_DX11
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using DirectX.D3D11;
|
||||
using DirectX.Common;
|
||||
using DirectXTK;
|
||||
using GlitchyEngine.Math;
|
||||
using GlitchyEngine.Platform.DX11;
|
||||
using System.Collections;
|
||||
|
||||
using internal GlitchyEngine.Renderer;
|
||||
|
||||
typealias NativeTex2DDesc = DirectX.D3D11.Texture2DDescription;
|
||||
|
||||
using GlitchyEngine.Platform.DX11;
|
||||
using internal GlitchyEngine.Platform.DX11;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
internal typealias NativeTex2DDesc = DirectX.D3D11.Texture2DDescription;
|
||||
|
||||
extension Texture
|
||||
{
|
||||
protected internal ID3D11ShaderResourceView* nativeResourceView ~ _?.Release();
|
||||
@@ -25,19 +25,28 @@ namespace GlitchyEngine.Renderer
|
||||
* @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
|
||||
protected bool LoadDdsResourcePlatform<T>(Stream stream, ref T* texture) where T : ID3D11Resource
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
uint8[] ddsData = new:ScopedAlloc! uint8[stream.Length];
|
||||
|
||||
var result = stream.TryRead(ddsData);
|
||||
|
||||
if (result case .Err(let err))
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to read texture data from stream. Error: {err}");
|
||||
}
|
||||
|
||||
((ID3D11Resource*)texture)?.Release();
|
||||
nativeResourceView?.Release();
|
||||
|
||||
HResult loadResult = DDSTextureLoader.CreateDDSTextureFromFile(NativeDevice, path.ToScopedNativeWChar!(),
|
||||
(.)&texture, &nativeResourceView);
|
||||
HResult loadResult = DDSTextureLoader.CreateDDSTextureFromMemory(NativeDevice,
|
||||
ddsData.Ptr, (uint)ddsData.Count, (.)&texture, &nativeResourceView);
|
||||
|
||||
if(loadResult.Failed)
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to load texture \"{path}\". Error({(int)loadResult}): {loadResult}");
|
||||
Log.EngineLogger.Error($"Failed to load texture. Error({(int)loadResult}): {loadResult}");
|
||||
|
||||
ReleaseAndNullify!(texture);
|
||||
ReleaseAndNullify!(nativeResourceView);
|
||||
@@ -85,11 +94,11 @@ namespace GlitchyEngine.Renderer
|
||||
public override uint32 ArraySize => nativeDesc.ArraySize;
|
||||
public override uint32 MipLevels => nativeDesc.MipLevels;
|
||||
|
||||
protected override void LoadTexturePlatform()
|
||||
protected override void LoadDdsPlatform(Stream stream)
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
LoadResourcePlatform(_path, ref nativeTexture);
|
||||
LoadDdsResourcePlatform(stream, ref nativeTexture);
|
||||
|
||||
let resType = nativeTexture.GetResourceType();
|
||||
Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a 2D texture (it is {resType}).");
|
||||
@@ -259,11 +268,11 @@ namespace GlitchyEngine.Renderer
|
||||
public override uint32 ArraySize => nativeDesc.ArraySize / 6;
|
||||
public override uint32 MipLevels => nativeDesc.MipLevels;
|
||||
|
||||
protected override void LoadTexturePlatform()
|
||||
protected override void LoadTexturePlatform(Stream stream)
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
LoadResourcePlatform(_path, ref nativeTexture);
|
||||
|
||||
LoadDdsResourcePlatform(stream, ref nativeTexture);
|
||||
|
||||
let resType = nativeTexture.GetResourceType();
|
||||
Log.EngineLogger.Assert(resType == .Texture2D, scope $"The texture \"{_path}\" is not a texture cube (it is {resType}).");
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
else if (strView.StartsWith(DdsMagicWord))
|
||||
{
|
||||
LoadTexturePlatform();
|
||||
LoadDds(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -137,6 +137,11 @@ namespace GlitchyEngine.Renderer
|
||||
LodePng.LodePng.Free(rawData);
|
||||
}
|
||||
|
||||
protected void LoadDds(Stream stream)
|
||||
{
|
||||
LoadDdsPlatform(stream);
|
||||
}
|
||||
|
||||
public this(Texture2DDesc desc)
|
||||
{
|
||||
PrepareTexturePlatform(desc, false);
|
||||
@@ -157,7 +162,7 @@ namespace GlitchyEngine.Renderer
|
||||
uint32 mipLevels = 1, uint32 arraySize = 1, Usage usage = .Default, CPUAccessFlags cpuAccess = .None
|
||||
*/
|
||||
|
||||
protected extern void LoadTexturePlatform();
|
||||
protected extern void LoadDdsPlatform(Stream stream);
|
||||
|
||||
protected extern void CreateTexturePlatform(Texture2DDesc desc, bool isRenderTarget, void* data, uint32 linePitch);
|
||||
|
||||
@@ -195,9 +200,19 @@ namespace GlitchyEngine.Renderer
|
||||
public this(String path)
|
||||
{
|
||||
this._path = new String(path);
|
||||
LoadTexturePlatform();
|
||||
LoadTexture();
|
||||
}
|
||||
|
||||
private void LoadTexture()
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
Stream data = Application.Get().ContentManager.GetFile(_path);
|
||||
defer delete data;
|
||||
|
||||
LoadTexturePlatform(data);
|
||||
}
|
||||
|
||||
protected extern void LoadTexturePlatform();
|
||||
protected extern void LoadTexturePlatform(Stream stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace GlitchyEngine.World
|
||||
|
||||
Entity entity2 = CreateEntity("Red Square");
|
||||
var v = entity2.AddComponent<SpriterRendererComponent>(.(ColorRGBA(0.95f, 0.1f, 0.3f)));
|
||||
v.Sprite = new Texture2D("Textures/rocket.png");
|
||||
v.Sprite = new Texture2D("Textures/rocket.dds");
|
||||
v.Sprite.SamplerState = SamplerStateManager.PointClamp;
|
||||
|
||||
_onComponentAddedHandlers.Add(typeof(CameraComponent), (e, t, c) => {
|
||||
|
||||
Reference in New Issue
Block a user