Browse code

Add implementation

Robert Cranston authored on 14/10/2022 20:41:19
Showing 1 changed files
... ...
@@ -2,10 +2,518 @@
2 2
 
3 3
 A [C++11][]/[OpenGL][]>=[1.0][] basics library.
4 4
 
5
+This library wraps up some common basic OpenGL functionality for convenience,
6
+including checking for supported OpenGL [version][]s and [extension][]s, basic
7
+image loading and saving, debugging helpers, error checking, and string
8
+helpers.
9
+
5 10
 [`glbase`]: https://git.rcrnstn.net/rcrnstn/glbase
6 11
 [C++11]: https://en.wikipedia.org/wiki/C++11
7 12
 [OpenGL]: https://en.wikipedia.org/wiki/OpenGL
8 13
 [1.0]: https://en.wikipedia.org/wiki/OpenGL#Version_history
14
+[version]: https://en.wikipedia.org/wiki/OpenGL#Version_history
15
+[extension]: https://www.khronos.org/opengl/wiki/OpenGL_Extension
16
+
17
+## Usage
18
+
19
+### OpenGL loading library
20
+
21
+This library can be used with an arbitrary [OpenGL loading library][] by making
22
+sure `GLBASE_INCLUDE` is defined to the file to `#include`, e.g.
23
+`<glad/glad.h>` (either in the source or through a compiler switch, probably
24
+defined in the build system). Note that double quotes or angle brackets are
25
+required. The default if none is defined is `<GL/glew.h>`.
26
+
27
+If [CMake][] is used for building (see [Building][]), the `GLBASE_INCLUDE`
28
+CMake variable can be set to tell `glbase` to not use the default [GLEW][], and
29
+to set the corresponding define. In this case, the CMake variables
30
+`GLBASE_PACKAGES` and `GLBASE_TARGETS` can be used to set the packages and
31
+targets respectively to use for OpenGL and the loading library (either or both
32
+can be empty).
33
+
34
+[OpenGL loading library]: https://www.khronos.org/opengl/wiki/OpenGL_Loading_Library
35
+[CMake]: https://cmake.org
36
+[Building]: #building
37
+[GLEW]: https://glew.sourceforge.net
38
+
39
+### Thread safety
40
+
41
+"Global" state (usually used to mirror some OpenGL [context][] internal state
42
+for performance) is declared [`thread_local`][] and initialized lazily. This
43
+means that a given thread may create at most one OpenGL context, and the
44
+`GLBase`-derived objects created while that context is current may be used only
45
+from that thread. Driver vendors recommend to not share OpenGL contexts between
46
+threads, for performance.
47
+
48
+The underlying mechanism used to retrieve system error messages may be thread
49
+unsafe. (`GLBase`-derived classes are encouraged to use
50
+`std::generic_category().message(errno)`, which often is, but is not required
51
+to be, thread safe, instead of [`std::strerror`][]`(errno)`, which is thread
52
+unsafe on most platforms).
53
+
54
+[context]: https://www.khronos.org/opengl/wiki/OpenGL_Context
55
+[`thread_local`]: https://en.cppreference.com/w/cpp/keyword/thread_local
56
+[`std::strerror`]: https://en.cppreference.com/w/cpp/string/byte/strerror
57
+
58
+### Conventions
59
+
60
+The following table summarizes the [naming convention][] used.
61
+
62
+| Category | Capitalization | Public | Protected  | Private    |
63
+| -------- | -------------- | ------ | ---------- | ---------- |
64
+| Type     | `PascalCase`   |        | `_` suffix | `_` suffix |
65
+| Function | `snake_case`   |        | `_` suffix | `_` suffix |
66
+| Variable | `snake_case`   | (none) | (none)     | `_` suffix |
67
+| Macro    | `MACRO_CASE`   | (few)  |            | `_` suffix |
68
+
69
+"Private" in this case includes things with [internal linkage][]. The [storage
70
+duration][] or whether members are bound to class instances or not does not
71
+affect naming. Parameters (including template parameters) are considered public
72
+even though their use obviously is constrained to a scope inaccessible to the
73
+outside user.
74
+
75
+As can be seen in the table, class member variables are always private and
76
+(either public or protected) access is provided by [Accessors][].
77
+`GLBase`-derived classes should prefer to use their own protected member
78
+functions over their private member variables.
79
+
80
+[naming convention]: https://en.wikipedia.org/wiki/Naming_convention_(programming)
81
+[internal linkage]: https://en.cppreference.com/w/cpp/language/storage_duration#internal_linkage
82
+[storage duration]: https://en.cppreference.com/w/cpp/language/storage_duration#storage_duration
83
+[Accessors]: #accessors
84
+
85
+### Size
86
+
87
+`GLBase` is an [empty][] class and the [empty base optimization][] applies.
88
+
89
+[empty]: https://en.cppreference.com/w/cpp/types/is_empty
90
+[empty base optimization]: https://en.cppreference.com/w/cpp/language/ebo
91
+
92
+### Special member functions
93
+
94
+Both the constructor and the destructor are [`protected`][]. End users should
95
+use a `GLBase`-derived class to instantiate objects.
96
+
97
+Note that the destructor is not [`virtual`][]. `GLBase`-derived objects must
98
+not be destroyed through `GLBase` pointers.
99
+
100
+[`protected`]: https://en.cppreference.com/w/cpp/keyword/protected
101
+[`virtual`]: https://en.cppreference.com/w/cpp/language/virtual
102
+
103
+### Accessors
104
+
105
+Getter and setter functions share the same name and use function overloading to
106
+disambiguate. Getters (which can be run on `const` objects) take no argument
107
+and return the value (by `const` reference). Setters take a [forwarding
108
+reference][] argument and return the old value (by value, after move).
109
+
110
+Macros that aid in the implementation of (potentially "global" static thread
111
+local) getters and setters are defined. These should be used in the class
112
+definition. They define functions named `NAME`, which operate on a variable
113
+named `NAME##_`. The underlying variable is not declared automatically, this
114
+must be done manually (probably [`private`][]). The `ACCESS` variant defines
115
+both `GET` and `SET`.
116
+
117
+`GLBASE_{GET,SET,ACCESS}{,_GLOBAL}(TYPE, NAME)`
118
+
119
+Additionally, "global" static thread local member variables need to be defined
120
+in exactly one [translation unit][]. A macro to help with this is defined as
121
+well. Note that, since the definition is outside the class definition, the
122
+`NAME` needs to be qualified with the class name.
123
+
124
+`GLBASE_GLOBAL(NAME, INIT)`
125
+
126
+[forwarding reference]: https://en.cppreference.com/w/cpp/language/reference#Forwarding_references
127
+[`private`]: https://en.cppreference.com/w/cpp/keyword/private
128
+[translation unit]: https://en.wikipedia.org/wiki/Translation_unit_(programming)
129
+
130
+### Base
131
+
132
+`Version` is an alias for `std::array<GLint, 2>`.
133
+
134
+`bool static supported(Version version_min, std::string const & extension =
135
+{})` returns `true` if the current OpenGL [context][] implements the given, or
136
+a later (but see `version_max(...)` below), version or the given extension. If
137
+no version check is desired, provide `{}` (or, equivalently, `{0, 0}`). If no
138
+extension check is desired, provide an empty extension string (the default). If
139
+a non-empty `extension` is provided, it must start with `"GL_"`. If no check at
140
+all is performed, `false` is returned. Being able to check for both version and
141
+extension is convenient because extensions are often absorbed into newer
142
+versions of the OpenGL specification itself, and some platforms stop reporting
143
+support for the extension for those versions, so only checking if the extension
144
+is available fails. [History of OpenGL][] has a list of which versions of
145
+OpenGL absorbed which extensions. Since this library is agnostic to the used
146
+[OpenGL loading library][] (which is usually used to perform these kind of
147
+checks), the OpenGL API itself is queried. A new method of determining
148
+supported extensions was introduced in OpenGL [3.0][] and the old method
149
+deprecated and removed in OpenGL [3.1][]. This function uses the method
150
+appropriate for the current OpenGL [context][]. Note that no other checks are
151
+performed, including checks for a compatibility [profile][] [context][] or
152
+support for the [`ARB_compatibility`][] extension.
153
+
154
+`Version version_max({Version version_max})` gets/sets the maximum version for
155
+which `supported(...)` described above will return `true`. To disable this
156
+functionality, provide `{}` (or, equivalently, `{0, 0}`), which is the default
157
+value. Setting it to any other value also disables extension checking in
158
+`supported(...)`. This is useful for testing fallback code paths, regardless of
159
+the version present on a development machine (many platforms will provide a
160
+[context][] with a version higher than the one requested).
161
+
162
+`char const * static string(GLenum name)` and `char const * static
163
+string(GLenum name, GLuint index)` call [`glGetString`][] and
164
+[`glGetStringi`][] respectively with the given arguments and return the result,
165
+which obviates the need to cast the result (the OpenGL functions return
166
+`GLubyte const *`).
167
+
168
+`GLint static integer(GLenum name)` calls [`glGetIntegerv`][] with the given
169
+argument and returns the result, which obviates the need to declare a variable
170
+beforehand. Make sure to only use values of `name` that get a single integer.
171
+
172
+[History of OpenGL]: https://www.khronos.org/opengl/wiki/History_of_OpenGL
173
+[`glGetIntegerv`]: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGet.xhtml
174
+[`glGetString`]: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetString.xhtml
175
+[`glGetStringi`]: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetString.xhtml
176
+[3.0]: https://en.wikipedia.org/wiki/OpenGL#Version_history
177
+[3.1]: https://en.wikipedia.org/wiki/OpenGL#Version_history
178
+[profile]: https://www.khronos.org/opengl/wiki/OpenGL_Context#OpenGL_3.2_and_Profiles
179
+[`ARB_compatibility`]: https://registry.khronos.org/OpenGL/extensions/ARB/ARB_compatibility.txt
180
+
181
+### Path
182
+
183
+`Path` is an alias for `std::string`.
184
+
185
+`Paths` is an alias for `std::vector<Path>`.
186
+
187
+`Path static path_prefix_(Path const & path, Path const & prefix)` returns
188
+`prefix` prepended to `path`, separated with a `/`, unless either
189
+
190
+1.  `prefix` is empty
191
+2.  `path` starts with a `/`
192
+
193
+in which case `path` is returned as is.
194
+
195
+### TGA
196
+
197
+A nested `GLBase::TGA_` class is provided to handle [Truevision TGA][] images
198
+in left-to-right, bottom-to-top, uncompressed [BGRA][] format. TGA was selected
199
+because it is widely supported and has a trivial header and data layout. It is
200
+also convenient because it has a pixel ordering compatible with the default
201
+[pixel transfer parameters][] and `GL_BGRA` is often preferred by graphics
202
+cards.
203
+
204
+`GLBase::TGA_` contains the following `static constexpr` member variables.
205
+
206
+-   `char const name[]`: `"TGA"`
207
+-   `GLint columns`: `1`
208
+-   `GLint rows`: `4`
209
+-   `GLenum glsl`: `GL_FLOAT_VEC4`
210
+-   `GLenum format`: `GL_BGRA`
211
+-   `GLenum type`: `GL_UNSIGNED_BYTE`
212
+-   `GLenum internal_format`: `GL_RGBA8`
213
+-   `GLenum internal_format_srgb`: `GL_SRGB8_ALPHA8`
214
+-   `GLenum internal_format_compressed`: `GL_COMPRESSED_RGBA`
215
+-   `GLenum internal_format_compressed_srgb`: `GL_COMPRESSED_SRGB_ALPHA`
216
+-   `GLenum id`: `glsl`
217
+
218
+(These are the same `static constexpr` member variables defined by
219
+[`GLTraits::Value`][].)
220
+
221
+`GLBase::TGA_` contains the following type definitions.
222
+
223
+-   `Size`. An alias for `std::array<GLsizei, 2>`.
224
+-   `Data`. An alias for `std::vector<GLubyte>`.
225
+
226
+`GLBase::TGA_` contains the following member functions.
227
+
228
+-   `explicit TGA_(Size size, Data data, Path const & path = {})`. Instantiates
229
+    a `TGA_` object with the given `size` and `data`. `path`, if given, is only
230
+    used for error reporting.
231
+-   `TGA_ static read(std::string const & path)`. Reads the file `path` into a
232
+    `TGA_` object.
233
+-   `void write(std::string const & path) const`. Writes the `TGA_` object to
234
+    the file `path`.
235
+-   `Size size() const`. Gets the size of the TGA image.
236
+-   `Data const & data() const`. Gets the data of the TGA image.
237
+
238
+[Truevision TGA]: https://en.wikipedia.org/wiki/Truevision_TGA
239
+[BGRA]: https://en.wikipedia.org/wiki/RGBA_color_model
240
+[pixel transfer parameters]: https://www.khronos.org/opengl/wiki/Pixel_Transfer#Pixel_transfer_parameters
241
+[`GLTraits::Value`]: https://git.rcrnstn.net/rcrnstn/gltraits/#value
242
+[GLSL]: https://www.khronos.org/opengl/wiki/OpenGL_Shading_Language
243
+
244
+### Exceptions
245
+
246
+All exceptions thrown are of the type `GLBase::Exception`, which inherits from
247
+[`std::runtime_error`][].
248
+
249
+[`std::runtime_error`]: https://en.cppreference.com/w/cpp/error/runtime_error
250
+
251
+### Debug
252
+
253
+A dynamic debug facility is used instead of asserts mainly because it allows
254
+dynamic error messages and it is often desirable to turn on debugging only
255
+during a problematic part of an application run.
256
+
257
+`DebugCallback` is an alias for [`std::function`][]`<void (std::string const &
258
+message)>`. These functions may not [`throw`][] since they are called by
259
+OpenGL, which may not support throwing exceptions across its stack frames.
260
+
261
+`int static debug({int debug})` gets/sets the global debug level. When `>= 1`,
262
+potentially costly debug operations are performed as part of other operations.
263
+When `>= 2` notifications may be emitted. Defaults to `0`.
264
+
265
+`DebugCallback static debug_callback({DebugCallback debug_callback})` gets/sets
266
+a callback that may be called by `GLBase`-derived classes (typically through
267
+`debug_message(...)`, see below). Defaults to a function which outputs the
268
+`mesage` argument to [`std::cerr`][], appends a newline and flushes.
269
+
270
+`void static debug_message(std::string const & message)` calls the callback
271
+registered with `debug_callback(...)` with `message` as argument if the
272
+callback is not empty (i.e. set to `nullptr`).
273
+
274
+`void static debug_action_(std::string const & action, std::string const &
275
+name)` calls `debug_message(...)` with a string containing `action` and `name`.
276
+
277
+[`std::function`]: https://en.cppreference.com/w/cpp/utility/functional/function
278
+[`throw`]: https://en.cppreference.com/w/cpp/language/throw
279
+[`std::cerr`]: https://en.cppreference.com/w/cpp/io/cerr
280
+
281
+### Check
282
+
283
+These functions throw an exception if some condition does not hold. It is
284
+recommended that `GLBase`-derived classes use similar helper functions, defined
285
+in an implementation file, to hide the string processing necessary to form a
286
+helpful exception message.
287
+
288
+`GLBase`-derived classes should treat error checking as free during
289
+construction and expensive data transfer operations. At all other times,
290
+non-critical error checking should only be performed if `debug() >= 1`.
291
+
292
+`void static check_supported(Version version_min, std::string const & extension
293
+= {})` checks that `supported(...)` returns `true` for the given arguments.
294
+
295
+`void static check_path_(std::string const & path)` checks that `path` is
296
+non-empty.
297
+
298
+`void static check_error_(GLenum error)` checks an error returned by
299
+[`glGetError`][].
300
+
301
+`void static check_type_(GLenum type, GLenum type_expected)` checks that `type`
302
+matches `type_expected`.
303
+
304
+`void static check_format_(GLenum format, GLenum format_expected)` checks that
305
+`format` matches `format_expected`.
306
+
307
+`void static check_internal_format_(GLenum internal_format)` checks that
308
+`internal_format` is supported.
309
+
310
+[`glGetError`]: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetError.xhtml
311
+
312
+### Fail
313
+
314
+These functions throw an exception and should be marked [`[[noreturn]]`][]. It
315
+is recommended that `GLBase`-derived classes use similar helper functions,
316
+defined in an implementation file, to hide the string processing necessary to
317
+form a helpful exception message.
318
+
319
+`[[noreturn]] void static fail_action_(std::string const & action, std::string
320
+const & name)` calls [`std::terminate`][] if called outside a [`catch`][]
321
+block. Otherwise, throws an exception with a message that includes `action` and
322
+`name` followed by `":\n"` and the [`what()`][] of the current exception if it
323
+is a (derives from) [`std::exception`][], otherwise simply rethrows the current
324
+exception.
325
+
326
+[`[[noreturn]]`]: https://en.cppreference.com/w/cpp/language/attributes/noreturn
327
+[`std::terminate`]: https://en.cppreference.com/w/cpp/error/terminate
328
+[`catch`]: https://en.cppreference.com/w/cpp/language/try_catch
329
+[`what()`]: https://en.cppreference.com/w/cpp/error/exception/what
330
+[`std::exception`]: https://en.cppreference.com/w/cpp/error/exception
331
+
332
+### String
333
+
334
+`std::string static str_path_(Path const & path)` returns `path` surrounded by
335
+double quotes.
336
+
337
+`std::string static str_paths_(Paths const & paths)` returns `paths` surrounded
338
+by double quotes and joined with commas.
339
+
340
+`std::string static str_enum_(GLenum name)` returns the hexadecimal string
341
+representation of `name` (often used as fallback).
342
+
343
+`std::string static str_error_(GLenum error)` returns the string representation
344
+of values returned by [`glGetError`][].
345
+
346
+`std::string static str_object_type_(GLenum object_type)` returns the string
347
+representation of `object_type`.
348
+
349
+`std::string static str_glsl_(GLenum glsl)` returns the string representation
350
+of `glsl`.
351
+
352
+`std::string static str_format_(GLenum format)` returns the string
353
+representation of `format`.
354
+
355
+`std::string static str_type_(GLenum type)` returns the string representation
356
+of `type`.
357
+
358
+`std::string static str_internal_format_(GLenum internal_format)` returns the
359
+string representation of `internal_format`.
360
+
361
+## Texture compression formats
362
+
363
+This is here for reference only.
364
+
365
+Extension conventions are defined in [`GL_ARB_texture_compression`][]. Formats
366
+are described in the [Khronons Data Format Specification "Compressed Texture
367
+Image Formats"][] section.
368
+
369
+[Direct3D][] defines `BC*` texture "block" compression formats which
370
+correspond with some of the formats described below. See:
371
+
372
+-   [Direct3D 10 Texture Block Compression][]
373
+-   [Direct3D 11 Texture Block Compression][]
374
+
375
+A non-exhaustive list of compressed texture formats defined by OpenGL:
376
+
377
+-   **S3TC**
378
+    -   Support: Widely supported  since OpenGL 1.3 (2001) (the non-sRGB
379
+        version is considered an "[ubiquitous extension][]"). Not core because
380
+        of patents, which expired 2017. [Mesa][] support since 17.3 (2017).
381
+    -   Origin: Introduced by [S3 Graphics][]' [Savage 3D][] (1998) and
382
+        supported by [Nvidia][]'s more popular [GeForce 256][] (also known
383
+        as the "GeForce 1") (1999). (`DXT2` and `DXT4` are premultiplied alpha
384
+        formats and not supported by OpenGL.)
385
+    -   Formats:
386
+        -   `{RGB{,A},SRGB{,_ALPHA}}_S3TC_DXT1_EXT` (`BC1`). 6:1 compression
387
+            ratio. The alpha variants only have a single bit of alpha, and when
388
+            `A` is `0` RGB must all be `0` as well. Therefore, it is best to
389
+            use premultiplied alpha when using the alpha variants.
390
+        -   `{RGBA,SRGB_ALPHA}_S3TC_DXT3_EXT` (`BC2`). 4:1 compression ratio.
391
+            Stores *uncompressed* alpha separately. Not generally recommended.
392
+        -   `{RGBA,SRGB_ALPHA}_S3TC_DXT5_EXT` (`BC3`). 4:1 compression ratio.
393
+            Stores *compressed* alpha separately.
394
+    -   References:
395
+        -   [`GL_EXT_texture_compression_s3tc`][]
396
+        -   [`GL_EXT_texture_compression_s3tc_srgb`][]
397
+        -   [`GL_EXT_texture_sRGB`][]
398
+        -   [`GL_NV_texture_compression_s3tc`][]
399
+        -   [`GL_S3_s3tc`][]
400
+        -   [OpenGL Wiki][S3TC OpenGL Wiki]
401
+        -   [Wikipedia][S3TC Wikipedia]
402
+-   VTC
403
+    -   Support: Not core. Only supported on Nvidia hardware.
404
+    -   Origin: Extension of S3TC to 3D ("volume") textures.
405
+    -   Formats: The same as S3TC, but interpreted differently for 3D textures.
406
+    -   References:
407
+        -   [`GL_NV_texture_compression_vtc`][]
408
+-   **RGTC**
409
+    -   Support: Core since OpenGL 3.0 (2008).
410
+    -   Origin: Uses a separate S3TC DXT5 alpha encoding for one or two
411
+        component red/green. Published at the same time as LATC.
412
+    -   Formats:
413
+        -   `{,SIGNED_}RED_RGTC1` (`BC4`). 2:1 compression ratio.
414
+        -   `{,SIGNED_}RG_RGTC2` (`BC5`). 2:1 compression ratio.
415
+    -   References:
416
+        -   [`GL_ARB_texture_compression_rgtc`][]
417
+        -   [`GL_EXT_texture_compression_rgtc`][]
418
+        -   [OpenGL Wiki][RGTC OpenGL Wiki]
419
+        -   [Wikipedia][RGTC Wikipedia]
420
+-   LATC:
421
+    -   Support: Not core, no ARB extension. Luminance/alpha formats in general
422
+        have seen a decline since the introduction of the programmable
423
+        pipeline, which can use [swizzle][]s to achieve the same effect.
424
+    -   Origin: Uses a separate S3TC DXT5 alpha encoding for one or two
425
+        component luminance/alpha. Published at the same time as RGTC.
426
+    -   Formats:
427
+        -   `{,SIGNED_}LUMINANCE_LATC1_EXT`. 2:1 compression ratio.
428
+        -   `{,SIGNED_}LUMINANCE_ALPHA_LATC2_EXT`. 2:1 compression ratio.
429
+    -   References
430
+        -   [`GL_EXT_texture_compression_latc`][]
431
+        -   [`GL_NV_texture_compression_latc`][]
432
+-   **BPTC**
433
+    -   Support: Core since OpenGL 4.2 (2011).
434
+    -   Origin: Block Partition texture compression.
435
+    -   Formats:
436
+        -   `RGB_BPTC_{UN,}SIGNED_FLOAT` (`BC6H`): 4:1 compression ratio.
437
+            Unsigned/signed 16-bit ("high dynamic range") float RGB.
438
+        -   `{RGBA,SRGB_ALPHA}_BPTC_UNORM` (`BC7`): 4:1 compression ratio.
439
+            Unsigned normalized integer RGBA/sRGBA.
440
+    -   References:
441
+        -   [`GL_ARB_texture_compression_bptc`][]
442
+        -   [`GL_EXT_texture_compression_bptc`][]
443
+        -   [OpenGL Wiki][BPTC OpenGL Wiki]
444
+        -   [Wikipedia][BPTC Wikipedia]
445
+-   **ETC**
446
+    -   Support: Core since OpenGL 4.3 (2012). Desktop OpenGL does not support
447
+        ETC1, only ETC2. Images encoded as ETC1 can be read by an ETC2 decoder.
448
+    -   Origins: [Ericsson][]. EAC presumably stands for "Ericsson Alpha
449
+        Compression" and is used to compress one or two channels (much like
450
+        RGTC uses the alpha compression format of S3TC DX5).
451
+    -   Formats:
452
+        -   `{,S}RGB8{,_PUNCHTHROUGH_ALPHA1}_ETC2` 6:1 compression ratio.
453
+        -   `{RGBA8,SRGB8_ALPHA8}_ETC2_EAC`. 4:1 compression ratio.
454
+        -   `{,SIGNED_}R11_EAC` 2:1 compression ratio.
455
+        -   `{,SIGNED_}RG11_EAC` 2:1 compression ratio.
456
+    -   References:
457
+        -   [`GL_ARB_ES3_compatibility`][]
458
+        -   [`GL_OES_compressed_ETC1_RGB8_texture`][]
459
+        -   [Wikipedia][ETC Wikipedia]
460
+-   ASTC:
461
+    -   Support: Not core. The extension is written against OpenGL ES, and
462
+        there is no wide desktop support, at least for the HDR version.
463
+    -   Origin: [ARM][] and [AMD][]. Variable block ("adaptive scalable")
464
+        texture compression.
465
+    -   Formats:
466
+        -   `{RGBA,SRGB8_ALPHA8}_ASTC_{4x4,5x{4,5},6x{5,6},8x{5,6,8},10x{5,6,8,10},12x{10,12}}_KHR`
467
+            A large number of variables are encoded per block so e.g. the
468
+            number of channels, dynamic range, and compression ratio vary.
469
+    -   References:
470
+        -   `GL_KHR_texture_compression_astc_ldr`, [`GL_KHR_texture_compression_astc_hdr`][]
471
+        -   [`GL_KHR_texture_compression_astc_sliced_3d`][]
472
+        -   [OpenGL Wiki][ASTC OpenGL Wiki]
473
+        -   [Wikipedia][ASTC Wikipedia]
474
+        -   [`ARM-software/astc-encoder`][]
475
+
476
+[`GL_ARB_texture_compression`]: https://registry.khronos.org/OpenGL/extensions/ARB/ARB_texture_compression.txt
477
+[Khronons Data Format Specification "Compressed Texture Image Formats"]: https://registry.khronos.org/DataFormat/specs/1.1/dataformat.1.1.html#_compressed_texture_image_formats
478
+[Direct3D]: https://en.wikipedia.org/wiki/Direct3D
479
+[Direct3D 10 Texture Block Compression]: https://learn.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression
480
+[Direct3D 11 Texture Block Compression]: https://learn.microsoft.com/en-us/windows/win32/direct3d11/texture-block-compression-in-direct3d-11
481
+[ubiquitous extension]: https://www.khronos.org/opengl/wiki/Ubiquitous_Extension
482
+[Mesa]: https://en.wikipedia.org/wiki/Mesa_(computer_graphics)
483
+[S3 Graphics]: https://en.wikipedia.org/wiki/S3_Graphics
484
+[Savage 3D]: https://en.wikipedia.org/wiki/S3_Savage#Savage_3D
485
+[Nvidia]: https://en.wikipedia.org/wiki/Nvidia
486
+[GeForce 256]: https://en.wikipedia.org/wiki/GeForce_256
487
+[`GL_EXT_texture_compression_s3tc`]: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
488
+[`GL_EXT_texture_compression_s3tc_srgb`]: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc_srgb.txt
489
+[`GL_EXT_texture_sRGB`]: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_sRGB.txt
490
+[`GL_NV_texture_compression_s3tc`]: https://registry.khronos.org/OpenGL/extensions/NV/NV_texture_compression_s3tc.txt
491
+[`GL_S3_s3tc`]: https://registry.khronos.org/OpenGL/extensions/S3/S3_s3tc.txt
492
+[S3TC OpenGL Wiki]: https://www.khronos.org/opengl/wiki/S3_Texture_Compression
493
+[S3TC Wikipedia]: https://en.wikipedia.org/wiki/S3_Texture_Compression
494
+[`GL_NV_texture_compression_vtc`]: https://registry.khronos.org/OpenGL/extensions/NV/NV_texture_compression_vtc.txt
495
+[`GL_ARB_texture_compression_rgtc`]: https://registry.khronos.org/OpenGL/extensions/ARB/ARB_texture_compression_rgtc.txt
496
+[`GL_EXT_texture_compression_rgtc`]: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
497
+[RGTC OpenGL Wiki]: https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression
498
+[RGTC Wikipedia]: https://en.wikipedia.org/wiki/S3_Texture_Compression#BC4_and_BC5
499
+[swizzle]: https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Swizzling
500
+[`GL_EXT_texture_compression_latc`]: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_latc.txt
501
+[`GL_NV_texture_compression_latc`]: https://registry.khronos.org/OpenGL/extensions/NV/NV_texture_compression_latc.txt
502
+[`GL_ARB_texture_compression_bptc`]: https://registry.khronos.org/OpenGL/extensions/ARB/ARB_texture_compression_bptc.txt
503
+[`GL_EXT_texture_compression_bptc`]: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
504
+[BPTC OpenGL Wiki]: https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression
505
+[BPTC Wikipedia]: https://en.wikipedia.org/wiki/S3_Texture_Compression#BC6H_and_BC7
506
+[Ericsson]: https://en.wikipedia.org/wiki/Ericsson
507
+[`GL_ARB_ES3_compatibility`]: https://registry.khronos.org/OpenGL/extensions/ARB/ARB_ES3_compatibility.txt
508
+[`GL_OES_compressed_ETC1_RGB8_texture`]: https://registry.khronos.org/OpenGL/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
509
+[ETC Wikipedia]: https://en.wikipedia.org/wiki/Ericsson_Texture_Compression
510
+[ARM]: https://en.wikipedia.org/wiki/Arm_(company)
511
+[AMD]: https://en.wikipedia.org/wiki/AMD
512
+[`GL_KHR_texture_compression_astc_hdr`]: https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
513
+[`GL_KHR_texture_compression_astc_sliced_3d`]: https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_sliced_3d.txt
514
+[ASTC OpenGL Wiki]: https://www.khronos.org/opengl/wiki/ASTC_Texture_Compression
515
+[ASTC Wikipedia]: https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression
516
+[`ARM-software/astc-encoder`]: https://github.com/ARM-software/astc-encoder
9 517
 
