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