mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Engine barely starts again
This commit is contained in:
@@ -153,10 +153,10 @@ namespace GlitchyEngine.Renderer
|
||||
// UnorderedAccess?
|
||||
}
|
||||
|
||||
public enum BufferMiscFlags
|
||||
public enum BufferMiscFlags : uint8 /* Don't commit, workaround for a beef bug!*/
|
||||
{
|
||||
None = 0,
|
||||
//AllowRawView = 1,
|
||||
// AllowRawView = 1,
|
||||
//Structured = 2,
|
||||
}
|
||||
|
||||
|
||||
@@ -12,26 +12,6 @@ public class Effect : Asset
|
||||
internal VertexShader _vs ~ _?.ReleaseRef();
|
||||
internal PixelShader _ps ~ _?.ReleaseRef();
|
||||
|
||||
typealias VariableDesc = Dictionary<String, Dictionary<String, Variant>>;
|
||||
|
||||
protected VariableDesc _variableDescriptions = new .() ~ {
|
||||
for (var (key, value) in _)
|
||||
{
|
||||
delete key;
|
||||
|
||||
for (var (entryKey, entry) in value)
|
||||
{
|
||||
delete entryKey;
|
||||
entry.Dispose();
|
||||
}
|
||||
|
||||
delete value;
|
||||
}
|
||||
|
||||
delete _;
|
||||
};
|
||||
|
||||
|
||||
BufferCollection _bufferCollection ~ _.ReleaseRef();
|
||||
|
||||
BufferVariableCollection _variables ~ delete _;
|
||||
@@ -84,7 +64,7 @@ public class Effect : Asset
|
||||
|
||||
for(let entry in _textures)
|
||||
{
|
||||
entry.value.BoundTexture.Release();
|
||||
entry.value.BoundTexture.ReleaseRef();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,14 +103,14 @@ public class Effect : Asset
|
||||
ref TextureEntry entry = ref _textures[name];
|
||||
|
||||
// TODO: Thats weird, we increment this reference somewhere... but WHERE?!
|
||||
entry.BoundTexture.Release();
|
||||
entry.BoundTexture.ReleaseRef();
|
||||
entry.BoundTexture = textureViewBinding;
|
||||
|
||||
if (entry.VsSlot != null)
|
||||
SetReferenceVar!(entry.VsSlot.BoundTexture, entry.BoundTexture);
|
||||
SetReference!(VertexShader.Textures[name].BoundTexture, entry.BoundTexture);
|
||||
|
||||
if (entry.PsSlot != null)
|
||||
SetReferenceVar!(entry.PsSlot.BoundTexture, entry.BoundTexture);
|
||||
SetReference!(PixelShader.Textures[name].BoundTexture, entry.BoundTexture);
|
||||
}
|
||||
|
||||
public void ApplyChanges()
|
||||
@@ -158,4 +138,25 @@ public class Effect : Asset
|
||||
RenderCommand.BindVertexShader(_vs);
|
||||
RenderCommand.BindPixelShader(_ps);
|
||||
}
|
||||
|
||||
// Stuff I'm not sure about
|
||||
|
||||
typealias VariableDesc = Dictionary<String, Dictionary<String, Variant>>;
|
||||
|
||||
protected VariableDesc _variableDescriptions = new .() ~ {
|
||||
for (var (key, value) in _)
|
||||
{
|
||||
delete key;
|
||||
|
||||
for (var (entryKey, entry) in value)
|
||||
{
|
||||
delete entryKey;
|
||||
entry.Dispose();
|
||||
}
|
||||
|
||||
delete value;
|
||||
}
|
||||
|
||||
delete _;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -364,9 +364,13 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
Debug.Profiler.ProfileRendererScope!("Draw Light");
|
||||
|
||||
Effect fsEffect = TestFullscreenEffect.Get();
|
||||
|
||||
if (fsEffect == null)
|
||||
continue;
|
||||
|
||||
float3 lightDir = -light.Transform.Forward;
|
||||
|
||||
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);
|
||||
@@ -405,17 +409,19 @@ namespace GlitchyEngine.Renderer
|
||||
RenderCommand.SetRenderTargetGroup(_sceneConstants.CompositionTarget, true);
|
||||
|
||||
Effect toneMappingFx = s_tonemappingEffect.Get();
|
||||
// TODO: Postprocessing effects
|
||||
toneMappingFx.SetTexture("CameraTarget", _sceneConstants.CameraTarget, 0);
|
||||
toneMappingFx.ApplyChanges();
|
||||
toneMappingFx.Bind();
|
||||
|
||||
RenderCommand.BindRenderTargets();
|
||||
//RenderCommand.BindEffect(s_tonemappingEffect);
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
|
||||
RenderCommand.UnbindTextures();
|
||||
if (toneMappingFx != null)
|
||||
{
|
||||
// TODO: Postprocessing effects
|
||||
toneMappingFx.SetTexture("CameraTarget", _sceneConstants.CameraTarget, 0);
|
||||
toneMappingFx.ApplyChanges();
|
||||
toneMappingFx.Bind();
|
||||
|
||||
RenderCommand.BindRenderTargets();
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
|
||||
RenderCommand.UnbindTextures();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Draw lights to camera target
|
||||
|
||||
@@ -522,10 +522,10 @@ namespace GlitchyEngine.Renderer
|
||||
s_currentLineEffect = s_lineBatchEffect;
|
||||
|
||||
Matrix viewProjection = camera.Projection * Matrix.Invert(transform);
|
||||
|
||||
s_currentQuadEffect.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentCircleEffect.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentLineEffect.Variables["ViewProjection"].SetData(viewProjection);
|
||||
|
||||
s_currentQuadEffect.Get()?.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentCircleEffect.Get()?.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentLineEffect.Get()?.Variables["ViewProjection"].SetData(viewProjection);
|
||||
|
||||
s_drawOrder = drawOrder;
|
||||
|
||||
@@ -564,9 +564,9 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
Matrix viewProjection = camera.Projection * camera.View;
|
||||
|
||||
s_currentQuadEffect.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentCircleEffect.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentLineEffect.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentQuadEffect.Get()?.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentCircleEffect.Get()?.Variables["ViewProjection"].SetData(viewProjection);
|
||||
s_currentLineEffect.Get()?.Variables["ViewProjection"].SetData(viewProjection);
|
||||
|
||||
s_drawOrder = drawOrder;
|
||||
|
||||
@@ -778,8 +778,13 @@ namespace GlitchyEngine.Renderer
|
||||
// TODO: per object blendstate
|
||||
RenderCommand.SetBlendState(s_transparentBlendState);
|
||||
|
||||
let quadEffect = s_currentQuadEffect.Get();
|
||||
|
||||
if (quadEffect == null)
|
||||
return;
|
||||
|
||||
Texture texture = s_QuadinstanceQueue[0].Texture;
|
||||
s_currentQuadEffect.SetTexture("Texture", texture);
|
||||
quadEffect.SetTexture("Texture", texture);
|
||||
|
||||
s_setQuadInstances = 0;
|
||||
|
||||
@@ -793,7 +798,7 @@ namespace GlitchyEngine.Renderer
|
||||
FlushQuadInstances();
|
||||
|
||||
texture = quad.Texture;
|
||||
s_currentQuadEffect.SetTexture("Texture", texture);
|
||||
quadEffect.SetTexture("Texture", texture);
|
||||
}
|
||||
|
||||
s_rawQuadInstances[s_setQuadInstances++] = .(quad.Transform, quad.Color, quad.uvTransform, quad.entityId);
|
||||
@@ -818,9 +823,14 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
// TODO: per object blendstate
|
||||
RenderCommand.SetBlendState(s_transparentBlendState);
|
||||
|
||||
let effect = s_currentCircleEffect.Get();
|
||||
|
||||
if (effect == null)
|
||||
return;
|
||||
|
||||
Texture texture = s_circleInstanceQueue[0].Texture;
|
||||
s_currentCircleEffect.SetTexture("Texture", texture);
|
||||
effect.SetTexture("Texture", texture);
|
||||
|
||||
s_setCircleInstances = 0;
|
||||
|
||||
@@ -834,7 +844,7 @@ namespace GlitchyEngine.Renderer
|
||||
FlushCircleInstances();
|
||||
|
||||
texture = circle.Texture;
|
||||
s_currentCircleEffect.SetTexture("Texture", texture);
|
||||
effect.SetTexture("Texture", texture);
|
||||
}
|
||||
|
||||
s_rawCircleInstances[s_setCircleInstances++] = .(circle.Transform, circle.Color, circle.uvTransform, circle.InnerRadius, circle.entityId);
|
||||
@@ -857,6 +867,11 @@ namespace GlitchyEngine.Renderer
|
||||
if(s_lineInstanceQueue.IsEmpty)
|
||||
return;
|
||||
|
||||
let effect = s_currentLineEffect.Get();
|
||||
|
||||
if (effect == null)
|
||||
return;
|
||||
|
||||
// TODO: per object blendstate
|
||||
RenderCommand.SetBlendState(s_transparentBlendState);
|
||||
|
||||
|
||||
@@ -9,14 +9,16 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
List<ResourceEntry> _textures ~ DeleteTextureEntries!(_);
|
||||
|
||||
Dictionary<String, ResourceEntry*> _strToBuf ~ delete _;
|
||||
Dictionary<int, ResourceEntry*> _idxToBuf ~ delete _;
|
||||
/*Dictionary<String, ResourceEntry*> _strToBuf ~ delete _;
|
||||
Dictionary<int, ResourceEntry*> _idxToBuf ~ delete _;*/
|
||||
Dictionary<String, uint32> _strToBuf ~ delete _;
|
||||
Dictionary<int, uint32> _idxToBuf ~ delete _;
|
||||
|
||||
public this()
|
||||
{
|
||||
let textures = new List<ResourceEntry>();
|
||||
let strToBuf = new Dictionary<String, ResourceEntry*>();
|
||||
let idxToBuf = new Dictionary<int, ResourceEntry*>();
|
||||
let strToBuf = new Dictionary<String, uint32>();
|
||||
let idxToBuf = new Dictionary<int, uint32>();
|
||||
|
||||
_textures = textures;
|
||||
_strToBuf = strToBuf;
|
||||
@@ -31,15 +33,15 @@ namespace GlitchyEngine.Renderer
|
||||
for(let entry in entries)
|
||||
{
|
||||
delete entry.Name;
|
||||
entry.BoundTexture.Release();
|
||||
entry.BoundTexture.ReleaseRef();
|
||||
}
|
||||
|
||||
delete entries;
|
||||
}
|
||||
|
||||
// TODO: finish implementation (like BufferCollection)
|
||||
public ResourceEntry* this[int idx] => _idxToBuf[idx];
|
||||
public ResourceEntry* this[String name] => _strToBuf[name];
|
||||
public ref ResourceEntry this[int idx] => ref _textures[_idxToBuf[idx]];
|
||||
public ref ResourceEntry this[String name] => ref _textures[_strToBuf[name]];
|
||||
|
||||
public void Add(String name, uint32 index, TextureViewBinding texture, TextureDimension dimension)
|
||||
{
|
||||
@@ -53,10 +55,8 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
_textures.Add(copy);
|
||||
|
||||
ResourceEntry* copyRef = &_textures.Back;
|
||||
|
||||
_strToBuf.Add(copy.Name, copyRef);
|
||||
_idxToBuf.Add(copy.Index, copyRef);
|
||||
_strToBuf.Add(copy.Name, (uint32)(_textures.Count - 1));
|
||||
_idxToBuf.Add(copy.Index, (uint32)(_textures.Count - 1));
|
||||
}
|
||||
|
||||
public List<ResourceEntry>.Enumerator GetEnumerator()
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
using System;
|
||||
using GlitchyEngine.Core;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
// TODO: I hate this. It is a reference counting struct?!
|
||||
/// Represents a reference to a texture that can be used as shader input resource.
|
||||
public struct TextureViewBinding : IRefCounted, IDisposable
|
||||
public class TextureViewBinding : RefCounter
|
||||
{
|
||||
/// True if the view binding actually has a texture. False otherwise.
|
||||
public extern bool IsEmpty { get; }
|
||||
|
||||
public extern void AddRef();
|
||||
public extern void Release();
|
||||
|
||||
public static extern TextureViewBinding CreateDefault();
|
||||
|
||||
public void Dispose() => Release();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user