Skip to content

Commit 5e04be7

Browse files
[Rendering] WIP;
1 parent c0d0168 commit 5e04be7

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

Engine/Staple.Core/Rendering/RenderSystem/Backend/Impls/SDLGPU/Commands/SDLGPURenderCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ state.indexBuffer is not SDLGPUIndexBuffer index ||
2828

2929
if(renderPass == nint.Zero)
3030
{
31-
throw new InvalidOperationException("Can't render without a render pass!");
31+
backend.ResumeRenderPass();
32+
33+
renderPass = backend.renderPass;
3234
}
3335

3436
SDL.SDL_BindGPUGraphicsPipeline(renderPass, pipeline);

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,83 @@ public void FinishPasses()
387387
}
388388
}
389389

390+
internal void ResumeRenderPass()
391+
{
392+
FinishPasses();
393+
394+
var texture = nint.Zero;
395+
var width = 0;
396+
var height = 0;
397+
398+
SDLGPUTexture depthTexture = null;
399+
400+
if (viewData.renderTarget == null)
401+
{
402+
texture = swapchainTexture;
403+
width = swapchainWidth;
404+
height = swapchainHeight;
405+
406+
depthTexture = depthTexture as SDLGPUTexture;
407+
408+
if (depthTexture == null)
409+
{
410+
UpdateDepthTextureIfNeeded(true);
411+
412+
depthTexture = depthTexture as SDLGPUTexture;
413+
}
414+
}
415+
else
416+
{
417+
//TODO: texture
418+
419+
width = viewData.renderTarget.width;
420+
height = viewData.renderTarget.height;
421+
422+
return;
423+
}
424+
425+
if (texture == nint.Zero ||
426+
(depthTexture?.Disposed ?? true) ||
427+
TryGetTexture(depthTexture.handle, out var depthTextureResource) == false)
428+
{
429+
return;
430+
}
431+
432+
var colorTarget = new SDL.SDL_GPUColorTargetInfo()
433+
{
434+
load_op = SDL.SDL_GPULoadOp.SDL_GPU_LOADOP_LOAD,
435+
store_op = SDL.SDL_GPUStoreOp.SDL_GPU_STOREOP_STORE,
436+
texture = texture,
437+
};
438+
439+
var depthTarget = new SDL.SDL_GPUDepthStencilTargetInfo()
440+
{
441+
clear_depth = 1,
442+
load_op = SDL.SDL_GPULoadOp.SDL_GPU_LOADOP_LOAD,
443+
store_op = SDL.SDL_GPUStoreOp.SDL_GPU_STOREOP_STORE,
444+
texture = depthTextureResource.texture,
445+
};
446+
447+
renderPass = SDL.SDL_BeginGPURenderPass(commandBuffer, [colorTarget], 1, in depthTarget);
448+
449+
if (renderPass == nint.Zero)
450+
{
451+
return;
452+
}
453+
454+
var viewportData = new SDL.SDL_GPUViewport()
455+
{
456+
x = (int)(viewData.viewport.X * width),
457+
y = (int)(viewData.viewport.Y * height),
458+
w = (int)(viewData.viewport.Z * width),
459+
h = (int)(viewData.viewport.W * height),
460+
min_depth = 0,
461+
max_depth = 1,
462+
};
463+
464+
SDL.SDL_SetGPUViewport(renderPass, in viewportData);
465+
}
466+
390467
public void BeginRenderPass(RenderTarget target, CameraClearMode clear, Color clearColor, Vector4 viewport,
391468
in Matrix4x4 view, in Matrix4x4 projection)
392469
{

0 commit comments

Comments
 (0)