mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-05 19:08:12 +00:00
tests: Update GPU tests to use new swapchain best practice
This commit is contained in:
@@ -82,26 +82,25 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
}
|
||||
|
||||
SDL_GPUTexture *swapchainTexture;
|
||||
if (!SDL_AcquireGPUSwapchainTexture(cmdbuf, state->windows[0], &swapchainTexture, NULL, NULL)) {
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(cmdbuf, state->windows[0], &swapchainTexture, NULL, NULL)) {
|
||||
SDL_Log("SDL_AcquireGPUSwapchainTexture failed: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
if (swapchainTexture != NULL) {
|
||||
const double currentTime = (double)SDL_GetPerformanceCounter() / SDL_GetPerformanceFrequency();
|
||||
SDL_GPURenderPass *renderPass;
|
||||
SDL_GPUColorTargetInfo color_target_info;
|
||||
SDL_zero(color_target_info);
|
||||
color_target_info.texture = swapchainTexture;
|
||||
color_target_info.clear_color.r = (float)(0.5 + 0.5 * SDL_sin(currentTime));
|
||||
color_target_info.clear_color.g = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 2 / 3));
|
||||
color_target_info.clear_color.b = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 4 / 3));
|
||||
color_target_info.clear_color.a = 1.0f;
|
||||
color_target_info.load_op = SDL_GPU_LOADOP_CLEAR;
|
||||
color_target_info.store_op = SDL_GPU_STOREOP_STORE;
|
||||
|
||||
renderPass = SDL_BeginGPURenderPass(cmdbuf, &color_target_info, 1, NULL);
|
||||
SDL_EndGPURenderPass(renderPass);
|
||||
}
|
||||
const double currentTime = (double)SDL_GetPerformanceCounter() / SDL_GetPerformanceFrequency();
|
||||
SDL_GPURenderPass *renderPass;
|
||||
SDL_GPUColorTargetInfo color_target_info;
|
||||
SDL_zero(color_target_info);
|
||||
color_target_info.texture = swapchainTexture;
|
||||
color_target_info.clear_color.r = (float)(0.5 + 0.5 * SDL_sin(currentTime));
|
||||
color_target_info.clear_color.g = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 2 / 3));
|
||||
color_target_info.clear_color.b = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 4 / 3));
|
||||
color_target_info.clear_color.a = 1.0f;
|
||||
color_target_info.load_op = SDL_GPU_LOADOP_CLEAR;
|
||||
color_target_info.store_op = SDL_GPU_STOREOP_STORE;
|
||||
|
||||
renderPass = SDL_BeginGPURenderPass(cmdbuf, &color_target_info, 1, NULL);
|
||||
SDL_EndGPURenderPass(renderPass);
|
||||
|
||||
SDL_SubmitGPUCommandBuffer(cmdbuf);
|
||||
|
||||
|
@@ -341,20 +341,14 @@ Render(SDL_Window *window, const int windownum)
|
||||
SDL_Log("Failed to acquire command buffer :%s", SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
if (!SDL_AcquireGPUSwapchainTexture(cmd, state->windows[windownum], &swapchainTexture, &drawablew, &drawableh)) {
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(cmd, state->windows[windownum], &swapchainTexture, &drawablew, &drawableh)) {
|
||||
SDL_Log("Failed to acquire swapchain texture: %s", SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
if (swapchainTexture == NULL) {
|
||||
/* No swapchain was acquired, probably too many frames in flight */
|
||||
SDL_SubmitGPUCommandBuffer(cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do some rotation with Euler angles. It is not a fixed axis as
|
||||
* quaterions would be, but the effect is cool.
|
||||
* quaternions would be, but the effect is cool.
|
||||
*/
|
||||
rotate_matrix((float)winstate->angle_x, 1.0f, 0.0f, 0.0f, matrix_modelview);
|
||||
rotate_matrix((float)winstate->angle_y, 0.0f, 1.0f, 0.0f, matrix_rotate);
|
||||
|
Reference in New Issue
Block a user