mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Use static D3D11 device and context
This commit is contained in:
@@ -42,24 +42,24 @@ namespace GlitchyEditor
|
|||||||
{
|
{
|
||||||
_context = Application.Get().Window.Context..AddRef();
|
_context = Application.Get().Window.Context..AddRef();
|
||||||
|
|
||||||
_swapchainDepthBuffer = new DepthStencilTarget(_context, _context.SwapChain.Width, _context.SwapChain.Height);
|
_swapchainDepthBuffer = new DepthStencilTarget(_context.SwapChain.Width, _context.SwapChain.Height);
|
||||||
|
|
||||||
RasterizerStateDescription rsDesc = .(.Solid, .Back, true);
|
RasterizerStateDescription rsDesc = .(.Solid, .Back, true);
|
||||||
_rasterizerState = new RasterizerState(_context, rsDesc);
|
_rasterizerState = new RasterizerState(rsDesc);
|
||||||
|
|
||||||
rsDesc.FrontCounterClockwise = false;
|
rsDesc.FrontCounterClockwise = false;
|
||||||
_rasterizerStateClockWise = new RasterizerState(_context, rsDesc);
|
_rasterizerStateClockWise = new RasterizerState(rsDesc);
|
||||||
|
|
||||||
BlendStateDescription blendDesc = .();
|
BlendStateDescription blendDesc = .();
|
||||||
blendDesc.RenderTarget[0] = .(true, .SourceAlpha, .InvertedSourceAlpha, .Add, .SourceAlpha, .InvertedSourceAlpha, .Add, .All);
|
blendDesc.RenderTarget[0] = .(true, .SourceAlpha, .InvertedSourceAlpha, .Add, .SourceAlpha, .InvertedSourceAlpha, .Add, .All);
|
||||||
_alphaBlendState = new BlendState(_context, blendDesc);
|
_alphaBlendState = new BlendState(blendDesc);
|
||||||
_opaqueBlendState = new BlendState(_context, .Default);
|
_opaqueBlendState = new BlendState(.Default);
|
||||||
|
|
||||||
_renderTarget2D = new RenderTarget2D(_context, RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100) {DepthStencilFormat = .D32_Float});
|
_renderTarget2D = new RenderTarget2D(RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100) {DepthStencilFormat = .D32_Float});
|
||||||
|
|
||||||
SamplerStateDescription desc = .();
|
SamplerStateDescription desc = .();
|
||||||
|
|
||||||
SamplerState sampler = new SamplerState(_context, desc);
|
SamplerState sampler = new SamplerState(desc);
|
||||||
|
|
||||||
_renderTarget2D.SamplerState = sampler;
|
_renderTarget2D.SamplerState = sampler;
|
||||||
|
|
||||||
@@ -117,10 +117,10 @@ namespace GlitchyEditor
|
|||||||
Renderer.EndScene();
|
Renderer.EndScene();
|
||||||
|
|
||||||
RenderCommand.Clear(null, .(0.2f, 0.2f, 0.2f));
|
RenderCommand.Clear(null, .(0.2f, 0.2f, 0.2f));
|
||||||
_swapchainDepthBuffer.Clear(1.0f, 0, .Depth);
|
RenderCommand.Clear(_swapchainDepthBuffer, 1.0f, 0, .Depth);
|
||||||
|
|
||||||
_context.SetRenderTarget(null);
|
_context.SetRenderTarget(null);
|
||||||
_swapchainDepthBuffer.Bind();
|
_context.SetDepthStencilTarget(_swapchainDepthBuffer);
|
||||||
_context.BindRenderTargets();
|
_context.BindRenderTargets();
|
||||||
|
|
||||||
RenderCommand.SetViewport(_context.SwapChain.BackbufferViewport);
|
RenderCommand.SetViewport(_context.SwapChain.BackbufferViewport);
|
||||||
@@ -188,7 +188,7 @@ namespace GlitchyEditor
|
|||||||
private bool OnWindowResize(WindowResizeEvent e)
|
private bool OnWindowResize(WindowResizeEvent e)
|
||||||
{
|
{
|
||||||
_swapchainDepthBuffer.ReleaseRef();
|
_swapchainDepthBuffer.ReleaseRef();
|
||||||
_swapchainDepthBuffer = new DepthStencilTarget(_context, _context.SwapChain.Width, _context.SwapChain.Height);
|
_swapchainDepthBuffer = new DepthStencilTarget(_context.SwapChain.Width, _context.SwapChain.Height);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ namespace GlitchyEngine
|
|||||||
_rendererApi = new RendererAPI();
|
_rendererApi = new RendererAPI();
|
||||||
_rendererApi.Context = _window.Context;
|
_rendererApi.Context = _window.Context;
|
||||||
|
|
||||||
SamplerStateManager.Init(_window.Context);
|
SamplerStateManager.Init();
|
||||||
|
|
||||||
RenderCommand.RendererAPI = _rendererApi;
|
RenderCommand.RendererAPI = _rendererApi;
|
||||||
|
|
||||||
_effectLibrary = new EffectLibrary(_window.Context);
|
_effectLibrary = new EffectLibrary();
|
||||||
|
|
||||||
Renderer.Init(_window.Context, _effectLibrary);
|
Renderer.Init(_window.Context, _effectLibrary);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace GlitchyEngine.Content
|
|||||||
{
|
{
|
||||||
static readonly Matrix RightToLeftHand = .Scaling(1, 1, -1);
|
static readonly Matrix RightToLeftHand = .Scaling(1, 1, -1);
|
||||||
|
|
||||||
public static void LoadModel(String filename, GraphicsContext context, Effect validationEffect, Material material, EcsWorld world,
|
public static void LoadModel(String filename, Effect validationEffect, Material material, EcsWorld world,
|
||||||
List<(Matrix Transform, GeometryBinding Model)> output, out Skeleton skeleton, out List<AnimationClip> clips)
|
List<(Matrix Transform, GeometryBinding Model)> output, out Skeleton skeleton, out List<AnimationClip> clips)
|
||||||
{
|
{
|
||||||
skeleton = null;
|
skeleton = null;
|
||||||
@@ -30,7 +30,7 @@ namespace GlitchyEngine.Content
|
|||||||
|
|
||||||
for(var node in data.Scenes[0].Nodes)
|
for(var node in data.Scenes[0].Nodes)
|
||||||
{
|
{
|
||||||
NodesToEntities(data, node, null, world, context, validationEffect, material);
|
NodesToEntities(data, node, null, world, validationEffect, material);
|
||||||
}
|
}
|
||||||
|
|
||||||
clips = removeMe___Clips;
|
clips = removeMe___Clips;
|
||||||
@@ -47,7 +47,7 @@ namespace GlitchyEngine.Content
|
|||||||
|
|
||||||
for(var primitive in node.Mesh.Primitives)
|
for(var primitive in node.Mesh.Primitives)
|
||||||
{
|
{
|
||||||
GeometryBinding binding = ModelLoader.PrimitiveToGeoBinding(context, primitive, validationEffect);
|
GeometryBinding binding = ModelLoader.PrimitiveToGeoBinding(primitive, validationEffect);
|
||||||
|
|
||||||
output.Add((transform, binding));
|
output.Add((transform, binding));
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ namespace GlitchyEngine.Content
|
|||||||
|
|
||||||
static List<AnimationClip> removeMe___Clips;
|
static List<AnimationClip> removeMe___Clips;
|
||||||
|
|
||||||
private static void NodesToEntities(CGLTF.Data* data, CGLTF.Node* node, Entity? parentEntity, EcsWorld world, GraphicsContext context, Effect validationEffect, Material material)
|
private static void NodesToEntities(CGLTF.Data* data, CGLTF.Node* node, Entity? parentEntity, EcsWorld world, Effect validationEffect, Material material)
|
||||||
{
|
{
|
||||||
Entity entity = world.NewEntity();
|
Entity entity = world.NewEntity();
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ namespace GlitchyEngine.Content
|
|||||||
if(node.Mesh.Primitives.Length == 1)
|
if(node.Mesh.Primitives.Length == 1)
|
||||||
{
|
{
|
||||||
var mesh = world.AssignComponent<MeshComponent>(entity);
|
var mesh = world.AssignComponent<MeshComponent>(entity);
|
||||||
mesh.Mesh = ModelLoader.PrimitiveToGeoBinding(context, node.Mesh.Primitives[0], validationEffect);
|
mesh.Mesh = ModelLoader.PrimitiveToGeoBinding(node.Mesh.Primitives[0], validationEffect);
|
||||||
|
|
||||||
if(skeleton == null)
|
if(skeleton == null)
|
||||||
{
|
{
|
||||||
@@ -151,7 +151,7 @@ namespace GlitchyEngine.Content
|
|||||||
meshParent.Entity = entity;
|
meshParent.Entity = entity;
|
||||||
|
|
||||||
var mesh = world.AssignComponent<MeshComponent>(meshEntity);
|
var mesh = world.AssignComponent<MeshComponent>(meshEntity);
|
||||||
mesh.Mesh = ModelLoader.PrimitiveToGeoBinding(context, node.Mesh.Primitives[0], validationEffect);
|
mesh.Mesh = ModelLoader.PrimitiveToGeoBinding(node.Mesh.Primitives[0], validationEffect);
|
||||||
|
|
||||||
if(skeleton == null)
|
if(skeleton == null)
|
||||||
{
|
{
|
||||||
@@ -170,13 +170,13 @@ namespace GlitchyEngine.Content
|
|||||||
|
|
||||||
for(var child in node.Children)
|
for(var child in node.Children)
|
||||||
{
|
{
|
||||||
NodesToEntities(data, child, entity, world, context, validationEffect, material);
|
NodesToEntities(data, child, entity, world, validationEffect, material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GeometryBinding PrimitiveToGeoBinding(GraphicsContext context, CGLTF.Primitive primitive, Effect validationEffect)
|
public static GeometryBinding PrimitiveToGeoBinding(CGLTF.Primitive primitive, Effect validationEffect)
|
||||||
{
|
{
|
||||||
GeometryBinding binding = new GeometryBinding(context);
|
GeometryBinding binding = new GeometryBinding();
|
||||||
|
|
||||||
// primitive topology
|
// primitive topology
|
||||||
switch(primitive.Type)
|
switch(primitive.Type)
|
||||||
@@ -203,7 +203,7 @@ namespace GlitchyEngine.Content
|
|||||||
{
|
{
|
||||||
bool is16bit = indices.ComponentType == .R_16u || indices.ComponentType == .R_16;
|
bool is16bit = indices.ComponentType == .R_16u || indices.ComponentType == .R_16;
|
||||||
|
|
||||||
IndexBuffer ib = new IndexBuffer(context, (.)indices.Count, .Immutable, .None, is16bit ? .Index16Bit : .Index32Bit);
|
IndexBuffer ib = new IndexBuffer((.)indices.Count, .Immutable, .None, is16bit ? .Index16Bit : .Index32Bit);
|
||||||
|
|
||||||
uint8* bufferData = (uint8*)indices.BufferView.Buffer.Data;
|
uint8* bufferData = (uint8*)indices.BufferView.Buffer.Data;
|
||||||
bufferData += indices.BufferView.Offset;
|
bufferData += indices.BufferView.Offset;
|
||||||
@@ -255,7 +255,7 @@ namespace GlitchyEngine.Content
|
|||||||
// if buffer doesn't exist -> create
|
// if buffer doesn't exist -> create
|
||||||
if(!buffers.TryGetValue(bufferView, out vertexBuffer))
|
if(!buffers.TryGetValue(bufferView, out vertexBuffer))
|
||||||
{
|
{
|
||||||
vertexBuffer = new VertexBuffer(context, 1, (uint32)bufferView.Size, .Immutable)..ReleaseRefNoDelete();
|
vertexBuffer = new VertexBuffer(1, (uint32)bufferView.Size, .Immutable)..ReleaseRefNoDelete();
|
||||||
|
|
||||||
uint8* bufferData = (uint8*)bufferView.Buffer.Data;
|
uint8* bufferData = (uint8*)bufferView.Buffer.Data;
|
||||||
bufferData += bufferView.Offset;
|
bufferData += bufferView.Offset;
|
||||||
@@ -318,7 +318,7 @@ namespace GlitchyEngine.Content
|
|||||||
else
|
else
|
||||||
GenerateNormals(positions, normals);
|
GenerateNormals(positions, normals);
|
||||||
|
|
||||||
VertexBuffer vertexBuffer = new VertexBuffer(context, (uint32)sizeof(Vector3), (uint32)normals.Count, .Immutable);
|
VertexBuffer vertexBuffer = new VertexBuffer((uint32)sizeof(Vector3), (uint32)normals.Count, .Immutable);
|
||||||
vertexBuffer.SetData<Vector3>(normals);
|
vertexBuffer.SetData<Vector3>(normals);
|
||||||
|
|
||||||
bindings.Add(vertexBuffer.Binding);
|
bindings.Add(vertexBuffer.Binding);
|
||||||
@@ -338,7 +338,7 @@ namespace GlitchyEngine.Content
|
|||||||
vertexElements[i] = elements[i];
|
vertexElements[i] = elements[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexLayout layout = new VertexLayout(context, vertexElements, true, validationEffect.VertexShader);
|
VertexLayout layout = new VertexLayout(vertexElements, true, validationEffect.VertexShader);
|
||||||
binding.SetVertexLayout(layout..ReleaseRefNoDelete());
|
binding.SetVertexLayout(layout..ReleaseRefNoDelete());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ using ImGuizmo;
|
|||||||
|
|
||||||
using internal ImGui;
|
using internal ImGui;
|
||||||
|
|
||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace GlitchyEngine.ImGui
|
namespace GlitchyEngine.ImGui
|
||||||
{
|
{
|
||||||
public class ImGuiLayer : Layer
|
public class ImGuiLayer : Layer
|
||||||
@@ -40,10 +47,10 @@ namespace GlitchyEngine.ImGui
|
|||||||
#if GE_WINDOWS
|
#if GE_WINDOWS
|
||||||
// Todo: temporary, needs to be platform independent
|
// Todo: temporary, needs to be platform independent
|
||||||
ImGuiImplWin32.Init((void*)(uint)(Windows.HWnd)(int)Application.Get().Window.NativeWindow);
|
ImGuiImplWin32.Init((void*)(uint)(Windows.HWnd)(int)Application.Get().Window.NativeWindow);
|
||||||
|
#endif
|
||||||
|
|
||||||
var context = Application.Get().Window.Context;
|
#if GE_D3D11
|
||||||
|
ImGuiImplDX11.Init(NativeDevice, NativeContext);
|
||||||
ImGuiImplDX11.Init(context.[Friend]nativeDevice, context.[Friend]nativeContext);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using DirectX.Common;
|
||||||
|
using DirectX.D3D11;
|
||||||
|
using DirectX.D3D11.SDKLayers;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Platform.DX11
|
||||||
|
{
|
||||||
|
static
|
||||||
|
{
|
||||||
|
/// Gets whether or not the DX11 device is initialized.
|
||||||
|
protected internal static bool IsDx11Initialized => NativeDevice != null;
|
||||||
|
protected internal static ID3D11Device* NativeDevice;
|
||||||
|
protected internal static ID3D11DeviceContext* NativeContext;
|
||||||
|
|
||||||
|
protected internal static ID3D11Debug* DebugDevice;
|
||||||
|
|
||||||
|
internal static void Dx11Init()
|
||||||
|
{
|
||||||
|
if(!IsDx11Initialized)
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Trace("Creating D3D11 Device and Context...");
|
||||||
|
|
||||||
|
DeviceCreationFlags deviceFlags = .None;
|
||||||
|
#if DEBUG
|
||||||
|
deviceFlags |= .Debug;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
FeatureLevel[] levels = scope .(.Level_11_0);
|
||||||
|
|
||||||
|
FeatureLevel deviceLevel = ?;
|
||||||
|
var deviceResult = D3D11.CreateDevice(null, .Hardware, 0, deviceFlags, levels, &NativeDevice, &deviceLevel, &NativeContext);
|
||||||
|
Log.EngineLogger.Assert(deviceResult.Succeeded, scope $"Failed to create D3D11 Device. Message({(int32)deviceResult}): {deviceResult}");
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
if(NativeDevice.QueryInterface<ID3D11Debug>(out DebugDevice).Succeeded)
|
||||||
|
{
|
||||||
|
ID3D11InfoQueue* infoQueue;
|
||||||
|
if(NativeDevice.QueryInterface<ID3D11InfoQueue>(out infoQueue).Succeeded)
|
||||||
|
{
|
||||||
|
infoQueue.SetBreakOnSeverity(.Corruption, true);
|
||||||
|
infoQueue.SetBreakOnSeverity(.Error, true);
|
||||||
|
|
||||||
|
infoQueue.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Log.EngineLogger.Trace($"D3D11 Device and Context created (Feature level: {deviceLevel})");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We created a second GraphicsContext (for some reason?) just increment references.
|
||||||
|
NativeDevice.AddRef();
|
||||||
|
NativeContext.AddRef();
|
||||||
|
DebugDevice.AddRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void Dx11Release()
|
||||||
|
{
|
||||||
|
NativeDevice.Release();
|
||||||
|
NativeContext.Release();
|
||||||
|
DebugDevice.ReportLiveDeviceObjects(.Detail);
|
||||||
|
DebugDevice.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using GlitchyEngine.Renderer;
|
using GlitchyEngine.Renderer;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
@@ -37,3 +39,5 @@ namespace ImGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
// Disable warning when taking pointer of in-Parameter
|
// Disable warning when taking pointer of in-Parameter
|
||||||
#pragma warning disable 4204
|
#pragma warning disable 4204
|
||||||
|
|
||||||
@@ -32,3 +34,5 @@ namespace GlitchyEngine.Math
|
|||||||
public static implicit operator Self(in DirectX.Math.Vector4 value) => *(Self*)&value;
|
public static implicit operator Self(in DirectX.Math.Vector4 value) => *(Self*)&value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
using GlitchyEngine.Math;
|
using GlitchyEngine.Math;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
extension BlendState
|
extension BlendState
|
||||||
@@ -12,7 +17,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public override void Bind(ColorRGBA blendFactor)
|
public override void Bind(ColorRGBA blendFactor)
|
||||||
{
|
{
|
||||||
_context.nativeContext.OutputMerger.SetBlendState(nativeBlendState, blendFactor);
|
NativeContext.OutputMerger.SetBlendState(nativeBlendState, blendFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PlatformCreateBlendState()
|
protected override void PlatformCreateBlendState()
|
||||||
@@ -33,9 +38,11 @@ namespace GlitchyEngine.Renderer
|
|||||||
nativeDesc.RenderTarget[i].RenderTargetWriteMask = _desc.RenderTarget[i].RenderTargetWriteMask;
|
nativeDesc.RenderTarget[i].RenderTargetWriteMask = _desc.RenderTarget[i].RenderTargetWriteMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
HResult result = _context.nativeDevice.CreateBlendState(ref nativeDesc, &nativeBlendState);
|
HResult result = NativeDevice.CreateBlendState(ref nativeDesc, &nativeBlendState);
|
||||||
|
|
||||||
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create blend state. Error({(int)result}): {result}");
|
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create blend state. Error({(int)result}): {result}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System;
|
using System;
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
extension BufferDescription
|
extension BufferDescription
|
||||||
@@ -67,7 +72,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
SubresourceData srData = .(byteData, byteLength, 0);
|
SubresourceData srData = .(byteData, byteLength, 0);
|
||||||
var result = _context.nativeDevice.CreateBuffer(ref nativeDescription, &srData, &nativeBuffer);
|
var result = NativeDevice.CreateBuffer(ref nativeDescription, &srData, &nativeBuffer);
|
||||||
if(result.Failed)
|
if(result.Failed)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Failed to create buffer. Message({(int)result}):{result}");
|
Log.EngineLogger.Error($"Failed to create buffer. Message({(int)result}):{result}");
|
||||||
@@ -91,14 +96,14 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
case .Default:
|
case .Default:
|
||||||
Box dataBox = .(dstByteOffset, 0, 0, dstByteOffset + byteLength, 1, 1);
|
Box dataBox = .(dstByteOffset, 0, 0, dstByteOffset + byteLength, 1, 1);
|
||||||
_context.nativeContext.UpdateSubresource(nativeBuffer, 0, &dataBox, data, byteLength, byteLength);
|
NativeContext.UpdateSubresource(nativeBuffer, 0, &dataBox, data, byteLength, byteLength);
|
||||||
case .Dynamic:
|
case .Dynamic:
|
||||||
Debug.Assert(mapType.CanWrite, "The map type has to have write access.");
|
Debug.Assert(mapType.CanWrite, "The map type has to have write access.");
|
||||||
// Todo: DoNotWaitFlag
|
// Todo: DoNotWaitFlag
|
||||||
MappedSubresource map = ?;
|
MappedSubresource map = ?;
|
||||||
_context.nativeContext.Map(nativeBuffer, 0, (.)mapType, .None, &map);
|
NativeContext.Map(nativeBuffer, 0, (.)mapType, .None, &map);
|
||||||
Internal.MemCpy(((uint8*)map.Data) + dstByteOffset, data, byteLength);
|
Internal.MemCpy(((uint8*)map.Data) + dstByteOffset, data, byteLength);
|
||||||
_context.nativeContext.Unmap(nativeBuffer, 0);
|
NativeContext.Unmap(nativeBuffer, 0);
|
||||||
case .Immutable:
|
case .Immutable:
|
||||||
Log.EngineLogger.Error("Can't set the data of an immutable resource.");
|
Log.EngineLogger.Error("Can't set the data of an immutable resource.");
|
||||||
return .Err;
|
return .Err;
|
||||||
@@ -111,3 +116,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
@@ -17,3 +19,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
extension CPUAccessFlags
|
extension CPUAccessFlags
|
||||||
@@ -16,3 +18,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
using DirectX.D3D11Shader;
|
using DirectX.D3D11Shader;
|
||||||
using System;
|
using System;
|
||||||
@@ -47,7 +49,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
extension ConstantBuffer
|
extension ConstantBuffer
|
||||||
{
|
{
|
||||||
internal this(GraphicsContext context, ID3D11ShaderReflectionConstantBuffer* bufferReflection) : base(context)
|
internal this(ID3D11ShaderReflectionConstantBuffer* bufferReflection)
|
||||||
{
|
{
|
||||||
Reflect(bufferReflection);
|
Reflect(bufferReflection);
|
||||||
|
|
||||||
@@ -80,3 +82,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
extension DepthStencilFormat
|
extension DepthStencilFormat
|
||||||
@@ -40,21 +45,13 @@ namespace GlitchyEngine.Renderer
|
|||||||
desc.SampleDesc = .(1, 0);
|
desc.SampleDesc = .(1, 0);
|
||||||
|
|
||||||
ID3D11Texture2D* tex = ?;
|
ID3D11Texture2D* tex = ?;
|
||||||
_context.nativeDevice.CreateTexture2D(ref desc, null, &tex);
|
NativeDevice.CreateTexture2D(ref desc, null, &tex);
|
||||||
|
|
||||||
_context.nativeDevice.CreateDepthStencilView(tex, null, &nativeView);
|
NativeDevice.CreateDepthStencilView(tex, null, &nativeView);
|
||||||
|
|
||||||
tex.Release();
|
tex.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Bind()
|
|
||||||
{
|
|
||||||
_context.SetDepthStencilTarget(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Clear(float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
|
||||||
{
|
|
||||||
_context.nativeContext.ClearDepthStencilView(nativeView, (.)clearFlags, depthValue, stencilValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DirectX;
|
using DirectX;
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
@@ -11,8 +13,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
protected override void Compile(String vsPath, String vsEntry, String psPath, String psEntry)
|
protected override void Compile(String vsPath, String vsEntry, String psPath, String psEntry)
|
||||||
{
|
{
|
||||||
// Todo: macros
|
// Todo: macros
|
||||||
VertexShader = new VertexShader(_context, vsPath, vsEntry);
|
VertexShader = new VertexShader(vsPath, vsEntry);
|
||||||
PixelShader = new PixelShader(_context, psPath, psEntry);
|
PixelShader = new PixelShader(psPath, psEntry);
|
||||||
|
|
||||||
Reflect();
|
Reflect();
|
||||||
}
|
}
|
||||||
@@ -23,3 +25,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
using internal GlitchyEngine.Renderer;
|
|
||||||
|
|
||||||
extension GeometryBinding
|
extension GeometryBinding
|
||||||
{
|
{
|
||||||
internal ID3D11Buffer*[DirectX.D3D11.D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] nativeBuffers;
|
internal ID3D11Buffer*[DirectX.D3D11.D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] nativeBuffers;
|
||||||
@@ -73,33 +77,29 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Bind(GraphicsContext context = null)
|
public override void Bind()
|
||||||
{
|
{
|
||||||
var context;
|
NativeContext.InputAssembler.SetVertexBuffers(0, nativeBuffers.Count, &nativeBuffers, &bufferStrides, &bufferOffsets);
|
||||||
context ??= _context;
|
NativeContext.InputAssembler.SetInputLayout(_vertexLayout.nativeLayout);
|
||||||
|
NativeContext.InputAssembler.SetPrimitiveTopology((.)_primitiveTopology);
|
||||||
context.nativeContext.InputAssembler.SetVertexBuffers(0, nativeBuffers.Count, &nativeBuffers, &bufferStrides, &bufferOffsets);
|
|
||||||
context.nativeContext.InputAssembler.SetInputLayout(_vertexLayout.nativeLayout);
|
|
||||||
context.nativeContext.InputAssembler.SetPrimitiveTopology((.)_primitiveTopology);
|
|
||||||
|
|
||||||
if(_indexBuffer != null)
|
if(_indexBuffer != null)
|
||||||
context.nativeContext.InputAssembler.SetIndexBuffer(_indexBuffer.nativeBuffer, _indexBuffer.Format == .Index32Bit ? .R32_UInt : .R16_UInt, _indexByteOffset);
|
NativeContext.InputAssembler.SetIndexBuffer(_indexBuffer.nativeBuffer, _indexBuffer.Format == .Index32Bit ? .R32_UInt : .R16_UInt, _indexByteOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unbind(GraphicsContext context = null)
|
public override void Unbind()
|
||||||
{
|
{
|
||||||
var context;
|
|
||||||
context ??= _context;
|
|
||||||
|
|
||||||
ID3D11Buffer*[nativeBuffers.Count] nullBuffers = .();
|
ID3D11Buffer*[nativeBuffers.Count] nullBuffers = .();
|
||||||
uint32[nativeBuffers.Count] zeroStrides = .();
|
uint32[nativeBuffers.Count] zeroStrides = .();
|
||||||
uint32[nativeBuffers.Count] zeroOffsets = .();
|
uint32[nativeBuffers.Count] zeroOffsets = .();
|
||||||
|
|
||||||
context.nativeContext.InputAssembler.SetVertexBuffers(0, nativeBuffers.Count, &nullBuffers, &zeroStrides, &zeroOffsets);
|
NativeContext.InputAssembler.SetVertexBuffers(0, nativeBuffers.Count, &nullBuffers, &zeroStrides, &zeroOffsets);
|
||||||
context.nativeContext.InputAssembler.SetInputLayout(null);
|
NativeContext.InputAssembler.SetInputLayout(null);
|
||||||
context.nativeContext.InputAssembler.SetPrimitiveTopology(.Undefined);
|
NativeContext.InputAssembler.SetPrimitiveTopology(.Undefined);
|
||||||
|
|
||||||
context.nativeContext.InputAssembler.SetIndexBuffer(null, .R16_UNorm, 0);
|
NativeContext.InputAssembler.SetIndexBuffer(null, .R16_UNorm, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
@@ -7,9 +9,11 @@ using DirectX.DXGI.DXGI1_2;
|
|||||||
using GlitchyEngine.Renderer;
|
using GlitchyEngine.Renderer;
|
||||||
using GlitchyEngine.Math;
|
using GlitchyEngine.Math;
|
||||||
using DirectX.D3D11.DeviceContextStages;
|
using DirectX.D3D11.DeviceContextStages;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
/// DirectX 11 specific implementation of the GraphicsContext
|
/// DirectX 11 specific implementation of the GraphicsContext
|
||||||
@@ -19,10 +23,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
internal Windows.HWnd nativeWindowHandle;
|
internal Windows.HWnd nativeWindowHandle;
|
||||||
|
|
||||||
internal ID3D11Device* nativeDevice;
|
/// Gets whether or not the DX11 device is initialized.
|
||||||
internal ID3D11DeviceContext* nativeContext;
|
//internal bool IsDx11Initialized => nativeDevice != null;
|
||||||
|
//internal ID3D11Device* nativeDevice => NativeDevice;
|
||||||
private ID3D11Debug* _debugDevice;
|
//internal ID3D11DeviceContext* nativeContext => NativeContext;
|
||||||
|
|
||||||
|
//internal ID3D11Debug* debugDevice => DebugDevice;
|
||||||
|
|
||||||
public override SwapChain SwapChain => _swapChain;
|
public override SwapChain SwapChain => _swapChain;
|
||||||
|
|
||||||
@@ -41,15 +47,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
delete _swapChain;
|
delete _swapChain;
|
||||||
|
|
||||||
nativeDevice?.Release();
|
Dx11Release();
|
||||||
nativeContext?.Release();
|
|
||||||
_debugDevice.ReportLiveDeviceObjects(.Detail);
|
|
||||||
_debugDevice?.Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
InitDevice();
|
Dx11Init();
|
||||||
|
|
||||||
SwapChain.Init();
|
SwapChain.Init();
|
||||||
}
|
}
|
||||||
@@ -57,47 +60,54 @@ namespace GlitchyEngine.Renderer
|
|||||||
/**
|
/**
|
||||||
* Initializes the Device and ImmediateContext.
|
* Initializes the Device and ImmediateContext.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
void InitDevice()
|
void InitDevice()
|
||||||
{
|
{
|
||||||
nativeDevice?.Release();
|
if(!IsDx11Initialized)
|
||||||
nativeContext?.Release();
|
{
|
||||||
|
Log.EngineLogger.Trace("Creating D3D11 Device and Context...");
|
||||||
Log.EngineLogger.Trace("Creating D3D11 Device and Context...");
|
|
||||||
|
DeviceCreationFlags deviceFlags = .None;
|
||||||
DeviceCreationFlags deviceFlags = .None;
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
deviceFlags |= .Debug;
|
deviceFlags |= .Debug;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FeatureLevel[] levels = scope .(.Level_11_0);
|
FeatureLevel[] levels = scope .(.Level_11_0);
|
||||||
|
|
||||||
FeatureLevel deviceLevel = ?;
|
FeatureLevel deviceLevel = ?;
|
||||||
var deviceResult = D3D11.CreateDevice(null, .Hardware, 0, deviceFlags, levels, &nativeDevice, &deviceLevel, &nativeContext);
|
var deviceResult = D3D11.CreateDevice(null, .Hardware, 0, deviceFlags, levels, &nativeDevice, &deviceLevel, &nativeContext);
|
||||||
Debug.Assert(deviceResult.Succeeded, scope $"Failed to create D3D11 Device. Message(0x{(int32)deviceResult}): {deviceResult}");
|
Log.EngineLogger.Assert(deviceResult.Succeeded, scope $"Failed to create D3D11 Device. Message({(int32)deviceResult}): {deviceResult}");
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if(nativeDevice.QueryInterface<ID3D11Debug>(out _debugDevice).Succeeded)
|
if(nativeDevice.QueryInterface<ID3D11Debug>(out debugDevice).Succeeded)
|
||||||
{
|
|
||||||
ID3D11InfoQueue* infoQueue;
|
|
||||||
if(nativeDevice.QueryInterface<ID3D11InfoQueue>(out infoQueue).Succeeded)
|
|
||||||
{
|
{
|
||||||
infoQueue.SetBreakOnSeverity(.Corruption, true);
|
ID3D11InfoQueue* infoQueue;
|
||||||
infoQueue.SetBreakOnSeverity(.Error, true);
|
if(nativeDevice.QueryInterface<ID3D11InfoQueue>(out infoQueue).Succeeded)
|
||||||
|
{
|
||||||
|
infoQueue.SetBreakOnSeverity(.Corruption, true);
|
||||||
|
infoQueue.SetBreakOnSeverity(.Error, true);
|
||||||
|
|
||||||
infoQueue.Release();
|
infoQueue.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Log.EngineLogger.Trace($"D3D11 Device and Context created (Feature level: {deviceLevel})");
|
Log.EngineLogger.Trace($"D3D11 Device and Context created (Feature level: {deviceLevel})");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We created a second GraphicsContext (for some reason?) just increment references.
|
||||||
|
nativeDevice.AddRef();
|
||||||
|
nativeContext.AddRef();
|
||||||
|
debugDevice.AddRef();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ID3D11DepthStencilView* _depthStencilTarget;
|
private ID3D11DepthStencilView* _depthStencilTarget;
|
||||||
private ID3D11RenderTargetView*[MaxRTVCount] _renderTargets;
|
private ID3D11RenderTargetView*[MaxRTVCount] _renderTargets;
|
||||||
|
|
||||||
internal void SetDepthStencilTarget(DepthStencilTarget target)
|
public override void SetDepthStencilTarget(DepthStencilTarget target)
|
||||||
{
|
{
|
||||||
_depthStencilTarget = target?.nativeView;
|
_depthStencilTarget = target?.nativeView;
|
||||||
}
|
}
|
||||||
@@ -121,18 +131,18 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public override void BindRenderTargets()
|
public override void BindRenderTargets()
|
||||||
{
|
{
|
||||||
nativeContext.OutputMerger.SetRenderTargets(MaxRTVCount, &_renderTargets, _depthStencilTarget);
|
NativeContext.OutputMerger.SetRenderTargets(MaxRTVCount, &_renderTargets, _depthStencilTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ClearRenderTarget(RenderTarget2D renderTarget, ColorRGBA color)
|
public override void ClearRenderTarget(RenderTarget2D renderTarget, ColorRGBA color)
|
||||||
{
|
{
|
||||||
if(renderTarget == null)
|
if(renderTarget == null)
|
||||||
{
|
{
|
||||||
nativeContext.ClearRenderTargetView(_swapChain.nativeBackBufferTarget, color);
|
NativeContext.ClearRenderTargetView(_swapChain.nativeBackBufferTarget, color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nativeContext.ClearRenderTargetView(renderTarget._nativeRenderTargetView, color);
|
NativeContext.ClearRenderTargetView(renderTarget._nativeRenderTargetView, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,42 +150,42 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
// make stride and offset mutable so that we can take their pointers.
|
// make stride and offset mutable so that we can take their pointers.
|
||||||
var stride, offset;
|
var stride, offset;
|
||||||
nativeContext.InputAssembler.SetVertexBuffers(slot, 1, &buffer.nativeBuffer, &stride, &offset);
|
NativeContext.InputAssembler.SetVertexBuffers(slot, 1, &buffer.nativeBuffer, &stride, &offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(uint32 vertexCount, uint32 startVertexIndex = 0)
|
public override void Draw(uint32 vertexCount, uint32 startVertexIndex = 0)
|
||||||
{
|
{
|
||||||
nativeContext.Draw(vertexCount, startVertexIndex);
|
NativeContext.Draw(vertexCount, startVertexIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawIndexed(uint32 indexCount, uint32 startIndexLocation = 0, int32 vertexOffset = 0)
|
public override void DrawIndexed(uint32 indexCount, uint32 startIndexLocation = 0, int32 vertexOffset = 0)
|
||||||
{
|
{
|
||||||
nativeContext.DrawIndexed(indexCount, startIndexLocation, vertexOffset);
|
NativeContext.DrawIndexed(indexCount, startIndexLocation, vertexOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetIndexBuffer(Buffer buffer, IndexFormat indexFormat = .Index16Bit, uint32 byteOffset = 0)
|
public override void SetIndexBuffer(Buffer buffer, IndexFormat indexFormat = .Index16Bit, uint32 byteOffset = 0)
|
||||||
{
|
{
|
||||||
nativeContext.InputAssembler.SetIndexBuffer(buffer.nativeBuffer, indexFormat == .Index32Bit ? .R32_UInt : .R16_UInt, byteOffset);
|
NativeContext.InputAssembler.SetIndexBuffer(buffer.nativeBuffer, indexFormat == .Index32Bit ? .R32_UInt : .R16_UInt, byteOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetRasterizerStateImpl()
|
protected override void SetRasterizerStateImpl()
|
||||||
{
|
{
|
||||||
nativeContext.Rasterizer.SetState(_currentRasterizerState.nativeRasterizerState);
|
NativeContext.Rasterizer.SetState(_currentRasterizerState.nativeRasterizerState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetViewports(uint32 viewportsCount, GlitchyEngine.Renderer.Viewport* viewports)
|
public override void SetViewports(uint32 viewportsCount, GlitchyEngine.Renderer.Viewport* viewports)
|
||||||
{
|
{
|
||||||
nativeContext.Rasterizer.SetViewports(viewportsCount, (.)viewports);
|
NativeContext.Rasterizer.SetViewports(viewportsCount, (.)viewports);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetVertexLayout(VertexLayout vertexLayout)
|
public override void SetVertexLayout(VertexLayout vertexLayout)
|
||||||
{
|
{
|
||||||
nativeContext.InputAssembler.SetInputLayout(vertexLayout.nativeLayout);
|
NativeContext.InputAssembler.SetInputLayout(vertexLayout.nativeLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetPrimitiveTopology(GlitchyEngine.Renderer.PrimitiveTopology primitiveTopology)
|
public override void SetPrimitiveTopology(GlitchyEngine.Renderer.PrimitiveTopology primitiveTopology)
|
||||||
{
|
{
|
||||||
nativeContext.InputAssembler.SetPrimitiveTopology((DirectX.Common.PrimitiveTopology)primitiveTopology);
|
NativeContext.InputAssembler.SetPrimitiveTopology((DirectX.Common.PrimitiveTopology)primitiveTopology);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,11 +218,11 @@ namespace GlitchyEngine.Renderer
|
|||||||
// TODO: Add remaining shader stages
|
// TODO: Add remaining shader stages
|
||||||
case typeof(PixelShader):
|
case typeof(PixelShader):
|
||||||
// TODO: bind uavs
|
// TODO: bind uavs
|
||||||
nativeContext.PixelShader.SetShaderResources(_firstTexture, _textureCount, &_textures[_firstTexture]);
|
NativeContext.PixelShader.SetShaderResources(_firstTexture, _textureCount, &_textures[_firstTexture]);
|
||||||
nativeContext.PixelShader.SetSamplers(_firstTexture, _textureCount, &_samplers[_firstTexture]);
|
NativeContext.PixelShader.SetSamplers(_firstTexture, _textureCount, &_samplers[_firstTexture]);
|
||||||
case typeof(VertexShader):
|
case typeof(VertexShader):
|
||||||
nativeContext.VertexShader.SetShaderResources(_firstTexture, _textureCount, &_textures[_firstTexture]);
|
NativeContext.VertexShader.SetShaderResources(_firstTexture, _textureCount, &_textures[_firstTexture]);
|
||||||
nativeContext.VertexShader.SetSamplers(_firstTexture, _textureCount, &_samplers[_firstTexture]);
|
NativeContext.VertexShader.SetSamplers(_firstTexture, _textureCount, &_samplers[_firstTexture]);
|
||||||
default:
|
default:
|
||||||
Runtime.FatalError(scope $"Shader stage \"{typeof(TShader)}\" not implemented.");
|
Runtime.FatalError(scope $"Shader stage \"{typeof(TShader)}\" not implemented.");
|
||||||
}
|
}
|
||||||
@@ -224,11 +234,11 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
// TODO: Add remaining shader stages
|
// TODO: Add remaining shader stages
|
||||||
case typeof(PixelShader):
|
case typeof(PixelShader):
|
||||||
nativeContext.PixelShader.SetConstantBuffers(0, shader.Buffers.nativeBuffers.Count, &shader.Buffers.nativeBuffers);
|
NativeContext.PixelShader.SetConstantBuffers(0, shader.Buffers.nativeBuffers.Count, &shader.Buffers.nativeBuffers);
|
||||||
[IgnoreErrors]{ nativeContext.PixelShader.SetShader(((PixelShader)shader).nativeShader); }
|
[IgnoreErrors]{ NativeContext.PixelShader.SetShader(((PixelShader)shader).nativeShader); }
|
||||||
case typeof(VertexShader):
|
case typeof(VertexShader):
|
||||||
nativeContext.VertexShader.SetConstantBuffers(0, shader.Buffers.nativeBuffers.Count, &shader.Buffers.nativeBuffers);
|
NativeContext.VertexShader.SetConstantBuffers(0, shader.Buffers.nativeBuffers.Count, &shader.Buffers.nativeBuffers);
|
||||||
[IgnoreErrors]{ nativeContext.VertexShader.SetShader(((VertexShader)shader).nativeShader); }
|
[IgnoreErrors]{ NativeContext.VertexShader.SetShader(((VertexShader)shader).nativeShader); }
|
||||||
default:
|
default:
|
||||||
Runtime.FatalError(scope $"Shader stage \"{typeof(TShader)}\" not implemented.");
|
Runtime.FatalError(scope $"Shader stage \"{typeof(TShader)}\" not implemented.");
|
||||||
}
|
}
|
||||||
@@ -245,3 +255,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
using DirectX.D3DCompiler;
|
using DirectX.D3DCompiler;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
@@ -14,7 +18,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "ps_5_0", DefaultCompileFlags, out nativeCode);
|
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "ps_5_0", DefaultCompileFlags, out nativeCode);
|
||||||
|
|
||||||
var result = _context.nativeDevice.CreatePixelShader(nativeCode.GetBufferPointer(), nativeCode.GetBufferSize(), null, &nativeShader);
|
var result = NativeDevice.CreatePixelShader(nativeCode.GetBufferPointer(), nativeCode.GetBufferSize(), null, &nativeShader);
|
||||||
if(result.Failed)
|
if(result.Failed)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Failed to create pixel shader: Message ({(int)result}): {result}");
|
Log.EngineLogger.Error($"Failed to create pixel shader: Message ({(int)result}): {result}");
|
||||||
@@ -24,3 +28,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
@@ -48,12 +52,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
internal DirectX.D3D11.RasterizerStateDescription nativeDescription;
|
internal DirectX.D3D11.RasterizerStateDescription nativeDescription;
|
||||||
internal ID3D11RasterizerState* nativeRasterizerState ~ _?.Release();
|
internal ID3D11RasterizerState* nativeRasterizerState ~ _?.Release();
|
||||||
|
|
||||||
public override this(GraphicsContext context, GlitchyEngine.Renderer.RasterizerStateDescription description) : this(context)
|
public override this(GlitchyEngine.Renderer.RasterizerStateDescription description)
|
||||||
{
|
{
|
||||||
_description = description;
|
_description = description;
|
||||||
nativeDescription = (.)_description;
|
nativeDescription = (.)_description;
|
||||||
|
|
||||||
var result = context.nativeDevice.CreateRasterizerState(ref nativeDescription, &nativeRasterizerState);
|
var result = NativeDevice.CreateRasterizerState(ref nativeDescription, &nativeRasterizerState);
|
||||||
if(result.Failed)
|
if(result.Failed)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Failed to create rasterizer state. Message({(int)result}): {result}");
|
Log.EngineLogger.Error($"Failed to create rasterizer state. Message({(int)result}): {result}");
|
||||||
@@ -61,3 +65,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
@@ -38,7 +43,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
if(_description.DepthStencilFormat != .None)
|
if(_description.DepthStencilFormat != .None)
|
||||||
{
|
{
|
||||||
_depthStenilTarget = new DepthStencilTarget(_context, _description.Width, _description.Height, _description.DepthStencilFormat);
|
_depthStenilTarget = new DepthStencilTarget(_description.Width, _description.Height, _description.DepthStencilFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +66,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
Usage = .Default
|
Usage = .Default
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = _context.nativeDevice.CreateTexture2D(ref desc, null, &_nativeTexture);
|
var result = NativeDevice.CreateTexture2D(ref desc, null, &_nativeTexture);
|
||||||
Log.EngineLogger.Assert(result.Succeeded, "Failed to create RenderTarget2D");
|
Log.EngineLogger.Assert(result.Succeeded, "Failed to create RenderTarget2D");
|
||||||
|
|
||||||
CreateViews();
|
CreateViews();
|
||||||
@@ -69,11 +74,13 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
private void CreateViews()
|
private void CreateViews()
|
||||||
{
|
{
|
||||||
var result = _context.nativeDevice.CreateShaderResourceView(_nativeTexture, null, &_nativeResourceView);
|
var result = NativeDevice.CreateShaderResourceView(_nativeTexture, null, &_nativeResourceView);
|
||||||
Log.EngineLogger.Assert(result.Succeeded, "Failed to create resource view");
|
Log.EngineLogger.Assert(result.Succeeded, "Failed to create resource view");
|
||||||
|
|
||||||
result = _context.nativeDevice.CreateRenderTargetView(_nativeTexture, null, &_nativeRenderTargetView);
|
result = NativeDevice.CreateRenderTargetView(_nativeTexture, null, &_nativeRenderTargetView);
|
||||||
Log.EngineLogger.Assert(result.Succeeded, "Failed to create render target view");
|
Log.EngineLogger.Assert(result.Succeeded, "Failed to create render target view");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using GlitchyEngine.Math;
|
using GlitchyEngine.Math;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
@@ -8,12 +12,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
extension RendererAPI
|
extension RendererAPI
|
||||||
{
|
{
|
||||||
private GraphicsContext _context;
|
private GraphicsContext _context ~ _?.ReleaseRef();
|
||||||
|
|
||||||
public GraphicsContext Context
|
public GraphicsContext Context
|
||||||
{
|
{
|
||||||
get => _context;
|
get => _context;
|
||||||
set => _context = value;
|
set => SetReference!(_context, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static override API Api => .D3D11;
|
public static override API Api => .D3D11;
|
||||||
@@ -30,12 +34,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public override void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
public override void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
||||||
{
|
{
|
||||||
_context.nativeContext.ClearDepthStencilView(target.nativeView, (.)clearFlags, depthValue, stencilValue);
|
NativeContext.ClearDepthStencilView(target.nativeView, (.)clearFlags, depthValue, stencilValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Clear(RenderTarget2D renderTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
public override void Clear(RenderTarget2D renderTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
||||||
{
|
{
|
||||||
_context.nativeContext.ClearDepthStencilView(renderTarget._depthStenilTarget.nativeView, (.)clearFlags, depthValue, stencilValue);
|
NativeContext.ClearDepthStencilView(renderTarget._depthStenilTarget.nativeView, (.)clearFlags, depthValue, stencilValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawIndexed(GeometryBinding geometry)
|
public override void DrawIndexed(GeometryBinding geometry)
|
||||||
@@ -48,7 +52,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public override void DrawIndexedInstanced(GeometryBinding geometry)
|
public override void DrawIndexedInstanced(GeometryBinding geometry)
|
||||||
{
|
{
|
||||||
_context.nativeContext.DrawIndexedInstanced(geometry.IndexCount, geometry.InstanceCount, geometry.IndexByteOffset, 0, 0);
|
NativeContext.DrawIndexedInstanced(geometry.IndexCount, geometry.InstanceCount, geometry.IndexByteOffset, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetViewport(Viewport viewport)
|
public override void SetViewport(Viewport viewport)
|
||||||
@@ -57,3 +61,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
using DirectX.D3D11;
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
|
using DirectX.D3D11;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace DirectX.D3D11
|
namespace DirectX.D3D11
|
||||||
{
|
{
|
||||||
@@ -73,8 +79,6 @@ namespace DirectX.D3D11
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
extension SamplerStateDescription
|
extension SamplerStateDescription
|
||||||
@@ -109,15 +113,17 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
_desc.ToNative(var nativeDesc);
|
_desc.ToNative(var nativeDesc);
|
||||||
|
|
||||||
HResult result = _context.nativeDevice.CreateSamplerState(ref nativeDesc, &nativeSamplerState);
|
HResult result = NativeDevice.CreateSamplerState(ref nativeDesc, &nativeSamplerState);
|
||||||
|
|
||||||
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create SamplerState. Error({(int)result}): {result}");
|
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create SamplerState. Error({(int)result}): {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Bind(uint32 slot)
|
public override void Bind(uint32 slot)
|
||||||
{
|
{
|
||||||
_context.nativeContext.VertexShader.SetSamplers(slot, 1, &nativeSamplerState);
|
NativeContext.VertexShader.SetSamplers(slot, 1, &nativeSamplerState);
|
||||||
_context.nativeContext.PixelShader.SetSamplers(slot, 1, &nativeSamplerState);
|
NativeContext.PixelShader.SetSamplers(slot, 1, &nativeSamplerState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using GlitchyEngine.Renderer;
|
using GlitchyEngine.Renderer;
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
@@ -79,7 +81,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
// ConstantBuffer
|
// ConstantBuffer
|
||||||
if(bufferDesc.Type == .D3D11_CT_CBUFFER)
|
if(bufferDesc.Type == .D3D11_CT_CBUFFER)
|
||||||
{
|
{
|
||||||
let buffer = new ConstantBuffer(_context, bufferReflection);
|
let buffer = new ConstantBuffer(bufferReflection);
|
||||||
|
|
||||||
_buffers.Add(bindDesc.BindPoint, buffer.Name, buffer);
|
_buffers.Add(bindDesc.BindPoint, buffer.Name, buffer);
|
||||||
|
|
||||||
@@ -98,3 +100,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
using DirectX.DXGI.DXGI1_2;
|
using DirectX.DXGI.DXGI1_2;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
public extension SwapChain
|
public extension SwapChain
|
||||||
{
|
{
|
||||||
private GraphicsContext _context;
|
private GraphicsContext _context ~ _.ReleaseRef();
|
||||||
|
|
||||||
private bool _changed;
|
private bool _changed;
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public this(GraphicsContext context)
|
public this(GraphicsContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context..AddRef();
|
||||||
|
|
||||||
SetResolutionFromWindow();
|
SetResolutionFromWindow();
|
||||||
}
|
}
|
||||||
@@ -107,7 +111,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_context.nativeDevice.QueryInterface(out nativeDxgiDevice);
|
NativeDevice.QueryInterface(out nativeDxgiDevice);
|
||||||
|
|
||||||
nativeDxgiDevice.GetAdapter(let adapter);
|
nativeDxgiDevice.GetAdapter(let adapter);
|
||||||
adapter.GetParent<DirectX.DXGI.IDXGIFactory2>(let factory);
|
adapter.GetParent<DirectX.DXGI.IDXGIFactory2>(let factory);
|
||||||
@@ -125,7 +129,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
SwapChainFullscreenDescription fsSwapChainDesc = .();
|
SwapChainFullscreenDescription fsSwapChainDesc = .();
|
||||||
fsSwapChainDesc.Windowed = true;
|
fsSwapChainDesc.Windowed = true;
|
||||||
|
|
||||||
var createResult = factory.CreateSwapChainForHwnd((.)_context.nativeDevice, _context.nativeWindowHandle, ref swDesc, &fsSwapChainDesc, null, &nativeSwapChain);
|
var createResult = factory.CreateSwapChainForHwnd((.)NativeDevice, _context.nativeWindowHandle, ref swDesc, &fsSwapChainDesc, null, &nativeSwapChain);
|
||||||
if(createResult.Failed)
|
if(createResult.Failed)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Failed to create swap chain. Message({(int)createResult}):{createResult}");
|
Log.EngineLogger.Error($"Failed to create swap chain. Message({(int)createResult}):{createResult}");
|
||||||
@@ -137,7 +141,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
nativeSwapChain.GetBuffer<ID3D11Texture2D>(0, let backBuffer);
|
nativeSwapChain.GetBuffer<ID3D11Texture2D>(0, let backBuffer);
|
||||||
|
|
||||||
RenderTargetViewDescription rtvDesc = .(backBuffer, .Texture2D, backBufferViewFormat);
|
RenderTargetViewDescription rtvDesc = .(backBuffer, .Texture2D, backBufferViewFormat);
|
||||||
_context.nativeDevice.CreateRenderTargetView(backBuffer, &rtvDesc, &nativeBackBufferTarget);
|
NativeDevice.CreateRenderTargetView(backBuffer, &rtvDesc, &nativeBackBufferTarget);
|
||||||
|
|
||||||
_backBufferViewport = GlitchyEngine.Renderer.Viewport(0, 0, _width, _height, 0.0f, 1.0f);
|
_backBufferViewport = GlitchyEngine.Renderer.Viewport(0, 0, _width, _height, 0.0f, 1.0f);
|
||||||
|
|
||||||
@@ -150,3 +154,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
@@ -9,6 +11,9 @@ using internal GlitchyEngine.Renderer;
|
|||||||
|
|
||||||
typealias NativeTex2DDesc = DirectX.D3D11.Texture2DDescription;
|
typealias NativeTex2DDesc = DirectX.D3D11.Texture2DDescription;
|
||||||
|
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
extension Texture
|
extension Texture
|
||||||
@@ -17,8 +22,9 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
protected override void ImplBind(uint32 slot)
|
protected override void ImplBind(uint32 slot)
|
||||||
{
|
{
|
||||||
_context.nativeContext.VertexShader.SetShaderResources(slot, 1, &nativeResourceView);
|
// TODO: textures don't bind themselves!
|
||||||
_context.nativeContext.PixelShader.SetShaderResources(slot, 1, &nativeResourceView);
|
NativeContext.VertexShader.SetShaderResources(slot, 1, &nativeResourceView);
|
||||||
|
NativeContext.PixelShader.SetShaderResources(slot, 1, &nativeResourceView);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Loads the texture from the specified path.
|
/** \brief Loads the texture from the specified path.
|
||||||
@@ -31,7 +37,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
((ID3D11Resource*)texture)?.Release();
|
((ID3D11Resource*)texture)?.Release();
|
||||||
nativeResourceView?.Release();
|
nativeResourceView?.Release();
|
||||||
|
|
||||||
HResult loadResult = DDSTextureLoader.CreateDDSTextureFromFile(_context.nativeDevice, path.ToScopedNativeWChar!(),
|
HResult loadResult = DDSTextureLoader.CreateDDSTextureFromFile(NativeDevice, path.ToScopedNativeWChar!(),
|
||||||
(.)&texture, &nativeResourceView);
|
(.)&texture, &nativeResourceView);
|
||||||
|
|
||||||
if(loadResult.Failed)
|
if(loadResult.Failed)
|
||||||
@@ -107,10 +113,10 @@ namespace GlitchyEngine.Renderer
|
|||||||
// If data is null, set subresourceData null
|
// If data is null, set subresourceData null
|
||||||
SubresourceData* resDataPtr = data == null ? null : &resData;
|
SubresourceData* resDataPtr = data == null ? null : &resData;
|
||||||
|
|
||||||
var result = _context.nativeDevice.CreateTexture2D(ref nativeDesc, resDataPtr, &nativeTexture);
|
var result = NativeDevice.CreateTexture2D(ref nativeDesc, resDataPtr, &nativeTexture);
|
||||||
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture 2D. Error ({result.Underlying}): {result}");
|
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture 2D. Error ({result.Underlying}): {result}");
|
||||||
|
|
||||||
result = _context.[Friend]nativeDevice.CreateShaderResourceView(nativeTexture, null, &nativeResourceView);
|
result = NativeDevice.CreateShaderResourceView(nativeTexture, null, &nativeResourceView);
|
||||||
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture view. Error ({result.Underlying}): {result}");
|
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to create texture view. Error ({result.Underlying}): {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +163,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
case .Default:
|
case .Default:
|
||||||
Box dataBox = .(destX, destY, 0, destX + destWidth, destY + destHeight, 1);
|
Box dataBox = .(destX, destY, 0, destX + destWidth, destY + destHeight, 1);
|
||||||
var rowPitch = elementSize * destWidth;
|
var rowPitch = elementSize * destWidth;
|
||||||
_context.nativeContext.UpdateSubresource(nativeTexture, subresourceIndex, &dataBox, data, rowPitch, rowPitch * destHeight);
|
NativeContext.UpdateSubresource(nativeTexture, subresourceIndex, &dataBox, data, rowPitch, rowPitch * destHeight);
|
||||||
case .Dynamic:
|
case .Dynamic:
|
||||||
Runtime.NotImplemented();
|
Runtime.NotImplemented();
|
||||||
/*
|
/*
|
||||||
@@ -202,7 +208,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
if(destination.nativeTexture == null)
|
if(destination.nativeTexture == null)
|
||||||
destination.InternalCreateTexture(null, 0, 0);
|
destination.InternalCreateTexture(null, 0, 0);
|
||||||
|
|
||||||
source._context.nativeContext.CopySubresourceRegion(destination.nativeTexture,
|
NativeContext.CopySubresourceRegion(destination.nativeTexture,
|
||||||
D3D11.CalcSubresource(destMipSlice, destArraySlice, destination.MipLevels), destX, destY, 0,
|
D3D11.CalcSubresource(destMipSlice, destArraySlice, destination.MipLevels), destX, destY, 0,
|
||||||
source.nativeTexture, D3D11.CalcSubresource(srcMipSlice, srcArraySlice, source.MipLevels), (.)&sourceBox);
|
source.nativeTexture, D3D11.CalcSubresource(srcMipSlice, srcArraySlice, source.MipLevels), (.)&sourceBox);
|
||||||
}
|
}
|
||||||
@@ -227,7 +233,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
Box sourceBox = .(0, 0, 0, Width, Height, 1);
|
Box sourceBox = .(0, 0, 0, Width, Height, 1);
|
||||||
|
|
||||||
_context.nativeContext.CopySubresourceRegion(destination.nativeTexture,
|
NativeContext.CopySubresourceRegion(destination.nativeTexture,
|
||||||
D3D11.CalcSubresource(mipSlice, arraySlice, destination.MipLevels), 0, 0, 0,
|
D3D11.CalcSubresource(mipSlice, arraySlice, destination.MipLevels), 0, 0, 0,
|
||||||
nativeTexture, D3D11.CalcSubresource(mipSlice, arraySlice, MipLevels), (.)&sourceBox);
|
nativeTexture, D3D11.CalcSubresource(mipSlice, arraySlice, MipLevels), (.)&sourceBox);
|
||||||
}
|
}
|
||||||
@@ -258,3 +264,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DirectX.D3D11;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using DirectX.Common;
|
using DirectX.Common;
|
||||||
|
using DirectX.D3D11;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
@@ -13,11 +17,10 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public ID3DBlob* nativeShaderCode ~ _?.Release();
|
public ID3DBlob* nativeShaderCode ~ _?.Release();
|
||||||
|
|
||||||
public this(GraphicsContext context, VertexElement[] elements, bool ownsElements, VertexShader vertexShader)
|
public this(VertexElement[] elements, bool ownsElements, VertexShader vertexShader)
|
||||||
{
|
{
|
||||||
nativeShaderCode = vertexShader.nativeCode..AddRef();
|
nativeShaderCode = vertexShader.nativeCode..AddRef();
|
||||||
|
|
||||||
_context = context..AddRef();
|
|
||||||
_elements = elements;
|
_elements = elements;
|
||||||
_ownsElements = ownsElements;
|
_ownsElements = ownsElements;
|
||||||
|
|
||||||
@@ -38,7 +41,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
ToNativeLayout(_elements, nativeElements);
|
ToNativeLayout(_elements, nativeElements);
|
||||||
|
|
||||||
var result = _context.nativeDevice.CreateInputLayout(nativeElements.CArray(), (.)nativeElements.Count, nativeShaderCode.GetBufferPointer(), nativeShaderCode.GetBufferSize(), &nativeLayout);
|
var result = NativeDevice.CreateInputLayout(nativeElements.CArray(), (.)nativeElements.Count, nativeShaderCode.GetBufferPointer(), nativeShaderCode.GetBufferSize(), &nativeLayout);
|
||||||
if(result.Failed)
|
if(result.Failed)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Failed to create D3D11 input layout: Message({(int)result}): {result}");
|
Log.EngineLogger.Error($"Failed to create D3D11 input layout: Message({(int)result}): {result}");
|
||||||
@@ -46,3 +49,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
#if GE_D3D11
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using GlitchyEngine.Renderer;
|
using GlitchyEngine.Renderer;
|
||||||
using DirectX.Common;
|
|
||||||
using DirectX.D3D11;
|
using DirectX.D3D11;
|
||||||
using DirectX.D3DCompiler;
|
using DirectX.D3DCompiler;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
using internal GlitchyEngine.Renderer;
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
namespace GlitchyEngine.Renderer
|
namespace GlitchyEngine.Renderer
|
||||||
{
|
{
|
||||||
@@ -16,7 +19,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "vs_5_0", DefaultCompileFlags, out nativeCode);
|
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "vs_5_0", DefaultCompileFlags, out nativeCode);
|
||||||
|
|
||||||
var result = _context.nativeDevice.CreateVertexShader(nativeCode.GetBufferPointer(), nativeCode.GetBufferSize(), null, &nativeShader);
|
var result = NativeDevice.CreateVertexShader(nativeCode.GetBufferPointer(), nativeCode.GetBufferSize(), null, &nativeShader);
|
||||||
if(result.Failed)
|
if(result.Failed)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Failed to create vertex shader: Message ({(int)result}): {result}");
|
Log.EngineLogger.Error($"Failed to create vertex shader: Message ({(int)result}): {result}");
|
||||||
@@ -26,3 +29,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -74,15 +74,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public class BlendState : RefCounter
|
public class BlendState : RefCounter
|
||||||
{
|
{
|
||||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
protected BlendStateDescription _desc;
|
protected BlendStateDescription _desc;
|
||||||
|
|
||||||
public BlendStateDescription Description => _desc;
|
public BlendStateDescription Description => _desc;
|
||||||
|
|
||||||
public this(GraphicsContext context, BlendStateDescription desc)
|
public this(BlendStateDescription desc)
|
||||||
{
|
{
|
||||||
_context = context..AddRef();
|
|
||||||
_desc = desc;
|
_desc = desc;
|
||||||
|
|
||||||
PlatformCreateBlendState();
|
PlatformCreateBlendState();
|
||||||
|
|||||||
@@ -83,24 +83,17 @@ namespace GlitchyEngine.Renderer
|
|||||||
/// Represents a buffer containing binary data on the GPU.
|
/// Represents a buffer containing binary data on the GPU.
|
||||||
public class Buffer : RefCounter
|
public class Buffer : RefCounter
|
||||||
{
|
{
|
||||||
internal GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
protected BufferDescription _description;
|
protected BufferDescription _description;
|
||||||
|
|
||||||
public GraphicsContext Context => _context;
|
|
||||||
|
|
||||||
public BufferDescription Description => _description;
|
public BufferDescription Description => _description;
|
||||||
|
|
||||||
protected this(GraphicsContext context)
|
protected this() { }
|
||||||
{
|
|
||||||
_context = context..AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of a Buffer.
|
* Creates a new instance of a Buffer.
|
||||||
* @param description The buffer description.
|
* @param description The buffer description.
|
||||||
*/
|
*/
|
||||||
public this(GraphicsContext context, BufferDescription description) : this(context)
|
public this(BufferDescription description)
|
||||||
{
|
{
|
||||||
_description = description;
|
_description = description;
|
||||||
}
|
}
|
||||||
@@ -162,10 +155,9 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of a Buffer<T>
|
* 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).
|
* @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)
|
public this(BufferDescription description)
|
||||||
{
|
{
|
||||||
_description = description;
|
_description = description;
|
||||||
_description.Size = (uint32)sizeof(T);
|
_description.Size = (uint32)sizeof(T);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public BufferVariableCollection Variables => _variables;
|
public BufferVariableCollection Variables => _variables;
|
||||||
|
|
||||||
protected this(GraphicsContext context) : base(context) {}
|
protected this() {}
|
||||||
|
|
||||||
protected internal void AddVariable(BufferVariable ownVariable)
|
protected internal void AddVariable(BufferVariable ownVariable)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public static bool DrawEntityTransforms = true;
|
public static bool DrawEntityTransforms = true;
|
||||||
|
|
||||||
public static void Init(GraphicsContext context)
|
public static void Init()
|
||||||
{
|
{
|
||||||
CreateCoordinateCross(context);
|
CreateCoordinateCross();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateCoordinateCross(GraphicsContext context)
|
private static void CreateCoordinateCross()
|
||||||
{
|
{
|
||||||
CoordinateCross = new GeometryBinding(context);
|
CoordinateCross = new GeometryBinding();
|
||||||
//CoordinateCross.PrimitiveTopology
|
//CoordinateCross.PrimitiveTopology
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
// TODO: add all features.
|
// TODO: add all features.
|
||||||
public class DepthStencilTarget : RefCounter
|
public class DepthStencilTarget : RefCounter
|
||||||
{
|
{
|
||||||
protected internal GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
protected uint32 _width, _height;
|
protected uint32 _width, _height;
|
||||||
protected DepthStencilFormat _format;
|
protected DepthStencilFormat _format;
|
||||||
|
|
||||||
@@ -23,11 +21,10 @@ namespace GlitchyEngine.Renderer
|
|||||||
public uint32 Height => _height;
|
public uint32 Height => _height;
|
||||||
public DepthStencilFormat Format => _format;
|
public DepthStencilFormat Format => _format;
|
||||||
|
|
||||||
public this(GraphicsContext context, uint32 width, uint32 height, DepthStencilFormat format = .D32_Float)
|
public this(uint32 width, uint32 height, DepthStencilFormat format = .D32_Float)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Assert(format != .None, "DepthStencilFormat None is only valid for RenderTarget");
|
Log.EngineLogger.Assert(format != .None, "DepthStencilFormat None is only valid for RenderTarget");
|
||||||
|
|
||||||
_context = context..AddRef();
|
|
||||||
_width = width;
|
_width = width;
|
||||||
_height = height;
|
_height = height;
|
||||||
_format = format;
|
_format = format;
|
||||||
@@ -36,9 +33,5 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected extern void PlatformCreate();
|
protected extern void PlatformCreate();
|
||||||
|
|
||||||
public extern void Bind();
|
|
||||||
|
|
||||||
public extern void Clear(float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
public class EffectLibrary
|
public class EffectLibrary
|
||||||
{
|
{
|
||||||
private GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
private Dictionary<String, Effect> _effects = new .() ~ delete _;
|
private Dictionary<String, Effect> _effects = new .() ~ delete _;
|
||||||
|
|
||||||
private List<String> _ownedStrings = new .() ~ DeleteContainerAndItems!(_);
|
private List<String> _ownedStrings = new .() ~ DeleteContainerAndItems!(_);
|
||||||
|
|
||||||
public this(GraphicsContext context)
|
public this()
|
||||||
{
|
{
|
||||||
_context = context..AddRef();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ~this()
|
public ~this()
|
||||||
@@ -63,7 +61,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
Log.EngineLogger.AssertDebug(!Exists(name), "Can't add two effects with the same name to library.");
|
Log.EngineLogger.AssertDebug(!Exists(name), "Can't add two effects with the same name to library.");
|
||||||
|
|
||||||
Effect effect = new Effect(_context, filepath, name);
|
Effect effect = new Effect(filepath, name);
|
||||||
Add(effect);
|
Add(effect);
|
||||||
|
|
||||||
return effect;
|
return effect;
|
||||||
@@ -92,7 +90,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public class Effect : RefCounter
|
public class Effect : RefCounter
|
||||||
{
|
{
|
||||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
internal VertexShader _vs ~ _?.ReleaseRef();
|
internal VertexShader _vs ~ _?.ReleaseRef();
|
||||||
internal PixelShader _ps ~ _?.ReleaseRef();
|
internal PixelShader _ps ~ _?.ReleaseRef();
|
||||||
protected String _name ~ delete _;
|
protected String _name ~ delete _;
|
||||||
@@ -104,8 +101,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
typealias TextureEntry = (Texture Texture, ShaderTextureCollection.ResourceEntry* VsSlot, ShaderTextureCollection.ResourceEntry* PsSlot);
|
typealias TextureEntry = (Texture Texture, ShaderTextureCollection.ResourceEntry* VsSlot, ShaderTextureCollection.ResourceEntry* PsSlot);
|
||||||
Dictionary<String, TextureEntry> _textures ~ delete _;
|
Dictionary<String, TextureEntry> _textures ~ delete _;
|
||||||
|
|
||||||
public GraphicsContext Context => _context;
|
|
||||||
|
|
||||||
public Dictionary<String, TextureEntry> Textures => _textures;
|
public Dictionary<String, TextureEntry> Textures => _textures;
|
||||||
|
|
||||||
public VertexShader VertexShader
|
public VertexShader VertexShader
|
||||||
@@ -140,9 +135,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public this(GraphicsContext context, String filename, String vsEntry, String psEntry, String shaderName = null)
|
public this(String filename, String vsEntry, String psEntry, String shaderName = null)
|
||||||
{
|
{
|
||||||
_context = context..AddRef();
|
|
||||||
CompileFromFile(filename, vsEntry, psEntry);
|
CompileFromFile(filename, vsEntry, psEntry);
|
||||||
|
|
||||||
if(shaderName == null)
|
if(shaderName == null)
|
||||||
@@ -156,10 +150,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public this(GraphicsContext context, String filename, String shaderName = null)
|
public this(String filename, String shaderName = null)
|
||||||
{
|
{
|
||||||
_context = context..AddRef();
|
|
||||||
|
|
||||||
String fileContent = scope String();
|
String fileContent = scope String();
|
||||||
String vsName = scope String();
|
String vsName = scope String();
|
||||||
String psName = scope String();
|
String psName = scope String();
|
||||||
@@ -243,10 +235,10 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
private void CompileFromFile(String filename, String vsEntry, String psEntry)
|
private void CompileFromFile(String filename, String vsEntry, String psEntry)
|
||||||
{
|
{
|
||||||
let vs = Shader.FromFile!<VertexShader>(_context, filename, vsEntry);
|
let vs = Shader.FromFile!<VertexShader>(filename, vsEntry);
|
||||||
VertexShader = vs;
|
VertexShader = vs;
|
||||||
vs.ReleaseRef();
|
vs.ReleaseRef();
|
||||||
let ps = Shader.FromFile!<PixelShader>(_context, filename, psEntry);
|
let ps = Shader.FromFile!<PixelShader>(filename, psEntry);
|
||||||
PixelShader = ps;
|
PixelShader = ps;
|
||||||
ps.ReleaseRef();
|
ps.ReleaseRef();
|
||||||
}
|
}
|
||||||
@@ -254,10 +246,10 @@ namespace GlitchyEngine.Renderer
|
|||||||
private void Compile(String fileContent, String vsEntry, String psEntry)
|
private void Compile(String fileContent, String vsEntry, String psEntry)
|
||||||
{
|
{
|
||||||
// TODO: vsEntry and psEntry could be empty (which is a valid case.)
|
// TODO: vsEntry and psEntry could be empty (which is a valid case.)
|
||||||
let vs = new VertexShader(_context, fileContent, vsEntry);
|
let vs = new VertexShader(fileContent, vsEntry);
|
||||||
VertexShader = vs;
|
VertexShader = vs;
|
||||||
vs.ReleaseRef();
|
vs.ReleaseRef();
|
||||||
let ps = new PixelShader(_context, fileContent, psEntry);
|
let ps = new PixelShader(fileContent, psEntry);
|
||||||
PixelShader = ps;
|
PixelShader = ps;
|
||||||
ps.ReleaseRef();
|
ps.ReleaseRef();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
public class GeometryBinding : RefCounter
|
public class GeometryBinding : RefCounter
|
||||||
{
|
{
|
||||||
internal GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
internal List<VertexBufferBinding> _vertexBuffers = new .() ~ delete _;
|
internal List<VertexBufferBinding> _vertexBuffers = new .() ~ delete _;
|
||||||
internal IndexBuffer _indexBuffer ~ _?.ReleaseRef();
|
internal IndexBuffer _indexBuffer ~ _?.ReleaseRef();
|
||||||
internal VertexLayout _vertexLayout ~ _?.ReleaseRef();
|
internal VertexLayout _vertexLayout ~ _?.ReleaseRef();
|
||||||
@@ -19,9 +17,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public bool IsIndexed => _indexBuffer != null;
|
public bool IsIndexed => _indexBuffer != null;
|
||||||
|
|
||||||
public this(GraphicsContext context)
|
public this()
|
||||||
{
|
{
|
||||||
_context = context..AddRef();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ~this()
|
public ~this()
|
||||||
@@ -120,8 +117,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
protected extern void PlatformSetIndexBuffer(IndexBuffer indexBuffer);
|
protected extern void PlatformSetIndexBuffer(IndexBuffer indexBuffer);
|
||||||
|
|
||||||
public extern void Bind(GraphicsContext context = null);
|
public extern void Bind();
|
||||||
|
|
||||||
public extern void Unbind(GraphicsContext context = null);
|
public extern void Unbind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ namespace GlitchyEngine.Renderer
|
|||||||
private RasterizerState _currentRasterizerState;
|
private RasterizerState _currentRasterizerState;
|
||||||
|
|
||||||
public extern SwapChain SwapChain {get;}
|
public extern SwapChain SwapChain {get;}
|
||||||
|
|
||||||
|
protected extern void PlatformConstruct();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of simultaneous rendertargets supported.
|
* The maximum number of simultaneous rendertargets supported.
|
||||||
*/
|
*/
|
||||||
@@ -17,6 +19,13 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public extern void Init();
|
public extern void Init();
|
||||||
|
|
||||||
|
/** @brief Sets a depthtarget.
|
||||||
|
* @BindRenderTargets has to be called in order to bind the rendertargets.
|
||||||
|
* @param renderTarget The render target to set. If null, the backbuffer will be set.
|
||||||
|
* @param slot The slot to which the rendertarget will be bound. If 0 the depth buffer of the current render target will be set. If it has no depthbuffer the current will be unset.
|
||||||
|
*/
|
||||||
|
public extern void SetDepthStencilTarget(DepthStencilTarget target);
|
||||||
|
|
||||||
/** @brief Sets a rendertarget to the given slot.
|
/** @brief Sets a rendertarget to the given slot.
|
||||||
* @BindRenderTargets has to be called in order to bind the rendertargets.
|
* @BindRenderTargets has to be called in order to bind the rendertargets.
|
||||||
* @param renderTarget The render target to set. If null, the backbuffer will be set.
|
* @param renderTarget The render target to set. If null, the backbuffer will be set.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
public uint32 IndexCount => _indexCount;
|
public uint32 IndexCount => _indexCount;
|
||||||
public IndexFormat Format => _format;
|
public IndexFormat Format => _format;
|
||||||
|
|
||||||
public this(GraphicsContext context, uint32 indexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None, IndexFormat indexFormat = .Index16Bit) : base(context)
|
public this(uint32 indexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None, IndexFormat indexFormat = .Index16Bit)
|
||||||
{
|
{
|
||||||
_indexCount = indexCount;
|
_indexCount = indexCount;
|
||||||
_format = indexFormat;
|
_format = indexFormat;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
public class PixelShader : Shader
|
public class PixelShader : Shader
|
||||||
{
|
{
|
||||||
[AllowAppend]
|
[AllowAppend]
|
||||||
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
|
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||||
: base(context, source, entryPoint, macros) { }
|
: base(source, entryPoint, macros) { }
|
||||||
|
|
||||||
public override extern void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
|
public override extern void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,17 +54,10 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public class RasterizerState : RefCounter
|
public class RasterizerState : RefCounter
|
||||||
{
|
{
|
||||||
internal GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
private RasterizerStateDescription _description;
|
private RasterizerStateDescription _description;
|
||||||
|
|
||||||
public GraphicsContext Context => _context;
|
|
||||||
public RasterizerStateDescription Description => _description;
|
public RasterizerStateDescription Description => _description;
|
||||||
|
|
||||||
protected this(GraphicsContext context)
|
public extern this(RasterizerStateDescription description);
|
||||||
{
|
|
||||||
_context = context..AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
public extern this(GraphicsContext context, RasterizerStateDescription description);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public class RenderTarget2D : RefCounter
|
public class RenderTarget2D : RefCounter
|
||||||
{
|
{
|
||||||
internal GraphicsContext _context;
|
|
||||||
|
|
||||||
private RenderTarget2DDescription _description;
|
private RenderTarget2DDescription _description;
|
||||||
|
|
||||||
public RenderTarget2DDescription Description => _description;
|
public RenderTarget2DDescription Description => _description;
|
||||||
@@ -63,9 +61,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public this(GraphicsContext context, RenderTarget2DDescription description)
|
public this(RenderTarget2DDescription description)
|
||||||
{
|
{
|
||||||
_context = context;
|
|
||||||
_description = description;
|
_description = description;
|
||||||
|
|
||||||
ApplyChanges();
|
ApplyChanges();
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
_context = context..AddRef();
|
_context = context..AddRef();
|
||||||
/*
|
/*
|
||||||
_sceneConstants = new Buffer<SceneConstants>(_context, .(0, .Constant, .Dynamic, .Write));
|
_sceneConstants = new Buffer<SceneConstants>(.(0, .Constant, .Dynamic, .Write));
|
||||||
_sceneConstants.Update();
|
_sceneConstants.Update();
|
||||||
|
|
||||||
_objectConstants = new Buffer<ObjectConstants>(_context, .(0, .Constant, .Dynamic, .Write));
|
_objectConstants = new Buffer<ObjectConstants>(.(0, .Constant, .Dynamic, .Write));
|
||||||
_objectConstants.Update();
|
_objectConstants.Update();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -53,23 +53,23 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
LineEffect = effectLibrary.Load("content\\Shaders\\lineShader.hlsl");
|
LineEffect = effectLibrary.Load("content\\Shaders\\lineShader.hlsl");
|
||||||
|
|
||||||
LineGeometry = new GeometryBinding(_context);
|
LineGeometry = new GeometryBinding();
|
||||||
LineGeometry.SetPrimitiveTopology(.LineList);
|
LineGeometry.SetPrimitiveTopology(.LineList);
|
||||||
|
|
||||||
Vector4[2] vertices = .(.Zero, .Zero);
|
Vector4[2] vertices = .(.Zero, .Zero);
|
||||||
LineVertices = new VertexBuffer(_context, sizeof(Vector4), 2, .Dynamic, .Write);
|
LineVertices = new VertexBuffer(sizeof(Vector4), 2, .Dynamic, .Write);
|
||||||
LineVertices.SetData<Vector4>(vertices, 0, .WriteDiscard);
|
LineVertices.SetData<Vector4>(vertices, 0, .WriteDiscard);
|
||||||
LineGeometry.SetVertexBufferSlot(LineVertices, 0);
|
LineGeometry.SetVertexBufferSlot(LineVertices, 0);
|
||||||
|
|
||||||
uint16[2] indices = .(0, 1);
|
uint16[2] indices = .(0, 1);
|
||||||
IndexBuffer indexBuffer = new IndexBuffer(_context, 2, .Immutable);
|
IndexBuffer indexBuffer = new IndexBuffer(2, .Immutable);
|
||||||
indexBuffer.SetData(indices);
|
indexBuffer.SetData(indices);
|
||||||
LineGeometry.SetIndexBuffer(indexBuffer);
|
LineGeometry.SetIndexBuffer(indexBuffer);
|
||||||
indexBuffer.ReleaseRef();
|
indexBuffer.ReleaseRef();
|
||||||
|
|
||||||
VertexElement[] vertexElements = new VertexElement[1];
|
VertexElement[] vertexElements = new VertexElement[1];
|
||||||
vertexElements[0] = .(.R32G32B32_Float, "POSITION");
|
vertexElements[0] = .(.R32G32B32_Float, "POSITION");
|
||||||
VertexLayout layout = new VertexLayout(_context, vertexElements, true, LineEffect.VertexShader);
|
VertexLayout layout = new VertexLayout(vertexElements, true, LineEffect.VertexShader);
|
||||||
LineGeometry.SetVertexLayout(layout..ReleaseRefNoDelete());
|
LineGeometry.SetVertexLayout(layout..ReleaseRefNoDelete());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,15 +107,15 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
private static void InitEffect()
|
private static void InitEffect()
|
||||||
{
|
{
|
||||||
s_textureColorEffect = new Effect(Renderer._context, "content\\Shaders\\textureColor.hlsl");
|
s_textureColorEffect = new Effect("content\\Shaders\\textureColor.hlsl");
|
||||||
s_batchEffect = new Effect(Renderer._context, "content\\Shaders\\spritebatch.hlsl");
|
s_batchEffect = new Effect("content\\Shaders\\spritebatch.hlsl");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InitGeometry()
|
private static void InitGeometry()
|
||||||
{
|
{
|
||||||
VertexLayout layout = new VertexLayout(Renderer._context, QuadVertex.VertexElements, false, s_textureColorEffect.VertexShader);
|
VertexLayout layout = new VertexLayout(QuadVertex.VertexElements, false, s_textureColorEffect.VertexShader);
|
||||||
|
|
||||||
VertexBuffer quadVertices = new VertexBuffer(Renderer._context, typeof(QuadVertex), 4, .Immutable);
|
VertexBuffer quadVertices = new VertexBuffer(typeof(QuadVertex), 4, .Immutable);
|
||||||
|
|
||||||
QuadVertex[4] vertices = .(
|
QuadVertex[4] vertices = .(
|
||||||
.(-0.5f,-0.5f, 0, 1),
|
.(-0.5f,-0.5f, 0, 1),
|
||||||
@@ -126,7 +126,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
quadVertices.SetData(vertices);
|
quadVertices.SetData(vertices);
|
||||||
|
|
||||||
IndexBuffer quadIndices = new IndexBuffer(Renderer._context, 6, .Immutable);
|
IndexBuffer quadIndices = new IndexBuffer(6, .Immutable);
|
||||||
|
|
||||||
uint16[6] indices = .(
|
uint16[6] indices = .(
|
||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
@@ -135,7 +135,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
quadIndices.SetData(indices);
|
quadIndices.SetData(indices);
|
||||||
|
|
||||||
s_quadGeometry = new GeometryBinding(Renderer._context);
|
s_quadGeometry = new GeometryBinding();
|
||||||
s_quadGeometry.SetVertexLayout(layout..ReleaseRefNoDelete());
|
s_quadGeometry.SetVertexLayout(layout..ReleaseRefNoDelete());
|
||||||
s_quadGeometry.SetPrimitiveTopology(.TriangleList);
|
s_quadGeometry.SetPrimitiveTopology(.TriangleList);
|
||||||
s_quadGeometry.SetVertexBufferSlot(quadVertices, 0);
|
s_quadGeometry.SetVertexBufferSlot(quadVertices, 0);
|
||||||
@@ -147,7 +147,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
private static void InitInstancingGeometry()
|
private static void InitInstancingGeometry()
|
||||||
{
|
{
|
||||||
s_instanceBuffer = new VertexBuffer(Renderer._context, typeof(BatchVertex), 1024, .Dynamic, .Write);
|
s_instanceBuffer = new VertexBuffer(typeof(BatchVertex), 1024, .Dynamic, .Write);
|
||||||
s_instanceBuffer.SetData(0);
|
s_instanceBuffer.SetData(0);
|
||||||
|
|
||||||
VertexElement[] vertexElements = new .(
|
VertexElement[] vertexElements = new .(
|
||||||
@@ -162,9 +162,9 @@ namespace GlitchyEngine.Renderer
|
|||||||
VertexElement(.R32G32B32A32_Float, "TEXCOORD", false, 1, 1, (.)-1, .PerInstanceData, 1)
|
VertexElement(.R32G32B32A32_Float, "TEXCOORD", false, 1, 1, (.)-1, .PerInstanceData, 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
VertexLayout batchLayout = new VertexLayout(Renderer._context, vertexElements, true, s_batchEffect.VertexShader);
|
VertexLayout batchLayout = new VertexLayout(vertexElements, true, s_batchEffect.VertexShader);
|
||||||
|
|
||||||
s_batchBinding = new GeometryBinding(Renderer._context);
|
s_batchBinding = new GeometryBinding();
|
||||||
s_batchBinding.SetVertexLayout(batchLayout..ReleaseRefNoDelete());
|
s_batchBinding.SetVertexLayout(batchLayout..ReleaseRefNoDelete());
|
||||||
s_batchBinding.SetPrimitiveTopology(.TriangleList);
|
s_batchBinding.SetPrimitiveTopology(.TriangleList);
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
Usage = .Immutable,
|
Usage = .Immutable,
|
||||||
CpuAccess = .None
|
CpuAccess = .None
|
||||||
};
|
};
|
||||||
s_whiteTexture = new Texture2D(Renderer._context, tex2Ddesc);
|
s_whiteTexture = new Texture2D(tex2Ddesc);
|
||||||
|
|
||||||
Color color = .White;
|
Color color = .White;
|
||||||
s_whiteTexture.SetData(&color);
|
s_whiteTexture.SetData(&color);
|
||||||
@@ -304,7 +304,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
s_currentEffect.Bind(Renderer._context);
|
s_currentEffect.Bind(Renderer._context);
|
||||||
s_batchBinding.InstanceCount = s_setInstances;
|
s_batchBinding.InstanceCount = s_setInstances;
|
||||||
s_batchBinding.Bind(Renderer._context);
|
s_batchBinding.Bind();
|
||||||
RenderCommand.DrawIndexedInstanced(s_batchBinding);
|
RenderCommand.DrawIndexedInstanced(s_batchBinding);
|
||||||
|
|
||||||
s_setInstances = 0;
|
s_setInstances = 0;
|
||||||
@@ -389,7 +389,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
s_textureColorEffect.Bind(Renderer._context);
|
s_textureColorEffect.Bind(Renderer._context);
|
||||||
|
|
||||||
s_quadGeometry.Bind(Renderer._context);
|
s_quadGeometry.Bind();
|
||||||
RenderCommand.DrawIndexed(s_quadGeometry);
|
RenderCommand.DrawIndexed(s_quadGeometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,8 +153,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public static class SamplerStateManager
|
public static class SamplerStateManager
|
||||||
{
|
{
|
||||||
static GraphicsContext _context;
|
|
||||||
|
|
||||||
static Dictionary<SamplerStateDescription, SamplerState> _samplers;
|
static Dictionary<SamplerStateDescription, SamplerState> _samplers;
|
||||||
|
|
||||||
public static SamplerState PointClamp;
|
public static SamplerState PointClamp;
|
||||||
@@ -164,9 +162,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
public static SamplerState AnisotropicClamp;
|
public static SamplerState AnisotropicClamp;
|
||||||
public static SamplerState AnisotropicWrap;
|
public static SamplerState AnisotropicWrap;
|
||||||
|
|
||||||
public static void Init(GraphicsContext context)
|
public static void Init()
|
||||||
{
|
{
|
||||||
_context = context..AddRef();
|
|
||||||
_samplers = new .();
|
_samplers = new .();
|
||||||
|
|
||||||
// Init point samplers
|
// Init point samplers
|
||||||
@@ -240,8 +237,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
AnisotropicClamp.ReleaseRef();
|
AnisotropicClamp.ReleaseRef();
|
||||||
AnisotropicWrap.ReleaseRef();
|
AnisotropicWrap.ReleaseRef();
|
||||||
|
|
||||||
_context?.ReleaseRef();
|
|
||||||
|
|
||||||
delete _samplers;
|
delete _samplers;
|
||||||
_samplers = null;
|
_samplers = null;
|
||||||
}
|
}
|
||||||
@@ -261,7 +256,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
return sampler..AddRef();
|
return sampler..AddRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
SamplerState newState = new SamplerState(_context, desc);
|
SamplerState newState = new SamplerState(desc);
|
||||||
ManageSampler(newState);
|
ManageSampler(newState);
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
@@ -288,8 +283,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public class SamplerState : RefCounter
|
public class SamplerState : RefCounter
|
||||||
{
|
{
|
||||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
protected SamplerStateDescription _desc;
|
protected SamplerStateDescription _desc;
|
||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
@@ -304,12 +297,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
[Inline]
|
[Inline]
|
||||||
public SamplerStateDescription Description => _desc;
|
public SamplerStateDescription Description => _desc;
|
||||||
|
|
||||||
protected this(GraphicsContext context)
|
public this(SamplerStateDescription desc)
|
||||||
{
|
|
||||||
_context = context..AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
public this(GraphicsContext context, SamplerStateDescription desc) : this(context)
|
|
||||||
{
|
{
|
||||||
_desc = desc;
|
_desc = desc;
|
||||||
|
|
||||||
|
|||||||
@@ -21,27 +21,22 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public abstract class Shader : RefCounter
|
public abstract class Shader : RefCounter
|
||||||
{
|
{
|
||||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
protected BufferCollection _buffers ~ delete _;//:append _;
|
protected BufferCollection _buffers ~ delete _;//:append _;
|
||||||
|
|
||||||
protected ShaderTextureCollection _textures ~ delete _;
|
protected ShaderTextureCollection _textures ~ delete _;
|
||||||
|
|
||||||
public GraphicsContext Context => _context;
|
|
||||||
|
|
||||||
public BufferCollection Buffers => _buffers;
|
public BufferCollection Buffers => _buffers;
|
||||||
|
|
||||||
public ShaderTextureCollection Textures => _textures;
|
public ShaderTextureCollection Textures => _textures;
|
||||||
|
|
||||||
[AllowAppend]
|
[AllowAppend]
|
||||||
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
|
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||||
{
|
{
|
||||||
// Todo: append as soon as it's fixed.
|
// Todo: append as soon as it's fixed.
|
||||||
//let buffers = new BufferCollection();
|
//let buffers = new BufferCollection();
|
||||||
_buffers = new BufferCollection();
|
_buffers = new BufferCollection();
|
||||||
_textures = new ShaderTextureCollection();
|
_textures = new ShaderTextureCollection();
|
||||||
|
|
||||||
_context = context..AddRef();
|
|
||||||
CompileFromSource(source, entryPoint);
|
CompileFromSource(source, entryPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +45,12 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static mixin FromFile<T>(GraphicsContext context, String fileName, String entryPoint, ShaderDefine[] macros = null) where T : Shader
|
public static mixin FromFile<T>(String fileName, String entryPoint, ShaderDefine[] macros = null) where T : Shader
|
||||||
{
|
{
|
||||||
String fileContent = new String();
|
String fileContent = new String();
|
||||||
|
|
||||||
File.ReadAllText(fileName, fileContent, true);
|
File.ReadAllText(fileName, fileContent, true);
|
||||||
T shader = new T(context, fileContent, entryPoint, macros);
|
T shader = new T(fileContent, entryPoint, macros);
|
||||||
|
|
||||||
delete fileContent;
|
delete fileContent;
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ namespace GlitchyEngine.Renderer.Text
|
|||||||
public bool IsRendered = false;
|
public bool IsRendered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GraphicsContext _context ~ _.ReleaseRef();
|
|
||||||
internal FT_Face _face ~ FreeType.Done_Face(_face);
|
internal FT_Face _face ~ FreeType.Done_Face(_face);
|
||||||
|
|
||||||
private Font _fallback ~ _?.ReleaseRef();
|
private Font _fallback ~ _?.ReleaseRef();
|
||||||
@@ -106,13 +105,11 @@ namespace GlitchyEngine.Renderer.Text
|
|||||||
return (double(value) / 64.0);
|
return (double(value) / 64.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public this(GraphicsContext context, String fontPath, uint32 fontSize, bool hasColor = true, char32 firstChar = '\0', uint32 charCount = 128, int32 faceIndex = 0)
|
public this(String fontPath, uint32 fontSize, bool hasColor = true, char32 firstChar = '\0', uint32 charCount = 128, int32 faceIndex = 0)
|
||||||
{
|
{
|
||||||
// Make sure the fontrenderer is initialized (Font only cares about freetype)
|
// Make sure the fontrenderer is initialized (Font only cares about freetype)
|
||||||
FontRenderer.Init();
|
FontRenderer.Init();
|
||||||
|
|
||||||
_context = context..AddRef();
|
|
||||||
|
|
||||||
// Set default sampler
|
// Set default sampler
|
||||||
Sampler = null;
|
Sampler = null;
|
||||||
|
|
||||||
@@ -317,7 +314,7 @@ namespace GlitchyEngine.Renderer.Text
|
|||||||
desc.CpuAccess = .None;
|
desc.CpuAccess = .None;
|
||||||
desc.Usage = .Default;
|
desc.Usage = .Default;
|
||||||
|
|
||||||
_atlas = new Texture2D(_context, desc);
|
_atlas = new Texture2D(desc);
|
||||||
_atlas.SamplerState = _sampler;
|
_atlas.SamplerState = _sampler;
|
||||||
|
|
||||||
if(oldAtlas != null)
|
if(oldAtlas != null)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace GlitchyEngine.Renderer.Text
|
|||||||
|
|
||||||
InitFreetype();
|
InitFreetype();
|
||||||
|
|
||||||
_msdfEffect = new Effect(Renderer._context, "content\\Shaders\\msdfShader.hlsl");
|
_msdfEffect = new Effect("content\\Shaders\\msdfShader.hlsl");
|
||||||
|
|
||||||
s_isInitialized = true;
|
s_isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
public abstract class Texture : RefCounter
|
public abstract class Texture : RefCounter
|
||||||
{
|
{
|
||||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
protected SamplerState _samplerState ~ _?.ReleaseRef();
|
protected SamplerState _samplerState ~ _?.ReleaseRef();
|
||||||
|
|
||||||
public GraphicsContext Context => _context;
|
|
||||||
|
|
||||||
public SamplerState SamplerState
|
public SamplerState SamplerState
|
||||||
{
|
{
|
||||||
get => _samplerState;
|
get => _samplerState;
|
||||||
@@ -41,11 +37,6 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected extern void ImplBind(uint32 slot);
|
protected extern void ImplBind(uint32 slot);
|
||||||
|
|
||||||
protected this(GraphicsContext context)
|
|
||||||
{
|
|
||||||
_context = context..AddRef();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Texture2DDesc
|
public struct Texture2DDesc
|
||||||
@@ -69,15 +60,13 @@ namespace GlitchyEngine.Renderer
|
|||||||
public override extern uint32 ArraySize {get;}
|
public override extern uint32 ArraySize {get;}
|
||||||
public override extern uint32 MipLevels {get;}
|
public override extern uint32 MipLevels {get;}
|
||||||
|
|
||||||
protected this(GraphicsContext context) : base(context) {}
|
public this(String path)
|
||||||
|
|
||||||
public this(GraphicsContext context, String path) : base(context)
|
|
||||||
{
|
{
|
||||||
this._path = new String(path);
|
this._path = new String(path);
|
||||||
LoadTexturePlatform();
|
LoadTexturePlatform();
|
||||||
}
|
}
|
||||||
|
|
||||||
public this(GraphicsContext context, Texture2DDesc desc) : base(context)
|
public this(Texture2DDesc desc)
|
||||||
{
|
{
|
||||||
PrepareTexturePlatform(desc, false);
|
PrepareTexturePlatform(desc, false);
|
||||||
}
|
}
|
||||||
@@ -132,9 +121,7 @@ namespace GlitchyEngine.Renderer
|
|||||||
public override extern uint32 ArraySize {get;}
|
public override extern uint32 ArraySize {get;}
|
||||||
public override extern uint32 MipLevels {get;}
|
public override extern uint32 MipLevels {get;}
|
||||||
|
|
||||||
protected this(GraphicsContext context) : base(context) {}
|
public this(String path)
|
||||||
|
|
||||||
public this(GraphicsContext context, String path) : base(context)
|
|
||||||
{
|
{
|
||||||
this._path = new String(path);
|
this._path = new String(path);
|
||||||
LoadTexturePlatform();
|
LoadTexturePlatform();
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public VertexBufferBinding Binding => _defaultBinding;
|
public VertexBufferBinding Binding => _defaultBinding;
|
||||||
|
|
||||||
public this(GraphicsContext context, Type vertexType, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None) :
|
public this(Type vertexType, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None) :
|
||||||
this(context, (.)vertexType.Stride, vertexCount, usage, cpuAccess)
|
this((.)vertexType.Stride, vertexCount, usage, cpuAccess)
|
||||||
{
|
{
|
||||||
_vertexType = vertexType;
|
_vertexType = vertexType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public this(GraphicsContext context, uint32 vertexStride, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None) : base(context)
|
public this(uint32 vertexStride, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None)
|
||||||
{
|
{
|
||||||
_vertexType = null;
|
_vertexType = null;
|
||||||
|
|
||||||
|
|||||||
@@ -81,24 +81,11 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public class VertexLayout : RefCounter
|
public class VertexLayout : RefCounter
|
||||||
{
|
{
|
||||||
private GraphicsContext _context ~ _?.ReleaseRef();
|
|
||||||
|
|
||||||
private VertexElement[] _elements;
|
private VertexElement[] _elements;
|
||||||
private bool _ownsElements;
|
private bool _ownsElements;
|
||||||
|
|
||||||
public GraphicsContext Context => _context;
|
|
||||||
|
|
||||||
public VertexElement[] Elements => _elements;
|
public VertexElement[] Elements => _elements;
|
||||||
|
|
||||||
public this(GraphicsContext context, VertexElement[] elements, bool ownsElements, VertexShader vertexShader)
|
|
||||||
{
|
|
||||||
_context = context..AddRef();
|
|
||||||
_elements = elements;
|
|
||||||
_ownsElements = ownsElements;
|
|
||||||
|
|
||||||
CreateNativeLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ~this()
|
public ~this()
|
||||||
{
|
{
|
||||||
if(_ownsElements)
|
if(_ownsElements)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
public class VertexShader : Shader
|
public class VertexShader : Shader
|
||||||
{
|
{
|
||||||
[AllowAppend]
|
[AllowAppend]
|
||||||
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
|
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||||
: base(context, source, entryPoint, macros) { }
|
: base(source, entryPoint, macros) { }
|
||||||
|
|
||||||
public override extern void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
|
public override extern void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ namespace Sandbox
|
|||||||
|
|
||||||
// Create rasterizer state
|
// Create rasterizer state
|
||||||
GlitchyEngine.Renderer.RasterizerStateDescription rsDesc = .(.Solid, .Back, false, 0);
|
GlitchyEngine.Renderer.RasterizerStateDescription rsDesc = .(.Solid, .Back, false, 0);
|
||||||
_rasterizerState = new RasterizerState(_context, rsDesc);
|
_rasterizerState = new RasterizerState(rsDesc);
|
||||||
|
|
||||||
_depthTarget = new DepthStencilTarget(_context, _context.SwapChain.Width, _context.SwapChain.Height);
|
_depthTarget = new DepthStencilTarget(_context.SwapChain.Width, _context.SwapChain.Height);
|
||||||
|
|
||||||
_checkerTexture = new Texture2D(_context, "content/Textures/Checkerboard.dds");
|
_checkerTexture = new Texture2D("content/Textures/Checkerboard.dds");
|
||||||
|
|
||||||
let sampler = SamplerStateManager.GetSampler(
|
let sampler = SamplerStateManager.GetSampler(
|
||||||
SamplerStateDescription()
|
SamplerStateDescription()
|
||||||
@@ -63,12 +63,12 @@ namespace Sandbox
|
|||||||
|
|
||||||
BlendStateDescription blendDesc = .();
|
BlendStateDescription blendDesc = .();
|
||||||
blendDesc.RenderTarget[0] = .(true, .SourceAlpha, .InvertedSourceAlpha, .Add, .SourceAlpha, .InvertedSourceAlpha, .Add, .All);
|
blendDesc.RenderTarget[0] = .(true, .SourceAlpha, .InvertedSourceAlpha, .Add, .SourceAlpha, .InvertedSourceAlpha, .Add, .All);
|
||||||
_alphaBlendState = new BlendState(_context, blendDesc);
|
_alphaBlendState = new BlendState(blendDesc);
|
||||||
|
|
||||||
fonty = new Font(_context, "C:\\Windows\\Fonts\\arial.ttf", 64, true, 'A', 16);
|
fonty = new Font("C:\\Windows\\Fonts\\arial.ttf", 64, true, 'A', 16);
|
||||||
var japanese = new Font(_context, "C:\\Windows\\Fonts\\YuGothM.ttc", 64, true, '\0', 1);
|
var japanese = new Font("C:\\Windows\\Fonts\\YuGothM.ttc", 64, true, '\0', 1);
|
||||||
var emojis = new Font(_context, "C:\\Windows\\Fonts\\seguiemj.ttf", 64, true, '😂' - 10, 1);
|
var emojis = new Font("C:\\Windows\\Fonts\\seguiemj.ttf", 64, true, '😂' - 10, 1);
|
||||||
var mathstuff = new Font(_context, "C:\\Windows\\Fonts\\cambria.ttc", 64, true, 'α', 1);
|
var mathstuff = new Font("C:\\Windows\\Fonts\\cambria.ttc", 64, true, 'α', 1);
|
||||||
fonty.Fallback = japanese..ReleaseRefNoDelete();
|
fonty.Fallback = japanese..ReleaseRefNoDelete();
|
||||||
japanese.Fallback = emojis..ReleaseRefNoDelete();
|
japanese.Fallback = emojis..ReleaseRefNoDelete();
|
||||||
emojis.Fallback = mathstuff..ReleaseRefNoDelete();
|
emojis.Fallback = mathstuff..ReleaseRefNoDelete();
|
||||||
@@ -87,7 +87,7 @@ namespace Sandbox
|
|||||||
|
|
||||||
// Draw test geometry
|
// Draw test geometry
|
||||||
_context.SetRenderTarget(null);
|
_context.SetRenderTarget(null);
|
||||||
_depthTarget.Bind();
|
_context.SetDepthStencilTarget(_depthTarget);
|
||||||
_context.BindRenderTargets();
|
_context.BindRenderTargets();
|
||||||
|
|
||||||
_context.SetRasterizerState(_rasterizerState);
|
_context.SetRasterizerState(_rasterizerState);
|
||||||
@@ -138,7 +138,7 @@ namespace Sandbox
|
|||||||
_textureViewer.ViewTexture(fonty.[Friend]_atlas);
|
_textureViewer.ViewTexture(fonty.[Friend]_atlas);
|
||||||
|
|
||||||
_context.SetRenderTarget(null);
|
_context.SetRenderTarget(null);
|
||||||
_depthTarget.Bind();
|
_context.SetDepthStencilTarget(_depthTarget);
|
||||||
_context.BindRenderTargets();
|
_context.BindRenderTargets();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -147,7 +147,7 @@ namespace Sandbox
|
|||||||
private bool OnWindowResize(WindowResizeEvent e)
|
private bool OnWindowResize(WindowResizeEvent e)
|
||||||
{
|
{
|
||||||
_depthTarget.ReleaseRef();
|
_depthTarget.ReleaseRef();
|
||||||
_depthTarget = new DepthStencilTarget(_context, _context.SwapChain.Width, _context.SwapChain.Height);
|
_depthTarget = new DepthStencilTarget(_context.SwapChain.Width, _context.SwapChain.Height);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-24
@@ -96,17 +96,17 @@ namespace Sandbox
|
|||||||
|
|
||||||
var textureEffect = effectLibrary.Load("content\\Shaders\\textureShader.hlsl");
|
var textureEffect = effectLibrary.Load("content\\Shaders\\textureShader.hlsl");
|
||||||
|
|
||||||
_depthTarget = new DepthStencilTarget(_context, _context.SwapChain.Width, _context.SwapChain.Height);
|
_depthTarget = new DepthStencilTarget(_context.SwapChain.Width, _context.SwapChain.Height);
|
||||||
|
|
||||||
// Create Input Layout
|
// Create Input Layout
|
||||||
|
|
||||||
VertexLayout vertexLayout = new VertexLayout(_context, VertexColorTexture.VertexElements, false, textureEffect.VertexShader);
|
VertexLayout vertexLayout = new VertexLayout(VertexColorTexture.VertexElements, false, textureEffect.VertexShader);
|
||||||
|
|
||||||
textureEffect.ReleaseRef();
|
textureEffect.ReleaseRef();
|
||||||
|
|
||||||
// Create hexagon
|
// Create hexagon
|
||||||
{
|
{
|
||||||
_geometryBinding = new GeometryBinding(_context);
|
_geometryBinding = new GeometryBinding();
|
||||||
_geometryBinding.SetPrimitiveTopology(.TriangleList);
|
_geometryBinding.SetPrimitiveTopology(.TriangleList);
|
||||||
_geometryBinding.SetVertexLayout(vertexLayout);
|
_geometryBinding.SetVertexLayout(vertexLayout);
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ namespace Sandbox
|
|||||||
VertexColorTexture(CircleCoord(-pO3), Color(255, 0,255)),
|
VertexColorTexture(CircleCoord(-pO3), Color(255, 0,255)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let vb = new VertexBuffer(_context, typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
|
let vb = new VertexBuffer(typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
|
||||||
vb.SetData(vertices);
|
vb.SetData(vertices);
|
||||||
_geometryBinding.SetVertexBufferSlot(vb, 0);
|
_geometryBinding.SetVertexBufferSlot(vb, 0);
|
||||||
vb.ReleaseRef();
|
vb.ReleaseRef();
|
||||||
@@ -134,7 +134,7 @@ namespace Sandbox
|
|||||||
0, 5, 6,
|
0, 5, 6,
|
||||||
0, 6, 1);
|
0, 6, 1);
|
||||||
|
|
||||||
let ib = new IndexBuffer(_context, (.)indices.Count, .Immutable);
|
let ib = new IndexBuffer((.)indices.Count, .Immutable);
|
||||||
ib.SetData(indices);
|
ib.SetData(indices);
|
||||||
_geometryBinding.SetIndexBuffer(ib);
|
_geometryBinding.SetIndexBuffer(ib);
|
||||||
ib.ReleaseRef();
|
ib.ReleaseRef();
|
||||||
@@ -142,7 +142,7 @@ namespace Sandbox
|
|||||||
|
|
||||||
// Create Quad
|
// Create Quad
|
||||||
{
|
{
|
||||||
_quadGeometryBinding = new GeometryBinding(_context);
|
_quadGeometryBinding = new GeometryBinding();
|
||||||
_quadGeometryBinding.SetPrimitiveTopology(.TriangleList);
|
_quadGeometryBinding.SetPrimitiveTopology(.TriangleList);
|
||||||
_quadGeometryBinding.SetVertexLayout(vertexLayout);
|
_quadGeometryBinding.SetVertexLayout(vertexLayout);
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ namespace Sandbox
|
|||||||
VertexColorTexture(Vector3(0.75f, 0.75f, 0), Color.White, .(1, 0)),
|
VertexColorTexture(Vector3(0.75f, 0.75f, 0), Color.White, .(1, 0)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let qvb = new VertexBuffer(_context, typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
|
let qvb = new VertexBuffer(typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
|
||||||
qvb.SetData(vertices);
|
qvb.SetData(vertices);
|
||||||
_quadGeometryBinding.SetVertexBufferSlot(qvb, 0);
|
_quadGeometryBinding.SetVertexBufferSlot(qvb, 0);
|
||||||
qvb.ReleaseRef();
|
qvb.ReleaseRef();
|
||||||
@@ -162,7 +162,7 @@ namespace Sandbox
|
|||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
2, 3, 0);
|
2, 3, 0);
|
||||||
|
|
||||||
let qib = new IndexBuffer(_context, (.)indices.Count, .Immutable);
|
let qib = new IndexBuffer((.)indices.Count, .Immutable);
|
||||||
qib.SetData(indices);
|
qib.SetData(indices);
|
||||||
_quadGeometryBinding.SetIndexBuffer(qib);
|
_quadGeometryBinding.SetIndexBuffer(qib);
|
||||||
qib.ReleaseRef();
|
qib.ReleaseRef();
|
||||||
@@ -172,13 +172,13 @@ namespace Sandbox
|
|||||||
|
|
||||||
// Create rasterizer state
|
// Create rasterizer state
|
||||||
RasterizerStateDescription rsDesc = .(.Solid, .Back, true);
|
RasterizerStateDescription rsDesc = .(.Solid, .Back, true);
|
||||||
_rasterizerState = new RasterizerState(_context, rsDesc);
|
_rasterizerState = new RasterizerState(rsDesc);
|
||||||
|
|
||||||
rsDesc.FrontCounterClockwise = false;
|
rsDesc.FrontCounterClockwise = false;
|
||||||
_rasterizerStateClockWise = new RasterizerState(_context, rsDesc);
|
_rasterizerStateClockWise = new RasterizerState(rsDesc);
|
||||||
|
|
||||||
_texture = new Texture2D(_context, "content/Textures/Checkerboard.dds");
|
_texture = new Texture2D("content/Textures/Checkerboard.dds");
|
||||||
_ge_logo = new Texture2D(_context, "content/Textures/GE_Logo.dds");
|
_ge_logo = new Texture2D("content/Textures/GE_Logo.dds");
|
||||||
|
|
||||||
let sampler = SamplerStateManager.GetSampler(
|
let sampler = SamplerStateManager.GetSampler(
|
||||||
SamplerStateDescription()
|
SamplerStateDescription()
|
||||||
@@ -199,8 +199,8 @@ namespace Sandbox
|
|||||||
|
|
||||||
BlendStateDescription blendDesc = .();
|
BlendStateDescription blendDesc = .();
|
||||||
blendDesc.RenderTarget[0] = .(true, .SourceAlpha, .InvertedSourceAlpha, .Add, .SourceAlpha, .InvertedSourceAlpha, .Add, .All);
|
blendDesc.RenderTarget[0] = .(true, .SourceAlpha, .InvertedSourceAlpha, .Add, .SourceAlpha, .InvertedSourceAlpha, .Add, .All);
|
||||||
_alphaBlendState = new BlendState(_context, blendDesc);
|
_alphaBlendState = new BlendState(blendDesc);
|
||||||
_opaqueBlendState = new BlendState(_context, .Default);
|
_opaqueBlendState = new BlendState(.Default);
|
||||||
|
|
||||||
InitEcs();
|
InitEcs();
|
||||||
|
|
||||||
@@ -255,13 +255,13 @@ namespace Sandbox
|
|||||||
materialTestMaterial.SetVariable("BaseColor", Color.White);
|
materialTestMaterial.SetVariable("BaseColor", Color.White);
|
||||||
materialTestMaterial.SetVariable("LightDir", Vector3(1, 1, -0.5f).Normalized());
|
materialTestMaterial.SetVariable("LightDir", Vector3(1, 1, -0.5f).Normalized());
|
||||||
|
|
||||||
//ModelLoader.LoadModel("content\\Models\\Test\\axisTest.glb", _context, testEffect, _modelTest, out Skeleton, out Clip);
|
//ModelLoader.LoadModel("content\\Models\\Test\\axisTest.glb", testEffect, _modelTest, out Skeleton, out Clip);
|
||||||
//ModelLoader.LoadModel("content\\Models\\RiggedSimple\\RiggedSimple.glb", _context, testEffect, _modelTest, out Skeleton, out Clip);
|
//ModelLoader.LoadModel("content\\Models\\RiggedSimple\\RiggedSimple.glb", testEffect, _modelTest, out Skeleton, out Clip);
|
||||||
//ModelLoader.LoadModel("content\\Models\\Fox\\Fox.glb", _context, testEffect, _modelTest, out Skeleton, out Clip);
|
//ModelLoader.LoadModel("content\\Models\\Fox\\Fox.glb", testEffect, _modelTest, out Skeleton, out Clip);
|
||||||
//ModelLoader.LoadModel("content\\Models\\Fox\\Fox_2.glb", _context, testEffect, materialTestMaterial, _world, _modelTest, out Skeleton, out Clips);
|
//ModelLoader.LoadModel("content\\Models\\Fox\\Fox_2.glb", testEffect, materialTestMaterial, _world, _modelTest, out Skeleton, out Clips);
|
||||||
//ModelLoader.LoadModel("content\\Models\\DancingCylinder\\DancingCylinder.glb", _context, testEffect, _modelTest, out Skeleton, out Clip);
|
//ModelLoader.LoadModel("content\\Models\\DancingCylinder\\DancingCylinder.glb", testEffect, _modelTest, out Skeleton, out Clip);
|
||||||
ModelLoader.LoadModel("content\\Models\\Figure\\Figure.gltf", _context, testEffect, materialTestMaterial, _world, _modelTest, out Skeleton, out Clips);
|
ModelLoader.LoadModel("content\\Models\\Figure\\Figure.gltf", testEffect, materialTestMaterial, _world, _modelTest, out Skeleton, out Clips);
|
||||||
//ModelLoader.LoadModel("content\\Models\\RiggedFigure\\RiggedFigure.glb", _context, testEffect, materialTestMaterial, _world, _modelTest, out Skeleton, out Clips);
|
//ModelLoader.LoadModel("content\\Models\\RiggedFigure\\RiggedFigure.glb", testEffect, materialTestMaterial, _world, _modelTest, out Skeleton, out Clips);
|
||||||
|
|
||||||
materialTestMaterial.ReleaseRef();
|
materialTestMaterial.ReleaseRef();
|
||||||
testEffect.ReleaseRef();
|
testEffect.ReleaseRef();
|
||||||
@@ -389,11 +389,11 @@ namespace Sandbox
|
|||||||
_cameraController.Update(gameTime);
|
_cameraController.Update(gameTime);
|
||||||
|
|
||||||
RenderCommand.Clear(null, .(0.2f, 0.2f, 0.2f));
|
RenderCommand.Clear(null, .(0.2f, 0.2f, 0.2f));
|
||||||
_depthTarget.Clear(1.0f, 0, .Depth);
|
RenderCommand.Clear(_depthTarget, 1.0f, 0, .Depth);
|
||||||
|
|
||||||
// Draw test geometry
|
// Draw test geometry
|
||||||
_context.SetRenderTarget(null);
|
_context.SetRenderTarget(null);
|
||||||
_depthTarget.Bind();
|
_context.SetDepthStencilTarget(_depthTarget);
|
||||||
_context.BindRenderTargets();
|
_context.BindRenderTargets();
|
||||||
|
|
||||||
RenderCommand.SetViewport(_context.SwapChain.BackbufferViewport);
|
RenderCommand.SetViewport(_context.SwapChain.BackbufferViewport);
|
||||||
@@ -560,7 +560,7 @@ namespace Sandbox
|
|||||||
private bool OnWindowResize(WindowResizeEvent e)
|
private bool OnWindowResize(WindowResizeEvent e)
|
||||||
{
|
{
|
||||||
_depthTarget.ReleaseRef();
|
_depthTarget.ReleaseRef();
|
||||||
_depthTarget = new DepthStencilTarget(_context, _context.SwapChain.Width, _context.SwapChain.Height);
|
_depthTarget = new DepthStencilTarget(_context.SwapChain.Width, _context.SwapChain.Height);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace Sandbox
|
|||||||
|
|
||||||
private void InitEffect()
|
private void InitEffect()
|
||||||
{
|
{
|
||||||
_effect = new Effect(_context, "content\\Shaders\\textureViewerShader.hlsl");
|
_effect = new Effect("content\\Shaders\\textureViewerShader.hlsl");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitState()
|
private void InitState()
|
||||||
@@ -100,9 +100,9 @@ namespace Sandbox
|
|||||||
if(_target == null || viewportSize.x != _target.Width || viewportSize.y != _target.Height)
|
if(_target == null || viewportSize.x != _target.Width || viewportSize.y != _target.Height)
|
||||||
{
|
{
|
||||||
_target?.ReleaseRef();
|
_target?.ReleaseRef();
|
||||||
_target = new RenderTarget2D(_context, .(.R8G8B8A8_UNorm, (.)viewportSize.x, (.)viewportSize.y));
|
_target = new RenderTarget2D(.(.R8G8B8A8_UNorm, (.)viewportSize.x, (.)viewportSize.y));
|
||||||
_depth?.ReleaseRef();
|
_depth?.ReleaseRef();
|
||||||
_depth = new DepthStencilTarget(_context, (.)viewportSize.x, (.)viewportSize.y, .D16_UNorm);
|
_depth = new DepthStencilTarget((.)viewportSize.x, (.)viewportSize.y, .D16_UNorm);
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTexture(viewedTexture);
|
RenderTexture(viewedTexture);
|
||||||
@@ -170,11 +170,11 @@ namespace Sandbox
|
|||||||
|
|
||||||
// TODO: don't clear pink!
|
// TODO: don't clear pink!
|
||||||
_context.ClearRenderTarget(_target, .Pink);
|
_context.ClearRenderTarget(_target, .Pink);
|
||||||
_depth.Clear(1.0f, 0, .Depth);
|
RenderCommand.Clear(_depth, 1.0f, 0, .Depth);
|
||||||
|
|
||||||
//_target.Bind();
|
//_target.Bind();
|
||||||
_context.SetRenderTarget(_target);
|
_context.SetRenderTarget(_target);
|
||||||
_depth.Bind();
|
_context.SetDepthStencilTarget(_depth);
|
||||||
_context.BindRenderTargets();
|
_context.BindRenderTargets();
|
||||||
|
|
||||||
Vector2 textureSize = Vector2(viewedTexture.Width, viewedTexture.Height);
|
Vector2 textureSize = Vector2(viewedTexture.Width, viewedTexture.Height);
|
||||||
|
|||||||
Reference in New Issue
Block a user