using Refresh again

refresh2
cosmonaut 2024-06-05 12:34:24 -07:00
parent 3cfb43438c
commit baf51d2ee9
31 changed files with 366 additions and 370 deletions

6
.gitmodules vendored
View File

@ -10,6 +10,6 @@
[submodule "lib/dav1dfile"]
path = lib/dav1dfile
url = https://github.com/MoonsideGames/dav1dfile.git
[submodule "SDL2_gpuCS"]
path = lib/SDL2_gpuCS
url = https://github.com/MoonsideGames/SDL2_gpuCS.git
[submodule "lib/RefreshCS"]
path = lib/RefreshCS
url = https://github.com/MoonsideGames/RefreshCS.git

View File

@ -11,7 +11,7 @@
<ItemGroup>
<Compile Include="lib\FAudio\csharp\FAudio.cs" />
<Compile Include="lib\SDL2_gpuCS\SDL2_gpuCS.cs" />
<Compile Include="lib\RefreshCS\RefreshCS.cs" />
<Compile Include="lib\SDL2-CS\src\SDL2.cs" />
<Compile Include="lib\WellspringCS\WellspringCS.cs" />
<Compile Include="lib\dav1dfile\csharp\dav1dfile.cs" />

1
lib/RefreshCS Submodule

@ -0,0 +1 @@
Subproject commit a0cdff3054c646a532e5850c0ab89d4611069237

@ -1 +0,0 @@
Subproject commit 70925aa394c0f24388f3cfb97f1c6ee1f91baf52

View File

