MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / main

Function main

samples/render_graph/rg-triangle/triangle.cpp:134–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134int main(int argc, char* argv[])
135{
136 if (SDL_Init(SDL_INIT_EVERYTHING) != 0) return -1;
137 sdl_window = SDL_CreateWindow((const char*)gCGPUBackendNames[backend],
138 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
139 BACK_BUFFER_WIDTH, BACK_BUFFER_HEIGHT,
140 SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
141 SDL_VERSION(&wmInfo.version);
142 SDL_GetWindowWMInfo(sdl_window, &wmInfo);
143 create_api_objects();
144 create_render_pipeline();
145 // initialize
146 namespace render_graph = skr::render_graph;
147 auto graph = render_graph::RenderGraph::create(
148 [=](render_graph::RenderGraphBuilder& builder) {
149 builder.with_device(device)
150 .with_gfx_queue(gfx_queue);
151 });
152 // loop
153 bool quit = false;
154 while (!quit)
155 {
156 SDL_Event event;
157 while (SDL_PollEvent(&event))
158 {
159 if (SDL_GetWindowID(sdl_window) == event.window.windowID)
160 {
161 if (!SDLEventHandler(&event, sdl_window))
162 {
163 quit = true;
164 }
165 }
166 if (event.type == SDL_WINDOWEVENT)
167 {
168 Uint8 window_event = event.window.event;
169 if (window_event == SDL_WINDOWEVENT_SIZE_CHANGED)
170 {
171 cgpu_wait_queue_idle(gfx_queue);
172 cgpu_free_swapchain(swapchain);
173 int width = 0, height = 0;
174 SDL_GetWindowSize(sdl_window, &width, &height);
175 CGPUSwapChainDescriptor chain_desc = {};
176 chain_desc.present_queues = &gfx_queue;
177 chain_desc.present_queues_count = 1;
178 chain_desc.width = width;
179 chain_desc.height = height;
180 chain_desc.surface = surface;
181 chain_desc.image_count = 3;
182 chain_desc.format = CGPU_FORMAT_R8G8B8A8_UNORM;
183 chain_desc.enable_vsync = true;
184 swapchain = cgpu_create_swapchain(device, &chain_desc);
185 }
186 }
187 }
188 // acquire frame
189 cgpu_wait_fences(&present_fence, 1);
190 CGPUAcquireNextDescriptor acquire_desc = {};
191 acquire_desc.fence = present_fence;

Callers

nothing calls this directly

Calls 15

cgpu_wait_queue_idleFunction · 0.85
cgpu_free_swapchainFunction · 0.85
cgpu_create_swapchainFunction · 0.85
cgpu_wait_fencesFunction · 0.85
cgpu_acquire_next_imageFunction · 0.85
cgpu_render_encoder_drawFunction · 0.85
cgpu_queue_presentFunction · 0.85
create_textureMethod · 0.80
add_render_passMethod · 0.80
add_present_passMethod · 0.80

Tested by

no test coverage detected