From d7703c822c7b2373615a972f02667287635c667b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 29 Oct 2020 16:32:32 +0100 Subject: Simplify header names --- bindings/cxx/include/pugl/cairo.hpp | 50 +++++++++ bindings/cxx/include/pugl/gl.hpp | 60 +++++++++++ bindings/cxx/include/pugl/pugl_cairo.hpp | 50 --------- bindings/cxx/include/pugl/pugl_gl.hpp | 60 ----------- bindings/cxx/include/pugl/pugl_stub.hpp | 50 --------- bindings/cxx/include/pugl/pugl_vulkan.hpp | 170 ------------------------------ bindings/cxx/include/pugl/stub.hpp | 50 +++++++++ bindings/cxx/include/pugl/vulkan.hpp | 170 ++++++++++++++++++++++++++++++ examples/cube_view.h | 2 +- examples/pugl_cairo_demo.c | 2 +- examples/pugl_cursor_demo.c | 2 +- examples/pugl_cxx_demo.cpp | 2 +- examples/pugl_embed_demo.c | 2 +- examples/pugl_print_events.c | 2 +- examples/pugl_shader_demo.c | 2 +- examples/pugl_vulkan_cxx_demo.cpp | 2 +- examples/pugl_vulkan_demo.c | 2 +- examples/pugl_window_demo.c | 2 +- include/pugl/cairo.h | 50 +++++++++ include/pugl/gl.h | 90 ++++++++++++++++ include/pugl/pugl.h | 4 +- include/pugl/pugl_cairo.h | 50 --------- include/pugl/pugl_gl.h | 90 ---------------- include/pugl/pugl_stub.h | 52 --------- include/pugl/pugl_vulkan.h | 148 -------------------------- include/pugl/stub.h | 52 +++++++++ include/pugl/vulkan.h | 148 ++++++++++++++++++++++++++ src/mac_gl.m | 2 +- src/mac_stub.m | 2 +- src/mac_vulkan.m | 4 +- src/win.c | 2 +- src/win_gl.c | 2 +- src/win_stub.c | 2 +- src/win_vulkan.c | 4 +- src/x11_cairo.c | 2 +- src/x11_gl.c | 2 +- src/x11_stub.c | 2 +- src/x11_vulkan.c | 2 +- test/test_build.c | 8 +- test/test_build.cpp | 12 +-- test/test_gl_hints.c | 2 +- test/test_realize.c | 2 +- test/test_redisplay.c | 2 +- test/test_show_hide.c | 2 +- test/test_stub_hints.c | 2 +- test/test_timer.c | 2 +- test/test_update.c | 2 +- 47 files changed, 712 insertions(+), 712 deletions(-) create mode 100644 bindings/cxx/include/pugl/cairo.hpp create mode 100644 bindings/cxx/include/pugl/gl.hpp delete mode 100644 bindings/cxx/include/pugl/pugl_cairo.hpp delete mode 100644 bindings/cxx/include/pugl/pugl_gl.hpp delete mode 100644 bindings/cxx/include/pugl/pugl_stub.hpp delete mode 100644 bindings/cxx/include/pugl/pugl_vulkan.hpp create mode 100644 bindings/cxx/include/pugl/stub.hpp create mode 100644 bindings/cxx/include/pugl/vulkan.hpp create mode 100644 include/pugl/cairo.h create mode 100644 include/pugl/gl.h delete mode 100644 include/pugl/pugl_cairo.h delete mode 100644 include/pugl/pugl_gl.h delete mode 100644 include/pugl/pugl_stub.h delete mode 100644 include/pugl/pugl_vulkan.h create mode 100644 include/pugl/stub.h create mode 100644 include/pugl/vulkan.h diff --git a/bindings/cxx/include/pugl/cairo.hpp b/bindings/cxx/include/pugl/cairo.hpp new file mode 100644 index 0000000..4df2702 --- /dev/null +++ b/bindings/cxx/include/pugl/cairo.hpp @@ -0,0 +1,50 @@ +/* + Copyright 2012-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file cairo.hpp + @brief Declaration of Cairo backend accessor for C++. +*/ + +#ifndef PUGL_CAIRO_HPP +#define PUGL_CAIRO_HPP + +#include "pugl/cairo.h" +#include "pugl/pugl.h" + +namespace pugl { + +/** + @defgroup cairoxx Cairo + Cairo graphics support. + @ingroup pugl_cxx + @{ +*/ + +/// @copydoc puglCairoBackend +static inline const PuglBackend* +cairoBackend() noexcept +{ + return puglCairoBackend(); +} + +/** + @} +*/ + +} // namespace pugl + +#endif // PUGL_CAIRO_HPP diff --git a/bindings/cxx/include/pugl/gl.hpp b/bindings/cxx/include/pugl/gl.hpp new file mode 100644 index 0000000..2777cbf --- /dev/null +++ b/bindings/cxx/include/pugl/gl.hpp @@ -0,0 +1,60 @@ +/* + Copyright 2012-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file gl.hpp + @brief OpenGL-specific C++ API. +*/ + +#ifndef PUGL_GL_HPP +#define PUGL_GL_HPP + +#include "pugl/gl.h" +#include "pugl/pugl.h" + +namespace pugl { + +/** + @defgroup glxx OpenGL + OpenGL graphics support. + @ingroup pugl_cxx + @{ +*/ + +/// @copydoc PuglGlFunc +using GlFunc = PuglGlFunc; + +/// @copydoc puglGetProcAddress +static inline GlFunc +getProcAddress(const char* name) noexcept +{ + return puglGetProcAddress(name); +} + +/// @copydoc puglGlBackend +static inline const PuglBackend* +glBackend() noexcept +{ + return puglGlBackend(); +} + +/** + @} +*/ + +} // namespace pugl + +#endif // PUGL_GL_HPP diff --git a/bindings/cxx/include/pugl/pugl_cairo.hpp b/bindings/cxx/include/pugl/pugl_cairo.hpp deleted file mode 100644 index 213c977..0000000 --- a/bindings/cxx/include/pugl/pugl_cairo.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright 2012-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_cairo.hpp - @brief Declaration of Cairo backend accessor for C++. -*/ - -#ifndef PUGL_PUGL_CAIRO_HPP -#define PUGL_PUGL_CAIRO_HPP - -#include "pugl/pugl.h" -#include "pugl/pugl_cairo.h" - -namespace pugl { - -/** - @defgroup cairoxx Cairo - Cairo graphics support. - @ingroup pugl_cxx - @{ -*/ - -/// @copydoc puglCairoBackend -static inline const PuglBackend* -cairoBackend() noexcept -{ - return puglCairoBackend(); -} - -/** - @} -*/ - -} // namespace pugl - -#endif // PUGL_PUGL_CAIRO_HPP diff --git a/bindings/cxx/include/pugl/pugl_gl.hpp b/bindings/cxx/include/pugl/pugl_gl.hpp deleted file mode 100644 index b7c581e..0000000 --- a/bindings/cxx/include/pugl/pugl_gl.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright 2012-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_gl.hpp - @brief OpenGL-specific C++ API. -*/ - -#ifndef PUGL_PUGL_GL_HPP -#define PUGL_PUGL_GL_HPP - -#include "pugl/pugl.h" -#include "pugl/pugl_gl.h" - -namespace pugl { - -/** - @defgroup glxx OpenGL - OpenGL graphics support. - @ingroup pugl_cxx - @{ -*/ - -/// @copydoc PuglGlFunc -using GlFunc = PuglGlFunc; - -/// @copydoc puglGetProcAddress -static inline GlFunc -getProcAddress(const char* name) noexcept -{ - return puglGetProcAddress(name); -} - -/// @copydoc puglGlBackend -static inline const PuglBackend* -glBackend() noexcept -{ - return puglGlBackend(); -} - -/** - @} -*/ - -} // namespace pugl - -#endif // PUGL_PUGL_GL_HPP diff --git a/bindings/cxx/include/pugl/pugl_stub.hpp b/bindings/cxx/include/pugl/pugl_stub.hpp deleted file mode 100644 index 362682b..0000000 --- a/bindings/cxx/include/pugl/pugl_stub.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright 2012-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_stub.hpp - @brief Declaration of Stub backend accessor for C++. -*/ - -#ifndef PUGL_PUGL_STUB_HPP -#define PUGL_PUGL_STUB_HPP - -#include "pugl/pugl.h" -#include "pugl/pugl_stub.h" - -namespace pugl { - -/** - @defgroup stubxx Stub - Stub graphics support. - @ingroup pugl_cxx - @{ -*/ - -/// @copydoc puglStubBackend -static inline const PuglBackend* -stubBackend() noexcept -{ - return puglStubBackend(); -} - -/** - @} -*/ - -} // namespace pugl - -#endif // PUGL_PUGL_STUB_HPP diff --git a/bindings/cxx/include/pugl/pugl_vulkan.hpp b/bindings/cxx/include/pugl/pugl_vulkan.hpp deleted file mode 100644 index 9241aba..0000000 --- a/bindings/cxx/include/pugl/pugl_vulkan.hpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - Copyright 2012-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_vulkan.hpp Vulkan-specific C++ API. - - Note that this header includes Vulkan headers, so if you are writing a - program or plugin that dynamically loads vulkan, you should first define - `VK_NO_PROTOTYPES` before including it. -*/ - -#ifndef PUGL_PUGL_VULKAN_HPP -#define PUGL_PUGL_VULKAN_HPP - -#include "pugl/pugl.h" -#include "pugl/pugl.hpp" -#include "pugl/pugl_vulkan.h" - -#include - -#include - -namespace pugl { - -/** - @defgroup vulkanxx Vulkan - Vulkan graphics support. - - Note that the Pugl C++ wrapper does not use vulkan.hpp because it is a - heavyweight dependency which not everyone uses, and its design is not very - friendly to dynamic loading in plugins anyway. However, if you do use - vulkan.hpp smart handles, it is relatively straightforward to wrap the - result of createSurface() manually. - - @ingroup pugl_cxx - @{ -*/ - -/// @copydoc PuglVulkanLoader -class PUGL_API VulkanLoader final - : public detail::Wrapper -{ -public: - /** - Create a new dynamic loader for Vulkan functions. - - This dynamically loads the Vulkan library and gets the load functions - from it. - - Note that this constructor does not throw exceptions, though failure is - possible. To check if the Vulkan library failed to load, test this - loader, which is explicitly convertible to `bool`. It is safe to use a - failed loader, but the accessors will always return null. - */ - explicit VulkanLoader(World& world) noexcept - : Wrapper{puglNewVulkanLoader(world.cobj())} - {} - - /** - Return the `vkGetInstanceProcAddr` function. - - @return Null if the Vulkan library failed to load, or does not contain - this function (which is unlikely and indicates a broken system). - */ - PFN_vkGetInstanceProcAddr getInstanceProcAddrFunc() const noexcept - { - return cobj() ? puglGetInstanceProcAddrFunc(cobj()) : nullptr; - } - - /** - Return the `vkGetDeviceProcAddr` function. - - @return Null if the Vulkan library failed to load, or does not contain - this function (which is unlikely and indicates a broken system). - */ - PFN_vkGetDeviceProcAddr getDeviceProcAddrFunc() const noexcept - { - return cobj() ? puglGetDeviceProcAddrFunc(cobj()) : nullptr; - } - - /// Return true if this loader is valid to use - explicit operator bool() const noexcept { return cobj(); } -}; - -/** - A simple wrapper for an array of static C strings. - - This provides a minimal API that supports iteration, like `std::vector`, but - avoids allocation, exceptions, and a dependency on the C++ standard library. -*/ -class PUGL_API StaticStringArray final -{ -public: - using value_type = const char*; - using const_iterator = const char* const*; - using size_type = uint32_t; - - StaticStringArray(const char* const* strings, const uint32_t size) noexcept - : _strings{strings} - , _size{size} - {} - - const char* const* begin() const noexcept { return _strings; } - const char* const* end() const noexcept { return _strings + _size; } - const char* const* data() const noexcept { return _strings; } - uint32_t size() const noexcept { return _size; } - -private: - const char* const* _strings; - uint32_t _size; -}; - -/** - Return the Vulkan instance extensions required to draw to a PuglView. - - If successful, the returned array always contains "VK_KHR_surface", along - with whatever other platform-specific extensions are required. - - @return An array of extension name strings. -*/ -inline StaticStringArray -getInstanceExtensions() noexcept -{ - uint32_t count = 0; - const char* const* const extensions = puglGetInstanceExtensions(&count); - - return StaticStringArray{extensions, count}; -} - -/// @copydoc puglCreateSurface -inline VkResult -createSurface(const VulkanLoader& loader, - View& view, - VkInstance instance, - const VkAllocationCallbacks* const allocator, - VkSurfaceKHR* const surface) noexcept -{ - const VkResult r = puglCreateSurface( - loader.cobj(), view.cobj(), instance, allocator, surface); - - return (!r && !surface) ? VK_ERROR_INITIALIZATION_FAILED : r; -} - -/// @copydoc puglVulkanBackend -static inline const PuglBackend* -vulkanBackend() noexcept -{ - return puglVulkanBackend(); -} - -/** - @} -*/ - -} // namespace pugl - -#endif // PUGL_PUGL_VULKAN_HPP diff --git a/bindings/cxx/include/pugl/stub.hpp b/bindings/cxx/include/pugl/stub.hpp new file mode 100644 index 0000000..74e8ef2 --- /dev/null +++ b/bindings/cxx/include/pugl/stub.hpp @@ -0,0 +1,50 @@ +/* + Copyright 2012-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file stub.hpp + @brief Declaration of Stub backend accessor for C++. +*/ + +#ifndef PUGL_STUB_HPP +#define PUGL_STUB_HPP + +#include "pugl/pugl.h" +#include "pugl/stub.h" + +namespace pugl { + +/** + @defgroup stubxx Stub + Stub graphics support. + @ingroup pugl_cxx + @{ +*/ + +/// @copydoc puglStubBackend +static inline const PuglBackend* +stubBackend() noexcept +{ + return puglStubBackend(); +} + +/** + @} +*/ + +} // namespace pugl + +#endif // PUGL_STUB_HPP diff --git a/bindings/cxx/include/pugl/vulkan.hpp b/bindings/cxx/include/pugl/vulkan.hpp new file mode 100644 index 0000000..a7b16cb --- /dev/null +++ b/bindings/cxx/include/pugl/vulkan.hpp @@ -0,0 +1,170 @@ +/* + Copyright 2012-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file vulkan.hpp Vulkan-specific C++ API. + + Note that this header includes Vulkan headers, so if you are writing a + program or plugin that dynamically loads vulkan, you should first define + `VK_NO_PROTOTYPES` before including it. +*/ + +#ifndef PUGL_VULKAN_HPP +#define PUGL_VULKAN_HPP + +#include "pugl/pugl.h" +#include "pugl/pugl.hpp" +#include "pugl/vulkan.h" + +#include + +#include + +namespace pugl { + +/** + @defgroup vulkanxx Vulkan + Vulkan graphics support. + + Note that the Pugl C++ wrapper does not use vulkan.hpp because it is a + heavyweight dependency which not everyone uses, and its design is not very + friendly to dynamic loading in plugins anyway. However, if you do use + vulkan.hpp smart handles, it is relatively straightforward to wrap the + result of createSurface() manually. + + @ingroup pugl_cxx + @{ +*/ + +/// @copydoc PuglVulkanLoader +class PUGL_API VulkanLoader final + : public detail::Wrapper +{ +public: + /** + Create a new dynamic loader for Vulkan functions. + + This dynamically loads the Vulkan library and gets the load functions + from it. + + Note that this constructor does not throw exceptions, though failure is + possible. To check if the Vulkan library failed to load, test this + loader, which is explicitly convertible to `bool`. It is safe to use a + failed loader, but the accessors will always return null. + */ + explicit VulkanLoader(World& world) noexcept + : Wrapper{puglNewVulkanLoader(world.cobj())} + {} + + /** + Return the `vkGetInstanceProcAddr` function. + + @return Null if the Vulkan library failed to load, or does not contain + this function (which is unlikely and indicates a broken system). + */ + PFN_vkGetInstanceProcAddr getInstanceProcAddrFunc() const noexcept + { + return cobj() ? puglGetInstanceProcAddrFunc(cobj()) : nullptr; + } + + /** + Return the `vkGetDeviceProcAddr` function. + + @return Null if the Vulkan library failed to load, or does not contain + this function (which is unlikely and indicates a broken system). + */ + PFN_vkGetDeviceProcAddr getDeviceProcAddrFunc() const noexcept + { + return cobj() ? puglGetDeviceProcAddrFunc(cobj()) : nullptr; + } + + /// Return true if this loader is valid to use + explicit operator bool() const noexcept { return cobj(); } +}; + +/** + A simple wrapper for an array of static C strings. + + This provides a minimal API that supports iteration, like `std::vector`, but + avoids allocation, exceptions, and a dependency on the C++ standard library. +*/ +class PUGL_API StaticStringArray final +{ +public: + using value_type = const char*; + using const_iterator = const char* const*; + using size_type = uint32_t; + + StaticStringArray(const char* const* strings, const uint32_t size) noexcept + : _strings{strings} + , _size{size} + {} + + const char* const* begin() const noexcept { return _strings; } + const char* const* end() const noexcept { return _strings + _size; } + const char* const* data() const noexcept { return _strings; } + uint32_t size() const noexcept { return _size; } + +private: + const char* const* _strings; + uint32_t _size; +}; + +/** + Return the Vulkan instance extensions required to draw to a PuglView. + + If successful, the returned array always contains "VK_KHR_surface", along + with whatever other platform-specific extensions are required. + + @return An array of extension name strings. +*/ +inline StaticStringArray +getInstanceExtensions() noexcept +{ + uint32_t count = 0; + const char* const* const extensions = puglGetInstanceExtensions(&count); + + return StaticStringArray{extensions, count}; +} + +/// @copydoc puglCreateSurface +inline VkResult +createSurface(const VulkanLoader& loader, + View& view, + VkInstance instance, + const VkAllocationCallbacks* const allocator, + VkSurfaceKHR* const surface) noexcept +{ + const VkResult r = puglCreateSurface( + loader.cobj(), view.cobj(), instance, allocator, surface); + + return (!r && !surface) ? VK_ERROR_INITIALIZATION_FAILED : r; +} + +/// @copydoc puglVulkanBackend +static inline const PuglBackend* +vulkanBackend() noexcept +{ + return puglVulkanBackend(); +} + +/** + @} +*/ + +} // namespace pugl + +#endif // PUGL_VULKAN_HPP diff --git a/examples/cube_view.h b/examples/cube_view.h index ceece42..87bf3b5 100644 --- a/examples/cube_view.h +++ b/examples/cube_view.h @@ -21,7 +21,7 @@ #include "demo_utils.h" -#include "pugl/pugl_gl.h" +#include "pugl/gl.h" // clang-format off diff --git a/examples/pugl_cairo_demo.c b/examples/pugl_cairo_demo.c index 5fe0661..d8a1b08 100644 --- a/examples/pugl_cairo_demo.c +++ b/examples/pugl_cairo_demo.c @@ -22,8 +22,8 @@ #include "demo_utils.h" #include "test/test_utils.h" +#include "pugl/cairo.h" #include "pugl/pugl.h" -#include "pugl/pugl_cairo.h" #include diff --git a/examples/pugl_cursor_demo.c b/examples/pugl_cursor_demo.c index ad9bb8e..de6b6f2 100644 --- a/examples/pugl_cursor_demo.c +++ b/examples/pugl_cursor_demo.c @@ -21,8 +21,8 @@ #include "test/test_utils.h" +#include "pugl/gl.h" #include "pugl/pugl.h" -#include "pugl/pugl_gl.h" #include diff --git a/examples/pugl_cxx_demo.cpp b/examples/pugl_cxx_demo.cpp index 214c03d..ed2d21a 100644 --- a/examples/pugl_cxx_demo.cpp +++ b/examples/pugl_cxx_demo.cpp @@ -23,10 +23,10 @@ #include "demo_utils.h" #include "test/test_utils.h" +#include "pugl/gl.hpp" #include "pugl/pugl.h" #include "pugl/pugl.hpp" #include "pugl/pugl.ipp" // IWYU pragma: keep -#include "pugl/pugl_gl.hpp" #include diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c index b481d4a..db4a141 100644 --- a/examples/pugl_embed_demo.c +++ b/examples/pugl_embed_demo.c @@ -23,8 +23,8 @@ #include "demo_utils.h" #include "test/test_utils.h" +#include "pugl/gl.h" #include "pugl/pugl.h" -#include "pugl/pugl_gl.h" #include #include diff --git a/examples/pugl_print_events.c b/examples/pugl_print_events.c index 95ac440..816086d 100644 --- a/examples/pugl_print_events.c +++ b/examples/pugl_print_events.c @@ -22,7 +22,7 @@ #include "test/test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include #include diff --git a/examples/pugl_shader_demo.c b/examples/pugl_shader_demo.c index 4b8064d..476489d 100644 --- a/examples/pugl_shader_demo.c +++ b/examples/pugl_shader_demo.c @@ -42,8 +42,8 @@ #include "glad/glad.h" +#include "pugl/gl.h" #include "pugl/pugl.h" -#include "pugl/pugl_gl.h" #include #include diff --git a/examples/pugl_vulkan_cxx_demo.cpp b/examples/pugl_vulkan_cxx_demo.cpp index fa40734..12b2626 100644 --- a/examples/pugl_vulkan_cxx_demo.cpp +++ b/examples/pugl_vulkan_cxx_demo.cpp @@ -37,7 +37,7 @@ #include "pugl/pugl.h" #include "pugl/pugl.hpp" #include "pugl/pugl.ipp" // IWYU pragma: keep -#include "pugl/pugl_vulkan.hpp" +#include "pugl/vulkan.hpp" #include #include diff --git a/examples/pugl_vulkan_demo.c b/examples/pugl_vulkan_demo.c index ef4550a..a65731b 100644 --- a/examples/pugl_vulkan_demo.c +++ b/examples/pugl_vulkan_demo.c @@ -24,7 +24,7 @@ #include "test/test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_vulkan.h" +#include "pugl/vulkan.h" #include #include diff --git a/examples/pugl_window_demo.c b/examples/pugl_window_demo.c index f326f21..9b7795c 100644 --- a/examples/pugl_window_demo.c +++ b/examples/pugl_window_demo.c @@ -23,8 +23,8 @@ #include "demo_utils.h" #include "test/test_utils.h" +#include "pugl/gl.h" #include "pugl/pugl.h" -#include "pugl/pugl_gl.h" #include #include diff --git a/include/pugl/cairo.h b/include/pugl/cairo.h new file mode 100644 index 0000000..2022c21 --- /dev/null +++ b/include/pugl/cairo.h @@ -0,0 +1,50 @@ +/* + Copyright 2012-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file cairo.h + @brief Declaration of Cairo backend accessor. +*/ + +#ifndef PUGL_CAIRO_H +#define PUGL_CAIRO_H + +#include "pugl/pugl.h" + +PUGL_BEGIN_DECLS + +/** + @defgroup cairo Cairo + Cairo graphics support. + @ingroup pugl_c + @{ +*/ + +/** + Cairo graphics backend accessor. + + Pass the returned value to puglSetBackend() to draw to a view with Cairo. +*/ +PUGL_API PUGL_CONST_FUNC const PuglBackend* +puglCairoBackend(void); + +/** + @} +*/ + +PUGL_END_DECLS + +#endif // PUGL_CAIRO_H diff --git a/include/pugl/gl.h b/include/pugl/gl.h new file mode 100644 index 0000000..dca9a45 --- /dev/null +++ b/include/pugl/gl.h @@ -0,0 +1,90 @@ +/* + Copyright 2012-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file gl.h + @brief OpenGL-specific API. +*/ + +#ifndef PUGL_GL_H +#define PUGL_GL_H + +#include "pugl/pugl.h" + +// IWYU pragma: begin_exports + +/* Unfortunately, GL includes vary across platforms, so include them here to + enable pure portable programs. */ + +#ifndef PUGL_NO_INCLUDE_GL_H +# ifdef __APPLE__ +# include "OpenGL/gl.h" +# else +# ifdef _WIN32 +# include +# endif +# include "GL/gl.h" +# endif +#endif + +#ifndef PUGL_NO_INCLUDE_GLU_H +# ifdef __APPLE__ +# include "OpenGL/glu.h" +# else +# ifdef _WIN32 +# include +# endif +# include "GL/glu.h" +# endif +#endif + +// IWYU pragma: end_exports + +PUGL_BEGIN_DECLS + +/** + @defgroup gl OpenGL + OpenGL graphics support. + @ingroup pugl_c + @{ +*/ + +/** + OpenGL extension function. +*/ +typedef void (*PuglGlFunc)(void); + +/** + Return the address of an OpenGL extension function. +*/ +PUGL_API PuglGlFunc +puglGetProcAddress(const char* name); + +/** + OpenGL graphics backend. + + Pass the returned value to puglSetBackend() to draw to a view with OpenGL. +*/ +PUGL_API PUGL_CONST_FUNC const PuglBackend* +puglGlBackend(void); + +PUGL_END_DECLS + +/** + @} +*/ + +#endif // PUGL_GL_H diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h index 19f9fa4..814b39b 100644 --- a/include/pugl/pugl.h +++ b/include/pugl/pugl.h @@ -899,8 +899,8 @@ puglGetHandle(PuglView* view); Pugl includes the following backends: - - puglGlBackend(), declared in pugl_gl.h - - puglCairoBackend(), declared in pugl_cairo.h + - puglGlBackend(), declared in pugl/gl.h + - puglCairoBackend(), declared in pugl/cairo.h Note that backends are modular and not compiled into the main Pugl library to avoid unnecessary dependencies. To use a particular backend, diff --git a/include/pugl/pugl_cairo.h b/include/pugl/pugl_cairo.h deleted file mode 100644 index 6e5a035..0000000 --- a/include/pugl/pugl_cairo.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright 2012-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_cairo.h - @brief Declaration of Cairo backend accessor. -*/ - -#ifndef PUGL_PUGL_CAIRO_H -#define PUGL_PUGL_CAIRO_H - -#include "pugl/pugl.h" - -PUGL_BEGIN_DECLS - -/** - @defgroup cairo Cairo - Cairo graphics support. - @ingroup pugl_c - @{ -*/ - -/** - Cairo graphics backend accessor. - - Pass the returned value to puglSetBackend() to draw to a view with Cairo. -*/ -PUGL_API PUGL_CONST_FUNC const PuglBackend* -puglCairoBackend(void); - -/** - @} -*/ - -PUGL_END_DECLS - -#endif // PUGL_PUGL_CAIRO_H diff --git a/include/pugl/pugl_gl.h b/include/pugl/pugl_gl.h deleted file mode 100644 index 78b994b..0000000 --- a/include/pugl/pugl_gl.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright 2012-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_gl.h - @brief OpenGL-specific API. -*/ - -#ifndef PUGL_PUGL_GL_H -#define PUGL_PUGL_GL_H - -#include "pugl/pugl.h" - -// IWYU pragma: begin_exports - -/* Unfortunately, GL includes vary across platforms, so include them here to - enable pure portable programs. */ - -#ifndef PUGL_NO_INCLUDE_GL_H -# ifdef __APPLE__ -# include "OpenGL/gl.h" -# else -# ifdef _WIN32 -# include -# endif -# include "GL/gl.h" -# endif -#endif - -#ifndef PUGL_NO_INCLUDE_GLU_H -# ifdef __APPLE__ -# include "OpenGL/glu.h" -# else -# ifdef _WIN32 -# include -# endif -# include "GL/glu.h" -# endif -#endif - -// IWYU pragma: end_exports - -PUGL_BEGIN_DECLS - -/** - @defgroup gl OpenGL - OpenGL graphics support. - @ingroup pugl_c - @{ -*/ - -/** - OpenGL extension function. -*/ -typedef void (*PuglGlFunc)(void); - -/** - Return the address of an OpenGL extension function. -*/ -PUGL_API PuglGlFunc -puglGetProcAddress(const char* name); - -/** - OpenGL graphics backend. - - Pass the returned value to puglSetBackend() to draw to a view with OpenGL. -*/ -PUGL_API PUGL_CONST_FUNC const PuglBackend* -puglGlBackend(void); - -PUGL_END_DECLS - -/** - @} -*/ - -#endif // PUGL_PUGL_GL_H diff --git a/include/pugl/pugl_stub.h b/include/pugl/pugl_stub.h deleted file mode 100644 index 569415c..0000000 --- a/include/pugl/pugl_stub.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2019-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_stub.h - @brief Stub backend functions and accessor declaration. -*/ - -#ifndef PUGL_PUGL_STUB_H -#define PUGL_PUGL_STUB_H - -#include "pugl/pugl.h" - -PUGL_BEGIN_DECLS - -/** - @defgroup stub Stub - Native graphics support. - @ingroup pugl_c - @{ -*/ - -/** - Stub graphics backend accessor. - - This backend just creates a simple native window without setting up any - portable graphics API. -*/ -PUGL_API PUGL_CONST_FUNC -const PuglBackend* -puglStubBackend(void); - -/** - @} -*/ - -PUGL_END_DECLS - -#endif // PUGL_PUGL_STUB_H diff --git a/include/pugl/pugl_vulkan.h b/include/pugl/pugl_vulkan.h deleted file mode 100644 index 451c28f..0000000 --- a/include/pugl/pugl_vulkan.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - Copyright 2012-2020 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file pugl_vulkan.h Vulkan-specific API. - - Note that this header includes Vulkan headers, so if you are writing a - program or plugin that dynamically loads vulkan, you should first define - `VK_NO_PROTOTYPES` before including it. -*/ - -#ifndef PUGL_PUGL_VULKAN_H -#define PUGL_PUGL_VULKAN_H - -#include "pugl/pugl.h" - -#include - -PUGL_BEGIN_DECLS - -/** - @defgroup vulkan Vulkan - Vulkan graphics support. - - Vulkan support differs from OpenGL because almost all most configuration is - done using the Vulkan API itself, rather than by setting view hints to - configure the context. Pugl only provides a minimal loader for loading the - Vulkan library, and a portable function to create a Vulkan surface for a - view, which hides the platform-specific implementation details. - - @ingroup pugl_c - @{ -*/ - -/** - Dynamic Vulkan loader. - - This can be used to dynamically load the Vulkan library. Applications or - plugins should not link against the Vulkan library, but instead use this at - runtime. This ensures that things will work on as many systems as possible, - and allows errors to be handled gracefully. - - This is not a "loader" in the sense of loading all the required Vulkan - functions (which is the application's responsibility), but just a minimal - implementation to portably load the Vulkan library and get the two functions - that are used to load everything else. - - Note that this owns the loaded Vulkan library, so it must outlive all use of - the Vulkan API. - - @see https://www.khronos.org/registry/vulkan/specs/1.0/html/chap4.html -*/ -typedef struct PuglVulkanLoaderImpl PuglVulkanLoader; - -/** - Create a new dynamic loader for Vulkan functions. - - This dynamically loads the Vulkan library and gets the load functions from it. - - @return A new Vulkan loader, or null on failure. -*/ -PUGL_API PuglVulkanLoader* -puglNewVulkanLoader(PuglWorld* world); - -/** - Free a loader created with puglNewVulkanLoader(). - - Note that this closes the Vulkan library, so no Vulkan objects or API may be - used after this is called. -*/ -PUGL_API void -puglFreeVulkanLoader(PuglVulkanLoader* loader); - -/** - Return the `vkGetInstanceProcAddr` function. - - @return Null if the Vulkan library does not contain this function (which is - unlikely and indicates a broken system). -*/ -PUGL_API PFN_vkGetInstanceProcAddr -puglGetInstanceProcAddrFunc(const PuglVulkanLoader* loader); - -/** - Return the `vkGetDeviceProcAddr` function. - - @return Null if the Vulkan library does not contain this function (which is - unlikely and indicates a broken system). -*/ -PUGL_API PFN_vkGetDeviceProcAddr -puglGetDeviceProcAddrFunc(const PuglVulkanLoader* loader); - -/** - Return the Vulkan instance extensions required to draw to a PuglView. - - This simply returns static strings, it does not access Vulkan or the window - system. The returned array always contains at least "VK_KHR_surface". - - @param[out] count The number of extensions in the returned array. - @return An array of extension name strings. -*/ -PUGL_API const char* const* -puglGetInstanceExtensions(uint32_t* count); - -/** - Create a Vulkan surface for a Pugl view. - - @param loader The loader for Vulkan functions. - @param view The view the surface is to be displayed on. - @param instance The Vulkan instance. - @param allocator Vulkan allocation callbacks, may be NULL. - @param[out] surface Pointed to a newly created Vulkan surface. - @return `VK_SUCCESS` on success, or a Vulkan error code. -*/ -PUGL_API VkResult -puglCreateSurface(const PuglVulkanLoader* loader, - PuglView* view, - VkInstance instance, - const VkAllocationCallbacks* allocator, - VkSurfaceKHR* surface); - -/** - Vulkan graphics backend. - - Pass the returned value to puglSetBackend() to draw to a view with Vulkan. -*/ -PUGL_API PUGL_CONST_FUNC const PuglBackend* -puglVulkanBackend(void); - -/** - @} -*/ - -PUGL_END_DECLS - -#endif // PUGL_PUGL_VULKAN_H diff --git a/include/pugl/stub.h b/include/pugl/stub.h new file mode 100644 index 0000000..fd62ff0 --- /dev/null +++ b/include/pugl/stub.h @@ -0,0 +1,52 @@ +/* + Copyright 2019-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file stub.h + @brief Stub backend functions and accessor declaration. +*/ + +#ifndef PUGL_STUB_H +#define PUGL_STUB_H + +#include "pugl/pugl.h" + +PUGL_BEGIN_DECLS + +/** + @defgroup stub Stub + Native graphics support. + @ingroup pugl_c + @{ +*/ + +/** + Stub graphics backend accessor. + + This backend just creates a simple native window without setting up any + portable graphics API. +*/ +PUGL_API PUGL_CONST_FUNC +const PuglBackend* +puglStubBackend(void); + +/** + @} +*/ + +PUGL_END_DECLS + +#endif // PUGL_STUB_H diff --git a/include/pugl/vulkan.h b/include/pugl/vulkan.h new file mode 100644 index 0000000..a2755f9 --- /dev/null +++ b/include/pugl/vulkan.h @@ -0,0 +1,148 @@ +/* + Copyright 2012-2020 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file vulkan.h Vulkan-specific API. + + Note that this header includes Vulkan headers, so if you are writing a + program or plugin that dynamically loads vulkan, you should first define + `VK_NO_PROTOTYPES` before including it. +*/ + +#ifndef PUGL_VULKAN_H +#define PUGL_VULKAN_H + +#include "pugl/pugl.h" + +#include + +PUGL_BEGIN_DECLS + +/** + @defgroup vulkan Vulkan + Vulkan graphics support. + + Vulkan support differs from OpenGL because almost all most configuration is + done using the Vulkan API itself, rather than by setting view hints to + configure the context. Pugl only provides a minimal loader for loading the + Vulkan library, and a portable function to create a Vulkan surface for a + view, which hides the platform-specific implementation details. + + @ingroup pugl_c + @{ +*/ + +/** + Dynamic Vulkan loader. + + This can be used to dynamically load the Vulkan library. Applications or + plugins should not link against the Vulkan library, but instead use this at + runtime. This ensures that things will work on as many systems as possible, + and allows errors to be handled gracefully. + + This is not a "loader" in the sense of loading all the required Vulkan + functions (which is the application's responsibility), but just a minimal + implementation to portably load the Vulkan library and get the two functions + that are used to load everything else. + + Note that this owns the loaded Vulkan library, so it must outlive all use of + the Vulkan API. + + @see https://www.khronos.org/registry/vulkan/specs/1.0/html/chap4.html +*/ +typedef struct PuglVulkanLoaderImpl PuglVulkanLoader; + +/** + Create a new dynamic loader for Vulkan functions. + + This dynamically loads the Vulkan library and gets the load functions from it. + + @return A new Vulkan loader, or null on failure. +*/ +PUGL_API PuglVulkanLoader* +puglNewVulkanLoader(PuglWorld* world); + +/** + Free a loader created with puglNewVulkanLoader(). + + Note that this closes the Vulkan library, so no Vulkan objects or API may be + used after this is called. +*/ +PUGL_API void +puglFreeVulkanLoader(PuglVulkanLoader* loader); + +/** + Return the `vkGetInstanceProcAddr` function. + + @return Null if the Vulkan library does not contain this function (which is + unlikely and indicates a broken system). +*/ +PUGL_API PFN_vkGetInstanceProcAddr +puglGetInstanceProcAddrFunc(const PuglVulkanLoader* loader); + +/** + Return the `vkGetDeviceProcAddr` function. + + @return Null if the Vulkan library does not contain this function (which is + unlikely and indicates a broken system). +*/ +PUGL_API PFN_vkGetDeviceProcAddr +puglGetDeviceProcAddrFunc(const PuglVulkanLoader* loader); + +/** + Return the Vulkan instance extensions required to draw to a PuglView. + + This simply returns static strings, it does not access Vulkan or the window + system. The returned array always contains at least "VK_KHR_surface". + + @param[out] count The number of extensions in the returned array. + @return An array of extension name strings. +*/ +PUGL_API const char* const* +puglGetInstanceExtensions(uint32_t* count); + +/** + Create a Vulkan surface for a Pugl view. + + @param loader The loader for Vulkan functions. + @param view The view the surface is to be displayed on. + @param instance The Vulkan instance. + @param allocator Vulkan allocation callbacks, may be NULL. + @param[out] surface Pointed to a newly created Vulkan surface. + @return `VK_SUCCESS` on success, or a Vulkan error code. +*/ +PUGL_API VkResult +puglCreateSurface(const PuglVulkanLoader* loader, + PuglView* view, + VkInstance instance, + const VkAllocationCallbacks* allocator, + VkSurfaceKHR* surface); + +/** + Vulkan graphics backend. + + Pass the returned value to puglSetBackend() to draw to a view with Vulkan. +*/ +PUGL_API PUGL_CONST_FUNC const PuglBackend* +puglVulkanBackend(void); + +/** + @} +*/ + +PUGL_END_DECLS + +#endif // PUGL_VULKAN_H diff --git a/src/mac_gl.m b/src/mac_gl.m index 038b942..f8847c0 100644 --- a/src/mac_gl.m +++ b/src/mac_gl.m @@ -23,7 +23,7 @@ #include "mac.h" #include "stub.h" -#include "pugl/pugl_gl.h" +#include "pugl/gl.h" #ifndef __MAC_10_10 # define NSOpenGLProfileVersion4_1Core NSOpenGLProfileVersion3_2Core diff --git a/src/mac_stub.m b/src/mac_stub.m index b4d9058..576734f 100644 --- a/src/mac_stub.m +++ b/src/mac_stub.m @@ -23,7 +23,7 @@ #include "mac.h" #include "stub.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #import diff --git a/src/mac_vulkan.m b/src/mac_vulkan.m index 90d349b..39c7f29 100644 --- a/src/mac_vulkan.m +++ b/src/mac_vulkan.m @@ -26,8 +26,8 @@ #include "types.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" -#include "pugl/pugl_vulkan.h" +#include "pugl/stub.h" +#include "pugl/vulkan.h" #include #include diff --git a/src/win.c b/src/win.c index 0578749..d7c0d57 100644 --- a/src/win.c +++ b/src/win.c @@ -25,7 +25,7 @@ #include "stub.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include #include diff --git a/src/win_gl.c b/src/win_gl.c index f011f5b..e46ece8 100644 --- a/src/win_gl.c +++ b/src/win_gl.c @@ -23,7 +23,7 @@ #include "types.h" #include "win.h" -#include "pugl/pugl_gl.h" +#include "pugl/gl.h" #include diff --git a/src/win_stub.c b/src/win_stub.c index e066e4d..2027836 100644 --- a/src/win_stub.c +++ b/src/win_stub.c @@ -18,7 +18,7 @@ #include "types.h" #include "win.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" PuglStatus puglWinStubConfigure(PuglView* view) diff --git a/src/win_vulkan.c b/src/win_vulkan.c index 5e3622e..eb20698 100644 --- a/src/win_vulkan.c +++ b/src/win_vulkan.c @@ -24,8 +24,8 @@ #include "types.h" #include "win.h" -#include "pugl/pugl_stub.h" -#include "pugl/pugl_vulkan.h" +#include "pugl/stub.h" +#include "pugl/vulkan.h" #include #include diff --git a/src/x11_cairo.c b/src/x11_cairo.c index f0b38a9..abfabff 100644 --- a/src/x11_cairo.c +++ b/src/x11_cairo.c @@ -22,8 +22,8 @@ #include "types.h" #include "x11.h" +#include "pugl/cairo.h" #include "pugl/pugl.h" -#include "pugl/pugl_cairo.h" #include #include diff --git a/src/x11_gl.c b/src/x11_gl.c index 72c2421..bab85c6 100644 --- a/src/x11_gl.c +++ b/src/x11_gl.c @@ -23,8 +23,8 @@ #include "types.h" #include "x11.h" +#include "pugl/gl.h" #include "pugl/pugl.h" -#include "pugl/pugl_gl.h" #include #include diff --git a/src/x11_stub.c b/src/x11_stub.c index 0f2e6d2..be66a88 100644 --- a/src/x11_stub.c +++ b/src/x11_stub.c @@ -14,7 +14,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include "stub.h" #include "types.h" diff --git a/src/x11_vulkan.c b/src/x11_vulkan.c index 1ca2ace..7004fd8 100644 --- a/src/x11_vulkan.c +++ b/src/x11_vulkan.c @@ -25,7 +25,7 @@ #include "x11.h" #include "pugl/pugl.h" -#include "pugl/pugl_vulkan.h" +#include "pugl/vulkan.h" #include #include diff --git a/test/test_build.c b/test/test_build.c index 984d23a..5259c7c 100644 --- a/test/test_build.c +++ b/test/test_build.c @@ -20,10 +20,10 @@ #define PUGL_DISABLE_DEPRECATED -#include "pugl/pugl.h" // IWYU pragma: keep -#include "pugl/pugl_cairo.h" // IWYU pragma: keep -#include "pugl/pugl_gl.h" // IWYU pragma: keep -#include "pugl/pugl_stub.h" // IWYU pragma: keep +#include "pugl/cairo.h" // IWYU pragma: keep +#include "pugl/gl.h" // IWYU pragma: keep +#include "pugl/pugl.h" // IWYU pragma: keep +#include "pugl/stub.h" // IWYU pragma: keep int main(void) diff --git a/test/test_build.cpp b/test/test_build.cpp index e8e64ab..4e29901 100644 --- a/test/test_build.cpp +++ b/test/test_build.cpp @@ -20,12 +20,12 @@ #define PUGL_DISABLE_DEPRECATED -#include "pugl/pugl.h" // IWYU pragma: keep -#include "pugl/pugl.hpp" // IWYU pragma: keep -#include "pugl/pugl.ipp" // IWYU pragma: keep -#include "pugl/pugl_cairo.hpp" // IWYU pragma: keep -#include "pugl/pugl_gl.hpp" // IWYU pragma: keep -#include "pugl/pugl_stub.hpp" // IWYU pragma: keep +#include "pugl/cairo.hpp" // IWYU pragma: keep +#include "pugl/gl.hpp" // IWYU pragma: keep +#include "pugl/pugl.h" // IWYU pragma: keep +#include "pugl/pugl.hpp" // IWYU pragma: keep +#include "pugl/pugl.ipp" // IWYU pragma: keep +#include "pugl/stub.hpp" // IWYU pragma: keep int main() diff --git a/test/test_gl_hints.c b/test/test_gl_hints.c index a40fdfa..c30d0ed 100644 --- a/test/test_gl_hints.c +++ b/test/test_gl_hints.c @@ -22,8 +22,8 @@ #include "test_utils.h" +#include "pugl/gl.h" #include "pugl/pugl.h" -#include "pugl/pugl_gl.h" #include diff --git a/test/test_realize.c b/test/test_realize.c index 4a12d1d..bb0b327 100644 --- a/test/test_realize.c +++ b/test/test_realize.c @@ -27,7 +27,7 @@ #include "test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include #include diff --git a/test/test_redisplay.c b/test/test_redisplay.c index 91b606f..66b9168 100644 --- a/test/test_redisplay.c +++ b/test/test_redisplay.c @@ -24,7 +24,7 @@ #include "test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include #include diff --git a/test/test_show_hide.c b/test/test_show_hide.c index ebbbee9..6252c28 100644 --- a/test/test_show_hide.c +++ b/test/test_show_hide.c @@ -24,7 +24,7 @@ #include "test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include #include diff --git a/test/test_stub_hints.c b/test/test_stub_hints.c index 96b2914..2bfc86c 100644 --- a/test/test_stub_hints.c +++ b/test/test_stub_hints.c @@ -23,7 +23,7 @@ #include "test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include diff --git a/test/test_timer.c b/test/test_timer.c index d567da0..219fa59 100644 --- a/test/test_timer.c +++ b/test/test_timer.c @@ -24,7 +24,7 @@ #include "test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include #include diff --git a/test/test_update.c b/test/test_update.c index bdcb28b..02b72a3 100644 --- a/test/test_update.c +++ b/test/test_update.c @@ -24,7 +24,7 @@ #include "test_utils.h" #include "pugl/pugl.h" -#include "pugl/pugl_stub.h" +#include "pugl/stub.h" #include #include -- cgit v1.2.1