mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
More asset handles
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
FileVersion = 1
|
||||
Projects = {Sandbox = {Path = "Sandbox"}, GlitchyEngine = {Path = "GlitchyEngine"}, GlitchLog = {Path = "GlitchLog"}, DirectX = {Path = "GlitchyEngine/vendor/directx/DirectX"}, LodePng = {Path = "vendor/lodepng-beef/lodepng-beef"}, FreeType = {Path = "GlitchyEngine/vendor/freetype"}, cgltf-beef = {Path = "GlitchyEngine/vendor/gltf/cgltf-beef"}, GlitchyEditor = {Path = "GlitchyEditor"}, msdfgen-beef = {Path = "GlitchyEngine/vendor/msdfgen/msdfgen-beef"}, ImGui = {Path = "GlitchyEngine/vendor/imgui/ImGui"}, ImGuiImplDX11 = {Path = "GlitchyEngine/vendor/imgui/ImGuiImplDX11"}, ImGuiImplWin32 = {Path = "GlitchyEngine/vendor/imgui/ImGuiImplWin32"}, ImGuizmo = {Path = "GlitchyEngine/vendor/imgui/ImGuizmo"}, GlitchyEngineHelper = {Path = "GlitchyEngineHelper"}, bon = {Path = "GlitchyEngine/vendor/bon"}, box2d-beef = {Path = "GlitchyEngine/vendor/box2D"}, "Beef.Linq" = {Path = "GlitchyEngine/vendor/Beef.Linq/src"}}
|
||||
Unlocked = ["corlib"]
|
||||
WorkspaceFolders = {GlitchyEngine = ["GlitchyEngine", "GlitchLog", "GlitchyEngineHelper"], "GlitchyEngine/Dependencies" = ["cgltf-beef", "DirectX", "FreeType", "ImGui", "ImGuiImplDX11", "ImGuiImplWin32", "ImGuizmo", "LodePng", "msdfgen-beef", "bon", "box2d-beef", "Beef.Linq"]}
|
||||
|
||||
[Workspace]
|
||||
|
||||
@@ -29,7 +29,7 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
|
||||
|
||||
mixin DropAssetTarget<T>() where T : Asset
|
||||
{
|
||||
Asset asset = null;
|
||||
AssetHandle handle = .Invalid;
|
||||
|
||||
if (ImGui.BeginDragDropTarget())
|
||||
{
|
||||
@@ -39,13 +39,13 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
|
||||
{
|
||||
StringView fullpath = .((char8*)payload.Data, (int)payload.DataSize);
|
||||
|
||||
asset = Content.LoadAsset<Asset>(fullpath);
|
||||
handle = Content.LoadAsset(fullpath);
|
||||
}
|
||||
|
||||
ImGui.EndDragDropTarget();
|
||||
}
|
||||
|
||||
asset
|
||||
handle
|
||||
}
|
||||
|
||||
public this(AssetFile asset) : base(asset)
|
||||
@@ -84,11 +84,11 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
|
||||
{
|
||||
StringView path = .((char8*)payload.Data, (int)payload.DataSize);
|
||||
|
||||
using (Texture2D newTexture = Content.LoadAsset<Texture2D>(path))//new Texture2D(path, true))
|
||||
{
|
||||
newTexture.SamplerState = SamplerStateManager.AnisotropicWrap;
|
||||
material.SetTexture(texture.key, newTexture);
|
||||
}
|
||||
AssetHandle<Texture2D> newTexture = Content.LoadAsset(path);//new Texture2D(path, true))
|
||||
|
||||
newTexture.Get().SamplerState = SamplerStateManager.AnisotropicWrap;
|
||||
//material.SetTexture(texture.key, newTexture);
|
||||
// TODO!!!
|
||||
}
|
||||
|
||||
ImGui.EndDragDropTarget();
|
||||
|
||||
@@ -268,10 +268,7 @@ namespace GlitchyEditor.EditWindows
|
||||
|
||||
StringView path = .((char8*)payload.Data, (int)payload.DataSize);
|
||||
|
||||
using (Texture2D texture = Content.LoadAsset<Texture2D>(path))
|
||||
{
|
||||
spriteRendererComponent.Sprite = texture;
|
||||
}
|
||||
spriteRendererComponent.Sprite = Content.LoadAsset(path);
|
||||
}
|
||||
|
||||
ImGui.EndDragDropTarget();
|
||||
@@ -301,10 +298,7 @@ namespace GlitchyEditor.EditWindows
|
||||
{
|
||||
StringView fullpath = .((char8*)payload.Data, (int)payload.DataSize);
|
||||
|
||||
using (Material loadedMaterial = Content.LoadAsset<Material>(fullpath))
|
||||
{
|
||||
meshRendererComponent.Material = loadedMaterial;
|
||||
}
|
||||
meshRendererComponent.Material = Content.LoadAsset(fullpath);
|
||||
}
|
||||
|
||||
ImGui.EndDragDropTarget();
|
||||
@@ -488,10 +482,7 @@ namespace GlitchyEditor.EditWindows
|
||||
StringView filePath = fullpath.Substring(0, idx);
|
||||
StringView meshName = fullpath.Substring(idx + 1);*/
|
||||
|
||||
using (GeometryBinding geometry = Content.LoadAsset<GeometryBinding>(fullpath))
|
||||
{
|
||||
meshComponent.Mesh = geometry;
|
||||
}
|
||||
meshComponent.Mesh = Content.LoadAsset(fullpath);
|
||||
|
||||
// TODO: support multiple primitives (treat every primitive as a single mesh? or: mesh can have multiple primitives)
|
||||
/*using (GeometryBinding binding = ModelLoader.LoadMesh(filePath, meshName, 0))
|
||||
|
||||
@@ -18,7 +18,8 @@ class PropertiesWindow : EditorWindow
|
||||
|
||||
private append String _selectedFileName = .();
|
||||
|
||||
private Asset _currentAsset ~ _?.ReleaseRef();
|
||||
private AssetHandle _currentAssetHandle;
|
||||
private Asset _currentAsset;
|
||||
|
||||
public this(Editor editor)
|
||||
{
|
||||
@@ -78,7 +79,8 @@ class PropertiesWindow : EditorWindow
|
||||
if (_currentAsset?.Identifier != assetFile.Identifier)
|
||||
{
|
||||
_currentAsset?.ReleaseRef();
|
||||
_currentAsset = _editor.ContentManager.LoadAsset(assetFile.Identifier);
|
||||
_currentAssetHandle = _editor.ContentManager.LoadAsset(assetFile.Identifier);
|
||||
_currentAsset = _editor.ContentManager.GetAsset(null, _currentAssetHandle);
|
||||
}
|
||||
|
||||
// TODO: allow changing AssetLoader
|
||||
|
||||
@@ -2,12 +2,13 @@ using System;
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Math;
|
||||
using GlitchyEngine;
|
||||
using GlitchyEngine.Content;
|
||||
|
||||
namespace GlitchyEditor
|
||||
{
|
||||
class EditorIcons : RefCounted
|
||||
{
|
||||
Texture2D _texture ~ _.ReleaseRef();
|
||||
AssetHandle<Texture2D> _texture;
|
||||
|
||||
public SubTexture2D DirectionalLight ~ _.ReleaseRef();
|
||||
public SubTexture2D Camera ~ _.ReleaseRef();
|
||||
@@ -18,13 +19,13 @@ namespace GlitchyEditor
|
||||
|
||||
public SamplerState SamplerState
|
||||
{
|
||||
get => _texture.SamplerState;
|
||||
set => _texture.SamplerState = value;
|
||||
get => _texture.Get().SamplerState;
|
||||
set => _texture.Get().SamplerState = value;
|
||||
}
|
||||
|
||||
public this(String texturePath, Vector2 iconSize)
|
||||
{
|
||||
_texture = Content.LoadAsset<Texture2D>(texturePath);//new Texture2D(texturePath);
|
||||
_texture = Content.LoadAsset(texturePath);//new Texture2D(texturePath);
|
||||
|
||||
Vector2 pen = .();
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ struct AssetHandle<T> where T : Asset
|
||||
private T _asset;
|
||||
private uint8 _currentFrame;
|
||||
|
||||
public const Self Invalid = .();
|
||||
|
||||
public this(AssetHandle handle, IContentManager contentManager = null)
|
||||
{
|
||||
_handle = handle;
|
||||
@@ -42,6 +44,30 @@ struct AssetHandle<T> where T : Asset
|
||||
_currentFrame = (uint8)Application.Get().GameTime.FrameCount;
|
||||
}
|
||||
|
||||
// Creates a new invalid asset handle
|
||||
private this()
|
||||
{
|
||||
_handle = .Invalid;
|
||||
_currentFrame = 0;
|
||||
_contentManager = null;
|
||||
_asset = null;
|
||||
}
|
||||
|
||||
public static implicit operator Self(AssetHandle handle)
|
||||
{
|
||||
return Self(handle);
|
||||
}
|
||||
|
||||
public static implicit operator AssetHandle(Self handle)
|
||||
{
|
||||
return handle._handle;
|
||||
}
|
||||
|
||||
public static implicit operator T(ref Self handle)
|
||||
{
|
||||
return handle.Get();
|
||||
}
|
||||
|
||||
public T Get(IContentManager contentManager = null) mut
|
||||
{
|
||||
// We only care whether we are in a different frame -> we only compare the lower 8 bits.
|
||||
@@ -58,7 +84,7 @@ struct AssetHandle<T> where T : Asset
|
||||
[Comptime, OnCompile(.TypeInit)]
|
||||
static void Init()
|
||||
{
|
||||
for (var field in typeof(T).GetFields())
|
||||
for (var field in typeof(T).GetFields(BindingFlags.FlattenHierarchy))
|
||||
{
|
||||
if (field.IsStatic || !field.IsPublic)
|
||||
continue;
|
||||
@@ -86,7 +112,7 @@ struct AssetHandle<T> where T : Asset
|
||||
|
||||
Dictionary<StringView, (MethodInfo? Getter, MethodInfo? Setter)> properties = scope .();
|
||||
|
||||
for (var method in typeof(T).GetMethods())
|
||||
for (var method in typeof(T).GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Public))
|
||||
{
|
||||
if (method.IsStatic || !method.IsPublic || method.IsConstructor || method.IsDestructor)
|
||||
continue;
|
||||
@@ -137,8 +163,8 @@ struct AssetHandle<T> where T : Asset
|
||||
{
|
||||
Type paramType = method.GetParamType(param);
|
||||
StringView paramName = method.GetParamName(param);
|
||||
//String buffer = scope .();
|
||||
//method.GetParamsDecl(buffer);
|
||||
/*String buffer = scope .();
|
||||
method.GetParamsDecl(buffer);*/
|
||||
|
||||
if (param != 0)
|
||||
{
|
||||
@@ -151,7 +177,7 @@ struct AssetHandle<T> where T : Asset
|
||||
|
||||
/*if (!buffer.IsEmpty)
|
||||
{
|
||||
parameters.AppendF($" = {buffer}");
|
||||
parameters.AppendF($"/*{buffer}*/");
|
||||
}*/
|
||||
|
||||
arguments.AppendF($" {paramName}");
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using GlitchyEngine.World;
|
||||
using GlitchyEngine.Content;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
public struct MeshComponent : IDisposableComponent
|
||||
public struct MeshComponent// : IDisposableComponent
|
||||
{
|
||||
public AssetHandle<GeometryBinding> Mesh {get; set mut;}
|
||||
/*
|
||||
private GeometryBinding _mesh;
|
||||
public GeometryBinding Mesh
|
||||
public AssetHandle<GeometryBinding> Mesh
|
||||
{
|
||||
[Inline]
|
||||
get => _mesh;
|
||||
@@ -22,6 +25,6 @@ namespace GlitchyEngine.Renderer
|
||||
public void Dispose() mut
|
||||
{
|
||||
ReleaseRefAndNullify!(_mesh);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,13 +80,13 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
static SceneConstants _sceneConstants;
|
||||
|
||||
static Effect LineEffect;
|
||||
static AssetHandle<Effect> LineEffect;
|
||||
static VertexBuffer LineVertices;
|
||||
static GeometryBinding LineGeometry;
|
||||
|
||||
static GBuffer _gBuffer;
|
||||
static Effect TestFullscreenEffect;
|
||||
static Effect s_tonemappingEffect;
|
||||
static AssetHandle<Effect> TestFullscreenEffect;
|
||||
static AssetHandle<Effect> s_tonemappingEffect;
|
||||
|
||||
static BlendState _gBufferBlend;
|
||||
static BlendState _lightBlend;
|
||||
@@ -133,7 +133,7 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
LineEffect = Content.LoadAsset<Effect>("Shaders\\lineShader.hlsl");
|
||||
LineEffect = Content.LoadAsset("Shaders\\lineShader.hlsl");
|
||||
|
||||
LineGeometry = new GeometryBinding();
|
||||
LineGeometry.SetPrimitiveTopology(.LineList);
|
||||
@@ -159,13 +159,12 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
LineVertices.ReleaseRef();
|
||||
LineGeometry.ReleaseRef();
|
||||
LineEffect.ReleaseRef();
|
||||
}
|
||||
|
||||
static void InitDeferredRenderer()
|
||||
{
|
||||
TestFullscreenEffect = Content.LoadAsset<Effect>("Shaders\\simpleLight.hlsl");
|
||||
s_tonemappingEffect = Content.LoadAsset<Effect>("Shaders\\SimpleTonemapping.hlsl");
|
||||
TestFullscreenEffect = Content.LoadAsset("Shaders\\simpleLight.hlsl");
|
||||
s_tonemappingEffect = Content.LoadAsset("Shaders\\SimpleTonemapping.hlsl");
|
||||
|
||||
_gBuffer = new GBuffer();
|
||||
BlendStateDescription gBufferBlendDesc = .Default;
|
||||
@@ -204,9 +203,6 @@ namespace GlitchyEngine.Renderer
|
||||
_lightBlend.ReleaseRef();
|
||||
_gBufferBlend.ReleaseRef();
|
||||
delete _gBuffer;
|
||||
|
||||
s_tonemappingEffect.ReleaseRef();
|
||||
TestFullscreenEffect.ReleaseRef();
|
||||
}
|
||||
|
||||
// [Obsolete("", false)]
|
||||
@@ -347,22 +343,23 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
Vector3 lightDir = -light.Transform.Forward;
|
||||
|
||||
TestFullscreenEffect.SetTexture("GBuffer_Albedo", _gBuffer.Target, 0);
|
||||
TestFullscreenEffect.SetTexture("GBuffer_Normal", _gBuffer.Target, 1);
|
||||
TestFullscreenEffect.SetTexture("GBuffer_Tangent", _gBuffer.Target, 2);
|
||||
TestFullscreenEffect.SetTexture("GBuffer_Position", _gBuffer.Target, 3);
|
||||
TestFullscreenEffect.SetTexture("GBuffer_Material", _gBuffer.Target, 4);
|
||||
Effect fsEffect = TestFullscreenEffect.Get();
|
||||
fsEffect.SetTexture("GBuffer_Albedo", _gBuffer.Target, 0);
|
||||
fsEffect.SetTexture("GBuffer_Normal", _gBuffer.Target, 1);
|
||||
fsEffect.SetTexture("GBuffer_Tangent", _gBuffer.Target, 2);
|
||||
fsEffect.SetTexture("GBuffer_Position", _gBuffer.Target, 3);
|
||||
fsEffect.SetTexture("GBuffer_Material", _gBuffer.Target, 4);
|
||||
|
||||
TestFullscreenEffect.Variables["LightColor"].SetData(light.Light.Color);
|
||||
TestFullscreenEffect.Variables["Illuminance"].SetData(light.Light.Illuminance);
|
||||
TestFullscreenEffect.Variables["LightDir"].SetData(lightDir);
|
||||
fsEffect.Variables["LightColor"].SetData(light.Light.Color);
|
||||
fsEffect.Variables["Illuminance"].SetData(light.Light.Illuminance);
|
||||
fsEffect.Variables["LightDir"].SetData(lightDir);
|
||||
|
||||
TestFullscreenEffect.Variables["CameraPos"].SetData(_sceneConstants.CameraPosition);
|
||||
fsEffect.Variables["CameraPos"].SetData(_sceneConstants.CameraPosition);
|
||||
|
||||
TestFullscreenEffect.Variables["Scaling"].SetData(scaling);
|
||||
fsEffect.Variables["Scaling"].SetData(scaling);
|
||||
|
||||
TestFullscreenEffect.ApplyChanges();
|
||||
TestFullscreenEffect.Bind();
|
||||
fsEffect.ApplyChanges();
|
||||
fsEffect.Bind();
|
||||
|
||||
//RenderCommand.BindEffect(TestFullscreenEffect);
|
||||
|
||||
@@ -379,11 +376,12 @@ namespace GlitchyEngine.Renderer
|
||||
RenderCommand.UnbindRenderTargets();
|
||||
RenderCommand.BindRenderTargets();
|
||||
RenderCommand.SetRenderTargetGroup(_sceneConstants.CompositionTarget, true);
|
||||
|
||||
|
||||
Effect toneMappingFx = s_tonemappingEffect.Get();
|
||||
// TODO: Postprocessing effects
|
||||
s_tonemappingEffect.SetTexture("CameraTarget", _sceneConstants.CameraTarget, 0);
|
||||
s_tonemappingEffect.ApplyChanges();
|
||||
s_tonemappingEffect.Bind();
|
||||
toneMappingFx.SetTexture("CameraTarget", _sceneConstants.CameraTarget, 0);
|
||||
toneMappingFx.ApplyChanges();
|
||||
toneMappingFx.Bind();
|
||||
|
||||
RenderCommand.BindRenderTargets();
|
||||
//RenderCommand.BindEffect(s_tonemappingEffect);
|
||||
|
||||
@@ -3,6 +3,7 @@ using GlitchyEngine.Math;
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Core;
|
||||
using Box2D;
|
||||
using GlitchyEngine.Content;
|
||||
|
||||
namespace GlitchyEngine.World
|
||||
{
|
||||
@@ -44,19 +45,19 @@ namespace GlitchyEngine.World
|
||||
}
|
||||
|
||||
[Component("Sprite Renderer")]
|
||||
struct SpriterRendererComponent : IDisposableComponent
|
||||
struct SpriterRendererComponent// : IDisposableComponent
|
||||
{
|
||||
private Texture2D _sprite = null;
|
||||
private AssetHandle<Texture2D> _sprite = .Invalid;
|
||||
|
||||
public Texture2D Sprite
|
||||
public AssetHandle<Texture2D> Sprite
|
||||
{
|
||||
get => _sprite;
|
||||
set mut
|
||||
{
|
||||
if (_sprite == value)
|
||||
return;
|
||||
|
||||
SetReference!(_sprite, value);
|
||||
_sprite = value;
|
||||
//SetReference!(_sprite, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +75,10 @@ namespace GlitchyEngine.World
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
/*public void Dispose()
|
||||
{
|
||||
_sprite?.ReleaseRef();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
struct SceneCamera : Camera
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
using GlitchyEngine.Renderer;
|
||||
using System;
|
||||
using GlitchyEngine.Content;
|
||||
|
||||
namespace GlitchyEngine.World
|
||||
{
|
||||
/// A component that allows to render a mesh.
|
||||
public struct MeshRendererComponent : IDisposableComponent
|
||||
public struct MeshRendererComponent// : IDisposableComponent
|
||||
{
|
||||
private Material _material;
|
||||
private AssetHandle<Material> _material;
|
||||
|
||||
public Material Material
|
||||
public AssetHandle<Material> Material
|
||||
{
|
||||
[Inline]
|
||||
get => _material;
|
||||
@@ -17,15 +18,13 @@ namespace GlitchyEngine.World
|
||||
if(_material == value)
|
||||
return;
|
||||
|
||||
_material?.ReleaseRef();
|
||||
_material = value;
|
||||
_material?.AddRef();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() mut
|
||||
/*public void Dispose() mut
|
||||
{
|
||||
_material?.ReleaseRef();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace GlitchyEngine.World
|
||||
{
|
||||
Serialize.Value(writer, "Color", component.Color);
|
||||
Serialize.Value(writer, "IsCircle", component.IsCircle);
|
||||
Serialize.Value(writer, "Sprite", component.Sprite?.Identifier);
|
||||
Serialize.Value(writer, "Sprite", component.Sprite.Get().Identifier);
|
||||
Serialize.Value(writer, "UvTransform", component.UvTransform);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user