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
53
namespace
vgl::ogre
54
{
55
56
// Creation parameters of a globe.
57
struct
globe_create_info
58
{
59
// How depth is written and compared (vgl/render.h).
60
vgl_depth_convention
depth_convention
=
VGL_DEPTH_CONVENTION_LOGARITHMIC
;
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.
69
struct
globe_settings
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
;
74
vgl_dmat4
view_matrix
{};
75
// Direction towards the sun, along the ECEF axes; it need not be normalized. Zero lights the
76
// terrain from the camera.
77
vgl_dvec3
sun_direction
{};
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.
86
vgl_draw_features
features
= 0;
87
// Views for inspecting level of detail and loading: vgl_debug_view values (vgl/render.h).
88
vgl_debug_views
debug_views
= 0;
89
// The Earth rotation angle in radians (vgl_earth_rotation_angle_get), for the stars.
90
double
earth_rotation_angle
= 0.0;
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
98
class
globe
final :
public
Ogre::MovableObject
99
{
100
public
:
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.
107
[[nodiscard]]
static
vgl::expected<globe*>
create
(
vgl::context
&
context
,
108
const
globe_create_info
&
info
)
noexcept
;
109
[[nodiscard]]
static
vgl::expected<globe*>
create
(
vgl_context
*
context
,
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
152
private:
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
base.hpp
vgl::context
Definition
context.hpp:106
vgl::expected
Definition
base.hpp:87
vgl::ogre::globe
Definition
ogre.hpp:99
vgl::ogre::globe::getMovableType
const Ogre::String & getMovableType() const override
vgl::ogre::globe::clouds_set
vgl::result clouds_set(const std::uint8_t *coverage, std::uint32_t width, std::uint32_t height) noexcept
vgl::ogre::globe::settings_set
vgl::result settings_set(const globe_settings &settings) noexcept
vgl::ogre::globe::_updateRenderQueue
void _updateRenderQueue(Ogre::RenderQueue *queue) override
vgl::ogre::globe::device_reset
void device_reset() noexcept
vgl::ogre::globe::create
static vgl::expected< globe * > create(vgl_context *context, const globe_create_info &info) noexcept
vgl::ogre::globe::stars_set
vgl::result stars_set(std::span< const vgl_star > stars) noexcept
vgl::ogre::globe::destroy
static void destroy(globe *g) noexcept
vgl::ogre::globe::getBoundingBox
const Ogre::AxisAlignedBox & getBoundingBox() const override
vgl::ogre::globe::visitRenderables
void visitRenderables(Ogre::Renderable::Visitor *visitor, bool debug_renderables) override
vgl::ogre::globe::create
static vgl::expected< globe * > create(vgl::context &context, const globe_create_info &info) noexcept
vgl::ogre::globe::getBoundingRadius
Ogre::Real getBoundingRadius() const override
context.h
vgl_context
struct vgl_context vgl_context
Definition
context.h:23
context.hpp
vgl::ogre
Definition
ogre.hpp:54
vgl::depth_convention
depth_convention
Definition
render.hpp:22
vgl::log_level::info
@ info
vgl::result
result
Definition
base.hpp:25
render.h
vgl_draw_features
uint32_t vgl_draw_features
Definition
render.h:480
vgl_depth_convention
vgl_depth_convention
Definition
render.h:105
VGL_DEPTH_CONVENTION_LOGARITHMIC
@ VGL_DEPTH_CONVENTION_LOGARITHMIC
Definition
render.h:112
vgl_debug_views
uint32_t vgl_debug_views
Definition
render.h:516
vgl::ogre::globe_create_info
Definition
ogre.hpp:58
vgl::ogre::globe_create_info::name
Ogre::String name
Definition
ogre.hpp:65
vgl::ogre::globe_create_info::resource_group
Ogre::String resource_group
Definition
ogre.hpp:63
vgl::ogre::globe_settings
Definition
ogre.hpp:70
vgl::ogre::globe_settings::contour_interval
double contour_interval
Definition
ogre.hpp:92
vgl::ogre::globe_settings::upload_budget
std::uint64_t upload_budget
Definition
ogre.hpp:82
vgl::ogre::globe_settings::view_matrix
vgl_dmat4 view_matrix
Definition
ogre.hpp:74
vgl::ogre::globe_settings::logarithmic_far
double logarithmic_far
Definition
ogre.hpp:80
vgl::ogre::globe_settings::debug_views
vgl_debug_views debug_views
Definition
ogre.hpp:88
vgl::ogre::globe_settings::features
vgl_draw_features features
Definition
ogre.hpp:86
vgl::ogre::globe_settings::cloud_height
double cloud_height
Definition
ogre.hpp:95
vgl::ogre::globe_settings::earth_rotation_angle
double earth_rotation_angle
Definition
ogre.hpp:90
vgl::ogre::globe_settings::has_view_matrix
bool has_view_matrix
Definition
ogre.hpp:73
vgl::ogre::globe_settings::sun_direction
vgl_dvec3 sun_direction
Definition
ogre.hpp:77
vgl_dmat4
Definition
base.h:88
vgl_dvec3
Definition
base.h:69
vgl
ogre.hpp
Generated by
1.9.8