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
61extern "C" {
62#endif
63
65typedef void (*vgl_gl_proc)(void);
66
78typedef vgl_gl_proc (*vgl_gl_get_proc_address_fn)(void* user_data, const char* name);
79
81
96
125 const vgl_gl_backend_create_info* info,
126 vgl_gl_backend** out_backend);
127
141
143typedef struct vgl_gl_draw_info
144{
145 uint32_t struct_size;
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;
174 vgl_debug_views debug_views;
177 double earth_rotation_angle;
180 double contour_interval;
183 double cloud_height;
185
213
236 const vgl_star* stars,
237 uint32_t star_count);
238
264 const uint8_t* coverage,
265 uint32_t width,
266 uint32_t height);
267
287
288#ifdef __cplusplus
289}
290#endif
291
292#endif /* VGL_GL_H */
vgl_result
Definition base.h:98
uint32_t vgl_bool
Definition base.h:56
#define VGL_POINTER_PADDING(name)
Definition base.h:46
struct vgl_context vgl_context
Definition context.h:23
vgl_result vgl_gl_backend_clouds_set(vgl_gl_backend *backend, const uint8_t *coverage, uint32_t width, uint32_t height)
vgl_result vgl_gl_backend_draw(vgl_gl_backend *backend, const vgl_gl_draw_info *info)
struct vgl_gl_backend vgl_gl_backend
Definition gl.h:80
vgl_result vgl_gl_backend_destroy(vgl_gl_backend *backend)
vgl_result vgl_gl_backend_create(vgl_context *context, const vgl_gl_backend_create_info *info, vgl_gl_backend **out_backend)
vgl_result vgl_gl_backend_device_reset(vgl_gl_backend *backend)
#define VGL_GL_API
Definition gl.h:57
vgl_gl_proc(* vgl_gl_get_proc_address_fn)(void *user_data, const char *name)
Definition gl.h:78
vgl_result vgl_gl_backend_stars_set(vgl_gl_backend *backend, const vgl_star *stars, uint32_t star_count)
void(* vgl_gl_proc)(void)
Definition gl.h:65
uint32_t vgl_draw_features
Definition render.h:480
vgl_depth_convention
Definition render.h:105
uint32_t vgl_debug_views
Definition render.h:516
Definition base.h:88
Definition base.h:69
Definition gl.h:84
uint32_t struct_size
Definition gl.h:85
vgl_gl_get_proc_address_fn get_proc_address
Definition gl.h:91
void * get_proc_address_user_data
Definition gl.h:93
vgl_depth_convention depth_convention
Definition gl.h:89
Definition gl.h:144
uint32_t struct_size
Definition gl.h:145
vgl_bool mirrored
Definition gl.h:149
const vgl_dmat4 * view_matrix
Definition gl.h:152
Definition render.h:53