Got a simple sdl3 window.
This commit is contained in:
parent
5e05d36370
commit
05f71170dc
2 changed files with 30 additions and 88 deletions
14
meson.build
14
meson.build
|
|
@ -6,20 +6,6 @@ sdl3_deps = [dependency('sdl3'), dependency('sdl3_image')]
|
|||
cglm_dep = dependency('cglm')
|
||||
wgpu_native_dep = dependency('wgpu-native')
|
||||
|
||||
pkg = import('pkgconfig')
|
||||
#wgpu_native_dep = dependency('wgpu-native', fallback: ['wgpu-native','webgpunative_dep'])
|
||||
|
||||
|
||||
#cmake = import('cmake')
|
||||
#dawn_cmakeopts = cmake.subproject_options()
|
||||
#dawn_cmakeopts.add_cmake_defines({'DAWN_FETCH_DEPENDENCIES': 'ON'})
|
||||
#dawn_cmakeopts.add_cmake_defines({'DAWN_ENABLE_INSTALL': 'ON'})
|
||||
#dawn_cmakeopts.add_cmake_defines({'CMAKE_BUILD_TYPE': 'Release'})
|
||||
|
||||
#dawn = cmake.subproject('dawn', options: dawn_cmakeopts)
|
||||
##message('CMake targets:\n - ' + '\n - '.join(dawn.target_list()))
|
||||
#webgpu_dawn_dep = dawn.dependency('webgpu_dawn')
|
||||
|
||||
executable('webgpu', 'src/main.c',
|
||||
win_subsystem: 'windows',
|
||||
dependencies: [sdl3_deps, cglm_dep, wgpu_native_dep, vulkan_dep]
|
||||
|
|
|
|||
104
src/main.c
104
src/main.c
|
|
@ -1,84 +1,40 @@
|
|||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <SDL3/SDL_vulkan.h>
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <webgpu/webgpu.h>
|
||||
#include "SDL3/SDL_init.h"
|
||||
#include "SDL3/SDL_log.h"
|
||||
#include "SDL3/SDL_render.h"
|
||||
#include "SDL3/SDL_video.h"
|
||||
|
||||
static void OnRequestAdapter(WGPURequestAdapterStatus status,
|
||||
WGPUAdapter adapter, WGPUStringView message,
|
||||
void *userdata1, void *userdata2) {
|
||||
// TODO handle messages and errors better
|
||||
if (status != WGPURequestAdapterStatus_Success) {
|
||||
printf("%s", message.data);
|
||||
}
|
||||
assert(status == WGPURequestAdapterStatus_Success);
|
||||
int main(int argc, char *argv[]) {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Event event;
|
||||
|
||||
WGPUAdapter *result = userdata1;
|
||||
if (*result == NULL) {
|
||||
*result = adapter;
|
||||
}
|
||||
}
|
||||
|
||||
void requestAdapterSync(WGPUInstance instance,
|
||||
WGPURequestAdapterOptions const *options,
|
||||
WGPUAdapter *adapter) {
|
||||
|
||||
WGPURequestAdapterCallbackInfo info = {.mode = WGPUCallbackMode_WaitAnyOnly,
|
||||
.callback = &OnRequestAdapter,
|
||||
.userdata1 = adapter};
|
||||
WGPUFuture future = wgpuInstanceRequestAdapter(instance, options, info);
|
||||
WGPUFutureWaitInfo wait = {
|
||||
.future = future,
|
||||
};
|
||||
WGPUWaitStatus status = wgpuInstanceWaitAny(instance, 1, &wait, 0);
|
||||
assert(status == WGPUWaitStatus_Success);
|
||||
assert(adapter);
|
||||
}
|
||||
|
||||
int main() {
|
||||
SDL_Window *window = NULL;
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
fprintf(stderr, "SDL failed to initialise: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
window = SDL_CreateWindow("SDL3 Example", 800, 600, SDL_WINDOW_VULKAN);
|
||||
if (window == NULL) {
|
||||
fprintf(stderr, "SDL window failed to initialise: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s",
|
||||
SDL_GetError());
|
||||
return 3;
|
||||
}
|
||||
|
||||
const char *driver = SDL_GetCurrentVideoDriver();
|
||||
printf("Driver: %s\n", driver);
|
||||
|
||||
// We create a descriptor
|
||||
WGPUInstanceDescriptor desc = {};
|
||||
desc.nextInChain = NULL;
|
||||
|
||||
// We create the instance using this descriptor
|
||||
WGPUInstance instance = wgpuCreateInstance(&desc);
|
||||
//
|
||||
// We can check whether there is actually an instance created
|
||||
if (!instance) {
|
||||
printf("Could not initialize WebGPU!\n");
|
||||
return 1;
|
||||
if (!SDL_CreateWindowAndRenderer("Hello SDL3", 320, 240, SDL_WINDOW_RESIZABLE,
|
||||
&window, &renderer)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Couldn't create window and renderer: %s", SDL_GetError());
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Display the object (WGPUInstance is a simple pointer, it may be
|
||||
// copied around without worrying about its size).
|
||||
printf("WGPU instance: %p\n", instance);
|
||||
while (1) {
|
||||
SDL_PollEvent(&event);
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
break;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
printf("Requesting Adapter.\n");
|
||||
WGPUAdapter adapter = NULL;
|
||||
WGPURequestAdapterOptions adapterOpts = {0};
|
||||
requestAdapterSync(instance, &adapterOpts, &adapter);
|
||||
printf("Got Adapter: %p\n", &adapter);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
// Cleanup
|
||||
wgpuAdapterRelease(adapter);
|
||||
wgpuInstanceRelease(instance);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue