#include #include #include #include #include #include #include // Include shader group and individual shader headers #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { namespace webgpu { // Forward declare and define the Impl class class RendererBackend::Impl { public: void* instance = nullptr; WGPUDevice device = nullptr; WGPUQueue queue = nullptr; void* surface = nullptr; wgpu::TextureFormat depthStencilFormat = wgpu::TextureFormat::Undefined; wgpu::TextureFormat colorFormat = wgpu::TextureFormat::Undefined; }; RendererBackend::RendererBackend(const gfx::ContextMode contextMode_) : gfx::RendererBackend(contextMode_), impl(std::make_unique()) {} RendererBackend::~RendererBackend() { context.reset(); } void RendererBackend::activate() { // Activation logic if needed } void RendererBackend::deactivate() { // Deactivation logic if needed } std::unique_ptr RendererBackend::createContext() { auto ctx = std::make_unique(*this); return ctx; } // getDefaultRenderable() is pure virtual and must be implemented by platform-specific backends // The platform backend (e.g., GLFWWebGPUBackend) typically inherits from gfx::Renderable itself // and returns *this from getDefaultRenderable() namespace { template void registerTypes(gfx::ShaderRegistry& registry, const ProgramParameters& programParameters) { using namespace std::string_literals; // Register each shader type using fold expression ( [&]() { using ShaderClass = shaders::ShaderSource; auto group = std::make_shared>(programParameters); if (!registry.registerShaderGroup(std::move(group), ShaderClass::name)) { assert(!"duplicate shader group"); throw std::runtime_error("Failed to register "s + ShaderClass::name + " with shader registry!"); } }(), ...); } } // namespace void RendererBackend::initShaders(gfx::ShaderRegistry& registry, const ProgramParameters& parameters) { // Register all shader types - even if headers don't exist yet, fallback implementation will be used // As WebGPU shader headers are created, they will automatically be picked up registerTypes(registry, parameters); } void RendererBackend::setSurface(void* nativeWindow) { // Platform-specific surface creation will be handled by subclasses // For now, just store the native window handle // The actual surface creation depends on the platform (X11, Wayland, etc.) (void)nativeWindow; } void RendererBackend::setInstance(void* instance) { impl->instance = instance; } void RendererBackend::setDevice(WGPUDevice device) { impl->device = device; } void RendererBackend::setQueue(WGPUQueue queue) { impl->queue = queue; } void* RendererBackend::getInstance() const { return impl->instance; } WGPUDevice RendererBackend::getDevice() const { return impl->device; } WGPUQueue RendererBackend::getQueue() const { return impl->queue; } void* RendererBackend::getSurface() const { return impl->surface; } void* RendererBackend::getCurrentTextureView() { // Default implementation - platform backends can override if needed return nullptr; } void* RendererBackend::getDepthStencilView() { // Default implementation - platform backends can override if needed return nullptr; } mbgl::Size RendererBackend::getFramebufferSize() const { // Default implementation - platform backends should override return {0, 0}; } void RendererBackend::setDepthStencilFormat(wgpu::TextureFormat format) { impl->depthStencilFormat = format; } wgpu::TextureFormat RendererBackend::getDepthStencilFormat() const { return impl->depthStencilFormat; } void RendererBackend::setColorFormat(wgpu::TextureFormat format) { impl->colorFormat = format; } wgpu::TextureFormat RendererBackend::getColorFormat() const { return impl->colorFormat; } } // namespace webgpu } // namespace mbgl