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:
@@ -63,13 +63,14 @@ class ShaderLoader : IProcessedAssetLoader
|
||||
if (vertexShaderBindPoint != -1 && vertexShader != null)
|
||||
{
|
||||
vertexShader.Textures.Add(textureName, (.)vertexShaderBindPoint, entry.BoundTexture, dimension);
|
||||
entry.VsSlot = vertexShader.Textures[textureName];
|
||||
entry.VsSlot = &vertexShader.Textures[textureName];
|
||||
}
|
||||
|
||||
// TODO: Why is nullcheck different for vertex and pixel shader?
|
||||
if (pixelShaderBindPoint != -1)
|
||||
{
|
||||
pixelShader?.Textures.Add(textureName, (.)pixelShaderBindPoint, entry.BoundTexture, dimension);
|
||||
entry.PsSlot = pixelShader.Textures[textureName];
|
||||
entry.PsSlot = &pixelShader.Textures[textureName];
|
||||
}
|
||||
|
||||
effect.Textures[textureName] = entry;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace ImGui
|
||||
|
||||
ImGui.Image(view, size, uv0, uv1, tint_col, border_col);
|
||||
|
||||
textureViewBinding.Release();
|
||||
textureViewBinding.ReleaseRef();
|
||||
}
|
||||
|
||||
public static override bool ImageButton(char8* id, TextureViewBinding textureViewBinding, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones)
|
||||
@@ -29,7 +29,7 @@ namespace ImGui
|
||||
|
||||
bool pressed = ImGui.ImageButton(id, view, imageSize, uv0, uv1, bg_col, tint_col);
|
||||
|
||||
textureViewBinding.Release();
|
||||
textureViewBinding.ReleaseRef();
|
||||
|
||||
return pressed;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace ImGui
|
||||
|
||||
bool pressed = ImGui.ImageButtonEx(id, view, imageSize, uv0, uv1, bg_col, tint_col);
|
||||
|
||||
textureViewBinding.Release();
|
||||
textureViewBinding.ReleaseRef();
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
protected override TextureViewBinding PlatformGetViewBinding()
|
||||
{
|
||||
return .(_nativeResourceView, _samplerState.nativeSamplerState);
|
||||
return new .(_nativeResourceView, _samplerState.nativeSamplerState);
|
||||
}
|
||||
|
||||
protected override void PlatformSneakySwappyTexture(RenderTarget2D otherTexture)
|
||||
@@ -448,13 +448,13 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
if (index == -1)
|
||||
{
|
||||
return .(_nativeDepthResourceView, _depthSamplerState.nativeSamplerState);
|
||||
return new .(_nativeDepthResourceView, _depthSamplerState.nativeSamplerState);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.AssertDebug(index < _nativeResourceViews.Count);
|
||||
|
||||
return .(_nativeResourceViews[index], _colorSamplerStates[index].nativeSamplerState);
|
||||
return new .(_nativeResourceViews[index], _colorSamplerStates[index].nativeSamplerState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,10 +92,12 @@ namespace GlitchyEngine.Renderer
|
||||
using (BlendState lastBlendState = _currentBlendState..AddRef())
|
||||
{
|
||||
SetBlendState(_nonblendingState);
|
||||
|
||||
_clearUintFx.Variables["ClearValue"].SetData(value);
|
||||
_clearUintFx.ApplyChanges();
|
||||
_clearUintFx.Bind();
|
||||
|
||||
var v = _clearUintFx.Get();
|
||||
|
||||
v.Variables["ClearValue"].SetData(value);
|
||||
v.ApplyChanges();
|
||||
v.Bind();
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
protected override TextureViewBinding PlatformGetViewBinding()
|
||||
{
|
||||
return .(_nativeResourceView, _samplerState?.nativeSamplerState);
|
||||
return new .(_nativeResourceView, _samplerState?.nativeSamplerState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
protected override TextureViewBinding PlatformGetViewBinding()
|
||||
{
|
||||
return .(_nativeResourceView, _samplerState?.nativeSamplerState);
|
||||
return new .(_nativeResourceView, _samplerState?.nativeSamplerState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,24 +12,18 @@ namespace GlitchyEngine.Renderer
|
||||
internal this(ID3D11ShaderResourceView* shaderResourceView, ID3D11SamplerState* samplerState)
|
||||
{
|
||||
_nativeShaderResourceView = shaderResourceView;
|
||||
|
||||
if ((uint)(void*)_nativeShaderResourceView != 0 && (uint)(void*)_nativeShaderResourceView < 200)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
_nativeShaderResourceView?.AddRef();
|
||||
|
||||
_nativeSamplerState = samplerState;
|
||||
_nativeSamplerState?.AddRef();
|
||||
}
|
||||
|
||||
public override void AddRef()
|
||||
{
|
||||
_nativeShaderResourceView?.AddRef();
|
||||
_nativeSamplerState?.AddRef();
|
||||
}
|
||||
|
||||
public override void Release()
|
||||
{
|
||||
_nativeShaderResourceView?.Release();
|
||||
_nativeSamplerState?.Release();
|
||||
}
|
||||
|
||||
public static override TextureViewBinding CreateDefault() => .(null, null);
|
||||
public static override TextureViewBinding CreateDefault() => new .(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,12 +152,15 @@ class SceneRenderer
|
||||
|
||||
Effect gammaEffect = Content.GetAsset<Effect>(_gammaCorrectEffect);
|
||||
|
||||
gammaEffect.SetTexture("Texture", _compositeTarget, 0);
|
||||
// TODO: iiihhh
|
||||
gammaEffect.ApplyChanges();
|
||||
gammaEffect.Bind();
|
||||
if (gammaEffect != null)
|
||||
{
|
||||
gammaEffect.SetTexture("Texture", _compositeTarget, 0);
|
||||
// TODO: iiihhh
|
||||
gammaEffect.ApplyChanges();
|
||||
gammaEffect.Bind();
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
FullscreenQuad.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
finalTarget.ReleaseRef();
|
||||
@@ -249,12 +252,15 @@ class SceneRenderer
|
||||
|
||||
Effect gammaEffect = Content.GetAsset<Effect>(_gammaCorrectEffect);
|
||||
|
||||
gammaEffect.SetTexture("Texture", _compositeTarget, 0);
|
||||
// TODO: iiihhh
|
||||
gammaEffect.ApplyChanges();
|
||||
gammaEffect.Bind();
|
||||
if (gammaEffect != null)
|
||||
{
|
||||
gammaEffect.SetTexture("Texture", _compositeTarget, 0);
|
||||
// TODO: iiihhh
|
||||
gammaEffect.ApplyChanges();
|
||||
gammaEffect.Bind();
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
FullscreenQuad.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
viewportTarget.ReleaseRef();
|
||||
|
||||
Reference in New Issue
Block a user