mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
RenderAPI changes and removed Context parameter from Effect and Material
This commit is contained in:
@@ -40,7 +40,7 @@ namespace GlitchyEditor
|
||||
|
||||
public this()
|
||||
{
|
||||
_context = Renderer.[Friend]_context..AddRef();
|
||||
_context = Application.Get().Window.Context..AddRef();
|
||||
|
||||
InitEffect();
|
||||
InitState();
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace GlitchyEngine
|
||||
|
||||
_effectLibrary = new EffectLibrary();
|
||||
|
||||
Renderer.Init(_window.Context, _effectLibrary);
|
||||
Renderer.Init(_effectLibrary);
|
||||
|
||||
#if IMGUI
|
||||
_imGuiLayer = new ImGuiLayer();
|
||||
|
||||
@@ -160,8 +160,6 @@ namespace GlitchyEngine
|
||||
|
||||
public static void NewFrame()
|
||||
{
|
||||
Log.EngineLogger.Info($"{Input.GetMousePosition()}");
|
||||
|
||||
if (_lockPositions.Count > 0)
|
||||
{
|
||||
var position = _lockPositions.Back.Position;
|
||||
|
||||
@@ -348,12 +348,12 @@ namespace GlitchyEngine.Renderer
|
||||
NativeContext.VertexShader.SetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, (.)voidArray);
|
||||
}
|
||||
|
||||
public override void SetVertexShader(VertexShader vertexShader)
|
||||
public override void BindVertexShader(VertexShader vertexShader)
|
||||
{
|
||||
BindShaderToStage(vertexShader);
|
||||
}
|
||||
|
||||
public override void SetPixelShader(PixelShader pixelShader)
|
||||
public override void BindPixelShader(PixelShader pixelShader)
|
||||
{
|
||||
BindShaderToStage(pixelShader);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace GlitchyEngine.Renderer
|
||||
SetBlendState(_nonblendingState);
|
||||
|
||||
_clearUintFx.Variables["ClearValue"].SetData(value);
|
||||
_clearUintFx.Bind(_context);
|
||||
_clearUintFx.Bind();
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
|
||||
@@ -254,6 +254,16 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
_context.BindConstantBuffer(buffer, slot, stage);
|
||||
}
|
||||
|
||||
public override void BindVertexShader(VertexShader vertexShader)
|
||||
{
|
||||
_context.BindVertexShader(vertexShader);
|
||||
}
|
||||
|
||||
public override void BindPixelShader(PixelShader pixelShader)
|
||||
{
|
||||
_context.BindPixelShader(pixelShader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,10 +197,7 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
Debug.Profiler.ProfileRendererFunction!();
|
||||
|
||||
ref TextureEntry entry = ref _textures[name];
|
||||
|
||||
entry.BoundTexture.Release();
|
||||
entry.BoundTexture = texture.GetViewBinding();
|
||||
[Inline]InternalSetTexture(name, texture.GetViewBinding());
|
||||
}
|
||||
|
||||
public void SetTexture(String name, RenderTargetGroup renderTargetGroup, int32 firstTarget, uint32 targetCount = 1)
|
||||
@@ -210,24 +207,31 @@ namespace GlitchyEngine.Renderer
|
||||
if (targetCount != 1)
|
||||
Runtime.NotImplemented("Binding multiple rendertargets to a slot is not yet implemented.");
|
||||
|
||||
ref TextureEntry entry = ref _textures[name];
|
||||
|
||||
entry.BoundTexture.Release();
|
||||
//entry.BoundTexture = .RenderTargetGroup(renderTargetGroup..AddRef(), firstTarget, targetCount);
|
||||
entry.BoundTexture = renderTargetGroup.GetViewBinding(firstTarget);
|
||||
// We have to release the viewBinding because GetViewBinding internally increases the counter
|
||||
[Inline]InternalSetTexture(name, renderTargetGroup.GetViewBinding(firstTarget));
|
||||
}
|
||||
|
||||
public void SetTexture(String name, TextureViewBinding textureViewBinding)
|
||||
{
|
||||
Debug.Profiler.ProfileRendererFunction!();
|
||||
|
||||
[Inline]InternalSetTexture(name, textureViewBinding..AddRef());
|
||||
}
|
||||
|
||||
private void InternalSetTexture(String name, TextureViewBinding textureViewBinding)
|
||||
{
|
||||
Debug.Profiler.ProfileRendererFunction!();
|
||||
|
||||
ref TextureEntry entry = ref _textures[name];
|
||||
|
||||
entry.BoundTexture.Release();
|
||||
entry.BoundTexture = textureViewBinding..AddRef();
|
||||
entry.BoundTexture = textureViewBinding;
|
||||
|
||||
entry.VsSlot?.BoundTexture..Release() = entry.BoundTexture..AddRef();
|
||||
entry.PsSlot?.BoundTexture..Release() = entry.BoundTexture..AddRef();
|
||||
}
|
||||
|
||||
private void ApplyTextures()
|
||||
/*private void ApplyTextures()
|
||||
{
|
||||
Debug.Profiler.ProfileRendererFunction!();
|
||||
|
||||
@@ -241,12 +245,14 @@ namespace GlitchyEngine.Renderer
|
||||
entry.PsSlot?.BoundTexture = entry.BoundTexture;
|
||||
entry.PsSlot?.BoundTexture.AddRef();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private void ApplyChanges()
|
||||
public void ApplyChanges()
|
||||
{
|
||||
Debug.Profiler.ProfileRendererFunction!();
|
||||
|
||||
//ApplyTextures();
|
||||
|
||||
for(let buffer in _bufferCollection)
|
||||
{
|
||||
if(let cbuffer = buffer.Buffer as ConstantBuffer)
|
||||
@@ -256,15 +262,15 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(GraphicsContext context)
|
||||
public void Bind()
|
||||
{
|
||||
Debug.Profiler.ProfileRendererFunction!();
|
||||
|
||||
ApplyTextures();
|
||||
ApplyChanges();
|
||||
//ApplyTextures();
|
||||
//ApplyChanges();
|
||||
|
||||
context.SetVertexShader(_vs);
|
||||
context.SetPixelShader(_ps);
|
||||
RenderCommand.BindVertexShader(_vs);
|
||||
RenderCommand.BindPixelShader(_ps);
|
||||
}
|
||||
|
||||
private void CompileFromFile(String filename, String vsEntry, String psEntry)
|
||||
|
||||
@@ -109,9 +109,9 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public extern void SetPrimitiveTopology(PrimitiveTopology primitiveTopology);
|
||||
|
||||
public extern void SetVertexShader(VertexShader vertexShader);
|
||||
public extern void BindVertexShader(VertexShader vertexShader);
|
||||
|
||||
public extern void SetPixelShader(PixelShader pixelShader);
|
||||
public extern void BindPixelShader(PixelShader pixelShader);
|
||||
|
||||
public extern void UnbindTextures();
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace GlitchyEngine.Renderer
|
||||
/**
|
||||
* Binds the materials Shaders and Parameters to the given context.
|
||||
*/
|
||||
public void Bind(GraphicsContext context)
|
||||
public void Bind()
|
||||
{
|
||||
Debug.Profiler.ProfileRendererFunction!();
|
||||
|
||||
@@ -79,7 +79,8 @@ namespace GlitchyEngine.Renderer
|
||||
variable.Variable.SetRawData(RawPointer!<uint8>(variable.Offset));
|
||||
}
|
||||
|
||||
_effect.Bind(context);
|
||||
_effect.ApplyChanges();
|
||||
_effect.Bind();
|
||||
}
|
||||
|
||||
/** @brief Sets a texture of the material.
|
||||
|
||||
@@ -128,5 +128,15 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
_rendererAPI.BindConstantBuffer(buffer, slot, stage);
|
||||
}
|
||||
|
||||
public static void BindVertexShader(VertexShader vertexShader)
|
||||
{
|
||||
_rendererAPI.BindVertexShader(vertexShader);
|
||||
}
|
||||
|
||||
public static void BindPixelShader(PixelShader pixelShader)
|
||||
{
|
||||
_rendererAPI.BindPixelShader(pixelShader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +77,6 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
static internal GraphicsContext _context;
|
||||
|
||||
static SceneConstants _sceneConstants;
|
||||
|
||||
static Effect LineEffect;
|
||||
@@ -106,12 +104,10 @@ namespace GlitchyEngine.Renderer
|
||||
private Vector3 _padding;
|
||||
}
|
||||
|
||||
public static void Init(GraphicsContext context, EffectLibrary effectLibrary)
|
||||
public static void Init(EffectLibrary effectLibrary)
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
_context = context..AddRef();
|
||||
|
||||
RenderCommand.Init();
|
||||
Renderer2D.Init();
|
||||
FullscreenQuad.Init();
|
||||
@@ -130,8 +126,6 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
FullscreenQuad.Deinit();
|
||||
Renderer2D.Deinit();
|
||||
|
||||
_context.ReleaseRef();
|
||||
}
|
||||
|
||||
static void InitLineRenderer(EffectLibrary effectLibrary)
|
||||
@@ -321,7 +315,7 @@ namespace GlitchyEngine.Renderer
|
||||
_objectBuffer.SetData(objectData, 0, .WriteDiscard);
|
||||
}
|
||||
|
||||
entry.Material.Bind(_context);
|
||||
entry.Material.Bind();
|
||||
|
||||
RenderCommand.BindConstantBuffer(_sceneBuffer, 0, .All);
|
||||
RenderCommand.BindConstantBuffer(_objectBuffer, 1, .All);
|
||||
@@ -366,7 +360,10 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
TestFullscreenEffect.Variables["Scaling"].SetData(scaling);
|
||||
|
||||
TestFullscreenEffect.Bind(_context);
|
||||
TestFullscreenEffect.ApplyChanges();
|
||||
TestFullscreenEffect.Bind();
|
||||
|
||||
//RenderCommand.BindEffect(TestFullscreenEffect);
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
}
|
||||
@@ -379,12 +376,16 @@ namespace GlitchyEngine.Renderer
|
||||
RenderCommand.SetBlendState(_gBufferBlend);
|
||||
|
||||
RenderCommand.UnbindRenderTargets();
|
||||
RenderCommand.SetRenderTargetGroup(_sceneConstants.CompositionTarget, true);
|
||||
RenderCommand.BindRenderTargets();
|
||||
RenderCommand.SetRenderTargetGroup(_sceneConstants.CompositionTarget, true);
|
||||
|
||||
// TODO: Postprocessing effects
|
||||
s_tonemappingEffect.SetTexture("CameraTarget", _sceneConstants.CameraTarget, 0);
|
||||
s_tonemappingEffect.Bind(_context);
|
||||
s_tonemappingEffect.ApplyChanges();
|
||||
s_tonemappingEffect.Bind();
|
||||
|
||||
RenderCommand.BindRenderTargets();
|
||||
//RenderCommand.BindEffect(s_tonemappingEffect);
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
|
||||
@@ -414,7 +415,8 @@ namespace GlitchyEngine.Renderer
|
||||
effect.Variables["ViewProjection"].SetData(_sceneConstants.ViewProjection);
|
||||
effect.Variables["Transform"].SetData(transform);
|
||||
|
||||
effect.Bind(_context);
|
||||
effect.ApplyChanges();
|
||||
effect.Bind();
|
||||
|
||||
geometry.Bind();
|
||||
RenderCommand.DrawIndexed(geometry);
|
||||
@@ -534,7 +536,8 @@ namespace GlitchyEngine.Renderer
|
||||
LineEffect.Variables["ViewProjection"].SetData(_sceneConstants.ViewProjection * transform);
|
||||
LineEffect.Variables["Color"].SetData(color);
|
||||
|
||||
LineEffect.Bind(_context);
|
||||
LineEffect.ApplyChanges();
|
||||
LineEffect.Bind();
|
||||
|
||||
LineGeometry.Bind();
|
||||
RenderCommand.DrawIndexed(LineGeometry);
|
||||
@@ -555,7 +558,8 @@ namespace GlitchyEngine.Renderer
|
||||
LineEffect.Variables["ViewProjection"].SetData(viewProjection * transform);
|
||||
LineEffect.Variables["Color"].SetData(color);
|
||||
|
||||
LineEffect.Bind(_context);
|
||||
LineEffect.ApplyChanges();
|
||||
LineEffect.Bind();
|
||||
|
||||
LineGeometry.Bind();
|
||||
RenderCommand.DrawIndexed(LineGeometry);
|
||||
|
||||
@@ -568,7 +568,8 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
s_quadInstanceBuffer.SetData<BatchVertex>(s_rawQuadInstances.Ptr, s_setInstances, 0, .WriteDiscard);
|
||||
|
||||
s_currentEffect.Bind(Renderer._context);
|
||||
s_currentEffect.ApplyChanges();
|
||||
s_currentEffect.Bind();
|
||||
s_quadBatchBinding.InstanceCount = s_setInstances;
|
||||
s_quadBatchBinding.Bind();
|
||||
RenderCommand.DrawIndexedInstanced(s_quadBatchBinding);
|
||||
@@ -587,7 +588,8 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
s_circleInstanceBuffer.SetData<CircleBatchVertex>(s_rawCircleInstances.Ptr, s_setInstances, 0, .WriteDiscard);
|
||||
|
||||
s_currentCircleEffect.Bind(Renderer._context);
|
||||
s_currentCircleEffect.ApplyChanges();
|
||||
s_currentCircleEffect.Bind();
|
||||
s_circleBatchBinding.InstanceCount = s_setInstances;
|
||||
s_circleBatchBinding.Bind();
|
||||
RenderCommand.DrawIndexedInstanced(s_circleBatchBinding);
|
||||
|
||||
@@ -64,5 +64,9 @@ namespace GlitchyEngine.Renderer
|
||||
public extern void UnbindTextures();
|
||||
|
||||
public extern void BindConstantBuffer(Buffer buffer, int slot, ShaderStage stage);
|
||||
|
||||
public extern void BindVertexShader(VertexShader vertexShader);
|
||||
|
||||
public extern void BindPixelShader(PixelShader pixelShader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,8 @@ namespace GlitchyEngine.World
|
||||
|
||||
_gammaCorrectEffect.SetTexture("Texture", _compositeTarget, 0);
|
||||
// TODO: iiihhh
|
||||
_gammaCorrectEffect.Bind(Application.Get().Window.Context);
|
||||
_gammaCorrectEffect.ApplyChanges();
|
||||
_gammaCorrectEffect.Bind();
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
}
|
||||
@@ -483,7 +484,8 @@ namespace GlitchyEngine.World
|
||||
|
||||
_gammaCorrectEffect.SetTexture("Texture", _compositeTarget, 0);
|
||||
// TODO: iiihhh
|
||||
_gammaCorrectEffect.Bind(Application.Get().Window.Context);
|
||||
_gammaCorrectEffect.ApplyChanges();
|
||||
_gammaCorrectEffect.Bind();
|
||||
|
||||
FullscreenQuad.Draw();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Sandbox
|
||||
|
||||
public this()
|
||||
{
|
||||
_context = Renderer.[Friend]_context..AddRef();
|
||||
_context = Application.Get().Window.Context..AddRef();
|
||||
|
||||
InitEffect();
|
||||
InitState();
|
||||
|
||||
Reference in New Issue
Block a user