Skip to content

Commit 51d13e4

Browse files
[Rendering] WIP;
1 parent 9c7ceb2 commit 51d13e4

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

Engine/Staple.Core/Rendering/Camera/Camera.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public sealed class Camera : IComponent
5959
/// <summary>
6060
/// The clear color for the camera
6161
/// </summary>
62-
public Color32 clearColor;
62+
public Color32 clearColor = Color32.LightBlue;
6363

6464
/// <summary>
6565
/// The layers this camera handles

Engine/Staple.Core/Rendering/Material.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ internal Texture[] Textures
129129
textures[0] = MainTexture;
130130
}
131131

132-
var counter = 1;
132+
var counter = hasMainTexture ? 1 : 0;
133133

134134
foreach (var pair in parameters)
135135
{

Engine/Staple.Core/Rendering/RenderSystem/Backend/Impls/SDLGPU/SDLGPURendererBackend.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,27 @@ public IShaderProgram CreateShaderVertexFragment(byte[] vertex, byte[] fragment,
259259
{
260260
unsafe
261261
{
262-
var entryPointBytes = Encoding.UTF8.GetBytes("main");
262+
var vertexEntryPointBytes = Encoding.UTF8.GetBytes("main");
263+
var fragmentEntryPointBytes = Encoding.UTF8.GetBytes("main");
263264

264265
var vertexShader = nint.Zero;
265266
var fragmentShader = nint.Zero;
266267

267-
fixed (byte* e = entryPointBytes)
268+
fixed (byte* entry = vertexEntryPointBytes)
268269
{
269270
fixed (byte* v = vertex)
270271
{
271272
var info = new SDL.SDL_GPUShaderCreateInfo()
272273
{
273274
code = v,
274275
code_size = (uint)vertex.Length,
275-
entrypoint = e,
276-
format = SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_SPIRV,
276+
entrypoint = entry,
277+
format = RenderWindow.CurrentRenderer switch
278+
{
279+
RendererType.Direct3D12 => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_DXIL,
280+
RendererType.Metal => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_MSL,
281+
_ => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_SPIRV,
282+
},
277283
stage = SDL.SDL_GPUShaderStage.SDL_GPU_SHADERSTAGE_VERTEX,
278284
num_samplers = (uint)vertexMetrics.samplerCount,
279285
num_storage_buffers = (uint)vertexMetrics.storageBufferCount,
@@ -283,20 +289,28 @@ public IShaderProgram CreateShaderVertexFragment(byte[] vertex, byte[] fragment,
283289

284290
vertexShader = SDL.SDL_CreateGPUShader(device, in info);
285291

286-
if(vertexShader == nint.Zero)
292+
if (vertexShader == nint.Zero)
287293
{
288294
return null;
289295
}
290296
}
297+
}
291298

299+
fixed (byte* entry = fragmentEntryPointBytes)
300+
{
292301
fixed (byte* f = fragment)
293302
{
294303
var info = new SDL.SDL_GPUShaderCreateInfo()
295304
{
296305
code = f,
297306
code_size = (uint)fragment.Length,
298-
entrypoint = e,
299-
format = SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_SPIRV,
307+
entrypoint = entry,
308+
format = RenderWindow.CurrentRenderer switch
309+
{
310+
RendererType.Direct3D12 => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_DXIL,
311+
RendererType.Metal => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_MSL,
312+
_ => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_SPIRV,
313+
},
300314
stage = SDL.SDL_GPUShaderStage.SDL_GPU_SHADERSTAGE_FRAGMENT,
301315
num_samplers = (uint)fragmentMetrics.samplerCount,
302316
num_storage_buffers = (uint)fragmentMetrics.storageBufferCount,
@@ -336,7 +350,12 @@ public IShaderProgram CreateShaderCompute(byte[] compute, ComputeShaderMetrics m
336350
code = c,
337351
code_size = (uint)compute.Length,
338352
entrypoint = e,
339-
format = SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_SPIRV,
353+
format = RenderWindow.CurrentRenderer switch
354+
{
355+
RendererType.Direct3D12 => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_DXIL,
356+
RendererType.Metal => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_MSL,
357+
_ => SDL.SDL_GPUShaderFormat.SDL_GPU_SHADERFORMAT_SPIRV,
358+
},
340359
num_samplers = (uint)metrics.samplerCount,
341360
num_uniform_buffers = (uint)metrics.uniformBufferCount,
342361
num_readonly_storage_buffers = (uint)metrics.readOnlyStorageBufferCount,

0 commit comments

Comments
 (0)