diff --git a/libs/wgpu/include/psemek/wgpu/instance.hpp b/libs/wgpu/include/psemek/wgpu/instance.hpp index ba230f06..b5a0bca9 100644 --- a/libs/wgpu/include/psemek/wgpu/instance.hpp +++ b/libs/wgpu/include/psemek/wgpu/instance.hpp @@ -21,7 +21,7 @@ namespace psemek::wgpu static instance create(descriptor const & desc); void process_events(); - surface create_surface(surface::descriptor const & desc) const; + surface create_surface(surface::descriptor const & desc); void request_adapter(adapter::request_options const & request_options, adapter::request_callback callback); static void reference(void * ptr); diff --git a/libs/wgpu/include/psemek/wgpu/surface.hpp b/libs/wgpu/include/psemek/wgpu/surface.hpp index 9915b220..3cd44682 100644 --- a/libs/wgpu/include/psemek/wgpu/surface.hpp +++ b/libs/wgpu/include/psemek/wgpu/surface.hpp @@ -81,15 +81,10 @@ namespace psemek::wgpu }; void configure(configuration const & conf); - capabilities get_capabilities(adapter const & adapter); - current_texture get_current_texture(); - wgpu::texture::format get_preferred_format(adapter const & adapter); - void present(); - void unconfigure(); struct from_android_native_window diff --git a/libs/wgpu/include/psemek/wgpu/texture.hpp b/libs/wgpu/include/psemek/wgpu/texture.hpp index e5d1202e..fc3e7887 100644 --- a/libs/wgpu/include/psemek/wgpu/texture.hpp +++ b/libs/wgpu/include/psemek/wgpu/texture.hpp @@ -1,8 +1,12 @@ #pragma once #include +#include +#include #include +#include +#include namespace psemek::wgpu { @@ -122,6 +126,32 @@ namespace psemek::wgpu render_attachment = 0x00000010, }; + enum class dimension : std::uint32_t + { + _1d = 0x00000000, + _2d = 0x00000001, + _3d = 0x00000002, + }; + + enum class aspect : std::uint32_t + { + all = 0x00000000, + stencil_only = 0x00000001, + depth_only = 0x00000002, + }; + + // TODO: WGPU_EXPORT WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, WGPU_NULLABLE WGPUTextureViewDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; + texture_view create_view(texture_view::descriptor const & desc); + void destroy(); + std::uint32_t get_width(); + std::uint32_t get_height(); + std::uint32_t get_depth(); + dimension get_dimension(); + format get_format(); + std::uint32_t get_mip_level_count(); + usage get_usage(); + void set_label(std::string const & label); + static void reference(void * ptr); static void release(void * ptr); @@ -134,6 +164,19 @@ namespace psemek::wgpu friend struct device; }; + struct texture_view::descriptor + { + std::vector chain = {}; + std::string label = {}; + texture::format format; + texture_view::dimension dimension; + std::uint32_t base_mip_level = 0; + std::uint32_t mip_level_count = 1; + std::uint32_t base_array_layer = 0; + std::uint32_t array_layer_count = 1; + texture::aspect aspect = texture::aspect::all; + }; + inline texture::usage operator | (texture::usage u1, texture::usage u2) { return static_cast(static_cast(u1) | static_cast(u2)); diff --git a/libs/wgpu/include/psemek/wgpu/texture_view.hpp b/libs/wgpu/include/psemek/wgpu/texture_view.hpp new file mode 100644 index 00000000..23ec5886 --- /dev/null +++ b/libs/wgpu/include/psemek/wgpu/texture_view.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include + +#include +#include + +namespace psemek::wgpu +{ + + struct texture_view + : detail::object + { + using detail::object::object; + + enum class dimension : std::uint32_t + { + undefined = 0x00000000, + _1d = 0x00000001, + _2d = 0x00000002, + _2d_array = 0x00000003, + cube = 0x00000004, + cube_array = 0x00000005, + _3d = 0x00000006, + }; + + // Defined in wgpu/texture.hpp to break circular dependencies + struct descriptor; + + void set_label(std::string const & label); + + static void reference(void * ptr); + static void release(void * ptr); + + private: + explicit texture_view(void * ptr) + : detail::object(ptr) + {} + + friend struct texture; + }; + +} diff --git a/libs/wgpu/objects-todo b/libs/wgpu/objects-todo index c51c42db..b13145bd 100644 --- a/libs/wgpu/objects-todo +++ b/libs/wgpu/objects-todo @@ -18,5 +18,5 @@ WGPUSampler WGPUShaderModule + WGPUSurface - WGPUTexture - WGPUTextureView ++ WGPUTexture ++ WGPUTextureView diff --git a/libs/wgpu/source/instance.cpp b/libs/wgpu/source/instance.cpp index 5c3e2b91..163c9594 100644 --- a/libs/wgpu/source/instance.cpp +++ b/libs/wgpu/source/instance.cpp @@ -16,7 +16,7 @@ namespace psemek::wgpu wgpuInstanceProcessEvents((WGPUInstance)get()); } - surface instance::create_surface(surface::descriptor const & desc) const + surface instance::create_surface(surface::descriptor const & desc) { WGPUSurfaceDescriptor descriptor = {}; descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain); diff --git a/libs/wgpu/source/texture.cpp b/libs/wgpu/source/texture.cpp index 84d8504d..ed8b08d1 100644 --- a/libs/wgpu/source/texture.cpp +++ b/libs/wgpu/source/texture.cpp @@ -4,6 +4,67 @@ namespace psemek::wgpu { + texture_view texture::create_view(texture_view::descriptor const & desc) + { + WGPUTextureViewDescriptor descriptor = {}; + descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain); + descriptor.label = desc.label.data(); + descriptor.format = (WGPUTextureFormat)desc.format; + descriptor.dimension = (WGPUTextureViewDimension)desc.dimension; + descriptor.baseMipLevel = desc.base_mip_level; + descriptor.mipLevelCount = desc.mip_level_count; + descriptor.baseArrayLayer = desc.base_array_layer; + descriptor.arrayLayerCount = desc.array_layer_count; + descriptor.aspect = (WGPUTextureAspect)desc.aspect; + + return texture_view(wgpuTextureCreateView((WGPUTexture)get(), &descriptor)); + } + + void texture::destroy() + { + wgpuTextureDestroy((WGPUTexture)get()); + } + + std::uint32_t texture::get_width() + { + return wgpuTextureGetWidth((WGPUTexture)get()); + } + + std::uint32_t texture::get_height() + { + return wgpuTextureGetHeight((WGPUTexture)get()); + } + + std::uint32_t texture::get_depth() + { + return wgpuTextureGetDepthOrArrayLayers((WGPUTexture)get()); + } + + texture::dimension texture::get_dimension() + { + return (dimension)wgpuTextureGetDimension((WGPUTexture)get()); + } + + texture::format texture::get_format() + { + return (format)wgpuTextureGetFormat((WGPUTexture)get()); + } + + std::uint32_t texture::get_mip_level_count() + { + return wgpuTextureGetMipLevelCount((WGPUTexture)get()); + } + + texture::usage texture::get_usage() + { + return (usage)wgpuTextureGetUsage((WGPUTexture)get()); + } + + void texture::set_label(std::string const & label) + { + wgpuTextureSetLabel((WGPUTexture)get(), label.data()); + } + void texture::reference(void * ptr) { wgpuTextureReference((WGPUTexture)ptr); diff --git a/libs/wgpu/source/texture_view.cpp b/libs/wgpu/source/texture_view.cpp new file mode 100644 index 00000000..60ebc094 --- /dev/null +++ b/libs/wgpu/source/texture_view.cpp @@ -0,0 +1,22 @@ +#include +#include + +namespace psemek::wgpu +{ + + void texture_view::set_label(std::string const & label) + { + wgpuTextureViewSetLabel((WGPUTextureView)get(), label.data()); + } + + void texture_view::reference(void * ptr) + { + wgpuTextureViewReference((WGPUTextureView)ptr); + } + + void texture_view::release(void * ptr) + { + wgpuTextureViewRelease((WGPUTextureView)ptr); + } + +}