10 518
 ## Building
11 519
 
Browse code

Add project

Robert Cranston authored on 14/10/2022 19:47:51
Showing 1 changed files
... ...
@@ -7,6 +7,12 @@ A [C++11][]/[OpenGL][]>=[1.0][] basics library.
7 7
 [OpenGL]: https://en.wikipedia.org/wiki/OpenGL
8 8
 [1.0]: https://en.wikipedia.org/wiki/OpenGL#Version_history
9 9
 
10
+## Building
11
+
12
+See [`BUILDING.md`][].
13
+
14
+[`BUILDING.md`]: BUILDING.md
15
+
10 16
 ## License
11 17
 
12 18
 Licensed under the [ISC License][] unless otherwise noted, see the
Browse code

Add license

Robert Cranston authored on 14/10/2022 19:35:14
Showing 1 changed files
... ...
@@ -6,3 +6,11 @@ A [C++11][]/[OpenGL][]>=[1.0][] basics library.
6 6
 [C++11]: https://en.wikipedia.org/wiki/C++11
7 7
 [OpenGL]: https://en.wikipedia.org/wiki/OpenGL
8 8
 [1.0]: https://en.wikipedia.org/wiki/OpenGL#Version_history
9
+
10
+## License
11
+
12
+Licensed under the [ISC License][] unless otherwise noted, see the
13
+[`LICENSE`][] file.
14
+
15
+[ISC License]: https://choosealicense.com/licenses/isc
16
+[`LICENSE`]: LICENSE
Browse code

Add readme

Robert Cranston authored on 14/10/2022 19:35:10
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+# [`glbase`][]
2
+
3
+A [C++11][]/[OpenGL][]>=[1.0][] basics library.
4
+
5
+[`glbase`]: https://git.rcrnstn.net/rcrnstn/glbase
6
+[C++11]: https://en.wikipedia.org/wiki/C++11
7
+[OpenGL]: https://en.wikipedia.org/wiki/OpenGL
8
+[1.0]: https://en.wikipedia.org/wiki/OpenGL#Version_history