aboutsummaryrefslogtreecommitdiff
path: root/subprojects/d2tk/pugl/doc/cpp
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-14 11:04:53 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-14 11:04:53 +0200
commit3007dd352c553ce465ec3746fb022ac0d9aad26a (patch)
treeb0163d7d3edd3b19eeeb4317ad45b98351aeb5fb /subprojects/d2tk/pugl/doc/cpp
parent80ecee6c568afa4448e8a69f997fc40d2f0ff13e (diff)
parent0348c6d4b26e2970723c56913f217d737a435b3a (diff)
downloadmephisto.lv2-3007dd352c553ce465ec3746fb022ac0d9aad26a.tar.xz
Merge commit '0348c6d4b26e2970723c56913f217d737a435b3a'
Diffstat (limited to 'subprojects/d2tk/pugl/doc/cpp')
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/Doxyfile.in (renamed from subprojects/d2tk/pugl/doc/cpp/Doxyfile)16
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/api/meson.build5
-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/event-loop.rst37
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/events.rst43
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/index.rst11
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/meson.build43
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/overview.rst406
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/view.rst299
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/world.rst41
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/wscript44
-rw-r--r--subprojects/d2tk/pugl/doc/cpp/xml/meson.build21
13 files changed, 510 insertions, 494 deletions
diff --git a/subprojects/d2tk/pugl/doc/cpp/Doxyfile b/subprojects/d2tk/pugl/doc/cpp/Doxyfile.in
index 0f5f636..889ac0b 100644
--- a/subprojects/d2tk/pugl/doc/cpp/Doxyfile
+++ b/subprojects/d2tk/pugl/doc/cpp/Doxyfile.in
@@ -2,7 +2,7 @@ PROJECT_NAME = Pugl
PROJECT_BRIEF = "A minimal portable API for embeddable GUIs"
QUIET = YES
-WARN_AS_ERROR = NO
+WARN_AS_ERROR = YES
WARN_IF_UNDOCUMENTED = NO
WARN_NO_PARAMDOC = NO
@@ -26,15 +26,7 @@ SHOW_FILES = NO
MACRO_EXPANSION = YES
PREDEFINED = PUGL_API PUGL_DISABLE_DEPRECATED PUGL_CONST_API= 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
+STRIP_FROM_PATH = @PUGL_SRCDIR@
+INPUT = @PUGL_HEADERS@
-OUTPUT_DIRECTORY = .
+OUTPUT_DIRECTORY = doc/cpp
diff --git a/subprojects/d2tk/pugl/doc/cpp/api/meson.build b/subprojects/d2tk/pugl/doc/cpp/api/meson.build
new file mode 100644
index 0000000..4bbbec2
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/api/meson.build
@@ -0,0 +1,5 @@
+cpp_pugl_rst = custom_target(
+ 'C++ API ReST Documentation',
+ command: [dox_to_sphinx, '-l', 'cpp', '-f', '@INPUT@', 'doc/cpp/api'],
+ input: cpp_index_xml,
+ output: 'pugl.rst')
diff --git a/subprojects/d2tk/pugl/doc/cpp/c-reference.rst b/subprojects/d2tk/pugl/doc/cpp/c-reference.rst
deleted file mode 100644
index 546e4d3..0000000
--- a/subprojects/d2tk/pugl/doc/cpp/c-reference.rst
+++ /dev/null
@@ -1,20 +0,0 @@
-###############
-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
deleted file mode 100644
index 96c523c..0000000
--- a/subprojects/d2tk/pugl/doc/cpp/cpp-reference.rst
+++ /dev/null
@@ -1,18 +0,0 @@
-#################
-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/event-loop.rst b/subprojects/d2tk/pugl/doc/cpp/event-loop.rst
new file mode 100644
index 0000000..1d2ac41
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/event-loop.rst
@@ -0,0 +1,37 @@
+.. default-domain:: cpp
+.. highlight:: cpp
+.. namespace:: pugl
+
+######################
+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.
diff --git a/subprojects/d2tk/pugl/doc/cpp/events.rst b/subprojects/d2tk/pugl/doc/cpp/events.rst
new file mode 100644
index 0000000..72c396c
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/events.rst
@@ -0,0 +1,43 @@
+.. default-domain:: cpp
+.. highlight:: cpp
+.. namespace:: pugl
+
+###############
+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.
diff --git a/subprojects/d2tk/pugl/doc/cpp/index.rst b/subprojects/d2tk/pugl/doc/cpp/index.rst
index c3d330e..b11d028 100644
--- a/subprojects/d2tk/pugl/doc/cpp/index.rst
+++ b/subprojects/d2tk/pugl/doc/cpp/index.rst
@@ -1,7 +1,12 @@
+####
+Pugl
+####
+
+.. include:: summary.rst
+
.. toctree::
- pugl
deployment
overview
- cpp-reference
- c-reference
+ api/pugl
+ api/puglxx
diff --git a/subprojects/d2tk/pugl/doc/cpp/meson.build b/subprojects/d2tk/pugl/doc/cpp/meson.build
new file mode 100644
index 0000000..d8bae11
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/meson.build
@@ -0,0 +1,43 @@
+config = configuration_data()
+config.set('PUGL_VERSION', meson.project_version())
+
+conf_py = configure_file(configuration: config,
+ input: '../conf.py.in',
+ output: 'conf.py')
+
+configure_file(copy: true, input: '../deployment.rst', output: 'deployment.rst')
+configure_file(copy: true, input: '../summary.rst', output: 'summary.rst')
+
+cpp_rst_files = files(
+ 'index.rst',
+ 'overview.rst',
+ 'world.rst',
+ 'view.rst',
+ 'events.rst',
+ 'event-loop.rst',
+)
+
+foreach f : cpp_rst_files
+ configure_file(copy: true, input: f, output: '@PLAINNAME@')
+endforeach
+
+subdir('xml')
+subdir('api')
+
+docs = custom_target(
+ 'C++ API Documentation (singlehtml)',
+ command: [sphinx_build, '-M', 'singlehtml', 'doc/cpp/', 'doc/cpp/', '-E', '-q', '-t', 'singlehtml'],
+ input: [cpp_rst_files, cpp_pugl_rst, cpp_index_xml],
+ output: 'singlehtml',
+ build_by_default: true,
+ install: true,
+ install_dir: docdir / 'puglxx-0')
+
+docs = custom_target(
+ 'C++ API Documentation (html)',
+ command: [sphinx_build, '-M', 'html', 'doc/cpp/', 'doc/cpp/', '-E', '-q', '-t', 'html'],
+ input: [cpp_rst_files, cpp_pugl_rst, cpp_index_xml],
+ output: 'html',
+ build_by_default: true,
+ install: true,
+ install_dir: docdir / 'puglxx-0')
diff --git a/subprojects/d2tk/pugl/doc/cpp/overview.rst b/subprojects/d2tk/pugl/doc/cpp/overview.rst
index 5fffe37..1928fba 100644
--- a/subprojects/d2tk/pugl/doc/cpp/overview.rst
+++ b/subprojects/d2tk/pugl/doc/cpp/overview.rst
@@ -2,6 +2,10 @@
.. highlight:: cpp
.. namespace:: pugl
+########
+Overview
+########
+
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,
@@ -23,401 +27,9 @@ 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
+.. toctree::
-.. [#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.
+ world
+ view
+ events
+ event-loop
diff --git a/subprojects/d2tk/pugl/doc/cpp/view.rst b/subprojects/d2tk/pugl/doc/cpp/view.rst
new file mode 100644
index 0000000..3f5aee8
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/view.rst
@@ -0,0 +1,299 @@
+.. default-domain:: cpp
+.. highlight:: cpp
+.. namespace:: pugl
+
+###############
+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.
+
+.. 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/world.rst b/subprojects/d2tk/pugl/doc/cpp/world.rst
new file mode 100644
index 0000000..1a3b432
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/world.rst
@@ -0,0 +1,41 @@
+.. default-domain:: cpp
+.. highlight:: cpp
+.. namespace:: pugl
+
+################
+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");
diff --git a/subprojects/d2tk/pugl/doc/cpp/wscript b/subprojects/d2tk/pugl/doc/cpp/wscript
deleted file mode 100644
index a7aefc1..0000000
--- a/subprojects/d2tk/pugl/doc/cpp/wscript
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/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/cpp/xml/meson.build b/subprojects/d2tk/pugl/doc/cpp/xml/meson.build
new file mode 100644
index 0000000..3f87f2a
--- /dev/null
+++ b/subprojects/d2tk/pugl/doc/cpp/xml/meson.build
@@ -0,0 +1,21 @@
+doxygen = find_program('doxygen')
+
+cpp_doxygen_input = []
+foreach h : c_headers + cpp_headers
+ cpp_doxygen_input += ['..' / h]
+endforeach
+
+config = configuration_data()
+config.set('PUGL_HEADERS', ' '.join(cpp_doxygen_input))
+config.set('PUGL_SRCDIR', pugl_src_root)
+
+cpp_doxyfile = configure_file(configuration: config,
+ input: '../Doxyfile.in',
+ output: 'Doxyfile')
+
+cpp_index_xml = custom_target(
+ 'cpp-index.xml',
+ command: [doxygen, '@INPUT0@'],
+ input: [cpp_doxyfile] + c_header_files + cpp_header_files,
+ output: 'index.xml')
+