From 5d97021d0ea00ccf2851452da8ab3cc465519c67 Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Tue, 30 Sep 2025 08:49:27 +0300 Subject: Working on initialization --- include/renderwindow.h | 2 ++ src/renderwindow.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/renderwindow.h b/include/renderwindow.h index 87d89b9..2d3ffbe 100644 --- a/include/renderwindow.h +++ b/include/renderwindow.h @@ -13,6 +13,8 @@ typedef struct { WGPUDevice wgpuDevice; WGPUSurfaceConfiguration configs; WGPUQueue queue; + + WGPUTexture screenTexture; } RenderWindow; RenderWindow InitRenderWindow(int width, int height, const char* title); diff --git a/src/renderwindow.c b/src/renderwindow.c index e9b7a80..769105b 100644 --- a/src/renderwindow.c +++ b/src/renderwindow.c @@ -7,6 +7,10 @@ #include #endif +#if defined(SDL_PLATFORM_WINDOWS) +#include +#endif + RenderWindow InitRenderWindow(int width, int height, const char* title) { RenderWindow renderWindow = {0}; SDL_Init(SDL_INIT_VIDEO); @@ -16,8 +20,32 @@ RenderWindow InitRenderWindow(int width, int height, const char* title) { .requiredFeatureCount = 1, .requiredFeatures = (WGPUInstanceFeatureName[]) { WGPUInstanceFeatureName_TimedWaitAny } }); + SDL_assert(renderWindow.wgpuInstance); SDL_PropertiesID windowProperties = SDL_GetWindowProperties(renderWindow.window); + +#if defined(SDL_PLATFORM_WINDOWS) + HWND hwnd = + (HWND)SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); + HINSTANCE hinstance = + (HINSTANCE)SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER, NULL); + + if (hwnd && hinstance) { + renderWindow.wgpuSurface = + wgpuInstanceCreateSurface(renderWindow.wgpuInstance, &(const WGPUSurfaceDescriptor){ + .nextInChain = (WGPUChainedStruct*)&(const WGPUSurfaceSourceWindowsHWND) { + .chain = (WGPUChainedStruct) { + .next = NULL, + .sType = WGPUSType_SurfaceSourceWindowsHWND + } + }, + + .hwnd = hwnd, + .hinstance = hinstance + }); + } +#endif + #if defined(SDL_PLATFORM_LINUX) if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { Display* xdisplay = @@ -61,6 +89,7 @@ RenderWindow InitRenderWindow(int width, int height, const char* title) { } } #endif + SDL_assert(renderWindow.wgpuSurface); return renderWindow; } -- cgit v1.2.3