Files
jak-project/third-party/SDL/test/testgpu_simple_clear.c
Tyler Wilding 1f6438e517 deps: update to SDL3 (#3852)
This PR updates to SDL3, and with it, adds a handful of new features.
Everything seems to work but I'm going to look over the code once last
time before merging, some of the API changes are hard to spot.

Fixes #2773

### Pressure sensitivity support for DS3 Controllers

SDL3 adds pressure sensitivity support for DS3 controllers on windows. I
have not tested on linux. The option is disabled by default.

On windows you will need https://docs.nefarius.at/projects/DsHidMini/
and to be using SXS mode.

### DualSense and Xbox One Trigger Effects

If enabled, Jak 2 will have certain trigger effects.  They are:
   - xbox1:
     - small vibrate when collecting dark eco
     - big vibrate when changing to dark jak
     - vibrate when shooting gun, proportional to gun type
   - ps5:
     - resistance when changing to dark jak
     - different gun shooting effects
       - red (resistance)
       - yellow (weapon trigger)
       - blue (vibrates)
       - purple (less resistance)
> **Gun Shooting effects are only enabled if the new "Swap R1 and R2"
option is enabled**

There are more effects that could be used in `dualsense_effects.cpp`,
but I only exposed the ones I needed to OpenGOAL. If a modder wants to
use some of the others and wires them up end-to-end, please consider
contributing that upstream.

### New ImGUI Menu

Added new imgui options for selecting the active controller, for those
people that struggle to select the initial controller.


![image](https://github.com/user-attachments/assets/48ff2985-d9ef-417a-b1f2-a25c74595935)

### Testing

The highlights of what I tested successfully:
   - display
     - [x] all mode switch permutations
     - [x] launch with all modes saved
- [x] switch monitors / unplug monitor that was active, how does it
handle it
     - [x] load with alternate monitor saved and all modes
     - [x] allowing hidpi doesnt break macos
   - controls
     - [x] keyboard and mouse still work
     - [x] pressure sensitivity on linux
2025-03-02 16:36:22 -05:00

129 lines
4.2 KiB
C
Vendored
Generated

/*
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
/* we don't actually use any shaders in this one, so just give us lots of options for backends. */
#define TESTGPU_SUPPORTED_FORMATS (SDL_GPU_SHADERFORMAT_SPIRV | SDL_GPU_SHADERFORMAT_DXBC | SDL_GPU_SHADERFORMAT_DXIL | SDL_GPU_SHADERFORMAT_METALLIB)
static SDLTest_CommonState *state;
static SDL_GPUDevice *gpu_device;
static Uint64 then = 0;
static Uint64 frames = 0;
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
const SDL_DisplayMode *mode;
int dw, dh;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return SDL_APP_FAILURE;
}
state->skip_renderer = 1;
if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
SDLTest_CommonQuit(state);
return SDL_APP_FAILURE;
}
gpu_device = SDL_CreateGPUDevice(TESTGPU_SUPPORTED_FORMATS, true, NULL);
if (!gpu_device) {
SDL_Log("SDL_CreateGPUDevice failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
if (!SDL_ClaimWindowForGPUDevice(gpu_device, state->windows[0])) {
SDL_Log("SDL_ClaimWindowForGPUDevice failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
if (mode) {
SDL_Log("Screen BPP : %d", SDL_BITSPERPIXEL(mode->format));
}
SDL_GetWindowSize(state->windows[0], &dw, &dh);
SDL_Log("Window Size : %d,%d", dw, dh);
SDL_GetWindowSizeInPixels(state->windows[0], &dw, &dh);
SDL_Log("Draw Size : %d,%d", dw, dh);
SDL_Log("%s", "");
then = SDL_GetTicks();
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
return SDLTest_CommonEventMainCallbacks(state, event);
}
SDL_AppResult SDL_AppIterate(void *appstate)
{
SDL_GPUCommandBuffer *cmdbuf = SDL_AcquireGPUCommandBuffer(gpu_device);
if (cmdbuf == NULL) {
SDL_Log("SDL_AcquireGPUCommandBuffer failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
SDL_GPUTexture *swapchainTexture;
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);
SDL_SubmitGPUCommandBuffer(cmdbuf);
} else {
/* Swapchain is unavailable, cancel work */
SDL_CancelGPUCommandBuffer(cmdbuf);
}
frames++;
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void *appstate, SDL_AppResult result)
{
/* Print out some timing information */
const Uint64 now = SDL_GetTicks();
if (now > then) {
SDL_Log("%2.2f frames per second", ((double)frames * 1000) / (now - then));
}
SDL_ReleaseWindowFromGPUDevice(gpu_device, state->windows[0]);
SDL_DestroyGPUDevice(gpu_device);
SDLTest_CommonQuit(state);
}