taisei/src/util/macrohax.h

62 lines
2 KiB
C
Raw Normal View History

2019-10-04 05:00:34 +02:00
/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
2024-05-16 23:30:41 +02:00
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
*/
2019-10-04 05:00:34 +02:00
#pragma once
2019-10-04 05:00:34 +02:00
#include "taisei.h"
#define MACROHAX_FIRST_(f, ...) f
#define MACROHAX_FIRST(...) MACROHAX_FIRST_(__VA_ARGS__, _)
#define MACROHAX_EMPTY()
#define MACROHAX_DEFER(id) id MACROHAX_EMPTY()
#define MACROHAX_OBSTRUCT(...) __VA_ARGS__ MACROHAX_DEFER(MACROHAX_EMPTY)()
#define MACROHAX_EXPAND(...) __VA_ARGS__
#define MACROHAX_CONCAT_(a, b) a ## b
#define MACROHAX_CONCAT(a, b) MACROHAX_CONCAT_(a, b)
#define MACROHAX_ADDLINENUM(a) MACROHAX_CONCAT(a, __LINE__)
Texturing overhaul: GPU compression, sRGB sampling, swizzles, etc. (#240) * WIP compressed textures, swizzles, sRGB sampling, ... * refactor texture type info & fix random bugs * fix preprocessing of sRGB textures * handle y-flipped basis textures * glcommon: better WebGL compat for compressed format detection * missed WEBGL_compressed_texture_pvrtc * implement compressed texture xcoding and uploading * Add basis_universal submodule * Reorganize texture loader code Clean up some code Isolate Basis Universal loader into a separate module * Add wrapper script for encoding .basis textures * basisu: honor custom metadata written by the mkbasis.py script * mkbasis.py: add --incredibly-slow and --dry-run * Move pixmap code from util/ to pixmap/ * Add an on-disk transcode cache for basis textures to speed up loads * Compress texture cache with zlib * Use readable format names for basisu cache filenames * basisu: mip bias test code * basisu: small caching cleanup * add TAISEI_BASISU_MIP_BIAS env variable * Improve OpenGL format matching heuristics * Document considerations for compressed format priority * Remove dead code * Enable two forgotten formats, BC3_RGBA and ATC_RGBA Also prefer BC7 over BC1/BC3 * Recognize GL_ANGLE_compressed_texture_etc for ETC2 textures * Default depth buffers to 24-bit; remove ANGLE hack * Fix glcommon_check_extension for GLES2/legacy gl * Add renderer feature bit for texture swizzle masks * glcommon: Fixup internal formats for GLES2 Sized internal formats are not allowed in GLES2 * Fix emscripten compile errors * Update basis_universal * remove more dead code * revert irrelevant stage4 change * shut up UBSan * basisu: shut up some debug spam * Add normalmap sampling helper to util.glslh * basisu: add a gray-alpha mode * mkbasis.py: Abort if image dimansions aren't multiples of 4 * Add basic Basis Universal encoding documentation (WIP) * doc/basisu: Add paragraph about modes; minor tweaks * basisu: workarounds for GL texture size requirements * gles20: fix uncompressed sRGB formats * Partial workaround for missing swizzles in gles2 and webgl * remove invalid assertion * New renderer API to expose glDrawBuffers-like functionality * stagedraw: disable all color outputs for copy_depth pass required for WebGL compatibility * support GL_ANGLE_request_extension * emscripten: include *.basis in gfx package Also fix a potential problem when more than one .pkgdir is used to construct emscripten packages * Don't rely on emscripten runtime to enable webgl extensions
2020-08-15 13:51:12 +02:00
#define MACROHAX_STRINGIFY(x) #x
2019-10-04 05:00:34 +02:00
// Expands to 0 if argument list is empty, 1 otherwise.
// Up to 32 arguments supported.
#define MACROHAX_HASARGS(...) \
MACROHAX_EXPAND(MACROHAX_DEFER(MACROHAX_ARGCOUNT_HELPER)(\
_, ##__VA_ARGS__, MACROHAX_HASARGS_RSEQ_N() \
))
// Expands to the number of its arguments.
// Up to 32 arguments supported.
#define MACROHAX_NARGS(...) \
MACROHAX_EXPAND(MACROHAX_DEFER(MACROHAX_ARGCOUNT_HELPER)(\
_, ##__VA_ARGS__, MACROHAX_NARGS_RSEQ_N() \
))
#define MACROHAX_HASARGS_RSEQ_N() \
1, 1, 1, 1, 1, 1, 1, 1, \
1, 1, 1, 1, 1, 1, 1, 1, \
1, 1, 1, 1, 1, 1, 1, 1, \
1, 1, 1, 1, 1, 1, 1, 1, 0,
#define MACROHAX_NARGS_RSEQ_N() \
32, 31, 30, 29, 28, 27, 26, 25, \
24, 23, 22, 21, 20, 19, 18, 17, \
16, 15, 14, 13, 12, 11, 10, 9, \
8, 7, 6, 5, 4, 3, 2, 1, 0,
#define MACROHAX_ARGCOUNT_HELPER(_0, \
__1, __2, __3, __4, __5, __6, __7, __8, \
__9, _10, _11, _12, _13, _14, _15, _16, \
_17, _18, _19, _20, _21, _22, _23, _24, \
_25, _26, _27, _28, _29, _30, _31, _32, N, ...) N
// Expands to baseN, where N is the number of arguments.
#define MACROHAX_OVERLOAD_NARGS(base, ...) \
MACROHAX_CONCAT(base, MACROHAX_NARGS(__VA_ARGS__))
// Expands to baseN, where N is 0 if the argument list is empty, 1 otherwise.
#define MACROHAX_OVERLOAD_HASARGS(base, ...) \
MACROHAX_CONCAT(base, MACROHAX_HASARGS(__VA_ARGS__))