aboutsummaryrefslogtreecommitdiff
path: root/subprojects/d2tk/pugl
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2021-01-02 18:46:50 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2021-01-02 18:46:50 +0100
commit179753003e5dc7908d9f577a962766f3b96de706 (patch)
treeb18d7844d7601c7ebb7517036cd9de685d4c5381 /subprojects/d2tk/pugl
parent1c1a467241bb2c944cef3fd57f75e7b15a171c65 (diff)
parentcfa8ca7436d78969a295b790f812a8bb4c9bcd6f (diff)
downloadmephisto.lv2-179753003e5dc7908d9f577a962766f3b96de706.tar.xz
Merge commit 'cfa8ca7436d78969a295b790f812a8bb4c9bcd6f'
Diffstat (limited to 'subprojects/d2tk/pugl')
-rw-r--r--subprojects/d2tk/pugl/.clang-format2
-rw-r--r--subprojects/d2tk/pugl/.clang-tidy19
-rw-r--r--subprojects/d2tk/pugl/.gitlab-ci.yml9
-rw-r--r--subprojects/d2tk/pugl/AUTHORS1
-rw-r--r--subprojects/d2tk/pugl/README.md52
-rw-r--r--subprojects/d2tk/pugl/bindings/cxx/include/.clang-tidy14
-rw-r--r--subprojects/d2tk/pugl/bindings/cxx/include/pugl/cairo.hpp (renamed from subprojects/d2tk/pugl/pugl/pugl_cairo.hpp)17
-rw-r--r--subprojects/d2tk/pugl/bindings/cxx/include/pugl/gl.hpp (renamed from subprojects/d2tk/pugl/pugl/pugl_gl.hpp)36
-rw-r--r--subprojects/d2tk/pugl/bindings/cxx/include/pugl/pugl.hpp (renamed from subprojects/d2tk/pugl/pugl/pugl.hpp)513
-rw-r--r--subprojects/d2tk/pugl/bindings/cxx/include/pugl/stub.hpp (renamed from subprojects/d2tk/pugl/pugl/pugl_stub.hpp)17
-rw-r--r--subprojects/d2tk/pugl/bindings/cxx/include/pugl/vulkan.hpp168
-rw-r--r--subprojects/d2tk/pugl/doc/_static/custom.css95
-rw-r--r--subprojects/d2tk/pugl/doc/_templates/about.html57
-rw-r--r--subprojects/d2tk/pugl/doc/c/Doxyfile30
-rw-r--r--subprojects/d2tk/pugl/doc/c/index.rst6
-rw-r--r--subprojects/d2tk/pugl/doc/c/overview.rst579
-rw-r--r--subprojects/d2tk/pugl/doc/c/reference.rst18
-rw-r--r--subprojects/d2tk/pugl/doc/c/wscript43
-rw-r--r--subprojects/d2tk/pugl/doc/conf.py.in88
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/Doxyfile40
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/c-reference.rst20
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/cpp-reference.rst18
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/index.rst7
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/overview.rst423
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/wscript44
-rw-r--r--subprojects/d2tk/pugl/doc/deployment.rst23
-rw-r--r--subprojects/d2tk/pugl/doc/footer.html20
-rw-r--r--subprojects/d2tk/pugl/doc/header.html49
-rw-r--r--subprojects/d2tk/pugl/doc/layout.xml194
-rw-r--r--subprojects/d2tk/pugl/doc/mainpage.md42
-rw-r--r--subprojects/d2tk/pugl/doc/pugl.rst26
-rw-r--r--subprojects/d2tk/pugl/doc/reference.doxygen.in2462
-rw-r--r--subprojects/d2tk/pugl/doc/style.css863
-rw-r--r--subprojects/d2tk/pugl/examples/.clang-tidy38
-rw-r--r--subprojects/d2tk/pugl/examples/cube_view.h54
-rw-r--r--subprojects/d2tk/pugl/examples/demo_utils.h61
-rw-r--r--subprojects/d2tk/pugl/examples/file_utils.c68
-rw-r--r--subprojects/d2tk/pugl/examples/file_utils.h (renamed from subprojects/d2tk/pugl/pugl/glu.h)33
-rw-r--r--subprojects/d2tk/pugl/examples/glad/glad.h2
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_cairo_demo.c9
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_cursor_demo.c11
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_cxx_demo.cpp41
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_embed_demo.c10
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_print_events.c15
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_shader_demo.c116
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_vulkan_cxx_demo.cpp1871
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_vulkan_demo.c1139
-rw-r--r--subprojects/d2tk/pugl/examples/pugl_window_demo.c9
-rw-r--r--subprojects/d2tk/pugl/examples/rects.h11
-rw-r--r--subprojects/d2tk/pugl/examples/shader_utils.h5
-rw-r--r--subprojects/d2tk/pugl/examples/shaders/header_330.glsl (renamed from subprojects/d2tk/pugl/shaders/header_330.glsl)0
-rw-r--r--subprojects/d2tk/pugl/examples/shaders/header_420.glsl (renamed from subprojects/d2tk/pugl/shaders/header_420.glsl)0
-rw-r--r--subprojects/d2tk/pugl/examples/shaders/rect.frag (renamed from subprojects/d2tk/pugl/shaders/rect.frag)0
-rw-r--r--subprojects/d2tk/pugl/examples/shaders/rect.vert (renamed from subprojects/d2tk/pugl/shaders/rect.vert)0
-rw-r--r--subprojects/d2tk/pugl/examples/sybok.hpp2358
-rw-r--r--subprojects/d2tk/pugl/include/.clang-tidy9
-rw-r--r--subprojects/d2tk/pugl/include/pugl/cairo.h (renamed from subprojects/d2tk/pugl/pugl/pugl_cairo.h)17
-rw-r--r--subprojects/d2tk/pugl/include/pugl/gl.h (renamed from subprojects/d2tk/pugl/pugl/pugl_gl.h)64
-rw-r--r--subprojects/d2tk/pugl/include/pugl/pugl.h (renamed from subprojects/d2tk/pugl/pugl/pugl.h)373
-rw-r--r--subprojects/d2tk/pugl/include/pugl/stub.h (renamed from subprojects/d2tk/pugl/pugl/pugl_stub.h)27
-rw-r--r--subprojects/d2tk/pugl/include/pugl/vulkan.h146
-rw-r--r--subprojects/d2tk/pugl/pugl.pc.in2
-rw-r--r--subprojects/d2tk/pugl/pugl/gl.h32
-rw-r--r--subprojects/d2tk/pugl/pugl/pugl.ipp154
-rw-r--r--subprojects/d2tk/pugl/resources/pugl.svg92
-rwxr-xr-xsubprojects/d2tk/pugl/scripts/dox_to_sphinx.py666
-rw-r--r--subprojects/d2tk/pugl/src/.clang-tidy19
-rw-r--r--subprojects/d2tk/pugl/src/implementation.c (renamed from subprojects/d2tk/pugl/pugl/detail/implementation.c)112
-rw-r--r--subprojects/d2tk/pugl/src/implementation.h (renamed from subprojects/d2tk/pugl/pugl/detail/implementation.h)39
-rw-r--r--subprojects/d2tk/pugl/src/mac.h (renamed from subprojects/d2tk/pugl/pugl/detail/mac.h)14
-rw-r--r--subprojects/d2tk/pugl/src/mac.m (renamed from subprojects/d2tk/pugl/pugl/detail/mac.m)197
-rw-r--r--subprojects/d2tk/pugl/src/mac_cairo.m (renamed from subprojects/d2tk/pugl/pugl/detail/mac_cairo.m)21
-rw-r--r--subprojects/d2tk/pugl/src/mac_gl.m (renamed from subprojects/d2tk/pugl/pugl/detail/mac_gl.m)63
-rw-r--r--subprojects/d2tk/pugl/src/mac_stub.m (renamed from subprojects/d2tk/pugl/pugl/detail/mac_stub.m)16
-rw-r--r--subprojects/d2tk/pugl/src/mac_vulkan.m213
-rw-r--r--subprojects/d2tk/pugl/src/stub.h (renamed from subprojects/d2tk/pugl/pugl/detail/stub.h)5
-rw-r--r--subprojects/d2tk/pugl/src/types.h (renamed from subprojects/d2tk/pugl/pugl/detail/types.h)9
-rw-r--r--subprojects/d2tk/pugl/src/win.c (renamed from subprojects/d2tk/pugl/pugl/detail/win.c)151
-rw-r--r--subprojects/d2tk/pugl/src/win.h (renamed from subprojects/d2tk/pugl/pugl/detail/win.h)37
-rw-r--r--subprojects/d2tk/pugl/src/win_cairo.c (renamed from subprojects/d2tk/pugl/pugl/detail/win_cairo.c)17
-rw-r--r--subprojects/d2tk/pugl/src/win_gl.c (renamed from subprojects/d2tk/pugl/pugl/detail/win_gl.c)46
-rw-r--r--subprojects/d2tk/pugl/src/win_stub.c80
-rw-r--r--subprojects/d2tk/pugl/src/win_vulkan.c127
-rw-r--r--subprojects/d2tk/pugl/src/x11.c (renamed from subprojects/d2tk/pugl/pugl/detail/x11.c)207
-rw-r--r--subprojects/d2tk/pugl/src/x11.h (renamed from subprojects/d2tk/pugl/pugl/detail/x11.h)22
-rw-r--r--subprojects/d2tk/pugl/src/x11_cairo.c (renamed from subprojects/d2tk/pugl/pugl/detail/x11_cairo.c)10
-rw-r--r--subprojects/d2tk/pugl/src/x11_gl.c (renamed from subprojects/d2tk/pugl/pugl/detail/x11_gl.c)73
-rw-r--r--subprojects/d2tk/pugl/src/x11_stub.c58
-rw-r--r--subprojects/d2tk/pugl/src/x11_vulkan.c131
-rw-r--r--subprojects/d2tk/pugl/test/.clang-tidy14
-rw-r--r--subprojects/d2tk/pugl/test/test_build.c10
-rw-r--r--subprojects/d2tk/pugl/test/test_build.cpp13
-rw-r--r--subprojects/d2tk/pugl/test/test_clipboard.c104
-rw-r--r--subprojects/d2tk/pugl/test/test_gl_hints.c89
-rw-r--r--subprojects/d2tk/pugl/test/test_realize.c100
-rw-r--r--subprojects/d2tk/pugl/test/test_redisplay.c4
-rw-r--r--subprojects/d2tk/pugl/test/test_show_hide.c6
-rw-r--r--subprojects/d2tk/pugl/test/test_stub_hints.c80
-rw-r--r--subprojects/d2tk/pugl/test/test_timer.c4
-rw-r--r--subprojects/d2tk/pugl/test/test_update.c4
-rw-r--r--subprojects/d2tk/pugl/test/test_utils.h70
-rw-r--r--subprojects/d2tk/pugl/wscript403
102 files changed, 10740 insertions, 5256 deletions
diff --git a/subprojects/d2tk/pugl/.clang-format b/subprojects/d2tk/pugl/.clang-format
index 043fd1f..a505e26 100644
--- a/subprojects/d2tk/pugl/.clang-format
+++ b/subprojects/d2tk/pugl/.clang-format
@@ -33,7 +33,7 @@ BraceWrapping:
AfterObjCDeclaration: true
AfterStruct: false
AfterUnion: false
- AfterExternBlock: true
+ AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
diff --git a/subprojects/d2tk/pugl/.clang-tidy b/subprojects/d2tk/pugl/.clang-tidy
index c8039e1..1e40901 100644
--- a/subprojects/d2tk/pugl/.clang-tidy
+++ b/subprojects/d2tk/pugl/.clang-tidy
@@ -1,21 +1,4 @@
Checks: >
*,
- -*avoid-c-arrays,
- -*magic-numbers,
- -*uppercase-literal-suffix,
- -android-cloexec-fopen,
- -bugprone-suspicious-string-compare,
- -cert-flp30-c,
- -clang-analyzer-alpha.*,
- -clang-analyzer-security.FloatLoopCounter,
- -google-runtime-references,
- -hicpp-multiway-paths-covered,
- -hicpp-signed-bitwise,
- -llvm-header-guard,
- -modernize-use-trailing-return-type,
- -readability-else-after-return,
- -readability-implicit-bool-conversion,
- -readability-named-parameter,
-WarningsAsErrors: ''
-HeaderFilterRegex: 'pugl/.*|test/.*|examples/.*'
FormatStyle: file
+WarningsAsErrors: '*'
diff --git a/subprojects/d2tk/pugl/.gitlab-ci.yml b/subprojects/d2tk/pugl/.gitlab-ci.yml
index 42d14cd..c0d0330 100644
--- a/subprojects/d2tk/pugl/.gitlab-ci.yml
+++ b/subprojects/d2tk/pugl/.gitlab-ci.yml
@@ -43,7 +43,7 @@ arm64_rel:
x64_dbg:
<<: *build_definition
image: lv2plugin/debian-x64
- script: python ./waf configure build -dST --werror --no-coverage --docs
+ script: python3 ./waf configure build -dST --werror --no-coverage --docs
artifacts:
paths:
- build/doc
@@ -108,7 +108,12 @@ win_rel:
pages:
stage: deploy
- script: mv build/doc/html/ public/
+ script:
+ - mkdir public
+ - mkdir public/c
+ - mkdir public/cpp
+ - mv build/doc/c/singlehtml/ public/c/singlehtml/
+ - mv build/doc/cpp/singlehtml/ public/cpp/singlehtml/
dependencies:
- x64_dbg
artifacts:
diff --git a/subprojects/d2tk/pugl/AUTHORS b/subprojects/d2tk/pugl/AUTHORS
index 18aadaf..99f6dac 100644
--- a/subprojects/d2tk/pugl/AUTHORS
+++ b/subprojects/d2tk/pugl/AUTHORS
@@ -10,3 +10,4 @@ Jordan Halase <jordan@halase.me>
Oliver Schmidt <oliver@luced.de>
Zoƫ Sparks <zoe@milky.flowers>
Jean Pierre Cimalando <jp-dev@inbox.ru>
+Thomas Brand <tom@trellis.ch>
diff --git a/subprojects/d2tk/pugl/README.md b/subprojects/d2tk/pugl/README.md
index e8794bc..97906a8 100644
--- a/subprojects/d2tk/pugl/README.md
+++ b/subprojects/d2tk/pugl/README.md
@@ -3,7 +3,7 @@ Pugl
Pugl (PlUgin Graphics Library) is a minimal portable API for GUIs which is
suitable for use in plugins. It works on X11, MacOS, and Windows, and
-optionally supports OpenGL and Cairo graphics contexts.
+optionally supports Vulkan, OpenGL, and Cairo graphics contexts.
Pugl is vaguely similar to libraries like GLUT and GLFW, but with some
distinguishing features:
@@ -37,35 +37,16 @@ being, however, the API may break occasionally. Please report any relevant
feedback, or file feature requests, so that we can ensure that the released API
is stable for as long as possible.
-Distribution
-------------
-
-Pugl is designed for flexible distribution. It can be used by simply including
-the source code, or installed and linked against as a static or shared library.
-Static linking or direct inclusion is a good idea for plugins that will be
-distributed as binaries to avoid dependency problems.
-
-If you are including the code, please use a submodule so that suitable changes
-can be merged upstream to keep fragmentation to a minimum.
-
-When installed, Pugl is split into different libraries to keep dependencies
-minimal. The core implementation is separate from graphics backends:
-
- * The core implementation for a particular platform is in one library:
- `pugl_x11`, `pugl_mac`, or `pugl_win`. This does not depend on backends or
- their dependencies.
+Documentation
+-------------
- * Backends for platforms are in separate libraries, which depend on the core:
- `pugl_x11_cairo`, `pugl_x11_gl`, `pugl_mac_cairo`, and so on.
+Pugl is a C library that includes C++ bindings.
+Each API is documented separately:
-Applications must link against the core and at least one backend. Normally,
-this can be achieved by simply depending on the package `pugl-gl-0` or
-`pugl-cairo-0`. Though it is possible to compile everything into a monolithic
-library, distributions should retain this separation so that GL applications
-don't depend on Cairo and its dependencies, or vice-versa.
+ * [C Documentation](https://lv2.gitlab.io/pugl/c/singlehtml)
+ * [C++ Documentation](https://lv2.gitlab.io/pugl/cpp/singlehtml)
-Distributions are encouraged to include static libraries if possible so that
-developers can build portable plugin binaries.
+The documentation can also be built from the source by configuring with `--docs`.
Testing
-------
@@ -81,8 +62,8 @@ Then, after building, the unit tests can be run:
./waf
./waf test --gui-tests
-Several example programs are included that serve as both manual tests and
-demonstrations:
+The `examples` directory contains several programs that serve as both manual
+tests and demonstrations:
* `pugl_embed_demo` shows a view embedded in another, and also tests
requesting attention (which happens after 5 seconds), keyboard focus
@@ -104,15 +85,14 @@ demonstrations:
* `pugl_cxx_demo` is a simple cube demo that uses the C++ API.
+ * `pugl_vulkan_demo` is a simple example of using Vulkan in C that simply
+ clears the window.
+
+ * `pugl_vulkan_cxx_demo` is a more advanced Vulkan demo in C++ that draws many
+ animated rectangles like `pugl_shader_demo`.
+
All example programs support several command line options to control various
behaviours, see the output of `--help` for details. Please file an issue if
any of these programs do not work as expected on your system.
-Documentation
--------------
-
-The [API reference](https://lv2.gitlab.io/pugl/) for the latest master is
-available online, and can also be built from the source code by configuring
-with `--docs`.
-
-- David Robillard <d@drobilla.net>
diff --git a/subprojects/d2tk/pugl/bindings/cxx/include/.clang-tidy b/subprojects/d2tk/pugl/bindings/cxx/include/.clang-tidy
new file mode 100644
index 0000000..816223d
--- /dev/null
+++ b/subprojects/d2tk/pugl/bindings/cxx/include/.clang-tidy
@@ -0,0 +1,14 @@
+Checks: >
+ *,
+ -*-uppercase-literal-suffix,
+ -clang-diagnostic-unused-macros,
+ -cppcoreguidelines-pro-bounds-pointer-arithmetic,
+ -cppcoreguidelines-pro-type-static-cast-downcast,
+ -google-runtime-references,
+ -hicpp-named-parameter,
+ -llvmlibc-*,
+ -modernize-use-trailing-return-type,
+ -readability-implicit-bool-conversion,
+ -readability-named-parameter,
+FormatStyle: file
+HeaderFilterRegex: 'pugl/.*'
diff --git a/subprojects/d2tk/pugl/pugl/pugl_cairo.hpp b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/cairo.hpp
index 5b17ab7..7416589 100644
--- a/subprojects/d2tk/pugl/pugl/pugl_cairo.hpp
+++ b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/cairo.hpp
@@ -14,16 +14,11 @@
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
+#ifndef PUGL_CAIRO_HPP
+#define PUGL_CAIRO_HPP
+#include "pugl/cairo.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_cairo.h"
namespace pugl {
@@ -35,8 +30,8 @@ namespace pugl {
*/
/// @copydoc puglCairoBackend
-static inline const PuglBackend*
-cairoBackend()
+inline const PuglBackend*
+cairoBackend() noexcept
{
return puglCairoBackend();
}
@@ -47,4 +42,4 @@ cairoBackend()
} // namespace pugl
-#endif // PUGL_PUGL_CAIRO_HPP
+#endif // PUGL_CAIRO_HPP
diff --git a/subprojects/d2tk/pugl/pugl/pugl_gl.hpp b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/gl.hpp
index 4bc5bbd..d8459a8 100644
--- a/subprojects/d2tk/pugl/pugl/pugl_gl.hpp
+++ b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/gl.hpp
@@ -14,16 +14,12 @@
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
+#ifndef PUGL_GL_HPP
+#define PUGL_GL_HPP
+#include "pugl/gl.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_gl.h"
+#include "pugl/pugl.hpp"
namespace pugl {
@@ -38,15 +34,29 @@ namespace pugl {
using GlFunc = PuglGlFunc;
/// @copydoc puglGetProcAddress
-static inline GlFunc
-getProcAddress(const char* name)
+inline GlFunc
+getProcAddress(const char* name) noexcept
{
return puglGetProcAddress(name);
}
+/// @copydoc puglEnterContext
+inline Status
+enterContext(View& view) noexcept
+{
+ return static_cast<Status>(puglEnterContext(view.cobj()));
+}
+
+/// @copydoc puglLeaveContext
+inline Status
+leaveContext(View& view) noexcept
+{
+ return static_cast<Status>(puglLeaveContext(view.cobj()));
+}
+
/// @copydoc puglGlBackend
-static inline const PuglBackend*
-glBackend()
+inline const PuglBackend*
+glBackend() noexcept
{
return puglGlBackend();
}
@@ -57,4 +67,4 @@ glBackend()
} // namespace pugl
-#endif // PUGL_PUGL_GL_HPP
+#endif // PUGL_GL_HPP
diff --git a/subprojects/d2tk/pugl/pugl/pugl.hpp b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/pugl.hpp
index 3072560..1a07734 100644
--- a/subprojects/d2tk/pugl/pugl/pugl.hpp
+++ b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/pugl.hpp
@@ -14,35 +14,26 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl.hpp
- @brief Pugl C++ API wrapper.
-*/
-
#ifndef PUGL_PUGL_HPP
#define PUGL_PUGL_HPP
#include "pugl/pugl.h"
-#include <cassert>
-#include <chrono>
-#include <functional>
-#include <memory>
-#include <stdexcept>
-#include <type_traits>
+#include <cstdint>
-/**
- @defgroup pugl_cxx C++ API
- C++ API wrapper.
+#if defined(PUGL_HPP_THROW_FAILED_CONSTRUCTION)
+# include <exception>
+#elif defined(PUGL_HPP_ASSERT_CONSTRUCTION)
+# include <cassert>
+#endif
- @ingroup pugl
- @{
-*/
+namespace pugl {
/**
- Pugl C++ API namespace.
+ @defgroup puglxx Pugl C++ API
+ Pugl C++ API wrapper.
+ @{
*/
-namespace pugl {
namespace detail {
@@ -50,27 +41,39 @@ namespace detail {
template<typename T>
using FreeFunc = void (*)(T*);
-/// Simple overhead-free deleter for a C object
-template<typename T, FreeFunc<T> Free>
-struct Deleter {
- void operator()(T* ptr) { Free(ptr); }
-};
-
/// Generic C++ wrapper for a C object
template<class T, FreeFunc<T> Free>
class Wrapper
{
public:
- T* cobj() { return _ptr.get(); }
- const T* cobj() const { return _ptr.get(); }
+ Wrapper(const Wrapper&) = delete;
+ Wrapper& operator=(const Wrapper&) = delete;
+
+ Wrapper(Wrapper&& wrapper) noexcept
+ : _ptr{wrapper._ptr}
+ {
+ wrapper._ptr = nullptr;
+ }
+
+ Wrapper& operator=(Wrapper&& wrapper) noexcept
+ {
+ _ptr = wrapper._ptr;
+ wrapper._ptr = nullptr;
+ return *this;
+ }
+
+ ~Wrapper() noexcept { Free(_ptr); }
+
+ T* cobj() noexcept { return _ptr; }
+ const T* cobj() const noexcept { return _ptr; }
protected:
- explicit Wrapper(T* ptr)
- : _ptr(ptr, Deleter<T, Free>{})
+ explicit Wrapper(T* ptr) noexcept
+ : _ptr{ptr}
{}
private:
- std::unique_ptr<T, Deleter<T, Free>> _ptr;
+ T* _ptr;
};
} // namespace detail
@@ -79,8 +82,6 @@ using Rect = PuglRect; ///< @copydoc PuglRect
/**
@defgroup eventsxx Events
- @ingroup pugl_cxx
- @copydoc events
@{
*/
@@ -96,8 +97,10 @@ using Rect = PuglRect; ///< @copydoc PuglRect
*/
template<PuglEventType t, class Base>
struct Event final : Base {
+ /// The type of the corresponding C event structure
using BaseEvent = Base;
+ /// The `type` field of the corresponding C event structure
static constexpr const PuglEventType type = t;
};
@@ -172,11 +175,15 @@ using ClientEvent = Event<PUGL_CLIENT, PuglEventClient>;
/// @copydoc PuglEventTimer
using TimerEvent = Event<PUGL_TIMER, PuglEventTimer>;
+/// @copydoc PuglEventLoopEnter
+using LoopEnterEvent = Event<PUGL_LOOP_ENTER, PuglEventLoopEnter>;
+
+/// @copydoc PuglEventLoopLeave
+using LoopLeaveEvent = Event<PUGL_LOOP_LEAVE, PuglEventLoopLeave>;
+
/**
@}
@defgroup statusxx Status
- @ingroup pugl_cxx
- @copydoc status
@{
*/
@@ -199,8 +206,8 @@ enum class Status {
static_assert(Status(PUGL_UNSUPPORTED_TYPE) == Status::unsupportedType, "");
/// @copydoc puglStrerror
-static inline const char*
-strerror(const pugl::Status status)
+inline const char*
+strerror(const Status status) noexcept
{
return puglStrerror(static_cast<PuglStatus>(status));
}
@@ -208,13 +215,9 @@ strerror(const pugl::Status status)
/**
@}
@defgroup worldxx World
- @ingroup pugl_cxx
- @copydoc world
@{
*/
-class World;
-
/// @copydoc PuglWorldType
enum class WorldType {
program, ///< @copydoc PUGL_PROGRAM
@@ -232,109 +235,97 @@ static_assert(WorldFlag(PUGL_WORLD_THREADS) == WorldFlag::threads, "");
using WorldFlags = PuglWorldFlags; ///< @copydoc PuglWorldFlags
-/// @copydoc PuglLogLevel
-enum class LogLevel {
- err = PUGL_LOG_LEVEL_ERR, ///< @copydoc PUGL_LOG_LEVEL_ERR
- warning = PUGL_LOG_LEVEL_WARNING, ///< @copydoc PUGL_LOG_LEVEL_WARNING
- info = PUGL_LOG_LEVEL_INFO, ///< @copydoc PUGL_LOG_LEVEL_INFO
- debug = PUGL_LOG_LEVEL_DEBUG, ///< @copydoc PUGL_LOG_LEVEL_DEBUG
-};
+#if defined(PUGL_HPP_THROW_FAILED_CONSTRUCTION)
-static_assert(LogLevel(PUGL_LOG_LEVEL_DEBUG) == LogLevel::debug, "");
-
-/// @copydoc PuglLogFunc
-using LogFunc =
- std::function<void(World& world, LogLevel level, const char* msg)>;
-
-/**
- A `std::chrono` compatible clock that uses Pugl time.
-*/
-class Clock
+/// An exception thrown when construction fails
+class FailedConstructionError : public std::exception
{
public:
- using rep = double; ///< Time representation
- using duration = std::chrono::duration<double>; ///< Duration in seconds
- using time_point = std::chrono::time_point<Clock>; ///< A Pugl time point
-
- static constexpr bool is_steady = true; ///< Steady clock flag, always true
-
- /// Construct a clock that uses time from puglGetTime()
- explicit Clock(World& world)
- : _world{world}
+ FailedConstructionError(const char* const msg) noexcept
+ : _msg{msg}
{}
- /// Return the current time
- time_point now() const;
+ virtual const char* what() const noexcept override;
private:
- const pugl::World& _world;
+ const char* _msg;
};
+# define PUGL_CHECK_CONSTRUCTION(cond, msg) \
+ do { \
+ if (!(cond)) { \
+ throw FailedConstructionError(msg); \
+ } \
+ } while (0)
+
+#elif defined(PUGL_HPP_ASSERT_CONSTRUCTION)
+# define PUGL_CHECK_CONSTRUCTION(cond, msg) assert(cond);
+#else
+/**
+ Configurable macro for handling construction failure.
+
+ If `PUGL_HPP_THROW_FAILED_CONSTRUCTION` is defined, then this throws a
+ `pugl::FailedConstructionError` if construction fails.
+
+ If `PUGL_HPP_ASSERT_CONSTRUCTION` is defined, then this asserts if
+ construction fails.
+
+ Otherwise, this does nothing.
+*/
+# define PUGL_CHECK_CONSTRUCTION(cond, msg)
+#endif
+
/// @copydoc PuglWorld
class World : public detail::Wrapper<PuglWorld, puglFreeWorld>
{
public:
- explicit World(WorldType type, WorldFlags flags)
- : Wrapper{puglNewWorld(static_cast<PuglWorldType>(type), flags)}
- , _clock(*this)
+ World(const World&) = delete;
+ World& operator=(const World&) = delete;
+
+ World(World&&) = delete;
+ World& operator=(World&&) = delete;
+
+ ~World() = default;
+
+ World(WorldType type, WorldFlag flag)
+ : Wrapper{puglNewWorld(static_cast<PuglWorldType>(type),
+ static_cast<PuglWorldFlags>(flag))}
{
- if (!cobj()) {
- throw std::runtime_error("Failed to create pugl::World");
- }
+ PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World");
}
- explicit World(WorldType type)
- : World{type, {}}
+ World(WorldType type, WorldFlags flags)
+ : Wrapper{puglNewWorld(static_cast<PuglWorldType>(type), flags)}
{
- if (!cobj()) {
- throw std::runtime_error("Failed to create pugl::World");
- }
+ PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World");
}
- /// @copydoc puglGetNativeWorld
- void* nativeWorld() { return puglGetNativeWorld(cobj()); }
-
- // TODO: setLogFunc
+ explicit World(WorldType type)
+ : World{type, WorldFlags{}}
+ {}
- Status setLogLevel(const LogLevel level)
- {
- return static_cast<Status>(
- puglSetLogLevel(cobj(), static_cast<PuglLogLevel>(level)));
- }
+ /// @copydoc puglGetNativeWorld
+ void* nativeWorld() noexcept { return puglGetNativeWorld(cobj()); }
/// @copydoc puglSetClassName
- Status setClassName(const char* const name)
+ Status setClassName(const char* const name) noexcept
{
return static_cast<Status>(puglSetClassName(cobj(), name));
}
/// @copydoc puglGetTime
- double time() const { return puglGetTime(cobj()); }
+ double time() const noexcept { return puglGetTime(cobj()); }
/// @copydoc puglUpdate
- Status update(const double timeout)
+ Status update(const double timeout) noexcept
{
return static_cast<Status>(puglUpdate(cobj(), timeout));
}
-
- /// Return a clock that uses Pugl time
- const Clock& clock() { return _clock; }
-
-private:
- Clock _clock;
};
-inline Clock::time_point
-Clock::now() const
-{
- return time_point{duration{_world.time()}};
-}
-
/**
@}
@defgroup viewxx View
- @ingroup pugl_cxx
- @copydoc view
@{
*/
@@ -358,10 +349,10 @@ enum class ViewHint {
swapInterval, ///< @copydoc PUGL_SWAP_INTERVAL
resizable, ///< @copydoc PUGL_RESIZABLE
ignoreKeyRepeat, ///< @copydoc PUGL_IGNORE_KEY_REPEAT
+ refreshRate, ///< @copydoc PUGL_REFRESH_RATE
};
-static_assert(ViewHint(PUGL_IGNORE_KEY_REPEAT) == ViewHint::ignoreKeyRepeat,
- "");
+static_assert(ViewHint(PUGL_REFRESH_RATE) == ViewHint::refreshRate, "");
using ViewHintValue = PuglViewHintValue; ///< @copydoc PuglViewHintValue
@@ -392,32 +383,71 @@ public:
: Wrapper{puglNewView(world.cobj())}
, _world(world)
{
- if (!cobj()) {
- throw std::runtime_error("Failed to create pugl::View");
- }
-
- puglSetHandle(cobj(), this);
- puglSetEventFunc(cobj(), dispatchEvent);
+ PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::View");
}
- virtual ~View() = default;
-
- View(const View&) = delete;
- View& operator=(const View&) = delete;
+ const World& world() const noexcept { return _world; }
+ World& world() noexcept { return _world; }
- View(View&&) = delete;
- View&& operator=(View&&) = delete;
+ /**
+ Set the object that will be called to handle events.
+
+ This is a type-safe wrapper for the C functions puglSetHandle() and
+ puglSetEventFunc() that will automatically dispatch events to the
+ `onEvent` method of `handler` that takes the appropriate event type.
+ The handler must have such a method defined for every event type, but if
+ the handler is the view itself, a `using` declaration can be used to
+ "inherit" the default implementation to avoid having to define every
+ method. For example:
+
+ @code
+ class MyView : public pugl::View
+ {
+ public:
+ explicit MyView(pugl::World& world)
+ : pugl::View{world}
+ {
+ setEventHandler(*this);
+ }
+
+ using pugl::View::onEvent;
+
+ pugl::Status onEvent(const pugl::ConfigureEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::ExposeEvent& event) noexcept;
+ };
+ @endcode
+
+ This facility is just a convenience, applications may use the C API
+ directly to set a handle and event function to set up a different
+ approach for event handling.
+ */
+ template<class Handler>
+ Status setEventHandler(Handler& handler)
+ {
+ puglSetHandle(cobj(), &handler);
+ return static_cast<Status>(
+ puglSetEventFunc(cobj(), eventFunc<Handler>));
+ }
- const pugl::World& world() const { return _world; }
- pugl::World& world() { return _world; }
+ /// @copydoc puglSetBackend
+ Status setBackend(const PuglBackend* backend) noexcept
+ {
+ return static_cast<Status>(puglSetBackend(cobj(), backend));
+ }
/// @copydoc puglSetViewHint
- Status setHint(ViewHint hint, int value)
+ Status setHint(ViewHint hint, int value) noexcept
{
return static_cast<Status>(
puglSetViewHint(cobj(), static_cast<PuglViewHint>(hint), value));
}
+ /// @copydoc puglGetViewHint
+ int getHint(ViewHint hint) noexcept
+ {
+ return puglGetViewHint(cobj(), static_cast<PuglViewHint>(hint));
+ }
+
/**
@}
@name Frame
@@ -426,34 +456,34 @@ public:
*/
/// @copydoc puglGetFrame
- Rect frame() const { return puglGetFrame(cobj()); }
+ Rect frame() const noexcept { return puglGetFrame(cobj()); }
/// @copydoc puglSetFrame
- Status setFrame(Rect frame)
+ Status setFrame(Rect frame) noexcept
{
return static_cast<Status>(puglSetFrame(cobj(), frame));
}
/// @copydoc puglSetDefaultSize
- Status setDefaultSize(int width, int height)
+ Status setDefaultSize(int width, int height) noexcept
{
return static_cast<Status>(puglSetDefaultSize(cobj(), width, height));
}
/// @copydoc puglSetMinSize
- Status setMinSize(int width, int height)
+ Status setMinSize(int width, int height) noexcept
{
return static_cast<Status>(puglSetMinSize(cobj(), width, height));
}
/// @copydoc puglSetMaxSize
- Status setMaxSize(int width, int height)
+ Status setMaxSize(int width, int height) noexcept
{
return static_cast<Status>(puglSetMaxSize(cobj(), width, height));
}
/// @copydoc puglSetAspectRatio
- Status setAspectRatio(int minX, int minY, int maxX, int maxY)
+ Status setAspectRatio(int minX, int minY, int maxX, int maxY) noexcept
{
return static_cast<Status>(
puglSetAspectRatio(cobj(), minX, minY, maxX, maxY));
@@ -467,37 +497,46 @@ public:
*/
/// @copydoc puglSetWindowTitle
- Status setWindowTitle(const char* title)
+ Status setWindowTitle(const char* title) noexcept
{
return static_cast<Status>(puglSetWindowTitle(cobj(), title));
}
/// @copydoc puglSetParentWindow
- Status setParentWindow(NativeView parent)
+ Status setParentWindow(NativeView parent) noexcept
{
return static_cast<Status>(puglSetParentWindow(cobj(), parent));
}
/// @copydoc puglSetTransientFor
- Status setTransientFor(NativeView parent)
+ Status setTransientFor(NativeView parent) noexcept
{
return static_cast<Status>(puglSetTransientFor(cobj(), parent));
}
/// @copydoc puglRealize
- Status realize() { return static_cast<Status>(puglRealize(cobj())); }
+ Status realize() noexcept
+ {
+ return static_cast<Status>(puglRealize(cobj()));
+ }
- /// @copydoc puglShowWindow
- Status showWindow() { return static_cast<Status>(puglShowWindow(cobj())); }
+ /// @copydoc puglShow
+ Status show() noexcept
+ {
+ return static_cast<Status>(puglShow(cobj()));
+ }
- /// @copydoc puglHideWindow
- Status hideWindow() { return static_cast<Status>(puglHideWindow(cobj())); }
+ /// @copydoc puglHide
+ Status hide() noexcept
+ {
+ return static_cast<Status>(puglHide(cobj()));
+ }
/// @copydoc puglGetVisible
- bool visible() const { return puglGetVisible(cobj()); }
+ bool visible() const noexcept { return puglGetVisible(cobj()); }
/// @copydoc puglGetNativeWindow
- NativeView nativeWindow() { return puglGetNativeWindow(cobj()); }
+ NativeView nativeWindow() noexcept { return puglGetNativeWindow(cobj()); }
/**
@}
@@ -508,16 +547,16 @@ public:
*/
/// @copydoc puglGetContext
- void* context() { return puglGetContext(cobj()); }
+ void* context() noexcept { return puglGetContext(cobj()); }
/// @copydoc puglPostRedisplay
- Status postRedisplay()
+ Status postRedisplay() noexcept
{
return static_cast<Status>(puglPostRedisplay(cobj()));
}
/// @copydoc puglPostRedisplayRect
- Status postRedisplayRect(const Rect rect)
+ Status postRedisplayRect(const Rect rect) noexcept
{
return static_cast<Status>(puglPostRedisplayRect(cobj(), rect));
}
@@ -530,158 +569,133 @@ public:
*/
/// @copydoc puglGrabFocus
- Status grabFocus() { return static_cast<Status>(puglGrabFocus(cobj())); }
-
- /// @copydoc puglHasFocus
- bool hasFocus() const { return puglHasFocus(cobj()); }
-
- /// @copydoc puglSetBackend
- Status setBackend(const PuglBackend* backend)
+ Status grabFocus() noexcept
{
- return static_cast<Status>(puglSetBackend(cobj(), backend));
+ return static_cast<Status>(puglGrabFocus(cobj()));
}
+ /// @copydoc puglHasFocus
+ bool hasFocus() const noexcept { return puglHasFocus(cobj()); }
+
/// @copydoc puglSetCursor
- Status setCursor(const Cursor cursor)
+ Status setCursor(const Cursor cursor) noexcept
{
return static_cast<Status>(
puglSetCursor(cobj(), static_cast<PuglCursor>(cursor)));
}
/// @copydoc puglRequestAttention
- Status requestAttention()
+ Status requestAttention() noexcept
{
return static_cast<Status>(puglRequestAttention(cobj()));
}
- /**
- @}
- @name Event Handlers
- Methods called when events are dispatched to the view.
- @{
- */
+ /// @copydoc puglStartTimer
+ Status startTimer(const uintptr_t id, const double timeout) noexcept
+ {
+ return static_cast<Status>(puglStartTimer(cobj(), id, timeout));
+ }
- virtual Status onCreate(const CreateEvent&) PUGL_CONST_FUNC;
- virtual Status onDestroy(const DestroyEvent&) PUGL_CONST_FUNC;
- virtual Status onConfigure(const ConfigureEvent&) PUGL_CONST_FUNC;
- virtual Status onMap(const MapEvent&) PUGL_CONST_FUNC;
- virtual Status onUnmap(const UnmapEvent&) PUGL_CONST_FUNC;
- virtual Status onUpdate(const UpdateEvent&) PUGL_CONST_FUNC;
- virtual Status onExpose(const ExposeEvent&) PUGL_CONST_FUNC;
- virtual Status onClose(const CloseEvent&) PUGL_CONST_FUNC;
- virtual Status onFocusIn(const FocusInEvent&) PUGL_CONST_FUNC;
- virtual Status onFocusOut(const FocusOutEvent&) PUGL_CONST_FUNC;
- virtual Status onKeyPress(const KeyPressEvent&) PUGL_CONST_FUNC;
- virtual Status onKeyRelease(const KeyReleaseEvent&) PUGL_CONST_FUNC;
- virtual Status onText(const TextEvent&) PUGL_CONST_FUNC;
- virtual Status onPointerIn(const PointerInEvent&) PUGL_CONST_FUNC;
- virtual Status onPointerOut(const PointerOutEvent&) PUGL_CONST_FUNC;
- virtual Status onButtonPress(const ButtonPressEvent&) PUGL_CONST_FUNC;
- virtual Status onButtonRelease(const ButtonReleaseEvent&) PUGL_CONST_FUNC;
- virtual Status onMotion(const MotionEvent&) PUGL_CONST_FUNC;
- virtual Status onScroll(const ScrollEvent&) PUGL_CONST_FUNC;
- virtual Status onClient(const ClientEvent&) PUGL_CONST_FUNC;
- virtual Status onTimer(const TimerEvent&) PUGL_CONST_FUNC;
+ /// @copydoc puglStopTimer
+ Status stopTimer(const uintptr_t id) noexcept
+ {
+ return static_cast<Status>(puglStopTimer(cobj(), id));
+ }
/**
@}
*/
- PuglView* cobj() { return Wrapper::cobj(); }
- const PuglView* cobj() const { return Wrapper::cobj(); }
+ PuglView* cobj() noexcept { return Wrapper::cobj(); }
+ const PuglView* cobj() const noexcept { return Wrapper::cobj(); }
private:
- template<class Typed, class Base>
- static const Typed& typedEventRef(const Base& base)
- {
- const auto& event = static_cast<const Typed&>(base);
- static_assert(sizeof(event) == sizeof(typename Typed::BaseEvent), "");
- static_assert(std::is_standard_layout<Typed>::value, "");
- assert(event.type == Typed::type);
- return event;
- }
-
- static PuglStatus dispatchEvent(PuglView* view, const PuglEvent* event) noexcept {
- try {
- View* self = static_cast<View*>(puglGetHandle(view));
-
- return self->dispatch(event);
- } catch (...) {
- return PUGL_UNKNOWN_ERROR;
- }
- }
-
- PuglStatus dispatch(const PuglEvent* event)
+ template<class Target>
+ static Status dispatch(Target& target, const PuglEvent* event)
{
switch (event->type) {
case PUGL_NOTHING:
- return PUGL_SUCCESS;
+ return Status::success;
case PUGL_CREATE:
- return static_cast<PuglStatus>(
- onCreate(typedEventRef<CreateEvent>(event->any)));
+ return target.onEvent(static_cast<const CreateEvent&>(event->any));
case PUGL_DESTROY:
- return static_cast<PuglStatus>(
- onDestroy(typedEventRef<DestroyEvent>(event->any)));
+ return target.onEvent(static_cast<const DestroyEvent&>(event->any));
case PUGL_CONFIGURE:
- return static_cast<PuglStatus>(onConfigure(
- typedEventRef<ConfigureEvent>(event->configure)));
+ return target.onEvent(
+ static_cast<const ConfigureEvent&>(event->configure));
case PUGL_MAP:
- return static_cast<PuglStatus>(
- onMap(typedEventRef<MapEvent>(event->any)));
+ return target.onEvent(static_cast<const MapEvent&>(event->any));
case PUGL_UNMAP:
- return static_cast<PuglStatus>(
- onUnmap(typedEventRef<UnmapEvent>(event->any)));
+ return target.onEvent(static_cast<const UnmapEvent&>(event->any));
case PUGL_UPDATE:
- return static_cast<PuglStatus>(
- onUpdate(typedEventRef<UpdateEvent>(event->any)));
+ return target.onEvent(static_cast<const UpdateEvent&>(event->any));
case PUGL_EXPOSE:
- return static_cast<PuglStatus>(
- onExpose(typedEventRef<ExposeEvent>(event->expose)));
+ return target.onEvent(
+ static_cast<const ExposeEvent&>(event->expose));
case PUGL_CLOSE:
- return static_cast<PuglStatus>(
- onClose(typedEventRef<CloseEvent>(event->any)));
+ return target.onEvent(static_cast<const CloseEvent&>(event->any));
case PUGL_FOCUS_IN:
- return static_cast<PuglStatus>(
- onFocusIn(typedEventRef<FocusInEvent>(event->focus)));
+ return target.onEvent(
+ static_cast<const FocusInEvent&>(event->focus));
case PUGL_FOCUS_OUT:
- return static_cast<PuglStatus>(
- onFocusOut(typedEventRef<FocusOutEvent>(event->focus)));
+ return target.onEvent(
+ static_cast<const FocusOutEvent&>(event->focus));
case PUGL_KEY_PRESS:
- return static_cast<PuglStatus>(
- onKeyPress(typedEventRef<KeyPressEvent>(event->key)));
+ return target.onEvent(
+ static_cast<const KeyPressEvent&>(event->key));
case PUGL_KEY_RELEASE:
- return static_cast<PuglStatus>(
- onKeyRelease(typedEventRef<KeyReleaseEvent>(event->key)));
+ return target.onEvent(
+ static_cast<const KeyReleaseEvent&>(event->key));
case PUGL_TEXT:
- return static_cast<PuglStatus>(
- onText(typedEventRef<TextEvent>(event->text)));
+ return target.onEvent(static_cast<const TextEvent&>(event->text));
case PUGL_POINTER_IN:
- return static_cast<PuglStatus>(onPointerIn(
- typedEventRef<PointerInEvent>(event->crossing)));
+ return target.onEvent(
+ static_cast<const PointerInEvent&>(event->crossing));
case PUGL_POINTER_OUT:
- return static_cast<PuglStatus>(onPointerOut(
- typedEventRef<PointerOutEvent>(event->crossing)));
+ return target.onEvent(
+ static_cast<const PointerOutEvent&>(event->crossing));
case PUGL_BUTTON_PRESS:
- return static_cast<PuglStatus>(onButtonPress(
- typedEventRef<ButtonPressEvent>(event->button)));
+ return target.onEvent(
+ static_cast<const ButtonPressEvent&>(event->button));
case PUGL_BUTTON_RELEASE:
- return static_cast<PuglStatus>(onButtonRelease(
- typedEventRef<ButtonReleaseEvent>(event->button)));
+ return target.onEvent(
+ static_cast<const ButtonReleaseEvent&>(event->button));
case PUGL_MOTION:
- return static_cast<PuglStatus>(
- onMotion(typedEventRef<MotionEvent>(event->motion)));
+ return target.onEvent(
+ static_cast<const MotionEvent&>(event->motion));
case PUGL_SCROLL:
- return static_cast<PuglStatus>(
- onScroll(typedEventRef<ScrollEvent>(event->scroll)));
+ return target.onEvent(
+ static_cast<const ScrollEvent&>(event->scroll));
case PUGL_CLIENT:
- return static_cast<PuglStatus>(
- onClient(typedEventRef<ClientEvent>(event->client)));
+ return target.onEvent(
+ static_cast<const ClientEvent&>(event->client));
case PUGL_TIMER:
- return static_cast<PuglStatus>(
- onTimer(typedEventRef<TimerEvent>(event->timer)));
+ return target.onEvent(static_cast<const TimerEvent&>(event->timer));
+ case PUGL_LOOP_ENTER:
+ return target.onEvent(
+ static_cast<const LoopEnterEvent&>(event->any));
+ case PUGL_LOOP_LEAVE:
+ return target.onEvent(
+ static_cast<const LoopLeaveEvent&>(event->any));
}
- return PUGL_FAILURE;
+ return Status::failure;
+ }
+
+ template<class Target>
+ static PuglStatus eventFunc(PuglView* view, const PuglEvent* event) noexcept
+ {
+ auto* target = static_cast<Target*>(puglGetHandle(view));
+
+#ifdef __cpp_exceptions
+ try {
+ return static_cast<PuglStatus>(dispatch(*target, event));
+ } catch (...) {
+ return PUGL_UNKNOWN_ERROR;
+ }
+#else
+ return static_cast<PuglStatus>(pugl::dispatch(*target, event));
+#endif
}
World& _world;
@@ -689,12 +703,9 @@ private:
/**
@}
+ @}
*/
} // namespace pugl
-/**
- @}
-*/
-
-#endif /* PUGL_PUGL_HPP */
+#endif // PUGL_PUGL_HPP
diff --git a/subprojects/d2tk/pugl/pugl/pugl_stub.hpp b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/stub.hpp
index c5f3901..8b37da4 100644
--- a/subprojects/d2tk/pugl/pugl/pugl_stub.hpp
+++ b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/stub.hpp
@@ -14,16 +14,11 @@
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
+#ifndef PUGL_STUB_HPP
+#define PUGL_STUB_HPP
#include "pugl/pugl.h"
-#include "pugl/pugl_stub.h"
+#include "pugl/stub.h"
namespace pugl {
@@ -35,8 +30,8 @@ namespace pugl {
*/
/// @copydoc puglStubBackend
-static inline const PuglBackend*
-stubBackend()
+inline const PuglBackend*
+stubBackend() noexcept
{
return puglStubBackend();
}
@@ -47,4 +42,4 @@ stubBackend()
} // namespace pugl
-#endif // PUGL_PUGL_STUB_HPP
+#endif // PUGL_STUB_HPP
diff --git a/subprojects/d2tk/pugl/bindings/cxx/include/pugl/vulkan.hpp b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/vulkan.hpp
new file mode 100644
index 0000000..65d1e57
--- /dev/null
+++ b/subprojects/d2tk/pugl/bindings/cxx/include/pugl/vulkan.hpp
@@ -0,0 +1,168 @@
+/*
+ Copyright 2012-2020 David Robillard <http://drobilla.net>
+
+ 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.
+*/
+
+/*
+ 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 <vulkan/vulkan_core.h>
+
+#include <cstdint>
+
+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 VulkanLoader final
+ : public detail::Wrapper<PuglVulkanLoader, puglFreeVulkanLoader>
+{
+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 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(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
+ View& view,
+ VkInstance instance,
+ const VkAllocationCallbacks* const allocator,
+ VkSurfaceKHR* const surface) noexcept
+{
+ const VkResult r = puglCreateSurface(
+ vkGetInstanceProcAddr, view.cobj(), instance, allocator, surface);
+
+ return (!r && !surface) ? VK_ERROR_INITIALIZATION_FAILED : r;
+}
+
+/// @copydoc puglVulkanBackend
+inline const PuglBackend*
+vulkanBackend() noexcept
+{
+ return puglVulkanBackend();
+}
+
+/**
+ @}
+*/
+
+} // namespace pugl
+
+#endif // PUGL_VULKAN_HPP
diff --git a/subprojects/d2tk/pugl/doc/_static/custom.css b/subprojects/d2tk/pugl/doc/_static/custom.css
new file mode 100644
index 0000000..60aa759
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/_static/custom.css
@@ -0,0 +1,95 @@
+div.document {
+ margin: 0;
+}
+
+div.body {
+ margin-top: 2em;
+}
+
+div.sphinxsidebarwrapper {
+ background: #EEE;
+}
+
+div.sphinxsidebarwrapper p.blurb {
+ text-align: center;
+}
+
+div.sphinxsidebarwrapper span.logo {
+ display: block;
+ text-align: center;
+ font-family: Georgia, serif;
+ padding: 0;
+ font-size: 180%;
+}
+
+div.sphinxsidebar a {
+ border-width: 0;
+}
+
+div.sphinxsidebar li {
+ color: #444;
+}
+
+div.section {
+ margin-top: 2.5em;
+}
+
+a.reference {
+ border-bottom: none;
+}
+
+code.xref {
+ font-weight: normal;
+ background-color: #F8F8F8;
+ padding: 0.1em 0 0.1em 0;
+}
+
+div.section > dl.c > dt:first-child,
+div.section > dl.cpp > dt:first-child {
+ background-color: #F8F8F8;
+ font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
+ font-size: 0.9em;
+ font-weight: normal;
+ margin-bottom: 0.5em;
+ padding: 0.1em 0 0.1em 0;
+}
+
+tt.descname, tt.descclassname, code.descname, code.descclassname {
+ font-size: 0.9em;
+}
+
+dl.member {
+ margin-top: 0.5em;
+}
+
+dl.enumerator {
+ margin-top: 0.5em;
+}
+
+dl.field-list > dt {
+ padding-left: 0;
+}
+
+pre, tt, code {
+ background-color: #F8F8F8;
+}
+
+.toctree-l1 {
+ margin-top: 1.0em;
+}
+
+img.logo {
+ width: 6em;
+}
+
+.class {
+ padding-top: 1.5em;
+}
+
+.exception {
+ padding-top: 1.5em;
+}
+
+.class > dd > dl.function {
+ padding-top: 1.0em;
+}
diff --git a/subprojects/d2tk/pugl/doc/_templates/about.html b/subprojects/d2tk/pugl/doc/_templates/about.html
new file mode 100644
index 0000000..5bbadbe
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/_templates/about.html
@@ -0,0 +1,57 @@
+{% if theme_logo %}
+<p class="logo">
+ <a href="{{ pathto(master_doc) }}">
+ <img class="logo" src="{{ pathto('_static/' ~ theme_logo, 1) }}" alt="Logo"/>
+ {% if theme_logo_name|lower == 'true' %}
+ <span class="logo logo-name">{{ project }}</span>
+ {% endif %}
+ </a>
+</p>
+{% else %}
+<h1 class="logo"><a href="{{ pathto(master_doc) }}">{{ project }}</a></h1>
+{% endif %}
+
+{% if theme_description %}
+<p class="blurb">{{ theme_description }}</p>
+{% endif %}
+
+{% if theme_github_user and theme_github_repo %}
+{% if theme_github_button|lower == 'true' %}
+<p>
+<iframe src="https://ghbtns.com/github-btn.html?user={{ theme_github_user }}&repo={{ theme_github_repo }}&type={{ theme_github_type }}&count={{ theme_github_count }}&size=large&v=2"
+ allowtransparency="true" frameborder="0" scrolling="0" width="200px" height="35px"></iframe>
+</p>
+{% endif %}
+{% endif %}
+
+{% if theme_travis_button|lower != 'false' %}
+{% if theme_travis_button|lower == 'true' %}
+ {% set path = theme_github_user + '/' + theme_github_repo %}
+{% else %}
+ {% set path = theme_travis_button %}
+{% endif %}
+<p>
+<a class="badge" href="https://travis-ci.org/{{ path }}">
+ <img
+ alt="https://secure.travis-ci.org/{{ path }}.svg?branch={{ theme_badge_branch }}"
+ src="https://secure.travis-ci.org/{{ path }}.svg?branch={{ theme_badge_branch }}"
+ />
+</a>
+</p>
+{% endif %}
+
+{% if theme_codecov_button|lower != 'false' %}
+{% if theme_codecov_button|lower == 'true' %}
+ {% set path = theme_github_user + '/' + theme_github_repo %}
+{% else %}
+ {% set path = theme_codecov_button %}
+{% endif %}
+<p>
+<a class="badge" href="https://codecov.io/github/{{ path }}">
+ <img
+ alt="https://codecov.io/github/{{ path }}/coverage.svg?branch={{ theme_badge_branch }}"
+ src="https://codecov.io/github/{{ path }}/coverage.svg?branch={{ theme_badge_branch }}"
+ />
+</a>
+</p>
+{% endif %}
diff --git a/subprojects/d2tk/pugl/doc/c/Doxyfile b/subprojects/d2tk/pugl/doc/c/Doxyfile
new file mode 100644
index 0000000..fe56f0b
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/c/Doxyfile
@@ -0,0 +1,30 @@
+PROJECT_NAME = Pugl
+PROJECT_BRIEF = "A minimal portable API for embeddable GUIs"
+
+QUIET = YES
+WARN_AS_ERROR = NO
+WARN_IF_UNDOCUMENTED = NO
+WARN_NO_PARAMDOC = NO
+
+JAVADOC_AUTOBRIEF = YES
+
+CASE_SENSE_NAMES = YES
+HIDE_IN_BODY_DOCS = YES
+REFERENCES_LINK_SOURCE = NO
+
+GENERATE_HTML = NO
+GENERATE_LATEX = NO
+GENERATE_XML = YES
+XML_PROGRAMLISTING = NO
+SHOW_FILES = NO
+
+MACRO_EXPANSION = YES
+PREDEFINED = PUGL_API PUGL_DISABLE_DEPRECATED PUGL_CONST_FUNC=
+
+INPUT = ../../include/pugl/cairo.h \
+ ../../include/pugl/gl.h \
+ ../../include/pugl/pugl.h \
+ ../../include/pugl/stub.h \
+ ../../include/pugl/vulkan.h
+
+OUTPUT_DIRECTORY = .
diff --git a/subprojects/d2tk/pugl/doc/c/index.rst b/subprojects/d2tk/pugl/doc/c/index.rst
new file mode 100644
index 0000000..6f046de
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/c/index.rst
@@ -0,0 +1,6 @@
+.. toctree::
+
+ pugl
+ deployment
+ overview
+ reference
diff --git a/subprojects/d2tk/pugl/doc/c/overview.rst b/subprojects/d2tk/pugl/doc/c/overview.rst
new file mode 100644
index 0000000..3ebe21e
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/c/overview.rst
@@ -0,0 +1,579 @@
+.. default-domain:: c
+.. highlight:: c
+
+The core API (excluding backend-specific components) is declared in ``pugl.h``:
+
+.. code-block:: c
+
+ #include <pugl/pugl.h>
+
+The API revolves around two main objects: the `world` and the `view`.
+An application creates a world to manage top-level state,
+then creates one or more views to display.
+
+****************
+Creating a World
+****************
+
+The world is the top-level object which represents an instance of Pugl.
+It handles the connection to the window system,
+and manages views and the event loop.
+
+An application typically has a single world,
+which is constructed once on startup and used to drive the main event loop.
+
+Construction
+============
+
+A world must be created before any views, and it must outlive all of its views.
+A world is created with :func:`puglNewWorld`, for example:
+
+.. code-block:: c
+
+ PuglWorld* world = puglNewWorld(PUGL_PROGRAM, 0);
+
+For a plugin, specify :enumerator:`PUGL_MODULE <PuglWorldType.PUGL_MODULE>` instead.
+In some cases, it is necessary to pass additional flags.
+For example, Vulkan requires thread support:
+
+.. code-block:: c
+
+ PuglWorld* world = puglNewWorld(PUGL_MODULE, PUGL_WORLD_THREADS)
+
+It is a good idea to set a class name for your project with :func:`puglSetClassName`.
+This allows the window system to distinguish different applications and,
+for example, users to set up rules to manage their windows nicely:
+
+.. code-block:: c
+
+ puglSetClassName(world, "MyAwesomeProject")
+
+Setting Application Data
+========================
+
+Pugl will call an event handler in the application with only a view pointer and an event,
+so there needs to be some way to access the data you use in your application.
+This is done by setting an opaque handle on the world with :func:`puglSetWorldHandle`,
+for example:
+
+.. code-block:: c
+
+ puglSetWorldHandle(world, myApp);
+
+The handle can be later retrieved with :func:`puglGetWorldHandle`:
+
+.. code-block:: c
+
+ MyApp* app = (MyApp*)puglGetWorldHandle(world);
+
+All non-constant data should be accessed via this handle,
+to avoid problems associated with static mutable data.
+
+***************
+Creating a View
+***************
+
+A view is a drawable region that receives events.
+You may think of it as a window,
+though it may be embedded and not represent a top-level system window. [#f1]_
+
+Creating a visible view is a multi-step process.
+When a new view is created with :func:`puglNewView`,
+it does not yet represent a "real" system view:
+
+.. code-block:: c
+
+ PuglView* view = puglNewView(world);
+
+Configuring the Frame
+=====================
+
+Before display,
+the necessary :doc:`frame <api/frame>` and :doc:`window <api/window>` attributes should be set.
+These allow the window system (or plugin host) to arrange the view properly.
+For example:
+
+.. code-block:: c
+
+ const double defaultWidth = 1920.0;
+ const double defaultHeight = 1080.0;
+
+ puglSetWindowTitle(view, "My Window");
+ puglSetDefaultSize(view, defaultWidth, defaultHeight);
+ puglSetMinSize(view, defaultWidth / 4.0, defaultHeight / 4.0);
+ puglSetAspectRatio(view, 1, 1, 16, 9);
+
+There are also several :enum:`hints <PuglViewHint>` for basic attributes that can be set:
+
+.. code-block:: c
+
+ puglSetViewHint(view, PUGL_RESIZABLE, PUGL_TRUE);
+ puglSetViewHint(view, PUGL_IGNORE_KEY_REPEAT, PUGL_TRUE);
+
+Embedding
+=========
+
+To embed the view in another window,
+you will need to somehow get the :type:`native view handle <PuglNativeView>` for the parent,
+then set it with :func:`puglSetParentWindow`.
+If the parent is a Pugl view,
+the native handle can be accessed with :func:`puglGetNativeWindow`.
+For example:
+
+.. code-block:: c
+
+ puglSetParentWindow(view, puglGetNativeWindow(parent));
+
+Setting an Event Handler
+========================
+
+In order to actually do anything, a view must process events from the system.
+Pugl dispatches all events to a single :type:`event handling function <PuglEventFunc>`,
+which is set with :func:`puglSetEventFunc`:
+
+.. code-block:: c
+
+ puglSetEventFunc(view, onEvent);
+
+See `Handling Events`_ below for details on writing the event handler itself.
+
+Setting View Data
+=================
+
+Since the event handler is called with only a view pointer and an event,
+there needs to be some way to access application data associated with the view.
+Similar to `Setting Application Data`_ above,
+this is done by setting an opaque handle on the view with :func:`puglSetHandle`,
+for example:
+
+.. code-block:: c
+
+ puglSetHandle(view, myViewData);
+
+The handle can be later retrieved,
+likely in the event handler,
+with :func:`puglGetHandle`:
+
+.. code-block:: c
+
+ MyViewData* data = (MyViewData*)puglGetHandle(view);
+
+All non-constant data should be accessed via this handle,
+to avoid problems associated with static mutable data.
+
+If data is also associated with the world,
+it can be retrieved via the view using :func:`puglGetWorld`:
+
+.. code-block:: c
+
+ PuglWorld* world = puglGetWorld(view);
+ MyApp* app = (MyApp*)puglGetWorldHandle(world);
+
+Setting a Backend
+=================
+
+Before being realized, the view must have a backend set with :func:`puglSetBackend`.
+
+The backend manages the graphics API that will be used for drawing.
+Pugl includes backends and supporting API for
+:doc:`Cairo <api/cairo>`, :doc:`OpenGL <api/gl>`, and :doc:`Vulkan <api/vulkan>`.
+
+Using Cairo
+-----------
+
+Cairo-specific API is declared in the ``cairo.h`` header:
+
+.. code-block:: c
+
+ #include <pugl/cairo.h>
+
+The Cairo backend is provided by :func:`puglCairoBackend()`:
+
+.. code-block:: c
+
+ puglSetBackend(view, puglCairoBackend());
+
+No additional configuration is required for Cairo.
+To draw when handling an expose event,
+the `Cairo context <https://www.cairographics.org/manual/cairo-cairo-t.html>`_ can be accessed with :func:`puglGetContext`:
+
+.. code-block:: c
+
+ cairo_t* cr = (cairo_t*)puglGetContext(view);
+
+Using OpenGL
+------------
+
+OpenGL-specific API is declared in the ``gl.h`` header:
+
+.. code-block:: c
+
+ #include <pugl/gl.h>
+
+The OpenGL backend is provided by :func:`puglGlBackend()`:
+
+.. code-block:: c
+
+ puglSetBackend(view, puglGlBackend());
+
+Some hints must also be set so that the context can be set up correctly.
+For example, to use OpenGL 3.3 Core Profile:
+
+.. code-block:: c
+
+ puglSetViewHint(view, PUGL_USE_COMPAT_PROFILE, PUGL_FALSE);
+ puglSetViewHint(view, PUGL_CONTEXT_VERSION_MAJOR, 3);
+ puglSetViewHint(view, PUGL_CONTEXT_VERSION_MINOR, 3);
+
+If you need to perform some setup using the OpenGL API,
+there are two ways to do so.
+
+The OpenGL context is active when
+:enumerator:`PUGL_CREATE <PuglEventType.PUGL_CREATE>` and
+:enumerator:`PUGL_DESTROY <PuglEventType.PUGL_DESTROY>`
+events are dispatched,
+so things like creating and destroying shaders and textures can be done then.
+
+Alternatively, if it is cumbersome to set up and tear down OpenGL in the event handler,
+:func:`puglEnterContext` and :func:`puglLeaveContext` can be used to manually activate the OpenGL context during application setup.
+Note, however, that unlike many other APIs, these functions must not be used for drawing.
+It is only valid to use the OpenGL API for configuration in a manually entered context,
+rendering will not work.
+For example:
+
+.. code-block:: c
+
+ puglEnterContext(view);
+ setupOpenGL(myApp);
+ puglLeaveContext(view);
+
+ while (!myApp->quit) {
+ puglUpdate(world, 0.0);
+ }
+
+ puglEnterContext(view);
+ teardownOpenGL(myApp);
+ puglLeaveContext(view);
+
+Using Vulkan
+------------
+
+Vulkan-specific API is declared in the ``vulkan.h`` header.
+This header includes Vulkan headers,
+so if you are dynamically loading Vulkan at runtime,
+you should define ``VK_NO_PROTOTYPES`` before including it.
+
+.. code-block:: c
+
+ #define VK_NO_PROTOTYPES
+
+ #include <pugl/vulkan.h>
+
+The Vulkan backend is provided by :func:`puglVulkanBackend()`:
+
+.. code-block:: c
+
+ puglSetBackend(view, puglVulkanBackend());
+
+Unlike OpenGL, almost all Vulkan configuration is done using the Vulkan API directly.
+Pugl only provides a portable mechanism to load the Vulkan library and get the functions used to load the rest of the Vulkan API.
+
+Loading Vulkan
+^^^^^^^^^^^^^^
+
+For maximum compatibility,
+it is best to not link to Vulkan at compile-time,
+but instead load the Vulkan API at run-time.
+To do so, first create a :struct:`PuglVulkanLoader`:
+
+.. code-block:: c
+
+ PuglVulkanLoader* loader = puglNewVulkanLoader(world);
+
+The loader manages the dynamically loaded Vulkan library,
+so it must be kept alive for as long as the application is using Vulkan.
+You can get the function used to load Vulkan functions with :func:`puglGetInstanceProcAddrFunc`:
+
+.. code-block:: c
+
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
+ puglGetInstanceProcAddrFunc(loader);
+
+This vkGetInstanceProcAddr_ function can be used to load the rest of the Vulkan API.
+For example, you can use it to get the vkCreateInstance_ function,
+then use that to create your Vulkan instance.
+In practice, you will want to use some loader or wrapper API since there are many Vulkan functions.
+
+For advanced situations,
+there is also :func:`puglGetDeviceProcAddrFunc` which retrieves the vkGetDeviceProcAddr_ function instead.
+
+The Vulkan loader is provided for convenience,
+so that applications to not need to write platform-specific code to load Vulkan.
+Its use it not mandatory and Pugl can be used with Vulkan loaded by some other method.
+
+Linking with Vulkan
+^^^^^^^^^^^^^^^^^^^
+
+If you do want to link to the Vulkan library at compile time,
+note that the Pugl Vulkan backend does not depend on it,
+so you will have to do so explicitly.
+
+Creating a Surface
+^^^^^^^^^^^^^^^^^^
+
+The details of using Vulkan are far beyond the scope of this documentation,
+but Pugl provides a portable function, :func:`puglCreateSurface`,
+to get the Vulkan surface for a view.
+Assuming you have somehow created your ``VkInstance``,
+you can get the surface for a view using :func:`puglCreateSurface`:
+
+.. code-block:: c
+
+ VkSurfaceKHR* surface = NULL;
+ puglCreateSurface(puglGetDeviceProcAddrFunc(loader),
+ view,
+ vulkanInstance,
+ NULL,
+ &surface);
+
+Showing the View
+================
+
+Once the view is configured, it can be "realized" with :func:`puglRealize`.
+This creates a "real" system view, for example:
+
+.. code-block:: c
+
+ PuglStatus status = puglRealize(view);
+ if (status) {
+ fprintf(stderr, "Error realizing view (%s)\n", puglStrerror(status));
+ }
+
+Note that realizing a view can fail for many reasons,
+so the return code should always be checked.
+This is generally the case for any function that interacts with the window system.
+Most functions also return a :enum:`PuglStatus`,
+but these checks are omitted for brevity in the rest of this documentation.
+
+A realized view is not initially visible,
+but can be shown with :func:`puglShow`:
+
+.. code-block:: c
+
+ puglShow(view);
+
+To create an initially visible view,
+it is also possible to simply call :func:`puglShow` right away.
+The view will be automatically realized if necessary.
+
+***************
+Handling Events
+***************
+
+Events are sent to a view when it has received user input,
+must be drawn, or in other situations that may need to be handled such as resizing.
+
+Events are sent to the event handler as a :union:`PuglEvent` union.
+The ``type`` field defines the type of the event and which field of the union is active.
+The application must handle at least :enumerator:`PUGL_CONFIGURE <PuglEventType.PUGL_CONFIGURE>`
+and :enumerator:`PUGL_EXPOSE <PuglEventType.PUGL_EXPOSE>` to draw anything,
+but there are many other :enum:`event types <PuglEventType>`.
+
+For example, a basic event handler might look something like this:
+
+.. code-block:: c
+
+ static PuglStatus
+ onEvent(PuglView* view, const PuglEvent* event)
+ {
+ MyApp* app = (MyApp*)puglGetHandle(view);
+
+ switch (event->type) {
+ case PUGL_CREATE:
+ return setupGraphics(app);
+ case PUGL_DESTROY:
+ return teardownGraphics(app);
+ case PUGL_CONFIGURE:
+ return resize(app, event->configure.width, event->configure.height);
+ case PUGL_EXPOSE:
+ return draw(app, view);
+ case PUGL_CLOSE:
+ return quit(app);
+ case PUGL_BUTTON_PRESS:
+ return onButtonPress(app, view, event->button);
+ default:
+ break;
+ }
+
+ return PUGL_SUCCESS;
+ }
+
+Using the Graphics Context
+==========================
+
+Drawing
+-------
+
+Note that Pugl uses a different drawing model than many libraries,
+particularly those designed for game-style main loops like `SDL <https://libsdl.org/>`_ and `GLFW <https://www.glfw.org/>`_.
+
+In that style of code, drawing is performed imperatively in the main loop,
+but with Pugl, the application must draw only while handling an expose event.
+This is because Pugl supports event-driven applications that only draw the damaged region when necessary,
+and handles exposure internally to provide optimized and consistent behavior across platforms.
+
+Cairo Context
+-------------
+
+A Cairo context is created for each :struct:`PuglEventExpose`,
+and only exists during the handling of that event.
+Null is returned by :func:`puglGetContext` at any other time.
+
+OpenGL Context
+--------------
+
+The OpenGL context is only active during the handling of these events:
+
+- :struct:`PuglEventCreate`
+- :struct:`PuglEventDestroy`
+- :struct:`PuglEventConfigure`
+- :struct:`PuglEventExpose`
+
+As always, drawing is only possible during an expose.
+
+Vulkan Context
+--------------
+
+With Vulkan, the graphics context is managed by the application rather than Pugl.
+However, drawing must still only be performed during an expose.
+
+**********************
+Driving the Event Loop
+**********************
+
+Pugl does not contain any threads or other event loop "magic".
+For flexibility, the event loop is driven explicitly by repeatedly calling :func:`puglUpdate`,
+which processes events from the window system and dispatches them to views when necessary.
+
+The exact use of :func:`puglUpdate` depends on the application.
+Plugins should call it with a ``timeout`` of 0 in a callback driven by the host.
+This avoids blocking the main loop,
+since other plugins and the host itself need to run as well.
+
+A program can use whatever timeout is appropriate:
+event-driven applications may wait forever by using a ``timeout`` of -1,
+while those that draw continuously may use a significant fraction of the frame period
+(with enough time left over to render).
+
+Redrawing
+=========
+
+Occasional redrawing can be requested by calling :func:`puglPostRedisplay` or :func:`puglPostRedisplayRect`.
+After these are called,
+a :struct:`PuglEventExpose` will be dispatched on the next call to :func:`puglUpdate`.
+
+For continuous redrawing,
+call :func:`puglPostRedisplay` while handling a :struct:`PuglEventUpdate` event.
+This event is sent just before views are redrawn,
+so it can be used as a hook to expand the update region right before the view is exposed.
+Anything else that needs to be done every frame can be handled similarly.
+
+Event Dispatching
+=================
+
+Ideally, pending events are dispatched during a call to :func:`puglUpdate`,
+directly within the scope of that call.
+
+Unfortunately, this is not universally true due to differences between platforms.
+
+MacOS
+-----
+
+On MacOS, drawing is handled specially and not by the normal event queue mechanism.
+This means that configure and expose events,
+and possibly others,
+may be dispatched to a view outside the scope of a :func:`puglUpdate` call.
+In general, you can not rely on coherent event dispatching semantics on MacOS:
+the operating system can call into application code at "random" times,
+and these calls may result in Pugl events being dispatched.
+
+An application that follows the Pugl guidelines should work fine,
+but there is one significant inconsistency you may encounter on MacOS:
+posting a redisplay will not wake up a blocked :func:`puglUpdate` call.
+
+Windows
+-------
+
+On Windows, the application has relatively tight control over the event loop,
+so events are typically dispatched explicitly by :func:`puglUpdate`.
+Drawing is handled by events,
+so posting a redisplay will wake up a blocked :func:`puglUpdate` call.
+
+However, it is possible for the system to dispatch events at other times.
+So,
+it is possible for events to be dispatched outside the scope of a :func:`puglUpdate` call,
+but this does not happen in normal circumstances and can largely be ignored.
+
+X11
+---
+
+On X11, the application strictly controls event dispatching,
+and there is no way for the system to call into application code at surprising times.
+So, all events are dispatched in the scope of a :func:`puglUpdate` call.
+
+Recursive Event Loops
+---------------------
+
+On Windows and MacOS,
+the event loop is stalled while the user is resizing the window or,
+on Windows,
+has displayed the window menu.
+This means that :func:`puglUpdate` will block until the resize is finished,
+or the menu is closed.
+
+Pugl dispatches :struct:`PuglEventLoopEnter` and :struct:`PuglEventLoopLeave` events to notify the application of this situation.
+If you want to continuously redraw during resizing on these platforms,
+you can schedule a timer with :func:`puglStartTimer` when the recursive loop is entered,
+and post redisplays when handling the :struct:`PuglEventTimer`.
+Be sure to remove the timer with :func:`puglStopTimer` when the recursive loop is finished.
+
+On X11, there are no recursive event loops,
+and everything works as usual while the user is resizing the window.
+There is nothing special about a "live resize" on X11,
+and the above loop events will never be dispatched.
+
+*************
+Shutting Down
+*************
+
+When a view is closed,
+it will receive a :struct:`PuglEventClose`.
+An application may also set a flag based on user input or other conditions,
+which can be used to break out of the main loop and stop calling :func:`puglUpdate`.
+
+When the main event loop has finished running,
+any views and the world need to be destroyed, in that order.
+For example:
+
+.. code-block:: c
+
+ puglFreeView(view);
+ puglFreeWorld(world);
+
+.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
+
+.. _vkCreateInstance: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateInstance.html
+
+.. _vkGetDeviceProcAddr: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceProcAddr.html
+
+.. _vkGetInstanceProcAddr: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetInstanceProcAddr.html
+
+.. rubric:: Footnotes
+
+.. [#f1] MacOS has a strong distinction between
+ `views <https://developer.apple.com/documentation/appkit/nsview>`_,
+ which may be nested, and
+ `windows <https://developer.apple.com/documentation/appkit/nswindow>`_,
+ which may not.
+ On Windows and X11, everything is a nestable window,
+ but top-level windows are configured differently.
diff --git a/subprojects/d2tk/pugl/doc/c/reference.rst b/subprojects/d2tk/pugl/doc/c/reference.rst
new file mode 100644
index 0000000..21a187f
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/c/reference.rst
@@ -0,0 +1,18 @@
+#############
+API Reference
+#############
+
+This section contains the generated documentation for all symbols in the public
+API.
+
+.. toctree::
+
+ api/status
+ api/world
+ api/view
+ api/events
+
+ api/cairo
+ api/gl
+ api/stub
+ api/vulkan
diff --git a/subprojects/d2tk/pugl/doc/c/wscript b/subprojects/d2tk/pugl/doc/c/wscript
new file mode 100644
index 0000000..4e0fbc9
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/c/wscript
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+def build(bld):
+ dox_to_sphinx = bld.path.find_node("../../scripts/dox_to_sphinx.py")
+ index_xml = bld.path.get_bld().make_node("xml/index.xml")
+
+ files = [
+ ("../../resources/pugl.svg", "sphinx/_static/pugl.svg"),
+ ("../_static/custom.css", "sphinx/_static/custom.css"),
+ ("../_templates/about.html", "sphinx/_templates/about.html"),
+ ("../deployment.rst", "sphinx/deployment.rst"),
+ ("../pugl.rst", "sphinx/pugl.rst"),
+ ("index.rst", "sphinx/index.rst"),
+ ("overview.rst", "sphinx/overview.rst"),
+ ("reference.rst", "sphinx/reference.rst"),
+ ]
+
+ # Run Doxygen to generate XML documentation
+ bld(features="doxygen", doxyfile="Doxyfile")
+
+ # Substitute variables to make Sphinx configuration file
+ bld(features="subst",
+ source="../conf.py.in",
+ target="sphinx/conf.py",
+ PUGL_VERSION=bld.env.PUGL_VERSION)
+
+ # Copy static documentation files to Sphinx build directory
+ for f in files:
+ bld(features="subst", is_copy=True, source=f[0], target=f[1])
+
+ # Generate Sphinx markup from Doxygen XML
+ bld.add_group()
+ bld(rule="${PYTHON} " + dox_to_sphinx.abspath() + " -f ${SRC} ${TGT}",
+ source=index_xml,
+ target="sphinx/api/")
+
+ # Run Sphinx to generate HTML documentation
+ doc_dir = bld.env.DOCDIR + "/pugl-%s/" % bld.env.PUGL_MAJOR_VERSION
+ bld(features="sphinx",
+ sphinx_source=bld.path.get_bld().make_node("sphinx"),
+ sphinx_output_format="singlehtml",
+ sphinx_options=["-E", "-q"],
+ install_path=doc_dir + "c/singlehtml/")
diff --git a/subprojects/d2tk/pugl/doc/conf.py.in b/subprojects/d2tk/pugl/doc/conf.py.in
new file mode 100644
index 0000000..9ca7bfa
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/conf.py.in
@@ -0,0 +1,88 @@
+# Project information
+
+project = "Pugl"
+copyright = "2020, David Robillard"
+author = "David Robillard"
+release = "@PUGL_VERSION@"
+
+# General configuration
+
+language = "en"
+
+extensions = [
+ # 'breathe',
+ # 'sphinx_rtd_theme',
+ # 'sphinx.ext.autodoc',
+ # 'sphinx.ext.doctest',
+ # 'sphinx.ext.napoleon',
+ # 'sphinx.ext.viewcode',
+]
+
+# Enable nitpicky mode to get warnings about broken links
+# Unfortunately this means we need to explicitly ignore everything external
+nitpicky = True
+_opaque = [
+ "PFN_vkGetDeviceProcAddr",
+ "PFN_vkGetInstanceProcAddr",
+ "PuglBackendImpl",
+ "PuglViewImpl",
+ "PuglVulkanLoaderImpl",
+ "PuglWorldImpl",
+ "VkAllocationCallbacks",
+ "VkInstance",
+ "VkResult",
+ "VkSurfaceKHR",
+ "size_t",
+ "uint32_t",
+ "uintptr_t",
+]
+_c_nitpick_ignore = map(lambda x: ("c:identifier", x), _opaque)
+_cpp_nitpick_ignore = map(lambda x: ("cpp:identifier", x), _opaque)
+nitpick_ignore = list(_c_nitpick_ignore) + list(_cpp_nitpick_ignore)
+
+templates_path = ["_templates"]
+
+pygments_style = "friendly"
+
+# C++
+
+cpp_index_common_prefix = ["pugl::"]
+
+# HTML output
+
+exclude_patterns = ["xml"]
+html_static_path = ["_static"]
+
+html_theme = "alabaster"
+# html_theme = "sphinx_rtd_theme"
+
+if html_theme == "alabaster":
+
+ html_theme_options = {
+ "description": "A minimal portable API for embeddable GUIs.",
+ "donate_url": "http://drobilla.net/pages/donate.html",
+ # "github_repo": "pugl",
+ # "github_user": "lv2",
+ "logo": "pugl.svg",
+ "logo_name": True,
+ "logo_text_align": "center",
+ "page_width": "80em - 20em",
+ "sidebar_width": "20em",
+ }
+
+ html_sidebars = {
+ "**": [
+ "about.html",
+ "localtoc.html",
+ "donate.html",
+ ]
+ }
+
+elif html_theme == "sphinx_rtd_theme":
+
+ html_theme_options = {
+ "sticky_navigation": False,
+ "collapse_navigation": False,
+ "navigation_depth": 4,
+ "display_version": True,
+ }
diff --git a/subprojects/d2tk/pugl/doc/cpp/Doxyfile b/subprojects/d2tk/pugl/doc/cpp/Doxyfile
new file mode 100644
index 0000000..2bb0f9f
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/Doxyfile
@@ -0,0 +1,40 @@
+PROJECT_NAME = Pugl
+PROJECT_BRIEF = "A minimal portable API for embeddable GUIs"
+
+QUIET = YES
+WARN_AS_ERROR = NO
+WARN_IF_UNDOCUMENTED = NO
+WARN_NO_PARAMDOC = NO
+
+JAVADOC_AUTOBRIEF = YES
+
+CASE_SENSE_NAMES = YES
+EXCLUDE_SYMBOLS = pugl::detail
+EXTRACT_LOCAL_CLASSES = NO
+EXTRACT_PRIVATE = NO
+HIDE_IN_BODY_DOCS = YES
+HIDE_UNDOC_CLASSES = YES
+HIDE_UNDOC_MEMBERS = YES
+REFERENCES_LINK_SOURCE = NO
+
+GENERATE_HTML = NO
+GENERATE_LATEX = NO
+GENERATE_XML = YES
+XML_PROGRAMLISTING = NO
+SHOW_FILES = NO
+
+MACRO_EXPANSION = YES
+PREDEFINED = PUGL_API PUGL_DISABLE_DEPRECATED PUGL_CONST_FUNC=
+
+INPUT = ../../include/pugl/cairo.h \
+ ../../include/pugl/gl.h \
+ ../../include/pugl/pugl.h \
+ ../../include/pugl/stub.h \
+ ../../include/pugl/vulkan.h \
+ ../../bindings/cxx/include/pugl/cairo.hpp \
+ ../../bindings/cxx/include/pugl/gl.hpp \
+ ../../bindings/cxx/include/pugl/pugl.hpp \
+ ../../bindings/cxx/include/pugl/stub.hpp \
+ ../../bindings/cxx/include/pugl/vulkan.hpp
+
+OUTPUT_DIRECTORY = .
diff --git a/subprojects/d2tk/pugl/doc/cpp/c-reference.rst b/subprojects/d2tk/pugl/doc/cpp/c-reference.rst
new file mode 100644
index 0000000..546e4d3
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/c-reference.rst
@@ -0,0 +1,20 @@
+###############
+C API Reference
+###############
+
+This section contains the generated documentation for all symbols in the public
+C API.
+It is included here because some C++ wrapper definitions refer to the underlying C symbols,
+but direct use of the C API should not be necessary in C++ applications.
+
+.. toctree::
+
+ api/status
+ api/world
+ api/view
+ api/events
+
+ api/cairo
+ api/gl
+ api/stub
+ api/vulkan
diff --git a/subprojects/d2tk/pugl/doc/cpp/cpp-reference.rst b/subprojects/d2tk/pugl/doc/cpp/cpp-reference.rst
new file mode 100644
index 0000000..96c523c
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/cpp-reference.rst
@@ -0,0 +1,18 @@
+#################
+C++ API Reference
+#################
+
+This section contains the generated documentation for all symbols in the public
+C++ API.
+
+.. toctree::
+
+ api/statusxx
+ api/worldxx
+ api/viewxx
+ api/eventsxx
+
+ api/cairoxx
+ api/glxx
+ api/stubxx
+ api/vulkanxx
diff --git a/subprojects/d2tk/pugl/doc/cpp/index.rst b/subprojects/d2tk/pugl/doc/cpp/index.rst
new file mode 100644
index 0000000..c3d330e
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/index.rst
@@ -0,0 +1,7 @@
+.. toctree::
+
+ pugl
+ deployment
+ overview
+ cpp-reference
+ c-reference
diff --git a/subprojects/d2tk/pugl/doc/cpp/overview.rst b/subprojects/d2tk/pugl/doc/cpp/overview.rst
new file mode 100644
index 0000000..5fffe37
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/overview.rst
@@ -0,0 +1,423 @@
+.. default-domain:: cpp
+.. highlight:: cpp
+.. namespace:: pugl
+
+Pugl is a C library,
+but the bindings documented here provide a more idiomatic and type-safe API for C++.
+If you would rather use C,
+refer instead to the `C API documentation <../../c/singlehtml/index.html>`_.
+
+The C++ bindings are very lightweight and do not require virtual functions,
+RTTI,
+exceptions,
+or linking to the C++ standard library.
+They are provided by the package ``puglxx-0`` which must be used in addition to the desired platform+backend package above.
+
+The core API (excluding backend-specific components) is declared in ``pugl.hpp``:
+
+.. code-block:: cpp
+
+ #include <pugl/pugl.hpp>
+
+The API revolves around two main objects: the `world` and the `view`.
+An application creates a world to manage top-level state,
+then creates one or more views to display.
+
+Creating a World
+================
+
+The world is the top-level object which represents an instance of Pugl.
+It handles the connection to the window system,
+and manages views and the event loop.
+
+An application typically has a single world,
+which is constructed once on startup and used to drive the main event loop.
+
+Construction
+------------
+
+A world must be created before any views, and it must outlive all of its views.
+The world constructor requires an argument to specify the application type:
+
+.. code-block:: cpp
+
+ pugl::World world{pugl::WorldType::program};
+
+For a plugin, specify :enumerator:`WorldType::module` instead.
+In some cases, it is necessary to pass additional flags.
+For example, Vulkan requires thread support:
+
+.. code-block:: cpp
+
+ pugl::World world{pugl::WorldType::program, pugl::WorldFlag::threads};
+
+It is a good idea to set a class name for your project with :func:`World::setClassName`.
+This allows the window system to distinguish different applications and,
+for example, users to set up rules to manage their windows nicely:
+
+.. code-block:: cpp
+
+ world.setClassName("MyAwesomeProject");
+
+Creating a View
+===============
+
+A `view` is a drawable region that receives events.
+You may think of it as a window,
+though it may be embedded and not represent a top-level system window. [#f1]_
+
+Pugl communicates with views by dispatching events.
+For flexibility, the event handler can be a different object than the view.
+This allows using :class:`View` along with a separate event handler class.
+Alternatively, a view class can inherit from :class:`View` and set itself as its event handler,
+for a more object-oriented style.
+
+This documentation will use the latter approach,
+so we will define a class for our view that contains everything needed:
+
+.. code-block:: cpp
+
+ class MyView : public pugl::View
+ {
+ public:
+ explicit MyView(pugl::World& world)
+ : pugl::View{world}
+ {
+ setEventHandler(*this);
+ }
+
+ pugl::Status onEvent(const pugl::ConfigureEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::ExposeEvent& event) noexcept;
+
+ // With other handlers here as needed...
+
+ // Fallback handler for all other events
+ template<PuglEventType t, class Base>
+ pugl::Status onEvent(const pugl::Event<t, Base>&) noexcept
+ {
+ return pugl::Status::success;
+ }
+
+ private:
+ // Some data...
+ };
+
+Pugl will call an ``onEvent`` method of the event handler (the view in this case) for every event.
+
+Note that Pugl uses a static dispatching mechanism rather than virtual functions to minimize overhead.
+It is therefore necessary for the final class to define a handler for every event type.
+A terse way to do this without writing every implementation is to define a fallback handler as a template,
+as in the example above.
+Alternatively, you can define an explicit handler for each event that simply returns :enumerator:`Status::success`.
+This way, it will be a compile error if any event is not explicitly handled.
+
+Configuring the Frame
+---------------------
+
+Before display,
+the necessary :doc:`frame <api/frame>` and :doc:`window <api/window>` attributes should be set.
+These allow the window system (or plugin host) to arrange the view properly.
+
+Derived classes can configure themselves during construction,
+but we assume here that configuration is being done outside the view.
+For example:
+
+.. code-block:: cpp
+
+ const double defaultWidth = 1920.0;
+ const double defaultHeight = 1080.0;
+
+ view.setWindowTitle("My Window");
+ view.setDefaultSize(defaultWidth, defaultHeight);
+ view.setMinSize(defaultWidth / 4.0, defaultHeight / 4.0);
+ view.setAspectRatio(1, 1, 16, 9);
+
+There are also several :type:`hints <PuglViewHint>` for basic attributes that can be set:
+
+.. code-block:: cpp
+
+ view.setHint(pugl::ViewHint::resizable, true);
+ view.setHint(pugl::ViewHint::ignoreKeyRepeat, true);
+
+Embedding
+---------
+
+To embed the view in another window,
+you will need to somehow get the :type:`native view handle <pugl::NativeView>` for the parent,
+then set it with :func:`View::setParentWindow`.
+If the parent is a Pugl view,
+the native handle can be accessed with :func:`View::nativeWindow`.
+For example:
+
+.. code-block:: cpp
+
+ view.setParentWindow(view, parent.getNativeWindow());
+
+Setting a Backend
+-----------------
+
+Before being realized, the view must have a backend set with :func:`View::setBackend`.
+
+The backend manages the graphics API that will be used for drawing.
+Pugl includes backends and supporting API for
+:doc:`Cairo <api/cairo>`, :doc:`OpenGL <api/gl>`, and :doc:`Vulkan <api/vulkan>`.
+
+Using Cairo
+^^^^^^^^^^^
+
+Cairo-specific API is declared in the ``cairo.hpp`` header:
+
+.. code-block:: cpp
+
+ #include <pugl/cairo.hpp>
+
+The Cairo backend is provided by :func:`cairoBackend()`:
+
+.. code-block:: cpp
+
+ view.setBackend(pugl::cairoBackend());
+
+No additional configuration is required for Cairo.
+To draw when handling an expose event,
+the `Cairo context <https://www.cairographics.org/manual/cairo-cairo-t.html>`_ can be accessed with :func:`View::context`:
+
+.. code-block:: cpp
+
+ cairo_t* cr = static_cast<cairo_t*>(view.context());
+
+Using OpenGL
+^^^^^^^^^^^^
+
+OpenGL-specific API is declared in the ``gl.hpp`` header:
+
+.. code-block:: cpp
+
+ #include <pugl/gl.hpp>
+
+The OpenGL backend is provided by :func:`glBackend()`:
+
+.. code-block:: cpp
+
+ view.setBackend(pugl::glBackend());
+
+Some hints must also be set so that the context can be set up correctly.
+For example, to use OpenGL 3.3 Core Profile:
+
+.. code-block:: cpp
+
+ view.setHint(pugl::ViewHint::useCompatProfile, false);
+ view.setHint(pugl::ViewHint::contextVersionMajor, 3);
+ view.setHint(pugl::ViewHint::contextVersionMinor, 3);
+
+If you need to perform some setup using the OpenGL API,
+there are two ways to do so.
+
+The OpenGL context is active when
+:type:`CreateEvent` and
+:type:`DestroyEvent`
+events are dispatched,
+so things like creating and destroying shaders and textures can be done then.
+
+Alternatively, if it is cumbersome to set up and tear down OpenGL in the event handler,
+:func:`enterContext` and :func:`leaveContext` can be used to manually activate the OpenGL context during application setup.
+Note, however, that unlike many other APIs, these functions must not be used for drawing.
+It is only valid to use the OpenGL API for configuration in a manually entered context,
+rendering will not work.
+For example:
+
+.. code-block:: cpp
+
+ pugl::enterContext(view);
+ myApp.setupOpenGL();
+ pugl::leaveContext(view);
+
+ while (!myApp.quit()) {
+ world.update(0.0);
+ }
+
+ pugl::enterContext(view);
+ myApp.teardownOpenGL();
+ pugl::leaveContext(view);
+
+Using Vulkan
+^^^^^^^^^^^^
+
+Vulkan-specific API is declared in the ``vulkan.hpp`` header.
+This header includes Vulkan headers,
+so if you are dynamically loading Vulkan at runtime,
+you should define ``VK_NO_PROTOTYPES`` before including it.
+
+.. code-block:: cpp
+
+ #define VK_NO_PROTOTYPES
+
+ #include <pugl/vulkan.hpp>
+
+The Vulkan backend is provided by :func:`vulkanBackend()`:
+
+.. code-block:: cpp
+
+ view.setBackend(pugl::vulkanBackend());
+
+Unlike OpenGL, almost all Vulkan configuration is done using the Vulkan API directly.
+Pugl only provides a portable mechanism to load the Vulkan library and get the functions used to load the rest of the Vulkan API.
+
+Loading Vulkan
+^^^^^^^^^^^^^^
+
+For maximum compatibility,
+it is best to not link to Vulkan at compile-time,
+but instead load the Vulkan API at run-time.
+To do so, first create a :class:`VulkanLoader`:
+
+.. code-block:: cpp
+
+ pugl::VulkanLoader loader{world};
+
+The loader manages the dynamically loaded Vulkan library,
+so it must be kept alive for as long as the application is using Vulkan.
+You can get the function used to load Vulkan functions with :func:`VulkanLoader::getInstanceProcAddrFunc`:
+
+.. code-block:: cpp
+
+ auto vkGetInstanceProcAddr = loader.getInstanceProcAddrFunc();
+
+It is best to use this function to load everything at run time,
+rather than link to the Vulkan library at run time.
+You can, for example, pass this to get the ``vkCreateInstance`` function using this,
+then use that to create your Vulkan instance.
+In practice, you will want to use some loader or wrapper API since there are many Vulkan functions.
+
+It is not necessary to use :class:`VulkanLoader`,
+you can, for example, use the ``DynamicLoader`` from ``vulkan.hpp`` in the Vulkan SDK instead.
+
+The details of using Vulkan are far beyond the scope of this documentation,
+but Pugl provides a portable function, :func:`createSurface`,
+to get the Vulkan surface for a view.
+Assuming you have somehow created your ``VkInstance``,
+you can get the surface for a view using :func:`createSurface`:
+
+.. code-block:: cpp
+
+ VkSurfaceKHR* surface = nullptr;
+ puglCreateSurface(loader.getDeviceProcAddrFunc(),
+ view,
+ vulkanInstance,
+ nullptr,
+ &surface);
+
+Pugl does not provide API that uses ``vulkan.hpp`` to avoid the onerous dependency,
+but if you are using it with exceptions and unique handles,
+it is straightforward to wrap the surface handle yourself.
+
+Showing the View
+----------------
+
+Once the view is configured, it can be "realized" with :func:`View::realize`.
+This creates a "real" system view, for example:
+
+.. code-block:: cpp
+
+ pugl::Status status = view.realize();
+ if (status != pugl::Status::success) {
+ std::cerr << "Error realizing view: " << pugl::strerror(status) << "\n";
+ }
+
+Note that realizing a view can fail for many reasons,
+so the return code should always be checked.
+This is generally the case for any function that interacts with the window system.
+Most functions also return a :enum:`Status`,
+but these checks are omitted for brevity in the rest of this documentation.
+
+A realized view is not initially visible,
+but can be shown with :func:`View::show`:
+
+.. code-block:: cpp
+
+ view.show();
+
+To create an initially visible view,
+it is also possible to simply call :func:`View::show()` right away.
+The view will be automatically realized if necessary.
+
+Handling Events
+===============
+
+Events are sent to a view when it has received user input,
+must be drawn, or in other situations that may need to be handled such as resizing.
+
+Events are sent to the ``onEvent`` method that takes the matching event type.
+The application must handle at least :type:`ConfigureEvent`
+and :type:`ExposeEvent` to draw anything,
+but there are many other :type:`event types <pugl::EventType>`.
+
+For example, basic event handling for our above class might look something like:
+
+.. code-block:: cpp
+
+ pugl::Status
+ MyView::onEvent(const pugl::ConfigureEvent& event) noexcept
+ {
+ return resize(event.width, event.height);
+ }
+
+ pugl::Status
+ MyView::onEvent(const pugl::ExposeEvent& event) noexcept
+ {
+ return drawMyAwesomeInterface(event.x, event.y, event.width, event.height);
+ }
+
+Drawing
+-------
+
+Note that Pugl uses a different drawing model than many libraries,
+particularly those designed for game-style main loops like `SDL <https://libsdl.org/>`_ and `GLFW <https://www.glfw.org/>`_.
+
+In that style of code, drawing is performed imperatively in the main loop,
+but with Pugl, the application must draw only while handling an expose event.
+This is because Pugl supports event-driven applications that only draw the damaged region when necessary,
+and handles exposure internally to provide optimized and consistent behavior across platforms.
+
+Driving the Event Loop
+======================
+
+Pugl does not contain any threads or other event loop "magic".
+For flexibility, the event loop is driven manually by repeatedly calling :func:`World::update`,
+which processes events from the window system and dispatches them to views when necessary.
+
+The exact use of :func:`World::update` depends on the application.
+Plugins typically call it with a ``timeout`` of 0 in a callback driven by the host.
+This avoids blocking the main loop,
+since other plugins and the host itself need to run as well.
+
+A program can use whatever timeout is appropriate:
+event-driven applications may wait forever by using a ``timeout`` of -1,
+while those that draw continuously may use a significant fraction of the frame period
+(with enough time left over to render).
+
+Redrawing
+---------
+
+Occasional redrawing can be requested by calling :func:`View::postRedisplay` or :func:`View::postRedisplayRect`.
+After these are called,
+a :type:`ExposeEvent` will be dispatched on the next call to :func:`World::update`.
+Note, however, that this will not wake up a blocked :func:`World::update` call on MacOS
+(which does not handle drawing via events).
+
+For continuous redrawing,
+call :func:`View::postRedisplay` while handling a :type:`UpdateEvent`.
+This event is sent just before views are redrawn,
+so it can be used as a hook to expand the update region right before the view is exposed.
+Anything else that needs to be done every frame can be handled similarly.
+
+.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
+
+.. rubric:: Footnotes
+
+.. [#f1] MacOS has a strong distinction between
+ `views <https://developer.apple.com/documentation/appkit/nsview>`_,
+ which may be nested, and
+ `windows <https://developer.apple.com/documentation/appkit/nswindow>`_,
+ which may not.
+ On Windows and X11, everything is a nestable window,
+ but top-level windows are configured differently.
diff --git a/subprojects/d2tk/pugl/doc/cpp/wscript b/subprojects/d2tk/pugl/doc/cpp/wscript
new file mode 100644
index 0000000..a7aefc1
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/wscript
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+def build(bld):
+ dox_to_sphinx = bld.path.find_node("../../scripts/dox_to_sphinx.py")
+ index_xml = bld.path.get_bld().make_node("xml/index.xml")
+
+ files = [
+ ("../../resources/pugl.svg", "sphinx/_static/pugl.svg"),
+ ("../_static/custom.css", "sphinx/_static/custom.css"),
+ ("../_templates/about.html", "sphinx/_templates/about.html"),
+ ("../deployment.rst", "sphinx/deployment.rst"),
+ ("../pugl.rst", "sphinx/pugl.rst"),
+ ("c-reference.rst", "sphinx/c-reference.rst"),
+ ("cpp-reference.rst", "sphinx/cpp-reference.rst"),
+ ("index.rst", "sphinx/index.rst"),
+ ("overview.rst", "sphinx/overview.rst"),
+ ]
+
+ # Run Doxygen to generate XML documentation
+ bld(features="doxygen", doxyfile="Doxyfile")
+
+ # Substitute variables to make Sphinx configuration file
+ bld(features="subst",
+ source="../conf.py.in",
+ target="sphinx/conf.py",
+ PUGL_VERSION=bld.env.PUGL_VERSION)
+
+ # Copy static documentation files to Sphinx build directory
+ for f in files:
+ bld(features="subst", is_copy=True, source=f[0], target=f[1])
+
+ # Generate Sphinx markup from Doxygen XML
+ bld.add_group()
+ bld(rule="${PYTHON} " + dox_to_sphinx.abspath() + " -l cpp -f ${SRC} ${TGT}",
+ source=index_xml,
+ target="sphinx/api/")
+
+ # Run Sphinx to generate HTML documentation
+ doc_dir = bld.env.DOCDIR + "/pugl-%s/" % bld.env.PUGL_MAJOR_VERSION
+ bld(features="sphinx",
+ sphinx_source=bld.path.get_bld().make_node("sphinx"),
+ sphinx_output_format="singlehtml",
+ sphinx_options=["-E", "-q"],
+ install_path=doc_dir + "cpp/singlehtml/")
diff --git a/subprojects/d2tk/pugl/doc/deployment.rst b/subprojects/d2tk/pugl/doc/deployment.rst
new file mode 100644
index 0000000..ffbeae9
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/deployment.rst
@@ -0,0 +1,23 @@
+##########
+Using Pugl
+##########
+
+Pugl is designed for flexible deployment,
+so the exact method of building against it depends on your approach.
+
+When targeting systems with pkg-config_,
+packages are provided that link against the core platform library and the desired backend,
+along with any backend dependencies:
+
+- ``pugl-cairo-0``
+- ``pugl-gl-0``
+- ``pugl-vulkan-0``
+
+Depending on one of these packages should be all that is necessary to use Pugl,
+but details on the individual libraries that are installed are available in the README.
+
+If you are instead including the source directly in your project,
+the structure is quite simple and hopefully obvious.
+It is only necessary to copy the platform and backend implementations that you need.
+
+.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
diff --git a/subprojects/d2tk/pugl/doc/footer.html b/subprojects/d2tk/pugl/doc/footer.html
deleted file mode 100644
index 0dc6919..0000000
--- a/subprojects/d2tk/pugl/doc/footer.html
+++ /dev/null
@@ -1,20 +0,0 @@
-<!-- HTML footer for doxygen 1.8.15-->
-<!-- start footer part -->
-<!--BEGIN GENERATE_TREEVIEW-->
-<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
- <ul>
- $navpath
- <li class="footer">$generatedby
- <a href="http://www.doxygen.org/index.html">Doxygen $doxygenversion</li>
- </ul>
-</div>
-<!--END GENERATE_TREEVIEW-->
-<!--BEGIN !GENERATE_TREEVIEW-->
-<div id="footer">
- <address class="footer">$generatedby
- <a href="http://www.doxygen.org/">Doxygen</a> $doxygenversion
- </address>
-</div>
-<!--END !GENERATE_TREEVIEW-->
-</body>
-</html>
diff --git a/subprojects/d2tk/pugl/doc/header.html b/subprojects/d2tk/pugl/doc/header.html
deleted file mode 100644
index 54c25b0..0000000
--- a/subprojects/d2tk/pugl/doc/header.html
+++ /dev/null
@@ -1,49 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
- <!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
- <link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
- $extrastylesheet
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
-
- <!--BEGIN TITLEAREA-->
- <div id="titlearea">
- <div id="header">
- <div id="titlebox">
- <!--BEGIN PROJECT_LOGO-->
- <div id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></div>
- <!--END PROJECT_LOGO-->
- <!--BEGIN PROJECT_NAME-->
- <h1 id="title">$projectname</h1>
- <!--END PROJECT_NAME-->
- <!--BEGIN PROJECT_BRIEF-->
- <div id="shortdesc">$projectbrief</div>
- <!--END PROJECT_BRIEF-->
- </div>
- <div id="metabox">
- <table id="meta">
- <!--BEGIN PROJECT_NUMBER-->
- <tr><th>Version</th><td>$projectnumber</td></tr>
- <!--END PROJECT_NUMBER-->
- </table>
- </div>
- </div>
- </div>
- <!--END TITLEAREA-->
- <!-- end header part -->
-
- <!-- Fake static menu from Doxygen 1.8.15 -->
- <div id="staticnavrow" class="tabs">
- <ul class="tablist">
- <li><a href="index.html"><span>Main&#160;Page</span></a></li>
- <li><a href="modules.html"><span>Modules</span></a></li>
- <li><a href="namespaces.html"><span>Namespaces</span></a></li>
- <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
- <li><a href="functions.html"><span>Symbols</span></a></li>
- <li><a href="files.html"><span>Files</span></a></li>
- </ul>
- </div>
diff --git a/subprojects/d2tk/pugl/doc/layout.xml b/subprojects/d2tk/pugl/doc/layout.xml
deleted file mode 100644
index 2995c0e..0000000
--- a/subprojects/d2tk/pugl/doc/layout.xml
+++ /dev/null
@@ -1,194 +0,0 @@
-<doxygenlayout version="1.0">
- <!-- Generated by doxygen 1.8.13 -->
- <!-- Navigation index tabs for HTML output -->
- <navindex>
- <tab type="mainpage" visible="yes" title=""/>
- <tab type="pages" visible="yes" title="" intro=""/>
- <tab type="modules" visible="yes" title="" intro=""/>
- <tab type="namespaces" visible="yes" title="">
- <tab type="namespacelist" visible="yes" title="" intro=""/>
- <tab type="namespacemembers" visible="yes" title="" intro=""/>
- </tab>
- <tab type="classes" visible="yes" title="">
- <tab type="classlist" visible="yes" title="" intro=""/>
- <tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
- <tab type="hierarchy" visible="yes" title="" intro=""/>
- <tab type="classmembers" visible="yes" title="" intro=""/>
- </tab>
- <tab type="files" visible="yes" title="">
- <tab type="filelist" visible="yes" title="" intro=""/>
- <tab type="globals" visible="yes" title="" intro=""/>
- </tab>
- <tab type="examples" visible="yes" title="" intro=""/>
- </navindex>
-
- <!-- Layout definition for a class page -->
- <class>
- <briefdescription visible="yes"/>
- <detaileddescription title=""/>
- <includes visible="$SHOW_INCLUDE_FILES"/>
- <inheritancegraph visible="$CLASS_GRAPH"/>
- <collaborationgraph visible="$COLLABORATION_GRAPH"/>
- <memberdecl>
- <nestedclasses visible="yes" title=""/>
- <publictypes title=""/>
- <services title=""/>
- <interfaces title=""/>
- <publicslots title=""/>
- <signals title=""/>
- <publicmethods title=""/>
- <publicstaticmethods title=""/>
- <publicattributes title=""/>
- <publicstaticattributes title=""/>
- <protectedtypes title=""/>
- <protectedslots title=""/>
- <protectedmethods title=""/>
- <protectedstaticmethods title=""/>
- <protectedattributes title=""/>
- <protectedstaticattributes title=""/>
- <packagetypes title=""/>
- <packagemethods title=""/>
- <packagestaticmethods title=""/>
- <packageattributes title=""/>
- <packagestaticattributes title=""/>
- <properties title=""/>
- <events title=""/>
- <privatetypes title=""/>
- <privateslots title=""/>
- <privatemethods title=""/>
- <privatestaticmethods title=""/>
- <privateattributes title=""/>
- <privatestaticattributes title=""/>
- <friends title=""/>
- <related title="" subtitle=""/>
- <membergroups visible="yes"/>
- </memberdecl>
- <memberdef>
- <inlineclasses title=""/>
- <typedefs title=""/>
- <enums title=""/>
- <services title=""/>
- <interfaces title=""/>
- <constructors title=""/>
- <functions title=""/>
- <related title=""/>
- <variables title=""/>
- <properties title=""/>
- <events title=""/>
- </memberdef>
- <allmemberslink visible="yes"/>
- <usedfiles visible="$SHOW_USED_FILES"/>
- <authorsection visible="yes"/>
- </class>
-
- <!-- Layout definition for a namespace page -->
- <namespace>
- <briefdescription visible="yes"/>
- <detaileddescription title=""/>
- <memberdecl>
- <nestednamespaces visible="yes" title=""/>
- <constantgroups visible="yes" title=""/>
- <classes visible="yes" title=""/>
- <typedefs title=""/>
- <enums title=""/>
- <functions title=""/>
- <variables title=""/>
- <membergroups visible="yes"/>
- </memberdecl>
- <memberdef>
- <inlineclasses title=""/>
- <typedefs title=""/>
- <enums title=""/>
- <functions title=""/>
- <variables title=""/>
- </memberdef>
- <authorsection visible="yes"/>
- </namespace>
-
- <!-- Layout definition for a file page -->
- <file>
- <briefdescription visible="yes"/>
- <detaileddescription title=""/>
- <includes visible="$SHOW_INCLUDE_FILES"/>
- <includegraph visible="$INCLUDE_GRAPH"/>
- <includedbygraph visible="$INCLUDED_BY_GRAPH"/>
- <sourcelink visible="yes"/>
- <memberdecl>
- <classes visible="yes" title=""/>
- <namespaces visible="yes" title=""/>
- <constantgroups visible="yes" title=""/>
- <defines title=""/>
- <typedefs title=""/>
- <enums title=""/>
- <functions title=""/>
- <variables title=""/>
- <membergroups visible="yes"/>
- </memberdecl>
- <memberdef>
- <inlineclasses title=""/>
- <defines title=""/>
- <typedefs title=""/>
- <enums title=""/>
- <functions title=""/>
- <variables title=""/>
- </memberdef>
- <authorsection/>
- </file>
-
- <!-- Layout definition for a group page -->
- <group>
- <briefdescription visible="yes"/>
- <detaileddescription title=""/>
- <groupgraph visible="$GROUP_GRAPHS"/>
- <memberdecl>
- <nestedgroups visible="yes" title=""/>
- <dirs visible="yes" title=""/>
- <files visible="yes" title=""/>
- <namespaces visible="yes" title=""/>
- <classes visible="yes" title=""/>
- <defines title=""/>
- <typedefs title=""/>
- <enums title=""/>
- <enumvalues title=""/>
- <functions title=""/>
- <variables title=""/>
- <signals title=""/>
- <publicslots title=""/>
- <protectedslots title=""/>
- <privateslots title=""/>
- <events title=""/>
- <properties title=""/>
- <friends title=""/>
- <membergroups visible="yes"/>
- </memberdecl>
- <memberdef>
- <pagedocs/>
- <inlineclasses title=""/>
- <defines title=""/>
- <typedefs title=""/>
- <enums title=""/>
- <enumvalues title=""/>
- <functions title=""/>
- <variables title=""/>
- <signals title=""/>
- <publicslots title=""/>
- <protectedslots title=""/>
- <privateslots title=""/>
- <events title=""/>
- <properties title=""/>
- <friends title=""/>
- </memberdef>
- <authorsection visible="yes"/>
- </group>
-
- <!-- Layout definition for a directory page -->
- <directory>
- <briefdescription visible="yes"/>
- <directorygraph visible="yes"/>
- <memberdecl>
- <dirs visible="yes"/>
- <files visible="yes"/>
- </memberdecl>
- <detaileddescription title=""/>
- </directory>
-</doxygenlayout>
diff --git a/subprojects/d2tk/pugl/doc/mainpage.md b/subprojects/d2tk/pugl/doc/mainpage.md
index c04bf9e..92f7409 100644
--- a/subprojects/d2tk/pugl/doc/mainpage.md
+++ b/subprojects/d2tk/pugl/doc/mainpage.md
@@ -1,23 +1,29 @@
-This is the API documentation for Pugl.
-This page refers to the [C API](@ref pugl_c),
-there is also a [C++ API](@ref pugl_cxx) in the `pugl` namespace.
+This is the documentation for Pugl, a minimal API for writing GUIs.
-The Pugl API revolves around two main objects:
-the [World](@ref world) and the [View](@ref view).
+## Reference
+
+Pugl is implemented in C, but also provides a header-only C++ API wrapper.
+
+ * [C API reference](@ref pugl)
+ * [C++ API reference](@ref puglxx)
+
+## Overview
+
+The Pugl API revolves around two main objects: the World and the View.
An application creates a single world to manage top-level state,
then creates one or more views to display.
-## World
+### World
-The [World](@ref world) contains all top-level state,
+The [World](@ref PuglWorld) contains all top-level state,
and manages views and the event loop.
A world must be [created](@ref puglNewWorld) before any views,
and it must outlive all views.
-## View
+### View
-A [View](@ref view) is a drawable region that receives events.
+A [View](@ref PuglView) is a drawable region that receives events.
Creating a visible view is a multi-step process.
When a new view is [created](@ref puglNewView),
@@ -28,27 +34,25 @@ and be configured by [setting hints](@ref puglSetViewHint)
and optionally [adjusting the frame](@ref frame).
The [Backend](@ref PuglBackend) controls drawing for a view.
-Pugl includes [Cairo](@ref cairo) and [OpenGL](@ref gl) backends,
-as well as a [stub](@ref stub) backend that creates a native window with no drawing context.
-
+Pugl includes [Cairo](@ref cairo), [OpenGL](@ref gl), and [Vulkan](@ref vulkan) backends,
+as well as a [stub](@ref stub) backend that creates a native window with no portable drawing context.
Once the view is configured,
-it can be [realized](@ref puglRealize) and [shown](@ref puglShowWindow).
+it can be [realized](@ref puglRealize) and [shown](@ref puglShow).
By default a view will correspond to a top-level system window.
To create a view within another window,
it must have a [parent window set](@ref puglSetParentWindow) before being created.
+### Events
-## Events
-
-[Events](@ref events) are sent to a view when it has received user input or must be drawn.
+[Events](@ref PuglEvent) are sent to a view when it has received user input or must be drawn.
Events are handled by the [event handler](@ref PuglEventFunc) set during initialisation.
This function is called whenever something happens that the view must respond to.
This includes user interaction like mouse and keyboard input,
and system events like window resizing and exposure.
-## Event Loop
+### Event Loop
The event loop is driven by repeatedly calling #puglUpdate which processes events from the window system,
and dispatches them to views when necessary.
@@ -68,6 +72,6 @@ For continuous redrawing, call #puglPostRedisplay when a #PUGL_UPDATE event is r
This event is sent before views are redrawn,
so can be used as a hook to expand the update region right before the view is exposed.
-## Error Handling
+### Error Handling
-Most functions return a [Status](@ref status) which should be checked to detect failure.
+Most functions return a [Status](@ref PuglStatus) which should be checked to detect failure.
diff --git a/subprojects/d2tk/pugl/doc/pugl.rst b/subprojects/d2tk/pugl/doc/pugl.rst
new file mode 100644
index 0000000..c48021b
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/pugl.rst
@@ -0,0 +1,26 @@
+####
+Pugl
+####
+
+Pugl is an API for writing portable and embeddable GUIs.
+Pugl is not a toolkit or framework,
+but a minimal portability layer that sets up a drawing context and delivers events.
+
+Compared to other libraries,
+Pugl is particularly suitable for use in plugins or other loadable modules.
+There is no implicit context or static data in the library,
+so it may be statically linked and used multiple times in the same process.
+
+Pugl has a modular design that separates the core library from graphics backends.
+The core library is graphics agnostic,
+it implements platform support and depends only on standard system libraries.
+MacOS, Windows, and X11 are currently supported as platforms.
+
+Graphics backends are separate so that applications only depend on the API that they use.
+Pugl includes graphics backends for Cairo_, OpenGL_, and Vulkan_.
+It is also possible to use some other graphics API by implementing a custom backend,
+or simply accessing the native platform handle for a window.
+
+.. _Cairo: https://www.cairographics.org/
+.. _OpenGL: https://www.opengl.org/
+.. _Vulkan: https://www.khronos.org/vulkan/
diff --git a/subprojects/d2tk/pugl/doc/reference.doxygen.in b/subprojects/d2tk/pugl/doc/reference.doxygen.in
deleted file mode 100644
index 4e91ca2..0000000
--- a/subprojects/d2tk/pugl/doc/reference.doxygen.in
+++ /dev/null
@@ -1,2462 +0,0 @@
-# Doxyfile 1.8.15
-
-# This file describes the settings to be used by the documentation system
-# doxygen (www.doxygen.org) for a project.
-#
-# All text after a double hash (##) is considered a comment and is placed in
-# front of the TAG it is preceding.
-#
-# All text after a single hash (#) is considered a comment and will be ignored.
-# The format is:
-# TAG = value [value, ...]
-# For lists, items can also be appended using:
-# TAG += value [value, ...]
-# Values that contain spaces should be placed between quotes (\" \").
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-
-# This tag specifies the encoding used for all characters in the configuration
-# file that follow. The default is UTF-8 which is also the encoding used for all
-# text before the first occurrence of this tag. Doxygen uses libiconv (or the
-# iconv built into libc) for the transcoding. See
-# https://www.gnu.org/software/libiconv/ for the list of possible encodings.
-# The default value is: UTF-8.
-
-DOXYFILE_ENCODING = UTF-8
-
-# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
-# double-quotes, unless you are using Doxywizard) that should identify the
-# project for which the documentation is generated. This name is used in the
-# title of most generated pages and in a few other places.
-# The default value is: My Project.
-
-PROJECT_NAME = Pugl
-
-# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
-# could be handy for archiving the generated documentation or if some version
-# control system is used.
-
-PROJECT_NUMBER = @PUGL_VERSION@
-
-# Using the PROJECT_BRIEF tag one can provide an optional one line description
-# for a project that appears at the top of each page and should give viewer a
-# quick idea about the purpose of the project. Keep the description short.
-
-PROJECT_BRIEF = "A minimal portable API for embeddable GUIs"
-
-# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
-# in the documentation. The maximum height of the logo should not exceed 55
-# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
-# the logo to the output directory.
-
-PROJECT_LOGO =
-
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
-# into which the generated documentation will be written. If a relative path is
-# entered, it will be relative to the location where doxygen was started. If
-# left blank the current directory will be used.
-
-OUTPUT_DIRECTORY = .
-
-# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
-# directories (in 2 levels) under the output directory of each output format and
-# will distribute the generated files over these directories. Enabling this
-# option can be useful when feeding doxygen a huge amount of source files, where
-# putting all generated files in the same directory would otherwise causes
-# performance problems for the file system.
-# The default value is: NO.
-
-CREATE_SUBDIRS = NO
-
-# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
-# characters to appear in the names of generated files. If set to NO, non-ASCII
-# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
-# U+3044.
-# The default value is: NO.
-
-ALLOW_UNICODE_NAMES = NO
-
-# The OUTPUT_LANGUAGE tag is used to specify the language in which all
-# documentation generated by doxygen is written. Doxygen will use this
-# information to generate all constant output in the proper language.
-# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,
-# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),
-# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,
-# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),
-# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,
-# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,
-# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
-# Ukrainian and Vietnamese.
-# The default value is: English.
-
-OUTPUT_LANGUAGE = English
-
-# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all
-# documentation generated by doxygen is written. Doxygen will use this
-# information to generate all generated output in the proper direction.
-# Possible values are: None, LTR, RTL and Context.
-# The default value is: None.
-
-OUTPUT_TEXT_DIRECTION = None
-
-# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
-# descriptions after the members that are listed in the file and class
-# documentation (similar to Javadoc). Set to NO to disable this.
-# The default value is: YES.
-
-BRIEF_MEMBER_DESC = NO
-
-# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
-# description of a member or function before the detailed description
-#
-# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
-# brief descriptions will be completely suppressed.
-# The default value is: YES.
-
-REPEAT_BRIEF = YES
-
-# This tag implements a quasi-intelligent brief description abbreviator that is
-# used to form the text in various listings. Each string in this list, if found
-# as the leading text of the brief description, will be stripped from the text
-# and the result, after processing the whole list, is used as the annotated
-# text. Otherwise, the brief description is used as-is. If left blank, the
-# following values are used ($name is automatically replaced with the name of
-# the entity):The $name class, The $name widget, The $name file, is, provides,
-# specifies, contains, represents, a, an and the.
-
-ABBREVIATE_BRIEF =
-
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
-# doxygen will generate a detailed section even if there is only a brief
-# description.
-# The default value is: NO.
-
-ALWAYS_DETAILED_SEC = NO
-
-# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
-# inherited members of a class in the documentation of that class as if those
-# members were ordinary class members. Constructors, destructors and assignment
-# operators of the base classes will not be shown.
-# The default value is: NO.
-
-INLINE_INHERITED_MEMB = NO
-
-# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
-# before files name in the file list and in the header files. If set to NO the
-# shortest path that makes the file name unique will be used
-# The default value is: YES.
-
-FULL_PATH_NAMES = NO
-
-# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
-# Stripping is only done if one of the specified strings matches the left-hand
-# part of the path. The tag can be used to show relative paths in the file list.
-# If left blank the directory from which doxygen is run is used as the path to
-# strip.
-#
-# Note that you can specify absolute paths here, but also relative paths, which
-# will be relative from the directory where doxygen is started.
-# This tag requires that the tag FULL_PATH_NAMES is set to YES.
-
-STRIP_FROM_PATH =
-
-# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
-# path mentioned in the documentation of a class, which tells the reader which
-# header file to include in order to use a class. If left blank only the name of
-# the header file containing the class definition is used. Otherwise one should
-# specify the list of include paths that are normally passed to the compiler
-# using the -I flag.
-
-STRIP_FROM_INC_PATH =
-
-# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
-# less readable) file names. This can be useful is your file systems doesn't
-# support long names like on DOS, Mac, or CD-ROM.
-# The default value is: NO.
-
-SHORT_NAMES = NO
-
-# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
-# first line (until the first dot) of a Javadoc-style comment as the brief
-# description. If set to NO, the Javadoc-style will behave just like regular Qt-
-# style comments (thus requiring an explicit @brief command for a brief
-# description.)
-# The default value is: NO.
-
-JAVADOC_AUTOBRIEF = YES
-
-# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
-# line (until the first dot) of a Qt-style comment as the brief description. If
-# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
-# requiring an explicit \brief command for a brief description.)
-# The default value is: NO.
-
-QT_AUTOBRIEF = NO
-
-# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
-# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
-# a brief description. This used to be the default behavior. The new default is
-# to treat a multi-line C++ comment block as a detailed description. Set this
-# tag to YES if you prefer the old behavior instead.
-#
-# Note that setting this tag to YES also means that rational rose comments are
-# not recognized any more.
-# The default value is: NO.
-
-MULTILINE_CPP_IS_BRIEF = NO
-
-# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
-# documentation from any documented member that it re-implements.
-# The default value is: YES.
-
-INHERIT_DOCS = YES
-
-# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
-# page for each member. If set to NO, the documentation of a member will be part
-# of the file/class/namespace that contains it.
-# The default value is: NO.
-
-SEPARATE_MEMBER_PAGES = NO
-
-# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
-# uses this value to replace tabs by spaces in code fragments.
-# Minimum value: 1, maximum value: 16, default value: 4.
-
-TAB_SIZE = 4
-
-# This tag can be used to specify a number of aliases that act as commands in
-# the documentation. An alias has the form:
-# name=value
-# For example adding
-# "sideeffect=@par Side Effects:\n"
-# will allow you to put the command \sideeffect (or @sideeffect) in the
-# documentation, which will result in a user-defined paragraph with heading
-# "Side Effects:". You can put \n's in the value part of an alias to insert
-# newlines (in the resulting output). You can put ^^ in the value part of an
-# alias to insert a newline as if a physical newline was in the original file.
-# When you need a literal { or } or , in the value part of an alias you have to
-# escape them by means of a backslash (\), this can lead to conflicts with the
-# commands \{ and \} for these it is advised to use the version @{ and @} or use
-# a double escape (\\{ and \\})
-
-ALIASES =
-
-# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
-# only. Doxygen will then generate output that is more tailored for C. For
-# instance, some of the names that are used will be different. The list of all
-# members will be omitted, etc.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_FOR_C = YES
-
-# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
-# Python sources only. Doxygen will then generate output that is more tailored
-# for that language. For instance, namespaces will be presented as packages,
-# qualified scopes will look different, etc.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_JAVA = NO
-
-# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
-# sources. Doxygen will then generate output that is tailored for Fortran.
-# The default value is: NO.
-
-OPTIMIZE_FOR_FORTRAN = NO
-
-# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
-# sources. Doxygen will then generate output that is tailored for VHDL.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_VHDL = NO
-
-# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice
-# sources only. Doxygen will then generate output that is more tailored for that
-# language. For instance, namespaces will be presented as modules, types will be
-# separated into more groups, etc.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_SLICE = NO
-
-# Doxygen selects the parser to use depending on the extension of the files it
-# parses. With this tag you can assign which parser to use for a given
-# extension. Doxygen has a built-in mapping, but you can override or extend it
-# using this tag. The format is ext=language, where ext is a file extension, and
-# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
-# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice,
-# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:
-# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser
-# tries to guess whether the code is fixed or free formatted code, this is the
-# default for Fortran type files), VHDL, tcl. For instance to make doxygen treat
-# .inc files as Fortran files (default is PHP), and .f files as C (default is
-# Fortran), use: inc=Fortran f=C.
-#
-# Note: For files without extension you can use no_extension as a placeholder.
-#
-# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
-# the files are not read by doxygen.
-
-EXTENSION_MAPPING =
-
-# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
-# according to the Markdown format, which allows for more readable
-# documentation. See https://daringfireball.net/projects/markdown/ for details.
-# The output of markdown processing is further processed by doxygen, so you can
-# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
-# case of backward compatibilities issues.
-# The default value is: YES.
-
-MARKDOWN_SUPPORT = YES
-
-# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up
-# to that level are automatically included in the table of contents, even if
-# they do not have an id attribute.
-# Note: This feature currently applies only to Markdown headings.
-# Minimum value: 0, maximum value: 99, default value: 0.
-# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
-
-TOC_INCLUDE_HEADINGS = 0
-
-# When enabled doxygen tries to link words that correspond to documented
-# classes, or namespaces to their corresponding documentation. Such a link can
-# be prevented in individual cases by putting a % sign in front of the word or
-# globally by setting AUTOLINK_SUPPORT to NO.
-# The default value is: YES.
-
-AUTOLINK_SUPPORT = YES
-
-# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
-# to include (a tag file for) the STL sources as input, then you should set this
-# tag to YES in order to let doxygen match functions declarations and
-# definitions whose arguments contain STL classes (e.g. func(std::string);
-# versus func(std::string) {}). This also make the inheritance and collaboration
-# diagrams that involve STL classes more complete and accurate.
-# The default value is: NO.
-
-BUILTIN_STL_SUPPORT = NO
-
-# If you use Microsoft's C++/CLI language, you should set this option to YES to
-# enable parsing support.
-# The default value is: NO.
-
-CPP_CLI_SUPPORT = NO
-
-# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
-# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen
-# will parse them like normal C++ but will assume all classes use public instead
-# of private inheritance when no explicit protection keyword is present.
-# The default value is: NO.
-
-SIP_SUPPORT = NO
-
-# For Microsoft's IDL there are propget and propput attributes to indicate
-# getter and setter methods for a property. Setting this option to YES will make
-# doxygen to replace the get and set methods by a property in the documentation.
-# This will only work if the methods are indeed getting or setting a simple
-# type. If this is not the case, or you want to show the methods anyway, you
-# should set this option to NO.
-# The default value is: YES.
-
-IDL_PROPERTY_SUPPORT = YES
-
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES then doxygen will reuse the documentation of the first
-# member in the group (if any) for the other members of the group. By default
-# all members of a group must be documented explicitly.
-# The default value is: NO.
-
-DISTRIBUTE_GROUP_DOC = NO
-
-# If one adds a struct or class to a group and this option is enabled, then also
-# any nested class or struct is added to the same group. By default this option
-# is disabled and one has to add nested compounds explicitly via \ingroup.
-# The default value is: NO.
-
-GROUP_NESTED_COMPOUNDS = NO
-
-# Set the SUBGROUPING tag to YES to allow class member groups of the same type
-# (for instance a group of public functions) to be put as a subgroup of that
-# type (e.g. under the Public Functions section). Set it to NO to prevent
-# subgrouping. Alternatively, this can be done per class using the
-# \nosubgrouping command.
-# The default value is: YES.
-
-SUBGROUPING = YES
-
-# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
-# are shown inside the group in which they are included (e.g. using \ingroup)
-# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
-# and RTF).
-#
-# Note that this feature does not work in combination with
-# SEPARATE_MEMBER_PAGES.
-# The default value is: NO.
-
-INLINE_GROUPED_CLASSES = YES
-
-# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
-# with only public data fields or simple typedef fields will be shown inline in
-# the documentation of the scope in which they are defined (i.e. file,
-# namespace, or group documentation), provided this scope is documented. If set
-# to NO, structs, classes, and unions are shown on a separate page (for HTML and
-# Man pages) or section (for LaTeX and RTF).
-# The default value is: NO.
-
-INLINE_SIMPLE_STRUCTS = YES
-
-# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
-# enum is documented as struct, union, or enum with the name of the typedef. So
-# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
-# with name TypeT. When disabled the typedef will appear as a member of a file,
-# namespace, or class. And the struct will be named TypeS. This can typically be
-# useful for C code in case the coding convention dictates that all compound
-# types are typedef'ed and only the typedef is referenced, never the tag name.
-# The default value is: NO.
-
-TYPEDEF_HIDES_STRUCT = YES
-
-# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
-# cache is used to resolve symbols given their name and scope. Since this can be
-# an expensive process and often the same symbol appears multiple times in the
-# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
-# doxygen will become slower. If the cache is too large, memory is wasted. The
-# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
-# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
-# symbols. At the end of a run doxygen will report the cache usage and suggest
-# the optimal cache size from a speed point of view.
-# Minimum value: 0, maximum value: 9, default value: 0.
-
-LOOKUP_CACHE_SIZE = 0
-
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-
-# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
-# documentation are documented, even if no documentation was available. Private
-# class members and static file members will be hidden unless the
-# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
-# Note: This will also disable the warnings about undocumented members that are
-# normally produced when WARNINGS is set to YES.
-# The default value is: NO.
-
-EXTRACT_ALL = NO
-
-# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
-# be included in the documentation.
-# The default value is: NO.
-
-EXTRACT_PRIVATE = NO
-
-# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
-# scope will be included in the documentation.
-# The default value is: NO.
-
-EXTRACT_PACKAGE = NO
-
-# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
-# included in the documentation.
-# The default value is: NO.
-
-EXTRACT_STATIC = YES
-
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
-# locally in source files will be included in the documentation. If set to NO,
-# only classes defined in header files are included. Does not have any effect
-# for Java sources.
-# The default value is: YES.
-
-EXTRACT_LOCAL_CLASSES = NO
-
-# This flag is only useful for Objective-C code. If set to YES, local methods,
-# which are defined in the implementation section but not in the interface are
-# included in the documentation. If set to NO, only methods in the interface are
-# included.
-# The default value is: NO.
-
-EXTRACT_LOCAL_METHODS = NO
-
-# If this flag is set to YES, the members of anonymous namespaces will be
-# extracted and appear in the documentation as a namespace called
-# 'anonymous_namespace{file}', where file will be replaced with the base name of
-# the file that contains the anonymous namespace. By default anonymous namespace
-# are hidden.
-# The default value is: NO.
-
-EXTRACT_ANON_NSPACES = NO
-
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
-# undocumented members inside documented classes or files. If set to NO these
-# members will be included in the various overviews, but no documentation
-# section is generated. This option has no effect if EXTRACT_ALL is enabled.
-# The default value is: NO.
-
-HIDE_UNDOC_MEMBERS = NO
-
-# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
-# undocumented classes that are normally visible in the class hierarchy. If set
-# to NO, these classes will be included in the various overviews. This option
-# has no effect if EXTRACT_ALL is enabled.
-# The default value is: NO.
-
-HIDE_UNDOC_CLASSES = NO
-
-# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
-# (class|struct|union) declarations. If set to NO, these declarations will be
-# included in the documentation.
-# The default value is: NO.
-
-HIDE_FRIEND_COMPOUNDS = NO
-
-# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
-# documentation blocks found inside the body of a function. If set to NO, these
-# blocks will be appended to the function's detailed documentation block.
-# The default value is: NO.
-
-HIDE_IN_BODY_DOCS = YES
-
-# The INTERNAL_DOCS tag determines if documentation that is typed after a
-# \internal command is included. If the tag is set to NO then the documentation
-# will be excluded. Set it to YES to include the internal documentation.
-# The default value is: NO.
-
-INTERNAL_DOCS = NO
-
-# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
-# names in lower-case letters. If set to YES, upper-case letters are also
-# allowed. This is useful if you have classes or files whose names only differ
-# in case and if your file system supports case sensitive file names. Windows
-# and Mac users are advised to set this option to NO.
-# The default value is: system dependent.
-
-CASE_SENSE_NAMES = YES
-
-# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
-# their full class and namespace scopes in the documentation. If set to YES, the
-# scope will be hidden.
-# The default value is: NO.
-
-HIDE_SCOPE_NAMES = YES
-
-# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
-# append additional text to a page's title, such as Class Reference. If set to
-# YES the compound reference will be hidden.
-# The default value is: NO.
-
-HIDE_COMPOUND_REFERENCE= NO
-
-# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
-# the files that are included by a file in the documentation of that file.
-# The default value is: YES.
-
-SHOW_INCLUDE_FILES = YES
-
-# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
-# grouped member an include statement to the documentation, telling the reader
-# which file to include in order to use the member.
-# The default value is: NO.
-
-SHOW_GROUPED_MEMB_INC = NO
-
-# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
-# files with double quotes in the documentation rather than with sharp brackets.
-# The default value is: NO.
-
-FORCE_LOCAL_INCLUDES = NO
-
-# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
-# documentation for inline members.
-# The default value is: YES.
-
-INLINE_INFO = YES
-
-# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
-# (detailed) documentation of file and class members alphabetically by member
-# name. If set to NO, the members will appear in declaration order.
-# The default value is: YES.
-
-SORT_MEMBER_DOCS = NO
-
-# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
-# descriptions of file, namespace and class members alphabetically by member
-# name. If set to NO, the members will appear in declaration order. Note that
-# this will also influence the order of the classes in the class list.
-# The default value is: NO.
-
-SORT_BRIEF_DOCS = NO
-
-# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
-# (brief and detailed) documentation of class members so that constructors and
-# destructors are listed first. If set to NO the constructors will appear in the
-# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
-# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
-# member documentation.
-# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
-# detailed member documentation.
-# The default value is: NO.
-
-SORT_MEMBERS_CTORS_1ST = NO
-
-# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
-# of group names into alphabetical order. If set to NO the group names will
-# appear in their defined order.
-# The default value is: NO.
-
-SORT_GROUP_NAMES = NO
-
-# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
-# fully-qualified names, including namespaces. If set to NO, the class list will
-# be sorted only by class name, not including the namespace part.
-# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
-# Note: This option applies only to the class list, not to the alphabetical
-# list.
-# The default value is: NO.
-
-SORT_BY_SCOPE_NAME = YES
-
-# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
-# type resolution of all parameters of a function it will reject a match between
-# the prototype and the implementation of a member function even if there is
-# only one candidate or it is obvious which candidate to choose by doing a
-# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
-# accept a match between prototype and implementation in such cases.
-# The default value is: NO.
-
-STRICT_PROTO_MATCHING = NO
-
-# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
-# list. This list is created by putting \todo commands in the documentation.
-# The default value is: YES.
-
-GENERATE_TODOLIST = NO
-
-# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
-# list. This list is created by putting \test commands in the documentation.
-# The default value is: YES.
-
-GENERATE_TESTLIST = NO
-
-# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
-# list. This list is created by putting \bug commands in the documentation.
-# The default value is: YES.
-
-GENERATE_BUGLIST = NO
-
-# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
-# the deprecated list. This list is created by putting \deprecated commands in
-# the documentation.
-# The default value is: YES.
-
-GENERATE_DEPRECATEDLIST= YES
-
-# The ENABLED_SECTIONS tag can be used to enable conditional documentation
-# sections, marked by \if <section_label> ... \endif and \cond <section_label>
-# ... \endcond blocks.
-
-ENABLED_SECTIONS =
-
-# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
-# initial value of a variable or macro / define can have for it to appear in the
-# documentation. If the initializer consists of more lines than specified here
-# it will be hidden. Use a value of 0 to hide initializers completely. The
-# appearance of the value of individual variables and macros / defines can be
-# controlled using \showinitializer or \hideinitializer command in the
-# documentation regardless of this setting.
-# Minimum value: 0, maximum value: 10000, default value: 30.
-
-MAX_INITIALIZER_LINES = 30
-
-# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
-# the bottom of the documentation of classes and structs. If set to YES, the
-# list will mention the files that were used to generate the documentation.
-# The default value is: YES.
-
-SHOW_USED_FILES = YES
-
-# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
-# will remove the Files entry from the Quick Index and from the Folder Tree View
-# (if specified).
-# The default value is: YES.
-
-SHOW_FILES = YES
-
-# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
-# page. This will remove the Namespaces entry from the Quick Index and from the
-# Folder Tree View (if specified).
-# The default value is: YES.
-
-SHOW_NAMESPACES = YES
-
-# The FILE_VERSION_FILTER tag can be used to specify a program or script that
-# doxygen should invoke to get the current version for each file (typically from
-# the version control system). Doxygen will invoke the program by executing (via
-# popen()) the command command input-file, where command is the value of the
-# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
-# by doxygen. Whatever the program writes to standard output is used as the file
-# version. For an example see the documentation.
-
-FILE_VERSION_FILTER =
-
-# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
-# by doxygen. The layout file controls the global structure of the generated
-# output files in an output format independent way. To create the layout file
-# that represents doxygen's defaults, run doxygen with the -l option. You can
-# optionally specify a file name after the option, if omitted DoxygenLayout.xml
-# will be used as the name of the layout file.
-#
-# Note that if you run doxygen from a directory containing a file called
-# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
-# tag is left empty.
-
-LAYOUT_FILE = @PUGL_SRCDIR@/doc/layout.xml
-
-# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
-# the reference definitions. This must be a list of .bib files. The .bib
-# extension is automatically appended if omitted. This requires the bibtex tool
-# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info.
-# For LaTeX the style of the bibliography can be controlled using
-# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
-# search path. See also \cite for info how to create references.
-
-CITE_BIB_FILES =
-
-#---------------------------------------------------------------------------
-# Configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-
-# The QUIET tag can be used to turn on/off the messages that are generated to
-# standard output by doxygen. If QUIET is set to YES this implies that the
-# messages are off.
-# The default value is: NO.
-
-QUIET = YES
-
-# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
-# this implies that the warnings are on.
-#
-# Tip: Turn warnings on while writing the documentation.
-# The default value is: YES.
-
-WARNINGS = YES
-
-# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
-# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
-# will automatically be disabled.
-# The default value is: YES.
-
-WARN_IF_UNDOCUMENTED = NO
-
-# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
-# potential errors in the documentation, such as not documenting some parameters
-# in a documented function, or documenting parameters that don't exist or using
-# markup commands wrongly.
-# The default value is: YES.
-
-WARN_IF_DOC_ERROR = YES
-
-# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
-# are documented, but have no documentation for their parameters or return
-# value. If set to NO, doxygen will only warn about wrong or incomplete
-# parameter documentation, but not about the absence of documentation. If
-# EXTRACT_ALL is set to YES then this flag will automatically be disabled.
-# The default value is: NO.
-
-WARN_NO_PARAMDOC = NO
-
-# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
-# a warning is encountered.
-# The default value is: NO.
-
-WARN_AS_ERROR = NO
-
-# The WARN_FORMAT tag determines the format of the warning messages that doxygen
-# can produce. The string should contain the $file, $line, and $text tags, which
-# will be replaced by the file and line number from which the warning originated
-# and the warning text. Optionally the format may contain $version, which will
-# be replaced by the version of the file (if it could be obtained via
-# FILE_VERSION_FILTER)
-# The default value is: $file:$line: $text.
-
-WARN_FORMAT = "$file:$line: $text"
-
-# The WARN_LOGFILE tag can be used to specify a file to which warning and error
-# messages should be written. If left blank the output is written to standard
-# error (stderr).
-
-WARN_LOGFILE =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the input files
-#---------------------------------------------------------------------------
-
-# The INPUT tag is used to specify the files and/or directories that contain
-# documented source files. You may enter file names like myfile.cpp or
-# directories like /usr/src/myproject. Separate the files or directories with
-# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
-# Note: If this tag is empty the current directory is searched.
-
-INPUT = @PUGL_SRCDIR@/pugl/ \
- @PUGL_SRCDIR@/doc/mainpage.md
-
-# This tag can be used to specify the character encoding of the source files
-# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
-# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
-# documentation (see: https://www.gnu.org/software/libiconv/) for the list of
-# possible encodings.
-# The default value is: UTF-8.
-
-INPUT_ENCODING = UTF-8
-
-# If the value of the INPUT tag contains directories, you can use the
-# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
-# *.h) to filter out the source-files in the directories.
-#
-# Note that for custom extensions or not directly supported extensions you also
-# need to set EXTENSION_MAPPING for the extension otherwise the files are not
-# read by doxygen.
-#
-# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
-# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
-# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
-# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,
-# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice.
-
-FILE_PATTERNS = *.h *.hpp
-
-# The RECURSIVE tag can be used to specify whether or not subdirectories should
-# be searched for input files as well.
-# The default value is: NO.
-
-RECURSIVE = NO
-
-# The EXCLUDE tag can be used to specify files and/or directories that should be
-# excluded from the INPUT source files. This way you can easily exclude a
-# subdirectory from a directory tree whose root is specified with the INPUT tag.
-#
-# Note that relative paths are relative to the directory from which doxygen is
-# run.
-
-EXCLUDE =
-
-# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
-# directories that are symbolic links (a Unix file system feature) are excluded
-# from the input.
-# The default value is: NO.
-
-EXCLUDE_SYMLINKS = NO
-
-# If the value of the INPUT tag contains directories, you can use the
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories.
-#
-# Note that the wildcards are matched against the file with absolute path, so to
-# exclude all test directories for example use the pattern */test/*
-
-EXCLUDE_PATTERNS =
-
-# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
-# (namespaces, classes, functions, etc.) that should be excluded from the
-# output. The symbol name can be a fully qualified name, a word, or if the
-# wildcard * is used, a substring. Examples: ANamespace, AClass,
-# AClass::ANamespace, ANamespace::*Test
-#
-# Note that the wildcards are matched against the file with absolute path, so to
-# exclude all test directories use the pattern */test/*
-
-EXCLUDE_SYMBOLS =
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or directories
-# that contain example code fragments that are included (see the \include
-# command).
-
-EXAMPLE_PATH =
-
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
-# *.h) to filter out the source-files in the directories. If left blank all
-# files are included.
-
-EXAMPLE_PATTERNS = *.c
-
-# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
-# searched for input files to be used with the \include or \dontinclude commands
-# irrespective of the value of the RECURSIVE tag.
-# The default value is: NO.
-
-EXAMPLE_RECURSIVE = NO
-
-# The IMAGE_PATH tag can be used to specify one or more files or directories
-# that contain images that are to be included in the documentation (see the
-# \image command).
-
-IMAGE_PATH =
-
-# The INPUT_FILTER tag can be used to specify a program that doxygen should
-# invoke to filter for each input file. Doxygen will invoke the filter program
-# by executing (via popen()) the command:
-#
-# <filter> <input-file>
-#
-# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the
-# name of an input file. Doxygen will then use the output that the filter
-# program writes to standard output. If FILTER_PATTERNS is specified, this tag
-# will be ignored.
-#
-# Note that the filter must not add or remove lines; it is applied before the
-# code is scanned, but not when the output code is generated. If lines are added
-# or removed, the anchors will not be placed correctly.
-#
-# Note that for custom extensions or not directly supported extensions you also
-# need to set EXTENSION_MAPPING for the extension otherwise the files are not
-# properly processed by doxygen.
-
-INPUT_FILTER =
-
-# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
-# basis. Doxygen will compare the file name with each pattern and apply the
-# filter if there is a match. The filters are a list of the form: pattern=filter
-# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
-# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
-# patterns match the file name, INPUT_FILTER is applied.
-#
-# Note that for custom extensions or not directly supported extensions you also
-# need to set EXTENSION_MAPPING for the extension otherwise the files are not
-# properly processed by doxygen.
-
-FILTER_PATTERNS =
-
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
-# INPUT_FILTER) will also be used to filter the input files that are used for
-# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
-# The default value is: NO.
-
-FILTER_SOURCE_FILES = NO
-
-# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
-# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
-# it is also possible to disable source filtering for a specific pattern using
-# *.ext= (so without naming a filter).
-# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
-
-FILTER_SOURCE_PATTERNS =
-
-# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
-# is part of the input, its contents will be placed on the main page
-# (index.html). This can be useful if you have a project on for instance GitHub
-# and want to reuse the introduction page also for the doxygen output.
-
-USE_MDFILE_AS_MAINPAGE = @PUGL_SRCDIR@/doc/mainpage.md
-
-#---------------------------------------------------------------------------
-# Configuration options related to source browsing
-#---------------------------------------------------------------------------
-
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
-# generated. Documented entities will be cross-referenced with these sources.
-#
-# Note: To get rid of all source code in the generated output, make sure that
-# also VERBATIM_HEADERS is set to NO.
-# The default value is: NO.
-
-SOURCE_BROWSER = NO
-
-# Setting the INLINE_SOURCES tag to YES will include the body of functions,
-# classes and enums directly into the documentation.
-# The default value is: NO.
-
-INLINE_SOURCES = NO
-
-# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
-# special comment blocks from generated source code fragments. Normal C, C++ and
-# Fortran comments will always remain visible.
-# The default value is: YES.
-
-STRIP_CODE_COMMENTS = YES
-
-# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
-# entity all documented functions referencing it will be listed.
-# The default value is: NO.
-
-REFERENCED_BY_RELATION = NO
-
-# If the REFERENCES_RELATION tag is set to YES then for each documented function
-# all documented entities called/used by that function will be listed.
-# The default value is: NO.
-
-REFERENCES_RELATION = YES
-
-# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
-# to YES then the hyperlinks from functions in REFERENCES_RELATION and
-# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
-# link to the documentation.
-# The default value is: YES.
-
-REFERENCES_LINK_SOURCE = YES
-
-# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
-# source code will show a tooltip with additional information such as prototype,
-# brief description and links to the definition and documentation. Since this
-# will make the HTML file larger and loading of large files a bit slower, you
-# can opt to disable this feature.
-# The default value is: YES.
-# This tag requires that the tag SOURCE_BROWSER is set to YES.
-
-SOURCE_TOOLTIPS = NO
-
-# If the USE_HTAGS tag is set to YES then the references to source code will
-# point to the HTML generated by the htags(1) tool instead of doxygen built-in
-# source browser. The htags tool is part of GNU's global source tagging system
-# (see https://www.gnu.org/software/global/global.html). You will need version
-# 4.8.6 or higher.
-#
-# To use it do the following:
-# - Install the latest version of global
-# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file
-# - Make sure the INPUT points to the root of the source tree
-# - Run doxygen as normal
-#
-# Doxygen will invoke htags (and that will in turn invoke gtags), so these
-# tools must be available from the command line (i.e. in the search path).
-#
-# The result: instead of the source browser generated by doxygen, the links to
-# source code will now point to the output of htags.
-# The default value is: NO.
-# This tag requires that the tag SOURCE_BROWSER is set to YES.
-
-USE_HTAGS = NO
-
-# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
-# verbatim copy of the header file for each class for which an include is
-# specified. Set to NO to disable this.
-# See also: Section \class.
-# The default value is: YES.
-
-VERBATIM_HEADERS = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
-# compounds will be generated. Enable this if the project contains a lot of
-# classes, structs, unions or interfaces.
-# The default value is: YES.
-
-ALPHABETICAL_INDEX = NO
-
-# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
-# which the alphabetical index list will be split.
-# Minimum value: 1, maximum value: 20, default value: 5.
-# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
-
-COLS_IN_ALPHA_INDEX = 5
-
-# In case all classes in a project start with a common prefix, all classes will
-# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
-# can be used to specify a prefix (or a list of prefixes) that should be ignored
-# while generating the index headers.
-# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
-
-IGNORE_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the HTML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
-# The default value is: YES.
-
-GENERATE_HTML = YES
-
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: html.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_OUTPUT = html
-
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
-# generated HTML page (for example: .htm, .php, .asp).
-# The default value is: .html.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_FILE_EXTENSION = .html
-
-# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
-# each generated HTML page. If the tag is left blank doxygen will generate a
-# standard header.
-#
-# To get valid HTML the header file that includes any scripts and style sheets
-# that doxygen needs, which is dependent on the configuration options used (e.g.
-# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
-# default header using
-# doxygen -w html new_header.html new_footer.html new_stylesheet.css
-# YourConfigFile
-# and then modify the file new_header.html. See also section "Doxygen usage"
-# for information on how to generate the default header that doxygen normally
-# uses.
-# Note: The header is subject to change so you typically have to regenerate the
-# default header when upgrading to a newer version of doxygen. For a description
-# of the possible markers and block names see the documentation.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_HEADER = @PUGL_SRCDIR@/doc/header.html
-
-# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
-# generated HTML page. If the tag is left blank doxygen will generate a standard
-# footer. See HTML_HEADER for more information on how to generate a default
-# footer and what special commands can be used inside the footer. See also
-# section "Doxygen usage" for information on how to generate the default footer
-# that doxygen normally uses.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_FOOTER = @PUGL_SRCDIR@/doc/footer.html
-
-# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
-# sheet that is used by each HTML page. It can be used to fine-tune the look of
-# the HTML output. If left blank doxygen will generate a default style sheet.
-# See also section "Doxygen usage" for information on how to generate the style
-# sheet that doxygen normally uses.
-# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
-# it is more robust and this tag (HTML_STYLESHEET) will in the future become
-# obsolete.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_STYLESHEET = @PUGL_SRCDIR@/doc/style.css
-
-# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
-# cascading style sheets that are included after the standard style sheets
-# created by doxygen. Using this option one can overrule certain style aspects.
-# This is preferred over using HTML_STYLESHEET since it does not replace the
-# standard style sheet and is therefore more robust against future updates.
-# Doxygen will copy the style sheet files to the output directory.
-# Note: The order of the extra style sheet files is of importance (e.g. the last
-# style sheet in the list overrules the setting of the previous ones in the
-# list). For an example see the documentation.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_EXTRA_STYLESHEET =
-
-# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
-# other source files which should be copied to the HTML output directory. Note
-# that these files will be copied to the base HTML output directory. Use the
-# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
-# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
-# files will be copied as-is; there are no commands or markers available.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_EXTRA_FILES =
-
-# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
-# will adjust the colors in the style sheet and background images according to
-# this color. Hue is specified as an angle on a colorwheel, see
-# https://en.wikipedia.org/wiki/Hue for more information. For instance the value
-# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
-# purple, and 360 is red again.
-# Minimum value: 0, maximum value: 359, default value: 220.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_HUE = 120
-
-# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
-# in the HTML output. For a value of 0 the output will use grayscales only. A
-# value of 255 will produce the most vivid colors.
-# Minimum value: 0, maximum value: 255, default value: 100.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_SAT = 32
-
-# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
-# luminance component of the colors in the HTML output. Values below 100
-# gradually make the output lighter, whereas values above 100 make the output
-# darker. The value divided by 100 is the actual gamma applied, so 80 represents
-# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
-# change the gamma.
-# Minimum value: 40, maximum value: 240, default value: 80.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_GAMMA = 80
-
-# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
-# page will contain the date and time when the page was generated. Setting this
-# to YES can help to show when doxygen was last run and thus if the
-# documentation is up to date.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_TIMESTAMP = NO
-
-# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML
-# documentation will contain a main index with vertical navigation menus that
-# are dynamically created via Javascript. If disabled, the navigation index will
-# consists of multiple levels of tabs that are statically embedded in every HTML
-# page. Disable this option to support browsers that do not have Javascript,
-# like the Qt help browser.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_DYNAMIC_MENUS = NO
-
-# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
-# documentation will contain sections that can be hidden and shown after the
-# page has loaded.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_DYNAMIC_SECTIONS = NO
-
-# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
-# shown in the various tree structured indices initially; the user can expand
-# and collapse entries dynamically later on. Doxygen will expand the tree to
-# such a level that at most the specified number of entries are visible (unless
-# a fully collapsed tree already exceeds this amount). So setting the number of
-# entries 1 will produce a full collapsed tree by default. 0 is a special value
-# representing an infinite number of entries and will result in a full expanded
-# tree by default.
-# Minimum value: 0, maximum value: 9999, default value: 100.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_INDEX_NUM_ENTRIES = 100
-
-# If the GENERATE_DOCSET tag is set to YES, additional index files will be
-# generated that can be used as input for Apple's Xcode 3 integrated development
-# environment (see: https://developer.apple.com/xcode/), introduced with OSX
-# 10.5 (Leopard). To create a documentation set, doxygen will generate a
-# Makefile in the HTML output directory. Running make will produce the docset in
-# that directory and running make install will install the docset in
-# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
-# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
-# genXcode/_index.html for more information.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_DOCSET = NO
-
-# This tag determines the name of the docset feed. A documentation feed provides
-# an umbrella under which multiple documentation sets from a single provider
-# (such as a company or product suite) can be grouped.
-# The default value is: Doxygen generated docs.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_FEEDNAME = "Doxygen generated docs"
-
-# This tag specifies a string that should uniquely identify the documentation
-# set bundle. This should be a reverse domain-name style string, e.g.
-# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_BUNDLE_ID = org.doxygen.Project
-
-# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
-# the documentation publisher. This should be a reverse domain-name style
-# string, e.g. com.mycompany.MyDocSet.documentation.
-# The default value is: org.doxygen.Publisher.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_PUBLISHER_ID = org.doxygen.Publisher
-
-# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
-# The default value is: Publisher.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_PUBLISHER_NAME = Publisher
-
-# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
-# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
-# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
-# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on
-# Windows.
-#
-# The HTML Help Workshop contains a compiler that can convert all HTML output
-# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
-# files are now used as the Windows 98 help format, and will replace the old
-# Windows help format (.hlp) on all Windows platforms in the future. Compressed
-# HTML files also contain an index, a table of contents, and you can search for
-# words in the documentation. The HTML workshop also contains a viewer for
-# compressed HTML files.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_HTMLHELP = NO
-
-# The CHM_FILE tag can be used to specify the file name of the resulting .chm
-# file. You can add a path in front of the file if the result should not be
-# written to the html output directory.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-CHM_FILE =
-
-# The HHC_LOCATION tag can be used to specify the location (absolute path
-# including file name) of the HTML help compiler (hhc.exe). If non-empty,
-# doxygen will try to run the HTML help compiler on the generated index.hhp.
-# The file has to be specified with full path.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-HHC_LOCATION =
-
-# The GENERATE_CHI flag controls if a separate .chi index file is generated
-# (YES) or that it should be included in the master .chm file (NO).
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-GENERATE_CHI = NO
-
-# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
-# and project file content.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-CHM_INDEX_ENCODING =
-
-# The BINARY_TOC flag controls whether a binary table of contents is generated
-# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
-# enables the Previous and Next buttons.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-BINARY_TOC = NO
-
-# The TOC_EXPAND flag can be set to YES to add extra items for group members to
-# the table of contents of the HTML help documentation and to the tree view.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-TOC_EXPAND = NO
-
-# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
-# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
-# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
-# (.qch) of the generated HTML documentation.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_QHP = NO
-
-# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
-# the file name of the resulting .qch file. The path specified is relative to
-# the HTML output folder.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QCH_FILE =
-
-# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
-# Project output. For more information please see Qt Help Project / Namespace
-# (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_NAMESPACE =
-
-# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
-# Help Project output. For more information please see Qt Help Project / Virtual
-# Folders (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-
-# folders).
-# The default value is: doc.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_VIRTUAL_FOLDER = doc
-
-# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
-# filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
-# filters).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_CUST_FILTER_NAME =
-
-# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
-# custom filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
-# filters).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_CUST_FILTER_ATTRS =
-
-# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
-# project's filter section matches. Qt Help Project / Filter Attributes (see:
-# http://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_SECT_FILTER_ATTRS =
-
-# The QHG_LOCATION tag can be used to specify the location of Qt's
-# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
-# generated .qhp file.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHG_LOCATION =
-
-# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
-# generated, together with the HTML files, they form an Eclipse help plugin. To
-# install this plugin and make it available under the help contents menu in
-# Eclipse, the contents of the directory containing the HTML and XML files needs
-# to be copied into the plugins directory of eclipse. The name of the directory
-# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
-# After copying Eclipse needs to be restarted before the help appears.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_ECLIPSEHELP = NO
-
-# A unique identifier for the Eclipse help plugin. When installing the plugin
-# the directory name containing the HTML and XML files should also have this
-# name. Each documentation set should have its own identifier.
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
-
-ECLIPSE_DOC_ID = org.doxygen.Project
-
-# If you want full control over the layout of the generated HTML pages it might
-# be necessary to disable the index and replace it with your own. The
-# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
-# of each HTML page. A value of NO enables the index and the value YES disables
-# it. Since the tabs in the index contain the same information as the navigation
-# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-DISABLE_INDEX = NO
-
-# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
-# structure should be generated to display hierarchical information. If the tag
-# value is set to YES, a side panel will be generated containing a tree-like
-# index structure (just like the one that is generated for HTML Help). For this
-# to work a browser that supports JavaScript, DHTML, CSS and frames is required
-# (i.e. any modern browser). Windows users are probably better off using the
-# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
-# further fine-tune the look of the index. As an example, the default style
-# sheet generated by doxygen has an example that shows how to put an image at
-# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
-# the same information as the tab index, you could consider setting
-# DISABLE_INDEX to YES when enabling this option.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_TREEVIEW = NO
-
-# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
-# doxygen will group on one line in the generated HTML documentation.
-#
-# Note that a value of 0 will completely suppress the enum values from appearing
-# in the overview section.
-# Minimum value: 0, maximum value: 20, default value: 4.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-ENUM_VALUES_PER_LINE = 0
-
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
-# to set the initial width (in pixels) of the frame in which the tree is shown.
-# Minimum value: 0, maximum value: 1500, default value: 250.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-TREEVIEW_WIDTH = 250
-
-# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
-# external symbols imported via tag files in a separate window.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-EXT_LINKS_IN_WINDOW = NO
-
-# Use this tag to change the font size of LaTeX formulas included as images in
-# the HTML documentation. When you change the font size after a successful
-# doxygen run you need to manually remove any form_*.png images from the HTML
-# output directory to force them to be regenerated.
-# Minimum value: 8, maximum value: 50, default value: 10.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-FORMULA_FONTSIZE = 10
-
-# Use the FORMULA_TRANSPARENT tag to determine whether or not the images
-# generated for formulas are transparent PNGs. Transparent PNGs are not
-# supported properly for IE 6.0, but are supported on all modern browsers.
-#
-# Note that when changing this option you need to delete any form_*.png files in
-# the HTML output directory before the changes have effect.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-FORMULA_TRANSPARENT = YES
-
-# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
-# https://www.mathjax.org) which uses client side Javascript for the rendering
-# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
-# installed or if you want to formulas look prettier in the HTML output. When
-# enabled you may also need to install MathJax separately and configure the path
-# to it using the MATHJAX_RELPATH option.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-USE_MATHJAX = NO
-
-# When MathJax is enabled you can set the default output format to be used for
-# the MathJax output. See the MathJax site (see:
-# http://docs.mathjax.org/en/latest/output.html) for more details.
-# Possible values are: HTML-CSS (which is slower, but has the best
-# compatibility), NativeMML (i.e. MathML) and SVG.
-# The default value is: HTML-CSS.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_FORMAT = HTML-CSS
-
-# When MathJax is enabled you need to specify the location relative to the HTML
-# output directory using the MATHJAX_RELPATH option. The destination directory
-# should contain the MathJax.js script. For instance, if the mathjax directory
-# is located at the same level as the HTML output directory, then
-# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
-# Content Delivery Network so you can quickly see the result without installing
-# MathJax. However, it is strongly recommended to install a local copy of
-# MathJax from https://www.mathjax.org before deployment.
-# The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
-
-# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
-# extension names that should be enabled during MathJax rendering. For example
-# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_EXTENSIONS =
-
-# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
-# of code that will be used on startup of the MathJax code. See the MathJax site
-# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
-# example see the documentation.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_CODEFILE =
-
-# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
-# the HTML output. The underlying search engine uses javascript and DHTML and
-# should work on any modern browser. Note that when using HTML help
-# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
-# there is already a search function so this one should typically be disabled.
-# For large projects the javascript based search engine can be slow, then
-# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
-# search using the keyboard; to jump to the search box use <access key> + S
-# (what the <access key> is depends on the OS and browser, but it is typically
-# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
-# key> to jump into the search results window, the results can be navigated
-# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
-# the search. The filter options can be selected when the cursor is inside the
-# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
-# to select a filter and <Enter> or <escape> to activate or cancel the filter
-# option.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-SEARCHENGINE = NO
-
-# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
-# implemented using a web server instead of a web client using Javascript. There
-# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
-# setting. When disabled, doxygen will generate a PHP script for searching and
-# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
-# and searching needs to be provided by external tools. See the section
-# "External Indexing and Searching" for details.
-# The default value is: NO.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SERVER_BASED_SEARCH = NO
-
-# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
-# script for searching. Instead the search results are written to an XML file
-# which needs to be processed by an external indexer. Doxygen will invoke an
-# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
-# search results.
-#
-# Doxygen ships with an example indexer (doxyindexer) and search engine
-# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: https://xapian.org/).
-#
-# See the section "External Indexing and Searching" for details.
-# The default value is: NO.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTERNAL_SEARCH = NO
-
-# The SEARCHENGINE_URL should point to a search engine hosted by a web server
-# which will return the search results when EXTERNAL_SEARCH is enabled.
-#
-# Doxygen ships with an example indexer (doxyindexer) and search engine
-# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: https://xapian.org/). See the section "External Indexing and
-# Searching" for details.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SEARCHENGINE_URL =
-
-# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
-# search data is written to a file for indexing by an external tool. With the
-# SEARCHDATA_FILE tag the name of this file can be specified.
-# The default file is: searchdata.xml.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SEARCHDATA_FILE = searchdata.xml
-
-# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
-# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
-# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
-# projects and redirect the results back to the right project.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTERNAL_SEARCH_ID =
-
-# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
-# projects other than the one defined by this configuration file, but that are
-# all added to the same external search index. Each project needs to have a
-# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
-# to a relative location where the documentation can be found. The format is:
-# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTRA_SEARCH_MAPPINGS =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
-# The default value is: YES.
-
-GENERATE_LATEX = NO
-
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: latex.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_OUTPUT = latex
-
-# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
-# invoked.
-#
-# Note that when not enabling USE_PDFLATEX the default is latex when enabling
-# USE_PDFLATEX the default is pdflatex and when in the later case latex is
-# chosen this is overwritten by pdflatex. For specific output languages the
-# default can have been set differently, this depends on the implementation of
-# the output language.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_CMD_NAME = latex
-
-# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
-# index for LaTeX.
-# Note: This tag is used in the Makefile / make.bat.
-# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file
-# (.tex).
-# The default file is: makeindex.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-MAKEINDEX_CMD_NAME = makeindex
-
-# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to
-# generate index for LaTeX.
-# Note: This tag is used in the generated output file (.tex).
-# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat.
-# The default value is: \makeindex.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_MAKEINDEX_CMD = \makeindex
-
-# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
-# documents. This may be useful for small projects and may help to save some
-# trees in general.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-COMPACT_LATEX = NO
-
-# The PAPER_TYPE tag can be used to set the paper type that is used by the
-# printer.
-# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x
-# 14 inches) and executive (7.25 x 10.5 inches).
-# The default value is: a4.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-PAPER_TYPE = a4
-
-# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
-# that should be included in the LaTeX output. The package can be specified just
-# by its name or with the correct syntax as to be used with the LaTeX
-# \usepackage command. To get the times font for instance you can specify :
-# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
-# To use the option intlimits with the amsmath package you can specify:
-# EXTRA_PACKAGES=[intlimits]{amsmath}
-# If left blank no extra packages will be included.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-EXTRA_PACKAGES =
-
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the
-# generated LaTeX document. The header should contain everything until the first
-# chapter. If it is left blank doxygen will generate a standard header. See
-# section "Doxygen usage" for information on how to let doxygen write the
-# default header to a separate file.
-#
-# Note: Only use a user-defined header if you know what you are doing! The
-# following commands have a special meaning inside the header: $title,
-# $datetime, $date, $doxygenversion, $projectname, $projectnumber,
-# $projectbrief, $projectlogo. Doxygen will replace $title with the empty
-# string, for the replacement values of the other commands the user is referred
-# to HTML_HEADER.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_HEADER =
-
-# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the
-# generated LaTeX document. The footer should contain everything after the last
-# chapter. If it is left blank doxygen will generate a standard footer. See
-# LATEX_HEADER for more information on how to generate a default footer and what
-# special commands can be used inside the footer.
-#
-# Note: Only use a user-defined footer if you know what you are doing!
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_FOOTER =
-
-# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
-# LaTeX style sheets that are included after the standard style sheets created
-# by doxygen. Using this option one can overrule certain style aspects. Doxygen
-# will copy the style sheet files to the output directory.
-# Note: The order of the extra style sheet files is of importance (e.g. the last
-# style sheet in the list overrules the setting of the previous ones in the
-# list).
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_EXTRA_STYLESHEET =
-
-# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
-# other source files which should be copied to the LATEX_OUTPUT output
-# directory. Note that the files will be copied as-is; there are no commands or
-# markers available.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_EXTRA_FILES =
-
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is
-# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will
-# contain links (just like the HTML output) instead of page references. This
-# makes the output suitable for online browsing using a PDF viewer.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-PDF_HYPERLINKS = YES
-
-# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
-# the PDF file directly from the LaTeX files. Set this option to YES, to get a
-# higher quality PDF documentation.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-USE_PDFLATEX = YES
-
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
-# command to the generated LaTeX files. This will instruct LaTeX to keep running
-# if errors occur, instead of asking the user for help. This option is also used
-# when generating formulas in HTML.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_BATCHMODE = NO
-
-# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the
-# index chapters (such as File Index, Compound Index, etc.) in the output.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_HIDE_INDICES = NO
-
-# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source
-# code with syntax highlighting in the LaTeX output.
-#
-# Note that which sources are shown also depends on other settings such as
-# SOURCE_BROWSER.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_SOURCE_CODE = NO
-
-# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
-# bibliography, e.g. plainnat, or ieeetr. See
-# https://en.wikipedia.org/wiki/BibTeX and \cite for more info.
-# The default value is: plain.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_BIB_STYLE = plain
-
-# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
-# page will contain the date and time when the page was generated. Setting this
-# to NO can help when comparing the output of multiple runs.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_TIMESTAMP = NO
-
-# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)
-# path from which the emoji images will be read. If a relative path is entered,
-# it will be relative to the LATEX_OUTPUT directory. If left blank the
-# LATEX_OUTPUT directory will be used.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_EMOJI_DIRECTORY =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the RTF output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
-# RTF output is optimized for Word 97 and may not look too pretty with other RTF
-# readers/editors.
-# The default value is: NO.
-
-GENERATE_RTF = NO
-
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: rtf.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_OUTPUT = rtf
-
-# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
-# documents. This may be useful for small projects and may help to save some
-# trees in general.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-COMPACT_RTF = NO
-
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will
-# contain hyperlink fields. The RTF file will contain links (just like the HTML
-# output) instead of page references. This makes the output suitable for online
-# browsing using Word or some other Word compatible readers that support those
-# fields.
-#
-# Note: WordPad (write) and others do not support links.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_HYPERLINKS = NO
-
-# Load stylesheet definitions from file. Syntax is similar to doxygen's
-# configuration file, i.e. a series of assignments. You only have to provide
-# replacements, missing definitions are set to their default value.
-#
-# See also section "Doxygen usage" for information on how to generate the
-# default style sheet that doxygen normally uses.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_STYLESHEET_FILE =
-
-# Set optional variables used in the generation of an RTF document. Syntax is
-# similar to doxygen's configuration file. A template extensions file can be
-# generated using doxygen -e rtf extensionFile.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_EXTENSIONS_FILE =
-
-# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code
-# with syntax highlighting in the RTF output.
-#
-# Note that which sources are shown also depends on other settings such as
-# SOURCE_BROWSER.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_SOURCE_CODE = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the man page output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
-# classes and files.
-# The default value is: NO.
-
-GENERATE_MAN = YES
-
-# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it. A directory man3 will be created inside the directory specified by
-# MAN_OUTPUT.
-# The default directory is: man.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_OUTPUT = man
-
-# The MAN_EXTENSION tag determines the extension that is added to the generated
-# man pages. In case the manual section does not start with a number, the number
-# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is
-# optional.
-# The default value is: .3.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_EXTENSION = .3
-
-# The MAN_SUBDIR tag determines the name of the directory created within
-# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
-# MAN_EXTENSION with the initial . removed.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_SUBDIR =
-
-# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
-# will generate one additional man file for each entity documented in the real
-# man page(s). These additional files only source the real man page, but without
-# them the man command would be unable to find the correct page.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_LINKS = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the XML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
-# captures the structure of the code including all documentation.
-# The default value is: NO.
-
-GENERATE_XML = YES
-
-# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: xml.
-# This tag requires that the tag GENERATE_XML is set to YES.
-
-XML_OUTPUT = xml
-
-# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
-# listings (including syntax highlighting and cross-referencing information) to
-# the XML output. Note that enabling this will significantly increase the size
-# of the XML output.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_XML is set to YES.
-
-XML_PROGRAMLISTING = YES
-
-# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include
-# namespace members in file scope as well, matching the HTML output.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_XML is set to YES.
-
-XML_NS_MEMB_FILE_SCOPE = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the DOCBOOK output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
-# that can be used to generate PDF.
-# The default value is: NO.
-
-GENERATE_DOCBOOK = NO
-
-# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
-# front of it.
-# The default directory is: docbook.
-# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
-
-DOCBOOK_OUTPUT = docbook
-
-# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the
-# program listings (including syntax highlighting and cross-referencing
-# information) to the DOCBOOK output. Note that enabling this will significantly
-# increase the size of the DOCBOOK output.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
-
-DOCBOOK_PROGRAMLISTING = NO
-
-#---------------------------------------------------------------------------
-# Configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
-# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures
-# the structure of the code including all documentation. Note that this feature
-# is still experimental and incomplete at the moment.
-# The default value is: NO.
-
-GENERATE_AUTOGEN_DEF = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
-# file that captures the structure of the code including all documentation.
-#
-# Note that this feature is still experimental and incomplete at the moment.
-# The default value is: NO.
-
-GENERATE_PERLMOD = NO
-
-# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
-# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
-# output from the Perl module output.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_PERLMOD is set to YES.
-
-PERLMOD_LATEX = NO
-
-# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
-# formatted so it can be parsed by a human reader. This is useful if you want to
-# understand what is going on. On the other hand, if this tag is set to NO, the
-# size of the Perl module output will be much smaller and Perl will parse it
-# just the same.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_PERLMOD is set to YES.
-
-PERLMOD_PRETTY = YES
-
-# The names of the make variables in the generated doxyrules.make file are
-# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful
-# so different doxyrules.make files included by the same Makefile don't
-# overwrite each other's variables.
-# This tag requires that the tag GENERATE_PERLMOD is set to YES.
-
-PERLMOD_MAKEVAR_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-
-# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
-# C-preprocessor directives found in the sources and include files.
-# The default value is: YES.
-
-ENABLE_PREPROCESSING = YES
-
-# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
-# in the source code. If set to NO, only conditional compilation will be
-# performed. Macro expansion can be done in a controlled way by setting
-# EXPAND_ONLY_PREDEF to YES.
-# The default value is: NO.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-MACRO_EXPANSION = YES
-
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
-# the macro expansion is limited to the macros specified with the PREDEFINED and
-# EXPAND_AS_DEFINED tags.
-# The default value is: NO.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-EXPAND_ONLY_PREDEF = YES
-
-# If the SEARCH_INCLUDES tag is set to YES, the include files in the
-# INCLUDE_PATH will be searched if a #include is found.
-# The default value is: YES.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-SEARCH_INCLUDES = YES
-
-# The INCLUDE_PATH tag can be used to specify one or more directories that
-# contain include files that are not input files but should be processed by the
-# preprocessor.
-# This tag requires that the tag SEARCH_INCLUDES is set to YES.
-
-INCLUDE_PATH =
-
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
-# patterns (like *.h and *.hpp) to filter out the header-files in the
-# directories. If left blank, the patterns specified with FILE_PATTERNS will be
-# used.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-INCLUDE_FILE_PATTERNS =
-
-# The PREDEFINED tag can be used to specify one or more macro names that are
-# defined before the preprocessor is started (similar to the -D option of e.g.
-# gcc). The argument of the tag is a list of macros of the form: name or
-# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
-# is assumed. To prevent a macro definition from being undefined via #undef or
-# recursively expanded use the := operator instead of the = operator.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-PREDEFINED = PUGL_API PUGL_DISABLE_DEPRECATED PUGL_CONST_FUNC=
-
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
-# tag can be used to specify a list of macro names that should be expanded. The
-# macro definition that is found in the sources will be used. Use the PREDEFINED
-# tag if you want to use a different macro definition that overrules the
-# definition found in the source code.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-EXPAND_AS_DEFINED =
-
-# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
-# remove all references to function-like macros that are alone on a line, have
-# an all uppercase name, and do not end with a semicolon. Such function macros
-# are typically used for boiler-plate code, and will confuse the parser if not
-# removed.
-# The default value is: YES.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-SKIP_FUNCTION_MACROS = YES
-
-#---------------------------------------------------------------------------
-# Configuration options related to external references
-#---------------------------------------------------------------------------
-
-# The TAGFILES tag can be used to specify one or more tag files. For each tag
-# file the location of the external documentation should be added. The format of
-# a tag file without this location is as follows:
-# TAGFILES = file1 file2 ...
-# Adding location for the tag files is done as follows:
-# TAGFILES = file1=loc1 "file2 = loc2" ...
-# where loc1 and loc2 can be relative or absolute paths or URLs. See the
-# section "Linking to external documentation" for more information about the use
-# of tag files.
-# Note: Each tag file must have a unique name (where the name does NOT include
-# the path). If a tag file is not located in the directory in which doxygen is
-# run, you must also specify the path to the tagfile here.
-
-TAGFILES =
-
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
-# tag file that is based on the input files it reads. See section "Linking to
-# external documentation" for more information about the usage of tag files.
-
-GENERATE_TAGFILE =
-
-# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
-# the class index. If set to NO, only the inherited external classes will be
-# listed.
-# The default value is: NO.
-
-ALLEXTERNALS = NO
-
-# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
-# in the modules index. If set to NO, only the current project's groups will be
-# listed.
-# The default value is: YES.
-
-EXTERNAL_GROUPS = YES
-
-# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
-# the related pages index. If set to NO, only the current project's pages will
-# be listed.
-# The default value is: YES.
-
-EXTERNAL_PAGES = YES
-
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-
-# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
-# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
-# NO turns the diagrams off. Note that this option also works with HAVE_DOT
-# disabled, but it is recommended to install and use dot, since it yields more
-# powerful graphs.
-# The default value is: YES.
-
-CLASS_DIAGRAMS = NO
-
-# You can include diagrams made with dia in doxygen documentation. Doxygen will
-# then run dia to produce the diagram and insert it in the documentation. The
-# DIA_PATH tag allows you to specify the directory where the dia binary resides.
-# If left empty dia is assumed to be found in the default search path.
-
-DIA_PATH =
-
-# If set to YES the inheritance and collaboration graphs will hide inheritance
-# and usage relations if the target is undocumented or is not a class.
-# The default value is: YES.
-
-HIDE_UNDOC_RELATIONS = YES
-
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
-# available from the path. This tool is part of Graphviz (see:
-# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
-# Bell Labs. The other options in this section have no effect if this option is
-# set to NO
-# The default value is: NO.
-
-HAVE_DOT = NO
-
-# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
-# to run in parallel. When set to 0 doxygen will base this on the number of
-# processors available in the system. You can set it explicitly to a value
-# larger than 0 to get control over the balance between CPU load and processing
-# speed.
-# Minimum value: 0, maximum value: 32, default value: 0.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_NUM_THREADS = 0
-
-# When you want a differently looking font in the dot files that doxygen
-# generates you can specify the font name using DOT_FONTNAME. You need to make
-# sure dot is able to find the font, which can be done by putting it in a
-# standard location or by setting the DOTFONTPATH environment variable or by
-# setting DOT_FONTPATH to the directory containing the font.
-# The default value is: Helvetica.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTNAME =
-
-# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
-# dot graphs.
-# Minimum value: 4, maximum value: 24, default value: 10.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTSIZE = 10
-
-# By default doxygen will tell dot to use the default font as specified with
-# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
-# the path where dot can find it using this tag.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTPATH =
-
-# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for
-# each documented class showing the direct and indirect inheritance relations.
-# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CLASS_GRAPH = NO
-
-# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
-# graph for each documented class showing the direct and indirect implementation
-# dependencies (inheritance, containment, and class references variables) of the
-# class with other documented classes.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-COLLABORATION_GRAPH = NO
-
-# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
-# groups, showing the direct groups dependencies.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GROUP_GRAPHS = YES
-
-# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
-# collaboration diagrams in a style similar to the OMG's Unified Modeling
-# Language.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-UML_LOOK = NO
-
-# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
-# class node. If there are many fields or methods and many nodes the graph may
-# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
-# number of items for each type to make the size more manageable. Set this to 0
-# for no limit. Note that the threshold may be exceeded by 50% before the limit
-# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
-# but if the number exceeds 15, the total amount of fields shown is limited to
-# 10.
-# Minimum value: 0, maximum value: 100, default value: 10.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-UML_LIMIT_NUM_FIELDS = 10
-
-# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
-# collaboration graphs will show the relations between templates and their
-# instances.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-TEMPLATE_RELATIONS = NO
-
-# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
-# YES then doxygen will generate a graph for each documented file showing the
-# direct and indirect include dependencies of the file with other documented
-# files.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INCLUDE_GRAPH = NO
-
-# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
-# set to YES then doxygen will generate a graph for each documented file showing
-# the direct and indirect include dependencies of the file with other documented
-# files.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INCLUDED_BY_GRAPH = NO
-
-# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
-# dependency graph for every global function or class method.
-#
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable call graphs for selected
-# functions only using the \callgraph command. Disabling a call graph can be
-# accomplished by means of the command \hidecallgraph.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CALL_GRAPH = NO
-
-# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
-# dependency graph for every global function or class method.
-#
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable caller graphs for selected
-# functions only using the \callergraph command. Disabling a caller graph can be
-# accomplished by means of the command \hidecallergraph.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CALLER_GRAPH = NO
-
-# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
-# hierarchy of all classes instead of a textual one.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GRAPHICAL_HIERARCHY = NO
-
-# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
-# dependencies a directory has on other directories in a graphical way. The
-# dependency relations are determined by the #include relations between the
-# files in the directories.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DIRECTORY_GRAPH = NO
-
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
-# generated by dot. For an explanation of the image formats see the section
-# output formats in the documentation of the dot tool (Graphviz (see:
-# http://www.graphviz.org/)).
-# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
-# to make the SVG files visible in IE 9+ (other browsers do not have this
-# requirement).
-# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo,
-# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
-# png:gdiplus:gdiplus.
-# The default value is: png.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_IMAGE_FORMAT = png
-
-# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
-# enable generation of interactive SVG images that allow zooming and panning.
-#
-# Note that this requires a modern browser other than Internet Explorer. Tested
-# and working are Firefox, Chrome, Safari, and Opera.
-# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
-# the SVG files visible. Older versions of IE do not have SVG support.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INTERACTIVE_SVG = NO
-
-# The DOT_PATH tag can be used to specify the path where the dot tool can be
-# found. If left blank, it is assumed the dot tool can be found in the path.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_PATH =
-
-# The DOTFILE_DIRS tag can be used to specify one or more directories that
-# contain dot files that are included in the documentation (see the \dotfile
-# command).
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOTFILE_DIRS =
-
-# The MSCFILE_DIRS tag can be used to specify one or more directories that
-# contain msc files that are included in the documentation (see the \mscfile
-# command).
-
-MSCFILE_DIRS =
-
-# The DIAFILE_DIRS tag can be used to specify one or more directories that
-# contain dia files that are included in the documentation (see the \diafile
-# command).
-
-DIAFILE_DIRS =
-
-# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
-# path where java can find the plantuml.jar file. If left blank, it is assumed
-# PlantUML is not used or called during a preprocessing step. Doxygen will
-# generate a warning when it encounters a \startuml command in this case and
-# will not generate output for the diagram.
-
-PLANTUML_JAR_PATH =
-
-# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a
-# configuration file for plantuml.
-
-PLANTUML_CFG_FILE =
-
-# When using plantuml, the specified paths are searched for files specified by
-# the !include statement in a plantuml block.
-
-PLANTUML_INCLUDE_PATH =
-
-# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
-# that will be shown in the graph. If the number of nodes in a graph becomes
-# larger than this value, doxygen will truncate the graph, which is visualized
-# by representing a node as a red box. Note that doxygen if the number of direct
-# children of the root node in a graph is already larger than
-# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
-# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
-# Minimum value: 0, maximum value: 10000, default value: 50.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_GRAPH_MAX_NODES = 50
-
-# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
-# generated by dot. A depth value of 3 means that only nodes reachable from the
-# root by following a path via at most 3 edges will be shown. Nodes that lay
-# further from the root node will be omitted. Note that setting this option to 1
-# or 2 may greatly reduce the computation time needed for large code bases. Also
-# note that the size of a graph can be further restricted by
-# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
-# Minimum value: 0, maximum value: 1000, default value: 0.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-MAX_DOT_GRAPH_DEPTH = 0
-
-# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
-# background. This is disabled by default, because dot on Windows does not seem
-# to support this out of the box.
-#
-# Warning: Depending on the platform used, enabling this option may lead to
-# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
-# read).
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_TRANSPARENT = NO
-
-# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
-# files in one run (i.e. multiple -o and -T options on the command line). This
-# makes dot run faster, but since only newer versions of dot (>1.8.10) support
-# this, this feature is disabled by default.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_MULTI_TARGETS = NO
-
-# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
-# explaining the meaning of the various boxes and arrows in the dot generated
-# graphs.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GENERATE_LEGEND = NO
-
-# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
-# files that are used to generate the various graphs.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_CLEANUP = YES
diff --git a/subprojects/d2tk/pugl/doc/style.css b/subprojects/d2tk/pugl/doc/style.css
deleted file mode 100644
index 680fe77..0000000
--- a/subprojects/d2tk/pugl/doc/style.css
+++ /dev/null
@@ -1,863 +0,0 @@
-body {
- background: #FFF;
- color: #222;
- font-style: normal;
- line-height: 1.6em;
- margin-left: auto;
- margin-right: auto;
- padding: 1em;
- max-width: 60em;
- font-family: "SF Pro Text", Verdana, "DejaVu Sans", sans-serif;
- text-rendering: optimizeLegibility;
-}
-
-h1 {
- font-size: 1.68em;
- font-weight: 500;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- line-height: 2em;
- margin: 0 0 0.25em 0;
-}
-
-h2 {
- line-height: 1.68em;
- font-size: 1.41em;
- font-weight: 600;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- margin: 1.25em 0 0.5em 0;
-}
-
-h3 {
- line-height: 1.41em;
- font-size: 1.18em;
- font-weight: 600;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- margin: 1.25em 0 0.5em 0;
-}
-
-h4 {
- line-height: 1.18em;
- font-size: 1em;
- font-weight: 600;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- margin: 1.25em 0 0.5em 0;
-}
-
-h5, h6 {
- font-size: 0.7em;
- font-weight: 600;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- margin: 1.25em 0 0.5em 0;
-}
-
-a {
- color: #546E00;
- text-decoration: none;
-}
-
-h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
- color: #444;
-}
-
-a:hover {
- text-decoration: underline;
-}
-
-h1 a:link, h2 a:link, h3 a:link, h4 a:link, h5 a:link, h6 a:link {
- color: #444;
-}
-
-h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
- color: #444;
-}
-
-p {
- margin: 0.5em 0 0.5em 0;
-}
-
-dt {
- font-weight: 600;
-}
-
-dd {
- margin-left: 2em;
-}
-
-caption {
- font-weight: 700;
-}
-
-.title, #projectname {
- line-height: 1.0125em;
- margin: 0.75em 0 0 0;
-}
-
-.titlearea .header .titlebox, #projectname {
- font-size: 1.68em;
- font-weight: 400;
- margin-bottom: 0.25em;
- margin-top: 0;
-}
-
-#header {
- padding: 0 0 0.5em 0;
- border-bottom: 1px solid #EEE;
-}
-
-.header .headertitle .title {
- line-height: 1.68em;
- font-size: 1.68em;
- font-weight: 600;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
-}
-
-.ingroups {
- display: none;
-}
-
-.title .ingroups a {
- font-size: small;
- margin-left: 1em;
-}
-
-#titlebox, #metabox {
- display: inline-block;
-}
-
-#titlebox {
- display: inline-block;
- width: 75%;
- left: 0;
- top: 0;
-}
-
-#title {
- margin-bottom: 0.25em;
- line-height: 1.25em;
- font-size: 2.5em;
- color: #333;
- font-weight: 600;
-}
-
-.PageDoc {
- margin-top: 1.5em;
-}
-
-.PageDoc .header .headertitle .title {
- display: none;
-}
-
-#shortdesc {
- margin: 0;
- color: #666;
- display: inline-block;
- font-style: italic;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- padding: 0;
-}
-
-#titlearea {
- margin: 0.25em auto 0 auto;
- padding: 0;
- position: relative;
- clear: both;
- line-height: 1em;
-}
-
-.legend {
- font-size: small;
- text-align: center;
-}
-
-.version {
- font-size: small;
- text-align: center;
-}
-
-div.qindex,div.navtab {
- background-color: #EBEFF6;
- border: 1px solid #A3B4D7;
- text-align: center;
- margin: 2px;
- padding: 2px;
-}
-
-div.navtab {
- margin-right: 15px;
-}
-
-.contents a:visited {
- color: #344E00;
-}
-
-a.qindexHL {
- background-color: #9CAFD4;
- color: #FFF;
- border: 1px double #869DCA;
-}
-
-code {
- color: #444;
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
-}
-
-dl.el {
- margin-left: -1cm;
-}
-
-.fragment {
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
-}
-
-pre.fragment {
- border: 1px solid #C4C4C4;
- background-color: #F9F9F9;
- padding: 0.5em;
- overflow: auto;
-}
-
-div.ah {
- background-color: #000;
- font-weight: 700;
- color: #FFF;
- margin-bottom: 3px;
- margin-top: 3px;
- padding: 0.2em;
- border: thin solid #333;
-}
-
-div.groupHeader {
- margin-left: 16px;
- margin-top: 12px;
- margin-bottom: 6px;
- font-weight: 700;
-}
-
-h2.groupheader {
- line-height: 1.18em;
- font-size: 1em;
- font-weight: 600;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- margin: 1.25em 0 0.5em 0;
-}
-
-a + h2.groupheader {
- display: none;
-}
-
-div.groupText {
- margin-left: 16px;
- font-style: italic;
-}
-
-div.contents, #content {
- max-width: 60em;
- margin-left: auto;
- margin-right: auto;
-}
-
-.groupheader + p {
- font-style: italic;
- color: #666;
- margin: 0 0 1em 0;
-}
-
-td.indexkey {
- background-color: #EBEFF6;
- font-weight: 700;
- border: 1px solid #C4CFE5;
- margin: 2px 0;
- padding: 2px 10px;
-}
-
-td.indexvalue {
- background-color: #EBEFF6;
- border: 1px solid #C4CFE5;
- padding: 2px 10px;
- margin: 2px 0;
-}
-
-table.memname {
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
- border-spacing: 0;
-}
-
-table.memname tbody tr:last-child {
- display: none;
-}
-
-table.memname tbody tr:only-child {
- display: table-cell;
-}
-
-table.memname tbody tr:nth-last-child(2)::after {
- content: ")";
-}
-
-tr.memlist {
- background-color: #EEF1F7;
-}
-
-p.formulaDsp {
- text-align: center;
-}
-
-img.formulaInl {
- vertical-align: middle;
-}
-
-div.center {
- text-align: center;
- margin-top: 0;
- margin-bottom: 0;
- padding: 0;
-}
-
-div.center img {
- border: 0;
-}
-
-address.footer {
- text-align: right;
-}
-
-img.footer {
- border: 0;
- vertical-align: middle;
-}
-
-span.keyword {
- color: #586E75;
-}
-
-span.keywordtype {
- color: #546E00;
-}
-
-span.keywordflow {
- color: #586E75;
-}
-
-span.comment {
- color: #6C71C4;
-}
-
-span.preprocessor {
- color: #D33682;
-}
-
-span.stringliteral {
- color: #CB4B16;
-}
-
-span.charliteral {
- color: #CB4B16;
-}
-
-td.tiny {
- font-size: x-small;
-}
-
-.dirtab {
- padding: 4px;
- border-collapse: collapse;
- border: 1px solid #A3B4D7;
-}
-
-th.dirtab {
- background: #EBEFF6;
- font-weight: 700;
-}
-
-hr {
- height: 0;
- border: none;
- border-top: 1px solid #DDD;
- margin: 2em 0;
-}
-
-#footer {
- bottom: 0;
- clear: both;
- font-size: x-small;
- margin: 2em 0 0;
- padding: 0 1em 1em 1em;
- vertical-align: top;
- color: #888;
-}
-
-td.ititle {
- padding-bottom: 0.75em;
-}
-
-table.memberdecls {
- border-spacing: 0.125em;
- line-height: 1.3em;
-}
-
-table.memberdecls h3 {
- line-height: 1.18em;
- font-size: 1em;
- font-weight: 600;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- margin: 1.25em 0 0.5em 0;
-}
-
-tr.inherit_header td {
- padding: 1em 0 0.5em 0;
-}
-
-.mdescLeft,.mdescRight,.memItemLeft,.memItemRight,.memTemplItemLeft,.memTemplItemRight,.memTemplParams {
- margin: 0;
- padding: 0;
-}
-
-.mdescLeft,.mdescRight {
- color: #555;
-}
-
-.memItemLeft,.memItemRight,.memTemplParams {
- border: 0;
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
-}
-
-.memItemLeft,.memTemplItemLeft {
- white-space: nowrap;
- padding-left: 2em;
-}
-
-.memItemLeft a.el {
- font-weight: bold;
-}
-
-.memTemplParams {
- color: #464646;
- white-space: nowrap;
-}
-
-td.memSeparator {
- display: none;
-}
-
-td.mlabels-left {
- margin-left: 0;
- padding-left: 0;
-}
-
-td.mlabels-right {
- color: #B4C342;
- font-weight: normal;
- margin-left: 1em;
- vertical-align: bottom;
-}
-
-.memtitle {
- border-bottom: 1px solid #EEE;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- font-size: 1.18em;
- font-weight: 600;
- line-height: 1.41em;
- margin: 1.5em 0 0 0;
-}
-
-.permalink {
- display: none;
-}
-
-.memtemplate {
- color: #888;
- font-style: italic;
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
- font-size: small;
-}
-
-.memnav {
- background-color: #EEE;
- border: 1px solid #B4C342;
- text-align: center;
- margin: 2px;
- margin-right: 15px;
- padding: 2px;
-}
-
-.memitem {
- padding: 0;
- margin: 0 0 3em 0;
-}
-
-.memproto {
- border-bottom: 1px solid #EEE;
- border-left: 1px solid #EEE;
- color: #444;
- float: right;
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
- font-size: small;
- margin-bottom: 1em;
- margin-left: 1em;
- padding: 0.25em 0 0.25em 0.25em;
-}
-
-.memproto .paramname {
- font-style: normal;
- padding-right: 0.25em;
-}
-
-.mlabels {
- padding-left: 0;
- padding-right: 0;
-}
-
-.memdoc {
- padding: 0;
-}
-
-.memdoc > p:first-child, .memdoc .textblock > p:first-child {
- font-style: italic;
- color: #444;
- margin-bottom: 0.75em;
- margin-top: 0;
- padding-top: 0.25em;
- font-weight: normal;
-}
-
-.memdoc > p:first-child, .memdoc .textblock > h3:first-child {
- color: #444;
- margin-bottom: 0.75em;
- margin-top: 0;
- padding-top: 0.25em;
- font-weight: normal;
- color: #444;
- font-size: 0.9em;
-}
-
-.paramkey {
- text-align: right;
-}
-
-.paramtype {
- color: #666;
- padding: 0 0.25em 0 0.25em;
- white-space: nowrap;
-}
-
-.params .paramname {
- color: #111;
- white-space: nowrap;
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
- font-style: italic;
- padding-right: 0.5em;
- vertical-align: top;
-}
-
-.fieldname {
- color: #000;
-}
-
-.fieldtable {
- margin-top: 1em;
- border-collapse: collapse;
-}
-
-.fieldtable tbody tr:first-child {
- display: none;
-}
-
-td.fieldname {
- vertical-align: top;
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
-}
-
-td.fielddoc {
- padding: 0.125em 0.5em 0 0.25em;
- vertical-align: top;
-}
-
-.fieldtable tbody tr td {
- border-top: 1px dashed #DDD;
- border-bottom: 1px dashed #DDD;
-}
-
-td.fieldtype {
- color: #666;
- padding: 0 0.5em 0 0;
- vertical-align: top;
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
-}
-
-td.fielddoc p {
- margin: 0;
- padding: 0 0.5em 0 0;
-}
-
-p.reference {
- font-size: x-small;
- font-style: italic;
-}
-
-.ftvtree {
- font-family: "DejaVu Sans", Verdana, Helvetica, Arial, sans-serif;
- margin: 0;
-}
-
-.directory {
- margin: 0.5em;
-}
-
-.directory h3 {
- margin: 0;
- margin-top: 1em;
- font-size: 11pt;
-}
-
-.directory > h3 {
- margin-top: 0;
-}
-
-.directory p {
- margin: 0;
- white-space: nowrap;
-}
-
-.directory div {
- display: none;
- margin: 0;
-}
-
-.directory img {
- vertical-align: -30%;
-}
-
-td.entry {
- font-family: "DejaVu Sans", Verdana, Helvetica, Arial, sans-serif;
- font-weight: 400;
- padding-right: 1em;
-}
-
-.arrow {
- color: #CCC;
- user-select: none;
- font-size: 80%;
- display: inline-block;
- width: 16px;
- height: 22px;
- vertical-align: top;
-}
-
-td.entry b {
- font-family: "DejaVu Sans", Verdana, Helvetica, Arial, sans-serif;
- font-weight: 400;
- font-size: 130%;
-}
-
-.directory-alt {
- font-size: 100%;
- font-weight: bold;
-}
-
-.directory-alt h3 {
- margin: 0;
- margin-top: 1em;
- font-size: 11pt;
-}
-
-.directory-alt > h3 {
- margin-top: 0;
-}
-
-.directory-alt p {
- margin: 0;
- white-space: nowrap;
-}
-
-.directory-alt div {
- display: none;
- margin: 0;
-}
-
-.directory-alt img {
- vertical-align: -30%;
-}
-
-div.dynheader {
- margin-top: 8px;
-}
-
-address {
- font-style: normal;
- color: #444;
-}
-
-table.doxtable {
- border-collapse: collapse;
- margin: 0.5em;
-}
-
-table.doxtable td,table.doxtable th {
- border: 1px solid #DDD;
- padding: 3px 7px 2px;
-}
-
-table.doxtable th {
- background-color: #F3F3F3;
- color: #000;
- padding-bottom: 4px;
- padding-top: 5px;
- text-align: left;
- font-weight: bold;
-}
-
-.tabsearch {
- top: 0;
- left: 10px;
- height: 36px;
- z-index: 101;
- overflow: hidden;
- font-size: 13px;
-}
-
-div.navpath {
- color: #DDD;
-}
-
-.navpath ul {
- overflow: hidden;
- margin: 0;
- padding: 0;
-}
-
-.navpath li {
- float: left;
- padding-left: 0;
- margin-left: 0.5em;
- padding-right: 1em;
-}
-
-.navpath a {
- display: block;
- text-decoration: none;
- outline: none;
-}
-
-div.summary {
- font-size: small;
- font-family: "DejaVu Sans", Verdana, Helvetica, Arial, sans-serif;
- margin: 0;
- padding: 0.25em 0;
- display: none;
-}
-
-div.summary a {
- white-space: nowrap;
-}
-
-#metabox {
- display: inline-block;
- font-size: x-small;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- position: absolute;
- right: 0;
- bottom: 0.25em;
- color: #666;
- font-style: italic;
-}
-
-#meta {
- border-style: hidden;
- margin-right: 0.25em;
-}
-
-#meta tr, #meta th, #meta td {
- background-color: transparent;
- border: 0;
- margin: 0;
- font-weight: normal;
-}
-
-#meta th {
- text-align: right;
-}
-
-#meta th::after {
- content: ":";
-}
-
-div.line {
- font-family: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace, fixed;
- line-height: 1.4em;
- white-space: pre-wrap;
-}
-
-.glow {
- background-color: #2AA198;
- box-shadow: 0 0 10px #2AA198;
-}
-
-span.lineno {
- padding-right: 4px;
- text-align: right;
- border-right: 2px solid #546E00;
- background-color: #E8E8E8;
- white-space: pre;
-}
-
-span.lineno a {
- background-color: #D8D8D8;
-}
-
-span.lineno a:hover {
- background-color: #C8C8C8;
-}
-
-.tabs, .tabs2, .navpath {
- padding: 0.25em 0;
- font-size: small;
- font-family: Helvetica, Arial, "DejaVu Sans Condensed", Verdana, sans-serif;
- margin: 0;
-}
-
-th {
- text-align: left;
- font-size: 110%;
- font-weight: 500;
-}
-
-.mlabel {
- padding: 0.125em;
-}
-
-#navrow1, #navrow2 {
- /* Disable menu from Doxygen 1.8.15, it is faked in the template */
- display: none;
-}
-
-.tablist {
- margin: 0;
- padding: 0;
- display: table;
-}
-
-.tablist li {
- display: table-cell;
- line-height: 2em;
- list-style: none;
- border-bottom: 0;
-}
-
-.tablist a {
- display: block;
- padding: 0 1em 0 0;
- text-decoration: none;
- outline: none;
-}
-
-.tabs3 .tablist a {
- padding: 0 10px;
-}
-
-.tablist li.current a {
- color: #222;
-}
-
-span.icon {
- display: none;
-}
diff --git a/subprojects/d2tk/pugl/examples/.clang-tidy b/subprojects/d2tk/pugl/examples/.clang-tidy
new file mode 100644
index 0000000..ad5b75a
--- /dev/null
+++ b/subprojects/d2tk/pugl/examples/.clang-tidy
@@ -0,0 +1,38 @@
+Checks: >
+ *,
+ -*avoid-c-arrays,
+ -*magic-numbers,
+ -*uppercase-literal-suffix,
+ -android-cloexec-fopen,
+ -bugprone-reserved-identifier,
+ -bugprone-suspicious-string-compare,
+ -cert-dcl37-c,
+ -cert-dcl51-cpp,
+ -cert-flp30-c,
+ -clang-analyzer-alpha.*,
+ -clang-analyzer-security.FloatLoopCounter,
+ -cppcoreguidelines-avoid-non-const-global-variables,
+ -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
+ -cppcoreguidelines-pro-bounds-constant-array-index,
+ -cppcoreguidelines-pro-bounds-pointer-arithmetic,
+ -cppcoreguidelines-pro-type-reinterpret-cast,
+ -cppcoreguidelines-pro-type-vararg,
+ -fuchsia-default-arguments,
+ -fuchsia-default-arguments-calls,
+ -google-runtime-references,
+ -hicpp-multiway-paths-covered,
+ -hicpp-named-parameter,
+ -hicpp-no-array-decay,
+ -hicpp-signed-bitwise,
+ -hicpp-vararg,
+ -llvm-else-after-return,
+ -llvm-header-guard,
+ -llvmlibc-*,
+ -misc-misplaced-const,
+ -misc-non-private-member-variables-in-classes,
+ -modernize-use-trailing-return-type,
+ -readability-else-after-return,
+ -readability-implicit-bool-conversion,
+ -readability-named-parameter,
+FormatStyle: file
+HeaderFilterRegex: 'pugl/.*|test/.*|examples/.*' \ No newline at end of file
diff --git a/subprojects/d2tk/pugl/examples/cube_view.h b/subprojects/d2tk/pugl/examples/cube_view.h
index 8a81f48..87bf3b5 100644
--- a/subprojects/d2tk/pugl/examples/cube_view.h
+++ b/subprojects/d2tk/pugl/examples/cube_view.h
@@ -14,12 +14,64 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef EXAMPLES_CUBE_VIEW_H
+#define EXAMPLES_CUBE_VIEW_H
+
#define GL_SILENCE_DEPRECATION 1
#include "demo_utils.h"
#include "pugl/gl.h"
+// clang-format off
+
+static const float cubeStripVertices[] = {
+ -1.0f, 1.0f, 1.0f, // Front top left
+ 1.0f, 1.0f, 1.0f, // Front top right
+ -1.0f, -1.0f, 1.0f, // Front bottom left
+ 1.0f, -1.0f, 1.0f, // Front bottom right
+ 1.0f, -1.0f, -1.0f, // Back bottom right
+ 1.0f, 1.0f, 1.0f, // Front top right
+ 1.0f, 1.0f, -1.0f, // Back top right
+ -1.0f, 1.0f, 1.0f, // Front top left
+ -1.0f, 1.0f, -1.0f, // Back top left
+ -1.0f, -1.0f, 1.0f, // Front bottom left
+ -1.0f, -1.0f, -1.0f, // Back bottom left
+ 1.0f, -1.0f, -1.0f, // Back bottom right
+ -1.0f, 1.0f, -1.0f, // Back top left
+ 1.0f, 1.0f, -1.0f // Back top right
+};
+
+static const float cubeFrontLineLoop[] = {
+ -1.0f, 1.0f, 1.0f, // Front top left
+ 1.0f, 1.0f, 1.0f, // Front top right
+ 1.0f, -1.0f, 1.0f, // Front bottom right
+ -1.0f, -1.0f, 1.0f, // Front bottom left
+};
+
+static const float cubeBackLineLoop[] = {
+ -1.0f, 1.0f, -1.0f, // Back top left
+ 1.0f, 1.0f, -1.0f, // Back top right
+ 1.0f, -1.0f, -1.0f, // Back bottom right
+ -1.0f, -1.0f, -1.0f, // Back bottom left
+};
+
+static const float cubeSideLines[] = {
+ -1.0f, 1.0f, 1.0f, // Front top left
+ -1.0f, 1.0f, -1.0f, // Back top left
+
+ -1.0f, -1.0f, 1.0f, // Front bottom left
+ -1.0f, -1.0f, -1.0f, // Back bottom left
+
+ 1.0f, 1.0f, 1.0f, // Front top right
+ 1.0f, 1.0f, -1.0f, // Back top right
+
+ 1.0f, -1.0f, 1.0f, // Front bottom right
+ 1.0f, -1.0f, -1.0f, // Back bottom right
+};
+
+// clang-format on
+
static inline void
reshapeCube(const float width, const float height)
{
@@ -80,3 +132,5 @@ displayCube(PuglView* const view,
glDrawArrays(GL_LINES, 0, 8);
glDisableClientState(GL_VERTEX_ARRAY);
}
+
+#endif // EXAMPLES_CUBE_VIEW_H
diff --git a/subprojects/d2tk/pugl/examples/demo_utils.h b/subprojects/d2tk/pugl/examples/demo_utils.h
index 6d3bb66..9057a32 100644
--- a/subprojects/d2tk/pugl/examples/demo_utils.h
+++ b/subprojects/d2tk/pugl/examples/demo_utils.h
@@ -14,8 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef PUGL_DEMO_UTILS_H
-#define PUGL_DEMO_UTILS_H
+#ifndef EXAMPLES_DEMO_UTILS_H
+#define EXAMPLES_DEMO_UTILS_H
#include "pugl/pugl.h"
@@ -31,55 +31,6 @@ typedef struct {
typedef float vec4[4];
typedef vec4 mat4[4];
-// clang-format off
-
-static const float cubeStripVertices[] = {
- -1.0f, 1.0f, 1.0f, // Front top left
- 1.0f, 1.0f, 1.0f, // Front top right
- -1.0f, -1.0f, 1.0f, // Front bottom left
- 1.0f, -1.0f, 1.0f, // Front bottom right
- 1.0f, -1.0f, -1.0f, // Back bottom right
- 1.0f, 1.0f, 1.0f, // Front top right
- 1.0f, 1.0f, -1.0f, // Back top right
- -1.0f, 1.0f, 1.0f, // Front top left
- -1.0f, 1.0f, -1.0f, // Back top left
- -1.0f, -1.0f, 1.0f, // Front bottom left
- -1.0f, -1.0f, -1.0f, // Back bottom left
- 1.0f, -1.0f, -1.0f, // Back bottom right
- -1.0f, 1.0f, -1.0f, // Back top left
- 1.0f, 1.0f, -1.0f // Back top right
-};
-
-static const float cubeFrontLineLoop[] = {
- -1.0f, 1.0f, 1.0f, // Front top left
- 1.0f, 1.0f, 1.0f, // Front top right
- 1.0f, -1.0f, 1.0f, // Front bottom right
- -1.0f, -1.0f, 1.0f, // Front bottom left
-};
-
-static const float cubeBackLineLoop[] = {
- -1.0f, 1.0f, -1.0f, // Back top left
- 1.0f, 1.0f, -1.0f, // Back top right
- 1.0f, -1.0f, -1.0f, // Back bottom right
- -1.0f, -1.0f, -1.0f, // Back bottom left
-};
-
-static const float cubeSideLines[] = {
- -1.0f, 1.0f, 1.0f, // Front top left
- -1.0f, 1.0f, -1.0f, // Back top left
-
- -1.0f, -1.0f, 1.0f, // Front bottom left
- -1.0f, -1.0f, -1.0f, // Back bottom left
-
- 1.0f, 1.0f, 1.0f, // Front top right
- 1.0f, 1.0f, -1.0f, // Back top right
-
- 1.0f, -1.0f, 1.0f, // Front bottom right
- 1.0f, -1.0f, -1.0f, // Back bottom right
-};
-
-// clang-format on
-
static inline void
mat4Identity(mat4 m)
{
@@ -162,14 +113,14 @@ puglPrintFps(const PuglWorld* world,
if (thisTime > printer->lastReportTime + 5) {
const double fps = *framesDrawn / (thisTime - printer->lastReportTime);
fprintf(stderr,
- "%u frames in %.0f seconds = %.3f FPS\n",
+ "FPS: %.2f (%u frames in %.0f seconds)\n",
+ fps,
*framesDrawn,
- thisTime - printer->lastReportTime,
- fps);
+ thisTime - printer->lastReportTime);
printer->lastReportTime = thisTime;
*framesDrawn = 0;
}
}
-#endif // PUGL_DEMO_UTILS_H
+#endif // EXAMPLES_DEMO_UTILS_H
diff --git a/subprojects/d2tk/pugl/examples/file_utils.c b/subprojects/d2tk/pugl/examples/file_utils.c
new file mode 100644
index 0000000..2b00bdc
--- /dev/null
+++ b/subprojects/d2tk/pugl/examples/file_utils.c
@@ -0,0 +1,68 @@
+/*
+ Copyright 2019-2020 David Robillard <d@drobilla.net>
+
+ 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.
+*/
+
+#if !defined(__APPLE__) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+
+#include "file_utils.h"
+
+#ifdef _WIN32
+# include <io.h>
+# include <windows.h>
+# define F_OK 0
+#else
+# include <libgen.h>
+# include <unistd.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char*
+resourcePath(const char* const programPath, const char* const name)
+{
+ char* const binary = strdup(programPath);
+
+#ifdef _WIN32
+ char programDir[_MAX_DIR];
+ _splitpath(binary, programDir, NULL, NULL, NULL);
+ _splitpath(binary, NULL, programDir + strlen(programDir), NULL, NULL);
+ programDir[strlen(programDir) - 1] = '\0';
+#else
+ char* const programDir = dirname(binary);
+#endif
+
+ const size_t programDirLen = strlen(programDir);
+ const size_t nameLen = strlen(name);
+ const size_t totalLen = programDirLen + nameLen + 4;
+
+ char* const programRelative = (char*)calloc(totalLen, 1);
+ snprintf(programRelative, totalLen, "%s/%s", programDir, name);
+ if (!access(programRelative, F_OK)) {
+ free(binary);
+ return programRelative;
+ }
+
+ free(programRelative);
+ free(binary);
+
+ const size_t sysPathLen = strlen(PUGL_DATA_DIR) + nameLen + 4;
+ char* const sysPath = (char*)calloc(sysPathLen, 1);
+ snprintf(sysPath, sysPathLen, "%s/%s", PUGL_DATA_DIR, name);
+ return sysPath;
+}
diff --git a/subprojects/d2tk/pugl/pugl/glu.h b/subprojects/d2tk/pugl/examples/file_utils.h
index 94da8fc..1530157 100644
--- a/subprojects/d2tk/pugl/pugl/glu.h
+++ b/subprojects/d2tk/pugl/examples/file_utils.h
@@ -1,5 +1,5 @@
/*
- Copyright 2012-2020 David Robillard <d@drobilla.net>
+ Copyright 2019-2020 David Robillard <d@drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -14,19 +14,28 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef EXAMPLES_FILE_UTILS_H
+#define EXAMPLES_FILE_UTILS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
- @file glu.h
- @brief Portable header wrapper for glu.h.
+ Return the path to a resource file.
- Unfortunately, GL includes vary across platforms so this header allows for
- pure portable programs.
+ This takes a name like "shaders/something.glsl" and returns the actual
+ path that can be used to load that resource, which may be relative to the
+ current executable (for running in bundles or the build directory), or a
+ shared system directory for installs.
+
+ The returned path must be freed with free().
*/
+char*
+resourcePath(const char* programPath, const char* name);
-#ifdef __APPLE__
-# include "OpenGL/glu.h"
-#else
-# ifdef _WIN32
-# include <windows.h> /* Broken Windows GL headers require this */
-# endif
-# include "GL/glu.h"
+#ifdef __cplusplus
+}
#endif
+
+#endif // EXAMPLES_FILE_UTILS_H
diff --git a/subprojects/d2tk/pugl/examples/glad/glad.h b/subprojects/d2tk/pugl/examples/glad/glad.h
index d8068c6..9efb229 100644
--- a/subprojects/d2tk/pugl/examples/glad/glad.h
+++ b/subprojects/d2tk/pugl/examples/glad/glad.h
@@ -124,8 +124,6 @@ typedef khronos_int64_t GLint64EXT;
typedef khronos_uint64_t GLuint64;
typedef khronos_uint64_t GLuint64EXT;
typedef struct __GLsync *GLsync;
-struct _cl_context;
-struct _cl_event;
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
typedef void (APIENTRY *GLDEBUGPROCKHR)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
diff --git a/subprojects/d2tk/pugl/examples/pugl_cairo_demo.c b/subprojects/d2tk/pugl/examples/pugl_cairo_demo.c
index 5fe0661..48a02db 100644
--- a/subprojects/d2tk/pugl/examples/pugl_cairo_demo.c
+++ b/subprojects/d2tk/pugl/examples/pugl_cairo_demo.c
@@ -14,16 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl_cairo_demo.c
- @brief An example of drawing with Cairo.
-*/
-
#include "demo_utils.h"
#include "test/test_utils.h"
+#include "pugl/cairo.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_cairo.h"
#include <cairo.h>
@@ -252,7 +247,7 @@ main(int argc, char** argv)
return logError("Failed to create window (%s)\n", puglStrerror(st));
}
- puglShowWindow(view);
+ puglShow(view);
PuglFpsPrinter fpsPrinter = { puglGetTime(app.world) };
const double timeout = app.opts.continuous ? (1 / 60.0) : -1.0;
diff --git a/subprojects/d2tk/pugl/examples/pugl_cursor_demo.c b/subprojects/d2tk/pugl/examples/pugl_cursor_demo.c
index 03ab5da..f20b0ea 100644
--- a/subprojects/d2tk/pugl/examples/pugl_cursor_demo.c
+++ b/subprojects/d2tk/pugl/examples/pugl_cursor_demo.c
@@ -14,16 +14,10 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl_cursor_demo.c
- @brief An example of changing the mouse cursor.
-*/
-
#include "test/test_utils.h"
#include "pugl/gl.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_gl.h"
#include <stdbool.h>
@@ -111,6 +105,9 @@ onEvent(PuglView* view, const PuglEvent* event)
case PUGL_EXPOSE:
onExpose();
break;
+ case PUGL_POINTER_OUT:
+ puglSetCursor(view, PUGL_CURSOR_ARROW);
+ break;
case PUGL_CLOSE:
app->quit = 1;
break;
@@ -158,7 +155,7 @@ main(int argc, char** argv)
return logError("Failed to create window (%s)\n", puglStrerror(st));
}
- puglShowWindow(view);
+ puglShow(view);
while (!app.quit) {
puglUpdate(app.world, -1.0);
diff --git a/subprojects/d2tk/pugl/examples/pugl_cxx_demo.cpp b/subprojects/d2tk/pugl/examples/pugl_cxx_demo.cpp
index 4addee2..8269ae4 100644
--- a/subprojects/d2tk/pugl/examples/pugl_cxx_demo.cpp
+++ b/subprojects/d2tk/pugl/examples/pugl_cxx_demo.cpp
@@ -14,20 +14,13 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl_cxx_demo.cpp
- @brief A simple demo of the Pugl C++ API.
-*/
-
#include "cube_view.h"
#include "demo_utils.h"
#include "test/test_utils.h"
-#include "pugl/gl.h"
+#include "pugl/gl.hpp"
#include "pugl/pugl.h"
#include "pugl/pugl.hpp"
-#include "pugl/pugl.ipp"
-#include "pugl/pugl_gl.hpp"
#include <cmath>
@@ -36,13 +29,21 @@ class CubeView : public pugl::View
public:
explicit CubeView(pugl::World& world)
: pugl::View{world}
- {}
+ {
+ setEventHandler(*this);
+ }
+
+ template<PuglEventType t, class Base>
+ pugl::Status onEvent(const pugl::Event<t, Base>&) noexcept
+ {
+ return pugl::Status::success;
+ }
- pugl::Status onConfigure(const pugl::ConfigureEvent& event) override;
- pugl::Status onUpdate(const pugl::UpdateEvent& event) override;
- pugl::Status onExpose(const pugl::ExposeEvent& event) override;
- pugl::Status onKeyPress(const pugl::KeyPressEvent& event) override;
- pugl::Status onClose(const pugl::CloseEvent& event) override;
+ static pugl::Status onEvent(const pugl::ConfigureEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::UpdateEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::ExposeEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::KeyPressEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::CloseEvent& event) noexcept;
bool quit() const { return _quit; }
@@ -54,7 +55,7 @@ private:
};
pugl::Status
-CubeView::onConfigure(const pugl::ConfigureEvent& event)
+CubeView::onEvent(const pugl::ConfigureEvent& event) noexcept
{
reshapeCube(static_cast<float>(event.width),
static_cast<float>(event.height));
@@ -63,13 +64,13 @@ CubeView::onConfigure(const pugl::ConfigureEvent& event)
}
pugl::Status
-CubeView::onUpdate(const pugl::UpdateEvent&)
+CubeView::onEvent(const pugl::UpdateEvent&) noexcept
{
return postRedisplay();
}
pugl::Status
-CubeView::onExpose(const pugl::ExposeEvent&)
+CubeView::onEvent(const pugl::ExposeEvent&) noexcept
{
const double thisTime = world().time();
const double dTime = thisTime - _lastDrawTime;
@@ -89,7 +90,7 @@ CubeView::onExpose(const pugl::ExposeEvent&)
}
pugl::Status
-CubeView::onKeyPress(const pugl::KeyPressEvent& event)
+CubeView::onEvent(const pugl::KeyPressEvent& event) noexcept
{
if (event.key == PUGL_KEY_ESCAPE || event.key == 'q') {
_quit = true;
@@ -99,7 +100,7 @@ CubeView::onKeyPress(const pugl::KeyPressEvent& event)
}
pugl::Status
-CubeView::onClose(const pugl::CloseEvent&)
+CubeView::onEvent(const pugl::CloseEvent&) noexcept
{
_quit = true;
@@ -132,7 +133,7 @@ main(int argc, char** argv)
view.setHint(pugl::ViewHint::swapInterval, opts.sync);
view.setHint(pugl::ViewHint::ignoreKeyRepeat, opts.ignoreKeyRepeat);
view.realize();
- view.showWindow();
+ view.show();
unsigned framesDrawn = 0;
while (!view.quit()) {
diff --git a/subprojects/d2tk/pugl/examples/pugl_embed_demo.c b/subprojects/d2tk/pugl/examples/pugl_embed_demo.c
index 774ac77..55480f6 100644
--- a/subprojects/d2tk/pugl/examples/pugl_embed_demo.c
+++ b/subprojects/d2tk/pugl/examples/pugl_embed_demo.c
@@ -14,18 +14,12 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl_embed_demo.c
- @brief An example of embedding a view in another.
-*/
-
#include "cube_view.h"
#include "demo_utils.h"
#include "test/test_utils.h"
#include "pugl/gl.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_gl.h"
#include <math.h>
#include <stdbool.h>
@@ -336,8 +330,8 @@ main(int argc, char** argv)
puglStrerror(st));
}
- puglShowWindow(app.parent);
- puglShowWindow(app.child);
+ puglShow(app.parent);
+ puglShow(app.child);
puglStartTimer(app.child, reverseTimerId, 3.6);
diff --git a/subprojects/d2tk/pugl/examples/pugl_print_events.c b/subprojects/d2tk/pugl/examples/pugl_print_events.c
index 08a4a86..8f8874b 100644
--- a/subprojects/d2tk/pugl/examples/pugl_print_events.c
+++ b/subprojects/d2tk/pugl/examples/pugl_print_events.c
@@ -14,15 +14,10 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl_print_events.c
- @brief A utility program that prints view events.
-*/
-
#include "test/test_utils.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_stub.h"
+#include "pugl/stub.h"
#include <stdbool.h>
#include <stdio.h>
@@ -59,15 +54,17 @@ main(void)
puglSetClassName(app.world, "Pugl Print Events");
puglSetWindowTitle(app.view, "Pugl Event Printer");
+ puglSetDefaultSize(app.view, 512, 512);
puglSetBackend(app.view, puglStubBackend());
puglSetHandle(app.view, &app);
puglSetEventFunc(app.view, onEvent);
- if (puglRealize(app.view)) {
- return logError("Failed to create window\n");
+ PuglStatus st = puglRealize(app.view);
+ if (st) {
+ return logError("Failed to create window (%s)\n", puglStrerror(st));
}
- puglShowWindow(app.view);
+ puglShow(app.view);
while (!app.quit) {
puglUpdate(app.world, -1.0);
diff --git a/subprojects/d2tk/pugl/examples/pugl_shader_demo.c b/subprojects/d2tk/pugl/examples/pugl_shader_demo.c
index 50afb37..8ebbe60 100644
--- a/subprojects/d2tk/pugl/examples/pugl_shader_demo.c
+++ b/subprojects/d2tk/pugl/examples/pugl_shader_demo.c
@@ -14,28 +14,28 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl_shader_demo.c
- @brief An example of drawing with OpenGL 3/4.
-
- This is an example of using OpenGL for pixel-perfect 2D drawing. It uses
- pixel coordinates for positions and sizes so that things work roughly like a
- typical 2D graphics API.
-
- The program draws a bunch of rectangles with borders, using instancing.
- Each rectangle has origin, size, and fill color attributes, which are shared
- for all four vertices. On each frame, a single buffer with all the
- rectangle data is sent to the GPU, and everything is drawn with a single
- draw call.
-
- This is not particularly realistic or optimal, but serves as a decent rough
- benchmark for how much simple geometry you can draw. The number of
- rectangles can be given on the command line. For reference, it begins to
- struggle to maintain 60 FPS on my machine (1950x + Vega64) with more than
- about 100000 rectangles.
+/*
+ An example of drawing with OpenGL 3/4.
+
+ This is an example of using OpenGL for pixel-perfect 2D drawing. It uses
+ pixel coordinates for positions and sizes so that things work roughly like a
+ typical 2D graphics API.
+
+ The program draws a bunch of rectangles with borders, using instancing.
+ Each rectangle has origin, size, and fill color attributes, which are shared
+ for all four vertices. On each frame, a single buffer with all the
+ rectangle data is sent to the GPU, and everything is drawn with a single
+ draw call.
+
+ This is not particularly realistic or optimal, but serves as a decent rough
+ benchmark for how much simple geometry you can draw. The number of
+ rectangles can be given on the command line. For reference, it begins to
+ struggle to maintain 60 FPS on my machine (1950x + Vega64) with more than
+ about 100000 rectangles.
*/
#include "demo_utils.h"
+#include "file_utils.h"
#include "rects.h"
#include "shader_utils.h"
#include "test/test_utils.h"
@@ -44,15 +44,17 @@
#include "pugl/gl.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_gl.h"
+#include <math.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-static const int defaultWidth = 512;
-static const int defaultHeight = 512;
+static const int defaultWidth = 512;
+static const int defaultHeight = 512;
+static const uintptr_t resizeTimerId = 1u;
typedef struct
{
@@ -61,6 +63,7 @@ typedef struct
typedef struct
{
+ const char* programPath;
PuglWorld* world;
PuglView* view;
PuglTestOptions opts;
@@ -71,6 +74,8 @@ typedef struct
GLuint vbo;
GLuint instanceVbo;
GLuint ibo;
+ double lastDrawDuration;
+ double lastFrameEndTime;
unsigned framesDrawn;
int glMajorVersion;
int glMinorVersion;
@@ -137,6 +142,9 @@ onExpose(PuglView* view)
(GLsizei)(app->numRects * 4));
++app->framesDrawn;
+
+ app->lastFrameEndTime = puglGetTime(puglGetWorld(view));
+ app->lastDrawDuration = app->lastFrameEndTime - time;
}
static PuglStatus
@@ -161,11 +169,24 @@ onEvent(PuglView* view, const PuglEvent* event)
break;
case PUGL_EXPOSE: onExpose(view); break;
case PUGL_CLOSE: app->quit = 1; break;
+ case PUGL_LOOP_ENTER:
+ puglStartTimer(view,
+ resizeTimerId,
+ 1.0 / (double)puglGetViewHint(view, PUGL_REFRESH_RATE));
+ break;
+ case PUGL_LOOP_LEAVE:
+ puglStopTimer(view, resizeTimerId);
+ break;
case PUGL_KEY_PRESS:
if (event->key.key == 'q' || event->key.key == PUGL_KEY_ESCAPE) {
app->quit = 1;
}
break;
+ case PUGL_TIMER:
+ if (event->timer.id == resizeTimerId) {
+ puglPostRedisplay(view);
+ }
+ break;
default: break;
}
@@ -184,14 +205,18 @@ makeRects(const size_t numRects)
}
static char*
-loadShader(const char* const path)
+loadShader(const char* const programPath, const char* const name)
{
+ char* const path = resourcePath(programPath, name);
+ fprintf(stderr, "Loading shader %s\n", path);
+
FILE* const file = fopen(path, "r");
if (!file) {
logError("Failed to open '%s'\n", path);
return NULL;
}
+ free(path);
fseek(file, 0, SEEK_END);
const size_t fileSize = (size_t)ftell(file);
@@ -284,9 +309,14 @@ setupGl(PuglTestApp* app)
: "shaders/header_420.glsl");
// Load shader sources
- char* const headerSource = loadShader(headerFile);
- char* const vertexSource = loadShader("shaders/rect.vert");
- char* const fragmentSource = loadShader("shaders/rect.frag");
+ char* const headerSource = loadShader(app->programPath, headerFile);
+
+ char* const vertexSource = loadShader(app->programPath,
+ "shaders/rect.vert");
+
+ char* const fragmentSource = loadShader(app->programPath,
+ "shaders/rect.frag");
+
if (!vertexSource || !fragmentSource) {
logError("Failed to load shader sources\n");
return PUGL_FAILURE;
@@ -386,6 +416,7 @@ main(int argc, char** argv)
{
PuglTestApp app = {0};
+ app.programPath = argv[0];
app.glMajorVersion = 3;
app.glMinorVersion = 3;
@@ -405,12 +436,39 @@ main(int argc, char** argv)
}
// Show window
- puglShowWindow(app.view);
+ printViewHints(app.view);
+ puglShow(app.view);
+
+ // Calculate ideal frame duration to drive the main loop at a good rate
+ const int refreshRate = puglGetViewHint(app.view, PUGL_REFRESH_RATE);
+ const double frameDuration = 1.0 / (double)refreshRate;
// Grind away, drawing continuously
- PuglFpsPrinter fpsPrinter = {puglGetTime(app.world)};
+ const double startTime = puglGetTime(app.world);
+ PuglFpsPrinter fpsPrinter = {startTime};
while (!app.quit) {
- puglUpdate(app.world, 0.0);
+ /* To minimize input latency and get smooth performance during window
+ resizing, we want to poll for events as long as possible before
+ starting to draw the next frame. This ensures that as many events
+ are consumed as possible before starting to draw, or, equivalently,
+ that the next rendered frame represents the latest events possible.
+ This is particularly important for mouse input and "live" window
+ resizing, where many events tend to pile up within a frame.
+
+ To do this, we keep track of the time when the last frame was
+ finished drawing, and how long it took to expose (and assume this is
+ relatively stable). Then, we can calculate how much time there is
+ from now until the time when we should start drawing to not miss the
+ deadline, and use that as the timeout for puglUpdate().
+ */
+
+ const double now = puglGetTime(app.world);
+ const double nextFrameEndTime = app.lastFrameEndTime + frameDuration;
+ const double nextExposeTime = nextFrameEndTime - app.lastDrawDuration;
+ const double timeUntilNext = nextExposeTime - now;
+ const double timeout = app.opts.sync ? timeUntilNext : 0.0;
+
+ puglUpdate(app.world, fmax(0.0, timeout));
puglPrintFps(app.world, &fpsPrinter, &app.framesDrawn);
}
diff --git a/subprojects/d2tk/pugl/examples/pugl_vulkan_cxx_demo.cpp b/subprojects/d2tk/pugl/examples/pugl_vulkan_cxx_demo.cpp
new file mode 100644
index 0000000..21fd4df
--- /dev/null
+++ b/subprojects/d2tk/pugl/examples/pugl_vulkan_cxx_demo.cpp
@@ -0,0 +1,1871 @@
+/*
+ Copyright 2019-2020 David Robillard <http://drobilla.net>
+
+ 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.
+*/
+
+/*
+ An example of drawing with Vulkan.
+
+ This is an example of using Vulkan for pixel-perfect 2D drawing. It uses
+ the same data and shaders as pugl_shader_demo.c and attempts to draw the
+ same thing, except using Vulkan.
+
+ Since Vulkan is a complicated and very verbose API, this example is
+ unfortunately much larger than the others. You should not use this as a
+ resource to learn Vulkan, but it provides a decent demo of using Vulkan with
+ Pugl that works nicely on all supported platforms.
+*/
+
+#include "demo_utils.h"
+#include "file_utils.h"
+#include "rects.h"
+#include "test/test_utils.h"
+
+#include "sybok.hpp"
+
+#include "pugl/pugl.h"
+#include "pugl/pugl.hpp"
+#include "pugl/vulkan.hpp"
+
+#include <vulkan/vk_platform.h>
+#include <vulkan/vulkan_core.h>
+
+#include <algorithm>
+#include <array>
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <initializer_list>
+#include <iomanip>
+#include <iostream>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace {
+
+constexpr uintptr_t resizeTimerId = 1u;
+
+struct PhysicalDeviceSelection {
+ sk::PhysicalDevice physicalDevice;
+ uint32_t graphicsFamilyIndex;
+};
+
+/// Basic Vulkan context associated with the window
+struct VulkanContext {
+ VkResult init(pugl::VulkanLoader& loader, const PuglTestOptions& opts);
+
+ sk::VulkanApi vk;
+ sk::Instance instance;
+ sk::DebugReportCallbackEXT debugCallback;
+};
+
+/// Basic setup of graphics device
+struct GraphicsDevice {
+ VkResult init(const pugl::VulkanLoader& loader,
+ const VulkanContext& context,
+ pugl::View& view,
+ const PuglTestOptions& opts);
+
+ sk::SurfaceKHR surface;
+ sk::PhysicalDevice physicalDevice{};
+ uint32_t graphicsIndex{};
+ VkSurfaceFormatKHR surfaceFormat{};
+ VkPresentModeKHR presentMode{};
+ VkPresentModeKHR resizePresentMode{};
+ sk::Device device{};
+ sk::Queue graphicsQueue{};
+ sk::CommandPool commandPool{};
+};
+
+/// Buffer allocated on the GPU
+struct Buffer {
+ VkResult init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ VkDeviceSize size,
+ VkBufferUsageFlags usage,
+ VkMemoryPropertyFlags properties);
+
+ sk::Buffer buffer;
+ sk::DeviceMemory deviceMemory;
+};
+
+/// A set of frames that can be rendered concurrently
+struct Swapchain {
+ VkResult init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ VkSurfaceCapabilitiesKHR capabilities,
+ VkExtent2D extent,
+ VkSwapchainKHR oldSwapchain,
+ bool resizing);
+
+ VkSurfaceCapabilitiesKHR capabilities{};
+ VkExtent2D extent{};
+ sk::SwapchainKHR swapchain{};
+ std::vector<sk::ImageView> imageViews{};
+};
+
+/// A pass that renders to a target
+struct RenderPass {
+ VkResult init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const Swapchain& swapchain);
+
+ sk::RenderPass renderPass;
+ std::vector<sk::Framebuffer> framebuffers;
+ sk::CommandBuffers<std::vector<VkCommandBuffer>> commandBuffers;
+};
+
+/// Uniform buffer for constant data used in shaders
+struct UniformBufferObject {
+ mat4 projection;
+};
+
+/// Rectangle data that does not depend on renderer configuration
+struct RectData {
+ VkResult
+ init(const sk::VulkanApi& vk, const GraphicsDevice& gpu, size_t nRects);
+
+ sk::DescriptorSetLayout descriptorSetLayout{};
+ Buffer uniformBuffer{};
+ sk::MappedMemory uniformData{};
+ Buffer modelBuffer{};
+ Buffer instanceBuffer{};
+ sk::MappedMemory vertexData{};
+ size_t numRects{};
+};
+
+/// Shader modules for drawing rectangles
+struct RectShaders {
+ VkResult init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const std::string& programPath);
+
+ sk::ShaderModule vert{};
+ sk::ShaderModule frag{};
+};
+
+/// A pipeline to render rectangles with our shaders
+struct RectPipeline {
+ VkResult init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const RectData& rectData,
+ const RectShaders& shaders,
+ const Swapchain& swapchain,
+ const RenderPass& renderPass);
+
+ sk::DescriptorPool descriptorPool{};
+ sk::DescriptorSets<std::vector<VkDescriptorSet>> descriptorSets{};
+ sk::PipelineLayout pipelineLayout{};
+ std::array<sk::Pipeline, 1> pipelines{};
+ uint32_t numImages{};
+};
+
+/// Synchronization primitives used to coordinate drawing frames
+struct RenderSync {
+ VkResult
+ init(const sk::VulkanApi& vk, const sk::Device& device, uint32_t numImages);
+
+ std::vector<sk::Semaphore> imageAvailable{};
+ std::vector<sk::Semaphore> renderFinished{};
+ std::vector<sk::Fence> inFlight{};
+ size_t currentFrame{};
+};
+
+/// Renderer that owns the above and everything required to draw
+struct Renderer {
+ VkResult init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const RectData& rectData,
+ const RectShaders& rectShaders,
+ VkExtent2D extent,
+ bool resizing);
+
+ VkResult recreate(const sk::VulkanApi& vk,
+ const sk::SurfaceKHR& surface,
+ const GraphicsDevice& gpu,
+ const RectData& rectData,
+ const RectShaders& rectShaders,
+ VkExtent2D extent,
+ bool resizing);
+
+ Swapchain swapchain;
+ RenderPass renderPass;
+ RectPipeline rectPipeline;
+ RenderSync sync;
+};
+
+VkResult
+selectSurfaceFormat(const sk::VulkanApi& vk,
+ const sk::PhysicalDevice& physicalDevice,
+ const sk::SurfaceKHR& surface,
+ VkSurfaceFormatKHR& surfaceFormat)
+{
+ std::vector<VkSurfaceFormatKHR> formats;
+ if (VkResult r = vk.getPhysicalDeviceSurfaceFormatsKHR(physicalDevice,
+ surface,
+ formats)) {
+ return r;
+ }
+
+ for (const auto& format : formats) {
+ if (format.format == VK_FORMAT_B8G8R8A8_UNORM &&
+ format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
+ surfaceFormat = format;
+ return VK_SUCCESS;
+ }
+ }
+
+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
+}
+
+VkResult
+selectPresentMode(const sk::VulkanApi& vk,
+ const sk::PhysicalDevice& physicalDevice,
+ const sk::SurfaceKHR& surface,
+ const bool multiBuffer,
+ const bool sync,
+ VkPresentModeKHR& presentMode)
+{
+ // Map command line options to mode priorities
+ static constexpr VkPresentModeKHR priorities[][2][4] = {
+ {
+ // No double buffer, no sync
+ {VK_PRESENT_MODE_IMMEDIATE_KHR,
+ VK_PRESENT_MODE_MAILBOX_KHR,
+ VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+ VK_PRESENT_MODE_FIFO_KHR},
+
+ // No double buffer, sync (nonsense, map to FIFO relaxed)
+ {VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+ VK_PRESENT_MODE_FIFO_KHR,
+ VK_PRESENT_MODE_MAILBOX_KHR,
+ VK_PRESENT_MODE_IMMEDIATE_KHR},
+ },
+ {
+ // Double buffer, no sync
+ {
+ VK_PRESENT_MODE_MAILBOX_KHR,
+ VK_PRESENT_MODE_IMMEDIATE_KHR,
+ VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+ VK_PRESENT_MODE_FIFO_KHR,
+ },
+
+ // Double buffer, sync
+ {VK_PRESENT_MODE_FIFO_KHR,
+ VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+ VK_PRESENT_MODE_MAILBOX_KHR,
+ VK_PRESENT_MODE_IMMEDIATE_KHR},
+ },
+ };
+
+ std::vector<VkPresentModeKHR> modes;
+ if (VkResult r = vk.getPhysicalDeviceSurfacePresentModesKHR(physicalDevice,
+ surface,
+ modes)) {
+ return r;
+ }
+
+ const auto& tryModes = priorities[bool(multiBuffer)][bool(sync)];
+ for (const auto m : tryModes) {
+ if (std::find(modes.begin(), modes.end(), m) != modes.end()) {
+ presentMode = m;
+ return VK_SUCCESS;
+ }
+ }
+
+ return VK_ERROR_INCOMPATIBLE_DRIVER;
+}
+
+VkResult
+openDevice(const sk::VulkanApi& vk,
+ const sk::PhysicalDevice& physicalDevice,
+ const uint32_t graphicsFamilyIndex,
+ sk::Device& device)
+{
+ const float graphicsQueuePriority = 1.0f;
+ const char* const swapchainName = "VK_KHR_swapchain";
+
+ const VkDeviceQueueCreateInfo queueCreateInfo{
+ VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
+ nullptr,
+ 0u,
+ graphicsFamilyIndex,
+ SK_COUNTED(1u, &graphicsQueuePriority),
+ };
+
+ const VkDeviceCreateInfo createInfo{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ nullptr,
+ 0u,
+ SK_COUNTED(1u, &queueCreateInfo),
+ SK_COUNTED(0u, nullptr), // Deprecated
+ SK_COUNTED(1u, &swapchainName),
+ nullptr};
+
+ return vk.createDevice(physicalDevice, createInfo, device);
+}
+
+/// Return whether the physical device supports the extensions we require
+VkResult
+deviceSupportsRequiredExtensions(const sk::VulkanApi& vk,
+ const sk::PhysicalDevice& device,
+ bool& supported)
+{
+ VkResult r = VK_SUCCESS;
+
+ std::vector<VkExtensionProperties> props;
+ if ((r = vk.enumerateDeviceExtensionProperties(device, props))) {
+ return r;
+ }
+
+ supported = std::any_of(props.begin(),
+ props.end(),
+ [&](const VkExtensionProperties& e) {
+ return !strcmp(e.extensionName,
+ "VK_KHR_swapchain");
+ });
+
+ return VK_SUCCESS;
+}
+
+/// Return the index of the graphics queue, if there is one
+VkResult
+findGraphicsQueue(const sk::VulkanApi& vk,
+ const sk::SurfaceKHR& surface,
+ const sk::PhysicalDevice& device,
+ uint32_t& queueIndex)
+{
+ VkResult r = VK_SUCCESS;
+
+ std::vector<VkQueueFamilyProperties> queueProps;
+ if ((r = vk.getPhysicalDeviceQueueFamilyProperties(device, queueProps))) {
+ return r;
+ }
+
+ for (uint32_t q = 0u; q < queueProps.size(); ++q) {
+ if (queueProps[q].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
+ bool supported = false;
+ if ((r = vk.getPhysicalDeviceSurfaceSupportKHR(
+ device, q, surface, supported))) {
+ return r;
+ }
+
+ if (supported) {
+ queueIndex = q;
+ return VK_SUCCESS;
+ }
+ }
+ }
+
+ return VK_ERROR_FEATURE_NOT_PRESENT;
+}
+
+/// Select a physical graphics device to use (simply the first found)
+VkResult
+selectPhysicalDevice(const sk::VulkanApi& vk,
+ const sk::Instance& instance,
+ const sk::SurfaceKHR& surface,
+ PhysicalDeviceSelection& selection)
+{
+ VkResult r = VK_SUCCESS;
+
+ std::vector<sk::PhysicalDevice> devices;
+ if ((r = vk.enumeratePhysicalDevices(instance, devices))) {
+ return r;
+ }
+
+ for (const auto& device : devices) {
+ auto supported = false;
+ if ((r = deviceSupportsRequiredExtensions(vk, device, supported))) {
+ return r;
+ }
+
+ if (supported) {
+ auto queueIndex = 0u;
+ if ((r = findGraphicsQueue(vk, surface, device, queueIndex))) {
+ return r;
+ }
+
+ selection = PhysicalDeviceSelection{device, queueIndex};
+ return VK_SUCCESS;
+ }
+ }
+
+ return VK_ERROR_INCOMPATIBLE_DISPLAY_KHR;
+}
+
+VkResult
+GraphicsDevice::init(const pugl::VulkanLoader& loader,
+ const VulkanContext& context,
+ pugl::View& view,
+ const PuglTestOptions& opts)
+{
+ const auto& vk = context.vk;
+ VkResult r = VK_SUCCESS;
+
+ // Create a Vulkan surface for the window using the Pugl API
+ VkSurfaceKHR surfaceHandle = {};
+ if ((r = pugl::createSurface(loader.getInstanceProcAddrFunc(),
+ view,
+ context.instance,
+ nullptr,
+ &surfaceHandle))) {
+ return r;
+ }
+
+ // Wrap surface in a safe RAII handle
+ surface = sk::SurfaceKHR{surfaceHandle,
+ {context.instance, vk.vkDestroySurfaceKHR}};
+
+ PhysicalDeviceSelection physicalDeviceSelection = {};
+ // Select a physical device to use
+ if ((r = selectPhysicalDevice(
+ vk, context.instance, surface, physicalDeviceSelection))) {
+ return r;
+ }
+
+ physicalDevice = physicalDeviceSelection.physicalDevice;
+ graphicsIndex = physicalDeviceSelection.graphicsFamilyIndex;
+
+ if ((r = selectSurfaceFormat(vk, physicalDevice, surface, surfaceFormat)) ||
+ (r = selectPresentMode(vk,
+ physicalDevice,
+ surface,
+ opts.doubleBuffer,
+ opts.sync,
+ presentMode)) ||
+ (r = selectPresentMode(
+ vk, physicalDevice, surface, true, false, resizePresentMode)) ||
+ (r = openDevice(vk, physicalDevice, graphicsIndex, device))) {
+ return r;
+ }
+
+ const VkCommandPoolCreateInfo commandPoolInfo{
+ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, {}, graphicsIndex};
+
+ if ((r = vk.createCommandPool(device, commandPoolInfo, commandPool))) {
+ return r;
+ }
+
+ graphicsQueue = vk.getDeviceQueue(device, graphicsIndex, 0);
+ return VK_SUCCESS;
+}
+
+uint32_t
+findMemoryType(const sk::VulkanApi& vk,
+ const sk::PhysicalDevice& physicalDevice,
+ const uint32_t typeFilter,
+ const VkMemoryPropertyFlags& properties)
+{
+ VkPhysicalDeviceMemoryProperties memProperties =
+ vk.getPhysicalDeviceMemoryProperties(physicalDevice);
+
+ for (uint32_t i = 0; i < memProperties.memoryTypeCount; ++i) {
+ if ((typeFilter & (1 << i)) &&
+ (memProperties.memoryTypes[i].propertyFlags & properties) ==
+ properties) {
+ return i;
+ }
+ }
+
+ return UINT32_MAX;
+}
+
+VkResult
+Buffer::init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const VkDeviceSize size,
+ const VkBufferUsageFlags usage,
+ const VkMemoryPropertyFlags properties)
+{
+ const VkBufferCreateInfo bufferInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+ nullptr,
+ {},
+ size,
+ usage,
+ VK_SHARING_MODE_EXCLUSIVE,
+ SK_COUNTED(0, nullptr)};
+
+ const auto& device = gpu.device;
+
+ VkResult r = VK_SUCCESS;
+ if ((r = vk.createBuffer(device, bufferInfo, buffer))) {
+ return r;
+ }
+
+ const auto requirements = vk.getBufferMemoryRequirements(device, buffer);
+ const auto memoryTypeIndex = findMemoryType(vk,
+ gpu.physicalDevice,
+ requirements.memoryTypeBits,
+ properties);
+
+ if (memoryTypeIndex == UINT32_MAX) {
+ return VK_ERROR_FEATURE_NOT_PRESENT;
+ }
+
+ const VkMemoryAllocateInfo allocInfo{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ nullptr,
+ requirements.size,
+ memoryTypeIndex};
+
+ if ((r = vk.allocateMemory(device, allocInfo, deviceMemory)) ||
+ (r = vk.bindBufferMemory(device, buffer, deviceMemory, 0))) {
+ return r;
+ }
+
+ return VK_SUCCESS;
+}
+
+VkResult
+Swapchain::init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const VkSurfaceCapabilitiesKHR surfaceCapabilities,
+ const VkExtent2D surfaceExtent,
+ VkSwapchainKHR oldSwapchain,
+ bool resizing)
+{
+ capabilities = surfaceCapabilities;
+ extent = surfaceExtent;
+
+ const auto minNumImages = (!capabilities.maxImageCount ||
+ capabilities.maxImageCount >= 3u)
+ ? 3u
+ : capabilities.maxImageCount;
+
+ const VkSwapchainCreateInfoKHR swapchainCreateInfo{
+ VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
+ nullptr,
+ {},
+ gpu.surface,
+ minNumImages,
+ gpu.surfaceFormat.format,
+ gpu.surfaceFormat.colorSpace,
+ surfaceExtent,
+ 1,
+ (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
+ VK_SHARING_MODE_EXCLUSIVE,
+ SK_COUNTED(0, nullptr),
+ capabilities.currentTransform,
+ VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR,
+ resizing ? gpu.resizePresentMode : gpu.presentMode,
+ VK_TRUE,
+ oldSwapchain};
+
+ VkResult r = VK_SUCCESS;
+ std::vector<VkImage> images;
+ if ((r = vk.createSwapchainKHR(gpu.device,
+ swapchainCreateInfo,
+ swapchain)) ||
+ (r = vk.getSwapchainImagesKHR(gpu.device, swapchain, images))) {
+ return r;
+ }
+
+ imageViews = std::vector<sk::ImageView>(images.size());
+ for (size_t i = 0; i < images.size(); ++i) {
+ const VkImageViewCreateInfo imageViewCreateInfo{
+ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
+ nullptr,
+ {},
+ images[i],
+ VK_IMAGE_VIEW_TYPE_2D,
+ gpu.surfaceFormat.format,
+ {},
+ {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
+
+ if ((r = vk.createImageView(gpu.device,
+ imageViewCreateInfo,
+ imageViews[i]))) {
+ return r;
+ }
+ }
+
+ return VK_SUCCESS;
+}
+
+VkResult
+RenderPass::init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const Swapchain& swapchain)
+{
+ const auto numImages = static_cast<uint32_t>(swapchain.imageViews.size());
+
+ assert(numImages > 0);
+
+ // Create command buffers
+ const VkCommandBufferAllocateInfo commandBufferAllocateInfo{
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+ nullptr,
+ gpu.commandPool,
+ VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+ numImages};
+
+ VkResult r = VK_SUCCESS;
+ if ((r = vk.allocateCommandBuffers(gpu.device,
+ commandBufferAllocateInfo,
+ commandBuffers))) {
+ return r;
+ }
+
+ static constexpr VkAttachmentReference colorAttachmentRef{
+ 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
+
+ static constexpr VkSubpassDescription subpass{
+ {},
+ VK_PIPELINE_BIND_POINT_GRAPHICS,
+ SK_COUNTED(0, nullptr),
+ SK_COUNTED(1, &colorAttachmentRef, nullptr, nullptr),
+ SK_COUNTED(0u, nullptr)};
+
+ static constexpr VkSubpassDependency dependency{
+ VK_SUBPASS_EXTERNAL,
+ 0,
+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
+ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT),
+ {},
+ {}};
+
+ const VkAttachmentDescription colorAttachment{
+ {},
+ gpu.surfaceFormat.format,
+ VK_SAMPLE_COUNT_1_BIT,
+ VK_ATTACHMENT_LOAD_OP_CLEAR,
+ VK_ATTACHMENT_STORE_OP_STORE,
+ VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ VK_ATTACHMENT_STORE_OP_DONT_CARE,
+ VK_IMAGE_LAYOUT_UNDEFINED,
+ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
+ };
+
+ const VkRenderPassCreateInfo renderPassCreateInfo{
+ VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
+ nullptr,
+ {},
+ SK_COUNTED(1, &colorAttachment),
+ SK_COUNTED(1, &subpass),
+ SK_COUNTED(1, &dependency)};
+
+ if ((r = vk.createRenderPass(gpu.device,
+ renderPassCreateInfo,
+ renderPass))) {
+ return r;
+ }
+
+ // Create framebuffers
+ framebuffers = std::vector<sk::Framebuffer>(numImages);
+ for (uint32_t i = 0; i < numImages; ++i) {
+ const VkFramebufferCreateInfo framebufferCreateInfo{
+ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
+ nullptr,
+ {},
+ renderPass,
+ SK_COUNTED(1, &swapchain.imageViews[i].get()),
+ swapchain.extent.width,
+ swapchain.extent.height,
+ 1};
+
+ if ((r = vk.createFramebuffer(gpu.device,
+ framebufferCreateInfo,
+ framebuffers[i]))) {
+ return r;
+ }
+ }
+
+ return VK_SUCCESS;
+}
+
+std::vector<uint32_t>
+readFile(const char* const programPath, const std::string& filename)
+{
+ std::unique_ptr<char, decltype(&free)> path{resourcePath(programPath,
+ filename.c_str()),
+ &free};
+
+ std::cerr << "Loading shader: " << path.get() << std::endl;
+
+ std::unique_ptr<FILE, decltype(&fclose)> file{fopen(path.get(), "rb"),
+ &fclose};
+
+ if (!file) {
+ std::cerr << "Failed to open file '" << filename << "'\n";
+ return {};
+ }
+
+ fseek(file.get(), 0, SEEK_END);
+ const auto fileSize = static_cast<size_t>(ftell(file.get()));
+ fseek(file.get(), 0, SEEK_SET);
+
+ const auto numWords = fileSize / sizeof(uint32_t);
+ std::vector<uint32_t> buffer(numWords);
+
+ fread(buffer.data(), sizeof(uint32_t), numWords, file.get());
+
+ return buffer;
+}
+
+VkResult
+createShaderModule(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const std::vector<uint32_t>& code,
+ sk::ShaderModule& shaderModule)
+{
+ const VkShaderModuleCreateInfo createInfo{
+ VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
+ nullptr,
+ {},
+ code.size() * sizeof(uint32_t),
+ code.data()};
+
+ return vk.createShaderModule(gpu.device, createInfo, shaderModule);
+}
+
+VkResult
+RectShaders::init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const std::string& programPath)
+{
+ auto vertShaderCode = readFile(programPath.c_str(),
+ "shaders/rect.vert.spv");
+
+ auto fragShaderCode = readFile(programPath.c_str(),
+ "shaders/rect.frag.spv");
+
+ if (vertShaderCode.empty() || fragShaderCode.empty()) {
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+ VkResult r = VK_SUCCESS;
+ if ((r = createShaderModule(vk, gpu, vertShaderCode, vert)) ||
+ (r = createShaderModule(vk, gpu, fragShaderCode, frag))) {
+ return r;
+ }
+
+ return VK_SUCCESS;
+}
+
+VkResult
+RectPipeline::init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const RectData& rectData,
+ const RectShaders& shaders,
+ const Swapchain& swapchain,
+ const RenderPass& renderPass)
+{
+ const auto oldNumImages = numImages;
+ VkResult r = VK_SUCCESS;
+
+ numImages = static_cast<uint32_t>(swapchain.imageViews.size());
+ pipelines = {};
+ pipelineLayout = {};
+ descriptorSets = {};
+
+ if (numImages != oldNumImages) {
+ // Create layout descriptor pool
+
+ const VkDescriptorPoolSize poolSize{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ numImages};
+
+ const VkDescriptorPoolCreateInfo descriptorPoolCreateInfo{
+ VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+ nullptr,
+ VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
+ numImages,
+ 1u,
+ &poolSize};
+ if ((r = vk.createDescriptorPool(gpu.device,
+ descriptorPoolCreateInfo,
+ descriptorPool))) {
+ return r;
+ }
+ }
+
+ const std::vector<VkDescriptorSetLayout> layouts(
+ numImages, rectData.descriptorSetLayout.get());
+
+ const VkDescriptorSetAllocateInfo descriptorSetAllocateInfo{
+ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
+ nullptr,
+ descriptorPool,
+ numImages,
+ layouts.data()};
+ if ((r = vk.allocateDescriptorSets(gpu.device,
+ descriptorSetAllocateInfo,
+ descriptorSets))) {
+ return r;
+ }
+
+ const VkDescriptorBufferInfo bufferInfo{rectData.uniformBuffer.buffer,
+ 0,
+ sizeof(UniformBufferObject)};
+
+ const std::array<VkWriteDescriptorSet, 1> descriptorWrites{
+ {{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
+ nullptr,
+ descriptorSets[0],
+ 0,
+ 0,
+ 1,
+ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ nullptr,
+ &bufferInfo,
+ nullptr}}};
+
+ const std::array<VkCopyDescriptorSet, 0> descriptorCopies{};
+
+ vk.updateDescriptorSets(gpu.device, descriptorWrites, descriptorCopies);
+
+ static constexpr std::array<VkVertexInputAttributeDescription, 4>
+ vertexAttributeDescriptions{
+ {// Model
+ {0u, 0u, VK_FORMAT_R32G32_SFLOAT, 0},
+
+ // Rect instance attributes
+ {1u, 1u, VK_FORMAT_R32G32_SFLOAT, offsetof(Rect, pos)},
+ {2u, 1u, VK_FORMAT_R32G32_SFLOAT, offsetof(Rect, size)},
+ {3u,
+ 1u,
+ VK_FORMAT_R32G32B32A32_SFLOAT,
+ offsetof(Rect, fillColor)}}};
+
+ static constexpr std::array<VkVertexInputBindingDescription, 2>
+ vertexBindingDescriptions{
+ VkVertexInputBindingDescription{0,
+ sizeof(vec2),
+ VK_VERTEX_INPUT_RATE_VERTEX},
+ VkVertexInputBindingDescription{1u,
+ sizeof(Rect),
+ VK_VERTEX_INPUT_RATE_INSTANCE}};
+
+ static constexpr VkPipelineInputAssemblyStateCreateInfo inputAssembly{
+ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
+ nullptr,
+ {},
+ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
+ false};
+
+ static constexpr VkPipelineRasterizationStateCreateInfo rasterizer{
+ VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
+ nullptr,
+ {},
+ 0,
+ 0,
+ VK_POLYGON_MODE_FILL,
+ VK_CULL_MODE_BACK_BIT,
+ VK_FRONT_FACE_CLOCKWISE,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1.0f};
+
+ static constexpr VkPipelineMultisampleStateCreateInfo multisampling{
+ VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
+ nullptr,
+ {},
+ VK_SAMPLE_COUNT_1_BIT,
+ false,
+ 0.0f,
+ nullptr,
+ false,
+ false};
+
+ static constexpr VkPipelineColorBlendAttachmentState colorBlendAttachment{
+ true,
+ VK_BLEND_FACTOR_SRC_ALPHA,
+ VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+ VK_BLEND_OP_ADD,
+ VK_BLEND_FACTOR_ONE,
+ VK_BLEND_FACTOR_ZERO,
+ VK_BLEND_OP_ADD,
+ (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
+ VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT)};
+
+ const VkPipelineShaderStageCreateInfo shaderStages[] = {
+ {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
+ nullptr,
+ {},
+ VK_SHADER_STAGE_VERTEX_BIT,
+ shaders.vert.get(),
+ "main",
+ nullptr},
+ {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
+ nullptr,
+ {},
+ VK_SHADER_STAGE_FRAGMENT_BIT,
+ shaders.frag.get(),
+ "main",
+ nullptr}};
+
+ const VkPipelineVertexInputStateCreateInfo vertexInputInfo{
+ VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+ nullptr,
+ {},
+ SK_COUNTED(static_cast<uint32_t>(vertexBindingDescriptions.size()),
+ vertexBindingDescriptions.data()),
+ SK_COUNTED(static_cast<uint32_t>(vertexAttributeDescriptions.size()),
+ vertexAttributeDescriptions.data())};
+
+ const VkViewport viewport{0.0f,
+ 0.0f,
+ float(swapchain.extent.width),
+ float(swapchain.extent.height),
+ 0.0f,
+ 1.0f};
+
+ const VkRect2D scissor{{0, 0}, swapchain.extent};
+
+ const VkPipelineViewportStateCreateInfo viewportState{
+ VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
+ nullptr,
+ {},
+ SK_COUNTED(1, &viewport),
+ SK_COUNTED(1, &scissor)};
+
+ const VkPipelineColorBlendStateCreateInfo colorBlending{
+ VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
+ nullptr,
+ {},
+ false,
+ VK_LOGIC_OP_COPY,
+ SK_COUNTED(1, &colorBlendAttachment),
+ {1.0f, 0.0f, 0.0f, 0.0f}};
+
+ const VkPipelineLayoutCreateInfo layoutInfo{
+ VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
+ nullptr,
+ {},
+ SK_COUNTED(1, &rectData.descriptorSetLayout.get()),
+ SK_COUNTED(0, nullptr)};
+
+ if ((r = vk.createPipelineLayout(gpu.device, layoutInfo, pipelineLayout))) {
+ return r;
+ }
+
+ const std::array<VkGraphicsPipelineCreateInfo, 1> pipelineInfos{
+ {{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
+ nullptr,
+ {},
+ SK_COUNTED(2, shaderStages),
+ &vertexInputInfo,
+ &inputAssembly,
+ nullptr,
+ &viewportState,
+ &rasterizer,
+ &multisampling,
+ nullptr,
+ &colorBlending,
+ nullptr,
+ pipelineLayout,
+ renderPass.renderPass,
+ 0u,
+ {},
+ 0}}};
+
+ if ((r = vk.createGraphicsPipelines(
+ gpu.device, {}, pipelineInfos, pipelines))) {
+ return r;
+ }
+
+ return VK_SUCCESS;
+}
+
+VkResult
+RectData::init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const size_t nRects)
+{
+ numRects = nRects;
+
+ static constexpr VkDescriptorSetLayoutBinding uboLayoutBinding{
+ 0,
+ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ 1,
+ VK_SHADER_STAGE_VERTEX_BIT,
+ nullptr};
+
+ const VkDescriptorSetLayoutCreateInfo descriptorSetLayoutInfo{
+ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
+ nullptr,
+ {},
+ 1,
+ &uboLayoutBinding};
+
+ VkResult r = VK_SUCCESS;
+ if ((r = vk.createDescriptorSetLayout(gpu.device,
+ descriptorSetLayoutInfo,
+ descriptorSetLayout)) ||
+ (r = uniformBuffer.init(vk,
+ gpu,
+ sizeof(UniformBufferObject),
+ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
+ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) ||
+ (r = vk.mapMemory(gpu.device,
+ uniformBuffer.deviceMemory,
+ 0,
+ sizeof(UniformBufferObject),
+ {},
+ uniformData))) {
+ return r;
+ }
+
+ const VkBufferUsageFlags usageFlags = (VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
+ VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
+ VK_BUFFER_USAGE_TRANSFER_DST_BIT);
+
+ const VkMemoryPropertyFlags propertyFlags =
+ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
+ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
+
+ if ((r = modelBuffer.init(
+ vk, gpu, sizeof(rectVertices), usageFlags, propertyFlags))) {
+ return r;
+ }
+
+ {
+ // Copy model vertices (directly, we do this only once)
+ sk::MappedMemory modelData;
+ if ((r = vk.mapMemory(gpu.device,
+ modelBuffer.deviceMemory,
+ 0,
+ static_cast<VkDeviceSize>(sizeof(rectVertices)),
+ {},
+ modelData))) {
+ return r;
+ }
+
+ memcpy(modelData.get(), rectVertices, sizeof(rectVertices));
+ }
+
+ if ((r = instanceBuffer.init(
+ vk, gpu, sizeof(Rect) * numRects, usageFlags, propertyFlags))) {
+ return r;
+ }
+
+ // Map attribute vertices (we will update them every frame)
+ const auto rectsSize = static_cast<VkDeviceSize>(sizeof(Rect) * numRects);
+ if ((r = vk.mapMemory(gpu.device,
+ instanceBuffer.deviceMemory,
+ 0,
+ rectsSize,
+ {},
+ vertexData))) {
+ return r;
+ }
+
+ return VK_SUCCESS;
+}
+
+VkResult
+RenderSync::init(const sk::VulkanApi& vk,
+ const sk::Device& device,
+ const uint32_t numImages)
+{
+ const auto maxInFlight = std::max(1u, numImages - 1u);
+ VkResult r = VK_SUCCESS;
+
+ imageAvailable = std::vector<sk::Semaphore>(numImages);
+ renderFinished = std::vector<sk::Semaphore>(numImages);
+ for (uint32_t i = 0; i < numImages; ++i) {
+ static constexpr VkSemaphoreCreateInfo semaphoreInfo{
+ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, {}};
+
+ if ((r = vk.createSemaphore(device,
+ semaphoreInfo,
+ imageAvailable[i])) ||
+ (r = vk.createSemaphore(device,
+ semaphoreInfo,
+ renderFinished[i]))) {
+ return r;
+ }
+ }
+
+ inFlight = std::vector<sk::Fence>(maxInFlight);
+ for (uint32_t i = 0; i < maxInFlight; ++i) {
+ static constexpr VkFenceCreateInfo fenceInfo{
+ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
+ nullptr,
+ VK_FENCE_CREATE_SIGNALED_BIT};
+
+ if ((r = vk.createFence(device, fenceInfo, inFlight[i]))) {
+ return r;
+ }
+ }
+
+ return VK_SUCCESS;
+}
+
+VkResult
+Renderer::init(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const RectData& rectData,
+ const RectShaders& rectShaders,
+ const VkExtent2D extent,
+ bool resizing)
+{
+ VkResult r = VK_SUCCESS;
+ VkSurfaceCapabilitiesKHR capabilities = {};
+
+ if ((r = vk.getPhysicalDeviceSurfaceCapabilitiesKHR(gpu.physicalDevice,
+ gpu.surface,
+ capabilities)) ||
+ (r = swapchain.init(vk, gpu, capabilities, extent, {}, resizing)) ||
+ (r = renderPass.init(vk, gpu, swapchain)) ||
+ (r = rectPipeline.init(
+ vk, gpu, rectData, rectShaders, swapchain, renderPass))) {
+ return r;
+ }
+
+ const auto numFrames = static_cast<uint32_t>(swapchain.imageViews.size());
+ return sync.init(vk, gpu.device, numFrames);
+}
+
+VkResult
+Renderer::recreate(const sk::VulkanApi& vk,
+ const sk::SurfaceKHR& surface,
+ const GraphicsDevice& gpu,
+ const RectData& rectData,
+ const RectShaders& rectShaders,
+ const VkExtent2D extent,
+ bool resizing)
+{
+ VkResult r = VK_SUCCESS;
+ const auto oldNumImages = swapchain.imageViews.size();
+
+ VkSurfaceCapabilitiesKHR capabilities = {};
+ if ((r = vk.getPhysicalDeviceSurfaceCapabilitiesKHR(gpu.physicalDevice,
+ surface,
+ capabilities)) ||
+ (r = swapchain.init(
+ vk, gpu, capabilities, extent, swapchain.swapchain, resizing)) ||
+ (r = renderPass.init(vk, gpu, swapchain)) ||
+ (r = rectPipeline.init(
+ vk, gpu, rectData, rectShaders, swapchain, renderPass))) {
+ return r;
+ }
+
+ const auto numFrames = static_cast<uint32_t>(swapchain.imageViews.size());
+ if (swapchain.imageViews.size() != oldNumImages) {
+ return sync.init(vk, gpu.device, numFrames);
+ }
+
+ return VK_SUCCESS;
+}
+
+VKAPI_ATTR
+VkBool32 VKAPI_CALL
+debugCallback(VkDebugReportFlagsEXT flags,
+ VkDebugReportObjectTypeEXT,
+ uint64_t,
+ size_t,
+ int32_t,
+ const char* layerPrefix,
+ const char* msg,
+ void*)
+{
+ std::cerr << sk::string(static_cast<VkDebugReportFlagBitsEXT>(flags))
+ << ": " << layerPrefix << ": " << msg << std::endl;
+
+ return VK_FALSE;
+}
+
+bool
+hasExtension(const char* name,
+ const std::vector<VkExtensionProperties>& properties)
+{
+ for (const auto& p : properties) {
+ if (!strcmp(p.extensionName, name)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool
+hasLayer(const char* name, const std::vector<VkLayerProperties>& properties)
+{
+ for (const auto& p : properties) {
+ if (!strcmp(p.layerName, name)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+template<class Value>
+void
+logInfo(const char* heading, const Value& value)
+{
+ std::cout << std::setw(26) << std::left << (std::string(heading) + ":")
+ << value << std::endl;
+}
+
+VkResult
+createInstance(sk::VulkanInitApi& initApi,
+ const PuglTestOptions& opts,
+ sk::Instance& instance)
+{
+ VkResult r = VK_SUCCESS;
+
+ std::vector<VkLayerProperties> layerProps;
+ std::vector<VkExtensionProperties> extProps;
+ if ((r = initApi.enumerateInstanceLayerProperties(layerProps)) ||
+ (r = initApi.enumerateInstanceExtensionProperties(extProps))) {
+ return r;
+ }
+
+ const auto puglExtensions = pugl::getInstanceExtensions();
+ auto extensions = std::vector<const char*>(puglExtensions.begin(),
+ puglExtensions.end());
+
+ // Add extra extensions we want to use if they are supported
+ if (hasExtension("VK_EXT_debug_report", extProps)) {
+ extensions.push_back("VK_EXT_debug_report");
+ }
+
+ // Add validation layers if error checking is enabled
+ std::vector<const char*> layers;
+ if (opts.errorChecking) {
+ for (const char* l : {"VK_LAYER_KHRONOS_validation",
+ "VK_LAYER_LUNARG_standard_validation"}) {
+ if (hasLayer(l, layerProps)) {
+ layers.push_back(l);
+ }
+ }
+ }
+
+ for (const auto& e : extensions) {
+ logInfo("Using instance extension", e);
+ }
+
+ for (const auto& l : layers) {
+ logInfo("Using instance layer", l);
+ }
+
+ static constexpr VkApplicationInfo appInfo{
+ VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ nullptr,
+ "Pugl Vulkan Demo",
+ 0,
+ nullptr,
+ 0,
+ VK_MAKE_VERSION(1, 0, 0),
+ };
+
+ const VkInstanceCreateInfo createInfo{
+ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ nullptr,
+ VkInstanceCreateFlags{},
+ &appInfo,
+ SK_COUNTED(uint32_t(layers.size()), layers.data()),
+ SK_COUNTED(uint32_t(extensions.size()), extensions.data())};
+
+ return initApi.createInstance(createInfo, instance);
+}
+
+VkResult
+getDebugReportCallback(sk::VulkanApi& api,
+ sk::Instance& instance,
+ const bool verbose,
+ sk::DebugReportCallbackEXT& callback)
+{
+ if (api.vkCreateDebugReportCallbackEXT) {
+ VkDebugReportFlagsEXT flags =
+ (VK_DEBUG_REPORT_WARNING_BIT_EXT |
+ VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
+ VK_DEBUG_REPORT_ERROR_BIT_EXT);
+
+ if (verbose) {
+ flags |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
+ flags |= VK_DEBUG_REPORT_DEBUG_BIT_EXT;
+ }
+
+ const VkDebugReportCallbackCreateInfoEXT createInfo{
+ VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT,
+ nullptr,
+ flags,
+ debugCallback,
+ nullptr};
+
+ return api.createDebugReportCallbackEXT(instance, createInfo, callback);
+ }
+
+ return VK_ERROR_FEATURE_NOT_PRESENT;
+}
+
+void
+recordCommandBuffer(sk::CommandScope& cmd,
+ const Swapchain& swapchain,
+ const RenderPass& renderPass,
+ const RectPipeline& rectPipeline,
+ const RectData& rectData,
+ const size_t imageIndex)
+{
+ const VkClearColorValue clearColorValue{{0.0f, 0.0f, 0.0f, 1.0f}};
+ const VkClearValue clearValue{clearColorValue};
+
+ const VkRenderPassBeginInfo renderPassBegin{
+ VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
+ nullptr,
+ renderPass.renderPass,
+ renderPass.framebuffers[imageIndex],
+ VkRect2D{{0, 0}, swapchain.extent},
+ SK_COUNTED(1, &clearValue)};
+
+ auto pass = cmd.beginRenderPass(renderPassBegin,
+ VK_SUBPASS_CONTENTS_INLINE);
+
+ pass.bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS,
+ rectPipeline.pipelines[0]);
+
+ const std::array<VkDeviceSize, 1> offsets{0};
+ pass.bindVertexBuffers(
+ 0u, SK_COUNTED(1u, &rectData.modelBuffer.buffer.get(), offsets.data()));
+
+ pass.bindVertexBuffers(1u,
+ SK_COUNTED(1u,
+ &rectData.instanceBuffer.buffer.get(),
+ offsets.data()));
+
+ pass.bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS,
+ rectPipeline.pipelineLayout,
+ 0u,
+ SK_COUNTED(1u, rectPipeline.descriptorSets.get()),
+ 0u,
+ nullptr);
+
+ pass.draw(4u, static_cast<uint32_t>(rectData.numRects), 0u, 0u);
+}
+
+VkResult
+recordCommandBuffers(const sk::VulkanApi& vk,
+ const Swapchain& swapchain,
+ const RenderPass& renderPass,
+ const RectPipeline& rectPipeline,
+ const RectData& rectData)
+{
+ VkResult r = VK_SUCCESS;
+
+ for (size_t i = 0; i < swapchain.imageViews.size(); ++i) {
+ const VkCommandBufferBeginInfo beginInfo{
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
+ nullptr,
+ VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
+ nullptr};
+
+ auto* const commandBuffer = renderPass.commandBuffers[i];
+ auto cmd = vk.beginCommandBuffer(commandBuffer, beginInfo);
+ if (!cmd) {
+ return cmd.error();
+ }
+
+ recordCommandBuffer(
+ cmd, swapchain, renderPass, rectPipeline, rectData, i);
+
+ if ((r = cmd.end())) {
+ return r;
+ }
+ }
+
+ return VK_SUCCESS;
+}
+
+class PuglVulkanDemo;
+
+class View : public pugl::View
+{
+public:
+ View(pugl::World& world, PuglVulkanDemo& app)
+ : pugl::View{world}
+ , _app{app}
+ {
+ setEventHandler(*this);
+ }
+
+ template<PuglEventType t, class Base>
+ pugl::Status onEvent(const pugl::Event<t, Base>&) noexcept
+ {
+ return pugl::Status::success;
+ }
+
+ pugl::Status onEvent(const pugl::ConfigureEvent& event);
+ pugl::Status onEvent(const pugl::UpdateEvent& event);
+ pugl::Status onEvent(const pugl::ExposeEvent& event);
+ pugl::Status onEvent(const pugl::LoopEnterEvent& event);
+ pugl::Status onEvent(const pugl::TimerEvent& event);
+ pugl::Status onEvent(const pugl::LoopLeaveEvent& event);
+ pugl::Status onEvent(const pugl::KeyPressEvent& event);
+ pugl::Status onEvent(const pugl::CloseEvent& event);
+
+private:
+ PuglVulkanDemo& _app;
+};
+
+class PuglVulkanDemo
+{
+public:
+ PuglVulkanDemo(const char* executablePath,
+ const PuglTestOptions& o,
+ size_t numRects);
+
+ const char* programPath;
+ PuglTestOptions opts;
+ pugl::World world;
+ pugl::VulkanLoader loader;
+ View view;
+ VulkanContext vulkan;
+ GraphicsDevice gpu;
+ Renderer renderer;
+ RectData rectData;
+ RectShaders rectShaders;
+ uint32_t framesDrawn{0};
+ VkExtent2D extent{512u, 512u};
+ std::vector<Rect> rects;
+ bool resizing{false};
+ bool quit{false};
+};
+
+std::vector<Rect>
+makeRects(const size_t numRects, const uint32_t windowWidth)
+{
+ std::vector<Rect> rects(numRects);
+ for (size_t i = 0; i < numRects; ++i) {
+ rects[i] = makeRect(i, static_cast<float>(windowWidth));
+ }
+
+ return rects;
+}
+
+PuglVulkanDemo::PuglVulkanDemo(const char* const executablePath,
+ const PuglTestOptions& o,
+ const size_t numRects)
+ : programPath{executablePath}
+ , opts{o}
+ , world{pugl::WorldType::program, pugl::WorldFlag::threads}
+ , loader{world}
+ , view{world, *this}
+ , rects{makeRects(numRects, extent.width)}
+{}
+
+VkResult
+recreateRenderer(PuglVulkanDemo& app,
+ const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const VkExtent2D extent,
+ const RectData& rectData,
+ const RectShaders& rectShaders)
+{
+ VkResult r = VK_SUCCESS;
+ VkSurfaceCapabilitiesKHR capabilities = {};
+ if ((r = vk.getPhysicalDeviceSurfaceCapabilitiesKHR(gpu.physicalDevice,
+ gpu.surface,
+ capabilities))) {
+ return r;
+ }
+
+ // There is a known race issue here, so we clamp and hope for the best
+ const VkExtent2D clampedExtent{
+ std::min(capabilities.maxImageExtent.width,
+ std::max(capabilities.minImageExtent.width, extent.width)),
+ std::min(capabilities.maxImageExtent.height,
+ std::max(capabilities.minImageExtent.height, extent.height))};
+
+ if ((r = vk.deviceWaitIdle(gpu.device)) ||
+ (r = app.renderer.recreate(vk,
+ gpu.surface,
+ gpu,
+ rectData,
+ rectShaders,
+ clampedExtent,
+ app.resizing))) {
+ return r;
+ }
+
+ // Reset current (initially signaled) fence because we already waited
+ vk.resetFence(gpu.device,
+ app.renderer.sync.inFlight[app.renderer.sync.currentFrame]);
+
+ // Record new command buffers
+ return recordCommandBuffers(vk,
+ app.renderer.swapchain,
+ app.renderer.renderPass,
+ app.renderer.rectPipeline,
+ rectData);
+}
+
+pugl::Status
+View::onEvent(const pugl::ConfigureEvent& event)
+{
+ // We just record the size here and lazily resize the surface when exposed
+ _app.extent = {static_cast<uint32_t>(event.width),
+ static_cast<uint32_t>(event.height)};
+
+ return pugl::Status::success;
+}
+
+pugl::Status
+View::onEvent(const pugl::UpdateEvent&)
+{
+ return postRedisplay();
+}
+
+VkResult
+beginFrame(PuglVulkanDemo& app, const sk::Device& device, uint32_t& imageIndex)
+{
+ const auto& vk = app.vulkan.vk;
+
+ VkResult r = VK_SUCCESS;
+
+ // Wait until we can start rendering the next frame
+ if ((r = vk.waitForFence(
+ device,
+ app.renderer.sync.inFlight[app.renderer.sync.currentFrame])) ||
+ (r = vk.resetFence(
+ device,
+ app.renderer.sync.inFlight[app.renderer.sync.currentFrame]))) {
+ return r;
+ }
+
+ // Rebuild the renderer first if the window size has changed
+ if (app.extent.width != app.renderer.swapchain.extent.width ||
+ app.extent.height != app.renderer.swapchain.extent.height) {
+ if ((r = recreateRenderer(app,
+ vk,
+ app.gpu,
+ app.extent,
+ app.rectData,
+ app.rectShaders))) {
+ return r;
+ }
+ }
+
+ // Acquire the next image to render, rebuilding if necessary
+ while (
+ (r = vk.acquireNextImageKHR(
+ device,
+ app.renderer.swapchain.swapchain,
+ UINT64_MAX,
+ app.renderer.sync.imageAvailable[app.renderer.sync.currentFrame],
+ {},
+ &imageIndex))) {
+ switch (r) {
+ case VK_SUBOPTIMAL_KHR:
+ case VK_ERROR_OUT_OF_DATE_KHR:
+ if ((r = recreateRenderer(app,
+ vk,
+ app.gpu,
+ app.renderer.swapchain.extent,
+ app.rectData,
+ app.rectShaders))) {
+ return r;
+ }
+ continue;
+ default:
+ return r;
+ }
+ }
+
+ return VK_SUCCESS;
+}
+
+void
+update(PuglVulkanDemo& app, const double time)
+{
+ // Animate rectangles
+ for (size_t i = 0; i < app.rects.size(); ++i) {
+ moveRect(&app.rects[i],
+ i,
+ app.rects.size(),
+ static_cast<float>(app.extent.width),
+ static_cast<float>(app.extent.height),
+ time);
+ }
+
+ // Update vertex buffer
+ memcpy(app.rectData.vertexData.get(),
+ app.rects.data(),
+ sizeof(Rect) * app.rects.size());
+
+ // Update uniform buffer
+ UniformBufferObject ubo = {{}};
+ mat4Ortho(ubo.projection,
+ 0.0f,
+ float(app.renderer.swapchain.extent.width),
+ 0.0f,
+ float(app.renderer.swapchain.extent.height),
+ -1.0f,
+ 1.0f);
+
+ memcpy(app.rectData.uniformData.get(), &ubo, sizeof(ubo));
+}
+
+VkResult
+endFrame(const sk::VulkanApi& vk,
+ const GraphicsDevice& gpu,
+ const Renderer& renderer,
+ const uint32_t imageIndex)
+{
+ const auto currentFrame = renderer.sync.currentFrame;
+ VkResult r = VK_SUCCESS;
+
+ static constexpr VkPipelineStageFlags waitStage =
+ VK_PIPELINE_STAGE_TRANSFER_BIT;
+
+ const VkSubmitInfo submitInfo{
+ VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ nullptr,
+ SK_COUNTED(1, &renderer.sync.imageAvailable[currentFrame].get()),
+ &waitStage,
+ SK_COUNTED(1, &renderer.renderPass.commandBuffers[imageIndex]),
+ SK_COUNTED(1, &renderer.sync.renderFinished[imageIndex].get())};
+
+ if ((r = vk.queueSubmit(gpu.graphicsQueue,
+ submitInfo,
+ renderer.sync.inFlight[currentFrame]))) {
+ return r;
+ }
+
+ const VkPresentInfoKHR presentInfo{
+ VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
+ nullptr,
+ SK_COUNTED(1, &renderer.sync.renderFinished[imageIndex].get()),
+ SK_COUNTED(1, &renderer.swapchain.swapchain.get(), &imageIndex),
+ nullptr};
+
+ switch ((r = vk.queuePresentKHR(gpu.graphicsQueue, presentInfo))) {
+ case VK_SUCCESS: // Sucessfully presented
+ case VK_SUBOPTIMAL_KHR: // Probably a resize race, ignore
+ case VK_ERROR_OUT_OF_DATE_KHR: // Probably a resize race, ignore
+ break;
+ default:
+ return r;
+ }
+
+ return VK_SUCCESS;
+}
+
+pugl::Status
+View::onEvent(const pugl::ExposeEvent&)
+{
+ const auto& vk = _app.vulkan.vk;
+ const auto& gpu = _app.gpu;
+
+ // Acquire the next image, waiting and/or rebuilding if necessary
+ auto nextImageIndex = 0u;
+ if (beginFrame(_app, gpu.device, nextImageIndex)) {
+ return pugl::Status::unknownError;
+ }
+
+ // Ready to go, update the data to the current time
+ update(_app, world().time());
+
+ // Submit the frame to the queue and present it
+ endFrame(vk, gpu, _app.renderer, nextImageIndex);
+
+ ++_app.framesDrawn;
+ ++_app.renderer.sync.currentFrame;
+ _app.renderer.sync.currentFrame %= _app.renderer.sync.inFlight.size();
+
+ return pugl::Status::success;
+}
+
+pugl::Status
+View::onEvent(const pugl::LoopEnterEvent&)
+{
+ _app.resizing = true;
+ startTimer(resizeTimerId,
+ 1.0 / static_cast<double>(getHint(pugl::ViewHint::refreshRate)));
+
+ return pugl::Status::success;
+}
+
+pugl::Status
+View::onEvent(const pugl::TimerEvent&)
+{
+ return postRedisplay();
+}
+
+pugl::Status
+View::onEvent(const pugl::LoopLeaveEvent&)
+{
+ stopTimer(resizeTimerId);
+
+ // Trigger a swapchain recreation with the normal present mode
+ _app.renderer.swapchain.extent = {};
+ _app.resizing = false;
+
+ return pugl::Status::success;
+}
+
+pugl::Status
+View::onEvent(const pugl::KeyPressEvent& event)
+{
+ if (event.key == PUGL_KEY_ESCAPE || event.key == 'q') {
+ _app.quit = true;
+ }
+
+ return pugl::Status::success;
+}
+
+pugl::Status
+View::onEvent(const pugl::CloseEvent&)
+{
+ _app.quit = true;
+
+ return pugl::Status::success;
+}
+
+VkResult
+VulkanContext::init(pugl::VulkanLoader& loader, const PuglTestOptions& opts)
+{
+ VkResult r = VK_SUCCESS;
+
+ sk::VulkanInitApi initApi{};
+
+ // Load Vulkan API and set up the fundamentals
+ if ((r = initApi.init(loader.getInstanceProcAddrFunc())) ||
+ (r = createInstance(initApi, opts, instance)) ||
+ (r = vk.init(initApi, instance)) ||
+ (r = getDebugReportCallback(
+ vk, instance, opts.verbose, debugCallback))) {
+ return r;
+ }
+
+ return VK_SUCCESS;
+}
+
+int
+run(const char* const programPath,
+ const PuglTestOptions opts,
+ const size_t numRects)
+{
+ PuglVulkanDemo app{programPath, opts, numRects};
+
+ VkResult r = VK_SUCCESS;
+ const auto width = static_cast<int>(app.extent.width);
+ const auto height = static_cast<int>(app.extent.height);
+
+ // Realize window so we can set up Vulkan
+ app.world.setClassName("PuglVulkanDemo");
+ app.view.setWindowTitle("Pugl Vulkan Demo");
+ app.view.setAspectRatio(1, 1, 16, 9);
+ app.view.setDefaultSize(width, height);
+ app.view.setMinSize(width / 4, height / 4);
+ app.view.setBackend(pugl::vulkanBackend());
+ app.view.setHint(pugl::ViewHint::resizable, opts.resizable);
+ const pugl::Status st = app.view.realize();
+ if (st != pugl::Status::success) {
+ return logError("Failed to create window (%s)\n", pugl::strerror(st));
+ }
+
+ if (!app.loader) {
+ return logError("Failed to load Vulkan library\n");
+ }
+
+ // Load Vulkan for the view
+ if ((r = app.vulkan.init(app.loader, opts))) {
+ return logError("Failed to set up Vulkan API (%s)\n", sk::string(r));
+ }
+
+ const auto& vk = app.vulkan.vk;
+
+ // Set up the graphics device
+ if ((r = app.gpu.init(app.loader, app.vulkan, app.view, opts))) {
+ return logError("Failed to set up device (%s)\n", sk::string(r));
+ }
+
+ logInfo("Present mode", sk::string(app.gpu.presentMode));
+ logInfo("Resize present mode", sk::string(app.gpu.resizePresentMode));
+
+ // Set up the rectangle data we will render every frame
+ if ((r = app.rectData.init(vk, app.gpu, app.rects.size()))) {
+ return logError("Failed to allocate render data (%s)\n", sk::string(r));
+ }
+
+ // Load shader modules
+ if ((r = app.rectShaders.init(vk, app.gpu, app.programPath))) {
+ return logError("Failed to load shaders (%s)\n", sk::string(r));
+ }
+
+ if ((r = app.renderer.init(app.vulkan.vk,
+ app.gpu,
+ app.rectData,
+ app.rectShaders,
+ app.extent,
+ false))) {
+ return logError("Failed to create renderer (%s)\n", sk::string(r));
+ }
+
+ logInfo("Swapchain frames",
+ std::to_string(app.renderer.swapchain.imageViews.size()));
+ logInfo("Frames in flight",
+ std::to_string(app.renderer.sync.inFlight.size()));
+
+ recordCommandBuffers(app.vulkan.vk,
+ app.renderer.swapchain,
+ app.renderer.renderPass,
+ app.renderer.rectPipeline,
+ app.rectData);
+
+ const int refreshRate = app.view.getHint(pugl::ViewHint::refreshRate);
+ const double frameDuration = 1.0 / static_cast<double>(refreshRate);
+ const double timeout = app.opts.sync ? frameDuration : 0.0;
+
+ PuglFpsPrinter fpsPrinter = {app.world.time()};
+ app.view.show();
+ while (!app.quit) {
+ app.world.update(timeout);
+ puglPrintFps(app.world.cobj(), &fpsPrinter, &app.framesDrawn);
+ }
+
+ if ((r = app.vulkan.vk.deviceWaitIdle(app.gpu.device))) {
+ return logError("Failed to wait for device idle (%s)\n", sk::string(r));
+ }
+
+ return 0;
+}
+
+} // namespace
+
+int
+main(int argc, char** argv)
+{
+ // Parse command line options
+ const char* const programPath = argv[0];
+ const PuglTestOptions opts = puglParseTestOptions(&argc, &argv);
+ if (opts.help) {
+ puglPrintTestUsage(programPath, "");
+ return 0;
+ }
+
+ // Parse number of rectangles argument, if given
+ int64_t numRects = 1000;
+ if (argc >= 1) {
+ char* endptr = nullptr;
+ numRects = strtol(argv[0], &endptr, 10);
+ if (endptr != argv[0] + strlen(argv[0]) || numRects < 1) {
+ logError("Invalid number of rectangles: %s\n", argv[0]);
+ return 1;
+ }
+ }
+
+ // Run application
+ return run(programPath, opts, static_cast<size_t>(numRects));
+}
diff --git a/subprojects/d2tk/pugl/examples/pugl_vulkan_demo.c b/subprojects/d2tk/pugl/examples/pugl_vulkan_demo.c
new file mode 100644
index 0000000..ec96ec3
--- /dev/null
+++ b/subprojects/d2tk/pugl/examples/pugl_vulkan_demo.c
@@ -0,0 +1,1139 @@
+/*
+ Copyright 2019-2020 David Robillard <http://drobilla.net>
+ Copyright 2019 Jordan Halase <jordan@halase.me>
+
+ 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.
+*/
+
+/*
+ A simple example of drawing with Vulkan.
+
+ For a more advanced demo that actually draws something interesting, see
+ pugl_vulkan_cxx_demo.cpp.
+*/
+
+#include "demo_utils.h"
+#include "test/test_utils.h"
+
+#include "pugl/pugl.h"
+#include "pugl/vulkan.h"
+
+#include <vulkan/vk_platform.h>
+#include <vulkan/vulkan_core.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define CLAMP(x, l, h) ((x) <= (l) ? (l) : (x) >= (h) ? (h) : (x))
+
+// Vulkan allocation callbacks which can be used for debugging
+#define ALLOC_VK NULL
+
+// Helper macro for allocating arrays by type, with C++ compatible cast
+#define AALLOC(size, Type) ((Type*)calloc(size, sizeof(Type)))
+
+// Helper macro for counted array arguments to make clang-format behave
+#define COUNTED(count, ...) count, __VA_ARGS__
+
+/// Dynamically loaded Vulkan API functions
+typedef struct {
+ PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT;
+ PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT;
+} InstanceAPI;
+
+/// Vulkan swapchain and everything that depends on it
+typedef struct {
+ VkSwapchainKHR rawSwapchain;
+ uint32_t nImages;
+ VkExtent2D extent;
+ VkImage* images;
+ VkImageView* imageViews;
+ VkFence* fences;
+ VkCommandBuffer* commandBuffers;
+} Swapchain;
+
+/// Synchronization semaphores
+typedef struct {
+ VkSemaphore presentComplete;
+ VkSemaphore renderFinished;
+} Sync;
+
+/// Vulkan state, purely Vulkan functions can depend on only this
+typedef struct {
+ InstanceAPI api;
+ VkInstance instance;
+ VkDebugReportCallbackEXT debugCallback;
+ VkSurfaceKHR surface;
+ VkSurfaceFormatKHR surfaceFormat;
+ VkPresentModeKHR presentMode;
+ VkPhysicalDeviceProperties deviceProperties;
+ VkPhysicalDevice physicalDevice;
+ uint32_t graphicsIndex;
+ VkDevice device;
+ VkQueue graphicsQueue;
+ VkCommandPool commandPool;
+ Swapchain* swapchain;
+ Sync sync;
+} VulkanState;
+
+/// Complete application
+typedef struct {
+ PuglTestOptions opts;
+ PuglWorld* world;
+ PuglView* view;
+ VulkanState vk;
+ uint32_t framesDrawn;
+ uint32_t width;
+ uint32_t height;
+ bool quit;
+} VulkanApp;
+
+static VKAPI_ATTR VkBool32 VKAPI_CALL
+debugCallback(VkDebugReportFlagsEXT flags,
+ VkDebugReportObjectTypeEXT objType,
+ uint64_t obj,
+ size_t location,
+ int32_t code,
+ const char* layerPrefix,
+ const char* msg,
+ void* userData)
+{
+ (void)userData;
+ (void)objType;
+ (void)obj;
+ (void)location;
+ (void)code;
+
+ if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
+ fprintf(stderr, "note: ");
+ } else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
+ fprintf(stderr, "warning: ");
+ } else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
+ fprintf(stderr, "performance warning: ");
+ } else if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
+ fprintf(stderr, "error: ");
+ } else if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
+ fprintf(stderr, "debug: ");
+ }
+
+ fprintf(stderr, "%s: ", layerPrefix);
+ fprintf(stderr, "%s\n", msg);
+ return VK_FALSE;
+}
+
+static bool
+hasExtension(const char* const name,
+ const VkExtensionProperties* const properties,
+ const uint32_t count)
+{
+ for (uint32_t i = 0; i < count; ++i) {
+ if (!strcmp(properties[i].extensionName, name)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool
+hasLayer(const char* const name,
+ const VkLayerProperties* const properties,
+ const uint32_t count)
+{
+ for (uint32_t i = 0; i < count; ++i) {
+ if (!strcmp(properties[i].layerName, name)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static void
+pushString(const char*** const array,
+ uint32_t* const count,
+ const char* const string)
+{
+ *array = (const char**)realloc(*array, (*count + 1) * sizeof(const char*));
+ (*array)[*count] = string;
+ ++*count;
+}
+
+static VkResult
+createInstance(VulkanApp* const app)
+{
+ const VkApplicationInfo appInfo = {
+ VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ NULL,
+ "Pugl Vulkan Test",
+ VK_MAKE_VERSION(0, 1, 0),
+ "Pugl Vulkan Test Engine",
+ VK_MAKE_VERSION(0, 1, 0),
+ VK_MAKE_VERSION(1, 0, 0),
+ };
+
+ // Get the number of supported extensions and layers
+ VkResult vr = VK_SUCCESS;
+ uint32_t nExtProps = 0;
+ uint32_t nLayerProps = 0;
+ if ((vr = vkEnumerateInstanceLayerProperties(&nLayerProps, NULL)) ||
+ (vr = vkEnumerateInstanceExtensionProperties(NULL, &nExtProps, NULL))) {
+ return vr;
+ }
+
+ // Get properties of supported extensions
+ VkExtensionProperties* extProps = AALLOC(nExtProps, VkExtensionProperties);
+ vkEnumerateInstanceExtensionProperties(NULL, &nExtProps, extProps);
+
+ uint32_t nExtensions = 0;
+ const char** extensions = NULL;
+
+ // Add extensions required by pugl
+ uint32_t nPuglExts = 0;
+ const char* const* puglExts = puglGetInstanceExtensions(&nPuglExts);
+ for (uint32_t i = 0; i < nPuglExts; ++i) {
+ pushString(&extensions, &nExtensions, puglExts[i]);
+ }
+
+ // Add extra extensions we want to use if they are supported
+ if (hasExtension("VK_EXT_debug_report", extProps, nExtProps)) {
+ pushString(&extensions, &nExtensions, "VK_EXT_debug_report");
+ }
+
+ // Get properties of supported layers
+ VkLayerProperties* layerProps = AALLOC(nLayerProps, VkLayerProperties);
+ vkEnumerateInstanceLayerProperties(&nLayerProps, layerProps);
+
+ // Add validation layers if error checking is enabled
+ uint32_t nLayers = 0;
+ const char** layers = NULL;
+ if (app->opts.errorChecking) {
+ const char* debugLayers[] = {"VK_LAYER_KHRONOS_validation",
+ "VK_LAYER_LUNARG_standard_validation",
+ NULL};
+
+ for (const char** l = debugLayers; *l; ++l) {
+ if (hasLayer(*l, layerProps, nLayerProps)) {
+ pushString(&layers, &nLayers, *l);
+ }
+ }
+ }
+
+ for (uint32_t i = 0; i < nExtensions; ++i) {
+ printf("Using instance extension: %s\n", extensions[i]);
+ }
+
+ for (uint32_t i = 0; i < nLayers; ++i) {
+ printf("Using instance layer: %s\n", layers[i]);
+ }
+
+ const VkInstanceCreateInfo createInfo = {
+ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ NULL,
+ 0,
+ &appInfo,
+ COUNTED(nLayers, layers),
+ COUNTED(nExtensions, extensions),
+ };
+
+ if ((vr = vkCreateInstance(&createInfo, ALLOC_VK, &app->vk.instance))) {
+ logError("Could not create Vulkan Instance: %d\n", vr);
+ }
+
+ free(layers);
+ free(extensions);
+ free(layerProps);
+ free(extProps);
+
+ return vr;
+}
+
+static VkResult
+enableDebugging(VulkanState* const vk)
+{
+ vk->api.vkCreateDebugReportCallbackEXT =
+ (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(
+ vk->instance, "vkCreateDebugReportCallbackEXT");
+
+ vk->api.vkDestroyDebugReportCallbackEXT =
+ (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(
+ vk->instance, "vkDestroyDebugReportCallbackEXT");
+
+ if (vk->api.vkCreateDebugReportCallbackEXT) {
+ const VkDebugReportCallbackCreateInfoEXT info = {
+ VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
+ NULL,
+ VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT,
+ debugCallback,
+ NULL,
+ };
+
+ VkResult vr = VK_SUCCESS;
+ if ((vr = vk->api.vkCreateDebugReportCallbackEXT(
+ vk->instance, &info, ALLOC_VK, &vk->debugCallback))) {
+ logError("Could not create debug reporter: %d\n", vr);
+ return vr;
+ }
+ }
+
+ return VK_SUCCESS;
+}
+
+static VkResult
+getGraphicsQueueIndex(VkSurfaceKHR surface,
+ VkPhysicalDevice device,
+ uint32_t* graphicsIndex)
+{
+ VkResult r = VK_SUCCESS;
+
+ uint32_t nProps = 0;
+ vkGetPhysicalDeviceQueueFamilyProperties(device, &nProps, NULL);
+
+ VkQueueFamilyProperties* props = AALLOC(nProps, VkQueueFamilyProperties);
+ vkGetPhysicalDeviceQueueFamilyProperties(device, &nProps, props);
+
+ for (uint32_t q = 0; q < nProps; ++q) {
+ if (props[q].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
+ VkBool32 supported = false;
+ if ((r = vkGetPhysicalDeviceSurfaceSupportKHR(
+ device, q, surface, &supported))) {
+ free(props);
+ return r;
+ } else if (supported) {
+ *graphicsIndex = q;
+ free(props);
+ return VK_SUCCESS;
+ }
+ }
+ }
+
+ free(props);
+ return VK_ERROR_FEATURE_NOT_PRESENT;
+}
+
+static bool
+supportsRequiredExtensions(const VkPhysicalDevice device)
+{
+ uint32_t nExtProps = 0;
+ vkEnumerateDeviceExtensionProperties(device, NULL, &nExtProps, NULL);
+
+ VkExtensionProperties* extProps = AALLOC(nExtProps, VkExtensionProperties);
+ vkEnumerateDeviceExtensionProperties(device, NULL, &nExtProps, extProps);
+
+ for (uint32_t i = 0; i < nExtProps; ++i) {
+ if (!strcmp(extProps[i].extensionName,
+ VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
+ free(extProps);
+ return true;
+ }
+ }
+
+ free(extProps);
+ return false;
+}
+
+static bool
+isDeviceSuitable(const VulkanState* const vk,
+ const VkPhysicalDevice device,
+ uint32_t* const graphicsIndex)
+{
+ if (!supportsRequiredExtensions(device) ||
+ getGraphicsQueueIndex(vk->surface, device, graphicsIndex)) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ Selects a physical graphics device.
+
+ This doesn't try to be clever, and just selects the first suitable device.
+*/
+static VkResult
+selectPhysicalDevice(VulkanState* const vk)
+{
+ VkResult vr = VK_SUCCESS;
+ if (!vk->surface) {
+ logError("Cannot select a physical device without a surface\n");
+ return VK_ERROR_SURFACE_LOST_KHR;
+ }
+
+ uint32_t nDevices = 0;
+ if ((vr = vkEnumeratePhysicalDevices(vk->instance, &nDevices, NULL))) {
+ logError("Failed to get count of physical devices: %d\n", vr);
+ return vr;
+ }
+
+ if (!nDevices) {
+ logError("No physical devices found\n");
+ return VK_ERROR_DEVICE_LOST;
+ }
+
+ VkPhysicalDevice* devices = AALLOC(nDevices, VkPhysicalDevice);
+ if ((vr = vkEnumeratePhysicalDevices(vk->instance, &nDevices, devices))) {
+ logError("Failed to enumerate physical devices: %d\n", vr);
+ free(devices);
+ return vr;
+ }
+
+ uint32_t i = 0;
+ for (i = 0; i < nDevices; ++i) {
+ VkPhysicalDeviceProperties deviceProps = {0};
+ vkGetPhysicalDeviceProperties(devices[i], &deviceProps);
+
+ uint32_t graphicsIndex = 0;
+ if (isDeviceSuitable(vk, devices[i], &graphicsIndex)) {
+ printf("Using device %u/%u: \"%s\"\n",
+ i + 1,
+ nDevices,
+ deviceProps.deviceName);
+ vk->deviceProperties = deviceProps;
+ vk->physicalDevice = devices[i];
+ vk->graphicsIndex = graphicsIndex;
+ printf("Using graphics queue family: %u\n", vk->graphicsIndex);
+ break;
+ }
+
+ printf("Device \"%s\" not suitable\n", deviceProps.deviceName);
+ }
+
+ if (i >= nDevices) {
+ logError("No suitable devices found\n");
+ vr = VK_ERROR_DEVICE_LOST;
+ }
+
+ free(devices);
+ return vr;
+}
+
+/// Opens the logical device and sets up the queue and command pool
+static VkResult
+openDevice(VulkanState* const vk)
+{
+ if (vk->device) {
+ logError("Renderer already has an opened device\n");
+ return VK_NOT_READY;
+ }
+
+ const float graphicsQueuePriority = 1.0f;
+ const char* const swapchainName = VK_KHR_SWAPCHAIN_EXTENSION_NAME;
+
+ const VkDeviceQueueCreateInfo queueCreateInfo = {
+ VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
+ NULL,
+ 0,
+ vk->graphicsIndex,
+ COUNTED(1, &graphicsQueuePriority),
+ };
+
+ const VkDeviceCreateInfo createInfo = {
+ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ NULL,
+ 0,
+ COUNTED(1, &queueCreateInfo),
+ COUNTED(0, NULL),
+ COUNTED(1, &swapchainName),
+ NULL,
+ };
+
+ VkDevice device = NULL;
+ VkResult vr = VK_SUCCESS;
+ if ((vr = vkCreateDevice(
+ vk->physicalDevice, &createInfo, ALLOC_VK, &device))) {
+ logError("Could not open device \"%s\": %d\n",
+ vk->deviceProperties.deviceName,
+ vr);
+ return vr;
+ }
+
+ vk->device = device;
+ vkGetDeviceQueue(vk->device, vk->graphicsIndex, 0, &vk->graphicsQueue);
+
+ const VkCommandPoolCreateInfo commandInfo = {
+ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
+ NULL,
+ 0,
+ vk->graphicsIndex,
+ };
+
+ if ((vr = vkCreateCommandPool(
+ vk->device, &commandInfo, ALLOC_VK, &vk->commandPool))) {
+ logError("Could not create command pool: %d\n", vr);
+ return vr;
+ }
+
+ return VK_SUCCESS;
+}
+
+static const char*
+presentModeString(const VkPresentModeKHR presentMode)
+{
+ switch (presentMode) {
+ case VK_PRESENT_MODE_IMMEDIATE_KHR:
+ return "Immediate";
+ case VK_PRESENT_MODE_MAILBOX_KHR:
+ return "Mailbox";
+ case VK_PRESENT_MODE_FIFO_KHR:
+ return "FIFO";
+ case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
+ return "FIFO relaxed";
+ default:
+ return "Other";
+ }
+}
+
+static bool
+hasPresentMode(const VkPresentModeKHR mode,
+ const VkPresentModeKHR* const presentModes,
+ const uint32_t nPresentModes)
+{
+ for (uint32_t i = 0; i < nPresentModes; ++i) {
+ if (presentModes[i] == mode) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/// Configure the surface for the currently opened device
+static VkResult
+configureSurface(VulkanState* const vk)
+{
+ uint32_t nFormats = 0;
+ vkGetPhysicalDeviceSurfaceFormatsKHR(vk->physicalDevice,
+ vk->surface,
+ &nFormats,
+ NULL);
+ if (!nFormats) {
+ logError("No surface formats available\n");
+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
+ }
+
+ VkSurfaceFormatKHR* surfaceFormats = AALLOC(nFormats, VkSurfaceFormatKHR);
+ vkGetPhysicalDeviceSurfaceFormatsKHR(vk->physicalDevice,
+ vk->surface,
+ &nFormats,
+ surfaceFormats);
+
+ const VkSurfaceFormatKHR want = {VK_FORMAT_B8G8R8A8_UNORM,
+ VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
+
+ uint32_t formatIndex = 0;
+ for (formatIndex = 0; formatIndex < nFormats; ++formatIndex) {
+ if (surfaceFormats[formatIndex].format == want.format &&
+ surfaceFormats[formatIndex].colorSpace == want.colorSpace) {
+ vk->surfaceFormat = want;
+ break;
+ }
+ }
+ free(surfaceFormats);
+ if (formatIndex >= nFormats) {
+ logError("Could not find a suitable surface format\n");
+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
+ }
+
+ uint32_t nPresentModes = 0;
+ vkGetPhysicalDeviceSurfacePresentModesKHR(vk->physicalDevice,
+ vk->surface,
+ &nPresentModes,
+ NULL);
+ if (!nPresentModes) {
+ logError("No present modes available\n");
+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
+ }
+
+ VkPresentModeKHR* presentModes = AALLOC(nPresentModes, VkPresentModeKHR);
+ vkGetPhysicalDeviceSurfacePresentModesKHR(vk->physicalDevice,
+ vk->surface,
+ &nPresentModes,
+ presentModes);
+
+ const VkPresentModeKHR tryModes[] = {
+ VK_PRESENT_MODE_MAILBOX_KHR,
+ VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+ VK_PRESENT_MODE_FIFO_KHR,
+ VK_PRESENT_MODE_IMMEDIATE_KHR,
+ };
+
+ VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
+ for (uint32_t i = 0; i < sizeof(tryModes) / sizeof(VkPresentModeKHR); ++i) {
+ if (hasPresentMode(tryModes[i], presentModes, nPresentModes)) {
+ presentMode = tryModes[i];
+ break;
+ }
+ }
+
+ free(presentModes);
+ vk->presentMode = presentMode;
+ printf("Using present mode: \"%s\" (%u)\n",
+ presentModeString(presentMode),
+ presentMode);
+
+ return VK_SUCCESS;
+}
+
+static VkResult
+createRawSwapchain(VulkanState* const vk,
+ const uint32_t width,
+ const uint32_t height)
+{
+ VkSurfaceCapabilitiesKHR surfaceCapabilities;
+ VkResult vr = VK_SUCCESS;
+ if ((vr = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
+ vk->physicalDevice, vk->surface, &surfaceCapabilities))) {
+ logError("Could not get surface capabilities: %d\n", vr);
+ return vr;
+ }
+
+ /* There is a known race condition with window/surface sizes, so we clamp
+ to what Vulkan reports and hope for the best. */
+
+ vk->swapchain->extent.width =
+ CLAMP(width,
+ surfaceCapabilities.minImageExtent.width,
+ surfaceCapabilities.maxImageExtent.width);
+
+ vk->swapchain->extent.height =
+ CLAMP(height,
+ surfaceCapabilities.minImageExtent.height,
+ surfaceCapabilities.maxImageExtent.height);
+
+ vk->swapchain->nImages = surfaceCapabilities.minImageCount;
+
+ const VkSwapchainCreateInfoKHR createInfo = {
+ VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
+ NULL,
+ 0,
+ vk->surface,
+ vk->swapchain->nImages,
+ vk->surfaceFormat.format,
+ VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
+ vk->swapchain->extent,
+ 1,
+ (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
+ VK_SHARING_MODE_EXCLUSIVE,
+ COUNTED(0, NULL),
+ surfaceCapabilities.currentTransform,
+ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
+ vk->presentMode,
+ VK_TRUE,
+ 0,
+ };
+
+ if ((vr = vkCreateSwapchainKHR(vk->device,
+ &createInfo,
+ ALLOC_VK,
+ &vk->swapchain->rawSwapchain))) {
+ logError("Could not create swapchain: %d\n", vr);
+ return vr;
+ }
+
+ return VK_SUCCESS;
+}
+
+static VkResult
+recordCommandBuffers(VulkanState* const vk)
+{
+ const VkClearColorValue clearValue = {{
+ 0xA4 / (float)0x100, // R
+ 0x1E / (float)0x100, // G
+ 0x22 / (float)0x100, // B
+ 0xFF / (float)0x100, // A
+ }};
+
+ const VkImageSubresourceRange range = {
+ VK_IMAGE_ASPECT_COLOR_BIT,
+ 0,
+ 1,
+ 0,
+ 1,
+ };
+
+ const VkCommandBufferBeginInfo beginInfo = {
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
+ NULL,
+ VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
+ NULL,
+ };
+
+ for (uint32_t i = 0; i < vk->swapchain->nImages; ++i) {
+ const VkImageMemoryBarrier toClearBarrier = {
+ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
+ NULL,
+ VK_ACCESS_MEMORY_READ_BIT,
+ VK_ACCESS_TRANSFER_WRITE_BIT,
+ VK_IMAGE_LAYOUT_UNDEFINED,
+ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ vk->graphicsIndex,
+ vk->graphicsIndex,
+ vk->swapchain->images[i],
+ range,
+ };
+
+ const VkImageMemoryBarrier toPresentBarrier = {
+ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
+ NULL,
+ VK_ACCESS_TRANSFER_WRITE_BIT,
+ VK_ACCESS_MEMORY_READ_BIT,
+ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
+ vk->graphicsIndex,
+ vk->graphicsIndex,
+ vk->swapchain->images[i],
+ range,
+ };
+
+ vkBeginCommandBuffer(vk->swapchain->commandBuffers[i], &beginInfo);
+
+ vkCmdPipelineBarrier(vk->swapchain->commandBuffers[i],
+ VK_PIPELINE_STAGE_TRANSFER_BIT,
+ VK_PIPELINE_STAGE_TRANSFER_BIT,
+ 0,
+ COUNTED(0, NULL),
+ COUNTED(0, NULL),
+ COUNTED(1, &toClearBarrier));
+
+ vkCmdClearColorImage(vk->swapchain->commandBuffers[i],
+ vk->swapchain->images[i],
+ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ &clearValue,
+ COUNTED(1, &range));
+
+ vkCmdPipelineBarrier(vk->swapchain->commandBuffers[i],
+ VK_PIPELINE_STAGE_TRANSFER_BIT,
+ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
+ 0,
+ COUNTED(0, NULL),
+ COUNTED(0, NULL),
+ COUNTED(1, &toPresentBarrier));
+
+ vkEndCommandBuffer(vk->swapchain->commandBuffers[i]);
+ }
+
+ return VK_SUCCESS;
+}
+
+static VkResult
+createSwapchain(VulkanState* const vk,
+ const uint32_t width,
+ const uint32_t height)
+{
+ VkResult vr = VK_SUCCESS;
+
+ vk->swapchain = AALLOC(1, Swapchain);
+ if ((vr = createRawSwapchain(vk, width, height))) {
+ return vr;
+ }
+
+ if ((vr = vkGetSwapchainImagesKHR(vk->device,
+ vk->swapchain->rawSwapchain,
+ &vk->swapchain->nImages,
+ NULL))) {
+ logError("Failed to query swapchain images: %d\n", vr);
+ return vr;
+ }
+
+ vk->swapchain->images = AALLOC(vk->swapchain->nImages, VkImage);
+ if ((vr = vkGetSwapchainImagesKHR(vk->device,
+ vk->swapchain->rawSwapchain,
+ &vk->swapchain->nImages,
+ vk->swapchain->images))) {
+ logError("Failed to get swapchain images: %d\n", vr);
+ return vr;
+ }
+
+ const VkCommandBufferAllocateInfo allocInfo = {
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+ NULL,
+ vk->commandPool,
+ VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+ vk->swapchain->nImages,
+ };
+
+ vk->swapchain->commandBuffers = AALLOC(vk->swapchain->nImages,
+ VkCommandBuffer);
+
+ if ((vr = vkAllocateCommandBuffers(vk->device,
+ &allocInfo,
+ vk->swapchain->commandBuffers))) {
+ logError("Could not allocate command buffers: %d\n", vr);
+ return vr;
+ }
+
+ const VkFenceCreateInfo fenceInfo = {
+ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
+ NULL,
+ VK_FENCE_CREATE_SIGNALED_BIT,
+ };
+ vk->swapchain->fences = AALLOC(vk->swapchain->nImages, VkFence);
+
+ for (uint32_t i = 0; i < vk->swapchain->nImages; ++i) {
+ if ((vr = vkCreateFence(vk->device,
+ &fenceInfo,
+ ALLOC_VK,
+ &vk->swapchain->fences[i]))) {
+ logError("Could not create render finished fence: %d\n", vr);
+ return vr;
+ }
+ }
+
+ if ((vr = recordCommandBuffers(vk))) {
+ logError("Failed to record command buffers\n");
+ return vr;
+ }
+
+ return VK_SUCCESS;
+}
+
+static void
+destroySwapchain(VulkanState* const vk, Swapchain* const swapchain)
+{
+ if (!swapchain) {
+ return;
+ }
+
+ for (uint32_t i = 0; i < swapchain->nImages; ++i) {
+ if (swapchain->fences[i]) {
+ vkDestroyFence(vk->device, swapchain->fences[i], ALLOC_VK);
+ }
+
+ if (swapchain->imageViews && swapchain->imageViews[i]) {
+ vkDestroyImageView(vk->device, swapchain->imageViews[i], ALLOC_VK);
+ }
+ }
+
+ free(swapchain->fences);
+ swapchain->fences = NULL;
+ free(swapchain->imageViews);
+ swapchain->imageViews = NULL;
+
+ if (swapchain->images) {
+ free(swapchain->images);
+ swapchain->images = NULL;
+ }
+
+ if (swapchain->commandBuffers) {
+ vkFreeCommandBuffers(vk->device,
+ vk->commandPool,
+ swapchain->nImages,
+ swapchain->commandBuffers);
+ free(swapchain->commandBuffers);
+ }
+
+ if (swapchain->rawSwapchain) {
+ vkDestroySwapchainKHR(vk->device, swapchain->rawSwapchain, ALLOC_VK);
+ }
+
+ free(swapchain);
+}
+
+static VkResult
+createSyncObjects(VulkanState* const vk)
+{
+ const VkSemaphoreCreateInfo info = {
+ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
+ NULL,
+ 0,
+ };
+
+ vkCreateSemaphore(vk->device, &info, ALLOC_VK, &vk->sync.presentComplete);
+ vkCreateSemaphore(vk->device, &info, ALLOC_VK, &vk->sync.renderFinished);
+ return VK_SUCCESS;
+}
+
+static void
+destroySyncObjects(VulkanState* const vk)
+{
+ if (vk->sync.renderFinished) {
+ vkDestroySemaphore(vk->device, vk->sync.renderFinished, ALLOC_VK);
+ vk->sync.renderFinished = VK_NULL_HANDLE;
+ }
+ if (vk->sync.presentComplete) {
+ vkDestroySemaphore(vk->device, vk->sync.presentComplete, ALLOC_VK);
+ vk->sync.presentComplete = VK_NULL_HANDLE;
+ }
+}
+
+static void
+closeDevice(VulkanState* const vk)
+{
+ if (vk->device) {
+ vkDeviceWaitIdle(vk->device);
+ destroySyncObjects(vk);
+ destroySwapchain(vk, vk->swapchain);
+ if (vk->commandPool) {
+ vkDestroyCommandPool(vk->device, vk->commandPool, ALLOC_VK);
+ vk->commandPool = VK_NULL_HANDLE;
+ }
+ vk->graphicsQueue = VK_NULL_HANDLE;
+ vkDestroyDevice(vk->device, ALLOC_VK);
+ vk->device = VK_NULL_HANDLE;
+ }
+}
+
+static void
+destroyWorld(VulkanApp* const app)
+{
+ VulkanState* vk = &app->vk;
+
+ if (vk) {
+ closeDevice(vk);
+
+ if (app->view) {
+ puglHide(app->view);
+ puglFreeView(app->view);
+ app->view = NULL;
+ }
+ if (vk->debugCallback && vk->api.vkDestroyDebugReportCallbackEXT) {
+ vk->api.vkDestroyDebugReportCallbackEXT(vk->instance,
+ vk->debugCallback,
+ ALLOC_VK);
+ vk->debugCallback = VK_NULL_HANDLE;
+ }
+ if (vk->surface) {
+ vkDestroySurfaceKHR(vk->instance, vk->surface, ALLOC_VK);
+ vk->surface = VK_NULL_HANDLE;
+ }
+ if (vk->instance) {
+ fflush(stderr);
+ vkDestroyInstance(vk->instance, ALLOC_VK);
+ vk->instance = VK_NULL_HANDLE;
+ }
+ if (app->world) {
+ puglFreeWorld(app->world);
+ app->world = NULL;
+ }
+ }
+}
+
+static PuglStatus
+onConfigure(PuglView* const view, const double width, const double height)
+{
+ VulkanApp* const app = (VulkanApp*)puglGetHandle(view);
+
+ // We just record the size here and lazily resize the surface when exposed
+ app->width = (uint32_t)width;
+ app->height = (uint32_t)height;
+
+ return PUGL_SUCCESS;
+}
+
+static PuglStatus
+recreateSwapchain(VulkanState* const vk,
+ const uint32_t width,
+ const uint32_t height)
+{
+ vkDeviceWaitIdle(vk->device);
+ destroySwapchain(vk, vk->swapchain);
+
+ if (createSwapchain(vk, width, height)) {
+ logError("Failed to recreate swapchain\n");
+ return PUGL_UNKNOWN_ERROR;
+ }
+
+ return PUGL_SUCCESS;
+}
+
+static PuglStatus
+onExpose(PuglView* const view)
+{
+ VulkanApp* app = (VulkanApp*)puglGetHandle(view);
+ VulkanState* vk = &app->vk;
+ uint32_t imageIndex = 0;
+ VkResult result = VK_SUCCESS;
+
+ // Recreate swapchain if the window size has changed
+ const Swapchain* swapchain = vk->swapchain;
+ if (swapchain->extent.width != app->width ||
+ swapchain->extent.height != app->height) {
+ recreateSwapchain(vk, app->width, app->height);
+ }
+
+ // Acquire the next image to render, rebuilding if necessary
+ while ((result = vkAcquireNextImageKHR(vk->device,
+ vk->swapchain->rawSwapchain,
+ UINT64_MAX,
+ vk->sync.presentComplete,
+ VK_NULL_HANDLE,
+ &imageIndex))) {
+ switch (result) {
+ case VK_SUCCESS:
+ break;
+ case VK_SUBOPTIMAL_KHR:
+ case VK_ERROR_OUT_OF_DATE_KHR:
+ recreateSwapchain(vk, app->width, app->height);
+ continue;
+ default:
+ logError("Could not acquire swapchain image: %d\n", result);
+ return PUGL_UNKNOWN_ERROR;
+ }
+ }
+
+ // Wait until we can start rendering this frame
+ vkWaitForFences(vk->device,
+ COUNTED(1, &vk->swapchain->fences[imageIndex]),
+ VK_TRUE,
+ UINT64_MAX);
+ vkResetFences(vk->device, 1, &vk->swapchain->fences[imageIndex]);
+
+ const VkPipelineStageFlags waitStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
+
+ // Submit command buffer to render this frame
+ const VkSubmitInfo submitInfo = {
+ VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ NULL,
+ COUNTED(1, &vk->sync.presentComplete),
+ &waitStage,
+ COUNTED(1, &vk->swapchain->commandBuffers[imageIndex]),
+ COUNTED(1, &vk->sync.renderFinished)};
+ if ((result = vkQueueSubmit(vk->graphicsQueue,
+ 1,
+ &submitInfo,
+ vk->swapchain->fences[imageIndex]))) {
+ logError("Could not submit to queue: %d\n", result);
+ return PUGL_FAILURE;
+ }
+
+ // Present this frame
+ const VkPresentInfoKHR presentInfo = {
+ VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
+ NULL,
+ COUNTED(1, &vk->sync.renderFinished),
+ COUNTED(1, &vk->swapchain->rawSwapchain, &imageIndex, NULL),
+ };
+ if ((result = vkQueuePresentKHR(vk->graphicsQueue, &presentInfo))) {
+ logError("Could not present image: %d\n", result);
+ }
+
+ if (app->opts.continuous) {
+ ++app->framesDrawn;
+ }
+
+ return PUGL_SUCCESS;
+}
+
+static PuglStatus
+onEvent(PuglView* const view, const PuglEvent* const e)
+{
+ VulkanApp* const app = (VulkanApp*)puglGetHandle(view);
+
+ printEvent(e, "Event: ", app->opts.verbose);
+
+ switch (e->type) {
+ case PUGL_EXPOSE:
+ return onExpose(view);
+ case PUGL_CONFIGURE:
+ return onConfigure(view, e->configure.width, e->configure.height);
+ case PUGL_CLOSE:
+ app->quit = 1;
+ break;
+ case PUGL_KEY_PRESS:
+ switch (e->key.key) {
+ case PUGL_KEY_ESCAPE:
+ case 'q':
+ app->quit = 1;
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ return PUGL_SUCCESS;
+}
+
+int
+main(int argc, char** argv)
+{
+ VulkanApp app = {0};
+ VulkanState* vk = &app.vk;
+ const uint32_t defaultWidth = 640;
+ const uint32_t defaultHeight = 360;
+ const PuglRect frame = {0, 0, defaultWidth, defaultHeight};
+
+ // Parse command line options
+ app.opts = puglParseTestOptions(&argc, &argv);
+ if (app.opts.help) {
+ puglPrintTestUsage(argv[0], "");
+ return 0;
+ }
+
+ // Create world and view
+ if (!(app.world = puglNewWorld(PUGL_PROGRAM, PUGL_WORLD_THREADS))) {
+ return logError("Failed to create world\n");
+ } else if (!(app.view = puglNewView(app.world))) {
+ puglFreeWorld(app.world);
+ return logError("Failed to create Pugl World and View\n");
+ }
+
+ // Create Vulkan instance
+ if (createInstance(&app)) {
+ puglFreeWorld(app.world);
+ return logError("Failed to create instance\n");
+ }
+
+ // Create window
+ puglSetWindowTitle(app.view, "Pugl Vulkan");
+ puglSetFrame(app.view, frame);
+ puglSetHandle(app.view, &app);
+ puglSetBackend(app.view, puglVulkanBackend());
+ puglSetViewHint(app.view, PUGL_RESIZABLE, app.opts.resizable);
+ puglSetEventFunc(app.view, onEvent);
+ const PuglStatus st = puglRealize(app.view);
+ if (st) {
+ puglFreeWorld(app.world);
+ puglFreeView(app.view);
+ return logError("Failed to create window (%s)\n", puglStrerror(st));
+ }
+
+ // Create Vulkan surface for Window
+ PuglVulkanLoader* loader = puglNewVulkanLoader(app.world);
+ if (puglCreateSurface(puglGetInstanceProcAddrFunc(loader),
+ app.view,
+ vk->instance,
+ ALLOC_VK,
+ &vk->surface)) {
+ return logError("Failed to create surface\n");
+ }
+
+ // Set up Vulkan
+ VkResult vr = VK_SUCCESS;
+ if ((vr = enableDebugging(vk)) || //
+ (vr = selectPhysicalDevice(vk)) || //
+ (vr = openDevice(vk)) || //
+ (vr = configureSurface(vk)) || //
+ (vr = createSwapchain(vk, defaultWidth, defaultHeight)) || //
+ (vr = createSyncObjects(vk))) {
+ destroyWorld(&app);
+ return logError("Failed to set up graphics (%d)\n", vr);
+ }
+
+ printf("Swapchain images: %u\n", app.vk.swapchain->nImages);
+
+ PuglFpsPrinter fpsPrinter = {puglGetTime(app.world)};
+ puglShow(app.view);
+ while (!app.quit) {
+ puglUpdate(app.world, -1.0);
+
+ if (app.opts.continuous) {
+ puglPrintFps(app.world, &fpsPrinter, &app.framesDrawn);
+ }
+ }
+
+ destroyWorld(&app);
+ return 0;
+}
diff --git a/subprojects/d2tk/pugl/examples/pugl_window_demo.c b/subprojects/d2tk/pugl/examples/pugl_window_demo.c
index f326f21..3dfc39a 100644
--- a/subprojects/d2tk/pugl/examples/pugl_window_demo.c
+++ b/subprojects/d2tk/pugl/examples/pugl_window_demo.c
@@ -14,17 +14,16 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl_window_demo.c
- @brief A demonstration of multiple Pugl windows.
+/*
+ A demonstration of using multiple top-level windows.
*/
#include "cube_view.h"
#include "demo_utils.h"
#include "test/test_utils.h"
+#include "pugl/gl.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_gl.h"
#include <math.h>
#include <stdbool.h>
@@ -236,7 +235,7 @@ main(int argc, char** argv)
return logError("Failed to create window (%s)\n", puglStrerror(st));
}
- puglShowWindow(view);
+ puglShow(view);
}
PuglFpsPrinter fpsPrinter = {puglGetTime(app.world)};
diff --git a/subprojects/d2tk/pugl/examples/rects.h b/subprojects/d2tk/pugl/examples/rects.h
index f760226..3537a5b 100644
--- a/subprojects/d2tk/pugl/examples/rects.h
+++ b/subprojects/d2tk/pugl/examples/rects.h
@@ -14,13 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file rects.h
- @brief Utilities for rectangle animation demos.
-
- This file contains common definitions for demos that show an animation of
- many 2D rectangles.
-*/
+#ifndef EXAMPLES_RECTS_H
+#define EXAMPLES_RECTS_H
#include <math.h>
#include <stddef.h>
@@ -80,3 +75,5 @@ moveRect(Rect* const rect,
(cosf((float)time * rect->size[1] / 64.0f + normal) + 1.0f) /
2.0f;
}
+
+#endif // EXAMPLES_RECTS_H
diff --git a/subprojects/d2tk/pugl/examples/shader_utils.h b/subprojects/d2tk/pugl/examples/shader_utils.h
index 10a7ace..217ba47 100644
--- a/subprojects/d2tk/pugl/examples/shader_utils.h
+++ b/subprojects/d2tk/pugl/examples/shader_utils.h
@@ -14,6 +14,9 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef EXAMPLES_SHADER_UTILS_H
+#define EXAMPLES_SHADER_UTILS_H
+
#include "glad/glad.h"
#include <stdio.h>
@@ -100,3 +103,5 @@ compileProgram(const char* headerSource,
return program;
}
+
+#endif // EXAMPLES_SHADER_UTILS_H
diff --git a/subprojects/d2tk/pugl/shaders/header_330.glsl b/subprojects/d2tk/pugl/examples/shaders/header_330.glsl
index bfe7a00..bfe7a00 100644
--- a/subprojects/d2tk/pugl/shaders/header_330.glsl
+++ b/subprojects/d2tk/pugl/examples/shaders/header_330.glsl
diff --git a/subprojects/d2tk/pugl/shaders/header_420.glsl b/subprojects/d2tk/pugl/examples/shaders/header_420.glsl
index 55fbe8a..55fbe8a 100644
--- a/subprojects/d2tk/pugl/shaders/header_420.glsl
+++ b/subprojects/d2tk/pugl/examples/shaders/header_420.glsl
diff --git a/subprojects/d2tk/pugl/shaders/rect.frag b/subprojects/d2tk/pugl/examples/shaders/rect.frag
index ecec50d..ecec50d 100644
--- a/subprojects/d2tk/pugl/shaders/rect.frag
+++ b/subprojects/d2tk/pugl/examples/shaders/rect.frag
diff --git a/subprojects/d2tk/pugl/shaders/rect.vert b/subprojects/d2tk/pugl/examples/shaders/rect.vert
index 09f1917..09f1917 100644
--- a/subprojects/d2tk/pugl/shaders/rect.vert
+++ b/subprojects/d2tk/pugl/examples/shaders/rect.vert
diff --git a/subprojects/d2tk/pugl/examples/sybok.hpp b/subprojects/d2tk/pugl/examples/sybok.hpp
new file mode 100644
index 0000000..8985547
--- /dev/null
+++ b/subprojects/d2tk/pugl/examples/sybok.hpp
@@ -0,0 +1,2358 @@
+/*
+ Copyright 2020 David Robillard <http://drobilla.net>
+
+ 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 sybok.hpp
+ @brief A minimal C++ wrapper for the Vulkan API.
+
+ This is a manually-written minimal wrapper for Vulkan. It makes working
+ with Vulkan a little easier in C++, but takes a different approach than
+ vulkan.hpp. In particular:
+
+ - Works nicely with dynamic loading. Since the API itself is an object, it
+ is simple to ensure the dynamically loaded API (or a consistent API in
+ general) is used everywhere. Passing a dispatch parameter to every
+ function as in vulkan.hpp makes dynamic loading extremely painful (not to
+ mention ugly), and mistakes tend to become link time errors. This is, in
+ my opinion, a glaring design flaw, and the real reason why this wrapper
+ reluctantly exists.
+
+ - Explicit separation of the initial API that does not require an instance
+ to load, from the rest of the API that does.
+
+ - Opinionated use of scoped handles everywhere.
+
+ - Remains close to the C API so that code can be easily ported. This means
+ that the pattern of return codes with output parameters is preserved,
+ except with smart handles that make leaks impossible. While less pretty,
+ this does not require exceptions.
+
+ - No exceptions or RTTI required.
+
+ - A safe scoped API for commands that encodes the semantics of the Vulkan
+ API. For example, it is statically impossible to call render scope
+ commands while not in a render scope.
+
+ - A reasonable amount of relatively readable code.
+
+ On the other hand, there are far fewer niceties, and the C API is used
+ directly as much as possible, particularly for structs (although they are
+ taken by const reference so they can be written inline). There is only
+ support for a minimal portable subset of Vulkan 1.1 with a few portable KHR
+ extensions.
+
+ In short, if the above sounds appealing, or you want a minimal wrapper that
+ can be extended if necessary to suit your application, you might find this
+ useful. If you want a fully-featured wrapper for Vulkan and don't care
+ about linker dependencies, you probably won't.
+*/
+
+#ifndef SYBOK_HPP
+#define SYBOK_HPP
+
+#define VK_NO_PROTOTYPES
+
+// On 64-bit platforms, all handles are "dispatchable" pointers
+#if defined(__LP64__) || defined(_WIN64) || \
+ (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || \
+ defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || \
+ defined(__powerpc64__)
+
+# define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) \
+ typedef struct object##_T* object;
+
+// On 32-bit platforms, some "non-dispatchable" handles are 64 bit integers
+#else
+
+/// Trivial wrapper class for a 64-bit integer handle for type safety
+template<class Tag>
+struct NonDispatchableHandle {
+ explicit operator uint64_t() const noexcept { return handle; }
+ explicit operator bool() const noexcept { return handle; }
+
+ uint64_t handle;
+};
+
+# define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) \
+ using object = NonDispatchableHandle<struct Sk##object##Tag>;
+
+#endif
+
+#include <vulkan/vulkan_core.h>
+
+#include <array>
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <type_traits>
+#include <utility>
+
+#if __cplusplus >= 201703L
+# define SYBOK_NODISCARD [[nodiscard]]
+#elif defined(__GNUC__)
+# define SYBOK_NODISCARD [[gnu::warn_unused_result]]
+#else
+# define SYBOK_NODISCARD
+#endif
+
+/// Helper macro to make array arguments format nicely
+#define SK_COUNTED(count, ...) count, __VA_ARGS__
+
+namespace sk {
+
+class CommandScope;
+class RenderCommandScope;
+
+static inline const char*
+string(const VkResult result)
+{
+ switch (result) {
+ case VK_SUCCESS:
+ return "Success";
+ case VK_NOT_READY:
+ return "Not Ready";
+ case VK_TIMEOUT:
+ return "Timeout";
+ case VK_EVENT_SET:
+ return "Event set";
+ case VK_EVENT_RESET:
+ return "Event reset";
+ case VK_INCOMPLETE:
+ return "Incomplete";
+ case VK_ERROR_OUT_OF_HOST_MEMORY:
+ return "Out of host memory";
+ case VK_ERROR_OUT_OF_DEVICE_MEMORY:
+ return "Out of device memory";
+ case VK_ERROR_INITIALIZATION_FAILED:
+ return "Initialization failed";
+ case VK_ERROR_DEVICE_LOST:
+ return "Device lost";
+ case VK_ERROR_MEMORY_MAP_FAILED:
+ return "Memory map failed";
+ case VK_ERROR_LAYER_NOT_PRESENT:
+ return "Layer not present";
+ case VK_ERROR_EXTENSION_NOT_PRESENT:
+ return "Extension not present";
+ case VK_ERROR_FEATURE_NOT_PRESENT:
+ return "Feature not present";
+ case VK_ERROR_INCOMPATIBLE_DRIVER:
+ return "Incompatible driver";
+ case VK_ERROR_TOO_MANY_OBJECTS:
+ return "Too many objects";
+ case VK_ERROR_FORMAT_NOT_SUPPORTED:
+ return "Format not supported";
+ case VK_ERROR_FRAGMENTED_POOL:
+ return "Fragmented pool";
+ case VK_ERROR_OUT_OF_POOL_MEMORY: // Vulkan 1.1
+ return "Out of pool memory";
+ case VK_ERROR_INVALID_EXTERNAL_HANDLE: // Vulkan 1.1
+ return "Invalid external handle";
+ case VK_ERROR_SURFACE_LOST_KHR: // VK_KHR_surface
+ return "Surface lost";
+ case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: // VK_KHR_surface
+ return "Native window in use";
+ case VK_SUBOPTIMAL_KHR: // VK_KHR_swapchain
+ return "Suboptimal";
+ case VK_ERROR_OUT_OF_DATE_KHR: // VK_KHR_swapchain
+ return "Out of date";
+ case VK_ERROR_VALIDATION_FAILED_EXT: // VK_EXT_debug_report
+ return "Validation failed";
+ default:
+ break;
+ }
+
+ return "Unknown error";
+}
+
+static inline const char*
+string(const VkPresentModeKHR presentMode)
+{
+ switch (presentMode) {
+ case VK_PRESENT_MODE_IMMEDIATE_KHR:
+ return "Immediate";
+ case VK_PRESENT_MODE_MAILBOX_KHR:
+ return "Mailbox";
+ case VK_PRESENT_MODE_FIFO_KHR:
+ return "FIFO";
+ case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
+ return "Relaxed FIFO";
+ default:
+ break;
+ }
+
+ return "Unknown present mode";
+}
+
+static inline const char*
+string(const VkDebugReportFlagBitsEXT flag)
+{
+ switch (flag) {
+ case VK_DEBUG_REPORT_INFORMATION_BIT_EXT:
+ return "Information";
+ case VK_DEBUG_REPORT_WARNING_BIT_EXT:
+ return "Warning";
+ case VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT:
+ return "Performance Warning";
+ case VK_DEBUG_REPORT_ERROR_BIT_EXT:
+ return "Error";
+ case VK_DEBUG_REPORT_DEBUG_BIT_EXT:
+ return "Debug";
+ default:
+ break;
+ }
+
+ return "Unknown report";
+}
+
+template<class T>
+class GlobalDeleter
+{
+public:
+ using DestroyFunc = void (*)(T, const VkAllocationCallbacks*);
+
+ GlobalDeleter() = default;
+ ~GlobalDeleter() = default;
+
+ GlobalDeleter(DestroyFunc destroyFunc) noexcept
+ : _destroyFunc{destroyFunc}
+ {}
+
+ GlobalDeleter(const GlobalDeleter&) = delete;
+ GlobalDeleter& operator=(const GlobalDeleter&) = delete;
+
+ GlobalDeleter(GlobalDeleter&& other) noexcept
+ {
+ std::swap(_destroyFunc, other._destroyFunc);
+ }
+
+ GlobalDeleter& operator=(GlobalDeleter&& other) noexcept
+ {
+ std::swap(_destroyFunc, other._destroyFunc);
+ return *this;
+ }
+
+ void operator()(T handle) noexcept
+ {
+ if (_destroyFunc && handle) {
+ _destroyFunc(handle, nullptr);
+ }
+ }
+
+private:
+ DestroyFunc _destroyFunc{};
+};
+
+template<class T, class Parent>
+class DependantDeleter
+{
+public:
+ using DestroyFunc = void (*)(Parent, T, const VkAllocationCallbacks*);
+
+ DependantDeleter() = default;
+ ~DependantDeleter() = default;
+
+ DependantDeleter(Parent parent, DestroyFunc destroyFunc) noexcept
+ : _parent{parent}
+ , _destroyFunc{destroyFunc}
+ {}
+
+ DependantDeleter(const DependantDeleter&) = delete;
+ DependantDeleter& operator=(const DependantDeleter&) = delete;
+
+ DependantDeleter(DependantDeleter&& other) noexcept { swap(other); }
+
+ DependantDeleter& operator=(DependantDeleter&& other) noexcept
+ {
+ swap(other);
+ return *this;
+ }
+
+ void operator()(T handle) noexcept
+ {
+ if (_parent && _destroyFunc && handle) {
+ _destroyFunc(_parent, handle, nullptr);
+ }
+ }
+
+private:
+ void swap(DependantDeleter& other) noexcept
+ {
+ std::swap(_parent, other._parent);
+ std::swap(_destroyFunc, other._destroyFunc);
+ }
+
+ Parent _parent{};
+ DestroyFunc _destroyFunc{};
+};
+
+template<class T, class Pool, class FreeFuncResult>
+class PoolDeleter
+{
+public:
+ using FreeFunc = FreeFuncResult (*)(VkDevice, Pool, uint32_t, const T*);
+
+ PoolDeleter() noexcept = default;
+ ~PoolDeleter() noexcept = default;
+
+ PoolDeleter(VkDevice device,
+ Pool pool,
+ uint32_t count,
+ FreeFunc freeFunc) noexcept
+ : _device{device}
+ , _pool{pool}
+ , _count{count}
+ , _freeFunc{freeFunc}
+ {}
+
+ PoolDeleter(const PoolDeleter&) = delete;
+ PoolDeleter& operator=(const PoolDeleter&) = delete;
+
+ PoolDeleter(PoolDeleter&& other) noexcept { swap(other); }
+
+ PoolDeleter& operator=(PoolDeleter&& other) noexcept
+ {
+ swap(other);
+ return *this;
+ }
+
+ void operator()(T* handle) noexcept
+ {
+ if (_device && _pool && handle) {
+ _freeFunc(_device, _pool, _count, handle);
+ }
+ }
+
+private:
+ void swap(PoolDeleter& other) noexcept
+ {
+ std::swap(_device, other._device);
+ std::swap(_pool, other._pool);
+ std::swap(_count, other._count);
+ std::swap(_freeFunc, other._freeFunc);
+ }
+
+ VkDevice _device{};
+ Pool _pool{};
+ uint32_t _count{};
+ FreeFunc _freeFunc{};
+};
+
+template<class T, class TDeleter>
+class UniqueDispatchableHandle
+{
+public:
+ using Deleter = TDeleter;
+ using Handle = T;
+
+ static_assert(std::is_pointer<T>::value, "");
+
+ UniqueDispatchableHandle() = default;
+
+ UniqueDispatchableHandle(Handle handle, Deleter deleter) noexcept
+ : _handle{handle}
+ , _deleter{std::move(deleter)}
+ {}
+
+ ~UniqueDispatchableHandle() noexcept
+ {
+ if (_handle) {
+ _deleter(_handle);
+ }
+ }
+
+ UniqueDispatchableHandle(const UniqueDispatchableHandle&) noexcept = delete;
+ UniqueDispatchableHandle&
+ operator=(const UniqueDispatchableHandle&) noexcept = delete;
+
+ UniqueDispatchableHandle(UniqueDispatchableHandle&& other) noexcept
+ {
+ swap(other);
+ }
+
+ UniqueDispatchableHandle&
+ operator=(UniqueDispatchableHandle&& other) noexcept
+ {
+ swap(other);
+ return *this;
+ }
+
+ const Handle& get() const noexcept { return _handle; }
+
+ operator Handle() const noexcept { return _handle; }
+
+private:
+ void swap(UniqueDispatchableHandle& other) noexcept
+ {
+ std::swap(_handle, other._handle);
+ std::swap(_deleter, other._deleter);
+ }
+
+ Handle _handle{};
+ Deleter _deleter{};
+};
+
+#if defined(__LP64__) || defined(_WIN64) || \
+ (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || \
+ defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || \
+ defined(__powerpc64__)
+
+template<class T, class TDeleter>
+using UniqueNonDispatchableHandle = UniqueDispatchableHandle<T, TDeleter>;
+
+#else
+
+template<class T, class TDeleter>
+class UniqueNonDispatchableHandle
+{
+public:
+ using Deleter = TDeleter;
+ using Handle = T;
+
+ UniqueNonDispatchableHandle() = default;
+
+ UniqueNonDispatchableHandle(T handle, Deleter deleter) noexcept
+ : _handle{handle}
+ , _deleter{std::move(deleter)}
+ {
+ assert(handle);
+ }
+
+ ~UniqueNonDispatchableHandle() noexcept
+ {
+ if (_handle) {
+ _deleter(_handle);
+ }
+ }
+
+ UniqueNonDispatchableHandle(const UniqueNonDispatchableHandle&) noexcept =
+ delete;
+ UniqueNonDispatchableHandle&
+ operator=(const UniqueNonDispatchableHandle&) noexcept = delete;
+
+ UniqueNonDispatchableHandle(UniqueNonDispatchableHandle&& other) noexcept
+ {
+ swap(other);
+ }
+
+ UniqueNonDispatchableHandle&
+ operator=(UniqueNonDispatchableHandle&& other) noexcept
+ {
+ swap(other);
+ return *this;
+ }
+
+ const Handle& get() const noexcept { return _handle; }
+
+ operator Handle() const noexcept { return _handle; }
+
+private:
+ void swap(UniqueNonDispatchableHandle& other) noexcept
+ {
+ std::swap(_handle, other._handle);
+ std::swap(_deleter, other._deleter);
+ }
+
+ T _handle{};
+ Deleter _deleter{};
+};
+
+#endif
+
+template<class Vector, class Deleter>
+class UniqueArrayHandle
+{
+public:
+ using T = typename Vector::value_type;
+
+ UniqueArrayHandle() = default;
+
+ UniqueArrayHandle(uint32_t size, Vector&& array, Deleter deleter) noexcept
+ : _array{std::move(array)}
+ , _deleter{std::move(deleter)}
+ , _size{size}
+ {
+ assert(!_array.empty());
+ }
+
+ ~UniqueArrayHandle() noexcept
+ {
+ if (!_array.empty()) {
+ _deleter(_array.data());
+ }
+ }
+
+ UniqueArrayHandle(const UniqueArrayHandle&) noexcept = delete;
+ UniqueArrayHandle& operator=(const UniqueArrayHandle&) noexcept = delete;
+
+ UniqueArrayHandle(UniqueArrayHandle&& other) noexcept { swap(other); }
+
+ UniqueArrayHandle& operator=(UniqueArrayHandle&& other) noexcept
+ {
+ swap(other);
+ return *this;
+ }
+
+ const T& operator[](const size_t index) const noexcept
+ {
+ return _array[index];
+ }
+
+ T& operator[](const size_t index) noexcept { return _array[index]; }
+
+ const T* get() const noexcept { return _array.data(); }
+ T* get() noexcept { return _array.data(); }
+
+private:
+ void swap(UniqueArrayHandle& other) noexcept
+ {
+ std::swap(_array, other._array);
+ std::swap(_deleter, other._deleter);
+ std::swap(_size, other._size);
+ }
+
+ Vector _array{};
+ Deleter _deleter{};
+ uint32_t _size{};
+};
+
+template<typename T>
+class OptionalParameter
+{
+public:
+ using Handle = typename T::Handle;
+
+ OptionalParameter(const T& value) noexcept
+ : _handle{value.get()}
+ {}
+
+ OptionalParameter() noexcept
+ : _handle{}
+ {}
+
+ OptionalParameter(const OptionalParameter&) = delete;
+ OptionalParameter& operator=(const OptionalParameter&) = delete;
+
+ OptionalParameter(OptionalParameter&&) = delete;
+ OptionalParameter& operator=(OptionalParameter&&) = delete;
+
+ const Handle get() const noexcept { return _handle; }
+
+private:
+ Handle _handle{};
+};
+
+template<typename T>
+using GlobalObject = UniqueDispatchableHandle<T, GlobalDeleter<T>>;
+
+template<typename T>
+using InstanceChild =
+ UniqueNonDispatchableHandle<T, DependantDeleter<T, VkInstance>>;
+
+template<typename T>
+using DispatchableDeviceChild =
+ UniqueDispatchableHandle<T, DependantDeleter<T, VkDevice>>;
+
+template<typename T>
+using NonDispatchableDeviceChild =
+ UniqueNonDispatchableHandle<T, DependantDeleter<T, VkDevice>>;
+
+template<typename Vector, typename Pool, typename FreeFuncResult>
+using PoolChild = UniqueArrayHandle<
+ Vector,
+ PoolDeleter<typename Vector::value_type, Pool, FreeFuncResult>>;
+
+using Device = GlobalObject<VkDevice>;
+using Instance = GlobalObject<VkInstance>;
+
+using PhysicalDevice = VkPhysicalDevice; // Weak handle, no destroy function
+using Queue = VkQueue; // Weak handle, no destroy function
+
+using Buffer = NonDispatchableDeviceChild<VkBuffer>;
+using BufferView = NonDispatchableDeviceChild<VkBufferView>;
+using CommandBuffer = DispatchableDeviceChild<VkCommandBuffer>;
+using CommandPool = NonDispatchableDeviceChild<VkCommandPool>;
+using DescriptorPool = NonDispatchableDeviceChild<VkDescriptorPool>;
+using DescriptorSetLayout = NonDispatchableDeviceChild<VkDescriptorSetLayout>;
+using DeviceMemory = NonDispatchableDeviceChild<VkDeviceMemory>;
+using Event = NonDispatchableDeviceChild<VkEvent>;
+using Fence = NonDispatchableDeviceChild<VkFence>;
+using Framebuffer = NonDispatchableDeviceChild<VkFramebuffer>;
+using Image = NonDispatchableDeviceChild<VkImage>;
+using ImageView = NonDispatchableDeviceChild<VkImageView>;
+using Pipeline = NonDispatchableDeviceChild<VkPipeline>;
+using PipelineCache = NonDispatchableDeviceChild<VkPipelineCache>;
+using PipelineLayout = NonDispatchableDeviceChild<VkPipelineLayout>;
+using QueryPool = NonDispatchableDeviceChild<VkQueryPool>;
+using RenderPass = NonDispatchableDeviceChild<VkRenderPass>;
+using Sampler = NonDispatchableDeviceChild<VkSampler>;
+using Semaphore = NonDispatchableDeviceChild<VkSemaphore>;
+using ShaderModule = NonDispatchableDeviceChild<VkShaderModule>;
+
+template<class VkCommandBufferVector>
+using CommandBuffers = PoolChild<VkCommandBufferVector, VkCommandPool, void>;
+
+template<class VkDescriptorSetVector>
+using DescriptorSets =
+ PoolChild<VkDescriptorSetVector, VkDescriptorPool, VkResult>;
+
+// VK_KHR_swapchain
+using SwapchainKHR = NonDispatchableDeviceChild<VkSwapchainKHR>;
+
+// VK_KHR_surface
+using SurfaceKHR = InstanceChild<VkSurfaceKHR>;
+
+// VK_EXT_debug_report
+using DebugReportCallbackEXT = InstanceChild<VkDebugReportCallbackEXT>;
+
+template<size_t...>
+struct IndexSequence {};
+
+template<size_t N, size_t... Next>
+struct IndexSequenceHelper
+ : public IndexSequenceHelper<N - 1U, N - 1U, Next...> {};
+
+template<size_t... Next>
+struct IndexSequenceHelper<0U, Next...> {
+ using type = IndexSequence<Next...>;
+};
+
+template<size_t N>
+using makeIndexSequence = typename IndexSequenceHelper<N>::type;
+
+template<class T, class Parent, class DestroyFunc, size_t count, size_t... Is>
+std::array<T, count>
+make_handle_array_h(Parent parent,
+ DestroyFunc destroyFunc,
+ std::array<typename T::Handle, count> handles,
+ IndexSequence<Is...>) noexcept
+{
+ return {T{handles[Is], {parent, destroyFunc}}...};
+}
+
+template<class T, class Parent, class DestroyFunc, size_t count>
+std::array<T, count>
+make_handle_array(Parent parent,
+ DestroyFunc destroyFunc,
+ std::array<typename T::Handle, count> handles) noexcept
+{
+ return make_handle_array_h<T, Parent, DestroyFunc, count>(
+ parent, destroyFunc, handles, makeIndexSequence<count>());
+}
+
+namespace detail {
+
+template<class Value, class Vector, class Func, class... Args>
+inline VkResult
+wrapVectorAccessor(Vector& vector, Func func, Args... args) noexcept
+{
+ uint32_t count = 0u;
+ VkResult r = func(args..., &count, nullptr);
+ if (r > VK_INCOMPLETE) {
+ vector.clear();
+ return r;
+ }
+
+ vector = Vector(count);
+ if ((r = func(args..., &count, vector.data()))) {
+ vector.clear();
+ return r;
+ }
+
+ return VK_SUCCESS;
+}
+
+} // namespace detail
+
+class VulkanApi;
+
+struct MappedMemory {
+ MappedMemory() noexcept = default;
+
+ MappedMemory(const VulkanApi& api,
+ VkDevice device,
+ VkDeviceMemory memory,
+ void* data) noexcept
+ : _api{&api}
+ , _device{device}
+ , _memory{memory}
+ , _data{data}
+ {}
+
+ MappedMemory(const MappedMemory&) = delete;
+ MappedMemory& operator=(const MappedMemory&) = delete;
+
+ MappedMemory(MappedMemory&& mappedMemory) noexcept
+ : _api{mappedMemory._api}
+ , _device{mappedMemory._device}
+ , _memory{mappedMemory._memory}
+ , _data{mappedMemory._data}
+ {
+ mappedMemory._device = {};
+ mappedMemory._memory = {};
+ mappedMemory._data = {};
+ }
+
+ MappedMemory& operator=(MappedMemory&& mappedMemory) noexcept
+ {
+ std::swap(_api, mappedMemory._api);
+ std::swap(_device, mappedMemory._device);
+ std::swap(_memory, mappedMemory._memory);
+ std::swap(_data, mappedMemory._data);
+ return *this;
+ }
+
+ ~MappedMemory() noexcept;
+
+ const void* get() const noexcept { return _data; }
+ void* get() noexcept { return _data; }
+
+private:
+ const VulkanApi* _api{};
+ VkDevice _device{};
+ VkDeviceMemory _memory{};
+ void* _data{};
+};
+
+class VulkanInitApi
+{
+public:
+ template<typename NotFoundFunc>
+ VkResult init(PFN_vkGetInstanceProcAddr pGetInstanceProcAddr,
+ NotFoundFunc notFound) noexcept
+ {
+#define SK_INIT(name) \
+ do { \
+ if (!(name = PFN_##name(getInstanceProcAddr(NULL, #name)))) { \
+ notFound(#name); \
+ } \
+ } while (0)
+
+ vkGetInstanceProcAddr = pGetInstanceProcAddr;
+ SK_INIT(vkCreateInstance);
+ vkDestroyInstance = {}; // Loaded after we create an instance
+ SK_INIT(vkEnumerateInstanceExtensionProperties);
+ SK_INIT(vkEnumerateInstanceLayerProperties);
+
+ if (!vkCreateInstance || !vkEnumerateInstanceExtensionProperties ||
+ !vkEnumerateInstanceLayerProperties) {
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+ return VK_SUCCESS;
+#undef SK_INIT
+ }
+
+ VkResult init(PFN_vkGetInstanceProcAddr pGetInstanceProcAddr) noexcept
+ {
+ return init(pGetInstanceProcAddr, [](const char*) {});
+ }
+
+ PFN_vkVoidFunction
+ getInstanceProcAddr(VkInstance instance,
+ const char* const name) const noexcept
+ {
+ return vkGetInstanceProcAddr(instance, name);
+ }
+
+ VkResult createInstance(const VkInstanceCreateInfo& createInfo,
+ Instance& instance) noexcept
+ {
+ VkInstance h = {};
+ if (const VkResult r = vkCreateInstance(&createInfo, nullptr, &h)) {
+ return r;
+ } else if (!h) {
+ // Shouldn't actually happen, but this lets the compiler know that
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+ if (!vkDestroyInstance) {
+ vkDestroyInstance = PFN_vkDestroyInstance(
+ getInstanceProcAddr(instance, "vkDestroyInstance"));
+ }
+
+ instance = {h, {vkDestroyInstance}};
+ return VK_SUCCESS;
+ }
+
+ template<class Vector>
+ VkResult
+ enumerateInstanceExtensionProperties(Vector& properties) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkExtensionProperties>(
+ properties, vkEnumerateInstanceExtensionProperties, nullptr);
+ }
+
+ template<class Vector>
+ VkResult
+ enumerateInstanceExtensionProperties(const char* const layerName,
+ Vector& properties) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkExtensionProperties>(
+ properties, vkEnumerateInstanceExtensionProperties, layerName);
+ }
+
+ template<class Vector>
+ VkResult enumerateInstanceLayerProperties(Vector& properties) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkLayerProperties>(
+ properties, vkEnumerateInstanceLayerProperties);
+ }
+
+private:
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
+
+#define SK_FUNC(name) \
+ PFN_##name name {}
+
+ SK_FUNC(vkCreateInstance);
+ SK_FUNC(vkDestroyInstance);
+ SK_FUNC(vkEnumerateInstanceExtensionProperties);
+ SK_FUNC(vkEnumerateInstanceLayerProperties);
+
+#undef SK_FUNC
+};
+
+class VulkanApi
+{
+public:
+ template<typename NotFoundFunc>
+ VkResult init(const VulkanInitApi& initApi,
+ const Instance& instance,
+ NotFoundFunc notFound) noexcept
+ {
+ VkResult r = VK_SUCCESS;
+
+ const auto notFoundWrapper = [&r, notFound](const char* name) {
+ r = VK_INCOMPLETE;
+ notFound(name);
+ };
+
+#define SK_INIT(name) \
+ do { \
+ if (!(name = PFN_##name( \
+ initApi.getInstanceProcAddr(instance, #name)))) { \
+ notFoundWrapper(#name); \
+ } \
+ } while (0)
+
+ SK_INIT(vkAllocateCommandBuffers);
+ SK_INIT(vkAllocateDescriptorSets);
+ SK_INIT(vkAllocateMemory);
+ SK_INIT(vkBeginCommandBuffer);
+ SK_INIT(vkBindBufferMemory);
+ SK_INIT(vkBindImageMemory);
+ SK_INIT(vkCmdBeginQuery);
+ SK_INIT(vkCmdBeginRenderPass);
+ SK_INIT(vkCmdBindDescriptorSets);
+ SK_INIT(vkCmdBindIndexBuffer);
+ SK_INIT(vkCmdBindPipeline);
+ SK_INIT(vkCmdBindVertexBuffers);
+ SK_INIT(vkCmdBlitImage);
+ SK_INIT(vkCmdClearAttachments);
+ SK_INIT(vkCmdClearColorImage);
+ SK_INIT(vkCmdClearDepthStencilImage);
+ SK_INIT(vkCmdCopyBuffer);
+ SK_INIT(vkCmdCopyBufferToImage);
+ SK_INIT(vkCmdCopyImage);
+ SK_INIT(vkCmdCopyImageToBuffer);
+ SK_INIT(vkCmdCopyQueryPoolResults);
+ SK_INIT(vkCmdDispatch);
+ SK_INIT(vkCmdDispatchIndirect);
+ SK_INIT(vkCmdDraw);
+ SK_INIT(vkCmdDrawIndexed);
+ SK_INIT(vkCmdDrawIndexedIndirect);
+ SK_INIT(vkCmdDrawIndirect);
+ SK_INIT(vkCmdEndQuery);
+ SK_INIT(vkCmdEndRenderPass);
+ SK_INIT(vkCmdExecuteCommands);
+ SK_INIT(vkCmdFillBuffer);
+ SK_INIT(vkCmdNextSubpass);
+ SK_INIT(vkCmdPipelineBarrier);
+ SK_INIT(vkCmdPushConstants);
+ SK_INIT(vkCmdResetEvent);
+ SK_INIT(vkCmdResetQueryPool);
+ SK_INIT(vkCmdResolveImage);
+ SK_INIT(vkCmdSetBlendConstants);
+ SK_INIT(vkCmdSetDepthBias);
+ SK_INIT(vkCmdSetDepthBounds);
+ SK_INIT(vkCmdSetEvent);
+ SK_INIT(vkCmdSetLineWidth);
+ SK_INIT(vkCmdSetScissor);
+ SK_INIT(vkCmdSetStencilCompareMask);
+ SK_INIT(vkCmdSetStencilReference);
+ SK_INIT(vkCmdSetStencilWriteMask);
+ SK_INIT(vkCmdSetViewport);
+ SK_INIT(vkCmdUpdateBuffer);
+ SK_INIT(vkCmdWaitEvents);
+ SK_INIT(vkCmdWriteTimestamp);
+ SK_INIT(vkCreateBuffer);
+ SK_INIT(vkCreateBufferView);
+ SK_INIT(vkCreateCommandPool);
+ SK_INIT(vkCreateComputePipelines);
+ SK_INIT(vkCreateDescriptorPool);
+ SK_INIT(vkCreateDescriptorSetLayout);
+ SK_INIT(vkCreateDevice);
+ SK_INIT(vkCreateEvent);
+ SK_INIT(vkCreateFence);
+ SK_INIT(vkCreateFramebuffer);
+ SK_INIT(vkCreateGraphicsPipelines);
+ SK_INIT(vkCreateImage);
+ SK_INIT(vkCreateImageView);
+ SK_INIT(vkCreateInstance);
+ SK_INIT(vkCreatePipelineCache);
+ SK_INIT(vkCreatePipelineLayout);
+ SK_INIT(vkCreateQueryPool);
+ SK_INIT(vkCreateRenderPass);
+ SK_INIT(vkCreateSampler);
+ SK_INIT(vkCreateSemaphore);
+ SK_INIT(vkCreateShaderModule);
+ SK_INIT(vkDestroyBuffer);
+ SK_INIT(vkDestroyBufferView);
+ SK_INIT(vkDestroyCommandPool);
+ SK_INIT(vkDestroyDescriptorPool);
+ SK_INIT(vkDestroyDescriptorSetLayout);
+ SK_INIT(vkDestroyDevice);
+ SK_INIT(vkDestroyEvent);
+ SK_INIT(vkDestroyFence);
+ SK_INIT(vkDestroyFramebuffer);
+ SK_INIT(vkDestroyImage);
+ SK_INIT(vkDestroyImageView);
+ SK_INIT(vkDestroyPipeline);
+ SK_INIT(vkDestroyPipelineCache);
+ SK_INIT(vkDestroyPipelineLayout);
+ SK_INIT(vkDestroyQueryPool);
+ SK_INIT(vkDestroyRenderPass);
+ SK_INIT(vkDestroySampler);
+ SK_INIT(vkDestroySemaphore);
+ SK_INIT(vkDestroyShaderModule);
+ SK_INIT(vkDeviceWaitIdle);
+ SK_INIT(vkEndCommandBuffer);
+ SK_INIT(vkEnumerateDeviceExtensionProperties);
+ SK_INIT(vkEnumerateDeviceLayerProperties);
+ SK_INIT(vkEnumeratePhysicalDevices);
+ SK_INIT(vkFlushMappedMemoryRanges);
+ SK_INIT(vkFreeCommandBuffers);
+ SK_INIT(vkFreeDescriptorSets);
+ SK_INIT(vkFreeMemory);
+ SK_INIT(vkGetBufferMemoryRequirements);
+ SK_INIT(vkGetDeviceMemoryCommitment);
+ SK_INIT(vkGetDeviceProcAddr);
+ SK_INIT(vkGetDeviceQueue);
+ SK_INIT(vkGetEventStatus);
+ SK_INIT(vkGetFenceStatus);
+ SK_INIT(vkGetImageMemoryRequirements);
+ SK_INIT(vkGetImageSparseMemoryRequirements);
+ SK_INIT(vkGetImageSubresourceLayout);
+ SK_INIT(vkGetInstanceProcAddr);
+ SK_INIT(vkGetPhysicalDeviceFeatures);
+ SK_INIT(vkGetPhysicalDeviceFormatProperties);
+ SK_INIT(vkGetPhysicalDeviceImageFormatProperties);
+ SK_INIT(vkGetPhysicalDeviceMemoryProperties);
+ SK_INIT(vkGetPhysicalDeviceProperties);
+ SK_INIT(vkGetPhysicalDeviceQueueFamilyProperties);
+ SK_INIT(vkGetPhysicalDeviceSparseImageFormatProperties);
+ SK_INIT(vkGetPipelineCacheData);
+ SK_INIT(vkGetQueryPoolResults);
+ SK_INIT(vkGetRenderAreaGranularity);
+ SK_INIT(vkInvalidateMappedMemoryRanges);
+ SK_INIT(vkMapMemory);
+ SK_INIT(vkMergePipelineCaches);
+ SK_INIT(vkQueueBindSparse);
+ SK_INIT(vkQueueSubmit);
+ SK_INIT(vkQueueWaitIdle);
+ SK_INIT(vkResetCommandBuffer);
+ SK_INIT(vkResetCommandPool);
+ SK_INIT(vkResetDescriptorPool);
+ SK_INIT(vkResetEvent);
+ SK_INIT(vkResetFences);
+ SK_INIT(vkSetEvent);
+ SK_INIT(vkUnmapMemory);
+ SK_INIT(vkUpdateDescriptorSets);
+ SK_INIT(vkWaitForFences);
+
+ // VK_EXT_debug_report
+ SK_INIT(vkCreateDebugReportCallbackEXT);
+ SK_INIT(vkDebugReportMessageEXT);
+ SK_INIT(vkDestroyDebugReportCallbackEXT);
+
+ // VK_KHR_surface
+ SK_INIT(vkDestroySurfaceKHR);
+ SK_INIT(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
+ SK_INIT(vkGetPhysicalDeviceSurfaceFormatsKHR);
+ SK_INIT(vkGetPhysicalDeviceSurfacePresentModesKHR);
+ SK_INIT(vkGetPhysicalDeviceSurfaceSupportKHR);
+
+ // VK_KHR_swapchain
+ SK_INIT(vkAcquireNextImageKHR);
+ SK_INIT(vkCreateSwapchainKHR);
+ SK_INIT(vkDestroySwapchainKHR);
+ SK_INIT(vkGetDeviceGroupPresentCapabilitiesKHR);
+ SK_INIT(vkGetDeviceGroupSurfacePresentModesKHR);
+ SK_INIT(vkGetPhysicalDevicePresentRectanglesKHR);
+ SK_INIT(vkGetSwapchainImagesKHR);
+ SK_INIT(vkQueuePresentKHR);
+
+#undef SK_INIT
+
+ return r;
+ }
+
+ VkResult
+ init(const VulkanInitApi& initApi, const Instance& instance) noexcept
+ {
+ return init(initApi, instance, [](const char*) {});
+ }
+
+ template<class VkCommandBufferVector>
+ VkResult allocateCommandBuffers(
+ const Device& device,
+ const VkCommandBufferAllocateInfo& allocateInfo,
+ CommandBuffers<VkCommandBufferVector>& commandBuffers) const noexcept
+ {
+ VkCommandBufferVector rawCommandBuffers = VkCommandBufferVector(
+ allocateInfo.commandBufferCount);
+
+ if (const VkResult r = vkAllocateCommandBuffers(
+ device, &allocateInfo, rawCommandBuffers.data())) {
+ return r;
+ }
+
+ commandBuffers = CommandBuffers<VkCommandBufferVector>{
+ allocateInfo.commandBufferCount,
+ std::move(rawCommandBuffers),
+ PoolDeleter<VkCommandBuffer, VkCommandPool, void>{
+ device,
+ allocateInfo.commandPool,
+ allocateInfo.commandBufferCount,
+ vkFreeCommandBuffers}};
+ return VK_SUCCESS;
+ }
+
+ template<class VkDescriptorSetVector>
+ VkResult allocateDescriptorSets(
+ const Device& device,
+ const VkDescriptorSetAllocateInfo& allocateInfo,
+ DescriptorSets<VkDescriptorSetVector>& descriptorSets) const noexcept
+ {
+ auto descriptorSetVector = VkDescriptorSetVector(
+ allocateInfo.descriptorSetCount);
+
+ if (const VkResult r = vkAllocateDescriptorSets(
+ device, &allocateInfo, descriptorSetVector.data())) {
+ return r;
+ }
+
+ descriptorSets = DescriptorSets<VkDescriptorSetVector>{
+ allocateInfo.descriptorSetCount,
+ std::move(descriptorSetVector),
+ PoolDeleter<VkDescriptorSet, VkDescriptorPool, VkResult>{
+ device,
+ allocateInfo.descriptorPool,
+ allocateInfo.descriptorSetCount,
+ vkFreeDescriptorSets}};
+ return VK_SUCCESS;
+ }
+
+ VkResult bindBufferMemory(const Device& device,
+ const Buffer& buffer,
+ const DeviceMemory& memory,
+ VkDeviceSize memoryOffset) const noexcept
+ {
+ return vkBindBufferMemory
+ ? vkBindBufferMemory(device, buffer, memory, memoryOffset)
+ : VK_ERROR_FEATURE_NOT_PRESENT;
+ }
+
+ VkResult createBuffer(const Device& device,
+ const VkBufferCreateInfo& createInfo,
+ Buffer& buffer) const noexcept
+ {
+ VkBuffer h = {};
+ const VkResult r = vkCreateBuffer(device, &createInfo, nullptr, &h);
+ return wrapResult(r, h, {device, vkDestroyBuffer}, buffer);
+ }
+
+ VkResult createBufferView(const Device& device,
+ const VkBufferViewCreateInfo& createInfo,
+ BufferView& bufferView) const noexcept
+ {
+ VkBufferView h = {};
+ const VkResult r = vkCreateBufferView(device, &createInfo, nullptr, &h);
+ return wrapResult(r, h, {device, vkDestroyBufferView}, bufferView);
+ }
+
+ VkResult createCommandPool(const Device& device,
+ const VkCommandPoolCreateInfo& createInfo,
+ CommandPool& commandPool) const noexcept
+ {
+ VkCommandPool h = {};
+ const VkResult r =
+ vkCreateCommandPool(device, &createInfo, nullptr, &h);
+ return wrapResult(r, h, {device, vkDestroyCommandPool}, commandPool);
+ }
+
+ VkResult createDescriptorPool(const Device& device,
+ const VkDescriptorPoolCreateInfo& createInfo,
+ DescriptorPool& descriptorPool) const noexcept
+ {
+ VkDescriptorPool h = {};
+ const VkResult r =
+ vkCreateDescriptorPool(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r,
+ h,
+ {device, vkDestroyDescriptorPool},
+ descriptorPool);
+ }
+
+ VkResult createDescriptorSetLayout(
+ const Device& device,
+ const VkDescriptorSetLayoutCreateInfo& createInfo,
+ DescriptorSetLayout& descriptorSetLayout) const noexcept
+ {
+ VkDescriptorSetLayout h = {};
+ const VkResult r =
+ vkCreateDescriptorSetLayout(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r,
+ h,
+ {device, vkDestroyDescriptorSetLayout},
+ descriptorSetLayout);
+ }
+
+ VkResult createDevice(const PhysicalDevice& physicalDevice,
+ const VkDeviceCreateInfo& createInfo,
+ Device& result) const noexcept
+ {
+ VkDevice h = {};
+ const VkResult r =
+ vkCreateDevice(physicalDevice, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {vkDestroyDevice}, result);
+ }
+
+ VkResult createEvent(const Device& device,
+ const VkEventCreateInfo& createInfo,
+ Event& event) const noexcept
+ {
+ VkEvent h = {};
+ const VkResult r = vkCreateEvent(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyEvent}, event);
+ }
+
+ VkResult createFence(const Device& device,
+ const VkFenceCreateInfo& createInfo,
+ Fence& fence) const noexcept
+ {
+ VkFence h = {};
+ const VkResult r = vkCreateFence(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyFence}, fence);
+ }
+
+ VkResult createFramebuffer(const Device& device,
+ const VkFramebufferCreateInfo& createInfo,
+ Framebuffer& framebuffer) const noexcept
+ {
+ VkFramebuffer h = {};
+ const VkResult r =
+ vkCreateFramebuffer(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyFramebuffer}, framebuffer);
+ }
+
+ VkResult createImage(const Device& device,
+ const VkImageCreateInfo& createInfo,
+ Image& image) const noexcept
+ {
+ VkImage h = {};
+ const VkResult r = vkCreateImage(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyImage}, image);
+ }
+
+ VkResult createImageView(const Device& device,
+ const VkImageViewCreateInfo& createInfo,
+ ImageView& imageView) const noexcept
+ {
+ VkImageView h = {};
+ const VkResult r = vkCreateImageView(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyImageView}, imageView);
+ }
+
+ template<size_t count>
+ VkResult createGraphicsPipelines(
+ const Device& device,
+ const OptionalParameter<PipelineCache>& pipelineCache,
+ const std::array<VkGraphicsPipelineCreateInfo, count>& createInfos,
+ std::array<Pipeline, count>& pipelines) const noexcept
+ {
+ std::array<VkPipeline, count> pipelineHandles{};
+
+ if (const VkResult r = vkCreateGraphicsPipelines(
+ device,
+ pipelineCache.get(),
+ static_cast<uint32_t>(createInfos.size()),
+ createInfos.data(),
+ nullptr,
+ pipelineHandles.data())) {
+ return r;
+ }
+
+ pipelines = make_handle_array<Pipeline>(device.get(),
+ vkDestroyPipeline,
+ pipelineHandles);
+ return VK_SUCCESS;
+ }
+
+ VkResult createPipelineCache(const Device& device,
+ const VkPipelineCacheCreateInfo& createInfo,
+ PipelineCache& pipelineCache) const noexcept
+ {
+ VkPipelineCache h = {};
+ const VkResult r =
+ vkCreatePipelineCache(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r,
+ h,
+ {device, vkDestroyPipelineCache},
+ pipelineCache);
+ }
+
+ VkResult createPipelineLayout(const Device& device,
+ const VkPipelineLayoutCreateInfo& createInfo,
+ PipelineLayout& pipelineLayout) const noexcept
+ {
+ VkPipelineLayout h = {};
+ const VkResult r =
+ vkCreatePipelineLayout(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r,
+ h,
+ {device, vkDestroyPipelineLayout},
+ pipelineLayout);
+ }
+
+ VkResult createQueryPool(const Device& device,
+ const VkQueryPoolCreateInfo& createInfo,
+ QueryPool& queryPool) const noexcept
+ {
+ VkQueryPool h = {};
+ const VkResult r = vkCreateQueryPool(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyQueryPool}, queryPool);
+ }
+
+ VkResult createRenderPass(const Device& device,
+ const VkRenderPassCreateInfo& createInfo,
+ RenderPass& renderPass) const noexcept
+ {
+ VkRenderPass h = {};
+ const VkResult r = vkCreateRenderPass(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyRenderPass}, renderPass);
+ }
+
+ VkResult createSampler(const Device& device,
+ const VkSamplerCreateInfo& createInfo,
+ Sampler& sampler) const noexcept
+ {
+ VkSampler h = {};
+ const VkResult r = vkCreateSampler(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroySampler}, sampler);
+ }
+
+ VkResult createSemaphore(const Device& device,
+ const VkSemaphoreCreateInfo& createInfo,
+ Semaphore& semaphore) const noexcept
+ {
+ VkSemaphore h = {};
+ const VkResult r = vkCreateSemaphore(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroySemaphore}, semaphore);
+ }
+
+ VkResult createShaderModule(const Device& device,
+ const VkShaderModuleCreateInfo& createInfo,
+ ShaderModule& shaderModule) const noexcept
+ {
+ VkShaderModule h = {};
+ const VkResult r =
+ vkCreateShaderModule(device, &createInfo, nullptr, &h);
+
+ return wrapResult(r, h, {device, vkDestroyShaderModule}, shaderModule);
+ }
+
+ VkResult deviceWaitIdle(const Device& device) const noexcept
+ {
+ return vkDeviceWaitIdle(device);
+ }
+
+ template<class Vector>
+ VkResult
+ enumerateDeviceExtensionProperties(const PhysicalDevice& physicalDevice,
+ const char* const layerName,
+ Vector& properties) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkExtensionProperties>(
+ properties,
+ vkEnumerateDeviceExtensionProperties,
+ physicalDevice,
+ layerName);
+ }
+
+ template<class Vector>
+ VkResult
+ enumerateDeviceExtensionProperties(const PhysicalDevice& physicalDevice,
+ Vector& properties) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkExtensionProperties>(
+ properties,
+ vkEnumerateDeviceExtensionProperties,
+ physicalDevice,
+ nullptr);
+ }
+
+ template<class Vector>
+ VkResult enumeratePhysicalDevices(const Instance& instance,
+ Vector& physicalDevices) const noexcept
+ {
+ uint32_t count = 0u;
+ VkResult r = vkEnumeratePhysicalDevices(instance, &count, nullptr);
+ if (r > VK_INCOMPLETE) {
+ return r;
+ }
+
+ physicalDevices = Vector(count);
+ if ((r = vkEnumeratePhysicalDevices(instance,
+ &count,
+ physicalDevices.data()))) {
+ return r;
+ }
+
+ return VK_SUCCESS;
+ }
+
+ sk::Queue getDeviceQueue(const Device& device,
+ const uint32_t queueFamilyIndex,
+ const uint32_t queueIndex) const noexcept
+ {
+ VkQueue queue{};
+ vkGetDeviceQueue(device, queueFamilyIndex, queueIndex, &queue);
+ return sk::Queue{queue};
+ }
+
+ VkPhysicalDeviceMemoryProperties getPhysicalDeviceMemoryProperties(
+ VkPhysicalDevice physicalDevice) const noexcept
+ {
+ VkPhysicalDeviceMemoryProperties properties{};
+ vkGetPhysicalDeviceMemoryProperties(physicalDevice, &properties);
+ return properties;
+ }
+
+ VkPhysicalDeviceProperties getPhysicalDeviceProperties(
+ const PhysicalDevice& physicalDevice) const noexcept
+ {
+ VkPhysicalDeviceProperties properties{};
+ vkGetPhysicalDeviceProperties(physicalDevice, &properties);
+ return properties;
+ }
+
+ template<class Vector>
+ VkResult getPhysicalDeviceQueueFamilyProperties(
+ const PhysicalDevice& physicalDevice,
+ Vector& queueFamilyProperties) const noexcept
+ {
+ uint32_t count = 0u;
+ vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice,
+ &count,
+ nullptr);
+
+ queueFamilyProperties = Vector(count);
+ vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice,
+ &count,
+ queueFamilyProperties.data());
+
+ return VK_SUCCESS;
+ }
+
+ VkMemoryRequirements
+ getBufferMemoryRequirements(const Device& device,
+ const Buffer& buffer) const noexcept
+ {
+ VkMemoryRequirements requirements;
+ vkGetBufferMemoryRequirements(device, buffer, &requirements);
+ return requirements;
+ }
+
+ VkResult allocateMemory(const Device& device,
+ const VkMemoryAllocateInfo& info,
+ DeviceMemory& memory) const noexcept
+ {
+ VkDeviceMemory h = {};
+ if (const VkResult r = vkAllocateMemory(device, &info, nullptr, &h)) {
+ return r;
+ } else if (!h) {
+ return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+ }
+
+ memory = DeviceMemory{h, {device, vkFreeMemory}};
+ return VK_SUCCESS;
+ }
+
+ VkResult mapMemory(const Device& device,
+ const DeviceMemory& memory,
+ VkDeviceSize offset,
+ VkDeviceSize size,
+ VkMemoryMapFlags flags,
+ MappedMemory& mappedMemory) const noexcept
+ {
+ void* data = nullptr;
+ if (const VkResult r =
+ vkMapMemory(device, memory, offset, size, flags, &data)) {
+ return r;
+ }
+
+ mappedMemory = MappedMemory{*this, device, memory, data};
+ return VK_SUCCESS;
+ }
+
+ VkResult queueSubmit(const Queue& queue,
+ uint32_t submitCount,
+ const VkSubmitInfo& submits,
+ const Fence& fence) const noexcept
+ {
+ return vkQueueSubmit(queue, submitCount, &submits, fence);
+ }
+
+ VkResult queueSubmit(const Queue& queue,
+ const VkSubmitInfo& submit,
+ const Fence& fence) const noexcept
+ {
+ return vkQueueSubmit(queue, 1u, &submit, fence);
+ }
+
+ template<size_t descriptorWriteCount, size_t descriptorCopyCount>
+ void updateDescriptorSets(
+ const Device& device,
+ std::array<VkWriteDescriptorSet, descriptorWriteCount> descriptorWrites,
+ std::array<VkCopyDescriptorSet, descriptorCopyCount> descriptorCopies)
+ const noexcept
+ {
+ vkUpdateDescriptorSets(device,
+ static_cast<uint32_t>(descriptorWrites.size()),
+ descriptorWrites.data(),
+ static_cast<uint32_t>(descriptorCopies.size()),
+ descriptorCopies.data());
+ }
+
+ VkResult resetFence(const Device& device, const Fence& fence) const noexcept
+ {
+ VkFence h = fence;
+ return vkResetFences(device, 1u, &h);
+ }
+
+ VkResult waitForFence(const Device& device,
+ const Fence& fence,
+ uint64_t timeout) const noexcept
+ {
+ VkFence h = fence;
+ return vkWaitForFences(device, 1u, &h, VK_TRUE, timeout);
+ }
+
+ VkResult
+ waitForFence(const Device& device, const Fence& fence) const noexcept
+ {
+ VkFence h = fence;
+ return vkWaitForFences(device, 1u, &h, VK_TRUE, UINT64_MAX);
+ }
+
+ // Scoped command buffer interface
+ SYBOK_NODISCARD
+ CommandScope
+ beginCommandBuffer(VkCommandBuffer commandBuffer,
+ VkCommandBufferBeginInfo beginInfo) const noexcept;
+
+ // VK_EXT_debug_report
+
+ VkResult createDebugReportCallbackEXT(
+ const Instance& instance,
+ const VkDebugReportCallbackCreateInfoEXT& createInfo,
+ DebugReportCallbackEXT& callback) const noexcept
+ {
+ VkDebugReportCallbackEXT h = {};
+
+ if (const VkResult r = vkCreateDebugReportCallbackEXT(
+ instance, &createInfo, nullptr, &h)) {
+ return r;
+ } else if (!h) {
+ return VK_ERROR_FEATURE_NOT_PRESENT;
+ }
+
+ callback = {h, {instance, vkDestroyDebugReportCallbackEXT}};
+ return VK_SUCCESS;
+ }
+
+ // VK_KHR_surface
+
+ VkResult getPhysicalDeviceSurfaceCapabilitiesKHR(
+ const PhysicalDevice& physicalDevice,
+ const SurfaceKHR& surface,
+ VkSurfaceCapabilitiesKHR& capabilities) const noexcept
+ {
+ return vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice,
+ surface,
+ &capabilities);
+ }
+
+ template<typename Vector>
+ VkResult
+ getPhysicalDeviceSurfaceFormatsKHR(const PhysicalDevice& physicalDevice,
+ const SurfaceKHR& surface,
+ Vector& surfaceFormats) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkSurfaceFormatKHR>(
+ surfaceFormats,
+ vkGetPhysicalDeviceSurfaceFormatsKHR,
+ physicalDevice,
+ surface.get());
+ }
+
+ template<typename Vector>
+ VkResult getPhysicalDeviceSurfacePresentModesKHR(
+ const PhysicalDevice& physicalDevice,
+ const SurfaceKHR& surface,
+ Vector& presentModes) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkPresentModeKHR>(
+ presentModes,
+ vkGetPhysicalDeviceSurfacePresentModesKHR,
+ physicalDevice,
+ surface.get());
+ }
+
+ VkResult
+ getPhysicalDeviceSurfaceSupportKHR(const PhysicalDevice& physicalDevice,
+ uint32_t queueFamilyIndex,
+ const SurfaceKHR& surface,
+ bool& supported) const noexcept
+ {
+ VkBool32 s = {};
+
+ if (VkResult r = vkGetPhysicalDeviceSurfaceSupportKHR(
+ physicalDevice, queueFamilyIndex, surface, &s)) {
+ return r;
+ }
+
+ supported = s;
+ return VK_SUCCESS;
+ }
+
+ // VK_KHR_swapchain
+
+ VkResult acquireNextImageKHR(const Device& device,
+ const SwapchainKHR& swapchain,
+ uint64_t timeout,
+ const Semaphore& semaphore,
+ const OptionalParameter<Fence>& fence,
+ uint32_t* pImageIndex) const noexcept
+ {
+ return vkAcquireNextImageKHR(
+ device, swapchain, timeout, semaphore, fence.get(), pImageIndex);
+ }
+
+ template<class Vector>
+ VkResult getSwapchainImagesKHR(const Device& device,
+ const SwapchainKHR& swapchain,
+ Vector& images) const noexcept
+ {
+ return detail::wrapVectorAccessor<VkImage>(images,
+ vkGetSwapchainImagesKHR,
+ device.get(),
+ swapchain.get());
+ }
+
+ VkResult createSwapchainKHR(const Device& device,
+ const VkSwapchainCreateInfoKHR& createInfo,
+ SwapchainKHR& swapchain) const noexcept
+ {
+ VkSwapchainKHR h = {};
+ const VkResult r =
+ vkCreateSwapchainKHR(device, &createInfo, nullptr, &h);
+
+ if (r) {
+ return r;
+ } else if (!h) {
+ return VK_ERROR_INCOMPATIBLE_DRIVER;
+ }
+
+ swapchain = {h, {device, vkDestroySwapchainKHR}};
+ return VK_SUCCESS;
+ }
+
+ VkResult queuePresentKHR(const Queue& queue,
+ const VkPresentInfoKHR& presentInfo) const noexcept
+ {
+ return vkQueuePresentKHR(queue, &presentInfo);
+ }
+
+#define SK_FUNC(name) \
+ PFN_##name name {} // NOLINT
+
+ // Vulkan 1.0 Core
+ SK_FUNC(vkAllocateCommandBuffers);
+ SK_FUNC(vkAllocateDescriptorSets);
+ SK_FUNC(vkAllocateMemory);
+ SK_FUNC(vkBeginCommandBuffer);
+ SK_FUNC(vkBindBufferMemory);
+ SK_FUNC(vkBindImageMemory);
+ SK_FUNC(vkCmdBeginQuery);
+ SK_FUNC(vkCmdBeginRenderPass);
+ SK_FUNC(vkCmdBindDescriptorSets);
+ SK_FUNC(vkCmdBindIndexBuffer);
+ SK_FUNC(vkCmdBindPipeline);
+ SK_FUNC(vkCmdBindVertexBuffers);
+ SK_FUNC(vkCmdBlitImage);
+ SK_FUNC(vkCmdClearAttachments);
+ SK_FUNC(vkCmdClearColorImage);
+ SK_FUNC(vkCmdClearDepthStencilImage);
+ SK_FUNC(vkCmdCopyBuffer);
+ SK_FUNC(vkCmdCopyBufferToImage);
+ SK_FUNC(vkCmdCopyImage);
+ SK_FUNC(vkCmdCopyImageToBuffer);
+ SK_FUNC(vkCmdCopyQueryPoolResults);
+ SK_FUNC(vkCmdDispatch);
+ SK_FUNC(vkCmdDispatchIndirect);
+ SK_FUNC(vkCmdDraw);
+ SK_FUNC(vkCmdDrawIndexed);
+ SK_FUNC(vkCmdDrawIndexedIndirect);
+ SK_FUNC(vkCmdDrawIndirect);
+ SK_FUNC(vkCmdEndQuery);
+ SK_FUNC(vkCmdEndRenderPass);
+ SK_FUNC(vkCmdExecuteCommands);
+ SK_FUNC(vkCmdFillBuffer);
+ SK_FUNC(vkCmdNextSubpass);
+ SK_FUNC(vkCmdPipelineBarrier);
+ SK_FUNC(vkCmdPushConstants);
+ SK_FUNC(vkCmdResetEvent);
+ SK_FUNC(vkCmdResetQueryPool);
+ SK_FUNC(vkCmdResolveImage);
+ SK_FUNC(vkCmdSetBlendConstants);
+ SK_FUNC(vkCmdSetDepthBias);
+ SK_FUNC(vkCmdSetDepthBounds);
+ SK_FUNC(vkCmdSetEvent);
+ SK_FUNC(vkCmdSetLineWidth);
+ SK_FUNC(vkCmdSetScissor);
+ SK_FUNC(vkCmdSetStencilCompareMask);
+ SK_FUNC(vkCmdSetStencilReference);
+ SK_FUNC(vkCmdSetStencilWriteMask);
+ SK_FUNC(vkCmdSetViewport);
+ SK_FUNC(vkCmdUpdateBuffer);
+ SK_FUNC(vkCmdWaitEvents);
+ SK_FUNC(vkCmdWriteTimestamp);
+ SK_FUNC(vkCreateBuffer);
+ SK_FUNC(vkCreateBufferView);
+ SK_FUNC(vkCreateCommandPool);
+ SK_FUNC(vkCreateComputePipelines);
+ SK_FUNC(vkCreateDescriptorPool);
+ SK_FUNC(vkCreateDescriptorSetLayout);
+ SK_FUNC(vkCreateDevice);
+ SK_FUNC(vkCreateEvent);
+ SK_FUNC(vkCreateFence);
+ SK_FUNC(vkCreateFramebuffer);
+ SK_FUNC(vkCreateGraphicsPipelines);
+ SK_FUNC(vkCreateImage);
+ SK_FUNC(vkCreateImageView);
+ SK_FUNC(vkCreateInstance);
+ SK_FUNC(vkCreatePipelineCache);
+ SK_FUNC(vkCreatePipelineLayout);
+ SK_FUNC(vkCreateQueryPool);
+ SK_FUNC(vkCreateRenderPass);
+ SK_FUNC(vkCreateSampler);
+ SK_FUNC(vkCreateSemaphore);
+ SK_FUNC(vkCreateShaderModule);
+ SK_FUNC(vkDestroyBuffer);
+ SK_FUNC(vkDestroyBufferView);
+ SK_FUNC(vkDestroyCommandPool);
+ SK_FUNC(vkDestroyDescriptorPool);
+ SK_FUNC(vkDestroyDescriptorSetLayout);
+ SK_FUNC(vkDestroyDevice);
+ SK_FUNC(vkDestroyEvent);
+ SK_FUNC(vkDestroyFence);
+ SK_FUNC(vkDestroyFramebuffer);
+ SK_FUNC(vkDestroyImage);
+ SK_FUNC(vkDestroyImageView);
+ SK_FUNC(vkDestroyPipeline);
+ SK_FUNC(vkDestroyPipelineCache);
+ SK_FUNC(vkDestroyPipelineLayout);
+ SK_FUNC(vkDestroyQueryPool);
+ SK_FUNC(vkDestroyRenderPass);
+ SK_FUNC(vkDestroySampler);
+ SK_FUNC(vkDestroySemaphore);
+ SK_FUNC(vkDestroyShaderModule);
+ SK_FUNC(vkDeviceWaitIdle);
+ SK_FUNC(vkEndCommandBuffer);
+ SK_FUNC(vkEnumerateDeviceExtensionProperties);
+ SK_FUNC(vkEnumerateDeviceLayerProperties);
+ SK_FUNC(vkEnumeratePhysicalDevices);
+ SK_FUNC(vkFlushMappedMemoryRanges);
+ SK_FUNC(vkFreeCommandBuffers);
+ SK_FUNC(vkFreeDescriptorSets);
+ SK_FUNC(vkFreeMemory);
+ SK_FUNC(vkGetBufferMemoryRequirements);
+ SK_FUNC(vkGetDeviceMemoryCommitment);
+ SK_FUNC(vkGetDeviceProcAddr);
+ SK_FUNC(vkGetDeviceQueue);
+ SK_FUNC(vkGetEventStatus);
+ SK_FUNC(vkGetFenceStatus);
+ SK_FUNC(vkGetImageMemoryRequirements);
+ SK_FUNC(vkGetImageSparseMemoryRequirements);
+ SK_FUNC(vkGetImageSubresourceLayout);
+ SK_FUNC(vkGetInstanceProcAddr);
+ SK_FUNC(vkGetPhysicalDeviceFeatures);
+ SK_FUNC(vkGetPhysicalDeviceFormatProperties);
+ SK_FUNC(vkGetPhysicalDeviceImageFormatProperties);
+ SK_FUNC(vkGetPhysicalDeviceMemoryProperties);
+ SK_FUNC(vkGetPhysicalDeviceProperties);
+ SK_FUNC(vkGetPhysicalDeviceQueueFamilyProperties);
+ SK_FUNC(vkGetPhysicalDeviceSparseImageFormatProperties);
+ SK_FUNC(vkGetPipelineCacheData);
+ SK_FUNC(vkGetQueryPoolResults);
+ SK_FUNC(vkGetRenderAreaGranularity);
+ SK_FUNC(vkInvalidateMappedMemoryRanges);
+ SK_FUNC(vkMapMemory);
+ SK_FUNC(vkMergePipelineCaches);
+ SK_FUNC(vkQueueBindSparse);
+ SK_FUNC(vkQueueSubmit);
+ SK_FUNC(vkQueueWaitIdle);
+ SK_FUNC(vkResetCommandBuffer);
+ SK_FUNC(vkResetCommandPool);
+ SK_FUNC(vkResetDescriptorPool);
+ SK_FUNC(vkResetEvent);
+ SK_FUNC(vkResetFences);
+ SK_FUNC(vkSetEvent);
+ SK_FUNC(vkUnmapMemory);
+ SK_FUNC(vkUpdateDescriptorSets);
+ SK_FUNC(vkWaitForFences);
+
+ // VK_EXT_debug_report
+ SK_FUNC(vkCreateDebugReportCallbackEXT);
+ SK_FUNC(vkDebugReportMessageEXT);
+ SK_FUNC(vkDestroyDebugReportCallbackEXT);
+
+ // VK_KHR_surface
+ SK_FUNC(vkDestroySurfaceKHR);
+ SK_FUNC(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
+ SK_FUNC(vkGetPhysicalDeviceSurfaceFormatsKHR);
+ SK_FUNC(vkGetPhysicalDeviceSurfacePresentModesKHR);
+ SK_FUNC(vkGetPhysicalDeviceSurfaceSupportKHR);
+
+ // VK_KHR_swapchain
+ SK_FUNC(vkAcquireNextImageKHR);
+ SK_FUNC(vkCreateSwapchainKHR);
+ SK_FUNC(vkDestroySwapchainKHR);
+ SK_FUNC(vkGetDeviceGroupPresentCapabilitiesKHR);
+ SK_FUNC(vkGetDeviceGroupSurfacePresentModesKHR);
+ SK_FUNC(vkGetPhysicalDevicePresentRectanglesKHR);
+ SK_FUNC(vkGetSwapchainImagesKHR);
+ SK_FUNC(vkQueuePresentKHR);
+
+#undef SK_FUNC
+
+private:
+ template<class T>
+ static inline VkResult wrapResult(const VkResult r,
+ const typename T::Handle handle,
+ typename T::Deleter&& deleter,
+ T& result) noexcept
+ {
+ if (r) {
+ return r;
+ } else if (!handle) {
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+ result = T{handle, std::move(deleter)};
+ return VK_SUCCESS;
+ }
+};
+
+/// Scope for commands that work both inside and outside a render pass
+class CommonCommandScope
+{
+public:
+ CommonCommandScope(const VulkanApi& api,
+ VkCommandBuffer commandBuffer,
+ VkResult result) noexcept
+ : _api{api}
+ , _commandBuffer{commandBuffer}
+ , _result{result}
+ {}
+
+ CommonCommandScope(const CommonCommandScope&) noexcept = delete;
+ CommonCommandScope& operator=(const CommonCommandScope&) noexcept = delete;
+
+ CommonCommandScope(CommonCommandScope&& scope) noexcept
+ : _api{scope._api}
+ , _commandBuffer{scope._commandBuffer}
+ {
+ scope._commandBuffer = {};
+ }
+
+ CommonCommandScope& operator=(CommonCommandScope&&) = delete;
+
+ ~CommonCommandScope() noexcept = default;
+
+ explicit operator bool() const noexcept { return _result == VK_SUCCESS; }
+
+ VkResult error() const noexcept { return _result; }
+
+ void bindPipeline(VkPipelineBindPoint pipelineBindPoint,
+ VkPipeline pipeline) const noexcept
+ {
+ _api.vkCmdBindPipeline(_commandBuffer, pipelineBindPoint, pipeline);
+ }
+
+ void setViewport(uint32_t firstViewport,
+ uint32_t viewportCount,
+ const VkViewport* pViewports) const noexcept
+ {
+ _api.vkCmdSetViewport(_commandBuffer,
+ firstViewport,
+ viewportCount,
+ pViewports);
+ }
+
+ void setScissor(uint32_t firstScissor,
+ uint32_t scissorCount,
+ const VkRect2D* pScissors) const noexcept
+ {
+ _api.vkCmdSetScissor(_commandBuffer,
+ firstScissor,
+ scissorCount,
+ pScissors);
+ }
+
+ void setLineWidth(float lineWidth) const noexcept
+ {
+ _api.vkCmdSetLineWidth(_commandBuffer, lineWidth);
+ }
+
+ void setDepthBias(float depthBiasConstantFactor,
+ float depthBiasClamp,
+ float depthBiasSlopeFactor) const noexcept
+ {
+ _api.vkCmdSetDepthBias(_commandBuffer,
+ depthBiasConstantFactor,
+ depthBiasClamp,
+ depthBiasSlopeFactor);
+ }
+
+ void setBlendConstants(const float blendConstants[4]) const noexcept
+ {
+ _api.vkCmdSetBlendConstants(_commandBuffer, blendConstants);
+ }
+
+ void
+ setDepthBounds(float minDepthBounds, float maxDepthBounds) const noexcept
+ {
+ _api.vkCmdSetDepthBounds(_commandBuffer,
+ minDepthBounds,
+ maxDepthBounds);
+ }
+
+ void setStencilCompareMask(VkStencilFaceFlags faceMask,
+ uint32_t compareMask) const noexcept
+ {
+ _api.vkCmdSetStencilCompareMask(_commandBuffer, faceMask, compareMask);
+ }
+
+ void setStencilWriteMask(VkStencilFaceFlags faceMask,
+ uint32_t writeMask) const noexcept
+ {
+ _api.vkCmdSetStencilWriteMask(_commandBuffer, faceMask, writeMask);
+ }
+
+ void setStencilReference(VkStencilFaceFlags faceMask,
+ uint32_t reference) const noexcept
+ {
+ _api.vkCmdSetStencilReference(_commandBuffer, faceMask, reference);
+ }
+
+ void bindDescriptorSets(VkPipelineBindPoint pipelineBindPoint,
+ VkPipelineLayout layout,
+ uint32_t firstSet,
+ uint32_t descriptorSetCount,
+ const VkDescriptorSet* pDescriptorSets,
+ uint32_t dynamicOffsetCount,
+ const uint32_t* pDynamicOffsets) const noexcept
+ {
+ _api.vkCmdBindDescriptorSets(_commandBuffer,
+ pipelineBindPoint,
+ layout,
+ firstSet,
+ descriptorSetCount,
+ pDescriptorSets,
+ dynamicOffsetCount,
+ pDynamicOffsets);
+ }
+
+ void bindIndexBuffer(VkBuffer buffer,
+ VkDeviceSize offset,
+ VkIndexType indexType) const noexcept
+ {
+ _api.vkCmdBindIndexBuffer(_commandBuffer, buffer, offset, indexType);
+ }
+
+ void bindVertexBuffers(uint32_t firstBinding,
+ uint32_t bindingCount,
+ const VkBuffer* pBuffers,
+ const VkDeviceSize* pOffsets) const noexcept
+ {
+ _api.vkCmdBindVertexBuffers(
+ _commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
+ }
+
+ void
+ waitEvents(uint32_t eventCount,
+ const VkEvent* pEvents,
+ VkPipelineStageFlags srcStageMask,
+ VkPipelineStageFlags dstStageMask,
+ uint32_t memoryBarrierCount,
+ const VkMemoryBarrier* pMemoryBarriers,
+ uint32_t bufferMemoryBarrierCount,
+ const VkBufferMemoryBarrier* pBufferMemoryBarriers,
+ uint32_t imageMemoryBarrierCount,
+ const VkImageMemoryBarrier* pImageMemoryBarriers) const noexcept
+ {
+ _api.vkCmdWaitEvents(_commandBuffer,
+ eventCount,
+ pEvents,
+ srcStageMask,
+ dstStageMask,
+ memoryBarrierCount,
+ pMemoryBarriers,
+ bufferMemoryBarrierCount,
+ pBufferMemoryBarriers,
+ imageMemoryBarrierCount,
+ pImageMemoryBarriers);
+ }
+
+ void pipelineBarrier(
+ VkPipelineStageFlags srcStageMask,
+ VkPipelineStageFlags dstStageMask,
+ VkDependencyFlags dependencyFlags,
+ uint32_t memoryBarrierCount,
+ const VkMemoryBarrier* pMemoryBarriers,
+ uint32_t bufferMemoryBarrierCount,
+ const VkBufferMemoryBarrier* pBufferMemoryBarriers,
+ uint32_t imageMemoryBarrierCount,
+ const VkImageMemoryBarrier* pImageMemoryBarriers) const noexcept
+ {
+ _api.vkCmdPipelineBarrier(_commandBuffer,
+ srcStageMask,
+ dstStageMask,
+ dependencyFlags,
+ memoryBarrierCount,
+ pMemoryBarriers,
+ bufferMemoryBarrierCount,
+ pBufferMemoryBarriers,
+ imageMemoryBarrierCount,
+ pImageMemoryBarriers);
+ }
+
+ void beginQuery(VkQueryPool queryPool,
+ uint32_t query,
+ VkQueryControlFlags flags) const noexcept
+ {
+ _api.vkCmdBeginQuery(_commandBuffer, queryPool, query, flags);
+ }
+
+ void endQuery(VkQueryPool queryPool, uint32_t query) const noexcept
+ {
+ _api.vkCmdEndQuery(_commandBuffer, queryPool, query);
+ }
+
+ void writeTimestamp(VkPipelineStageFlagBits pipelineStage,
+ VkQueryPool queryPool,
+ uint32_t query) const noexcept
+ {
+ _api.vkCmdWriteTimestamp(_commandBuffer,
+ pipelineStage,
+ queryPool,
+ query);
+ }
+
+ void pushConstants(VkPipelineLayout layout,
+ VkShaderStageFlags stageFlags,
+ uint32_t offset,
+ uint32_t size,
+ const void* pValues) const noexcept
+ {
+ _api.vkCmdPushConstants(
+ _commandBuffer, layout, stageFlags, offset, size, pValues);
+ }
+
+ void executeCommands(uint32_t commandBufferCount,
+ const VkCommandBuffer* pCommandBuffers) const noexcept
+ {
+ _api.vkCmdExecuteCommands(_commandBuffer,
+ commandBufferCount,
+ pCommandBuffers);
+ }
+
+protected:
+ const VulkanApi& _api;
+ VkCommandBuffer _commandBuffer;
+ VkResult _result;
+};
+
+// Top level command scope outside a render pass
+class CommandScope : public CommonCommandScope
+{
+public:
+ CommandScope(const VulkanApi& api,
+ VkCommandBuffer commandBuffer,
+ VkResult result) noexcept
+ : CommonCommandScope{api, commandBuffer, result}
+ {}
+
+ CommandScope(const CommandScope&) = delete;
+ CommandScope& operator=(const CommandScope&) = delete;
+
+ CommandScope(CommandScope&& scope) noexcept
+ : CommonCommandScope{std::forward<CommandScope>(scope)}
+ {}
+
+ CommandScope& operator=(CommandScope&&) = delete;
+
+ ~CommandScope() noexcept
+ {
+ assert(!_commandBuffer); // Buffer must be finished with end()
+ }
+
+ VkResult end() noexcept
+ {
+ if (_commandBuffer) {
+ VkResult r = _api.vkEndCommandBuffer(_commandBuffer);
+ _commandBuffer = {};
+ return r;
+ }
+
+ return VK_NOT_READY;
+ }
+
+ void dispatch(uint32_t groupCountX,
+ uint32_t groupCountY,
+ uint32_t groupCountZ) const noexcept
+ {
+ _api.vkCmdDispatch(_commandBuffer,
+ groupCountX,
+ groupCountY,
+ groupCountZ);
+ }
+
+ void dispatchIndirect(VkBuffer buffer, VkDeviceSize offset) const noexcept
+ {
+ _api.vkCmdDispatchIndirect(_commandBuffer, buffer, offset);
+ }
+
+ void copyBuffer(VkBuffer srcBuffer,
+ VkBuffer dstBuffer,
+ uint32_t regionCount,
+ const VkBufferCopy* pRegions) const noexcept
+ {
+ _api.vkCmdCopyBuffer(
+ _commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
+ }
+
+ void copyImage(VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkImageCopy* pRegions) const noexcept
+ {
+ _api.vkCmdCopyImage(_commandBuffer,
+ srcImage,
+ srcImageLayout,
+ dstImage,
+ dstImageLayout,
+ regionCount,
+ pRegions);
+ }
+
+ void blitImage(VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkImageBlit* pRegions,
+ VkFilter filter) const noexcept
+ {
+ _api.vkCmdBlitImage(_commandBuffer,
+ srcImage,
+ srcImageLayout,
+ dstImage,
+ dstImageLayout,
+ regionCount,
+ pRegions,
+ filter);
+ }
+
+ void copyBufferToImage(VkBuffer srcBuffer,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkBufferImageCopy* pRegions) const noexcept
+ {
+ _api.vkCmdCopyBufferToImage(_commandBuffer,
+ srcBuffer,
+ dstImage,
+ dstImageLayout,
+ regionCount,
+ pRegions);
+ }
+
+ void copyImageToBuffer(VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkBuffer dstBuffer,
+ uint32_t regionCount,
+ const VkBufferImageCopy* pRegions) const noexcept
+ {
+ _api.vkCmdCopyImageToBuffer(_commandBuffer,
+ srcImage,
+ srcImageLayout,
+ dstBuffer,
+ regionCount,
+ pRegions);
+ }
+
+ void updateBuffer(VkBuffer dstBuffer,
+ VkDeviceSize dstOffset,
+ VkDeviceSize dataSize,
+ const void* pData) const noexcept
+ {
+ _api.vkCmdUpdateBuffer(
+ _commandBuffer, dstBuffer, dstOffset, dataSize, pData);
+ }
+
+ void fillBuffer(VkBuffer dstBuffer,
+ VkDeviceSize dstOffset,
+ VkDeviceSize size,
+ uint32_t data) const noexcept
+ {
+ _api.vkCmdFillBuffer(_commandBuffer, dstBuffer, dstOffset, size, data);
+ }
+
+ void clearColorImage(VkImage image,
+ VkImageLayout imageLayout,
+ const VkClearColorValue& color,
+ uint32_t rangeCount,
+ const VkImageSubresourceRange* pRanges) const noexcept
+ {
+ _api.vkCmdClearColorImage(
+ _commandBuffer, image, imageLayout, &color, rangeCount, pRanges);
+ }
+
+ void clearDepthStencilImage(
+ VkImage image,
+ VkImageLayout imageLayout,
+ const VkClearDepthStencilValue& depthStencil,
+ uint32_t rangeCount,
+ const VkImageSubresourceRange* pRanges) const noexcept
+ {
+ _api.vkCmdClearDepthStencilImage(_commandBuffer,
+ image,
+ imageLayout,
+ &depthStencil,
+ rangeCount,
+ pRanges);
+ }
+
+ void resolveImage(VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkImageResolve* pRegions) const noexcept
+ {
+ _api.vkCmdResolveImage(_commandBuffer,
+ srcImage,
+ srcImageLayout,
+ dstImage,
+ dstImageLayout,
+ regionCount,
+ pRegions);
+ }
+
+ void setEvent(VkEvent event, VkPipelineStageFlags stageMask) const noexcept
+ {
+ _api.vkCmdSetEvent(_commandBuffer, event, stageMask);
+ }
+
+ void
+ resetEvent(VkEvent event, VkPipelineStageFlags stageMask) const noexcept
+ {
+ _api.vkCmdResetEvent(_commandBuffer, event, stageMask);
+ }
+
+ void resetQueryPool(VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount) const noexcept
+ {
+ _api.vkCmdResetQueryPool(_commandBuffer,
+ queryPool,
+ firstQuery,
+ queryCount);
+ }
+
+ void copyQueryPoolResults(VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount,
+ VkBuffer dstBuffer,
+ VkDeviceSize dstOffset,
+ VkDeviceSize stride,
+ VkQueryResultFlags flags) const noexcept
+ {
+ _api.vkCmdCopyQueryPoolResults(_commandBuffer,
+ queryPool,
+ firstQuery,
+ queryCount,
+ dstBuffer,
+ dstOffset,
+ stride,
+ flags);
+ }
+
+ SYBOK_NODISCARD
+ RenderCommandScope
+ beginRenderPass(const VkRenderPassBeginInfo& renderPassBegin,
+ VkSubpassContents contents) const noexcept;
+};
+
+class RenderCommandScope : public CommonCommandScope
+{
+public:
+ RenderCommandScope(const VulkanApi& api,
+ VkCommandBuffer commandBuffer) noexcept
+ : CommonCommandScope{api, commandBuffer, VK_SUCCESS}
+ {}
+
+ RenderCommandScope(const RenderCommandScope&) = delete;
+ RenderCommandScope& operator=(const RenderCommandScope&) = delete;
+
+ RenderCommandScope(RenderCommandScope&& scope) noexcept
+ : CommonCommandScope{std::forward<RenderCommandScope>(scope)}
+ {}
+
+ RenderCommandScope& operator=(RenderCommandScope&&) = delete;
+
+ ~RenderCommandScope() noexcept { _api.vkCmdEndRenderPass(_commandBuffer); }
+
+ void draw(uint32_t vertexCount,
+ uint32_t instanceCount,
+ uint32_t firstVertex,
+ uint32_t firstInstance) const noexcept
+ {
+ _api.vkCmdDraw(_commandBuffer,
+ vertexCount,
+ instanceCount,
+ firstVertex,
+ firstInstance);
+ }
+
+ void drawIndexed(uint32_t indexCount,
+ uint32_t instanceCount,
+ uint32_t firstIndex,
+ int32_t vertexOffset,
+ uint32_t firstInstance) const noexcept
+ {
+ _api.vkCmdDrawIndexed(_commandBuffer,
+ indexCount,
+ instanceCount,
+ firstIndex,
+ vertexOffset,
+ firstInstance);
+ }
+
+ void drawIndirect(VkBuffer buffer,
+ VkDeviceSize offset,
+ uint32_t drawCount,
+ uint32_t stride) const noexcept
+ {
+ _api.vkCmdDrawIndirect(
+ _commandBuffer, buffer, offset, drawCount, stride);
+ }
+
+ void drawIndexedIndirect(VkBuffer buffer,
+ VkDeviceSize offset,
+ uint32_t drawCount,
+ uint32_t stride) const noexcept
+ {
+ _api.vkCmdDrawIndexedIndirect(
+ _commandBuffer, buffer, offset, drawCount, stride);
+ }
+
+ void clearAttachments(uint32_t attachmentCount,
+ const VkClearAttachment& attachments,
+ uint32_t rectCount,
+ const VkClearRect* pRects) const noexcept
+ {
+ _api.vkCmdClearAttachments(
+ _commandBuffer, attachmentCount, &attachments, rectCount, pRects);
+ }
+
+ void nextSubpass(VkSubpassContents contents) const noexcept
+ {
+ _api.vkCmdNextSubpass(_commandBuffer, contents);
+ }
+};
+
+CommandScope
+VulkanApi::beginCommandBuffer(
+ VkCommandBuffer commandBuffer,
+ const VkCommandBufferBeginInfo beginInfo) const noexcept
+{
+ if (const VkResult r = vkBeginCommandBuffer(commandBuffer, &beginInfo)) {
+ return {*this, nullptr, r};
+ }
+
+ return {*this, commandBuffer, VK_SUCCESS};
+}
+
+inline RenderCommandScope
+CommandScope::beginRenderPass(const VkRenderPassBeginInfo& renderPassBegin,
+ VkSubpassContents contents) const noexcept
+{
+ _api.vkCmdBeginRenderPass(_commandBuffer, &renderPassBegin, contents);
+
+ return {_api, _commandBuffer};
+}
+
+inline MappedMemory::~MappedMemory() noexcept
+{
+ if (_api && _memory) {
+ _api->vkUnmapMemory(_device, _memory);
+ }
+}
+
+} // namespace sk
+
+#endif // SYBOK_HPP
diff --git a/subprojects/d2tk/pugl/include/.clang-tidy b/subprojects/d2tk/pugl/include/.clang-tidy
new file mode 100644
index 0000000..dd2fd47
--- /dev/null
+++ b/subprojects/d2tk/pugl/include/.clang-tidy
@@ -0,0 +1,9 @@
+Checks: >
+ *,
+ -*-magic-numbers,
+ -*-uppercase-literal-suffix,
+ -clang-diagnostic-unused-function,
+ -clang-diagnostic-unused-macros,
+ -llvmlibc-*,
+FormatStyle: file
+HeaderFilterRegex: 'pugl/.*'
diff --git a/subprojects/d2tk/pugl/pugl/pugl_cairo.h b/subprojects/d2tk/pugl/include/pugl/cairo.h
index c68f6bb..d72580d 100644
--- a/subprojects/d2tk/pugl/pugl/pugl_cairo.h
+++ b/subprojects/d2tk/pugl/include/pugl/cairo.h
@@ -14,13 +14,8 @@
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
+#ifndef PUGL_CAIRO_H
+#define PUGL_CAIRO_H
#include "pugl/pugl.h"
@@ -29,16 +24,16 @@ PUGL_BEGIN_DECLS
/**
@defgroup cairo Cairo
Cairo graphics support.
- @ingroup pugl_c
+ @ingroup pugl
@{
*/
/**
Cairo graphics backend accessor.
- Pass the return value to puglInitBackend() to draw to a view with Cairo.
+ Pass the returned value to puglSetBackend() to draw to a view with Cairo.
*/
-PUGL_API const PuglBackend*
+PUGL_API PUGL_CONST_FUNC const PuglBackend*
puglCairoBackend(void);
/**
@@ -47,4 +42,4 @@ puglCairoBackend(void);
PUGL_END_DECLS
-#endif // PUGL_PUGL_CAIRO_H
+#endif // PUGL_CAIRO_H
diff --git a/subprojects/d2tk/pugl/pugl/pugl_gl.h b/subprojects/d2tk/pugl/include/pugl/gl.h
index d501b3c..eb86c3d 100644
--- a/subprojects/d2tk/pugl/pugl/pugl_gl.h
+++ b/subprojects/d2tk/pugl/include/pugl/gl.h
@@ -14,22 +14,46 @@
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
+#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 <windows.h>
+# endif
+# include "GL/gl.h"
+# endif
+#endif
+
+#ifndef PUGL_NO_INCLUDE_GLU_H
+# ifdef __APPLE__
+# include "OpenGL/glu.h"
+# else
+# ifdef _WIN32
+# include <windows.h>
+# endif
+# include "GL/glu.h"
+# endif
+#endif
+
+// IWYU pragma: end_exports
+
PUGL_BEGIN_DECLS
/**
@defgroup gl OpenGL
OpenGL graphics support.
- @ingroup pugl_c
+ @ingroup pugl
@{
*/
@@ -45,11 +69,29 @@ PUGL_API PuglGlFunc
puglGetProcAddress(const char* name);
/**
+ Enter the OpenGL context.
+
+ This can be used to enter the graphics context in unusual situations, for
+ doing things like loading textures. Note that this must not be used for
+ drawing, which may only be done while processing an expose event.
+*/
+PUGL_API PuglStatus
+puglEnterContext(PuglView* view);
+
+/**
+ Leave the OpenGL context.
+
+ This must only be called after puglEnterContext().
+*/
+PUGL_API PuglStatus
+puglLeaveContext(PuglView* view);
+
+/**
OpenGL graphics backend.
- Pass the return value to puglSetBackend() to draw to a view with OpenGL.
+ Pass the returned value to puglSetBackend() to draw to a view with OpenGL.
*/
-PUGL_API const PuglBackend*
+PUGL_API PUGL_CONST_FUNC const PuglBackend*
puglGlBackend(void);
PUGL_END_DECLS
@@ -58,4 +100,4 @@ PUGL_END_DECLS
@}
*/
-#endif // PUGL_PUGL_GL_H
+#endif // PUGL_GL_H
diff --git a/subprojects/d2tk/pugl/pugl/pugl.h b/subprojects/d2tk/pugl/include/pugl/pugl.h
index c32a17d..9ddc1ec 100644
--- a/subprojects/d2tk/pugl/pugl/pugl.h
+++ b/subprojects/d2tk/pugl/include/pugl/pugl.h
@@ -14,11 +14,6 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file pugl.h
- @brief Pugl API.
-*/
-
#ifndef PUGL_PUGL_H
#define PUGL_PUGL_H
@@ -70,12 +65,8 @@
PUGL_BEGIN_DECLS
/**
- @defgroup pugl Pugl
- A minimal portable API for embeddable GUIs.
- @{
-
- @defgroup pugl_c C API
- Public C API.
+ @defgroup pugl Pugl C API
+ Pugl C API.
@{
*/
@@ -95,29 +86,23 @@ typedef struct {
/**
@defgroup events Events
- Event definitions.
-
All updates to the view happen via events, which are dispatched to the
- view's event function by Pugl. Most events map directly to one from the
- underlying window system, but some are constructed by Pugl itself so there
- is not necessarily a direct correspondence.
+ view's event function. Most events map directly to one from the underlying
+ window system, but some are constructed by Pugl itself so there is not
+ necessarily a direct correspondence.
@{
*/
-/**
- Keyboard modifier flags.
-*/
+/// Keyboard modifier flags
typedef enum {
- PUGL_MOD_SHIFT = 1, ///< Shift key
- PUGL_MOD_CTRL = 1 << 1, ///< Control key
- PUGL_MOD_ALT = 1 << 2, ///< Alt/Option key
- PUGL_MOD_SUPER = 1 << 3 ///< Mod4/Command/Windows key
+ PUGL_MOD_SHIFT = 1u << 0u, ///< Shift key
+ PUGL_MOD_CTRL = 1u << 1u, ///< Control key
+ PUGL_MOD_ALT = 1u << 2u, ///< Alt/Option key
+ PUGL_MOD_SUPER = 1u << 3u ///< Mod4/Command/Windows key
} PuglMod;
-/**
- Bitwise OR of #PuglMod values.
-*/
+/// Bitwise OR of #PuglMod values
typedef uint32_t PuglMods;
/**
@@ -182,9 +167,7 @@ typedef enum {
PUGL_KEY_PAUSE
} PuglKey;
-/**
- The type of a PuglEvent.
-*/
+/// The type of a PuglEvent
typedef enum {
PUGL_NOTHING, ///< No event
PUGL_CREATE, ///< View created, a #PuglEventCreate
@@ -208,6 +191,8 @@ typedef enum {
PUGL_SCROLL, ///< Scrolled, a #PuglEventScroll
PUGL_CLIENT, ///< Custom client message, a #PuglEventClient
PUGL_TIMER, ///< Timer triggered, a #PuglEventTimer
+ PUGL_LOOP_ENTER, ///< Recursive loop entered, a #PuglEventLoopEnter
+ PUGL_LOOP_LEAVE, ///< Recursive loop left, a #PuglEventLoopLeave
#ifndef PUGL_DISABLE_DEPRECATED
PUGL_ENTER_NOTIFY PUGL_DEPRECATED_BY("PUGL_POINTER_IN") = PUGL_POINTER_IN,
@@ -217,22 +202,16 @@ typedef enum {
} PuglEventType;
-/**
- Common flags for all event types.
-*/
+/// Common flags for all event types
typedef enum {
PUGL_IS_SEND_EVENT = 1, ///< Event is synthetic
PUGL_IS_HINT = 2 ///< Event is a hint (not direct user input)
} PuglEventFlag;
-/**
- Bitwise OR of #PuglEventFlag values.
-*/
+/// Bitwise OR of #PuglEventFlag values
typedef uint32_t PuglEventFlags;
-/**
- Reason for a PuglEventCrossing.
-*/
+/// Reason for a PuglEventCrossing
typedef enum {
PUGL_CROSSING_NORMAL, ///< Crossing due to pointer motion
PUGL_CROSSING_GRAB, ///< Crossing due to a grab
@@ -255,9 +234,7 @@ typedef enum {
PUGL_SCROLL_SMOOTH ///< Smooth scroll in any direction
} PuglScrollDirection;
-/**
- Common header for all event structs.
-*/
+/// Common header for all event structs
typedef struct {
PuglEventType type; ///< Event type
PuglEventFlags flags; ///< Bitwise OR of #PuglEventFlag values
@@ -531,6 +508,38 @@ typedef struct {
} PuglEventTimer;
/**
+ Recursive loop enter event.
+
+ This event is sent when the window system enters a recursive loop. The main
+ loop will be stalled and no expose events will be received while in the
+ recursive loop. To give the application full control, Pugl does not do any
+ special handling of this situation, but this event can be used to install a
+ timer to perform continuous actions (such as drawing) on platforms that do
+ this.
+
+ - MacOS: A recursive loop is entered while the window is being live resized.
+
+ - Windows: A recursive loop is entered while the window is being live
+ resized or the menu is shown.
+
+ - X11: A recursive loop is never entered and the event loop runs as usual
+ while the view is being resized.
+
+ This event type has no extra fields.
+*/
+typedef PuglEventAny PuglEventLoopEnter;
+
+/**
+ Recursive loop leave event.
+
+ This event is sent after a loop enter event when the recursive loop is
+ finished and normal iteration will continue.
+
+ This event type has no extra fields.
+*/
+typedef PuglEventAny PuglEventLoopLeave;
+
+/**
View event.
This is a union of all event types. The type must be checked to determine
@@ -561,14 +570,12 @@ typedef union {
@}
@defgroup status Status
- Status codes and error handling.
+ Most functions return a status code which can be used to check for errors.
@{
*/
-/**
- Return status code.
-*/
+/// Return status code
typedef enum {
PUGL_SUCCESS, ///< Success
PUGL_FAILURE, ///< Non-fatal failure
@@ -576,7 +583,7 @@ typedef enum {
PUGL_BAD_BACKEND, ///< Invalid or missing backend
PUGL_BAD_CONFIGURATION, ///< Invalid view configuration
PUGL_BAD_PARAMETER, ///< Invalid parameter
- PUGL_BACKEND_FAILED, ///< Backend initialisation failed
+ PUGL_BACKEND_FAILED, ///< Backend initialization failed
PUGL_REGISTRATION_FAILED, ///< Class registration failed
PUGL_REALIZE_FAILED, ///< System view realization failed
PUGL_SET_FORMAT_FAILED, ///< Failed to set pixel format
@@ -584,10 +591,8 @@ typedef enum {
PUGL_UNSUPPORTED_TYPE, ///< Unsupported data type
} PuglStatus;
-/**
- Return a string describing a status code.
-*/
-PUGL_API
+/// Return a string describing a status code
+PUGL_API PUGL_CONST_FUNC
const char*
puglStrerror(PuglStatus status);
@@ -615,58 +620,29 @@ puglStrerror(PuglStatus status);
*/
typedef struct PuglWorldImpl PuglWorld;
-/**
- Handle for the world's opaque user data.
-*/
+/// Handle for the world's opaque user data
typedef void* PuglWorldHandle;
-/**
- The type of a World.
-*/
+/// The type of a World
typedef enum {
PUGL_PROGRAM, ///< Top-level application
PUGL_MODULE ///< Plugin or module within a larger application
} PuglWorldType;
-/**
- World flags.
-*/
+/// World flags
typedef enum {
/**
Set up support for threads if necessary.
- X11: Calls XInitThreads() which is required for some drivers.
*/
- PUGL_WORLD_THREADS = 1 << 0
+ PUGL_WORLD_THREADS = 1u << 0u
} PuglWorldFlag;
-/**
- Bitwise OR of #PuglWorldFlag values.
-*/
+/// Bitwise OR of #PuglWorldFlag values
typedef uint32_t PuglWorldFlags;
/**
- A log message level, compatible with syslog.
-*/
-typedef enum {
- PUGL_LOG_LEVEL_ERR = 3, ///< Error
- PUGL_LOG_LEVEL_WARNING = 4, ///< Warning
- PUGL_LOG_LEVEL_INFO = 6, ///< Informational message
- PUGL_LOG_LEVEL_DEBUG = 7 ///< Debug message
-} PuglLogLevel;
-
-/**
- A function called to report log messages.
-
- @param world The world that produced this log message.
- @param level Log level.
- @param msg Message string.
-*/
-typedef void (*PuglLogFunc)(PuglWorld* world,
- PuglLogLevel level,
- const char* msg);
-
-/**
Create a new world.
@param type The type, which dictates what this world is responsible for.
@@ -676,9 +652,7 @@ typedef void (*PuglLogFunc)(PuglWorld* world,
PUGL_API PuglWorld*
puglNewWorld(PuglWorldType type, PuglWorldFlags flags);
-/**
- Free a world allocated with puglNewWorld().
-*/
+/// Free a world allocated with puglNewWorld()
PUGL_API void
puglFreeWorld(PuglWorld* world);
@@ -693,39 +667,21 @@ puglFreeWorld(PuglWorld* world);
PUGL_API void
puglSetWorldHandle(PuglWorld* world, PuglWorldHandle handle);
-/**
- Get the user data for the world.
-*/
+/// Get the user data for the world
PUGL_API PuglWorldHandle
puglGetWorldHandle(PuglWorld* world);
/**
Return a pointer to the native handle of the world.
- @return
- - X11: A pointer to the `Display`.
- - MacOS: `NULL`.
- - Windows: The `HMODULE` of the calling process.
-*/
-PUGL_API void*
-puglGetNativeWorld(PuglWorld* world);
+ X11: Returns a pointer to the `Display`.
-/**
- Set the function to call to log a message.
+ MacOS: Returns null.
- This will be called to report any log messages generated internally by Pugl
- which are enabled according to the log level.
+ Windows: Returns the `HMODULE` of the calling process.
*/
-PUGL_API PuglStatus
-puglSetLogFunc(PuglWorld* world, PuglLogFunc logFunc);
-
-/**
- Set the level of log messages to emit.
-
- Any log messages with a level less than or equal to `level` will be emitted.
-*/
-PUGL_API PuglStatus
-puglSetLogLevel(PuglWorld* world, PuglLogLevel level);
+PUGL_API void*
+puglGetNativeWorld(PuglWorld* world);
/**
Set the class name of the application.
@@ -765,7 +721,7 @@ puglGetTime(const PuglWorld* world);
until an event occurs.
For continuously animating programs, a timeout that is a reasonable fraction
- of the ideal frame period should be used, to minimise input latency by
+ of the ideal frame period should be used, to minimize input latency by
ensuring that as many input events are consumed as possible before drawing.
@return #PUGL_SUCCESS if events are read, #PUGL_FAILURE if not, or an error.
@@ -775,7 +731,6 @@ puglUpdate(PuglWorld* world, double timeout);
/**
@}
-
@defgroup view View
A drawable region that receives events.
@@ -788,9 +743,7 @@ puglUpdate(PuglWorld* world, double timeout);
@{
*/
-/**
- A drawable region that receives events.
-*/
+/// A drawable region that receives events
typedef struct PuglViewImpl PuglView;
/**
@@ -817,14 +770,10 @@ typedef struct PuglBackendImpl PuglBackend;
*/
typedef uintptr_t PuglNativeView;
-/**
- Handle for a view's opaque user data.
-*/
+/// Handle for a view's opaque user data
typedef void* PuglHandle;
-/**
- A hint for configuring a view.
-*/
+/// A hint for configuring a view
typedef enum {
PUGL_USE_COMPAT_PROFILE, ///< Use compatible (not core) OpenGL profile
PUGL_USE_DEBUG_CONTEXT, ///< True to use a debug OpenGL context
@@ -841,26 +790,23 @@ typedef enum {
PUGL_SWAP_INTERVAL, ///< Number of frames between buffer swaps
PUGL_RESIZABLE, ///< True if view should be resizable
PUGL_IGNORE_KEY_REPEAT, ///< True if key repeat events are ignored
+ PUGL_REFRESH_RATE, ///< Refresh rate in Hz
PUGL_NUM_VIEW_HINTS
} PuglViewHint;
-/**
- A special view hint value.
-*/
+/// A special view hint value
typedef enum {
PUGL_DONT_CARE = -1, ///< Use best available value
PUGL_FALSE = 0, ///< Explicitly false
PUGL_TRUE = 1 ///< Explicitly true
} PuglViewHintValue;
-/**
- A function called when an event occurs.
-*/
+/// A function called when an event occurs
typedef PuglStatus (*PuglEventFunc)(PuglView* view, const PuglEvent* event);
/**
- @name Setup
+ @defgroup setup Setup
Functions for creating and destroying a view.
@{
*/
@@ -875,15 +821,11 @@ typedef PuglStatus (*PuglEventFunc)(PuglView* view, const PuglEvent* event);
PUGL_API PuglView*
puglNewView(PuglWorld* world);
-/**
- Free a view created with puglNewView().
-*/
+/// Free a view created with puglNewView()
PUGL_API void
puglFreeView(PuglView* view);
-/**
- Return the world that `view` is a part of.
-*/
+/// Return the world that `view` is a part of
PUGL_API PuglWorld*
puglGetWorld(PuglView* view);
@@ -899,9 +841,7 @@ puglGetWorld(PuglView* view);
PUGL_API void
puglSetHandle(PuglView* view, PuglHandle handle);
-/**
- Get the user data for a view.
-*/
+/// Get the user data for a view
PUGL_API PuglHandle
puglGetHandle(PuglView* view);
@@ -913,8 +853,9 @@ puglGetHandle(PuglView* view);
Pugl includes the following backends:
- - puglGlBackend(), declared in pugl_gl.h
- - puglCairoBackend(), declared in pugl_cairo.h
+ - puglCairoBackend()
+ - puglGlBackend()
+ - puglVulkanBackend()
Note that backends are modular and not compiled into the main Pugl library
to avoid unnecessary dependencies. To use a particular backend,
@@ -924,9 +865,7 @@ puglGetHandle(PuglView* view);
PUGL_API PuglStatus
puglSetBackend(PuglView* view, const PuglBackend* backend);
-/**
- Set the function to call when an event occurs.
-*/
+/// Set the function to call when an event occurs
PUGL_API PuglStatus
puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc);
@@ -939,9 +878,18 @@ PUGL_API PuglStatus
puglSetViewHint(PuglView* view, PuglViewHint hint, int value);
/**
+ Get the value for a view hint.
+
+ If the view has been realized, this can be used to get the actual value of a
+ hint which was initially set to PUGL_DONT_CARE, or has been adjusted from
+ the suggested value.
+*/
+PUGL_API int
+puglGetViewHint(const PuglView* view, PuglViewHint hint);
+
+/**
@}
- @anchor frame
- @name Frame
+ @defgroup frame Frame
Functions for working with the position and size of a view.
@{
*/
@@ -958,6 +906,9 @@ puglGetFrame(const PuglView* view);
Set the current position and size of the view.
The position is in screen coordinates with an upper left origin.
+
+ @return #PUGL_UNKNOWN_ERROR on failure, in which case the view frame is
+ unchanged.
*/
PUGL_API PuglStatus
puglSetFrame(PuglView* view, PuglRect frame);
@@ -968,6 +919,9 @@ puglSetFrame(PuglView* view, PuglRect frame);
This should be called before puglResize() to set the default size of the
view, which will be the initial size of the window if this is a top level
view.
+
+ @return #PUGL_UNKNOWN_ERROR on failure, but always succeeds if the view is
+ not yet realized.
*/
PUGL_API PuglStatus
puglSetDefaultSize(PuglView* view, int width, int height);
@@ -977,6 +931,9 @@ puglSetDefaultSize(PuglView* view, int width, int height);
If an initial minimum size is known, this should be called before
puglRealize() to avoid stutter, though it can be called afterwards as well.
+
+ @return #PUGL_UNKNOWN_ERROR on failure, but always succeeds if the view is
+ not yet realized.
*/
PUGL_API PuglStatus
puglSetMinSize(PuglView* view, int width, int height);
@@ -986,6 +943,9 @@ puglSetMinSize(PuglView* view, int width, int height);
If an initial maximum size is known, this should be called before
puglRealize() to avoid stutter, though it can be called afterwards as well.
+
+ @return #PUGL_UNKNOWN_ERROR on failure, but always succeeds if the view is
+ not yet realized.
*/
PUGL_API PuglStatus
puglSetMaxSize(PuglView* view, int width, int height);
@@ -1002,14 +962,17 @@ puglSetMaxSize(PuglView* view, int width, int height);
If an initial aspect ratio is known, this should be called before
puglRealize() to avoid stutter, though it can be called afterwards as well.
+
+ @return #PUGL_UNKNOWN_ERROR on failure, but always succeeds if the view is
+ not yet realized.
*/
PUGL_API PuglStatus
puglSetAspectRatio(PuglView* view, int minX, int minY, int maxX, int maxY);
/**
@}
- @name Windows
- Functions for working with system views and the window hierarchy.
+ @defgroup window Window
+ Functions to control the top-level window of a view.
@{
*/
@@ -1045,7 +1008,7 @@ PUGL_API PuglStatus
puglSetTransientFor(PuglView* view, PuglNativeView parent);
/**
- Realise a view by creating a corresponding system view or window.
+ Realize a view by creating a corresponding system view or window.
After this call, the (initially invisible) underlying system view exists and
can be accessed with puglGetNativeWindow(). There is currently no
@@ -1068,29 +1031,23 @@ puglRealize(PuglView* view);
top depending on the platform.
*/
PUGL_API PuglStatus
-puglShowWindow(PuglView* view);
+puglShow(PuglView* view);
-/**
- Hide the current window.
-*/
+/// Hide the current window
PUGL_API PuglStatus
-puglHideWindow(PuglView* view);
+puglHide(PuglView* view);
-/**
- Return true iff the view is currently visible.
-*/
+/// Return true iff the view is currently visible
PUGL_API bool
puglGetVisible(const PuglView* view);
-/**
- Return the native window handle.
-*/
+/// Return the native window handle
PUGL_API PuglNativeView
puglGetNativeWindow(PuglView* view);
/**
@}
- @name Graphics
+ @defgroup graphics Graphics
Functions for working with the graphics context and scheduling redisplays.
@{
*/
@@ -1101,10 +1058,10 @@ puglGetNativeWindow(PuglView* view);
This is a backend-specific context used for drawing if the backend graphics
API requires one. It is only available during an expose.
- @return
- - OpenGL: `NULL`.
- - Cairo: A pointer to a
- [`cairo_t`](http://www.cairographics.org/manual/cairo-cairo-t.html).
+ Cairo: Returns a pointer to a
+ [`cairo_t`](http://www.cairographics.org/manual/cairo-cairo-t.html).
+
+ All other backends: returns null.
*/
PUGL_API void*
puglGetContext(PuglView* view);
@@ -1132,8 +1089,7 @@ puglPostRedisplayRect(PuglView* view, PuglRect rect);
/**
@}
- @anchor interaction
- @name Interaction
+ @defgroup interaction Interaction
Functions for interacting with the user and window system.
@{
*/
@@ -1154,15 +1110,11 @@ typedef enum {
PUGL_CURSOR_UP_DOWN, ///< Up/down arrow for vertical resize
} PuglCursor;
-/**
- Grab the keyboard input focus.
-*/
+/// Grab the keyboard input focus
PUGL_API PuglStatus
puglGrabFocus(PuglView* view);
-/**
- Return whether `view` has the keyboard input focus.
-*/
+/// Return whether `view` has the keyboard input focus
PUGL_API bool
puglHasFocus(const PuglView* view);
@@ -1192,7 +1144,7 @@ puglSetClipboard(PuglView* view,
@param view The view.
@param[out] type Set to the MIME type of the data.
@param[out] len Set to the length of the data in bytes.
- @return The clipboard contents.
+ @return The clipboard contents, or `NULL`.
*/
PUGL_API const void*
puglGetClipboard(PuglView* view, const char** type, size_t* len);
@@ -1203,7 +1155,11 @@ puglGetClipboard(PuglView* view, const char** type, size_t* len);
This changes the system cursor that is displayed when the pointer is inside
the view. May fail if setting the cursor is not supported on this system,
for example if compiled on X11 without Xcursor support.
- */
+
+ Errors:
+ - #PUGL_BAD_PARAMETER if the given cursor is invalid.
+ - #PUGL_FAILURE if the cursor isknown but loading it from the system fails.
+*/
PUGL_API PuglStatus
puglSetCursor(PuglView* view, PuglCursor cursor);
@@ -1227,7 +1183,7 @@ puglRequestAttention(PuglView* view);
If the given timer already exists, it is replaced.
- @param view The view to begin seding #PUGL_TIMER events to.
+ @param view The view to begin sending #PUGL_TIMER events to.
@param id The identifier for this timer. This is an application-specific ID
that should be a low number, typically the value of a constant or `enum`
@@ -1240,8 +1196,9 @@ puglRequestAttention(PuglView* view);
resolution on Windows) and may be rounded up if it is too short. On X11 and
MacOS, a resolution of about 1ms can usually be relied on.
- @return #PUGL_SUCCESS, #PUGL_FAILURE if timers are not supported on this
- system, or an error code.
+ Errors:
+ - #PUGL_FAILURE if timers are not supported by this system or build.
+ - #PUGL_UNKNOWN_ERROR if setting the timer failed.
*/
PUGL_API PuglStatus
puglStartTimer(PuglView* view, uintptr_t id, double timeout);
@@ -1251,7 +1208,10 @@ puglStartTimer(PuglView* view, uintptr_t id, double timeout);
@param view The view that the timer is set for.
@param id The ID previously passed to puglStartTimer().
- @return #PUGL_SUCCESS, or #PUGL_FAILURE if no such timer was found.
+
+ Errors:
+ - #PUGL_FAILURE if timers are not supported by this system or build.
+ - #PUGL_UNKNOWN_ERROR if stopping the timer failed.
*/
PUGL_API PuglStatus
puglStopTimer(PuglView* view, uintptr_t id);
@@ -1261,8 +1221,17 @@ puglStopTimer(PuglView* view, uintptr_t id);
If supported, the event will be delivered to the view via the event loop
like other events. Note that this function only works for certain event
- types, and will return PUGL_UNSUPPORTED_TYPE for events that are not
- supported.
+ types.
+
+ Currently, only #PUGL_CLIENT events are supported on all platforms.
+
+ X11: A #PUGL_EXPOSE event can be sent, which is similar to calling
+ puglPostRedisplayRect(), but will always send a message to the X server,
+ even when called in an event handler.
+
+ Errors:
+ - #PUGL_UNSUPPORTED_TYPE if sending events of this type is not supported.
+ - #PUGL_UNKNOWN_ERROR if sending the event failed.
*/
PUGL_API PuglStatus
puglSendEvent(PuglView* view, const PuglEvent* event);
@@ -1275,7 +1244,7 @@ puglSendEvent(PuglView* view, const PuglEvent* event);
/**
@}
- @name Deprecated API
+ @defgroup deprecated Deprecated API
@{
*/
@@ -1462,7 +1431,7 @@ puglInitBackend(PuglView* view, const PuglBackend* backend)
}
/**
- Realise a view by creating a corresponding system view or window.
+ Realize a view by creating a corresponding system view or window.
The view should be fully configured using the above functions before this is
called. This function may only be called once per view.
@@ -1532,47 +1501,19 @@ puglPollEvents(PuglWorld* world, double timeout);
PUGL_API PUGL_DEPRECATED_BY("puglUpdate") PuglStatus
puglDispatchEvents(PuglWorld* world);
-/**
- Enter the graphics context.
-
- Note that, unlike some similar libraries, Pugl automatically enters and
- leaves the graphics context when required and application should not
- normally do this. Drawing in Pugl is only allowed during the processing of
- an expose event.
-
- However, this can be used to enter the graphics context elsewhere, for
- example to call any GL functions during setup.
-
- @param view The view being entered.
- @param drawing If true, prepare for drawing.
-
- @deprecated Set up graphics when a #PUGL_CREATE event is received.
-*/
-PUGL_API PUGL_DEPRECATED_BY("PUGL_CREATE") PuglStatus
-puglEnterContext(PuglView* view, bool drawing);
-
-/**
- Leave the graphics context.
-
- This must be called after puglEnterContext() with a matching `drawing`
- parameter.
-
- @param view The view being left.
- @param drawing If true, finish drawing, for example by swapping buffers.
+PUGL_API PUGL_DEPRECATED_BY("puglShow") PuglStatus
+puglShowWindow(PuglView* view);
- @deprecated Shut down graphics when a #PUGL_DESTROY event is received.
-*/
-PUGL_API PUGL_DEPRECATED_BY("PUGL_DESTROY") PuglStatus
-puglLeaveContext(PuglView* view, bool drawing);
+PUGL_API PUGL_DEPRECATED_BY("puglHide") PuglStatus
+puglHideWindow(PuglView* view);
-#endif /* PUGL_DISABLE_DEPRECATED */
+#endif // PUGL_DISABLE_DEPRECATED
/**
@}
@}
- @}
*/
PUGL_END_DECLS
-#endif /* PUGL_PUGL_H */
+#endif // PUGL_PUGL_H
diff --git a/subprojects/d2tk/pugl/pugl/pugl_stub.h b/subprojects/d2tk/pugl/include/pugl/stub.h
index ef48000..d2d1236 100644
--- a/subprojects/d2tk/pugl/pugl/pugl_stub.h
+++ b/subprojects/d2tk/pugl/include/pugl/stub.h
@@ -14,13 +14,8 @@
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
+#ifndef PUGL_STUB_H
+#define PUGL_STUB_H
#include "pugl/pugl.h"
@@ -28,26 +23,18 @@ PUGL_BEGIN_DECLS
/**
@defgroup stub Stub
-
- Stub graphics backend.
-
- The stub backend functions do nothing and always
- return success. These do not make for a usable backend on their own since
- the platform implementation would fail to create a window, but are useful
- for other backends to reuse since not all need non-trivial implementations
- of every backend function.
-
- @ingroup pugl_c
+ Native graphics support.
+ @ingroup pugl
@{
*/
/**
- Stub graphics backend.
+ Stub graphics backend accessor.
This backend just creates a simple native window without setting up any
portable graphics API.
*/
-PUGL_API
+PUGL_API PUGL_CONST_FUNC
const PuglBackend*
puglStubBackend(void);
@@ -57,4 +44,4 @@ puglStubBackend(void);
PUGL_END_DECLS
-#endif // PUGL_PUGL_STUB_H
+#endif // PUGL_STUB_H
diff --git a/subprojects/d2tk/pugl/include/pugl/vulkan.h b/subprojects/d2tk/pugl/include/pugl/vulkan.h
new file mode 100644
index 0000000..bd4ad8e
--- /dev/null
+++ b/subprojects/d2tk/pugl/include/pugl/vulkan.h
@@ -0,0 +1,146 @@
+/*
+ Copyright 2012-2020 David Robillard <http://drobilla.net>
+
+ 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.
+*/
+
+/*
+ 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 <vulkan/vulkan.h>
+
+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
+ @{
+*/
+
+/**
+ 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 vkGetInstanceProcAddr Accessor 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(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
+ 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/subprojects/d2tk/pugl/pugl.pc.in b/subprojects/d2tk/pugl/pugl.pc.in
index 531cd54..2cfa644 100644
--- a/subprojects/d2tk/pugl/pugl.pc.in
+++ b/subprojects/d2tk/pugl/pugl.pc.in
@@ -8,4 +8,4 @@ Description: @DESCRIPTION@
Version: @PUGL_VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @LIBS@
-Cflags: -I${includedir}/pugl-@PUGL_MAJOR_VERSION@
+Cflags: @CFLAGS@
diff --git a/subprojects/d2tk/pugl/pugl/gl.h b/subprojects/d2tk/pugl/pugl/gl.h
deleted file mode 100644
index dbb2e60..0000000
--- a/subprojects/d2tk/pugl/pugl/gl.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- Copyright 2012-2020 David Robillard <d@drobilla.net>
-
- 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 Portable header wrapper for gl.h.
-
- Unfortunately, GL includes vary across platforms so this header allows for
- pure portable programs.
-*/
-
-#ifdef __APPLE__
-# include "OpenGL/gl.h"
-#else
-# ifdef _WIN32
-# include <windows.h> /* Broken Windows GL headers require this */
-# endif
-# include "GL/gl.h"
-#endif
diff --git a/subprojects/d2tk/pugl/pugl/pugl.ipp b/subprojects/d2tk/pugl/pugl/pugl.ipp
deleted file mode 100644
index 7c39a63..0000000
--- a/subprojects/d2tk/pugl/pugl/pugl.ipp
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- Copyright 2012-2020 David Robillard <d@drobilla.net>
-
- 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.ipp
- @brief Pugl C++ API wrapper implementation.
-
- This file must be included exactly once in the application.
-*/
-
-#include "pugl/pugl.hpp"
-
-namespace pugl {
-
-Status
-View::onCreate(const CreateEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onDestroy(const DestroyEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onConfigure(const ConfigureEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onMap(const MapEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onUnmap(const UnmapEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onUpdate(const UpdateEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onExpose(const ExposeEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onClose(const CloseEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onFocusIn(const FocusInEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onFocusOut(const FocusOutEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onKeyPress(const KeyPressEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onKeyRelease(const KeyReleaseEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onText(const TextEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onPointerIn(const PointerInEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onPointerOut(const PointerOutEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onButtonPress(const ButtonPressEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onButtonRelease(const ButtonReleaseEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onMotion(const MotionEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onScroll(const ScrollEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onClient(const ClientEvent&)
-{
- return pugl::Status::success;
-}
-
-Status
-View::onTimer(const TimerEvent&)
-{
- return pugl::Status::success;
-}
-
-}
diff --git a/subprojects/d2tk/pugl/resources/pugl.svg b/subprojects/d2tk/pugl/resources/pugl.svg
index 5bb5335..93189f4 100644
--- a/subprojects/d2tk/pugl/resources/pugl.svg
+++ b/subprojects/d2tk/pugl/resources/pugl.svg
@@ -1,83 +1,9 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- version="1.1"
- id="svg2"
- xml:space="preserve"
- width="544"
- height="544"
- viewBox="0 0 544.00035 544.00035"
- sodipodi:docname="pugl.svg"
- inkscape:version="0.92.4 5da689c313, 2019-01-14"
- inkscape:export-filename="/home/drobilla/src/pugl/resources/pugl.png"
- inkscape:export-xdpi="90.352943"
- inkscape:export-ydpi="90.352943">
- <metadata
- id="metadata8"><rdf:RDF><cc:Work
- rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata>
- <defs
- id="defs6" />
- <sodipodi:namedview
- pagecolor="#ffffff"
- bordercolor="#666666"
- borderopacity="1"
- objecttolerance="10"
- gridtolerance="10"
- guidetolerance="10"
- inkscape:pageopacity="0"
- inkscape:pageshadow="2"
- inkscape:window-width="3816"
- inkscape:window-height="2100"
- id="namedview4"
- showgrid="false"
- inkscape:zoom="2"
- inkscape:cx="399.81254"
- inkscape:cy="304.68124"
- inkscape:window-x="12"
- inkscape:window-y="48"
- inkscape:window-maximized="0"
- inkscape:current-layer="g10"
- fit-margin-top="16"
- fit-margin-left="16"
- fit-margin-right="16"
- fit-margin-bottom="16"
- inkscape:document-units="mm"
- scale-x="1" /><g
- id="g10"
- inkscape:groupmode="layer"
- inkscape:label="ink_ext_XXXXXX"
- transform="matrix(1.3333333,0,0,-1.3333333,57.333339,486.66667)"
- style="filter:url(#filter5238)"><path
- inkscape:connector-curvature="0"
- id="path16"
- style="opacity:1;vector-effect:none;fill:#4b4ba3;fill-opacity:1;stroke:#000000;stroke-width:13.87951851;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;"
- d="M -24.060246,272.03615 H 346.06025 v 74.0241 H -24.060246 Z" /><path
- inkscape:connector-curvature="0"
- id="path18"
- style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#000000;stroke-width:13.87951851;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;"
- d="M -24.060246,-24.060246 H 346.06025 V 346.06025 H -24.060246 Z" /><path
- inkscape:connector-curvature="0"
- id="path20"
- style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#000000;stroke-width:13.87951851;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;"
- d="M 31.457828,31.457828 H 290.54217 V 216.51807 H 31.457828 Z" /><path
- inkscape:connector-curvature="0"
- id="path24"
- style="opacity:1;vector-effect:none;fill:#4b4ba3;fill-opacity:1;stroke:#000000;stroke-width:13.87951851;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;"
- d="M 31.457828,179.50602 H 290.54217 v 37.01205 H 31.457828 Z" /><path
- inkscape:connector-curvature="0"
- id="path14"
- style="opacity:1;vector-effect:none;fill:#546e00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:13.87951851;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;"
- d="M -24.060246,272.03615 H 346.06025 v 74.0241 H -24.060246 Z" /><path
- inkscape:connector-curvature="0"
- id="path22"
- style="opacity:1;vector-effect:none;fill:#546e00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:13.87951851;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;"
- d="M 31.457828,179.50602 H 290.54217 v 37.01205 H 31.457828 Z" /></g></svg>
+<svg xmlns="http://www.w3.org/2000/svg" width="544" height="544">
+ <g stroke="#000" stroke-width="13.88" stroke-linejoin="round">
+ <path d="M25.253 123.952h493.494V25.253H25.253z" fill="#4b4ba3" stroke-width="18.5066204"/>
+ <path d="M25.253 518.747h493.494V25.253H25.253z" fill="none" stroke-width="18.5066204"/>
+ <path d="M99.277 444.723h345.446V197.976H99.277z" fill="none" stroke-width="18.5066204"/>
+ <path d="M99.277 247.325h345.446v-49.35H99.277z" fill="#4b4ba3" stroke-width="18.5066204"/>
+ <path d="M25.253 123.952h493.494V25.253H25.253zM99.277 247.325h345.446v-49.35H99.277z" fill="#546e00" fill-rule="evenodd" stroke-width="18.5066204"/>
+ </g>
+</svg>
diff --git a/subprojects/d2tk/pugl/scripts/dox_to_sphinx.py b/subprojects/d2tk/pugl/scripts/dox_to_sphinx.py
new file mode 100755
index 0000000..b4eee9f
--- /dev/null
+++ b/subprojects/d2tk/pugl/scripts/dox_to_sphinx.py
@@ -0,0 +1,666 @@
+#!/usr/bin/env python3
+
+# Copyright 2020 David Robillard <d@drobilla.net>
+#
+# 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.
+
+"""
+Write Sphinx markup from Doxygen XML.
+
+Takes a path to a directory of XML generated by Doxygen, and emits a directory
+with a reStructuredText file for every documented symbol.
+"""
+
+import argparse
+import os
+import sys
+import textwrap
+import xml.etree.ElementTree
+
+__author__ = "David Robillard"
+__date__ = "2020-11-18"
+__email__ = "d@drobilla.net"
+__license__ = "ISC"
+__version__ = __date__.replace("-", ".")
+
+
+def load_index(index_path):
+ """
+ Load the index from XML.
+
+ :returns: A dictionary from ID to skeleton records with basic information
+ for every documented entity. Some records have an ``xml_filename`` key
+ with the filename of a definition file. These files will be loaded later
+ to flesh out the records in the index.
+ """
+
+ root = xml.etree.ElementTree.parse(index_path).getroot()
+ index = {}
+
+ for compound in root:
+ compound_id = compound.get("refid")
+ compound_kind = compound.get("kind")
+ compound_name = compound.find("name").text
+ if compound_kind in ["dir", "file", "page"]:
+ continue
+
+ # Add record for compound (compounds appear only once in the index)
+ assert compound_id not in index
+ index[compound_id] = {
+ "kind": compound_kind,
+ "name": compound_name,
+ "xml_filename": compound_id + ".xml",
+ "children": [],
+ }
+
+ name_prefix = (
+ ("%s::" % compound_name) if compound_kind == "namespace" else ""
+ )
+
+ for child in compound.findall("member"):
+ if child.get("refid") in index:
+ assert compound_kind == "group"
+ continue
+
+ # Everything has a kind and a name
+ child_record = {
+ "kind": child.get("kind"),
+ "name": name_prefix + child.find("name").text,
+ }
+
+ if child.get("kind") == "enum":
+ # Enums are not compounds, but we want to resolve the parent of
+ # their values so they are not written as top level documents
+ child_record["children"] = []
+
+ if child.get("kind") == "enumvalue":
+ # Remove namespace prefix
+ child_record["name"] = child.find("name").text
+
+ index[child.get("refid")] = child_record
+
+ return index
+
+
+def resolve_index(index, root):
+ """
+ Walk a definition document and extend the index for linking.
+
+ This does two things: sets the "parent" and "children" fields of all
+ applicable records, and sets the "strong" field of enums so that the
+ correct Sphinx role can be used when referring to them.
+ """
+
+ def add_child(index, parent_id, child_id):
+ parent = index[parent_id]
+ child = index[child_id]
+
+ if child["kind"] == "enumvalue":
+ assert parent["kind"] == "enum"
+ assert "parent" not in child or child["parent"] == parent_id
+ child["parent"] = parent_id
+
+ else:
+ if parent["kind"] in ["class", "struct", "union"]:
+ assert "parent" not in child or child["parent"] == parent_id
+ child["parent"] = parent_id
+
+ if child_id not in parent["children"]:
+ parent["children"] += [child_id]
+
+ compound = root.find("compounddef")
+ compound_kind = compound.get("kind")
+
+ if compound_kind == "group":
+ for subgroup in compound.findall("innergroup"):
+ add_child(index, compound.get("id"), subgroup.get("refid"))
+
+ for klass in compound.findall("innerclass"):
+ add_child(index, compound.get("id"), klass.get("refid"))
+
+ for section in compound.findall("sectiondef"):
+ if section.get("kind").startswith("private"):
+ for member in section.findall("memberdef"):
+ if member.get("id") in index:
+ del index[member.get("id")]
+ else:
+ for member in section.findall("memberdef"):
+ member_id = member.get("id")
+ add_child(index, compound.get("id"), member_id)
+
+ if member.get("kind") == "enum":
+ index[member_id]["strong"] = member.get("strong") == "yes"
+ for value in member.findall("enumvalue"):
+ add_child(index, member_id, value.get("id"))
+
+
+def sphinx_role(record, lang):
+ """
+ Return the Sphinx role used for a record.
+
+ This is used for the description directive like ".. c:function::", and
+ links like ":c:func:`foo`.
+ """
+
+ kind = record["kind"]
+
+ if kind in ["class", "function", "namespace", "struct", "union"]:
+ return lang + ":" + kind
+
+ if kind == "define":
+ return "c:macro"
+
+ if kind == "enum":
+ return lang + (":enum-class" if record["strong"] else ":enum")
+
+ if kind == "typedef":
+ return lang + ":type"
+
+ if kind == "enumvalue":
+ return lang + ":enumerator"
+
+ if kind == "variable":
+ return lang + (":member" if "parent" in record else ":var")
+
+ raise RuntimeError("No known role for kind '%s'" % kind)
+
+
+def child_identifier(lang, parent_name, child_name):
+ """
+ Return the identifier for an enum value or struct member.
+
+ Sphinx, for some reason, uses a different syntax for this in C and C++.
+ """
+
+ separator = "::" if lang == "cpp" else "."
+
+ return "%s%s%s" % (parent_name, separator, child_name)
+
+
+def link_markup(index, lang, refid):
+ """Return a Sphinx link for a Doxygen reference."""
+
+ record = index[refid]
+ kind, name = record["kind"], record["name"]
+ role = sphinx_role(record, lang)
+
+ if kind in ["class", "enum", "struct", "typedef", "union"]:
+ return ":%s:`%s`" % (role, name)
+
+ if kind == "function":
+ return ":%s:func:`%s`" % (lang, name)
+
+ if kind == "enumvalue":
+ parent_name = index[record["parent"]]["name"]
+ return ":%s:`%s`" % (role, child_identifier(lang, parent_name, name))
+
+ if kind == "variable":
+ if "parent" not in record:
+ return ":%s:var:`%s`" % (lang, name)
+
+ parent_name = index[record["parent"]]["name"]
+ return ":%s:`%s`" % (role, child_identifier(lang, parent_name, name))
+
+ raise RuntimeError("Unknown link target kind: %s" % kind)
+
+
+def indent(markup, depth):
+ """
+ Indent markup to a depth level.
+
+ Like textwrap.indent() but takes an integer and works in reST indentation
+ levels for clarity."
+ """
+
+ return textwrap.indent(markup, " " * depth)
+
+
+def heading(text, level):
+ """
+ Return a ReST heading at a given level.
+
+ Follows the style in the Python documentation guide, see
+ <https://devguide.python.org/documenting/#sections>.
+ """
+
+ assert 1 <= level <= 6
+
+ chars = ("#", "*", "=", "-", "^", '"')
+ line = chars[level] * len(text)
+
+ return "%s\n%s\n%s\n\n" % (line if level < 3 else "", text, line)
+
+
+def dox_to_rst(index, lang, node):
+ """
+ Convert documentation commands (docCmdGroup) to Sphinx markup.
+
+ This is used to convert the content of descriptions in the documentation.
+ It recursively parses all children tags and raises a RuntimeError if any
+ unknown tag is encountered.
+ """
+
+ def field_value(markup):
+ """Return a value for a field as a single line or indented block."""
+ if "\n" in markup.strip():
+ return "\n" + indent(markup, 1)
+
+ return " " + markup.strip()
+
+ if node.tag == "computeroutput":
+ assert len(node) == 0
+ return "``%s``" % node.text
+
+ if node.tag == "itemizedlist":
+ markup = ""
+ for item in node.findall("listitem"):
+ assert len(item) == 1
+ markup += "\n- %s" % dox_to_rst(index, lang, item[0])
+
+ return markup
+
+ if node.tag == "para":
+ markup = node.text if node.text is not None else ""
+ for child in node:
+ markup += dox_to_rst(index, lang, child)
+ markup += child.tail if child.tail is not None else ""
+
+ return markup.strip() + "\n\n"
+
+ if node.tag == "parameterlist":
+ markup = ""
+ for item in node.findall("parameteritem"):
+ name = item.find("parameternamelist/parametername")
+ description = item.find("parameterdescription")
+ assert len(description) == 1
+ markup += "\n\n:param %s:%s" % (
+ name.text,
+ field_value(dox_to_rst(index, lang, description[0])),
+ )
+
+ return markup + "\n"
+
+ if node.tag == "programlisting":
+ return "\n.. code-block:: %s\n\n%s" % (
+ lang,
+ indent(plain_text(node), 1),
+ )
+
+ if node.tag == "ref":
+ refid = node.get("refid")
+ if refid not in index:
+ sys.stderr.write("warning: Unresolved link: %s\n" % refid)
+ return node.text
+
+ assert len(node) == 0
+ assert len(link_markup(index, lang, refid)) > 0
+ return link_markup(index, lang, refid)
+
+ if node.tag == "simplesect":
+ assert len(node) == 1
+
+ if node.get("kind") == "return":
+ return "\n:returns:" + field_value(
+ dox_to_rst(index, lang, node[0])
+ )
+
+ if node.get("kind") == "see":
+ return dox_to_rst(index, lang, node[0])
+
+ raise RuntimeError("Unknown simplesect kind: %s" % node.get("kind"))
+
+ if node.tag == "ulink":
+ return "`%s <%s>`_" % (node.text, node.get("url"))
+
+ raise RuntimeError("Unknown documentation command: %s" % node.tag)
+
+
+def description_markup(index, lang, node):
+ """Return the markup for a brief or detailed description."""
+
+ assert node.tag == "briefdescription" or node.tag == "detaileddescription"
+ assert not (node.tag == "briefdescription" and len(node) > 1)
+ assert len(node.text.strip()) == 0
+
+ return "".join([dox_to_rst(index, lang, child) for child in node])
+
+
+def set_descriptions(index, lang, definition, record):
+ """Set a record's brief/detailed descriptions from the XML definition."""
+
+ for tag in ["briefdescription", "detaileddescription"]:
+ node = definition.find(tag)
+ if node is not None:
+ record[tag] = description_markup(index, lang, node)
+
+
+def set_template_params(node, record):
+ """Set a record's template_params from the XML definition."""
+
+ template_param_list = node.find("templateparamlist")
+ if template_param_list is not None:
+ params = []
+ for param in template_param_list.findall("param"):
+ if param.find("declname") is not None:
+ # Value parameter
+ type_text = plain_text(param.find("type"))
+ name_text = plain_text(param.find("declname"))
+
+ params += ["%s %s" % (type_text, name_text)]
+ else:
+ # Type parameter
+ params += ["%s" % (plain_text(param.find("type")))]
+
+ record["template_params"] = "%s" % ", ".join(params)
+
+
+def plain_text(node):
+ """
+ Return the plain text of a node with all tags ignored.
+
+ This is needed where Doxygen may include refs but Sphinx needs plain text
+ because it parses things itself to generate links.
+ """
+
+ if node.tag == "sp":
+ markup = " "
+ elif node.text is not None:
+ markup = node.text
+ else:
+ markup = ""
+
+ for child in node:
+ markup += plain_text(child)
+ markup += child.tail if child.tail is not None else ""
+
+ return markup
+
+
+def local_name(name):
+ """Return a name with all namespace prefixes stripped."""
+
+ return name[name.rindex("::") + 2 :] if "::" in name else name
+
+
+def read_definition_doc(index, lang, root):
+ """Walk a definition document and update described records in the index."""
+
+ # Set descriptions for the compound itself
+ compound = root.find("compounddef")
+ compound_record = index[compound.get("id")]
+ set_descriptions(index, lang, compound, compound_record)
+ set_template_params(compound, compound_record)
+
+ if compound.find("title") is not None:
+ compound_record["title"] = compound.find("title").text.strip()
+
+ # Set documentation for all children
+ for section in compound.findall("sectiondef"):
+ if section.get("kind").startswith("private"):
+ continue
+
+ for member in section.findall("memberdef"):
+ kind = member.get("kind")
+ record = index[member.get("id")]
+ set_descriptions(index, lang, member, record)
+ set_template_params(member, record)
+
+ if compound.get("kind") in ["class", "struct", "union"]:
+ assert kind in ["function", "typedef", "variable"]
+ record["type"] = plain_text(member.find("type"))
+
+ if kind == "enum":
+ for value in member.findall("enumvalue"):
+ set_descriptions(
+ index, lang, value, index[value.get("id")]
+ )
+
+ elif kind == "function":
+ record["prototype"] = "%s %s%s" % (
+ plain_text(member.find("type")),
+ member.find("name").text,
+ member.find("argsstring").text,
+ )
+
+ elif kind == "typedef":
+ name = local_name(record["name"])
+ args_text = member.find("argsstring").text
+ target_text = plain_text(member.find("type"))
+ if args_text is not None: # Function pointer
+ assert target_text[-2:] == "(*" and args_text[0] == ")"
+ record["type"] = target_text + args_text
+ record["definition"] = target_text + name + args_text
+ else: # Normal named typedef
+ assert target_text is not None
+ record["type"] = target_text
+ if member.find("definition").text.startswith("using"):
+ record["definition"] = "%s = %s" % (
+ name,
+ target_text,
+ )
+ else:
+ record["definition"] = "%s %s" % (
+ target_text,
+ name,
+ )
+
+
+def declaration_string(record):
+ """
+ Return the string that describes a declaration.
+
+ This is what follows the directive, and is in C/C++ syntax, except without
+ keywords like "typedef" and "using" as expected by Sphinx. For example,
+ "struct ThingImpl Thing" or "void run(int value)".
+ """
+
+ kind = record["kind"]
+ result = ""
+
+ if "template_params" in record:
+ result = "template <%s> " % record["template_params"]
+
+ if kind == "function":
+ result += record["prototype"]
+ elif kind == "typedef":
+ result += record["definition"]
+ elif "type" in record:
+ result += "%s %s" % (record["type"], local_name(record["name"]))
+ else:
+ result += local_name(record["name"])
+
+ return result
+
+
+def document_markup(index, lang, record):
+ """Return the complete document that describes some documented entity."""
+
+ kind = record["kind"]
+ role = sphinx_role(record, lang)
+ name = record["name"]
+ markup = ""
+
+ if name != local_name(name):
+ markup += ".. cpp:namespace:: %s\n\n" % name[0 : name.rindex("::")]
+
+ # Write top-level directive
+ markup += ".. %s:: %s\n" % (role, declaration_string(record))
+
+ # Write main description blurb
+ markup += "\n"
+ markup += indent(record["briefdescription"], 1)
+ markup += indent(record["detaileddescription"], 1)
+
+ assert (
+ kind in ["class", "enum", "namespace", "struct", "union"]
+ or "children" not in record
+ )
+
+ # Sphinx C++ namespaces work by setting a scope, they have no content
+ child_indent = 0 if kind == "namespace" else 1
+
+ # Write inline children if applicable
+ markup += "\n"
+ for child_id in record.get("children", []):
+ child_record = index[child_id]
+ child_role = sphinx_role(child_record, lang)
+
+ child_header = ".. %s:: %s\n\n" % (
+ child_role,
+ declaration_string(child_record),
+ )
+
+ markup += "\n"
+ markup += indent(child_header, child_indent)
+ markup += indent(child_record["briefdescription"], child_indent + 1)
+ markup += indent(child_record["detaileddescription"], child_indent + 1)
+ markup += "\n"
+
+ return markup
+
+
+def symbol_filename(name):
+ """Adapt the name of a symbol to be suitable for use as a filename."""
+
+ return name.replace("::", "__")
+
+
+def emit_symbols(index, lang, symbol_dir, force):
+ """Write a description file for every symbol documented in the index."""
+
+ for record in index.values():
+ if (
+ record["kind"] in ["group", "namespace"]
+ or "parent" in record
+ and index[record["parent"]]["kind"] != "group"
+ ):
+ continue
+
+ name = record["name"]
+ filename = os.path.join(symbol_dir, symbol_filename("%s.rst" % name))
+ if not force and os.path.exists(filename):
+ raise FileExistsError("File already exists: '%s'" % filename)
+
+ with open(filename, "w") as rst:
+ rst.write(heading(local_name(name), 3))
+ rst.write(document_markup(index, lang, record))
+
+
+def emit_groups(index, output_dir, symbol_dir_name, force):
+ """Write a description file for every group documented in the index."""
+
+ for record in index.values():
+ if record["kind"] != "group":
+ continue
+
+ name = record["name"]
+ filename = os.path.join(output_dir, "%s.rst" % name)
+ if not force and os.path.exists(filename):
+ raise FileExistsError("File already exists: '%s'" % filename)
+
+ with open(filename, "w") as rst:
+ rst.write(heading(record["title"], 2))
+
+ # Get all child group and symbol names
+ group_names = []
+ symbol_names = []
+ for child_id in record["children"]:
+ child = index[child_id]
+ if child["kind"] == "group":
+ group_names += [child["name"]]
+ else:
+ symbol_names += [child["name"]]
+
+ # Emit description (document body)
+ rst.write(record["briefdescription"] + "\n\n")
+ rst.write(record["detaileddescription"] + "\n\n")
+
+ # Emit TOC
+ rst.write(".. toctree::\n")
+
+ # Emit groups at the top of the TOC
+ for group_name in group_names:
+ rst.write("\n" + indent(group_name, 1))
+
+ # Emit symbols in sorted order
+ for symbol_name in sorted(symbol_names):
+ path = "/".join(
+ [symbol_dir_name, symbol_filename(symbol_name)]
+ )
+ rst.write("\n" + indent(path, 1))
+
+ rst.write("\n")
+
+
+def run(index_xml_path, output_dir, symbol_dir_name, language, force):
+ """Write a directory of Sphinx files from a Doxygen XML directory."""
+
+ # Build skeleton index from index.xml
+ xml_dir = os.path.dirname(index_xml_path)
+ index = load_index(index_xml_path)
+
+ # Load all definition documents
+ definition_docs = []
+ for record in index.values():
+ if "xml_filename" in record:
+ xml_path = os.path.join(xml_dir, record["xml_filename"])
+ definition_docs += [xml.etree.ElementTree.parse(xml_path)]
+
+ # Do an initial pass of the definition documents to resolve the index
+ for root in definition_docs:
+ resolve_index(index, root)
+
+ # Finally read the documentation from definition documents
+ for root in definition_docs:
+ read_definition_doc(index, language, root)
+
+ # Emit output files
+ symbol_dir = os.path.join(output_dir, symbol_dir_name)
+ os.makedirs(symbol_dir, exist_ok=True)
+ emit_symbols(index, language, symbol_dir, force)
+ emit_groups(index, output_dir, symbol_dir_name, force)
+
+
+if __name__ == "__main__":
+ ap = argparse.ArgumentParser(
+ usage="%(prog)s [OPTION]... XML_DIR OUTPUT_DIR",
+ description=__doc__,
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ )
+
+ ap.add_argument(
+ "-f",
+ "--force",
+ action="store_true",
+ help="overwrite files",
+ )
+
+ ap.add_argument(
+ "-l",
+ "--language",
+ default="c",
+ choices=["c", "cpp"],
+ help="language domain for output",
+ )
+
+ ap.add_argument(
+ "-s",
+ "--symbol-dir-name",
+ default="symbols",
+ help="name for subdirectory of symbol documentation files",
+ )
+
+ ap.add_argument("index_xml_path", help="path index.xml from Doxygen")
+ ap.add_argument("output_dir", help="output directory")
+
+ run(**vars(ap.parse_args(sys.argv[1:])))
diff --git a/subprojects/d2tk/pugl/src/.clang-tidy b/subprojects/d2tk/pugl/src/.clang-tidy
new file mode 100644
index 0000000..808cbb1
--- /dev/null
+++ b/subprojects/d2tk/pugl/src/.clang-tidy
@@ -0,0 +1,19 @@
+Checks: >
+ *,
+ -*-uppercase-literal-suffix,
+ -*magic-numbers,
+ -bugprone-reserved-identifier,
+ -bugprone-suspicious-string-compare,
+ -cert-dcl37-c,
+ -cert-dcl51-cpp,
+ -cert-flp30-c,
+ -clang-analyzer-security.FloatLoopCounter,
+ -clang-diagnostic-unused-macros,
+ -hicpp-multiway-paths-covered,
+ -hicpp-signed-bitwise,
+ -llvm-else-after-return,
+ -llvm-header-guard,
+ -llvmlibc-*,
+ -readability-else-after-return,
+FormatStyle: file
+HeaderFilterRegex: 'pugl/.*'
diff --git a/subprojects/d2tk/pugl/pugl/detail/implementation.c b/subprojects/d2tk/pugl/src/implementation.c
index 6cc4490..e9b7e5a 100644
--- a/subprojects/d2tk/pugl/pugl/detail/implementation.c
+++ b/subprojects/d2tk/pugl/src/implementation.c
@@ -14,44 +14,15 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file implementation.c
- @brief Platform-independent implementation.
-*/
+#include "implementation.h"
-#include "pugl/detail/implementation.h"
#include "pugl/pugl.h"
#include <assert.h>
#include <stdbool.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-static const char*
-puglLogLevelPrefix(const PuglLogLevel level)
-{
- switch (level) {
- case PUGL_LOG_LEVEL_ERR:
- return "error: ";
- case PUGL_LOG_LEVEL_WARNING:
- return "warning: ";
- case PUGL_LOG_LEVEL_INFO:
- case PUGL_LOG_LEVEL_DEBUG:
- return "";
- }
-
- return "";
-}
-
-static void
-puglDefaultLogFunc(PuglWorld* PUGL_UNUSED(world),
- PuglLogLevel level,
- const char* msg)
-{
- fprintf(stderr, "%s%s", puglLogLevelPrefix(level), msg);
-}
-
const char*
puglStrerror(const PuglStatus status)
{
@@ -106,17 +77,18 @@ puglSetDefaultHints(PuglHints hints)
hints[PUGL_USE_COMPAT_PROFILE] = PUGL_TRUE;
hints[PUGL_CONTEXT_VERSION_MAJOR] = 2;
hints[PUGL_CONTEXT_VERSION_MINOR] = 0;
- hints[PUGL_RED_BITS] = 4;
- hints[PUGL_GREEN_BITS] = 4;
- hints[PUGL_BLUE_BITS] = 4;
- hints[PUGL_ALPHA_BITS] = 4;
- hints[PUGL_DEPTH_BITS] = 24;
- hints[PUGL_STENCIL_BITS] = 8;
+ hints[PUGL_RED_BITS] = 8;
+ hints[PUGL_GREEN_BITS] = 8;
+ hints[PUGL_BLUE_BITS] = 8;
+ hints[PUGL_ALPHA_BITS] = 8;
+ hints[PUGL_DEPTH_BITS] = 0;
+ hints[PUGL_STENCIL_BITS] = 0;
hints[PUGL_SAMPLES] = 0;
hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE;
hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE;
hints[PUGL_RESIZABLE] = PUGL_FALSE;
hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE;
+ hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE;
}
PuglWorld*
@@ -129,8 +101,6 @@ puglNewWorld(PuglWorldType type, PuglWorldFlags flags)
}
world->startTime = puglGetTime(world);
- world->logFunc = puglDefaultLogFunc;
- world->logLevel = PUGL_LOG_LEVEL_INFO;
puglSetString(&world->className, "Pugl");
@@ -159,22 +129,6 @@ puglGetWorldHandle(PuglWorld* world)
}
PuglStatus
-puglSetLogFunc(PuglWorld* world, PuglLogFunc logFunc)
-{
- world->logFunc = logFunc;
-
- return PUGL_SUCCESS;
-}
-
-PuglStatus
-puglSetLogLevel(PuglWorld* world, PuglLogLevel level)
-{
- world->logLevel = level;
-
- return PUGL_SUCCESS;
-}
-
-PuglStatus
puglSetClassName(PuglWorld* const world, const char* const name)
{
puglSetString(&world->className, name);
@@ -242,6 +196,19 @@ puglGetWorld(PuglView* view)
PuglStatus
puglSetViewHint(PuglView* view, PuglViewHint hint, int value)
{
+ if (value == PUGL_DONT_CARE) {
+ switch (hint) {
+ case PUGL_USE_COMPAT_PROFILE:
+ case PUGL_USE_DEBUG_CONTEXT:
+ case PUGL_CONTEXT_VERSION_MAJOR:
+ case PUGL_CONTEXT_VERSION_MINOR:
+ case PUGL_SWAP_INTERVAL:
+ return PUGL_BAD_PARAMETER;
+ default:
+ break;
+ }
+ }
+
if (hint < PUGL_NUM_VIEW_HINTS) {
view->hints[hint] = value;
return PUGL_SUCCESS;
@@ -250,6 +217,16 @@ puglSetViewHint(PuglView* view, PuglViewHint hint, int value)
return PUGL_BAD_PARAMETER;
}
+int
+puglGetViewHint(const PuglView* view, PuglViewHint hint)
+{
+ if (hint < PUGL_NUM_VIEW_HINTS) {
+ return view->hints[hint];
+ }
+
+ return PUGL_DONT_CARE;
+}
+
PuglStatus
puglSetParentWindow(PuglView* view, PuglNativeView parent)
{
@@ -309,25 +286,15 @@ puglDispatchEvents(PuglWorld* world)
}
PuglStatus
-puglEnterContext(PuglView* view, bool drawing)
+puglShowWindow(PuglView* view)
{
- const PuglEventExpose expose = {
- PUGL_EXPOSE, 0, 0.0, 0.0, view->frame.width, view->frame.height};
-
- view->backend->enter(view, drawing ? &expose : NULL);
-
- return PUGL_SUCCESS;
+ return puglShow(view);
}
PuglStatus
-puglLeaveContext(PuglView* view, bool drawing)
+puglHideWindow(PuglView* view)
{
- const PuglEventExpose expose = {
- PUGL_EXPOSE, 0, 0.0, 0.0, view->frame.width, view->frame.height};
-
- view->backend->leave(view, drawing ? &expose : NULL);
-
- return PUGL_SUCCESS;
+ return puglHide(view);
}
#endif
@@ -385,7 +352,8 @@ void
puglDispatchSimpleEvent(PuglView* view, const PuglEventType type)
{
assert(type == PUGL_CREATE || type == PUGL_DESTROY || type == PUGL_MAP ||
- type == PUGL_UNMAP || type == PUGL_UPDATE || type == PUGL_CLOSE);
+ type == PUGL_UNMAP || type == PUGL_UPDATE || type == PUGL_CLOSE ||
+ type == PUGL_LOOP_ENTER || type == PUGL_LOOP_LEAVE);
const PuglEvent event = {{type, 0}};
puglDispatchEvent(view, &event);
@@ -404,6 +372,10 @@ puglDispatchEventInContext(PuglView* view, const PuglEvent* event)
view->eventFunc(view, event);
view->lastConfigure = event->configure;
}
+ } else if (event->type == PUGL_EXPOSE) {
+ if (event->expose.width > 0 && event->expose.height > 0) {
+ view->eventFunc(view, event);
+ }
} else {
view->eventFunc(view, event);
}
@@ -430,7 +402,7 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event)
break;
case PUGL_EXPOSE:
view->backend->enter(view, &event->expose);
- view->eventFunc(view, event);
+ puglDispatchEventInContext(view, event);
view->backend->leave(view, &event->expose);
break;
default:
diff --git a/subprojects/d2tk/pugl/pugl/detail/implementation.h b/subprojects/d2tk/pugl/src/implementation.h
index ff97fef..8c5398c 100644
--- a/subprojects/d2tk/pugl/pugl/detail/implementation.h
+++ b/subprojects/d2tk/pugl/src/implementation.h
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file implementation.h
- @brief Shared declarations for implementation.
-*/
+#ifndef PUGL_IMPLEMENTATION_H
+#define PUGL_IMPLEMENTATION_H
-#ifndef PUGL_DETAIL_IMPLEMENTATION_H
-#define PUGL_DETAIL_IMPLEMENTATION_H
+#include "types.h"
-#include "pugl/detail/types.h"
#include "pugl/pugl.h"
#include <stddef.h>
@@ -31,35 +27,44 @@
PUGL_BEGIN_DECLS
/// Set `blob` to `data` with length `len`, reallocating if necessary
-void puglSetBlob(PuglBlob* dest, const void* data, size_t len);
+void
+puglSetBlob(PuglBlob* dest, const void* data, size_t len);
/// Reallocate and set `*dest` to `string`
-void puglSetString(char** dest, const char* string);
+void
+puglSetString(char** dest, const char* string);
/// Allocate and initialise world internals (implemented once per platform)
PuglWorldInternals*
puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags);
/// Destroy and free world internals (implemented once per platform)
-void puglFreeWorldInternals(PuglWorld* world);
+void
+puglFreeWorldInternals(PuglWorld* world);
/// Allocate and initialise view internals (implemented once per platform)
-PuglInternals* puglInitViewInternals(void);
+PuglInternals*
+puglInitViewInternals(void);
/// Destroy and free view internals (implemented once per platform)
-void puglFreeViewInternals(PuglView* view);
+void
+puglFreeViewInternals(PuglView* view);
/// Return the Unicode code point for `buf` or the replacement character
-uint32_t puglDecodeUTF8(const uint8_t* buf);
+uint32_t
+puglDecodeUTF8(const uint8_t* buf);
/// Dispatch an event with a simple `type` to `view`
-void puglDispatchSimpleEvent(PuglView* view, PuglEventType type);
+void
+puglDispatchSimpleEvent(PuglView* view, PuglEventType type);
/// Dispatch `event` to `view` while already in the graphics context
-void puglDispatchEventInContext(PuglView* view, const PuglEvent* event);
+void
+puglDispatchEventInContext(PuglView* view, const PuglEvent* event);
/// Dispatch `event` to `view`, entering graphics context if necessary
-void puglDispatchEvent(PuglView* view, const PuglEvent* event);
+void
+puglDispatchEvent(PuglView* view, const PuglEvent* event);
/// Set internal (stored in view) clipboard contents
const void*
@@ -74,4 +79,4 @@ puglSetInternalClipboard(PuglView* view,
PUGL_END_DECLS
-#endif // PUGL_DETAIL_IMPLEMENTATION_H
+#endif // PUGL_IMPLEMENTATION_H
diff --git a/subprojects/d2tk/pugl/pugl/detail/mac.h b/subprojects/d2tk/pugl/src/mac.h
index 7b64cfe..d17c74f 100644
--- a/subprojects/d2tk/pugl/pugl/detail/mac.h
+++ b/subprojects/d2tk/pugl/src/mac.h
@@ -15,10 +15,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file mac.h
- @brief Shared definitions for MacOS implementation.
-*/
+#ifndef PUGL_DETAIL_MAC_H
+#define PUGL_DETAIL_MAC_H
#include "pugl/pugl.h"
@@ -28,14 +26,14 @@
@interface PuglWrapperView : NSView<NSTextInputClient>
-- (void) dispatchExpose:(NSRect)rect;
-- (void) setReshaped;
+- (void)dispatchExpose:(NSRect)rect;
+- (void)setReshaped;
@end
@interface PuglWindow : NSWindow
-- (void) setPuglview:(PuglView*)view;
+- (void)setPuglview:(PuglView*)view;
@end
@@ -53,3 +51,5 @@ struct PuglInternalsImpl {
uint32_t mods;
bool mouseTracked;
};
+
+#endif // PUGL_DETAIL_MAC_H
diff --git a/subprojects/d2tk/pugl/pugl/detail/mac.m b/subprojects/d2tk/pugl/src/mac.m
index 5f3b89f..90fcfd0 100644
--- a/subprojects/d2tk/pugl/pugl/detail/mac.m
+++ b/subprojects/d2tk/pugl/src/mac.m
@@ -15,15 +15,12 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file mac.m
- @brief MacOS implementation.
-*/
-
#define GL_SILENCE_DEPRECATION 1
-#include "pugl/detail/implementation.h"
-#include "pugl/detail/mac.h"
+#include "mac.h"
+
+#include "implementation.h"
+
#include "pugl/pugl.h"
#import <Cocoa/Cocoa.h>
@@ -124,10 +121,10 @@ updateViewRect(PuglView* view)
PuglView* puglview;
}
-- (id) initWithContentRect:(NSRect)contentRect
- styleMask:(NSWindowStyleMask)aStyle
- backing:(NSBackingStoreType)bufferingType
- defer:(BOOL)flag
+- (id)initWithContentRect:(NSRect)contentRect
+ styleMask:(NSWindowStyleMask)aStyle
+ backing:(NSBackingStoreType)bufferingType
+ defer:(BOOL)flag
{
(void)flag;
@@ -148,17 +145,17 @@ updateViewRect(PuglView* view)
setContentSize:sizePoints(view, view->frame.width, view->frame.height)];
}
-- (BOOL) canBecomeKeyWindow
+- (BOOL)canBecomeKeyWindow
{
return YES;
}
-- (BOOL) canBecomeMainWindow
+- (BOOL)canBecomeMainWindow
{
return YES;
}
-- (void) setIsVisible:(BOOL)flag
+- (void)setIsVisible:(BOOL)flag
{
if (flag && !puglview->visible) {
const PuglEventConfigure ev = {
@@ -189,12 +186,11 @@ updateViewRect(PuglView* view)
PuglView* puglview;
NSTrackingArea* trackingArea;
NSMutableAttributedString* markedText;
- NSTimer* timer;
NSMutableDictionary* userTimers;
bool reshaped;
}
-- (void) dispatchExpose:(NSRect)rect
+- (void)dispatchExpose:(NSRect)rect
{
const double scaleFactor = [[NSScreen mainScreen] backingScaleFactor];
@@ -230,7 +226,7 @@ updateViewRect(PuglView* view)
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
-- (NSSize) intrinsicContentSize
+- (NSSize)intrinsicContentSize
{
if (puglview->defaultWidth || puglview->defaultHeight) {
return sizePoints(puglview,
@@ -241,17 +237,17 @@ updateViewRect(PuglView* view)
return NSMakeSize(NSViewNoInstrinsicMetric, NSViewNoInstrinsicMetric);
}
-- (BOOL) isFlipped
+- (BOOL)isFlipped
{
return YES;
}
-- (BOOL) acceptsFirstResponder
+- (BOOL)acceptsFirstResponder
{
return YES;
}
-- (void) setReshaped
+- (void)setReshaped
{
reshaped = true;
}
@@ -307,7 +303,7 @@ keySymToSpecial(const NSEvent* const ev)
return (PuglKey)0;
}
-- (void) updateTrackingAreas
+- (void)updateTrackingAreas
{
if (trackingArea != nil) {
[self removeTrackingArea:trackingArea];
@@ -325,7 +321,7 @@ keySymToSpecial(const NSEvent* const ev)
[super updateTrackingAreas];
}
-- (NSPoint) eventLocation:(NSEvent*)event
+- (NSPoint)eventLocation:(NSEvent*)event
{
return nsPointFromPoints(puglview,
[self convertPoint:[event locationInWindow]
@@ -352,21 +348,27 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(view->puglview, (const PuglEvent*)&ev);
}
-- (void) mouseEntered:(NSEvent*)event
+- (void)mouseEntered:(NSEvent*)event
{
handleCrossing(self, event, PUGL_POINTER_IN);
[puglview->impl->cursor set];
puglview->impl->mouseTracked = true;
}
-- (void) mouseExited:(NSEvent*)event
+- (void)mouseExited:(NSEvent*)event
{
[[NSCursor arrowCursor] set];
handleCrossing(self, event, PUGL_POINTER_OUT);
puglview->impl->mouseTracked = false;
}
-- (void) mouseMoved:(NSEvent*)event
+- (void)cursorUpdate:(NSEvent*)event
+{
+ (void)event;
+ [puglview->impl->cursor set];
+}
+
+- (void)mouseMoved:(NSEvent*)event
{
const NSPoint wloc = [self eventLocation:event];
const NSPoint rloc = [NSEvent mouseLocation];
@@ -384,22 +386,22 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
-- (void) mouseDragged:(NSEvent*)event
+- (void)mouseDragged:(NSEvent*)event
{
[self mouseMoved: event];
}
-- (void) rightMouseDragged:(NSEvent*)event
+- (void)rightMouseDragged:(NSEvent*)event
{
[self mouseMoved: event];
}
-- (void) otherMouseDragged:(NSEvent*)event
+- (void)otherMouseDragged:(NSEvent*)event
{
[self mouseMoved: event];
}
-- (void) mouseDown:(NSEvent*)event
+- (void)mouseDown:(NSEvent*)event
{
const NSPoint wloc = [self eventLocation:event];
const NSPoint rloc = [NSEvent mouseLocation];
@@ -418,7 +420,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
-- (void) mouseUp:(NSEvent*)event
+- (void)mouseUp:(NSEvent*)event
{
const NSPoint wloc = [self eventLocation:event];
const NSPoint rloc = [NSEvent mouseLocation];
@@ -437,27 +439,27 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
-- (void) rightMouseDown:(NSEvent*)event
+- (void)rightMouseDown:(NSEvent*)event
{
[self mouseDown: event];
}
-- (void) rightMouseUp:(NSEvent*)event
+- (void)rightMouseUp:(NSEvent*)event
{
[self mouseUp: event];
}
-- (void) otherMouseDown:(NSEvent*)event
+- (void)otherMouseDown:(NSEvent*)event
{
[self mouseDown: event];
}
-- (void) otherMouseUp:(NSEvent*)event
+- (void)otherMouseUp:(NSEvent*)event
{
[self mouseUp: event];
}
-- (void) scrollWheel:(NSEvent*)event
+- (void)scrollWheel:(NSEvent*)event
{
const NSPoint wloc = [self eventLocation:event];
const NSPoint rloc = [NSEvent mouseLocation];
@@ -490,7 +492,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
-- (void) keyDown:(NSEvent*)event
+- (void)keyDown:(NSEvent*)event
{
if (puglview->hints[PUGL_IGNORE_KEY_REPEAT] && [event isARepeat]) {
return;
@@ -548,19 +550,19 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
-- (BOOL) hasMarkedText
+- (BOOL)hasMarkedText
{
return [markedText length] > 0;
}
-- (NSRange) markedRange
+- (NSRange)markedRange
{
return (([markedText length] > 0)
? NSMakeRange(0, [markedText length] - 1)
: NSMakeRange(NSNotFound, 0));
}
-- (NSRange) selectedRange
+- (NSRange)selectedRange
{
return NSMakeRange(NSNotFound, 0);
}
@@ -578,33 +580,33 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
: [[NSMutableAttributedString alloc] initWithString:string]);
}
-- (void) unmarkText
+- (void)unmarkText
{
[[markedText mutableString] setString:@""];
}
-- (NSArray*) validAttributesForMarkedText
+- (NSArray*)validAttributesForMarkedText
{
return @[];
}
-- (NSAttributedString*)
- attributedSubstringForProposedRange:(NSRange)range
- actualRange:(NSRangePointer)actual
+- (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
+ actualRange:
+ (NSRangePointer)actual
{
(void)range;
(void)actual;
return nil;
}
-- (NSUInteger) characterIndexForPoint:(NSPoint)point
+- (NSUInteger)characterIndexForPoint:(NSPoint)point
{
(void)point;
return 0;
}
-- (NSRect) firstRectForCharacterRange:(NSRange)range
- actualRange:(NSRangePointer)actual
+- (NSRect)firstRectForCharacterRange:(NSRange)range
+ actualRange:(NSRangePointer)actual
{
(void)range;
(void)actual;
@@ -613,13 +615,12 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
return NSMakeRect(frame.origin.x, frame.origin.y, 0.0, 0.0);
}
-- (void) doCommandBySelector:(SEL)selector
+- (void)doCommandBySelector:(SEL)selector
{
(void)selector;
}
-- (void) insertText:(id)string
- replacementRange:(NSRange)replacement
+- (void)insertText:(id)string replacementRange:(NSRange)replacement
{
(void)replacement;
@@ -663,7 +664,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
}
}
-- (void) flagsChanged:(NSEvent*)event
+- (void)flagsChanged:(NSEvent*)event
{
const uint32_t mods = getModifiers(event);
PuglEventType type = PUGL_NOTHING;
@@ -704,36 +705,28 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglview->impl->mods = mods;
}
-- (BOOL) preservesContentInLiveResize
+- (BOOL)preservesContentInLiveResize
{
return NO;
}
-- (void) viewWillStartLiveResize
+- (void)viewWillStartLiveResize
{
- timer = [NSTimer timerWithTimeInterval:(1 / 60.0)
- target:self
- selector:@selector(resizeTick)
- userInfo:nil
- repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:timer
- forMode:NSRunLoopCommonModes];
-
- [super viewWillStartLiveResize];
+ puglDispatchSimpleEvent(puglview, PUGL_LOOP_ENTER);
}
-- (void) viewWillDraw
+- (void)viewWillDraw
{
puglDispatchSimpleEvent(puglview, PUGL_UPDATE);
[super viewWillDraw];
}
-- (void) resizeTick
+- (void)resizeTick
{
puglPostRedisplay(puglview);
}
-- (void) timerTick:(NSTimer*)userTimer
+- (void)timerTick:(NSTimer*)userTimer
{
const NSNumber* userInfo = userTimer.userInfo;
const PuglEventTimer ev = {PUGL_TIMER, 0, userInfo.unsignedLongValue};
@@ -741,18 +734,16 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
-- (void) viewDidEndLiveResize
+- (void)viewDidEndLiveResize
{
- [super viewDidEndLiveResize];
- [timer invalidate];
- timer = NULL;
+ puglDispatchSimpleEvent(puglview, PUGL_LOOP_LEAVE);
}
@end
@interface PuglWindowDelegate : NSObject<NSWindowDelegate>
-- (instancetype) initWithPuglWindow:(PuglWindow*)window;
+- (instancetype)initWithPuglWindow:(PuglWindow*)window;
@end
@@ -761,7 +752,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
PuglWindow* window;
}
-- (instancetype) initWithPuglWindow:(PuglWindow*)puglWindow
+- (instancetype)initWithPuglWindow:(PuglWindow*)puglWindow
{
if ((self = [super init])) {
window = puglWindow;
@@ -770,7 +761,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
return self;
}
-- (BOOL) windowShouldClose:(id)sender
+- (BOOL)windowShouldClose:(id)sender
{
(void)sender;
@@ -778,14 +769,14 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
return YES;
}
-- (void) windowDidMove:(NSNotification*)notification
+- (void)windowDidMove:(NSNotification*)notification
{
(void)notification;
updateViewRect(window->puglview);
}
-- (void) windowDidBecomeKey:(NSNotification*)notification
+- (void)windowDidBecomeKey:(NSNotification*)notification
{
(void)notification;
@@ -794,7 +785,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
puglDispatchEvent(window->puglview, &ev);
}
-- (void) windowDidResignKey:(NSNotification*)notification
+- (void)windowDidResignKey:(NSNotification*)notification
{
(void)notification;
@@ -862,10 +853,48 @@ puglConstraint(id item, NSLayoutAttribute attribute, float constant)
PuglStatus
puglRealize(PuglView* view)
{
- PuglInternals* impl = view->impl;
+ PuglInternals* impl = view->impl;
+ if (impl->wrapperView) {
+ return PUGL_FAILURE;
+ }
+
const NSScreen* const screen = [NSScreen mainScreen];
const double scaleFactor = [screen backingScaleFactor];
+ // Getting depth from the display mode seems tedious, just set usual values
+ if (view->hints[PUGL_RED_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_RED_BITS] = 8;
+ }
+ if (view->hints[PUGL_BLUE_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_BLUE_BITS] = 8;
+ }
+ if (view->hints[PUGL_GREEN_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_GREEN_BITS] = 8;
+ }
+ if (view->hints[PUGL_ALPHA_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_ALPHA_BITS] = 8;
+ }
+
+ CGDirectDisplayID displayId = CGMainDisplayID();
+ CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
+
+ // Try to get refresh rate from mode (usually fails)
+ view->hints[PUGL_REFRESH_RATE] = (int)CGDisplayModeGetRefreshRate(mode);
+
+ CGDisplayModeRelease(mode);
+ if (view->hints[PUGL_REFRESH_RATE] == 0) {
+ // Get refresh rate from a display link
+ // TODO: Keep and actually use the display link for something?
+ CVDisplayLinkRef link;
+ CVDisplayLinkCreateWithCGDisplay(displayId, &link);
+
+ const CVTime p = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
+ const double r = p.timeScale / (double)p.timeValue;
+ view->hints[PUGL_REFRESH_RATE] = (int)lrint(r);
+
+ CVDisplayLinkRelease(link);
+ }
+
if (view->frame.width == 0.0 && view->frame.height == 0.0) {
if (view->defaultWidth == 0.0 && view->defaultHeight == 0.0) {
return PUGL_BAD_CONFIGURATION;
@@ -969,12 +998,19 @@ puglRealize(PuglView* view)
puglDispatchSimpleEvent(view, PUGL_CREATE);
- return 0;
+ return PUGL_SUCCESS;
}
PuglStatus
-puglShowWindow(PuglView* view)
+puglShow(PuglView* view)
{
+ if (!view->impl->wrapperView) {
+ const PuglStatus st = puglRealize(view);
+ if (st) {
+ return st;
+ }
+ }
+
if (![view->impl->window isVisible]) {
[view->impl->window setIsVisible:YES];
[view->impl->drawView setNeedsDisplay: YES];
@@ -985,7 +1021,7 @@ puglShowWindow(PuglView* view)
}
PuglStatus
-puglHideWindow(PuglView* view)
+puglHide(PuglView* view)
{
[view->impl->window setIsVisible:NO];
return PUGL_SUCCESS;
@@ -1078,7 +1114,8 @@ puglStopTimer(PuglView* view, uintptr_t id)
return PUGL_UNKNOWN_ERROR;
}
-PuglStatus puglSendEvent(PuglView* view, const PuglEvent* event)
+PuglStatus
+puglSendEvent(PuglView* view, const PuglEvent* event)
{
if (event->type == PUGL_CLIENT) {
PuglWrapperView* wrapper = view->impl->wrapperView;
diff --git a/subprojects/d2tk/pugl/pugl/detail/mac_cairo.m b/subprojects/d2tk/pugl/src/mac_cairo.m
index 18209d9..9a46037 100644
--- a/subprojects/d2tk/pugl/pugl/detail/mac_cairo.m
+++ b/subprojects/d2tk/pugl/src/mac_cairo.m
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file mac_cairo.m
- @brief Cairo graphics backend for MacOS.
-*/
+#include "implementation.h"
+#include "mac.h"
+#include "stub.h"
-#include "pugl/detail/implementation.h"
-#include "pugl/detail/mac.h"
-#include "pugl/detail/stub.h"
-#include "pugl/pugl_cairo.h"
+#include "pugl/cairo.h"
#include <cairo-quartz.h>
@@ -41,14 +37,14 @@
cairo_t* cr;
}
-- (id) initWithFrame:(NSRect)frame
+- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
return self;
}
-- (void) resizeWithOldSuperviewSize:(NSSize)oldSize
+- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
{
PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
@@ -56,7 +52,7 @@
[wrapper setReshaped];
}
-- (void) drawRect:(NSRect)rect
+- (void)drawRect:(NSRect)rect
{
PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
[wrapper dispatchExpose:rect];
@@ -151,7 +147,8 @@ puglMacCairoGetContext(PuglView* view)
return ((PuglCairoView*)view->impl->drawView)->cr;
}
-const PuglBackend* puglCairoBackend(void)
+const PuglBackend*
+puglCairoBackend(void)
{
static const PuglBackend backend = {puglStubConfigure,
puglMacCairoCreate,
diff --git a/subprojects/d2tk/pugl/pugl/detail/mac_gl.m b/subprojects/d2tk/pugl/src/mac_gl.m
index 4bf6fc1..b29221f 100644
--- a/subprojects/d2tk/pugl/pugl/detail/mac_gl.m
+++ b/subprojects/d2tk/pugl/src/mac_gl.m
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file mac_gl.m
- @brief OpenGL graphics backend for MacOS.
-*/
+#include "implementation.h"
+#include "mac.h"
+#include "stub.h"
-#include "pugl/detail/implementation.h"
-#include "pugl/detail/mac.h"
-#include "pugl/detail/stub.h"
-#include "pugl/pugl_gl.h"
+#include "pugl/gl.h"
#ifndef __MAC_10_10
# define NSOpenGLProfileVersion4_1Core NSOpenGLProfileVersion3_2Core
@@ -37,7 +33,7 @@
PuglView* puglview;
}
-- (id) initWithFrame:(NSRect)frame
+- (id)initWithFrame:(NSRect)frame
{
const bool compat = puglview->hints[PUGL_USE_COMPAT_PROFILE];
const unsigned samples = (unsigned)puglview->hints[PUGL_SAMPLES];
@@ -48,12 +44,36 @@
? NSOpenGLProfileVersion4_1Core
: NSOpenGLProfileVersion3_2Core));
- NSOpenGLPixelFormatAttribute pixelAttribs[16] = {
+ // Set attributes to default if they are unset
+ // (There is no GLX_DONT_CARE equivalent on MacOS)
+ if (puglview->hints[PUGL_DEPTH_BITS] == PUGL_DONT_CARE) {
+ puglview->hints[PUGL_DEPTH_BITS] = 0;
+ }
+ if (puglview->hints[PUGL_STENCIL_BITS] == PUGL_DONT_CARE) {
+ puglview->hints[PUGL_STENCIL_BITS] = 0;
+ }
+ if (puglview->hints[PUGL_SAMPLES] == PUGL_DONT_CARE) {
+ puglview->hints[PUGL_SAMPLES] = 1;
+ }
+ if (puglview->hints[PUGL_DOUBLE_BUFFER] == PUGL_DONT_CARE) {
+ puglview->hints[PUGL_DOUBLE_BUFFER] = 1;
+ }
+ if (puglview->hints[PUGL_SWAP_INTERVAL] == PUGL_DONT_CARE) {
+ puglview->hints[PUGL_SWAP_INTERVAL] = 1;
+ }
+
+ const unsigned colorSize = (unsigned)(puglview->hints[PUGL_RED_BITS] +
+ puglview->hints[PUGL_BLUE_BITS] +
+ puglview->hints[PUGL_GREEN_BITS] +
+ puglview->hints[PUGL_ALPHA_BITS]);
+
+ NSOpenGLPixelFormatAttribute pixelAttribs[17] = {
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFAOpenGLProfile, profile,
- NSOpenGLPFAColorSize, 32,
- NSOpenGLPFADepthSize, 32,
+ NSOpenGLPFAColorSize, colorSize,
+ NSOpenGLPFADepthSize, (unsigned)puglview->hints[PUGL_DEPTH_BITS],
+ NSOpenGLPFAStencilSize, (unsigned)puglview->hints[PUGL_STENCIL_BITS],
NSOpenGLPFAMultisample, samples ? 1 : 0,
NSOpenGLPFASampleBuffers, samples ? 1 : 0,
NSOpenGLPFASamples, samples,
@@ -78,7 +98,7 @@
return self;
}
-- (void) reshape
+- (void)reshape
{
PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
@@ -86,7 +106,7 @@
[wrapper setReshaped];
}
-- (void) drawRect:(NSRect)rect
+- (void)drawRect:(NSRect)rect
{
PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
[wrapper dispatchExpose:rect];
@@ -164,7 +184,20 @@ puglGetProcAddress(const char *name)
return func;
}
-const PuglBackend* puglGlBackend(void)
+PuglStatus
+puglEnterContext(PuglView* view)
+{
+ return view->backend->enter(view, NULL);
+}
+
+PuglStatus
+puglLeaveContext(PuglView* view)
+{
+ return view->backend->leave(view, NULL);
+}
+
+const PuglBackend*
+puglGlBackend(void)
{
static const PuglBackend backend = {puglStubConfigure,
puglMacGlCreate,
diff --git a/subprojects/d2tk/pugl/pugl/detail/mac_stub.m b/subprojects/d2tk/pugl/src/mac_stub.m
index 8271735..404d295 100644
--- a/subprojects/d2tk/pugl/pugl/detail/mac_stub.m
+++ b/subprojects/d2tk/pugl/src/mac_stub.m
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file mac_stub.m
- @brief Stub graphics backend for MacOS.
-*/
+#include "implementation.h"
+#include "mac.h"
+#include "stub.h"
-#include "pugl/detail/implementation.h"
-#include "pugl/detail/mac.h"
-#include "pugl/detail/stub.h"
-#include "pugl/pugl_stub.h"
+#include "pugl/stub.h"
#import <Cocoa/Cocoa.h>
@@ -35,7 +31,7 @@
PuglView* puglview;
}
-- (void) resizeWithOldSuperviewSize:(NSSize)oldSize
+- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
{
PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
@@ -43,7 +39,7 @@
[wrapper setReshaped];
}
-- (void) drawRect:(NSRect)rect
+- (void)drawRect:(NSRect)rect
{
PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
diff --git a/subprojects/d2tk/pugl/src/mac_vulkan.m b/subprojects/d2tk/pugl/src/mac_vulkan.m
new file mode 100644
index 0000000..c56346c
--- /dev/null
+++ b/subprojects/d2tk/pugl/src/mac_vulkan.m
@@ -0,0 +1,213 @@
+/*
+ Copyright 2012-2020 David Robillard <http://drobilla.net>
+
+ 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.
+*/
+
+#define VK_NO_PROTOTYPES 1
+
+#include "implementation.h"
+#include "mac.h"
+#include "stub.h"
+#include "types.h"
+
+#include "pugl/pugl.h"
+#include "pugl/stub.h"
+#include "pugl/vulkan.h"
+
+#include <vulkan/vulkan_core.h>
+#include <vulkan/vulkan_macos.h>
+
+#import <Cocoa/Cocoa.h>
+#import <QuartzCore/CAMetalLayer.h>
+
+#include <dlfcn.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+
+@interface PuglVulkanView : NSView<CALayerDelegate>
+
+@end
+
+@implementation PuglVulkanView
+{
+@public
+ PuglView* puglview;
+}
+
+- (id)initWithFrame:(NSRect)frame
+{
+ self = [super initWithFrame:frame];
+
+ if (self) {
+ self.wantsLayer = YES;
+ self.layerContentsRedrawPolicy =
+ NSViewLayerContentsRedrawOnSetNeedsDisplay;
+ }
+
+ return self;
+}
+
+- (CALayer*)makeBackingLayer
+{
+ CAMetalLayer* layer = [CAMetalLayer layer];
+ [layer setDelegate:self];
+ return layer;
+}
+
+- (void)setFrameSize:(NSSize)newSize
+{
+ PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
+
+ [super setFrameSize:newSize];
+ [wrapper setReshaped];
+
+ self.layer.frame = self.bounds;
+}
+
+- (void)displayLayer:(CALayer*)layer
+{
+ (void)layer;
+ PuglWrapperView* wrapper = (PuglWrapperView*)[self superview];
+ [wrapper dispatchExpose:[self bounds]];
+}
+
+@end
+
+static PuglStatus
+puglMacVulkanCreate(PuglView* view)
+{
+ PuglInternals* impl = view->impl;
+ PuglVulkanView* drawView = [PuglVulkanView alloc];
+ const NSRect rect = NSMakeRect(0, 0, view->frame.width, view->frame.height);
+
+ drawView->puglview = view;
+ [drawView initWithFrame:rect];
+ if (view->hints[PUGL_RESIZABLE]) {
+ [drawView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ } else {
+ [drawView setAutoresizingMask:NSViewNotSizable];
+ }
+
+ impl->drawView = drawView;
+ return PUGL_SUCCESS;
+}
+
+static PuglStatus
+puglMacVulkanDestroy(PuglView* view)
+{
+ PuglVulkanView* const drawView = (PuglVulkanView*)view->impl->drawView;
+
+ [drawView removeFromSuperview];
+ [drawView release];
+
+ view->impl->drawView = nil;
+ return PUGL_SUCCESS;
+}
+
+struct PuglVulkanLoaderImpl {
+ void* libvulkan;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
+ PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
+};
+
+PuglVulkanLoader*
+puglNewVulkanLoader(PuglWorld* PUGL_UNUSED(world))
+{
+ PuglVulkanLoader* loader = (PuglVulkanLoader*)
+ calloc(1, sizeof(PuglVulkanLoader));
+ if (!loader) {
+ return NULL;
+ }
+
+ if (!(loader->libvulkan = dlopen("libvulkan.dylib", RTLD_LAZY))) {
+ free(loader);
+ return NULL;
+ }
+
+ loader->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)
+ dlsym(loader->libvulkan, "vkGetInstanceProcAddr");
+
+ loader->vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)
+ dlsym(loader->libvulkan, "vkGetDeviceProcAddr");
+
+ return loader;
+}
+
+void
+puglFreeVulkanLoader(PuglVulkanLoader* loader)
+{
+ if (loader) {
+ dlclose(loader->libvulkan);
+ free(loader);
+ }
+}
+
+PFN_vkGetInstanceProcAddr
+puglGetInstanceProcAddrFunc(const PuglVulkanLoader* loader)
+{
+ return loader->vkGetInstanceProcAddr;
+}
+
+PFN_vkGetDeviceProcAddr
+puglGetDeviceProcAddrFunc(const PuglVulkanLoader* loader)
+{
+ return loader->vkGetDeviceProcAddr;
+}
+
+const PuglBackend*
+puglVulkanBackend(void)
+{
+ static const PuglBackend backend = {puglStubConfigure,
+ puglMacVulkanCreate,
+ puglMacVulkanDestroy,
+ puglStubEnter,
+ puglStubLeave,
+ puglStubGetContext};
+
+ return &backend;
+}
+
+const char* const*
+puglGetInstanceExtensions(uint32_t* const count)
+{
+ static const char* const extensions[] = {"VK_KHR_surface",
+ "VK_MVK_macos_surface"};
+
+ *count = 2;
+ return extensions;
+}
+
+VkResult
+puglCreateSurface(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
+ PuglView* const view,
+ VkInstance instance,
+ const VkAllocationCallbacks* const allocator,
+ VkSurfaceKHR* const surface)
+{
+ PuglInternals* const impl = view->impl;
+
+ PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK =
+ (PFN_vkCreateMacOSSurfaceMVK)
+ vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK");
+
+ const VkMacOSSurfaceCreateInfoMVK info = {
+ VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK,
+ NULL,
+ 0,
+ impl->drawView,
+ };
+
+ return vkCreateMacOSSurfaceMVK(instance, &info, allocator, surface);
+}
diff --git a/subprojects/d2tk/pugl/pugl/detail/stub.h b/subprojects/d2tk/pugl/src/stub.h
index acd3181..36d7364 100644
--- a/subprojects/d2tk/pugl/pugl/detail/stub.h
+++ b/subprojects/d2tk/pugl/src/stub.h
@@ -14,11 +14,6 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file stub.h
- @brief Definition of generic stub backend functions.
-*/
-
#ifndef PUGL_DETAIL_STUB_H
#define PUGL_DETAIL_STUB_H
diff --git a/subprojects/d2tk/pugl/pugl/detail/types.h b/subprojects/d2tk/pugl/src/types.h
index 6f676fd..6fa658f 100644
--- a/subprojects/d2tk/pugl/pugl/detail/types.h
+++ b/subprojects/d2tk/pugl/src/types.h
@@ -14,11 +14,6 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file types.h
- @brief Shared internal type definitions.
-*/
-
#ifndef PUGL_DETAIL_TYPES_H
#define PUGL_DETAIL_TYPES_H
@@ -31,7 +26,7 @@
// Unused parameter macro to suppresses warnings and make it impossible to use
#if defined(__cplusplus)
# define PUGL_UNUSED(name)
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) || defined(__clang__)
# define PUGL_UNUSED(name) name##_unused __attribute__((__unused__))
#else
# define PUGL_UNUSED(name) name
@@ -84,12 +79,10 @@ struct PuglViewImpl {
struct PuglWorldImpl {
PuglWorldInternals* impl;
PuglWorldHandle handle;
- PuglLogFunc logFunc;
char* className;
double startTime;
size_t numViews;
PuglView** views;
- PuglLogLevel logLevel;
};
/// Opaque surface used by graphics backend
diff --git a/subprojects/d2tk/pugl/pugl/detail/win.c b/subprojects/d2tk/pugl/src/win.c
index ce81ede..1b9ee99 100644
--- a/subprojects/d2tk/pugl/pugl/detail/win.c
+++ b/subprojects/d2tk/pugl/src/win.c
@@ -14,17 +14,13 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file win.c
- @brief Windows implementation.
-*/
+#include "win.h"
-#include "pugl/detail/win.h"
+#include "implementation.h"
+#include "stub.h"
-#include "pugl/detail/implementation.h"
-#include "pugl/detail/stub.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_stub.h"
+#include "pugl/stub.h"
#include <windows.h>
#include <windowsx.h>
@@ -51,7 +47,6 @@
#define PUGL_LOCAL_CLOSE_MSG (WM_USER + 50)
#define PUGL_LOCAL_MARK_MSG (WM_USER + 51)
#define PUGL_LOCAL_CLIENT_MSG (WM_USER + 52)
-#define PUGL_RESIZE_TIMER_ID 9461
#define PUGL_USER_TIMER_MIN 9470
typedef BOOL (WINAPI *PFN_SetProcessDPIAware)(void);
@@ -165,11 +160,28 @@ PuglStatus
puglRealize(PuglView* view)
{
PuglInternals* impl = view->impl;
+ if (impl->hwnd) {
+ return PUGL_FAILURE;
+ }
+
+ // Getting depth from the display mode seems tedious, just set usual values
+ if (view->hints[PUGL_RED_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_RED_BITS] = 8;
+ }
+ if (view->hints[PUGL_BLUE_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_BLUE_BITS] = 8;
+ }
+ if (view->hints[PUGL_GREEN_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_GREEN_BITS] = 8;
+ }
+ if (view->hints[PUGL_ALPHA_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_ALPHA_BITS] = 8;
+ }
// Get refresh rate for resize draw timer
DEVMODEA devMode = {0};
EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &devMode);
- view->impl->refreshRate = devMode.dmDisplayFrequency;
+ view->hints[PUGL_REFRESH_RATE] = (int)devMode.dmDisplayFrequency;
// Register window class if necessary
if (!puglRegisterWindowClass(view->world->className)) {
@@ -180,11 +192,10 @@ puglRealize(PuglView* view)
return PUGL_BAD_BACKEND;
}
- PuglStatus st = view->backend->configure(view);
- if (st) {
- return PUGL_SET_FORMAT_FAILED;
- } else if ((st = view->backend->create(view))) {
- return PUGL_CREATE_CONTEXT_FAILED;
+ PuglStatus st = PUGL_SUCCESS;
+ if ((st = view->backend->configure(view)) ||
+ (st = view->backend->create(view))) {
+ return st;
}
if (view->title) {
@@ -202,17 +213,24 @@ puglRealize(PuglView* view)
}
PuglStatus
-puglShowWindow(PuglView* view)
+puglShow(PuglView* view)
{
PuglInternals* impl = view->impl;
+ if (!impl->hwnd) {
+ const PuglStatus st = puglRealize(view);
+ if (st) {
+ return st;
+ }
+ }
+
ShowWindow(impl->hwnd, SW_SHOWNORMAL);
SetFocus(impl->hwnd);
return PUGL_SUCCESS;
}
PuglStatus
-puglHideWindow(PuglView* view)
+puglHide(PuglView* view)
{
PuglInternals* impl = view->impl;
@@ -401,9 +419,9 @@ initKeyEvent(PuglEventKey* event,
const PuglKey special = keySymToSpecial(vkey);
if (special) {
if (ext && (special == PUGL_KEY_CTRL || special == PUGL_KEY_ALT)) {
- event->key = special + 1u; // Right hand key
+ event->key = (uint32_t)special + 1u; // Right hand key
} else {
- event->key = special;
+ event->key = (uint32_t)special;
}
} else if (!dead) {
// Translate unshifted key
@@ -418,7 +436,8 @@ initKeyEvent(PuglEventKey* event,
static void
initCharEvent(PuglEvent* event, PuglView* view, WPARAM wParam, LPARAM lParam)
{
- const wchar_t utf16[2] = { wParam & 0xFFFF, (wParam >> 16) & 0xFFFF };
+ const wchar_t utf16[2] = {wParam & 0xFFFF,
+ (wchar_t)((wParam >> 16) & 0xFFFF)};
initKeyEvent(&event->key, view, true, wParam, lParam);
event->type = PUGL_TEXT;
@@ -494,33 +513,33 @@ constrainAspect(const PuglView* const view,
{
const float minA = (float)view->minAspectX / (float)view->minAspectY;
const float maxA = (float)view->maxAspectX / (float)view->maxAspectY;
- const int w = size->right - size->left;
- const int h = size->bottom - size->top;
- const float a = (float)w / (float)h;
+ const float w = (float)(size->right - size->left);
+ const float h = (float)(size->bottom - size->top);
+ const float a = w / h;
switch (wParam) {
case WMSZ_TOP:
- size->top = (a < minA ? (LONG)(size->bottom - w * minA) :
- a > maxA ? (LONG)(size->bottom - w * maxA) :
+ size->top = (a < minA ? (LONG)((float)size->bottom - w * minA) :
+ a > maxA ? (LONG)((float)size->bottom - w * maxA) :
size->top);
break;
case WMSZ_TOPRIGHT:
case WMSZ_RIGHT:
case WMSZ_BOTTOMRIGHT:
- size->right = (a < minA ? (LONG)(size->left + h * minA) :
- a > maxA ? (LONG)(size->left + h * maxA) :
+ size->right = (a < minA ? (LONG)((float)size->left + h * minA) :
+ a > maxA ? (LONG)((float)size->left + h * maxA) :
size->right);
break;
case WMSZ_BOTTOM:
- size->bottom = (a < minA ? (LONG)(size->top + w * minA) :
- a > maxA ? (LONG)(size->top + w * maxA) :
+ size->bottom = (a < minA ? (LONG)((float)size->top + w * minA) :
+ a > maxA ? (LONG)((float)size->top + w * maxA) :
size->bottom);
break;
case WMSZ_BOTTOMLEFT:
case WMSZ_LEFT:
case WMSZ_TOPLEFT:
- size->left = (a < minA ? (LONG)(size->right - h * minA) :
- a > maxA ? (LONG)(size->right - h * maxA) :
+ size->left = (a < minA ? (LONG)((float)size->right - h * minA) :
+ a > maxA ? (LONG)((float)size->right - h * maxA) :
size->left);
break;
}
@@ -529,15 +548,12 @@ constrainAspect(const PuglView* const view,
static LRESULT
handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
{
- PuglEvent event;
+ PuglEvent event = {{PUGL_NOTHING, 0}};
+ RECT rect = {0, 0, 0, 0};
+ POINT pt = {0, 0};
+ MINMAXINFO* mmi = NULL;
void* dummy_ptr = NULL;
- RECT rect;
- MINMAXINFO* mmi;
- POINT pt;
- memset(&event, 0, sizeof(event));
-
- event.any.type = PUGL_NOTHING;
if (InSendMessageEx(dummy_ptr)) {
event.any.flags |= PUGL_IS_SEND_EVENT;
}
@@ -546,6 +562,8 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT) {
SetCursor(view->impl->cursor);
+ } else {
+ return DefWindowProc(view->impl->hwnd, message, wParam, lParam);
}
break;
case WM_SHOWWINDOW:
@@ -575,17 +593,10 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_ENTERSIZEMOVE:
case WM_ENTERMENULOOP:
- view->impl->resizing = true;
- SetTimer(view->impl->hwnd,
- PUGL_RESIZE_TIMER_ID,
- 1000 / view->impl->refreshRate,
- NULL);
+ puglDispatchSimpleEvent(view, PUGL_LOOP_ENTER);
break;
case WM_TIMER:
- if (wParam == PUGL_RESIZE_TIMER_ID) {
- RedrawWindow(view->impl->hwnd, NULL, NULL,
- RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_INTERNALPAINT);
- } else if (wParam >= PUGL_USER_TIMER_MIN) {
+ if (wParam >= PUGL_USER_TIMER_MIN) {
PuglEvent ev = {{PUGL_TIMER, 0}};
ev.timer.id = wParam - PUGL_USER_TIMER_MIN;
puglDispatchEvent(view, &ev);
@@ -593,9 +604,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_EXITSIZEMOVE:
case WM_EXITMENULOOP:
- KillTimer(view->impl->hwnd, PUGL_RESIZE_TIMER_ID);
- view->impl->resizing = false;
- puglPostRedisplay(view);
+ puglDispatchSimpleEvent(view, PUGL_LOOP_LEAVE);
break;
case WM_GETMINMAXINFO:
mmi = (MINMAXINFO*)lParam;
@@ -667,14 +676,14 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_MOUSEWHEEL:
initScrollEvent(&event, view, lParam);
- event.scroll.dy = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
+ event.scroll.dy = GET_WHEEL_DELTA_WPARAM(wParam) / (double)WHEEL_DELTA;
event.scroll.direction = (event.scroll.dy > 0
? PUGL_SCROLL_UP
: PUGL_SCROLL_DOWN);
break;
case WM_MOUSEHWHEEL:
initScrollEvent(&event, view, lParam);
- event.scroll.dx = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
+ event.scroll.dx = GET_WHEEL_DELTA_WPARAM(wParam) / (double)WHEEL_DELTA;
event.scroll.direction = (event.scroll.dx > 0
? PUGL_SCROLL_RIGHT
: PUGL_SCROLL_LEFT);
@@ -1079,7 +1088,8 @@ puglSetClipboard(PuglView* const view,
// Measure string and allocate global memory for clipboard
const char* str = (const char*)data;
const int wlen = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
- HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (wlen + 1) * sizeof(wchar_t));
+ HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,
+ (size_t)(wlen + 1) * sizeof(wchar_t));
if (!mem) {
CloseClipboard();
return PUGL_UNKNOWN_ERROR;
@@ -1102,28 +1112,6 @@ puglSetClipboard(PuglView* const view,
return PUGL_SUCCESS;
}
-static PuglStatus
-puglWinStubEnter(PuglView* view, const PuglEventExpose* expose)
-{
- if (expose) {
- PAINTSTRUCT ps;
- BeginPaint(view->impl->hwnd, &ps);
- }
-
- return PUGL_SUCCESS;
-}
-
-static PuglStatus
-puglWinStubLeave(PuglView* view, const PuglEventExpose* expose)
-{
- if (expose) {
- PAINTSTRUCT ps;
- EndPaint(view->impl->hwnd, &ps);
- }
-
- return PUGL_SUCCESS;
-}
-
static const char* const cursor_ids[] = {
IDC_ARROW, // ARROW
IDC_IBEAM, // CARET
@@ -1157,16 +1145,3 @@ puglSetCursor(PuglView* view, PuglCursor cursor)
return PUGL_SUCCESS;
}
-
-const PuglBackend*
-puglStubBackend(void)
-{
- static const PuglBackend backend = {puglWinStubConfigure,
- puglStubCreate,
- puglStubDestroy,
- puglWinStubEnter,
- puglWinStubLeave,
- puglStubGetContext};
-
- return &backend;
-}
diff --git a/subprojects/d2tk/pugl/pugl/detail/win.h b/subprojects/d2tk/pugl/src/win.h
index 1b9b0c4..bc1f763 100644
--- a/subprojects/d2tk/pugl/pugl/detail/win.h
+++ b/subprojects/d2tk/pugl/src/win.h
@@ -14,12 +14,10 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file win.h
- @brief Shared definitions for Windows implementation.
-*/
+#ifndef PUGL_DETAIL_WIN_H
+#define PUGL_DETAIL_WIN_H
-#include "pugl/detail/implementation.h"
+#include "implementation.h"
#include <windows.h>
@@ -38,9 +36,7 @@ struct PuglInternalsImpl {
HCURSOR cursor;
HDC hdc;
PuglSurface* surface;
- DWORD refreshRate;
bool flashing;
- bool resizing;
bool mouseTracked;
};
@@ -138,26 +134,13 @@ puglWinCreateWindow(PuglView* const view,
return PUGL_SUCCESS;
}
-static inline PuglStatus
-puglWinStubConfigure(PuglView* view)
-{
- PuglInternals* const impl = view->impl;
- PuglStatus st = PUGL_SUCCESS;
-
- if ((st = puglWinCreateWindow(view, "Pugl", &impl->hwnd, &impl->hdc))) {
- return st;
- }
+PuglStatus
+puglWinStubConfigure(PuglView* view);
- impl->pfd = puglWinGetPixelFormatDescriptor(view->hints);
- impl->pfId = ChoosePixelFormat(impl->hdc, &impl->pfd);
+PuglStatus
+puglWinStubEnter(PuglView* view, const PuglEventExpose* expose);
- if (!SetPixelFormat(impl->hdc, impl->pfId, &impl->pfd)) {
- ReleaseDC(impl->hwnd, impl->hdc);
- DestroyWindow(impl->hwnd);
- impl->hwnd = NULL;
- impl->hdc = NULL;
- return PUGL_SET_FORMAT_FAILED;
- }
+PuglStatus
+puglWinStubLeave(PuglView* view, const PuglEventExpose* expose);
- return PUGL_SUCCESS;
-}
+#endif // PUGL_DETAIL_WIN_H
diff --git a/subprojects/d2tk/pugl/pugl/detail/win_cairo.c b/subprojects/d2tk/pugl/src/win_cairo.c
index 1b9afb9..bab8ea0 100644
--- a/subprojects/d2tk/pugl/pugl/detail/win_cairo.c
+++ b/subprojects/d2tk/pugl/src/win_cairo.c
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file win_cairo.c
- @brief Cairo graphics backend for Windows.
-*/
+#include "stub.h"
+#include "types.h"
+#include "win.h"
-#include "pugl/detail/stub.h"
-#include "pugl/detail/types.h"
-#include "pugl/detail/win.h"
-#include "pugl/pugl_cairo.h"
+#include "pugl/cairo.h"
#include <cairo-win32.h>
#include <cairo.h>
@@ -96,11 +92,10 @@ puglWinCairoOpen(PuglView* view)
PuglInternals* const impl = view->impl;
PuglWinCairoSurface* const surface = (PuglWinCairoSurface*)impl->surface;
- cairo_status_t st = CAIRO_STATUS_SUCCESS;
if (!(surface->surface = cairo_win32_surface_create(surface->drawDc)) ||
- (st = cairo_surface_status(surface->surface)) ||
+ cairo_surface_status(surface->surface) ||
!(surface->cr = cairo_create(surface->surface)) ||
- (st = cairo_status(surface->cr))) {
+ cairo_status(surface->cr)) {
return PUGL_CREATE_CONTEXT_FAILED;
}
diff --git a/subprojects/d2tk/pugl/pugl/detail/win_gl.c b/subprojects/d2tk/pugl/src/win_gl.c
index 8cdad76..fcf511b 100644
--- a/subprojects/d2tk/pugl/pugl/detail/win_gl.c
+++ b/subprojects/d2tk/pugl/src/win_gl.c
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file win_gl.c
- @brief OpenGL graphics backend for Windows.
-*/
+#include "stub.h"
+#include "types.h"
+#include "win.h"
-#include "pugl/detail/stub.h"
-#include "pugl/detail/types.h"
-#include "pugl/detail/win.h"
-#include "pugl/pugl_gl.h"
+#include "pugl/gl.h"
#include <windows.h>
@@ -108,6 +104,24 @@ puglWinGlConfigure(PuglView* view)
{
PuglInternals* impl = view->impl;
+ // Set attributes to default if they are unset
+ // (There is no GLX_DONT_CARE equivalent on Windows)
+ if (view->hints[PUGL_DEPTH_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_DEPTH_BITS] = 0;
+ }
+ if (view->hints[PUGL_STENCIL_BITS] == PUGL_DONT_CARE) {
+ view->hints[PUGL_STENCIL_BITS] = 0;
+ }
+ if (view->hints[PUGL_SAMPLES] == PUGL_DONT_CARE) {
+ view->hints[PUGL_SAMPLES] = 1;
+ }
+ if (view->hints[PUGL_DOUBLE_BUFFER] == PUGL_DONT_CARE) {
+ view->hints[PUGL_DOUBLE_BUFFER] = 1;
+ }
+ if (view->hints[PUGL_SWAP_INTERVAL] == PUGL_DONT_CARE) {
+ view->hints[PUGL_SWAP_INTERVAL] = 1;
+ }
+
// clang-format off
const int pixelAttrs[] = {
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
@@ -142,9 +156,7 @@ puglWinGlConfigure(PuglView* view)
// Set pixel format for fake window
const PuglWinPFD fakePfd = puglWinGetPixelFormatDescriptor(view->hints);
const int fakePfId = ChoosePixelFormat(fakeWin.hdc, &fakePfd);
- if (!fakePfId) {
- return puglWinError(&fakeWin, PUGL_SET_FORMAT_FAILED);
- } else if (!SetPixelFormat(fakeWin.hdc, fakePfId, &fakePfd)) {
+ if (!fakePfId || !SetPixelFormat(fakeWin.hdc, fakePfId, &fakePfd)) {
return puglWinError(&fakeWin, PUGL_SET_FORMAT_FAILED);
}
@@ -293,6 +305,18 @@ puglGetProcAddress(const char* name)
: (PuglGlFunc)GetProcAddress(GetModuleHandle("opengl32.dll"), name);
}
+PuglStatus
+puglEnterContext(PuglView* view)
+{
+ return view->backend->enter(view, NULL);
+}
+
+PuglStatus
+puglLeaveContext(PuglView* view)
+{
+ return view->backend->leave(view, NULL);
+}
+
const PuglBackend*
puglGlBackend(void)
{
diff --git a/subprojects/d2tk/pugl/src/win_stub.c b/subprojects/d2tk/pugl/src/win_stub.c
new file mode 100644
index 0000000..2027836
--- /dev/null
+++ b/subprojects/d2tk/pugl/src/win_stub.c
@@ -0,0 +1,80 @@
+/*
+ Copyright 2012-2020 David Robillard <d@drobilla.net>
+
+ 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.
+*/
+
+#include "stub.h"
+#include "types.h"
+#include "win.h"
+
+#include "pugl/stub.h"
+
+PuglStatus
+puglWinStubConfigure(PuglView* view)
+{
+ PuglInternals* const impl = view->impl;
+ PuglStatus st = PUGL_SUCCESS;
+
+ if ((st = puglWinCreateWindow(view, "Pugl", &impl->hwnd, &impl->hdc))) {
+ return st;
+ }
+
+ impl->pfd = puglWinGetPixelFormatDescriptor(view->hints);
+ impl->pfId = ChoosePixelFormat(impl->hdc, &impl->pfd);
+
+ if (!SetPixelFormat(impl->hdc, impl->pfId, &impl->pfd)) {
+ ReleaseDC(impl->hwnd, impl->hdc);
+ DestroyWindow(impl->hwnd);
+ impl->hwnd = NULL;
+ impl->hdc = NULL;
+ return PUGL_SET_FORMAT_FAILED;
+ }
+
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
+puglWinStubEnter(PuglView* view, const PuglEventExpose* expose)
+{
+ if (expose) {
+ PAINTSTRUCT ps;
+ BeginPaint(view->impl->hwnd, &ps);
+ }
+
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
+puglWinStubLeave(PuglView* view, const PuglEventExpose* expose)
+{
+ if (expose) {
+ PAINTSTRUCT ps;
+ EndPaint(view->impl->hwnd, &ps);
+ }
+
+ return PUGL_SUCCESS;
+}
+
+const PuglBackend*
+puglStubBackend(void)
+{
+ static const PuglBackend backend = {puglWinStubConfigure,
+ puglStubCreate,
+ puglStubDestroy,
+ puglWinStubEnter,
+ puglWinStubLeave,
+ puglStubGetContext};
+
+ return &backend;
+}
diff --git a/subprojects/d2tk/pugl/src/win_vulkan.c b/subprojects/d2tk/pugl/src/win_vulkan.c
new file mode 100644
index 0000000..f862716
--- /dev/null
+++ b/subprojects/d2tk/pugl/src/win_vulkan.c
@@ -0,0 +1,127 @@
+/*
+ Copyright 2012-2020 David Robillard <http://drobilla.net>
+
+ 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.
+*/
+
+#define VK_NO_PROTOTYPES 1
+
+#include "stub.h"
+#include "types.h"
+#include "win.h"
+
+#include "pugl/stub.h"
+#include "pugl/vulkan.h"
+
+#include <vulkan/vulkan.h>
+#include <vulkan/vulkan_win32.h>
+
+#include <stdlib.h>
+
+struct PuglVulkanLoaderImpl
+{
+ HMODULE libvulkan;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
+ PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
+};
+
+PuglVulkanLoader*
+puglNewVulkanLoader(PuglWorld* PUGL_UNUSED(world))
+{
+ PuglVulkanLoader* loader =
+ (PuglVulkanLoader*)calloc(1, sizeof(PuglVulkanLoader));
+ if (!loader) {
+ return NULL;
+ }
+
+ if (!(loader->libvulkan = LoadLibrary("vulkan-1.dll"))) {
+ free(loader);
+ return NULL;
+ }
+
+ loader->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)GetProcAddress(
+ loader->libvulkan, "vkGetInstanceProcAddr");
+
+ loader->vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)GetProcAddress(
+ loader->libvulkan, "vkGetDeviceProcAddr");
+
+ return loader;
+}
+
+void
+puglFreeVulkanLoader(PuglVulkanLoader* loader)
+{
+ if (loader) {
+ FreeLibrary(loader->libvulkan);
+ free(loader);
+ }
+}
+
+PFN_vkGetInstanceProcAddr
+puglGetInstanceProcAddrFunc(const PuglVulkanLoader* loader)
+{
+ return loader->vkGetInstanceProcAddr;
+}
+
+PFN_vkGetDeviceProcAddr
+puglGetDeviceProcAddrFunc(const PuglVulkanLoader* loader)
+{
+ return loader->vkGetDeviceProcAddr;
+}
+
+const PuglBackend*
+puglVulkanBackend()
+{
+ static const PuglBackend backend = {puglWinStubConfigure,
+ puglStubCreate,
+ puglStubDestroy,
+ puglWinStubEnter,
+ puglWinStubLeave,
+ puglStubGetContext};
+
+ return &backend;
+}
+
+const char* const*
+puglGetInstanceExtensions(uint32_t* const count)
+{
+ static const char* const extensions[] = {"VK_KHR_surface",
+ "VK_KHR_win32_surface"};
+
+ *count = 2;
+ return extensions;
+}
+
+VkResult
+puglCreateSurface(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
+ PuglView* const view,
+ VkInstance instance,
+ const VkAllocationCallbacks* const pAllocator,
+ VkSurfaceKHR* const pSurface)
+{
+ PuglInternals* const impl = view->impl;
+
+ PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR =
+ (PFN_vkCreateWin32SurfaceKHR)
+ vkGetInstanceProcAddr(instance, "vkCreateWin32SurfaceKHR");
+
+ const VkWin32SurfaceCreateInfoKHR createInfo = {
+ VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
+ NULL,
+ 0,
+ GetModuleHandle(NULL),
+ impl->hwnd,
+ };
+
+ return vkCreateWin32SurfaceKHR(instance, &createInfo, pAllocator, pSurface);
+}
diff --git a/subprojects/d2tk/pugl/pugl/detail/x11.c b/subprojects/d2tk/pugl/src/x11.c
index 01058a3..328d5c3 100644
--- a/subprojects/d2tk/pugl/pugl/detail/x11.c
+++ b/subprojects/d2tk/pugl/src/x11.c
@@ -16,20 +16,14 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file x11.c
- @brief X11 implementation.
-*/
-
#define _POSIX_C_SOURCE 199309L
-#include "pugl/detail/x11.h"
+#include "x11.h"
+
+#include "implementation.h"
+#include "types.h"
-#include "pugl/detail/implementation.h"
-#include "pugl/detail/stub.h"
-#include "pugl/detail/types.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_stub.h"
#include <X11/X.h>
#include <X11/Xatom.h>
@@ -37,6 +31,10 @@
#include <X11/Xutil.h>
#include <X11/keysym.h>
+#ifdef HAVE_XRANDR
+# include <X11/extensions/Xrandr.h>
+#endif
+
#ifdef HAVE_XSYNC
# include <X11/extensions/sync.h>
# include <X11/extensions/syncconst.h>
@@ -71,12 +69,6 @@ enum WmClientStateMessageAction {
WM_STATE_TOGGLE
};
-static const long eventMask =
- (ExposureMask | StructureNotifyMask |
- VisibilityChangeMask | FocusChangeMask |
- EnterWindowMask | LeaveWindowMask | PointerMotionMask |
- ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask);
-
static bool
puglInitXSync(PuglWorldInternals* impl)
{
@@ -279,81 +271,114 @@ puglRealize(PuglView* view)
PuglWorld* const world = view->world;
PuglX11Atoms* const atoms = &view->world->impl->atoms;
Display* const display = world->impl->display;
-
- impl->display = display;
- impl->screen = DefaultScreen(display);
-
- if (!view->backend || !view->backend->configure) {
+ const int screen = DefaultScreen(display);
+ const Window root = RootWindow(display, screen);
+ const Window parent = view->parent ? (Window)view->parent : root;
+ XSetWindowAttributes attr = {0};
+ PuglStatus st = PUGL_SUCCESS;
+
+ // Ensure that we're unrealized and that a reasonable backend has been set
+ if (impl->win) {
+ return PUGL_FAILURE;
+ } else if (!view->backend || !view->backend->configure) {
return PUGL_BAD_BACKEND;
- } else if (view->frame.width == 0.0 && view->frame.height == 0.0) {
- if (view->defaultWidth == 0.0 && view->defaultHeight == 0.0) {
+ }
+
+ // Set the size to the default if it has not already been set
+ if (view->frame.width == 0.0 && view->frame.height == 0.0) {
+ if (view->defaultWidth == 0.0 || view->defaultHeight == 0.0) {
return PUGL_BAD_CONFIGURATION;
}
- const int screenWidth = DisplayWidth(display, impl->screen);
- const int screenHeight = DisplayHeight(display, impl->screen);
-
view->frame.width = view->defaultWidth;
view->frame.height = view->defaultHeight;
- view->frame.x = screenWidth / 2.0 - view->frame.width / 2.0;
- view->frame.y = screenHeight / 2.0 - view->frame.height / 2.0;
}
- PuglStatus st = view->backend->configure(view);
- if (st || !impl->vi) {
+ // Center top-level windows if a position has not been set
+ if (!view->parent && view->frame.x == 0.0 && view->frame.y == 0.0) {
+ const int screenWidth = DisplayWidth(display, screen);
+ const int screenHeight = DisplayHeight(display, screen);
+
+ view->frame.x = screenWidth / 2.0 - view->frame.width / 2.0;
+ view->frame.y = screenHeight / 2.0 - view->frame.height / 2.0;
+ }
+
+ // Configure the backend to get the visual info
+ impl->display = display;
+ impl->screen = screen;
+ if ((st = view->backend->configure(view)) || !impl->vi) {
view->backend->destroy(view);
return st ? st : PUGL_BACKEND_FAILED;
}
- Window xParent = view->parent ? (Window)view->parent
- : RootWindow(display, impl->screen);
-
- Colormap cmap = XCreateColormap(
- display, xParent, impl->vi->visual, AllocNone);
-
- XSetWindowAttributes attr = {0};
- attr.colormap = cmap;
- attr.event_mask = eventMask;
-
- const Window win = impl->win = XCreateWindow(
- display, xParent,
- (int)view->frame.x, (int)view->frame.y,
- (unsigned)view->frame.width, (unsigned)view->frame.height,
- 0, impl->vi->depth, InputOutput,
- impl->vi->visual, CWColormap | CWEventMask, &attr);
-
+ // Create a colormap based on the visual info from the backend
+ attr.colormap =
+ XCreateColormap(display, parent, impl->vi->visual, AllocNone);
+
+ // Set the event mask to request all of the event types we react to
+ attr.event_mask |= ButtonPressMask;
+ attr.event_mask |= ButtonReleaseMask;
+ attr.event_mask |= EnterWindowMask;
+ attr.event_mask |= ExposureMask;
+ attr.event_mask |= FocusChangeMask;
+ attr.event_mask |= KeyPressMask;
+ attr.event_mask |= KeyReleaseMask;
+ attr.event_mask |= LeaveWindowMask;
+ attr.event_mask |= PointerMotionMask;
+ attr.event_mask |= StructureNotifyMask;
+ attr.event_mask |= VisibilityChangeMask;
+
+ // Create the window
+ impl->win = XCreateWindow(display,
+ parent,
+ (int)view->frame.x,
+ (int)view->frame.y,
+ (unsigned)view->frame.width,
+ (unsigned)view->frame.height,
+ 0,
+ impl->vi->depth,
+ InputOutput,
+ impl->vi->visual,
+ CWColormap | CWEventMask,
+ &attr);
+
+ // Create the backend drawing context/surface
if ((st = view->backend->create(view))) {
return st;
}
+#ifdef HAVE_XRANDR
+ // Set refresh rate hint to the real refresh rate
+ XRRScreenConfiguration* conf = XRRGetScreenInfo(display, parent);
+ short current_rate = XRRConfigCurrentRate(conf);
+
+ view->hints[PUGL_REFRESH_RATE] = current_rate;
+ XRRFreeScreenConfigInfo(conf);
+#endif
+
updateSizeHints(view);
XClassHint classHint = { world->className, world->className };
- XSetClassHint(display, win, &classHint);
+ XSetClassHint(display, impl->win, &classHint);
if (view->title) {
puglSetWindowTitle(view, view->title);
}
- if (!view->parent) {
- XSetWMProtocols(display, win, &atoms->WM_DELETE_WINDOW, 1);
+ if (parent == root) {
+ XSetWMProtocols(display, impl->win, &atoms->WM_DELETE_WINDOW, 1);
}
if (view->transientParent) {
- XSetTransientForHint(display, win, (Window)(view->transientParent));
+ XSetTransientForHint(display, impl->win, (Window)view->transientParent);
}
// Create input context
- const XIMStyle im_style = XIMPreeditNothing | XIMStatusNothing;
- if (!(impl->xic = XCreateIC(world->impl->xim,
- XNInputStyle, im_style,
- XNClientWindow, win,
- XNFocusWindow, win,
- NULL))) {
- view->world->logFunc(view->world,
- PUGL_LOG_LEVEL_WARNING,
- "XCreateID failed\n");
- }
+ impl->xic = XCreateIC(world->impl->xim,
+ XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
+ XNClientWindow, impl->win,
+ XNFocusWindow, impl->win,
+ NULL);
#ifdef HAVE_XCURSOR
puglDefineCursorShape(view, impl->cursorShape);
@@ -365,7 +390,7 @@ puglRealize(PuglView* view)
}
PuglStatus
-puglShowWindow(PuglView* view)
+puglShow(PuglView* view)
{
PuglStatus st = PUGL_SUCCESS;
@@ -382,7 +407,7 @@ puglShowWindow(PuglView* view)
}
PuglStatus
-puglHideWindow(PuglView* view)
+puglHide(PuglView* view)
{
XUnmapWindow(view->impl->display, view->impl->win);
return PUGL_SUCCESS;
@@ -845,6 +870,8 @@ puglSendEvent(PuglView* view, const PuglEvent* event)
if (xev.type) {
if (XSendEvent(view->impl->display, view->impl->win, False, 0, &xev)) {
return PUGL_SUCCESS;
+ } else {
+ return PUGL_UNKNOWN_ERROR;
}
}
@@ -862,20 +889,18 @@ puglWaitForEvent(PuglView* view)
#endif
static void
-mergeExposeEvents(PuglEvent* dst, const PuglEvent* src)
+mergeExposeEvents(PuglEventExpose* dst, const PuglEventExpose* src)
{
if (!dst->type) {
*dst = *src;
} else {
- const double max_x = MAX(dst->expose.x + dst->expose.width,
- src->expose.x + src->expose.width);
- const double max_y = MAX(dst->expose.y + dst->expose.height,
- src->expose.y + src->expose.height);
-
- dst->expose.x = MIN(dst->expose.x, src->expose.x);
- dst->expose.y = MIN(dst->expose.y, src->expose.y);
- dst->expose.width = max_x - dst->expose.x;
- dst->expose.height = max_y - dst->expose.y;
+ const double max_x = MAX(dst->x + dst->width, src->x + src->width);
+ const double max_y = MAX(dst->y + dst->height, src->y + src->height);
+
+ dst->x = MIN(dst->x, src->x);
+ dst->y = MIN(dst->y, src->y);
+ dst->width = max_x - dst->x;
+ dst->height = max_y - dst->y;
}
}
@@ -1074,7 +1099,7 @@ puglDispatchX11Events(PuglWorld* world)
if (event.type == PUGL_EXPOSE) {
// Expand expose event to be dispatched after loop
- mergeExposeEvents(&view->impl->pendingExpose, &event);
+ mergeExposeEvents(&view->impl->pendingExpose.expose, &event.expose);
} else if (event.type == PUGL_CONFIGURE) {
// Expand configure event to be dispatched after loop
view->impl->pendingConfigure = event;
@@ -1164,7 +1189,7 @@ puglPostRedisplayRect(PuglView* view, PuglRect rect)
if (view->world->impl->dispatchingEvents) {
// Currently dispatching events, add/expand expose for the loop end
- mergeExposeEvents(&view->impl->pendingExpose, (const PuglEvent*)&event);
+ mergeExposeEvents(&view->impl->pendingExpose.expose, &event);
} else if (view->visible) {
// Not dispatching events, send an X expose so we wake up next time
return puglSendEvent(view, (const PuglEvent*)&event);
@@ -1200,15 +1225,18 @@ puglSetWindowTitle(PuglView* view, const char* title)
PuglStatus
puglSetFrame(PuglView* view, const PuglRect frame)
{
- view->frame = frame;
-
- if (view->impl->win &&
- !XMoveResizeWindow(view->world->impl->display, view->impl->win,
- (int)frame.x, (int)frame.y,
- (unsigned)frame.width, (unsigned)frame.height)) {
- return PUGL_UNKNOWN_ERROR;
+ if (view->impl->win) {
+ if (!XMoveResizeWindow(view->world->impl->display,
+ view->impl->win,
+ (int)frame.x,
+ (int)frame.y,
+ (unsigned)frame.width,
+ (unsigned)frame.height)) {
+ return PUGL_UNKNOWN_ERROR;
+ }
}
+ view->frame = frame;
return PUGL_SUCCESS;
}
@@ -1356,18 +1384,3 @@ puglSetCursor(PuglView* view, PuglCursor cursor)
return PUGL_FAILURE;
#endif
}
-
-const PuglBackend*
-puglStubBackend(void)
-{
- static const PuglBackend backend = {
- puglX11StubConfigure,
- puglStubCreate,
- puglStubDestroy,
- puglStubEnter,
- puglStubLeave,
- puglStubGetContext,
- };
-
- return &backend;
-}
diff --git a/subprojects/d2tk/pugl/pugl/detail/x11.h b/subprojects/d2tk/pugl/src/x11.h
index cedba56..5bf5e5b 100644
--- a/subprojects/d2tk/pugl/pugl/detail/x11.h
+++ b/subprojects/d2tk/pugl/src/x11.h
@@ -14,12 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file x11.h
- @brief Shared definitions for X11 implementation.
-*/
+#ifndef PUGL_DETAIL_X11_H
+#define PUGL_DETAIL_X11_H
+
+#include "types.h"
-#include "pugl/detail/types.h"
#include "pugl/pugl.h"
#include <X11/X.h>
@@ -74,15 +73,6 @@ struct PuglInternalsImpl {
#endif
};
-static inline PuglStatus
-puglX11StubConfigure(PuglView* view)
-{
- PuglInternals* const impl = view->impl;
- XVisualInfo pat = {0};
- int n = 0;
-
- pat.screen = impl->screen;
- impl->vi = XGetVisualInfo(impl->display, VisualScreenMask, &pat, &n);
+PuglStatus puglX11StubConfigure(PuglView* view);
- return PUGL_SUCCESS;
-}
+#endif // PUGL_DETAIL_X11_H
diff --git a/subprojects/d2tk/pugl/pugl/detail/x11_cairo.c b/subprojects/d2tk/pugl/src/x11_cairo.c
index 0112c4e..3147266 100644
--- a/subprojects/d2tk/pugl/pugl/detail/x11_cairo.c
+++ b/subprojects/d2tk/pugl/src/x11_cairo.c
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file x11_cairo.c
- @brief Cairo graphics backend for X11.
-*/
+#include "types.h"
+#include "x11.h"
-#include "pugl/detail/types.h"
-#include "pugl/detail/x11.h"
+#include "pugl/cairo.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_cairo.h"
#include <X11/Xutil.h>
#include <cairo-xlib.h>
diff --git a/subprojects/d2tk/pugl/pugl/detail/x11_gl.c b/subprojects/d2tk/pugl/src/x11_gl.c
index f5e6b8d..50b37b8 100644
--- a/subprojects/d2tk/pugl/pugl/detail/x11_gl.c
+++ b/subprojects/d2tk/pugl/src/x11_gl.c
@@ -14,16 +14,12 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/**
- @file x11_gl.c
- @brief OpenGL graphics backend for X11.
-*/
+#include "stub.h"
+#include "types.h"
+#include "x11.h"
-#include "pugl/detail/stub.h"
-#include "pugl/detail/types.h"
-#include "pugl/detail/x11.h"
+#include "pugl/gl.h"
#include "pugl/pugl.h"
-#include "pugl/pugl_gl.h"
#include <GL/glx.h>
#include <X11/X.h>
@@ -37,7 +33,6 @@
typedef struct {
GLXFBConfig fb_config;
GLXContext ctx;
- int double_buffered;
} PuglX11GlSurface;
static int
@@ -72,7 +67,7 @@ puglX11GlConfigure(PuglView* view)
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_SAMPLES, view->hints[PUGL_SAMPLES],
+ GLX_SAMPLES, puglX11GlHintValue(view->hints[PUGL_SAMPLES]),
GLX_RED_SIZE, puglX11GlHintValue(view->hints[PUGL_RED_BITS]),
GLX_GREEN_SIZE, puglX11GlHintValue(view->hints[PUGL_GREEN_BITS]),
GLX_BLUE_SIZE, puglX11GlHintValue(view->hints[PUGL_BLUE_BITS]),
@@ -92,22 +87,22 @@ puglX11GlConfigure(PuglView* view)
surface->fb_config = fbc[0];
impl->vi = glXGetVisualFromFBConfig(impl->display, fbc[0]);
- char msg[128];
-
- snprintf(
- msg,
- sizeof(msg),
- "Using visual 0x%lX: R=%d G=%d B=%d A=%d D=%d DOUBLE=%d SAMPLES=%d\n",
- impl->vi->visualid,
- puglX11GlGetAttrib(display, fbc[0], GLX_RED_SIZE),
- puglX11GlGetAttrib(display, fbc[0], GLX_GREEN_SIZE),
- puglX11GlGetAttrib(display, fbc[0], GLX_BLUE_SIZE),
- puglX11GlGetAttrib(display, fbc[0], GLX_ALPHA_SIZE),
- puglX11GlGetAttrib(display, fbc[0], GLX_DEPTH_SIZE),
- puglX11GlGetAttrib(display, fbc[0], GLX_DOUBLEBUFFER),
- puglX11GlGetAttrib(display, fbc[0], GLX_SAMPLES));
-
- view->world->logFunc(view->world, PUGL_LOG_LEVEL_INFO, msg);
+ view->hints[PUGL_RED_BITS] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_RED_SIZE);
+ view->hints[PUGL_GREEN_BITS] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_GREEN_SIZE);
+ view->hints[PUGL_BLUE_BITS] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_BLUE_SIZE);
+ view->hints[PUGL_ALPHA_BITS] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_ALPHA_SIZE);
+ view->hints[PUGL_DEPTH_BITS] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_DEPTH_SIZE);
+ view->hints[PUGL_STENCIL_BITS] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_STENCIL_SIZE);
+ view->hints[PUGL_SAMPLES] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_SAMPLES);
+ view->hints[PUGL_DOUBLE_BUFFER] = puglX11GlGetAttrib(
+ display, fbc[0], GLX_DOUBLEBUFFER);
XFree(fbc);
@@ -125,9 +120,7 @@ puglX11GlEnter(PuglView* view, const PuglEventExpose* PUGL_UNUSED(expose))
static PuglStatus
puglX11GlLeave(PuglView* view, const PuglEventExpose* expose)
{
- PuglX11GlSurface* surface = (PuglX11GlSurface*)view->impl->surface;
-
- if (expose && surface->double_buffered) {
+ if (expose && view->hints[PUGL_DOUBLE_BUFFER]) {
glXSwapBuffers(view->impl->display, view->impl->win);
}
@@ -183,7 +176,12 @@ puglX11GlCreate(PuglView* view)
glXGetConfig(impl->display,
impl->vi,
GLX_DOUBLEBUFFER,
- &surface->double_buffered);
+ &view->hints[PUGL_DOUBLE_BUFFER]);
+
+ glXQueryDrawable(display,
+ impl->win,
+ GLX_SWAP_INTERVAL_EXT,
+ (unsigned int*)&view->hints[PUGL_SWAP_INTERVAL]);
return PUGL_SUCCESS;
}
@@ -206,7 +204,20 @@ puglGetProcAddress(const char* name)
return glXGetProcAddress((const uint8_t*)name);
}
-const PuglBackend* puglGlBackend(void)
+PuglStatus
+puglEnterContext(PuglView* view)
+{
+ return view->backend->enter(view, NULL);
+}
+
+PuglStatus
+puglLeaveContext(PuglView* view)
+{
+ return view->backend->leave(view, NULL);
+}
+
+const PuglBackend*
+puglGlBackend(void)
{
static const PuglBackend backend = {puglX11GlConfigure,
puglX11GlCreate,
diff --git a/subprojects/d2tk/pugl/src/x11_stub.c b/subprojects/d2tk/pugl/src/x11_stub.c
new file mode 100644
index 0000000..be66a88
--- /dev/null
+++ b/subprojects/d2tk/pugl/src/x11_stub.c
@@ -0,0 +1,58 @@
+/*
+ Copyright 2012-2020 David Robillard <d@drobilla.net>
+
+ 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.
+*/
+
+#include "pugl/stub.h"
+
+#include "stub.h"
+#include "types.h"
+#include "x11.h"
+
+#include "pugl/pugl.h"
+
+#include <X11/Xutil.h>
+
+PuglStatus
+puglX11StubConfigure(PuglView* view)
+{
+ PuglInternals* const impl = view->impl;
+ XVisualInfo pat = {0};
+ int n = 0;
+
+ pat.screen = impl->screen;
+ impl->vi = XGetVisualInfo(impl->display, VisualScreenMask, &pat, &n);
+
+ view->hints[PUGL_RED_BITS] = impl->vi->bits_per_rgb;
+ view->hints[PUGL_GREEN_BITS] = impl->vi->bits_per_rgb;
+ view->hints[PUGL_BLUE_BITS] = impl->vi->bits_per_rgb;
+ view->hints[PUGL_ALPHA_BITS] = 0;
+
+ return PUGL_SUCCESS;
+}
+
+const PuglBackend*
+puglStubBackend(void)
+{
+ static const PuglBackend backend = {
+ puglX11StubConfigure,
+ puglStubCreate,
+ puglStubDestroy,
+ puglStubEnter,
+ puglStubLeave,
+ puglStubGetContext,
+ };
+
+ return &backend;
+}
diff --git a/subprojects/d2tk/pugl/src/x11_vulkan.c b/subprojects/d2tk/pugl/src/x11_vulkan.c
new file mode 100644
index 0000000..b32111c
--- /dev/null
+++ b/subprojects/d2tk/pugl/src/x11_vulkan.c
@@ -0,0 +1,131 @@
+/*
+ Copyright 2012-2020 David Robillard <http://drobilla.net>
+
+ 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.
+*/
+
+#define VK_NO_PROTOTYPES 1
+
+#include "stub.h"
+#include "types.h"
+#include "x11.h"
+
+#include "pugl/pugl.h"
+#include "pugl/vulkan.h"
+
+#include <vulkan/vulkan_core.h>
+#include <vulkan/vulkan_xlib.h>
+
+#include <dlfcn.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+
+struct PuglVulkanLoaderImpl
+{
+ void* libvulkan;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
+ PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
+};
+
+PuglVulkanLoader*
+puglNewVulkanLoader(PuglWorld* PUGL_UNUSED(world))
+{
+ PuglVulkanLoader* loader =
+ (PuglVulkanLoader*)calloc(1, sizeof(PuglVulkanLoader));
+ if (!loader) {
+ return NULL;
+ }
+
+ if (!(loader->libvulkan = dlopen("libvulkan.so", RTLD_LAZY))) {
+ free(loader);
+ return NULL;
+ }
+
+ loader->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym(
+ loader->libvulkan, "vkGetInstanceProcAddr");
+
+ loader->vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)dlsym(
+ loader->libvulkan, "vkGetDeviceProcAddr");
+
+ return loader;
+}
+
+void
+puglFreeVulkanLoader(PuglVulkanLoader* loader)
+{
+ if (loader) {
+ dlclose(loader->libvulkan);
+ free(loader);
+ }
+}
+
+PFN_vkGetInstanceProcAddr
+puglGetInstanceProcAddrFunc(const PuglVulkanLoader* loader)
+{
+ return loader->vkGetInstanceProcAddr;
+}
+
+PFN_vkGetDeviceProcAddr
+puglGetDeviceProcAddrFunc(const PuglVulkanLoader* loader)
+{
+ return loader->vkGetDeviceProcAddr;
+}
+
+const PuglBackend*
+puglVulkanBackend(void)
+{
+ static const PuglBackend backend = {puglX11StubConfigure,
+ puglStubCreate,
+ puglStubDestroy,
+ puglStubEnter,
+ puglStubLeave,
+ puglStubGetContext};
+
+ return &backend;
+}
+
+const char* const*
+puglGetInstanceExtensions(uint32_t* const count)
+{
+ static const char* const extensions[] = {"VK_KHR_surface",
+ "VK_KHR_xlib_surface"};
+
+ *count = 2;
+ return extensions;
+}
+
+VkResult
+puglCreateSurface(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr,
+ PuglView* const view,
+ VkInstance instance,
+ const VkAllocationCallbacks* const allocator,
+ VkSurfaceKHR* const surface)
+{
+ PuglInternals* const impl = view->impl;
+ PuglWorldInternals* world_impl = view->world->impl;
+
+ PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR =
+ (PFN_vkCreateXlibSurfaceKHR)
+ vkGetInstanceProcAddr(instance, "vkCreateXlibSurfaceKHR");
+
+ const VkXlibSurfaceCreateInfoKHR info = {
+ VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
+ NULL,
+ 0,
+ world_impl->display,
+ impl->win,
+ };
+
+ return vkCreateXlibSurfaceKHR(instance, &info, allocator, surface);
+}
diff --git a/subprojects/d2tk/pugl/test/.clang-tidy b/subprojects/d2tk/pugl/test/.clang-tidy
new file mode 100644
index 0000000..e7c1e2c
--- /dev/null
+++ b/subprojects/d2tk/pugl/test/.clang-tidy
@@ -0,0 +1,14 @@
+Checks: >
+ *,
+ -*-magic-numbers,
+ -*-uppercase-literal-suffix,
+ -bugprone-reserved-identifier,
+ -cert-dcl37-c,
+ -cert-dcl51-cpp,
+ -hicpp-multiway-paths-covered,
+ -hicpp-signed-bitwise,
+ -llvm-header-guard,
+ -llvmlibc-*,
+ -modernize-use-trailing-return-type,
+FormatStyle: file
+HeaderFilterRegex: 'pugl/.*|test/.*'
diff --git a/subprojects/d2tk/pugl/test/test_build.c b/subprojects/d2tk/pugl/test/test_build.c
index de2ed28..5259c7c 100644
--- a/subprojects/d2tk/pugl/test/test_build.c
+++ b/subprojects/d2tk/pugl/test/test_build.c
@@ -20,12 +20,10 @@
#define PUGL_DISABLE_DEPRECATED
-#include "pugl/gl.h"
-#include "pugl/glu.h"
-#include "pugl/pugl.h"
-#include "pugl/pugl_cairo.h"
-#include "pugl/pugl_gl.h"
-#include "pugl/pugl_stub.h"
+#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/subprojects/d2tk/pugl/test/test_build.cpp b/subprojects/d2tk/pugl/test/test_build.cpp
index 79f1dfc..5beb4c3 100644
--- a/subprojects/d2tk/pugl/test/test_build.cpp
+++ b/subprojects/d2tk/pugl/test/test_build.cpp
@@ -20,14 +20,11 @@
#define PUGL_DISABLE_DEPRECATED
-#include "pugl/gl.h"