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:
@@ -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