Tiny bit of cleanup
This commit is contained in:
parent
144edab071
commit
4f9e31a69d
3 changed files with 17 additions and 9 deletions
|
|
@ -23,7 +23,7 @@ const char shaderCode[] = R"(
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
class window {
|
class Window {
|
||||||
wgpu::Instance instance;
|
wgpu::Instance instance;
|
||||||
wgpu::Adapter adapter;
|
wgpu::Adapter adapter;
|
||||||
wgpu::Device device;
|
wgpu::Device device;
|
||||||
|
|
@ -41,7 +41,7 @@ class window {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//TODO: make init the constructor
|
//TODO: make init the constructor
|
||||||
window();
|
Window();
|
||||||
void Start();
|
void Start();
|
||||||
};
|
};
|
||||||
} // namespace wne
|
} // namespace wne
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "wne/window.hpp"
|
#include "wne/window.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
wne::window window = wne::window{};
|
wne::Window window = wne::Window{};
|
||||||
window.Start();
|
window.Start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
#include "wne/window.hpp"
|
#include "wne/window.hpp"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_error.h>
|
||||||
#include <SDL3/SDL_events.h>
|
#include <SDL3/SDL_events.h>
|
||||||
#include <SDL3/SDL_init.h>
|
#include <SDL3/SDL_init.h>
|
||||||
|
#include <SDL3/SDL_log.h>
|
||||||
#include <SDL3/SDL_video.h>
|
#include <SDL3/SDL_video.h>
|
||||||
#include <sdl3webgpu.h>
|
#include <sdl3webgpu.h>
|
||||||
|
|
||||||
namespace wne {
|
namespace wne {
|
||||||
|
|
||||||
void window::ConfigureSurface() {
|
void Window::ConfigureSurface() {
|
||||||
wgpu::SurfaceCapabilities capabilities;
|
wgpu::SurfaceCapabilities capabilities;
|
||||||
surface.GetCapabilities(adapter, &capabilities);
|
surface.GetCapabilities(adapter, &capabilities);
|
||||||
format = capabilities.formats[0];
|
format = capabilities.formats[0];
|
||||||
|
|
@ -17,7 +19,7 @@ void window::ConfigureSurface() {
|
||||||
surface.Configure(&config);
|
surface.Configure(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window::CreateRenderPipeline() {
|
void Window::CreateRenderPipeline() {
|
||||||
wgpu::ShaderSourceWGSL wgsl{{.code = shaderCode}};
|
wgpu::ShaderSourceWGSL wgsl{{.code = shaderCode}};
|
||||||
|
|
||||||
wgpu::ShaderModuleDescriptor shaderModuleDescriptor{.nextInChain = &wgsl};
|
wgpu::ShaderModuleDescriptor shaderModuleDescriptor{.nextInChain = &wgsl};
|
||||||
|
|
@ -33,7 +35,8 @@ void window::CreateRenderPipeline() {
|
||||||
.fragment = &fragmentState};
|
.fragment = &fragmentState};
|
||||||
pipeline = device.CreateRenderPipeline(&descriptor);
|
pipeline = device.CreateRenderPipeline(&descriptor);
|
||||||
}
|
}
|
||||||
void window::Render() {
|
|
||||||
|
void Window::Render() {
|
||||||
wgpu::SurfaceTexture surfaceTexture;
|
wgpu::SurfaceTexture surfaceTexture;
|
||||||
surface.GetCurrentTexture(&surfaceTexture);
|
surface.GetCurrentTexture(&surfaceTexture);
|
||||||
|
|
||||||
|
|
@ -53,12 +56,13 @@ void window::Render() {
|
||||||
wgpu::CommandBuffer commands = encoder.Finish();
|
wgpu::CommandBuffer commands = encoder.Finish();
|
||||||
device.GetQueue().Submit(1, &commands);
|
device.GetQueue().Submit(1, &commands);
|
||||||
}
|
}
|
||||||
void window::InitGraphics() {
|
|
||||||
|
void Window::InitGraphics() {
|
||||||
ConfigureSurface();
|
ConfigureSurface();
|
||||||
CreateRenderPipeline();
|
CreateRenderPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
window::window() {
|
Window::Window() {
|
||||||
static const auto kTimedWaitAny = wgpu::InstanceFeatureName::TimedWaitAny;
|
static const auto kTimedWaitAny = wgpu::InstanceFeatureName::TimedWaitAny;
|
||||||
wgpu::InstanceDescriptor instanceDesc{.requiredFeatureCount = 1,
|
wgpu::InstanceDescriptor instanceDesc{.requiredFeatureCount = 1,
|
||||||
.requiredFeatures = &kTimedWaitAny};
|
.requiredFeatures = &kTimedWaitAny};
|
||||||
|
|
@ -95,8 +99,11 @@ window::window() {
|
||||||
});
|
});
|
||||||
instance.WaitAny(f2, UINT64_MAX);
|
instance.WaitAny(f2, UINT64_MAX);
|
||||||
}
|
}
|
||||||
void window::Start() {
|
|
||||||
|
void Window::Start() {
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Could not initialise SDL: %s",
|
||||||
|
SDL_GetError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,4 +141,5 @@ void window::Start() {
|
||||||
#endif
|
#endif
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace wne
|
} // namespace wne
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue