2022-07-27 11:25:25 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <aurora/aurora.h>
|
2026-04-01 00:49:28 -06:00
|
|
|
#include <aurora/math.hpp>
|
2022-07-27 11:25:25 -04:00
|
|
|
|
|
|
|
|
#include "wgpu.hpp"
|
|
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
struct SDL_Window;
|
|
|
|
|
|
|
|
|
|
namespace aurora::webgpu {
|
|
|
|
|
struct GraphicsConfig {
|
2025-04-03 00:12:22 -06:00
|
|
|
wgpu::SurfaceConfiguration surfaceConfiguration;
|
2022-08-02 16:37:56 -04:00
|
|
|
wgpu::TextureFormat depthFormat;
|
2022-07-27 11:25:25 -04:00
|
|
|
uint32_t msaaSamples;
|
|
|
|
|
uint16_t textureAnisotropy;
|
|
|
|
|
};
|
|
|
|
|
struct TextureWithSampler {
|
|
|
|
|
wgpu::Texture texture;
|
|
|
|
|
wgpu::TextureView view;
|
2022-08-02 16:37:56 -04:00
|
|
|
wgpu::Extent3D size;
|
|
|
|
|
wgpu::TextureFormat format;
|
2022-07-27 11:25:25 -04:00
|
|
|
wgpu::Sampler sampler;
|
|
|
|
|
};
|
2026-05-05 23:13:31 -06:00
|
|
|
struct Viewport {
|
|
|
|
|
float left;
|
|
|
|
|
float top;
|
|
|
|
|
float width;
|
|
|
|
|
float height;
|
|
|
|
|
float znear;
|
|
|
|
|
float zfar;
|
|
|
|
|
|
|
|
|
|
bool operator==(const Viewport& rhs) const {
|
|
|
|
|
return left == rhs.left && top == rhs.top && width == rhs.width && height == rhs.height && znear == rhs.znear &&
|
|
|
|
|
zfar == rhs.zfar;
|
|
|
|
|
}
|
|
|
|
|
bool operator!=(const Viewport& rhs) const { return !(*this == rhs); }
|
|
|
|
|
};
|
2022-07-27 11:25:25 -04:00
|
|
|
|
2022-08-02 16:37:56 -04:00
|
|
|
extern wgpu::Device g_device;
|
|
|
|
|
extern wgpu::Queue g_queue;
|
2025-04-03 00:12:22 -06:00
|
|
|
extern wgpu::Surface g_surface;
|
2022-08-02 16:37:56 -04:00
|
|
|
extern wgpu::BackendType g_backendType;
|
2022-07-27 11:25:25 -04:00
|
|
|
extern GraphicsConfig g_graphicsConfig;
|
|
|
|
|
extern TextureWithSampler g_frameBuffer;
|
|
|
|
|
extern TextureWithSampler g_frameBufferResolved;
|
|
|
|
|
extern TextureWithSampler g_depthBuffer;
|
2022-08-02 16:37:56 -04:00
|
|
|
extern wgpu::RenderPipeline g_CopyPipeline;
|
|
|
|
|
extern wgpu::BindGroup g_CopyBindGroup;
|
|
|
|
|
extern wgpu::Instance g_instance;
|
2026-05-14 23:40:45 +02:00
|
|
|
extern bool g_bcTexturesSupported;
|
2026-06-06 07:40:41 -06:00
|
|
|
extern bool g_astcTexturesSupported;
|
2026-05-30 09:57:21 -06:00
|
|
|
extern bool g_textureComponentSwizzleSupported;
|
2022-07-27 11:25:25 -04:00
|
|
|
|
2026-06-12 10:28:52 -06:00
|
|
|
const wgpu::AdapterInfo& adapter_info();
|
|
|
|
|
|
2026-05-24 12:55:38 -06:00
|
|
|
bool initialize(AuroraBackend backend, bool allowCpu);
|
2022-07-27 11:25:25 -04:00
|
|
|
void shutdown();
|
2026-05-08 16:55:12 -06:00
|
|
|
void release_surface() noexcept;
|
2026-02-19 23:53:38 -07:00
|
|
|
bool refresh_surface(bool recreate = true);
|
2026-05-05 23:13:31 -06:00
|
|
|
void resize_swapchain(uint32_t width, uint32_t height, uint32_t native_width, uint32_t native_height,
|
|
|
|
|
bool force = false);
|
2026-04-07 05:05:55 +02:00
|
|
|
TextureWithSampler create_render_texture(uint32_t width, uint32_t height, bool multisampled);
|
2026-05-05 23:13:31 -06:00
|
|
|
const TextureWithSampler& present_source() noexcept;
|
|
|
|
|
wgpu::BindGroup create_copy_bind_group(const TextureWithSampler& source);
|
2026-05-17 20:57:23 -04:00
|
|
|
void set_resampler(AuroraSampler sampler) noexcept;
|
|
|
|
|
AuroraSampler get_resampler() noexcept;
|
2026-05-05 23:13:31 -06:00
|
|
|
Viewport calculate_present_viewport(uint32_t surface_width, uint32_t surface_height, uint32_t content_width,
|
|
|
|
|
uint32_t content_height) noexcept;
|
2026-05-17 20:57:23 -04:00
|
|
|
const TextureWithSampler& resample_present_source(const wgpu::CommandEncoder& encoder, const Viewport& viewport);
|
2026-04-01 00:49:28 -06:00
|
|
|
void draw_clear(const wgpu::RenderPassEncoder& pass, bool clearColor, bool clearAlpha, bool clearDepth,
|
|
|
|
|
const Vec4<float>& clearColorValue, float clearDepthValue);
|
2026-04-08 21:46:51 +02:00
|
|
|
|
2026-05-05 23:13:31 -06:00
|
|
|
size_t load_from_cache(void const* key, size_t keySize, void* value, size_t valueSize, void* userdata);
|
|
|
|
|
void store_to_cache(void const* key, size_t keySize, void const* value, size_t valueSize, void* userdata);
|
2026-06-09 00:19:03 -06:00
|
|
|
void cache_prune();
|
2026-04-08 21:46:51 +02:00
|
|
|
void cache_shutdown();
|
|
|
|
|
|
2022-07-27 11:25:25 -04:00
|
|
|
} // namespace aurora::webgpu
|