mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Added generic Buffer
This commit is contained in:
@@ -70,6 +70,7 @@ namespace GlitchyEngine
|
|||||||
|
|
||||||
VertexBuffer<VertexColor> _vertexBuffer ~ delete _;
|
VertexBuffer<VertexColor> _vertexBuffer ~ delete _;
|
||||||
IndexBuffer _indexBuffer ~ delete _;
|
IndexBuffer _indexBuffer ~ delete _;
|
||||||
|
Buffer<ColorRGBA> _cBuffer ~ delete _;
|
||||||
|
|
||||||
RasterizerState _rasterizerState ~ delete _;
|
RasterizerState _rasterizerState ~ delete _;
|
||||||
|
|
||||||
@@ -94,7 +95,6 @@ namespace GlitchyEngine
|
|||||||
if(result.Failed || errorBlob != null)
|
if(result.Failed || errorBlob != null)
|
||||||
{
|
{
|
||||||
Debug.Write("ERROR: Failed to compile Vertex Shader: {}", result);
|
Debug.Write("ERROR: Failed to compile Vertex Shader: {}", result);
|
||||||
//ErrorPrinter.PrintErrorBlob(errorBlob);
|
|
||||||
Runtime.FatalError("Failed to compile Vertex Shader");
|
Runtime.FatalError("Failed to compile Vertex Shader");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +126,11 @@ namespace GlitchyEngine
|
|||||||
//
|
//
|
||||||
|
|
||||||
_pixelShader = Shader.FromFile!<PixelShader>(_window.Context, "content\\basicShader.hlsl", "PS");
|
_pixelShader = Shader.FromFile!<PixelShader>(_window.Context, "content\\basicShader.hlsl", "PS");
|
||||||
|
_pixelShader.[Friend]_buffers = new .[1];
|
||||||
|
|
||||||
|
_cBuffer = new Buffer<ColorRGBA>(_window.Context, .(0, .Constant, .Immutable, .None));
|
||||||
|
_cBuffer.Data = .White;
|
||||||
|
_cBuffer.Update();
|
||||||
|
|
||||||
float pO3 = Math.PI_f / 3.0f;
|
float pO3 = Math.PI_f / 3.0f;
|
||||||
VertexColor[?] vertices = .(
|
VertexColor[?] vertices = .(
|
||||||
@@ -206,6 +211,7 @@ namespace GlitchyEngine
|
|||||||
|
|
||||||
_window.Context.SetViewport(Window.Context.SwapChain.BackbufferViewport);
|
_window.Context.SetViewport(Window.Context.SwapChain.BackbufferViewport);
|
||||||
|
|
||||||
|
_immediateContext.PixelShader.SetConstantBuffers(0, 1, &_cBuffer.[Friend]nativeBuffer);
|
||||||
_window.Context.SetPixelShader(_pixelShader);
|
_window.Context.SetPixelShader(_pixelShader);
|
||||||
|
|
||||||
_window.Context.DrawIndexed(3 * 6);
|
_window.Context.DrawIndexed(3 * 6);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
Log.EngineLogger.Error($"Failed to create pixel shader: Message ({(int)result}): {result}");
|
Log.EngineLogger.Error($"Failed to create pixel shader: Message ({(int)result}): {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Reflect(shaderBlob);
|
//Reflect(shaderBlob);
|
||||||
|
|
||||||
shaderBlob?.Release();
|
shaderBlob?.Release();
|
||||||
}
|
}
|
||||||
@@ -78,6 +78,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
var bufferReflection = reflection.GetConstantBufferByIndex(i);
|
var bufferReflection = reflection.GetConstantBufferByIndex(i);
|
||||||
bufferReflection.GetDescription(let bufferDesc);
|
bufferReflection.GetDescription(let bufferDesc);
|
||||||
}
|
}
|
||||||
|
reflection.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,4 +179,35 @@ namespace GlitchyEngine.Renderer
|
|||||||
*/
|
*/
|
||||||
protected extern Result<void> PlatformSetData(void* data, uint32 byteLength, uint32 dstByteOffset, MapType mapType);
|
protected extern Result<void> PlatformSetData(void* data, uint32 byteLength, uint32 dstByteOffset, MapType mapType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A buffer containing an array of a struct on the GPU.
|
||||||
|
* @param T The type of the struct represented by this buffer.
|
||||||
|
*/
|
||||||
|
public class Buffer<T> : Buffer where T : struct
|
||||||
|
{
|
||||||
|
public T Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of a Buffer<T>
|
||||||
|
* @param context The graphics context.
|
||||||
|
* @param description Describes the Buffer. Note: description.Size is ignored, as it will always be sizeof(T).
|
||||||
|
*/
|
||||||
|
public this(GraphicsContext context, BufferDescription description) : base(context)
|
||||||
|
{
|
||||||
|
_description = description;
|
||||||
|
_description.Size = (uint32)sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo: perhaps add a constructor that takes all parameters from description except Size
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads the date from @see Data to the GPU.
|
||||||
|
*/
|
||||||
|
[Inline]
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
PlatformSetData(&Data, (uint32)sizeof(T), 0, .WriteDiscard);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
cbuffer Constants
|
||||||
|
{
|
||||||
|
float4 BaseColor;
|
||||||
|
}
|
||||||
|
|
||||||
struct VS_IN
|
struct VS_IN
|
||||||
{
|
{
|
||||||
float3 Position : POSITION;
|
float3 Position : POSITION;
|
||||||
@@ -21,5 +26,5 @@ PS_IN VS(VS_IN input)
|
|||||||
|
|
||||||
float4 PS(PS_IN input) : SV_TARGET
|
float4 PS(PS_IN input) : SV_TARGET
|
||||||
{
|
{
|
||||||
return input.Color;
|
return input.Color * BaseColor;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user