1
+ #include < array>
1
2
#include < unordered_set>
2
3
#include " StdAfxRD.h"
3
4
#include " xmath.h"
@@ -82,11 +83,10 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
82
83
desc.logger .func = slog_func;
83
84
84
85
// Setup swapchain and fill color
85
- render_targets.emplace_back ();
86
- auto & swapchain_pass = render_targets[0 ].render_pass ;
87
- swapchain_pass.swapchain .width = ScreenSize.x ;
88
- swapchain_pass.swapchain .height = ScreenSize.y ;
89
- swapchain_pass.swapchain .sample_count = 1 ;
86
+ swapchain = {};
87
+ swapchain.width = ScreenSize.x ;
88
+ swapchain.height = ScreenSize.y ;
89
+ swapchain.sample_count = 1 ;
90
90
fill_color = sg_color { 0 .0f , 0 .0f , 0 .0f , 1 .0f };
91
91
92
92
// OpenGL / OpenGLES
@@ -131,8 +131,7 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
131
131
}
132
132
printf (" GPU vendor: %s, renderer: %s\n " , glGetString (GL_VENDOR), glGetString (GL_RENDER));
133
133
134
- auto & swapchain_pass = render_targets[0 ].render_pass ;
135
- swapchain_pass.swapchain .gl .framebuffer = 0 ;
134
+ swapchain.gl .framebuffer = 0 ;
136
135
#endif // PERIMETER_SOKOL_GL
137
136
138
137
// Direct3D
@@ -215,8 +214,7 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
215
214
dxgiAdapter->Release ();
216
215
217
216
// Create swap chain
218
- auto & swapchain_pass = render_targets[0 ].render_pass ;
219
- uint32_t sample_count = swapchain_pass.swapchain .sample_count ;
217
+ uint32_t sample_count = swapchain.sample_count ;
220
218
DXGI_SWAP_CHAIN_DESC* swap_chain_desc = &d3d_context->swap_chain_desc ;
221
219
memset (&d3d_context->swap_chain_desc , 0 , sizeof (DXGI_SWAP_CHAIN_DESC));
222
220
swap_chain_desc->BufferDesc .Width = static_cast <uint32_t >(xScr);
@@ -253,7 +251,7 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
253
251
SDL_SetHintWithPriority (SDL_HINT_RENDER_DRIVER, " metal" , SDL_HINT_OVERRIDE);
254
252
255
253
// Setup metal sokol context
256
- sokol_metal_setup (sdl_window, &desc, &swapchain_pass. swapchain , ScreenHZ);
254
+ sokol_metal_setup (sdl_window, &desc, &swapchain, ScreenHZ);
257
255
#endif
258
256
259
257
const char * render_driver = SDL_GetHint (SDL_HINT_RENDER_DRIVER);
@@ -334,9 +332,8 @@ bool cSokolRender::ChangeSize(int xScr, int yScr, int mode) {
334
332
#endif
335
333
336
334
// Update swapchain
337
- auto & swapchain_pass = render_targets[0 ].render_pass ;
338
- swapchain_pass.swapchain .width = ScreenSize.x ;
339
- swapchain_pass.swapchain .height = ScreenSize.y ;
335
+ swapchain.width = ScreenSize.x ;
336
+ swapchain.height = ScreenSize.y ;
340
337
341
338
#ifdef SOKOL_D3D11
342
339
if (d3d_context->swap_chain && need_resize) {
@@ -391,10 +388,9 @@ int cSokolRender::Done() {
391
388
}
392
389
#endif
393
390
#ifdef SOKOL_METAL
394
- auto & swapchain_pass = render_targets[0 ].render_pass ;
395
- if (swapchain_pass.swapchain .metal .current_drawable != nullptr ) {
391
+ if (swapchain.metal .current_drawable != nullptr ) {
396
392
RenderSubmitEvent (RenderEvent::DONE, " Sokol Metal shutdown" );
397
- sokol_metal_destroy (&swapchain_pass. swapchain );
393
+ sokol_metal_destroy (&swapchain);
398
394
}
399
395
#endif
400
396
#ifdef PERIMETER_SOKOL_GL
@@ -461,8 +457,8 @@ void cSokolRender::ClearPooledResources(uint32_t max_life) {
461
457
462
458
void cSokolRender::ClearCommands () {
463
459
std::unordered_set<SokolResourceBuffer*> pooled;
464
- for ( auto & render_target : render_targets ) {
465
- for (SokolCommand* command : render_target. commands ) {
460
+ auto ClearCommands = [&pooled, this ](std::vector<SokolCommand*>& commands ) {
461
+ for (SokolCommand* command : commands) {
466
462
// Reclaim resources that can be reused
467
463
SokolResourceBuffer* vertex_buffer = command->vertex_buffer ;
468
464
if (vertex_buffer && vertex_buffer->key != SokolResourceKeyNone && pooled.count (vertex_buffer) == 0 ) {
@@ -487,9 +483,18 @@ void cSokolRender::ClearCommands() {
487
483
488
484
delete command;
489
485
}
490
- render_target.commands .clear ();
486
+ };
487
+
488
+ for (auto & target : std::array<SokolRenderTarget*, 2 >{shadowMapRenderTarget, lightMapRenderTarget}) {
489
+ if (target != nullptr ) {
490
+ ClearCommands (target->commands );
491
+ target->commands .clear ();
492
+ }
491
493
}
492
494
495
+ ClearCommands (commands);
496
+ commands.clear ();
497
+
493
498
#ifdef PERIMETER_DEBUG
494
499
// printf("%ld %ld\n", reclaimed.size(), bufferPool.size());
495
500
#endif
@@ -593,17 +598,15 @@ void cSokolRender::d3d_CreateDefaultRenderTarget() {
593
598
assert (SUCCEEDED (hr) && d3d_context->depth_stencil_view );
594
599
595
600
// Apply into swapchain pass
596
- auto & swapchain_pass = render_targets[0 ].render_pass ;
597
- swapchain_pass.swapchain .d3d11 .render_view = 1 < sample_count ? d3d_context->msaa_view : d3d_context->render_target_view ;
598
- swapchain_pass.swapchain .d3d11 .resolve_view = 1 < sample_count ? d3d_context->render_target_view : nullptr ;
599
- swapchain_pass.swapchain .d3d11 .depth_stencil_view = d3d_context->depth_stencil_view ;
601
+ swapchain.d3d11 .render_view = 1 < sample_count ? d3d_context->msaa_view : d3d_context->render_target_view ;
602
+ swapchain.d3d11 .resolve_view = 1 < sample_count ? d3d_context->render_target_view : nullptr ;
603
+ swapchain.d3d11 .depth_stencil_view = d3d_context->depth_stencil_view ;
600
604
}
601
605
602
606
void cSokolRender::d3d_DestroyDefaultRenderTarget () {
603
- auto & swapchain_pass = render_targets[0 ].render_pass ;
604
- swapchain_pass.swapchain .d3d11 .render_view = nullptr ;
605
- swapchain_pass.swapchain .d3d11 .resolve_view = nullptr ;
606
- swapchain_pass.swapchain .d3d11 .depth_stencil_view = nullptr ;
607
+ swapchain.d3d11 .render_view = nullptr ;
608
+ swapchain.d3d11 .resolve_view = nullptr ;
609
+ swapchain.d3d11 .depth_stencil_view = nullptr ;
607
610
RELEASE (d3d_context->render_target_texture );
608
611
RELEASE (d3d_context->render_target_view );
609
612
RELEASE (d3d_context->depth_stencil_texture );
0 commit comments