Tiny bit of cleanup

This commit is contained in:
Warwick New 2026-07-31 13:31:57 +01:00
parent 144edab071
commit 4f9e31a69d
3 changed files with 17 additions and 9 deletions

View file

@ -23,7 +23,7 @@ const char shaderCode[] = R"(
}
)";
class window {
class Window {
wgpu::Instance instance;
wgpu::Adapter adapter;
wgpu::Device device;
@ -41,7 +41,7 @@ class window {
public:
//TODO: make init the constructor
window();
Window();
void Start();
};
} // namespace wne

View file

@ -1,6 +1,6 @@
#include "wne/window.hpp"
int main() {
wne::window window = wne::window{};
wne::Window window = wne::Window{};
window.Start();
}

View file

@ -1,13 +1,15 @@
#include "wne/window.hpp"
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_video.h>
#include <sdl3webgpu.h>
namespace wne {
void window::ConfigureSurface() {
void Window::ConfigureSurface() {
wgpu::SurfaceCapabilities capabilities;
surface.GetCapabilities(adapter, &capabilities);
format = capabilities.formats[0];
@ -17,7 +19,7 @@ void window::ConfigureSurface() {
surface.Configure(&config);
}
void window::CreateRenderPipeline() {
void Window::CreateRenderPipeline() {
wgpu::ShaderSourceWGSL wgsl{{.code = shaderCode}};
wgpu::ShaderModuleDescriptor shaderModuleDescriptor{.nextInChain = &wgsl};
@ -33,7 +35,8 @@ void window::CreateRenderPipeline() {
.fragment = &fragmentState};
pipeline = device.CreateRenderPipeline(&descriptor);
}
void window::Render() {
void Window::Render() {
wgpu::SurfaceTexture surfaceTexture;
surface.GetCurrentTexture(&surfaceTexture);
@ -53,12 +56,13 @@ void window::Render() {
wgpu::CommandBuffer commands = encoder.Finish();
device.GetQueue().Submit(1, &commands);
}
void window::InitGraphics() {
void Window::InitGraphics() {
ConfigureSurface();
CreateRenderPipeline();
}
window::window() {
Window::Window() {
static const auto kTimedWaitAny = wgpu::InstanceFeatureName::TimedWaitAny;
wgpu::InstanceDescriptor instanceDesc{.requiredFeatureCount = 1,
.requiredFeatures = &kTimedWaitAny};
@ -95,8 +99,11 @@ window::window() {
});
instance.WaitAny(f2, UINT64_MAX);
}
void window::Start() {
void Window::Start() {
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Could not initialise SDL: %s",
SDL_GetError());
return;
}
@ -134,4 +141,5 @@ void window::Start() {
#endif
SDL_Quit();
}
} // namespace wne