vgl 1.0.0
Virtual Globe Library: API reference
Loading...
Searching...
No Matches
d3d11.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2026 Jeremiah van Oosten
3//
4// C++ wrapper for vgl/d3d11.h (docs/c-api.md, section 16). Link vgl::d3d11.
5
6#ifndef VGL_D3D11_HPP
7#define VGL_D3D11_HPP
8
9#include <vgl/base.hpp>
10#include <vgl/context.hpp>
11#include <vgl/d3d11.h>
12
13#include <cstdint>
14#include <span>
15#include <utility>
16
17namespace vgl
18{
19
20// Owns a vgl_d3d11_backend. Destroy it on the thread that owns its device context, before its
21// context.
23{
24public:
25 d3d11_backend() noexcept = default;
26 explicit d3d11_backend(vgl_d3d11_backend* handle) noexcept : handle_(handle) {}
27 d3d11_backend(const d3d11_backend&) = delete;
29 d3d11_backend(d3d11_backend&& other) noexcept : handle_(other.release()) {}
31 {
32 if (this != &other)
33 {
34 reset(other.release());
35 }
36 return *this;
37 }
39
40 // Creates a backend for owner on the device that info names.
41 [[nodiscard]] static expected<d3d11_backend>
43 {
44 vgl_d3d11_backend* handle = nullptr;
45 const auto r = static_cast<result>(vgl_d3d11_backend_create(owner.get(), &info, &handle));
46 if (failed(r))
47 {
48 return unexpected(r);
49 }
50 return d3d11_backend(handle);
51 }
52
53 [[nodiscard]] vgl_d3d11_backend* get() const noexcept { return handle_; }
54 [[nodiscard]] explicit operator bool() const noexcept { return handle_ != nullptr; }
55
56 [[nodiscard]] vgl_d3d11_backend* release() noexcept { return std::exchange(handle_, nullptr); }
57
58 void reset(vgl_d3d11_backend* handle = nullptr) noexcept
59 {
60 static_cast<void>(vgl_d3d11_backend_destroy(std::exchange(handle_, handle)));
61 }
62
63 // Draws the globe into the bound render target. info may be null.
64 [[nodiscard]] result draw(const vgl_d3d11_draw_info* info = nullptr) noexcept
65 {
66 return static_cast<result>(vgl_d3d11_backend_draw(handle_, info));
67 }
68
69 // Sets the stars it draws with VGL_DRAW_FEATURE_STARS (vgl_d3d11_backend_stars_set).
70 [[nodiscard]] result stars_set(std::span<const vgl_star> stars) noexcept
71 {
72 return static_cast<result>(vgl_d3d11_backend_stars_set(
73 handle_, stars.data(), static_cast<std::uint32_t>(stars.size())));
74 }
75
76 // Sets the clouds it draws with VGL_DRAW_FEATURE_CLOUDS (vgl_d3d11_backend_clouds_set).
77 [[nodiscard]] result
78 clouds_set(const std::uint8_t* coverage, std::uint32_t width, std::uint32_t height) noexcept
79 {
80 return static_cast<result>(vgl_d3d11_backend_clouds_set(handle_, coverage, width, height));
81 }
82
83 // Recovers from a removed device, on the new one (vgl_d3d11_backend_device_reset).
84 [[nodiscard]] result device_reset(ID3D11Device* device,
85 ID3D11DeviceContext* device_context) noexcept
86 {
87 return static_cast<result>(vgl_d3d11_backend_device_reset(handle_, device, device_context));
88 }
89
90private:
91 vgl_d3d11_backend* handle_ = nullptr;
92};
93
94} // namespace vgl
95
96#endif // VGL_D3D11_HPP
Definition context.hpp:106
Definition d3d11.hpp:23
void reset(vgl_d3d11_backend *handle=nullptr) noexcept
Definition d3d11.hpp:58
d3d11_backend & operator=(d3d11_backend &&other) noexcept
Definition d3d11.hpp:30
d3d11_backend(d3d11_backend &&other) noexcept
Definition d3d11.hpp:29
d3d11_backend(const d3d11_backend &)=delete
result device_reset(ID3D11Device *device, ID3D11DeviceContext *device_context) noexcept
Definition d3d11.hpp:84
d3d11_backend & operator=(const d3d11_backend &)=delete
result stars_set(std::span< const vgl_star > stars) noexcept
Definition d3d11.hpp:70
d3d11_backend() noexcept=default
vgl_d3d11_backend * release() noexcept
Definition d3d11.hpp:56
static expected< d3d11_backend > create(context &owner, const vgl_d3d11_backend_create_info &info) noexcept
Definition d3d11.hpp:42
result clouds_set(const std::uint8_t *coverage, std::uint32_t width, std::uint32_t height) noexcept
Definition d3d11.hpp:78
result draw(const vgl_d3d11_draw_info *info=nullptr) noexcept
Definition d3d11.hpp:64
~d3d11_backend()
Definition d3d11.hpp:38
vgl_d3d11_backend * get() const noexcept
Definition d3d11.hpp:53
Definition base.hpp:87
Definition base.hpp:72
vgl_result vgl_d3d11_backend_stars_set(vgl_d3d11_backend *backend, const vgl_star *stars, uint32_t star_count)
struct vgl_d3d11_backend vgl_d3d11_backend
Definition d3d11.h:58
vgl_result vgl_d3d11_backend_create(vgl_context *context, const vgl_d3d11_backend_create_info *info, vgl_d3d11_backend **out_backend)
vgl_result vgl_d3d11_backend_destroy(vgl_d3d11_backend *backend)
vgl_result vgl_d3d11_backend_draw(vgl_d3d11_backend *backend, const vgl_d3d11_draw_info *info)
vgl_result vgl_d3d11_backend_device_reset(vgl_d3d11_backend *backend, ID3D11Device *device, ID3D11DeviceContext *device_context)
vgl_result vgl_d3d11_backend_clouds_set(vgl_d3d11_backend *backend, const uint8_t *coverage, uint32_t width, uint32_t height)
Definition base.hpp:22
result
Definition base.hpp:25
Definition d3d11.h:62
Definition d3d11.h:119