vgl
1.0.0
Virtual Globe Library: API reference
Loading...
Searching...
No Matches
gl.h
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: MIT
3
* Copyright (c) 2026 Jeremiah van Oosten
4
*
5
* vgl OpenGL backend: draws a context's globe with OpenGL 3.3 or OpenGL ES 3.0, into the
6
* host's framebuffer (design document, section 7.6). It is a consumer of the render interface
7
* (vgl/render.h), linked separately as vgl_gl, and uses vgl only through the C API.
8
*
9
* The host creates the OpenGL context, makes it current and passes a function loader; the
10
* backend never touches EGL, WGL or GLX. A minimal host, with GLFW:
11
*
12
* static vgl_gl_proc load(void* user_data, const char* name)
13
* {
14
* (void)user_data;
15
* return (vgl_gl_proc)glfwGetProcAddress(name);
16
* }
17
*
18
* vgl_gl_backend_create_info info = {.struct_size = sizeof(info)};
19
* info.get_proc_address = load;
20
* vgl_gl_backend* backend;
21
* vgl_gl_backend_create(context, &info, &backend);
22
*
23
* // Each frame, in the host's render pass, after vgl_context_update:
24
* vgl_gl_backend_draw(backend, NULL);
25
*
26
* vgl_gl_backend_destroy(backend); // Before the context and the OpenGL context.
27
*
28
* State (NFR-08). The backend saves the following state when it draws, and restores it before
29
* returning: the current program, the vertex array binding, the GL_ARRAY_BUFFER,
30
* GL_COPY_WRITE_BUFFER and GL_PIXEL_UNPACK_BUFFER bindings, the active texture unit, the 2D
31
* texture and sampler bindings of units 0 to 5, the unpack alignment, row length and skips,
32
* GL_DEPTH_TEST, the depth function and write mask, GL_CULL_FACE, the cull face mode, the front
33
* face, GL_BLEND, the blend functions and equations, primitive restart (where it exists) and,
34
* for the reversed-Z convention, the clip control depth mode. It draws with the
35
* host's framebuffer, viewport, scissor, depth range, color and stencil state unchanged, so a
36
* stencil test or color mask the host leaves enabled applies to the globe as well.
37
*/
38
#ifndef VGL_GL_H
39
#define VGL_GL_H
40
41
#include <
vgl/base.h
>
42
#include <
vgl/context.h
>
43
#include <
vgl/render.h
>
44
45
/* Symbol visibility of the backend library, which is shared when vgl is. */
46
#if defined(VGL_SHARED)
47
# if defined(_WIN32)
48
# if defined(VGL_GL_BUILDING)
49
# define VGL_GL_API __declspec(dllexport)
50
# else
51
# define VGL_GL_API __declspec(dllimport)
52
# endif
53
# else
54
# define VGL_GL_API __attribute__((visibility("default")))
55
# endif
56
#else
57
# define VGL_GL_API
58
#endif
59
60
#ifdef __cplusplus
61
extern
"C"
{
62
#endif
63
65
typedef
void (*
vgl_gl_proc
)(void);
66
78
typedef
vgl_gl_proc
(*
vgl_gl_get_proc_address_fn
)(
void
* user_data,
const
char
* name);
79
80
typedef
struct
vgl_gl_backend
vgl_gl_backend
;
81
83
typedef
struct
vgl_gl_backend_create_info
84
{
85
uint32_t
struct_size
;
89
vgl_depth_convention
depth_convention
;
91
vgl_gl_get_proc_address_fn
get_proc_address
;
92
VGL_POINTER_PADDING
(get_proc_address_padding)
93
void*
get_proc_address_user_data
;
94
VGL_POINTER_PADDING
(get_proc_address_user_data_padding)
95
}
vgl_gl_backend_create_info
;
96
124
VGL_GL_API
vgl_result
vgl_gl_backend_create
(
vgl_context
* context,
125
const
vgl_gl_backend_create_info
* info,
126
vgl_gl_backend
** out_backend);
127
140
VGL_GL_API
vgl_result
vgl_gl_backend_destroy
(
vgl_gl_backend
* backend);
141
143
typedef struct
vgl_gl_draw_info
144
{
145
uint32_t
struct_size
;
149
vgl_bool
mirrored
;
152
const
vgl_dmat4
*
view_matrix
;
153
VGL_POINTER_PADDING
(view_matrix_padding)
158
const
vgl_dmat4
* projection_matrix;
159
VGL_POINTER_PADDING
(projection_matrix_padding)
162
vgl_dvec3
sun_direction;
165
double
logarithmic_far;
168
uint64_t upload_budget;
171
vgl_draw_features
features;
174
vgl_debug_views
debug_views;
177
double
earth_rotation_angle;
180
double
contour_interval;
183
double
cloud_height;
184
}
vgl_gl_draw_info
;
185
212
VGL_GL_API
vgl_result
vgl_gl_backend_draw
(
vgl_gl_backend
* backend, const
vgl_gl_draw_info
* info);
213
235
VGL_GL_API
vgl_result
vgl_gl_backend_stars_set
(
vgl_gl_backend
* backend,
236
const
vgl_star
* stars,
237
uint32_t star_count);
238
263
VGL_GL_API
vgl_result
vgl_gl_backend_clouds_set
(
vgl_gl_backend
* backend,
264
const uint8_t* coverage,
265
uint32_t width,
266
uint32_t height);
267
286
VGL_GL_API
vgl_result
vgl_gl_backend_device_reset
(
vgl_gl_backend
* backend);
287
288
#ifdef __cplusplus
289
}
290
#endif
291
292
#endif
/* VGL_GL_H */
base.h
vgl_result
vgl_result
Definition
base.h:98
vgl_bool
uint32_t vgl_bool
Definition
base.h:56
VGL_POINTER_PADDING
#define VGL_POINTER_PADDING(name)
Definition
base.h:46
context.h
vgl_context
struct vgl_context vgl_context
Definition
context.h:23
vgl_gl_backend_clouds_set
vgl_result vgl_gl_backend_clouds_set(vgl_gl_backend *backend, const uint8_t *coverage, uint32_t width, uint32_t height)
vgl_gl_backend_draw
vgl_result vgl_gl_backend_draw(vgl_gl_backend *backend, const vgl_gl_draw_info *info)
vgl_gl_backend
struct vgl_gl_backend vgl_gl_backend
Definition
gl.h:80
vgl_gl_backend_destroy
vgl_result vgl_gl_backend_destroy(vgl_gl_backend *backend)
vgl_gl_backend_create
vgl_result vgl_gl_backend_create(vgl_context *context, const vgl_gl_backend_create_info *info, vgl_gl_backend **out_backend)
vgl_gl_backend_device_reset
vgl_result vgl_gl_backend_device_reset(vgl_gl_backend *backend)
VGL_GL_API
#define VGL_GL_API
Definition
gl.h:57
vgl_gl_get_proc_address_fn
vgl_gl_proc(* vgl_gl_get_proc_address_fn)(void *user_data, const char *name)
Definition
gl.h:78
vgl_gl_backend_stars_set
vgl_result vgl_gl_backend_stars_set(vgl_gl_backend *backend, const vgl_star *stars, uint32_t star_count)
vgl_gl_proc
void(* vgl_gl_proc)(void)
Definition
gl.h:65
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_debug_views
uint32_t vgl_debug_views
Definition
render.h:516
vgl_dmat4
Definition
base.h:88
vgl_dvec3
Definition
base.h:69
vgl_gl_backend_create_info
Definition
gl.h:84
vgl_gl_backend_create_info::struct_size
uint32_t struct_size
Definition
gl.h:85
vgl_gl_backend_create_info::get_proc_address
vgl_gl_get_proc_address_fn get_proc_address
Definition
gl.h:91
vgl_gl_backend_create_info::get_proc_address_user_data
void * get_proc_address_user_data
Definition
gl.h:93
vgl_gl_backend_create_info::depth_convention
vgl_depth_convention depth_convention
Definition
gl.h:89
vgl_gl_draw_info
Definition
gl.h:144
vgl_gl_draw_info::struct_size
uint32_t struct_size
Definition
gl.h:145
vgl_gl_draw_info::mirrored
vgl_bool mirrored
Definition
gl.h:149
vgl_gl_draw_info::view_matrix
const vgl_dmat4 * view_matrix
Definition
gl.h:152
vgl_star
Definition
render.h:53
vgl
gl.h
Generated by
1.9.8