@ -85,8 +85,14 @@ namespace MoonWorks
debugMode
);
SDL.SDL_WindowFlags windowFlags = 0;
if ((preferredBackends & BackendFlags.Vulkan) != 0)
{
windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN;
}
Logger.LogInfo("Initializing main window...");
MainWindow = new Window(windowCreateInfo, GraphicsDevice.WindowFlags | SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN);
MainWindow = new Window(windowCreateInfo, windowFlags | SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN);
if (!GraphicsDevice.ClaimWindow(MainWindow, windowCreateInfo.SwapchainComposition, windowCreateInfo.PresentMode))
{

View File

@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using SDL2;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
@ -82,7 +81,7 @@ public class CommandBuffer
}
#endif
var texturePtr = SDL_Gpu.SDL_GpuAcquireSwapchainTexture(
var texturePtr = Refresh.Refresh_AcquireSwapchainTexture(
Handle,
window.Handle,
out var width,
@ -123,14 +122,14 @@ public class CommandBuffer
AssertColorTarget(colorAttachmentInfo);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[1];
sdlColorAttachmentInfos[0] = colorAttachmentInfo.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[1];
sdlColorAttachmentInfos[0] = colorAttachmentInfo.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
1,
(SDL_Gpu.DepthStencilAttachmentInfo*) nint.Zero
(Refresh.DepthStencilAttachmentInfo*) nint.Zero
);
var renderPass = Device.RenderPassPool.Obtain();
@ -171,15 +170,15 @@ public class CommandBuffer
AssertSameSampleCount(colorAttachmentInfoOne.TextureSlice.Texture, colorAttachmentInfoTwo.TextureSlice.Texture);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[2];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToSDL();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[2];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToRefresh();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
2,
(SDL_Gpu.DepthStencilAttachmentInfo*) nint.Zero
(Refresh.DepthStencilAttachmentInfo*) nint.Zero
);
var renderPass = Device.RenderPassPool.Obtain();
@ -227,16 +226,16 @@ public class CommandBuffer
AssertSameSampleCount(colorAttachmentInfoOne.TextureSlice.Texture, colorAttachmentInfoThree.TextureSlice.Texture);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[3];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToSDL();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToSDL();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[3];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToRefresh();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToRefresh();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
3,
(SDL_Gpu.DepthStencilAttachmentInfo*) nint.Zero
(Refresh.DepthStencilAttachmentInfo*) nint.Zero
);
var renderPass = Device.RenderPassPool.Obtain();
@ -290,17 +289,17 @@ public class CommandBuffer
AssertSameSampleCount(colorAttachmentInfoOne.TextureSlice.Texture, colorAttachmentInfoFour.TextureSlice.Texture);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[4];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToSDL();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToSDL();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToSDL();
sdlColorAttachmentInfos[3] = colorAttachmentInfoFour.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[4];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToRefresh();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToRefresh();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToRefresh();
sdlColorAttachmentInfos[3] = colorAttachmentInfoFour.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
4,
(SDL_Gpu.DepthStencilAttachmentInfo*) nint.Zero
(Refresh.DepthStencilAttachmentInfo*) nint.Zero
);
var renderPass = Device.RenderPassPool.Obtain();
@ -334,11 +333,11 @@ public class CommandBuffer
AssertValidDepthAttachment(depthStencilAttachmentInfo);
#endif
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToSDL();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
(SDL_Gpu.ColorAttachmentInfo*) nint.Zero,
(Refresh.ColorAttachmentInfo*) nint.Zero,
0,
&sdlDepthStencilAttachmentInfo
);
@ -376,12 +375,12 @@ public class CommandBuffer
AssertSameSampleCount(colorAttachmentInfo.TextureSlice.Texture, depthStencilAttachmentInfo.TextureSlice.Texture);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[1];
sdlColorAttachmentInfos[0] = colorAttachmentInfo.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[1];
sdlColorAttachmentInfos[0] = colorAttachmentInfo.ToRefresh();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToSDL();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
1,
@ -431,13 +430,13 @@ public class CommandBuffer
AssertSameSampleCount(colorAttachmentInfoOne.TextureSlice.Texture, depthStencilAttachmentInfo.TextureSlice.Texture);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[2];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToSDL();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[2];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToRefresh();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToRefresh();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToSDL();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
2,
@ -494,14 +493,14 @@ public class CommandBuffer
AssertSameSampleCount(colorAttachmentInfoOne.TextureSlice.Texture, depthStencilAttachmentInfo.TextureSlice.Texture);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[3];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToSDL();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToSDL();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[3];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToRefresh();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToRefresh();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToRefresh();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToSDL();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
3,
@ -565,15 +564,15 @@ public class CommandBuffer
AssertSameSampleCount(colorAttachmentInfoOne.TextureSlice.Texture, depthStencilAttachmentInfo.TextureSlice.Texture);
#endif
var sdlColorAttachmentInfos = stackalloc SDL_Gpu.ColorAttachmentInfo[4];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToSDL();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToSDL();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToSDL();
sdlColorAttachmentInfos[3] = colorAttachmentInfoFour.ToSDL();
var sdlColorAttachmentInfos = stackalloc Refresh.ColorAttachmentInfo[4];
sdlColorAttachmentInfos[0] = colorAttachmentInfoOne.ToRefresh();
sdlColorAttachmentInfos[1] = colorAttachmentInfoTwo.ToRefresh();
sdlColorAttachmentInfos[2] = colorAttachmentInfoThree.ToRefresh();
sdlColorAttachmentInfos[3] = colorAttachmentInfoFour.ToRefresh();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToSDL();
var sdlDepthStencilAttachmentInfo = depthStencilAttachmentInfo.ToRefresh();
var renderPassHandle = SDL_Gpu.SDL_GpuBeginRenderPass(
var renderPassHandle = Refresh.Refresh_BeginRenderPass(
Handle,
sdlColorAttachmentInfos,
4,
@ -613,7 +612,7 @@ public class CommandBuffer
renderPass.active = false;
#endif
SDL_Gpu.SDL_GpuEndRenderPass(
Refresh.Refresh_EndRenderPass(
renderPass.Handle
);
@ -633,11 +632,11 @@ public class CommandBuffer
Filter filter,
bool cycle
) {
SDL_Gpu.SDL_GpuBlit(
Refresh.Refresh_Blit(
Handle,
source.ToSDL(),
destination.ToSDL(),
(SDL_Gpu.Filter) filter,
source.ToRefresh(),
destination.ToRefresh(),
(Refresh.Filter) filter,
Conversions.BoolToInt(cycle)
);
}
@ -651,13 +650,13 @@ public class CommandBuffer
computePassActive = true;
#endif
var sdlTextureBinding = readWriteTextureBinding.ToSDL();
var sdlTextureBinding = readWriteTextureBinding.ToRefresh();
var computePassHandle = SDL_Gpu.SDL_GpuBeginComputePass(
var computePassHandle = Refresh.Refresh_BeginComputePass(
Handle,
&sdlTextureBinding,
1,
(SDL_Gpu.StorageBufferReadWriteBinding*) nint.Size,
(Refresh.StorageBufferReadWriteBinding*) nint.Size,
0
);
@ -680,11 +679,11 @@ public class CommandBuffer
computePassActive = true;
#endif
var sdlBufferBinding = readWriteBufferBinding.ToSDL();
var sdlBufferBinding = readWriteBufferBinding.ToRefresh();
var computePassHandle = SDL_Gpu.SDL_GpuBeginComputePass(
var computePassHandle = Refresh.Refresh_BeginComputePass(
Handle,
(SDL_Gpu.StorageTextureReadWriteBinding*) nint.Zero,
(Refresh.StorageTextureReadWriteBinding*) nint.Zero,
0,
&sdlBufferBinding,
1
@ -710,10 +709,10 @@ public class CommandBuffer
computePassActive = true;
#endif
var sdlTextureBinding = readWriteTextureBinding.ToSDL();
var sdlBufferBinding = readWriteBufferBinding.ToSDL();
var sdlTextureBinding = readWriteTextureBinding.ToRefresh();
var sdlBufferBinding = readWriteBufferBinding.ToRefresh();
var computePassHandle = SDL_Gpu.SDL_GpuBeginComputePass(
var computePassHandle = Refresh.Refresh_BeginComputePass(
Handle,
&sdlTextureBinding,
1,
@ -749,11 +748,11 @@ public class CommandBuffer
(nuint) (readWriteBufferBindings.Length * Marshal.SizeOf<StorageBufferReadWriteBinding>())
);
var computePassHandle = SDL_Gpu.SDL_GpuBeginComputePass(
var computePassHandle = Refresh.Refresh_BeginComputePass(
Handle,
(SDL_Gpu.StorageTextureReadWriteBinding*) sdlTextureBindings,
(Refresh.StorageTextureReadWriteBinding*) sdlTextureBindings,
(uint) readWriteTextureBindings.Length,
(SDL_Gpu.StorageBufferReadWriteBinding*) sdlBufferBindings,
(Refresh.StorageBufferReadWriteBinding*) sdlBufferBindings,
(uint) readWriteBufferBindings.Length
);
@ -779,7 +778,7 @@ public class CommandBuffer
computePass.active = false;
#endif
SDL_Gpu.SDL_GpuEndComputePass(
Refresh.Refresh_EndComputePass(
computePass.Handle
);
@ -802,7 +801,7 @@ public class CommandBuffer
copyPassActive = true;
#endif
var copyPassHandle = SDL_Gpu.SDL_GpuBeginCopyPass(Handle);
var copyPassHandle = Refresh.Refresh_BeginCopyPass(Handle);
var copyPass = Device.CopyPassPool.Obtain();
copyPass.SetHandle(copyPassHandle);
@ -818,7 +817,7 @@ public class CommandBuffer
copyPassActive = false;
#endif
SDL_Gpu.SDL_GpuEndCopyPass(
Refresh.Refresh_EndCopyPass(
copyPass.Handle
);

View File

@ -1,6 +1,5 @@
using System.Runtime.InteropServices;
using SDL2;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
@ -32,7 +31,7 @@ public class ComputePass
// TODO: validate formats?
#endif
SDL_Gpu.SDL_GpuBindComputePipeline(
Refresh.Refresh_BindComputePipeline(
Handle,
computePipeline.Handle
);
@ -57,9 +56,9 @@ public class ComputePass
AssertTextureHasComputeStorageReadFlag(textureSlice.Texture);
#endif
var sdlTextureSlice = textureSlice.ToSDL();
var sdlTextureSlice = textureSlice.ToRefresh();
SDL_Gpu.SDL_GpuBindComputeStorageTextures(
Refresh.Refresh_BindComputeStorageTextures(
Handle,
slot,
&sdlTextureSlice,
@ -84,7 +83,7 @@ public class ComputePass
var bufferHandle = buffer.Handle;
SDL_Gpu.SDL_GpuBindComputeStorageBuffers(
Refresh.Refresh_BindComputeStorageBuffers(
Handle,
slot,
&bufferHandle,
@ -111,7 +110,7 @@ public class ComputePass
}
#endif
SDL_Gpu.SDL_GpuPushComputeUniformData(
Refresh.Refresh_PushComputeUniformData(
Handle,
slot,
(nint) uniformsPtr,
@ -153,7 +152,7 @@ public class ComputePass
}
#endif
SDL_Gpu.SDL_GpuDispatchCompute(
Refresh.Refresh_DispatchCompute(
Handle,
groupCountX,
groupCountY,

View File

@ -1,5 +1,5 @@
using System.Runtime.InteropServices;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
@ -32,11 +32,11 @@ public class CopyPass
AssertBufferBoundsCheck(transferBuffer.Size, copyParams.BufferOffset, textureRegion.Size);
#endif
SDL_Gpu.SDL_GpuUploadToTexture(
Refresh.Refresh_UploadToTexture(
Handle,
transferBuffer.Handle,
textureRegion.ToSDL(),
copyParams.ToSDL(),
textureRegion.ToRefresh(),
copyParams.ToRefresh(),
Conversions.BoolToInt(cycle)
);
}
@ -78,11 +78,11 @@ public class CopyPass
AssertBufferBoundsCheck(buffer.Size, copyParams.DstOffset, copyParams.Size);
#endif
SDL_Gpu.SDL_GpuUploadToBuffer(
Refresh.Refresh_UploadToBuffer(
Handle,
transferBuffer.Handle,
buffer.Handle,
copyParams.ToSDL(),
copyParams.ToRefresh(),
Conversions.BoolToInt(cycle)
);
}
@ -149,10 +149,10 @@ public class CopyPass
}
#endif
SDL_Gpu.SDL_GpuCopyTextureToTexture(
Refresh.Refresh_CopyTextureToTexture(
Handle,
source.ToSDL(),
destination.ToSDL(),
source.ToRefresh(),
destination.ToRefresh(),
Conversions.BoolToInt(cycle)
);
}
@ -174,11 +174,11 @@ public class CopyPass
AssertBufferBoundsCheck(destination.Size, copyParams.DstOffset, copyParams.Size);
#endif
SDL_Gpu.SDL_GpuCopyBufferToBuffer(
Refresh.Refresh_CopyBufferToBuffer(
Handle,
source.Handle,
destination.Handle,
copyParams.ToSDL(),
copyParams.ToRefresh(),
Conversions.BoolToInt(cycle)
);
}

View File

@ -35,7 +35,7 @@ namespace MoonWorks.Graphics.Font
VertexBuffer = GpuBuffer.Create<Vertex>(GraphicsDevice, BufferUsageFlags.Vertex, INITIAL_VERTEX_COUNT);
IndexBuffer = GpuBuffer.Create<uint>(GraphicsDevice, BufferUsageFlags.Index, INITIAL_INDEX_COUNT);
TransferBuffer = TransferBuffer.Create<byte>(GraphicsDevice, TransferUsage.Buffer, VertexBuffer.Size + IndexBuffer.Size);
TransferBuffer = TransferBuffer.Create<byte>(GraphicsDevice, TransferUsage.Buffer, TransferBufferMapFlags.Write, VertexBuffer.Size + IndexBuffer.Size);
}
// Call this to initialize or reset the batch.
@ -119,35 +119,35 @@ namespace MoonWorks.Graphics.Font
if (newTransferBufferNeeded)
{
TransferBuffer.Dispose();
TransferBuffer = new TransferBuffer(GraphicsDevice, TransferUsage.Buffer, VertexBuffer.Size + IndexBuffer.Size);
TransferBuffer = new TransferBuffer(GraphicsDevice, TransferUsage.Buffer, TransferBufferMapFlags.Write, VertexBuffer.Size + IndexBuffer.Size);
}
if (vertexDataLengthInBytes > 0 && indexDataLengthInBytes > 0)
{
TransferBuffer.SetData(vertexSpan, TransferOptions.Cycle);
TransferBuffer.SetData(indexSpan, (uint) vertexSpan.Length, TransferOptions.Unsafe);
TransferBuffer.SetData(vertexSpan, true);
TransferBuffer.SetData(indexSpan, (uint) vertexSpan.Length, false);
commandBuffer.BeginCopyPass();
commandBuffer.UploadToBuffer(TransferBuffer, VertexBuffer, new BufferCopy(0, 0, (uint) vertexSpan.Length), WriteOptions.Cycle);
commandBuffer.UploadToBuffer(TransferBuffer, IndexBuffer, new BufferCopy((uint) vertexSpan.Length, 0, (uint) indexSpan.Length), WriteOptions.Cycle);
commandBuffer.EndCopyPass();
var copyPass = commandBuffer.BeginCopyPass();
copyPass.UploadToBuffer(TransferBuffer, VertexBuffer, new BufferCopy(0, 0, (uint) vertexSpan.Length), true);
copyPass.UploadToBuffer(TransferBuffer, IndexBuffer, new BufferCopy((uint) vertexSpan.Length, 0, (uint) indexSpan.Length), true);
commandBuffer.EndCopyPass(copyPass);
}
PrimitiveCount = vertexCount / 2;
}
// Call this AFTER binding your text pipeline!
public void Render(CommandBuffer commandBuffer, Math.Float.Matrix4x4 transformMatrix)
public void Render(RenderPass renderPass, Math.Float.Matrix4x4 transformMatrix)
{
commandBuffer.BindFragmentSamplers(new TextureSamplerBinding(
renderPass.BindFragmentSamplers(new TextureSamplerBinding(
CurrentFont.Texture,
GraphicsDevice.LinearSampler
));
commandBuffer.BindVertexBuffers(VertexBuffer);
commandBuffer.BindIndexBuffer(IndexBuffer, IndexElementSize.ThirtyTwo);
commandBuffer.PushVertexShaderUniforms(transformMatrix);
commandBuffer.PushFragmentShaderUniforms(CurrentFont.DistanceRange);
commandBuffer.DrawIndexedPrimitives(
renderPass.BindVertexBuffer(VertexBuffer);
renderPass.BindIndexBuffer(IndexBuffer, IndexElementSize.ThirtyTwo);
renderPass.PushVertexUniformData(transformMatrix);
renderPass.PushFragmentUniformData(CurrentFont.DistanceRange);
renderPass.DrawIndexedPrimitives(
0,
0,
PrimitiveCount

View File

@ -3,8 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using MoonWorks.Video;
using SDL2;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
@ -17,9 +16,6 @@ namespace MoonWorks.Graphics
public BackendFlags Backend { get; }
public bool DebugMode { get; }
private uint windowFlags;
public SDL2.SDL.SDL_WindowFlags WindowFlags => (SDL2.SDL.SDL_WindowFlags) windowFlags;
// Built-in video pipeline
internal GraphicsPipeline VideoPipeline { get; }
@ -39,9 +35,9 @@ namespace MoonWorks.Graphics
private readonly HashSet<GCHandle> resources = new HashSet<GCHandle>();
private CommandBufferPool CommandBufferPool;
private FencePool FencePool;
internal RenderPassPool RenderPassPool;
internal ComputePassPool ComputePassPool;
internal CopyPassPool CopyPassPool;
internal RenderPassPool RenderPassPool = new RenderPassPool();
internal ComputePassPool ComputePassPool = new ComputePassPool();
internal CopyPassPool CopyPassPool = new CopyPassPool();
internal unsafe GraphicsDevice(
BackendFlags preferredBackends,
@ -52,15 +48,15 @@ namespace MoonWorks.Graphics
throw new System.Exception("Could not set graphics backend!");
}
Handle = SDL_Gpu.SDL_GpuCreateDevice(
(SDL_Gpu.BackendFlags) preferredBackends,
Handle = Refresh.Refresh_CreateDevice(
(Refresh.BackendFlags) preferredBackends,
Conversions.BoolToByte(debugMode)
);
DebugMode = debugMode;
// TODO: check for CreateDevice fail
Backend = (BackendFlags) SDL_Gpu.SDL_GpuGetBackend(Handle);
Backend = (BackendFlags) Refresh.Refresh_GetBackend(Handle);
// Check for replacement stock shaders
string basePath = System.AppContext.BaseDirectory;
@ -257,11 +253,11 @@ namespace MoonWorks.Graphics
}
var success = Conversions.IntToBool(
SDL_Gpu.SDL_GpuClaimWindow(
Refresh.Refresh_ClaimWindow(
Handle,
window.Handle,
(SDL_Gpu.SwapchainComposition) swapchainComposition,
(SDL_Gpu.PresentMode) presentMode
(Refresh.SwapchainComposition) swapchainComposition,
(Refresh.PresentMode) presentMode
)
);
@ -287,7 +283,7 @@ namespace MoonWorks.Graphics
{
if (window.Claimed)
{
SDL_Gpu.SDL_GpuUnclaimWindow(
Refresh.Refresh_UnclaimWindow(
Handle,
window.Handle
);
@ -316,11 +312,11 @@ namespace MoonWorks.Graphics
return;
}
SDL_Gpu.SDL_GpuSetSwapchainParameters(
Refresh.Refresh_SetSwapchainParameters(
Handle,
window.Handle,
(SDL_Gpu.SwapchainComposition) swapchainComposition,
(SDL_Gpu.PresentMode) presentMode
(Refresh.SwapchainComposition) swapchainComposition,
(Refresh.PresentMode) presentMode
);
}
@ -332,7 +328,7 @@ namespace MoonWorks.Graphics
public CommandBuffer AcquireCommandBuffer()
{
var commandBuffer = CommandBufferPool.Obtain();
commandBuffer.SetHandle(SDL_Gpu.SDL_GpuAcquireCommandBuffer(Handle));
commandBuffer.SetHandle(Refresh.Refresh_AcquireCommandBuffer(Handle));
#if DEBUG
commandBuffer.ResetStateTracking();
#endif
@ -351,7 +347,7 @@ namespace MoonWorks.Graphics
}
#endif
SDL_Gpu.SDL_GpuSubmit(
Refresh.Refresh_Submit(
commandBuffer.Handle
);
@ -368,7 +364,7 @@ namespace MoonWorks.Graphics
/// <returns></returns>
public Fence SubmitAndAcquireFence(CommandBuffer commandBuffer)
{
var fenceHandle = SDL_Gpu.SDL_GpuSubmitAndAcquireFence(
var fenceHandle = Refresh.Refresh_SubmitAndAcquireFence(
commandBuffer.Handle
);
@ -383,7 +379,7 @@ namespace MoonWorks.Graphics
/// </summary>
public void Wait()
{
SDL_Gpu.SDL_GpuWait(Handle);
Refresh.Refresh_Wait(Handle);
}
/// <summary>
@ -393,7 +389,7 @@ namespace MoonWorks.Graphics
{
var fenceHandle = fence.Handle;
SDL_Gpu.SDL_GpuWaitForFences(
Refresh.Refresh_WaitForFences(
Handle,
1,
1,
@ -414,7 +410,7 @@ namespace MoonWorks.Graphics
handlePtr[0] = fenceOne.Handle;
handlePtr[1] = fenceTwo.Handle;
SDL_Gpu.SDL_GpuWaitForFences(
Refresh.Refresh_WaitForFences(
Handle,
Conversions.BoolToInt(waitAll),
2,
@ -437,7 +433,7 @@ namespace MoonWorks.Graphics
handlePtr[1] = fenceTwo.Handle;
handlePtr[2] = fenceThree.Handle;
SDL_Gpu.SDL_GpuWaitForFences(
Refresh.Refresh_WaitForFences(
Handle,
Conversions.BoolToInt(waitAll),
3,
@ -462,7 +458,7 @@ namespace MoonWorks.Graphics
handlePtr[2] = fenceThree.Handle;
handlePtr[3] = fenceFour.Handle;
SDL_Gpu.SDL_GpuWaitForFences(
Refresh.Refresh_WaitForFences(
Handle,
Conversions.BoolToInt(waitAll),
4,
@ -483,7 +479,7 @@ namespace MoonWorks.Graphics
handlePtr[i] = fences[i].Handle;
}
SDL_Gpu.SDL_GpuWaitForFences(
Refresh.Refresh_WaitForFences(
Handle,
Conversions.BoolToInt(waitAll),
4,
@ -497,7 +493,7 @@ namespace MoonWorks.Graphics
/// <exception cref="InvalidOperationException">Throws if the fence query indicates that the graphics device has been lost.</exception>
public bool QueryFence(Fence fence)
{
var result = SDL_Gpu.SDL_GpuQueryFence(Handle, fence.Handle);
var result = Refresh.Refresh_QueryFence(Handle, fence.Handle);
if (result < 0)
{
@ -512,7 +508,7 @@ namespace MoonWorks.Graphics
/// </summary>
public void ReleaseFence(Fence fence)
{
SDL_Gpu.SDL_GpuReleaseFence(Handle, fence.Handle);
Refresh.Refresh_ReleaseFence(Handle, fence.Handle);
fence.Handle = IntPtr.Zero;
FencePool.Return(fence);
}
@ -524,7 +520,7 @@ namespace MoonWorks.Graphics
throw new System.ArgumentException("Cannot get swapchain format of unclaimed window!");
}
return (TextureFormat) SDL_Gpu.SDL_GpuGetSwapchainTextureFormat(Handle, window.Handle);
return (TextureFormat) Refresh.Refresh_GetSwapchainTextureFormat(Handle, window.Handle);
}
internal void AddResourceReference(GCHandle resourceReference)
@ -572,7 +568,7 @@ namespace MoonWorks.Graphics
}
}
SDL_Gpu.SDL_GpuDestroyDevice(Handle);
Refresh.Refresh_DestroyDevice(Handle);
IsDisposed = true;
}

View File

@ -23,7 +23,7 @@ namespace MoonWorks.Graphics
{
var pixelData =
Refresh.Refresh_Image_Load(
(nint) ptr,
ptr,
data.Length,
out var w,
out var h,
@ -34,7 +34,7 @@ namespace MoonWorks.Graphics
height = (uint) h;
sizeInBytes = (uint) len;
return pixelData;
return (nint) pixelData;
}
}
@ -89,7 +89,7 @@ namespace MoonWorks.Graphics
{
var result =
Refresh.Refresh_Image_Info(
(nint) ptr,
ptr,
data.Length,
out var w,
out var h,
@ -100,7 +100,7 @@ namespace MoonWorks.Graphics
height = (uint) h;
sizeInBytes = (uint) len;
return Conversions.ByteToBool(result);
return Conversions.IntToBool(result);
}
}
@ -141,9 +141,9 @@ namespace MoonWorks.Graphics
/// <summary>
/// Frees pixel data obtained from GetPixelData methods.
/// </summary>
public static void FreePixelData(IntPtr pixels)
public unsafe static void FreePixelData(IntPtr pixels)
{
Refresh.Refresh_Image_Free(pixels);
Refresh.Refresh_Image_Free((byte*) pixels);
}
/// <summary>
@ -159,7 +159,7 @@ namespace MoonWorks.Graphics
) {
var sizeInBytes = width * height * 4;
var pixelsPtr = NativeMemory.Alloc((nuint) sizeInBytes);
var pixelsPtr = (byte*) NativeMemory.Alloc((nuint) sizeInBytes);
var pixelsSpan = new Span<byte>(pixelsPtr, sizeInBytes);
transferBuffer.GetData(pixelsSpan, bufferOffsetInBytes);
@ -167,7 +167,7 @@ namespace MoonWorks.Graphics
if (bgra)
{
// if data is bgra, we have to swap the R and B channels
var rgbaPtr = NativeMemory.Alloc((nuint) sizeInBytes);
var rgbaPtr = (byte*) NativeMemory.Alloc((nuint) sizeInBytes);
var rgbaSpan = new Span<byte>(rgbaPtr, sizeInBytes);
for (var i = 0; i < sizeInBytes; i += 4)
@ -182,7 +182,7 @@ namespace MoonWorks.Graphics
pixelsPtr = rgbaPtr;
}
Refresh.Refresh_Image_SavePNG(path, (nint) pixelsPtr, width, height);
Refresh.Refresh_Image_SavePNG(path, pixelsPtr, width, height);
NativeMemory.Free(pixelsPtr);
}

View File

@ -3,14 +3,14 @@ using System.Threading;
namespace MoonWorks.Graphics;
public abstract class SDL_GpuResource : GraphicsResource
public abstract class RefreshResource : GraphicsResource
{
public IntPtr Handle { get => handle; internal set => handle = value; }
private IntPtr handle;
protected abstract Action<IntPtr, IntPtr> ReleaseFunction { get; }
protected SDL_GpuResource(GraphicsDevice device) : base(device)
protected RefreshResource(GraphicsDevice device) : base(device)
{
}

View File

@ -1,10 +1,10 @@
using System;
using System.Runtime.InteropServices;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
// Recreate certain types in here so we can hide the SDL_GpuCS namespace
// Recreate certain types in here so we can hide the Refresh namespace
public enum PrimitiveType
{
@ -334,9 +334,9 @@ public struct DepthStencilValue
}
// FIXME: can we do an unsafe cast somehow?
public SDL_Gpu.DepthStencilValue ToSDL()
public Refresh.DepthStencilValue ToRefresh()
{
return new SDL_Gpu.DepthStencilValue
return new Refresh.DepthStencilValue
{
Depth = Depth,
Stencil = Stencil
@ -369,9 +369,9 @@ public struct Rect
}
// FIXME: can we do an unsafe cast somehow?
public SDL_Gpu.Rect ToSDL()
public Refresh.Rect ToRefresh()
{
return new SDL_Gpu.Rect
return new Refresh.Rect
{
X = X,
Y = Y,
@ -421,9 +421,9 @@ public struct Viewport
MaxDepth = maxDepth;
}
public SDL_Gpu.Viewport ToSDL()
public Refresh.Viewport ToRefresh()
{
return new SDL_Gpu.Viewport
return new Refresh.Viewport
{
X = X,
Y = Y,
@ -452,13 +452,13 @@ public struct VertexBinding
};
}
public SDL_Gpu.VertexBinding ToSDL()
public Refresh.VertexBinding ToRefresh()
{
return new SDL_Gpu.VertexBinding
return new Refresh.VertexBinding
{
Binding = Binding,
Stride = Stride,
InputRate = (SDL_Gpu.VertexInputRate) InputRate
InputRate = (Refresh.VertexInputRate) InputRate
};
}
}
@ -471,13 +471,13 @@ public struct VertexAttribute
public VertexElementFormat Format;
public uint Offset;
public SDL_Gpu.VertexAttribute ToSDL()
public Refresh.VertexAttribute ToRefresh()
{
return new SDL_Gpu.VertexAttribute
return new Refresh.VertexAttribute
{
Location = Location,
Binding = Binding,
Format = (SDL_Gpu.VertexElementFormat) Format,
Format = (Refresh.VertexElementFormat) Format,
Offset = Offset
};
}
@ -491,14 +491,14 @@ public struct StencilOpState
public StencilOp DepthFailOp;
public CompareOp CompareOp;
public SDL_Gpu.StencilOpState ToSDL()
public Refresh.StencilOpState ToRefresh()
{
return new SDL_Gpu.StencilOpState
return new Refresh.StencilOpState
{
FailOp = (SDL_Gpu.StencilOp) FailOp,
PassOp = (SDL_Gpu.StencilOp) PassOp,
DepthFailOp = (SDL_Gpu.StencilOp) DepthFailOp,
CompareOp = (SDL_Gpu.CompareOp) CompareOp
FailOp = (Refresh.StencilOp) FailOp,
PassOp = (Refresh.StencilOp) PassOp,
DepthFailOp = (Refresh.StencilOp) DepthFailOp,
CompareOp = (Refresh.CompareOp) CompareOp
};
}
}
@ -574,20 +574,20 @@ public struct ColorAttachmentInfo
Cycle = cycle;
}
public SDL_Gpu.ColorAttachmentInfo ToSDL()
public Refresh.ColorAttachmentInfo ToRefresh()
{
return new SDL_Gpu.ColorAttachmentInfo
return new Refresh.ColorAttachmentInfo
{
TextureSlice = TextureSlice.ToSDL(),
ClearColor = new SDL_Gpu.Color
TextureSlice = TextureSlice.ToRefresh(),
ClearColor = new Refresh.Color
{
R = ClearColor.R / 255f,
G = ClearColor.G / 255f,
B = ClearColor.B / 255f,
A = ClearColor.A / 255f
},
LoadOp = (SDL_Gpu.LoadOp) LoadOp,
StoreOp = (SDL_Gpu.StoreOp) StoreOp,
LoadOp = (Refresh.LoadOp) LoadOp,
StoreOp = (Refresh.StoreOp) StoreOp,
Cycle = Conversions.BoolToInt(Cycle)
};
}
@ -720,16 +720,16 @@ public struct DepthStencilAttachmentInfo
Cycle = cycle;
}
public SDL_Gpu.DepthStencilAttachmentInfo ToSDL()
public Refresh.DepthStencilAttachmentInfo ToRefresh()
{
return new SDL_Gpu.DepthStencilAttachmentInfo
return new Refresh.DepthStencilAttachmentInfo
{
TextureSlice = TextureSlice.ToSDL(),
DepthStencilClearValue = DepthStencilClearValue.ToSDL(),
LoadOp = (SDL_Gpu.LoadOp) LoadOp,
StoreOp = (SDL_Gpu.StoreOp) StoreOp,
StencilLoadOp = (SDL_Gpu.LoadOp) StencilLoadOp,
StencilStoreOp = (SDL_Gpu.StoreOp) StencilStoreOp,
TextureSlice = TextureSlice.ToRefresh(),
DepthStencilClearValue = DepthStencilClearValue.ToRefresh(),
LoadOp = (Refresh.LoadOp) LoadOp,
StoreOp = (Refresh.StoreOp) StoreOp,
StencilLoadOp = (Refresh.LoadOp) StencilLoadOp,
StencilStoreOp = (Refresh.StoreOp) StencilStoreOp,
Cycle = Conversions.BoolToInt(Cycle)
};
}
@ -788,9 +788,9 @@ public struct BufferCopy
Size = size;
}
public SDL_Gpu.BufferCopy ToSDL()
public Refresh.BufferCopy ToRefresh()
{
return new SDL_Gpu.BufferCopy
return new Refresh.BufferCopy
{
SourceOffset = SrcOffset,
DestinationOffset = DstOffset,
@ -811,9 +811,9 @@ public readonly record struct BufferImageCopy(
uint BufferStride,
uint BufferImageHeight
) {
public SDL_Gpu.BufferImageCopy ToSDL()
public Refresh.BufferImageCopy ToRefresh()
{
return new SDL_Gpu.BufferImageCopy
return new Refresh.BufferImageCopy
{
BufferOffset = BufferOffset,
BufferStride = BufferStride,
@ -828,9 +828,9 @@ public readonly record struct GraphicsPipelineResourceInfo(
uint StorageTextureCount,
uint UniformBufferCount
) {
public SDL_Gpu.GraphicsPipelineResourceInfo ToSDL()
public Refresh.GraphicsPipelineResourceInfo ToRefresh()
{
return new SDL_Gpu.GraphicsPipelineResourceInfo
return new Refresh.GraphicsPipelineResourceInfo
{
SamplerCount = SamplerCount,
StorageBufferCount = StorageBufferCount,
@ -847,9 +847,9 @@ public readonly record struct ComputePipelineResourceInfo(
uint ReadWriteStorageBufferCount,
uint UniformBufferCount
) {
public SDL_Gpu.ComputePipelineResourceInfo ToSDL()
public Refresh.ComputePipelineResourceInfo ToRefresh()
{
return new SDL_Gpu.ComputePipelineResourceInfo
return new Refresh.ComputePipelineResourceInfo
{
ReadOnlyStorageTextureCount = ReadOnlyStorageTextureCount,
ReadOnlyStorageBufferCount = ReadOnlyStorageBufferCount,
@ -867,9 +867,9 @@ public readonly record struct BufferBinding(
GpuBuffer Buffer,
uint Offset
) {
public SDL_Gpu.BufferBinding ToSDL()
public Refresh.BufferBinding ToRefresh()
{
return new SDL_Gpu.BufferBinding
return new Refresh.BufferBinding
{
Buffer = Buffer.Handle,
Offset = Offset
@ -884,9 +884,9 @@ public readonly record struct TextureSamplerBinding(
Texture Texture,
Sampler Sampler
) {
public SDL_Gpu.TextureSamplerBinding ToSDL()
public Refresh.TextureSamplerBinding ToRefresh()
{
return new SDL_Gpu.TextureSamplerBinding
return new Refresh.TextureSamplerBinding
{
Texture = Texture.Handle,
Sampler = Sampler.Handle
@ -898,9 +898,9 @@ public readonly record struct StorageBufferReadWriteBinding(
GpuBuffer Buffer,
bool cycle
) {
public SDL_Gpu.StorageBufferReadWriteBinding ToSDL()
public Refresh.StorageBufferReadWriteBinding ToRefresh()
{
return new SDL_Gpu.StorageBufferReadWriteBinding
return new Refresh.StorageBufferReadWriteBinding
{
Buffer = Buffer.Handle,
Cycle = Conversions.BoolToInt(cycle)
@ -912,11 +912,11 @@ public readonly record struct StorageTextureReadWriteBinding(
in TextureSlice TextureSlice,
bool cycle
) {
public SDL_Gpu.StorageTextureReadWriteBinding ToSDL()
public Refresh.StorageTextureReadWriteBinding ToRefresh()
{
return new SDL_Gpu.StorageTextureReadWriteBinding
return new Refresh.StorageTextureReadWriteBinding
{
TextureSlice = TextureSlice.ToSDL(),
TextureSlice = TextureSlice.ToRefresh(),
Cycle = Conversions.BoolToInt(cycle)
};
}

View File

@ -1,6 +1,6 @@
using System;
using System.Runtime.InteropServices;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
/// <summary>
@ -59,7 +59,7 @@ public class RenderPass
}
#endif
SDL_Gpu.SDL_GpuBindGraphicsPipeline(
Refresh.Refresh_BindGraphicsPipeline(
Handle,
graphicsPipeline.Handle
);
@ -78,9 +78,9 @@ public class RenderPass
AssertRenderPassActive();
#endif
SDL_Gpu.SDL_GpuSetViewport(
Refresh.Refresh_SetViewport(
Handle,
viewport.ToSDL()
viewport.ToRefresh()
);
}
@ -98,9 +98,9 @@ public class RenderPass
}
#endif
SDL_Gpu.SDL_GpuSetScissor(
Refresh.Refresh_SetScissor(
Handle,
scissor.ToSDL()
scissor.ToRefresh()
);
}
@ -117,9 +117,9 @@ public class RenderPass
AssertGraphicsPipelineBound();
#endif
var sdlBufferBinding = bufferBinding.ToSDL();
var sdlBufferBinding = bufferBinding.ToRefresh();
SDL_Gpu.SDL_GpuBindVertexBuffers(
Refresh.Refresh_BindVertexBuffers(
Handle,
firstBinding,
&sdlBufferBinding,
@ -142,10 +142,10 @@ public class RenderPass
AssertGraphicsPipelineBound();
#endif
SDL_Gpu.SDL_GpuBindIndexBuffer(
Refresh.Refresh_BindIndexBuffer(
Handle,
bufferBinding.ToSDL(),
(SDL_Gpu.IndexElementSize) indexElementSize
bufferBinding.ToRefresh(),
(Refresh.IndexElementSize) indexElementSize
);
}
@ -163,9 +163,9 @@ public class RenderPass
AssertTextureHasSamplerFlag(textureSamplerBinding.Texture);
#endif
var sdlTextureSamplerBinding = textureSamplerBinding.ToSDL();
var sdlTextureSamplerBinding = textureSamplerBinding.ToRefresh();
SDL_Gpu.SDL_GpuBindVertexSamplers(
Refresh.Refresh_BindVertexSamplers(
Handle,
slot,
&sdlTextureSamplerBinding,
@ -183,9 +183,9 @@ public class RenderPass
AssertTextureHasGraphicsStorageFlag(textureSlice.Texture);
#endif
var sdlTextureSlice = textureSlice.ToSDL();
var sdlTextureSlice = textureSlice.ToRefresh();
SDL_Gpu.SDL_GpuBindVertexStorageTextures(
Refresh.Refresh_BindVertexStorageTextures(
Handle,
slot,
&sdlTextureSlice,
@ -205,7 +205,7 @@ public class RenderPass
var bufferHandle = buffer.Handle;
SDL_Gpu.SDL_GpuBindVertexStorageBuffers(
Refresh.Refresh_BindVertexStorageBuffers(
Handle,
slot,
&bufferHandle,
@ -223,9 +223,9 @@ public class RenderPass
AssertTextureHasSamplerFlag(textureSamplerBinding.Texture);
#endif
var sdlTextureSamplerBinding = textureSamplerBinding.ToSDL();
var sdlTextureSamplerBinding = textureSamplerBinding.ToRefresh();
SDL_Gpu.SDL_GpuBindFragmentSamplers(
Refresh.Refresh_BindFragmentSamplers(
Handle,
slot,
&sdlTextureSamplerBinding,
@ -243,9 +243,9 @@ public class RenderPass
AssertTextureHasGraphicsStorageFlag(textureSlice.Texture);
#endif
var sdlTextureSlice = textureSlice.ToSDL();
var sdlTextureSlice = textureSlice.ToRefresh();
SDL_Gpu.SDL_GpuBindFragmentStorageTextures(
Refresh.Refresh_BindFragmentStorageTextures(
Handle,
slot,
&sdlTextureSlice,
@ -265,7 +265,7 @@ public class RenderPass
var bufferHandle = buffer.Handle;
SDL_Gpu.SDL_GpuBindFragmentStorageBuffers(
Refresh.Refresh_BindFragmentStorageBuffers(
Handle,
slot,
&bufferHandle,
@ -287,7 +287,7 @@ public class RenderPass
}
#endif
SDL_Gpu.SDL_GpuPushVertexUniformData(
Refresh.Refresh_PushVertexUniformData(
Handle,
slot,
(nint) uniformsPtr,
@ -320,7 +320,7 @@ public class RenderPass
}
#endif
SDL_Gpu.SDL_GpuPushFragmentUniformData(
Refresh.Refresh_PushFragmentUniformData(
Handle,
slot,
(nint) uniformsPtr,
@ -356,7 +356,7 @@ public class RenderPass
AssertGraphicsPipelineBound();
#endif
SDL_Gpu.SDL_GpuDrawIndexedPrimitives(
Refresh.Refresh_DrawIndexedPrimitives(
Handle,
baseVertex,
startIndex,
@ -380,7 +380,7 @@ public class RenderPass
AssertGraphicsPipelineBound();
#endif
SDL_Gpu.SDL_GpuDrawPrimitives(
Refresh.Refresh_DrawPrimitives(
Handle,
vertexStart,
primitiveCount
@ -405,7 +405,7 @@ public class RenderPass
AssertGraphicsPipelineBound();
#endif
SDL_Gpu.SDL_GpuDrawPrimitivesIndirect(
Refresh.Refresh_DrawPrimitivesIndirect(
Handle,
buffer.Handle,
offsetInBytes,
@ -432,7 +432,7 @@ public class RenderPass
AssertGraphicsPipelineBound();
#endif
SDL_Gpu.SDL_GpuDrawIndexedPrimitivesIndirect(
Refresh.Refresh_DrawIndexedPrimitivesIndirect(
Handle,
buffer.Handle,
offsetInBytes,

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
using System;
namespace MoonWorks.Graphics
@ -6,9 +6,9 @@ namespace MoonWorks.Graphics
/// <summary>
/// Compute pipelines perform arbitrary parallel processing on input data.
/// </summary>
public class ComputePipeline : SDL_GpuResource
public class ComputePipeline : RefreshResource
{
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseComputePipeline;
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_ReleaseComputePipeline;
public ComputePipelineResourceInfo ResourceInfo { get; }
@ -18,13 +18,13 @@ namespace MoonWorks.Graphics
ComputePipelineResourceInfo resourceInfo
) : base(device)
{
var sdlComputePipelineCreateInfo = new SDL_Gpu.ComputePipelineCreateInfo
var sdlComputePipelineCreateInfo = new Refresh.ComputePipelineCreateInfo
{
ComputeShader = computeShader.Handle,
PipelineResourceInfo = resourceInfo.ToSDL()
PipelineResourceInfo = resourceInfo.ToRefresh()
};
Handle = SDL_Gpu.SDL_GpuCreateComputePipeline(
Handle = Refresh.Refresh_CreateComputePipeline(
device.Handle,
sdlComputePipelineCreateInfo
);

View File

@ -1,5 +1,5 @@
using System;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
@ -10,9 +10,9 @@ namespace MoonWorks.Graphics;
/// The Fence object itself is basically just a wrapper for the Refresh_Fence. <br/>
/// The internal handle is replaced so that we can pool Fence objects to manage garbage.
/// </summary>
public class Fence : SDL_GpuResource
public class Fence : RefreshResource
{
protected override Action<nint, nint> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseFence;
protected override Action<nint, nint> ReleaseFunction => Refresh.Refresh_ReleaseFence;
internal Fence(GraphicsDevice device) : base(device)
{

View File

@ -1,15 +1,15 @@
using System;
using System.Runtime.InteropServices;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
/// <summary>
/// GpuBuffers are generic data containers that can be used by the GPU.
/// </summary>
public class GpuBuffer : SDL_GpuResource
public class GpuBuffer : RefreshResource
{
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseBuffer;
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_ReleaseBuffer;
public BufferUsageFlags UsageFlags { get; }
@ -27,7 +27,7 @@ public class GpuBuffer : SDL_GpuResource
{
if (Device.DebugMode)
{
SDL_Gpu.SDL_GpuSetBufferName(
Refresh.Refresh_SetBufferName(
Device.Handle,
Handle,
value
@ -71,9 +71,9 @@ public class GpuBuffer : SDL_GpuResource
uint sizeInBytes
) : base(device)
{
Handle = SDL_Gpu.SDL_GpuCreateBuffer(
Handle = Refresh.Refresh_CreateBuffer(
device.Handle,
(SDL_Gpu.BufferUsageFlags) usageFlags,
(Refresh.BufferUsageFlags) usageFlags,
sizeInBytes
);
UsageFlags = usageFlags;

View File

@ -1,6 +1,6 @@
using System;
using System.Runtime.InteropServices;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
@ -8,9 +8,9 @@ namespace MoonWorks.Graphics
/// Graphics pipelines encapsulate all of the render state in a single object. <br/>
/// These pipelines are bound before draw calls are issued.
/// </summary>
public class GraphicsPipeline : SDL_GpuResource
public class GraphicsPipeline : RefreshResource
{
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseGraphicsPipeline;
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_ReleaseGraphicsPipeline;
public GraphicsPipelineResourceInfo VertexShaderResourceInfo { get; }
public GraphicsPipelineResourceInfo FragmentShaderResourceInfo { get; }
@ -25,34 +25,34 @@ namespace MoonWorks.Graphics
in GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
) : base(device)
{
SDL_Gpu.GraphicsPipelineCreateInfo sdlGraphicsPipelineCreateInfo;
Refresh.GraphicsPipelineCreateInfo sdlGraphicsPipelineCreateInfo;
var vertexAttributes = (SDL_Gpu.VertexAttribute*) NativeMemory.Alloc(
(nuint) (graphicsPipelineCreateInfo.VertexInputState.VertexAttributes.Length * Marshal.SizeOf<SDL_Gpu.VertexAttribute>())
var vertexAttributes = (Refresh.VertexAttribute*) NativeMemory.Alloc(
(nuint) (graphicsPipelineCreateInfo.VertexInputState.VertexAttributes.Length * Marshal.SizeOf<Refresh.VertexAttribute>())
);
for (var i = 0; i < graphicsPipelineCreateInfo.VertexInputState.VertexAttributes.Length; i += 1)
{
vertexAttributes[i] = graphicsPipelineCreateInfo.VertexInputState.VertexAttributes[i].ToSDL();
vertexAttributes[i] = graphicsPipelineCreateInfo.VertexInputState.VertexAttributes[i].ToRefresh();
}
var vertexBindings = (SDL_Gpu.VertexBinding*) NativeMemory.Alloc(
(nuint) (graphicsPipelineCreateInfo.VertexInputState.VertexBindings.Length * Marshal.SizeOf<SDL_Gpu.VertexBinding>())
var vertexBindings = (Refresh.VertexBinding*) NativeMemory.Alloc(
(nuint) (graphicsPipelineCreateInfo.VertexInputState.VertexBindings.Length * Marshal.SizeOf<Refresh.VertexBinding>())
);
for (var i = 0; i < graphicsPipelineCreateInfo.VertexInputState.VertexBindings.Length; i += 1)
{
vertexBindings[i] = graphicsPipelineCreateInfo.VertexInputState.VertexBindings[i].ToSDL();
vertexBindings[i] = graphicsPipelineCreateInfo.VertexInputState.VertexBindings[i].ToRefresh();
}
var colorAttachmentDescriptions = stackalloc SDL_Gpu.ColorAttachmentDescription[
var colorAttachmentDescriptions = stackalloc Refresh.ColorAttachmentDescription[
graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions.Length
];
for (var i = 0; i < graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions.Length; i += 1)
{
colorAttachmentDescriptions[i].Format = (SDL_Gpu.TextureFormat) graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[i].Format;
colorAttachmentDescriptions[i].BlendState = graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[i].BlendState.ToSDL();
colorAttachmentDescriptions[i].Format = (Refresh.TextureFormat) graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[i].Format;
colorAttachmentDescriptions[i].BlendState = graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[i].BlendState.ToRefresh();
}
sdlGraphicsPipelineCreateInfo.VertexShader = graphicsPipelineCreateInfo.VertexShader.Handle;
@ -63,26 +63,26 @@ namespace MoonWorks.Graphics
sdlGraphicsPipelineCreateInfo.VertexInputState.VertexBindings = vertexBindings;
sdlGraphicsPipelineCreateInfo.VertexInputState.VertexBindingCount = (uint) graphicsPipelineCreateInfo.VertexInputState.VertexBindings.Length;
sdlGraphicsPipelineCreateInfo.PrimitiveType = (SDL_Gpu.PrimitiveType) graphicsPipelineCreateInfo.PrimitiveType;
sdlGraphicsPipelineCreateInfo.PrimitiveType = (Refresh.PrimitiveType) graphicsPipelineCreateInfo.PrimitiveType;
sdlGraphicsPipelineCreateInfo.RasterizerState = graphicsPipelineCreateInfo.RasterizerState.ToSDL();
sdlGraphicsPipelineCreateInfo.MultisampleState = graphicsPipelineCreateInfo.MultisampleState.ToSDL();
sdlGraphicsPipelineCreateInfo.DepthStencilState = graphicsPipelineCreateInfo.DepthStencilState.ToSDL();
sdlGraphicsPipelineCreateInfo.RasterizerState = graphicsPipelineCreateInfo.RasterizerState.ToRefresh();
sdlGraphicsPipelineCreateInfo.MultisampleState = graphicsPipelineCreateInfo.MultisampleState.ToRefresh();
sdlGraphicsPipelineCreateInfo.DepthStencilState = graphicsPipelineCreateInfo.DepthStencilState.ToRefresh();
sdlGraphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentCount = (uint) graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions.Length;
sdlGraphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions = colorAttachmentDescriptions;
sdlGraphicsPipelineCreateInfo.AttachmentInfo.DepthStencilFormat = (SDL_Gpu.TextureFormat) graphicsPipelineCreateInfo.AttachmentInfo.DepthStencilFormat;
sdlGraphicsPipelineCreateInfo.AttachmentInfo.DepthStencilFormat = (Refresh.TextureFormat) graphicsPipelineCreateInfo.AttachmentInfo.DepthStencilFormat;
sdlGraphicsPipelineCreateInfo.AttachmentInfo.HasDepthStencilAttachment = Conversions.BoolToInt(graphicsPipelineCreateInfo.AttachmentInfo.HasDepthStencilAttachment);
sdlGraphicsPipelineCreateInfo.VertexResourceInfo = graphicsPipelineCreateInfo.VertexShaderResourceInfo.ToSDL();
sdlGraphicsPipelineCreateInfo.FragmentResourceInfo = graphicsPipelineCreateInfo.FragmentShaderResourceInfo.ToSDL();
sdlGraphicsPipelineCreateInfo.VertexResourceInfo = graphicsPipelineCreateInfo.VertexShaderResourceInfo.ToRefresh();
sdlGraphicsPipelineCreateInfo.FragmentResourceInfo = graphicsPipelineCreateInfo.FragmentShaderResourceInfo.ToRefresh();
sdlGraphicsPipelineCreateInfo.BlendConstants[0] = graphicsPipelineCreateInfo.BlendConstants.R;
sdlGraphicsPipelineCreateInfo.BlendConstants[1] = graphicsPipelineCreateInfo.BlendConstants.G;
sdlGraphicsPipelineCreateInfo.BlendConstants[2] = graphicsPipelineCreateInfo.BlendConstants.B;
sdlGraphicsPipelineCreateInfo.BlendConstants[3] = graphicsPipelineCreateInfo.BlendConstants.A;
Handle = SDL_Gpu.SDL_GpuCreateGraphicsPipeline(device.Handle, sdlGraphicsPipelineCreateInfo);
Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, sdlGraphicsPipelineCreateInfo);
if (Handle == IntPtr.Zero)
{
throw new Exception("Could not create graphics pipeline!");

View File

@ -1,23 +1,23 @@
using System;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
/// <summary>
/// A sampler specifies how a texture will be sampled in a shader.
/// </summary>
public class Sampler : SDL_GpuResource
public class Sampler : RefreshResource
{
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseSampler;
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_ReleaseSampler;
public Sampler(
GraphicsDevice device,
in SamplerCreateInfo samplerCreateInfo
) : base(device)
{
Handle = SDL_Gpu.SDL_GpuCreateSampler(
Handle = Refresh.Refresh_CreateSampler(
device.Handle,
samplerCreateInfo.ToSDL()
samplerCreateInfo.ToRefresh()
);
}
}

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
using System;
using System.IO;
using System.Runtime.InteropServices;
@ -8,9 +8,9 @@ namespace MoonWorks.Graphics
/// <summary>
/// Shader modules expect input in Refresh bytecode format.
/// </summary>
public class Shader : SDL_GpuResource
public class Shader : RefreshResource
{
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseShader;
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_ReleaseShader;
public unsafe Shader(
GraphicsDevice device,
@ -46,14 +46,14 @@ namespace MoonWorks.Graphics
var bytecodeSpan = new Span<byte>(bytecodeBuffer, (int) stream.Length);
stream.ReadExactly(bytecodeSpan);
SDL_Gpu.ShaderCreateInfo shaderCreateInfo;
Refresh.ShaderCreateInfo shaderCreateInfo;
shaderCreateInfo.CodeSize = (nuint) stream.Length;
shaderCreateInfo.Code = (byte*) bytecodeBuffer;
shaderCreateInfo.EntryPointName = entryPointName;
shaderCreateInfo.Stage = (SDL_Gpu.ShaderStage) shaderStage;
shaderCreateInfo.Format = (SDL_Gpu.ShaderFormat) shaderFormat;
shaderCreateInfo.Stage = (Refresh.ShaderStage) shaderStage;
shaderCreateInfo.Format = (Refresh.ShaderFormat) shaderFormat;
var shaderModule = SDL_Gpu.SDL_GpuCreateShader(
var shaderModule = Refresh.Refresh_CreateShader(
device.Handle,
shaderCreateInfo
);

View File

@ -1,13 +1,12 @@
using System;
using System.IO;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
/// <summary>
/// A container for pixel data.
/// </summary>
public class Texture : SDL_GpuResource
public class Texture : RefreshResource
{
public uint Width { get; internal set; }
public uint Height { get; internal set; }
@ -29,7 +28,7 @@ namespace MoonWorks.Graphics
{
if (Device.DebugMode)
{
SDL_Gpu.SDL_GpuSetTextureName(
Refresh.Refresh_SetTextureName(
Device.Handle,
Handle,
value
@ -41,7 +40,7 @@ namespace MoonWorks.Graphics
}
// FIXME: this allocates a delegate instance
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseTexture;
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_ReleaseTexture;
/// <summary>
/// Creates a 2D texture.
@ -179,9 +178,9 @@ namespace MoonWorks.Graphics
in TextureCreateInfo textureCreateInfo
) : base(device)
{
Handle = SDL_Gpu.SDL_GpuCreateTexture(
Handle = Refresh.Refresh_CreateTexture(
device.Handle,
textureCreateInfo.ToSDL()
textureCreateInfo.ToRefresh()
);
Format = textureCreateInfo.Format;

View File

@ -1,12 +1,12 @@
using System;
using System.Runtime.InteropServices;
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
public unsafe class TransferBuffer : SDL_GpuResource
public unsafe class TransferBuffer : RefreshResource
{
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseTransferBuffer;
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_ReleaseTransferBuffer;
/// <summary>
/// Size in bytes.
@ -48,10 +48,10 @@ namespace MoonWorks.Graphics
uint sizeInBytes
) : base(device)
{
Handle = SDL_Gpu.SDL_GpuCreateTransferBuffer(
Handle = Refresh.Refresh_CreateTransferBuffer(
device.Handle,
(SDL_Gpu.TransferUsage) usage,
(SDL_Gpu.TransferBufferMapFlags) mapFlags,
(Refresh.TransferUsage) usage,
(Refresh.TransferBufferMapFlags) mapFlags,
sizeInBytes
);
Size = sizeInBytes;
@ -82,11 +82,11 @@ namespace MoonWorks.Graphics
fixed (T* dataPtr = data)
{
SDL_Gpu.SDL_GpuSetTransferData(
Refresh.Refresh_SetTransferData(
Device.Handle,
(nint) dataPtr,
Handle,
new SDL_Gpu.BufferCopy
new Refresh.BufferCopy
{
SourceOffset = 0,
DestinationOffset = bufferOffsetInBytes,
@ -134,11 +134,11 @@ namespace MoonWorks.Graphics
fixed (T* dataPtr = data)
{
SDL_Gpu.SDL_GpuGetTransferData(
Refresh.Refresh_GetTransferData(
Device.Handle,
Handle,
(nint) dataPtr,
new SDL_Gpu.BufferCopy
new Refresh.BufferCopy
{
SourceOffset = bufferOffsetInBytes,
DestinationOffset = 0,

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
@ -106,18 +106,18 @@ namespace MoonWorks.Graphics
ColorWriteMask = ColorComponentFlags.None
};
public SDL_Gpu.ColorAttachmentBlendState ToSDL()
public Refresh.ColorAttachmentBlendState ToRefresh()
{
return new SDL_Gpu.ColorAttachmentBlendState
return new Refresh.ColorAttachmentBlendState
{
BlendEnable = Conversions.BoolToInt(BlendEnable),
AlphaBlendOp = (SDL_Gpu.BlendOp) AlphaBlendOp,
ColorBlendOp = (SDL_Gpu.BlendOp) ColorBlendOp,
ColorWriteMask = (SDL_Gpu.ColorComponentFlags) ColorWriteMask,
DestinationAlphaBlendFactor = (SDL_Gpu.BlendFactor) DestinationAlphaBlendFactor,
DestinationColorBlendFactor = (SDL_Gpu.BlendFactor) DestinationColorBlendFactor,
SourceAlphaBlendFactor = (SDL_Gpu.BlendFactor) SourceAlphaBlendFactor,
SourceColorBlendFactor = (SDL_Gpu.BlendFactor) SourceColorBlendFactor
AlphaBlendOp = (Refresh.BlendOp) AlphaBlendOp,
ColorBlendOp = (Refresh.BlendOp) ColorBlendOp,
ColorWriteMask = (Refresh.ColorComponentFlags) ColorWriteMask,
DestinationAlphaBlendFactor = (Refresh.BlendFactor) DestinationAlphaBlendFactor,
DestinationColorBlendFactor = (Refresh.BlendFactor) DestinationColorBlendFactor,
SourceAlphaBlendFactor = (Refresh.BlendFactor) SourceAlphaBlendFactor,
SourceColorBlendFactor = (Refresh.BlendFactor) SourceColorBlendFactor
};
}
}

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
@ -93,17 +93,17 @@ namespace MoonWorks.Graphics
StencilTestEnable = false
};
public SDL_Gpu.DepthStencilState ToSDL()
public Refresh.DepthStencilState ToRefresh()
{
return new SDL_Gpu.DepthStencilState
return new Refresh.DepthStencilState
{
DepthTestEnable = Conversions.BoolToInt(DepthTestEnable),
BackStencilState = BackStencilState.ToSDL(),
FrontStencilState = FrontStencilState.ToSDL(),
BackStencilState = BackStencilState.ToRefresh(),
FrontStencilState = FrontStencilState.ToRefresh(),
CompareMask = CompareMask,
WriteMask = WriteMask,
Reference = Reference,
CompareOp = (SDL_Gpu.CompareOp) CompareOp,
CompareOp = (Refresh.CompareOp) CompareOp,
DepthBoundsTestEnable = Conversions.BoolToInt(DepthBoundsTestEnable),
DepthWriteEnable = Conversions.BoolToInt(DepthWriteEnable),
MinDepthBounds = MinDepthBounds,

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
@ -24,11 +24,11 @@ namespace MoonWorks.Graphics
SampleMask = sampleMask;
}
public SDL_Gpu.MultisampleState ToSDL()
public Refresh.MultisampleState ToRefresh()
{
return new SDL_Gpu.MultisampleState
return new Refresh.MultisampleState
{
MultisampleCount = (SDL_Gpu.SampleCount) MultisampleCount,
MultisampleCount = (Refresh.SampleCount) MultisampleCount,
SampleMask = SampleMask
};
}

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
@ -106,17 +106,17 @@ public struct RasterizerState
DepthBiasEnable = false
};
public SDL_Gpu.RasterizerState ToSDL()
public Refresh.RasterizerState ToRefresh()
{
return new SDL_Gpu.RasterizerState
return new Refresh.RasterizerState
{
CullMode = (SDL_Gpu.CullMode) CullMode,
CullMode = (Refresh.CullMode) CullMode,
DepthBiasClamp = DepthBiasClamp,
DepthBiasConstantFactor = DepthBiasConstantFactor,
DepthBiasEnable = Conversions.BoolToInt(DepthBiasEnable),
DepthBiasSlopeFactor = DepthBiasSlopeFactor,
FillMode = (SDL_Gpu.FillMode) FillMode,
FrontFace = (SDL_Gpu.FrontFace) FrontFace
FillMode = (Refresh.FillMode) FillMode,
FrontFace = (Refresh.FrontFace) FrontFace
};
}
}

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
@ -150,24 +150,24 @@ public struct SamplerCreateInfo
MaxLod = 1000
};
public SDL_Gpu.SamplerCreateInfo ToSDL()
public Refresh.SamplerCreateInfo ToRefresh()
{
return new SDL_Gpu.SamplerCreateInfo
return new Refresh.SamplerCreateInfo
{
MinFilter = (SDL_Gpu.Filter) MinFilter,
MagFilter = (SDL_Gpu.Filter) MagFilter,
MipmapMode = (SDL_Gpu.SamplerMipmapMode) MipmapMode,
AddressModeU = (SDL_Gpu.SamplerAddressMode) AddressModeU,
AddressModeV = (SDL_Gpu.SamplerAddressMode) AddressModeV,
AddressModeW = (SDL_Gpu.SamplerAddressMode) AddressModeW,
MinFilter = (Refresh.Filter) MinFilter,
MagFilter = (Refresh.Filter) MagFilter,
MipmapMode = (Refresh.SamplerMipmapMode) MipmapMode,
AddressModeU = (Refresh.SamplerAddressMode) AddressModeU,
AddressModeV = (Refresh.SamplerAddressMode) AddressModeV,
AddressModeW = (Refresh.SamplerAddressMode) AddressModeW,
MipLodBias = MipLodBias,
AnisotropyEnable = Conversions.BoolToByte(AnisotropyEnable),
AnisotropyEnable = Conversions.BoolToInt(AnisotropyEnable),
MaxAnisotropy = MaxAnisotropy,
CompareEnable = Conversions.BoolToByte(CompareEnable),
CompareOp = (SDL_Gpu.CompareOp) CompareOp,
CompareEnable = Conversions.BoolToInt(CompareEnable),
CompareOp = (Refresh.CompareOp) CompareOp,
MinLod = MinLod,
MaxLod = MaxLod,
BorderColor = (SDL_Gpu.BorderColor) BorderColor
BorderColor = (Refresh.BorderColor) BorderColor
};
}
}

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
@ -17,9 +17,9 @@ namespace MoonWorks.Graphics
public TextureFormat Format;
public TextureUsageFlags UsageFlags;
public SDL_Gpu.TextureCreateInfo ToSDL()
public Refresh.TextureCreateInfo ToRefresh()
{
return new SDL_Gpu.TextureCreateInfo
return new Refresh.TextureCreateInfo
{
Width = Width,
Height = Height,
@ -27,9 +27,9 @@ namespace MoonWorks.Graphics
IsCube = Conversions.BoolToInt(IsCube),
LayerCount = LayerCount,
LevelCount = LevelCount,
SampleCount = (SDL_Gpu.SampleCount) SampleCount,
Format = (SDL_Gpu.TextureFormat) Format,
UsageFlags = (SDL_Gpu.TextureUsageFlags) UsageFlags
SampleCount = (Refresh.SampleCount) SampleCount,
Format = (Refresh.TextureFormat) Format,
UsageFlags = (Refresh.TextureUsageFlags) UsageFlags
};
}
}

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics
{
@ -29,11 +29,11 @@ namespace MoonWorks.Graphics
Depth = texture.Depth;
}
public SDL_Gpu.TextureRegion ToSDL()
public Refresh.TextureRegion ToRefresh()
{
return new SDL_Gpu.TextureRegion
return new Refresh.TextureRegion
{
TextureSlice = TextureSlice.ToSDL(),
TextureSlice = TextureSlice.ToRefresh(),
X = X,
Y = Y,
Z = Z,

View File

@ -1,4 +1,4 @@
using SDL2_gpuCS;
using RefreshCS;
namespace MoonWorks.Graphics;
/// <summary>
@ -19,9 +19,9 @@ public struct TextureSlice
Layer = 0;
}
public SDL_Gpu.TextureSlice ToSDL()
public Refresh.TextureSlice ToRefresh()
{
return new SDL_Gpu.TextureSlice
return new Refresh.TextureSlice
{
Texture = Texture.Handle,
MipLevel = MipLevel,

View File

@ -242,11 +242,11 @@ namespace MoonWorks.Video
if (TransferBuffer == null || TransferBuffer.Size < ySpan.Length + uSpan.Length + vSpan.Length)
{
TransferBuffer?.Dispose();
TransferBuffer = new TransferBuffer(Device, TransferUsage.Texture, (uint) (ySpan.Length + uSpan.Length + vSpan.Length));
TransferBuffer = new TransferBuffer(Device, TransferUsage.Texture, TransferBufferMapFlags.Write, (uint) (ySpan.Length + uSpan.Length + vSpan.Length));
}
TransferBuffer.SetData(ySpan, 0, TransferOptions.Cycle);
TransferBuffer.SetData(uSpan, (uint) ySpan.Length, TransferOptions.Unsafe);
TransferBuffer.SetData(vSpan, (uint) (ySpan.Length + uSpan.Length), TransferOptions.Unsafe);
TransferBuffer.SetData(ySpan, 0, true);
TransferBuffer.SetData(uSpan, (uint) ySpan.Length, false);
TransferBuffer.SetData(vSpan, (uint) (ySpan.Length + uSpan.Length), false);
uOffset = (uint) ySpan.Length;
vOffset = (uint) (ySpan.Length + vSpan.Length);
@ -257,9 +257,9 @@ namespace MoonWorks.Video
var commandBuffer = Device.AcquireCommandBuffer();
commandBuffer.BeginCopyPass();
var copyPass = commandBuffer.BeginCopyPass();
commandBuffer.UploadToTexture(
copyPass.UploadToTexture(
TransferBuffer,
yTexture,
new BufferImageCopy
@ -268,10 +268,10 @@ namespace MoonWorks.Video
BufferStride = yStride,
BufferImageHeight = yTexture.Height
},
WriteOptions.Cycle
true
);
commandBuffer.UploadToTexture(
copyPass.UploadToTexture(
TransferBuffer,
uTexture,
new BufferImageCopy{
@ -279,10 +279,10 @@ namespace MoonWorks.Video
BufferStride = uvStride,
BufferImageHeight = uTexture.Height
},
WriteOptions.Cycle
true
);
commandBuffer.UploadToTexture(
copyPass.UploadToTexture(
TransferBuffer,
vTexture,
new BufferImageCopy
@ -291,25 +291,22 @@ namespace MoonWorks.Video
BufferStride = uvStride,
BufferImageHeight = vTexture.Height
},
WriteOptions.Cycle
true
);
commandBuffer.EndCopyPass();
commandBuffer.EndCopyPass(copyPass);
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(RenderTexture, WriteOptions.Cycle, Color.Black)
var renderPass = commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(RenderTexture, true, Color.Black)
);
commandBuffer.BindGraphicsPipeline(Device.VideoPipeline);
commandBuffer.BindFragmentSamplers(
new TextureSamplerBinding(yTexture, LinearSampler),
new TextureSamplerBinding(uTexture, LinearSampler),
new TextureSamplerBinding(vTexture, LinearSampler)
);
renderPass.BindGraphicsPipeline(Device.VideoPipeline);
renderPass.BindFragmentSamplers(new TextureSamplerBinding(yTexture, LinearSampler), 0);
renderPass.BindFragmentSamplers(new TextureSamplerBinding(uTexture, LinearSampler), 1);
renderPass.BindFragmentSamplers(new TextureSamplerBinding(vTexture, LinearSampler), 2);
renderPass.DrawPrimitives(0, 1);
commandBuffer.DrawPrimitives(0, 1);
commandBuffer.EndRenderPass();
commandBuffer.EndRenderPass(renderPass);
Device.Submit(commandBuffer);
}