vgl 1.0.0
Virtual Globe Library: API reference
Loading...
Searching...
No Matches
ogre.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2026 Jeremiah van Oosten
3//
4// vgl Ogre backend: draws a context's globe in a classic Ogre 14 scene (design document,
5// section 7.6). It is a consumer of the render interface (vgl/render.h), linked as vgl::ogre, a
6// static library that uses vgl only through the C API. Ogre's interface is C++, so this one is
7// too; no exception crosses it.
8//
9// The globe is an Ogre MovableObject. The host attaches it to a scene node at the origin, which
10// is ECEF's, and keeps that node unrotated and unscaled:
11//
12// vgl::ogre::globe_create_info info;
13// info.depth_convention = VGL_DEPTH_CONVENTION_REVERSED_Z;
14// vgl::expected<vgl::ogre::globe*> globe = vgl::ogre::globe::create(context, info);
15// scene_manager->getRootSceneNode()->attachObject(*globe);
16//
17// // Each frame, after vgl_context_update, before Ogre renders:
18// (*globe)->settings_set(settings); // Optional: the camera in double precision, features.
19// root->renderOneFrame();
20//
21// scene_manager->getRootSceneNode()->detachObject(*globe);
22// vgl::ogre::globe::destroy(*globe); // Before the context and Ogre's render system.
23//
24// The globe's functions are called on Ogre's render thread, as Ogre's own are, and one at a
25// time with the calls on its context (docs/c-api.md, section 11).
26//
27// Ogre draws the tiles with its camera's projection only: each tile's model_view, composed by
28// the core in double precision from the context's view or from the view in the settings,
29// replaces Ogre's view, whose single precision is too coarse at the Earth's radius. The host
30// therefore keeps Ogre's camera's field of view, aspect and clip distances matching the
31// projection it gives the context. For the reversed-Z convention, the render system's "Reversed
32// Z-Buffer" option must be on, and Ogre's far clip distance is best 0 (infinite). Ogre then gives
33// render textures a 32-bit floating-point depth buffer, but its render windows keep a 24-bit
34// integer one, which is too coarse at planetary scale: draw the globe into a render texture and
35// show that, as the Ogre sample does, or use the logarithmic convention.
36//
37// The globe needs Ogre's Media/Main among the resource locations of its resource group, for
38// OgreUnifiedShader.h, as every Ogre application with the shader system has.
39
40#ifndef VGL_OGRE_HPP
41#define VGL_OGRE_HPP
42
43#include <vgl/base.hpp>
44#include <vgl/context.h>
45#include <vgl/context.hpp>
46#include <vgl/render.h>
47
48#include <Ogre.h>
49
50#include <cstdint>
51#include <span>
52
53namespace vgl::ogre
54{
55
56// Creation parameters of a globe.
58{
59 // How depth is written and compared (vgl/render.h).
61 // The resource group of the globe's programs, materials, buffers and textures. It must see
62 // Ogre's Media/Main.
63 Ogre::String resource_group = Ogre::RGN_DEFAULT;
64 // Ogre's name of the globe, unique among its movable objects.
65 Ogre::String name = "vgl/globe";
66};
67
68// How the globe draws, from the next frame on.
70{
71 // The camera to draw from, in double precision, when it differs from the context's view
72 // (vgl_frame_begin_info.view_matrix). has_view_matrix false uses the context's view.
73 bool has_view_matrix = false;
75 // Direction towards the sun, along the ECEF axes; it need not be normalized. Zero lights the
76 // terrain from the camera.
78 // The logarithmic convention's far distance, in metres. 0 selects
79 // VGL_LOGARITHMIC_DEPTH_FAR_DEFAULT.
80 double logarithmic_far = 0.0;
81 // Bytes of resources to upload per frame. 0 selects VGL_UPLOAD_BUDGET_DEFAULT.
82 std::uint64_t upload_budget = 0;
83 // What to draw besides the terrain and its imagery: vgl_draw_feature values (vgl/render.h).
84 // The atmosphere draws in the render queue group RENDER_QUEUE_SKIES_LATE, and the stars in
85 // the group before it.
87 // Views for inspecting level of detail and loading: vgl_debug_view values (vgl/render.h).
89 // The Earth rotation angle in radians (vgl_earth_rotation_angle_get), for the stars.
91 // Height between contour lines, in metres. 0 selects VGL_CONTOUR_INTERVAL_DEFAULT.
92 double contour_interval = 0.0;
93 // The cloud shell's height above the ellipsoid, in metres. 0 selects
94 // VGL_CLOUD_HEIGHT_DEFAULT.
95 double cloud_height = 0.0;
96};
97
98class globe final : public Ogre::MovableObject
99{
100public:
101 // Creates a globe for a context on Ogre's current render system: creates its programs and
102 // material, and tells the context which texture formats it samples. The context must outlive
103 // the globe. Fails with invalid_argument for an unknown depth convention, not_supported if
104 // the render system lacks a shading language the globe has, or the reversed-Z convention
105 // without the render system's option, out_of_memory, and backend_error if Ogre fails; the
106 // context's log says which.
108 const globe_create_info& info) noexcept;
110 const globe_create_info& info) noexcept;
111
112 // Detach it from its scene node first. Null does nothing.
113 static void destroy(globe* g) noexcept;
114
115 // Sets how the globe draws from the next frame on. Fails with invalid_argument, keeping the
116 // settings before, for a matrix or direction that is not finite, unknown feature or debug
117 // view bits, or a distance, interval, height or angle that is not finite or, but for the
118 // angle, negative; the context's log says which.
119 [[nodiscard]] vgl::result settings_set(const globe_settings& settings) noexcept;
120
121 // Sets the stars the globe draws with VGL_DRAW_FEATURE_STARS, replacing those set before, as
122 // vgl_gl_backend_stars_set does: copied, drawn as small quads. vgl ships no stars. Fails with
123 // invalid_argument for an invalid star or more than VGL_STAR_COUNT_MAX, and out_of_memory.
124 [[nodiscard]] vgl::result stars_set(std::span<const vgl_star> stars) noexcept;
125
126 // Sets the clouds the globe draws with VGL_DRAW_FEATURE_CLOUDS, as
127 // vgl_gl_backend_clouds_set does: a coverage image of the whole globe, copied with its mip
128 // levels; null with width and height 0 removes them. Fails with invalid_argument for a size
129 // outside the limits of vgl/render.h (VGL_CLOUD_IMAGE_*), and out_of_memory.
130 [[nodiscard]] vgl::result
131 clouds_set(const std::uint8_t* coverage, std::uint32_t width, std::uint32_t height) noexcept;
132
133 // Forgets the globe's Ogre objects and the context's render resources, which are uploaded
134 // again over the next frames: after Ogre's render system lost its device, and the like, as
135 // the C backends' device_reset does.
136 void device_reset() noexcept;
137
138 // Ogre::MovableObject
139 [[nodiscard]] const Ogre::String& getMovableType() const override;
140 [[nodiscard]] const Ogre::AxisAlignedBox& getBoundingBox() const override;
141 [[nodiscard]] Ogre::Real getBoundingRadius() const override;
142 void _updateRenderQueue(Ogre::RenderQueue* queue) override;
143 void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debug_renderables) override;
144
145 globe(const globe&) = delete;
146 globe& operator=(const globe&) = delete;
147 globe(globe&&) = delete;
148 globe& operator=(globe&&) = delete;
149
150 struct state;
151
152private:
153 explicit globe(const Ogre::String& name, state* s) noexcept;
154 ~globe() override;
155
156 state* state_;
157};
158
159} // namespace vgl::ogre
160
161#endif // VGL_OGRE_HPP
Definition context.hpp:106
Definition base.hpp:87
Definition ogre.hpp:99
const Ogre::String & getMovableType() const override
vgl::result clouds_set(const std::uint8_t *coverage, std::uint32_t width, std::uint32_t height) noexcept
vgl::result settings_set(const globe_settings &settings) noexcept
void _updateRenderQueue(Ogre::RenderQueue *queue) override
void device_reset() noexcept
static vgl::expected< globe * > create(vgl_context *context, const globe_create_info &info) noexcept
vgl::result stars_set(std::span< const vgl_star > stars) noexcept
static void destroy(globe *g) noexcept
const Ogre::AxisAlignedBox & getBoundingBox() const override
void visitRenderables(Ogre::Renderable::Visitor *visitor, bool debug_renderables) override
static vgl::expected< globe * > create(vgl::context &context, const globe_create_info &info) noexcept
Ogre::Real getBoundingRadius() const override
struct vgl_context vgl_context
Definition context.h:23
Definition ogre.hpp:54
depth_convention
Definition render.hpp:22
result
Definition base.hpp:25
uint32_t vgl_draw_features
Definition render.h:480
vgl_depth_convention
Definition render.h:105
@ VGL_DEPTH_CONVENTION_LOGARITHMIC
Definition render.h:112
uint32_t vgl_debug_views
Definition render.h:516
Definition ogre.hpp:58
Ogre::String name
Definition ogre.hpp:65
Ogre::String resource_group
Definition ogre.hpp:63
Definition ogre.hpp:70
double contour_interval
Definition ogre.hpp:92
std::uint64_t upload_budget
Definition ogre.hpp:82
vgl_dmat4 view_matrix
Definition ogre.hpp:74
double logarithmic_far
Definition ogre.hpp:80
vgl_debug_views debug_views
Definition ogre.hpp:88
vgl_draw_features features
Definition ogre.hpp:86
double cloud_height
Definition ogre.hpp:95
double earth_rotation_angle
Definition ogre.hpp:90
bool has_view_matrix
Definition ogre.hpp:73
vgl_dvec3 sun_direction
Definition ogre.hpp:77
Definition base.h:88
Definition base.h:69