MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ShaderCompat.hpp File Reference

GLSL type and function spellings made valid as C++. More...

#include <glm/glm.hpp>
#include <cstdint>
+ Include dependency graph for ShaderCompat.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  MayaFlux
 Main namespace for the Maya Flux audio engine.
 
namespace  MayaFlux::ShaderCompat
 

Typedefs

using MayaFlux::ShaderCompat::ivec2 = glm::ivec2
 
using MayaFlux::ShaderCompat::ivec3 = glm::ivec3
 
using MayaFlux::ShaderCompat::mat3 = glm::mat3
 
using MayaFlux::ShaderCompat::mat4 = glm::mat4
 
using MayaFlux::ShaderCompat::uint = std::uint32_t
 
using MayaFlux::ShaderCompat::uvec3 = glm::uvec3
 
using MayaFlux::ShaderCompat::vec2 = glm::vec2
 
using MayaFlux::ShaderCompat::vec3 = glm::vec3
 
using MayaFlux::ShaderCompat::vec4 = glm::vec4
 

Detailed Description

GLSL type and function spellings made valid as C++.

A dual-source field body is authored once and compiled twice: by the host compiler into a callable, and by shaderc into SPIR-V. GLSL has no namespace qualification, so the body must be written unqualified, and this header makes unqualified lookup succeed on the host side.

Nothing is reimplemented. glm already mirrors the GLSL function set. Vector arguments would resolve through ADL without any declaration here, since a glm::vec3 argument brings namespace glm into the lookup set. Scalar arguments would not: a float has no associated namespace. The declarations below are therefore load-bearing for expressions such as clamp(d, 0.0f, 1.0f) and max(d * d, 0.1f), and the type aliases are load-bearing because vec3 and uint have no glm spelling that is also GLSL.

Authoring rules for any body that must survive both compilers:

  1. Do not author inside namespace MayaFlux::Kinesis or any namespace nested within it. A using-directive injects these names into the nearest namespace enclosing both, which is MayaFlux, so Kinesis::clamp and Kinesis::smoothstep hide the glm overloads rather than competing with them and the call fails to resolve. Author in MayaFlux::Fields or another namespace outside Kinesis; the resulting .cpu halves compose with the Kinesis factories through qualification as normal.
  2. Every decimal literal carries an f suffix. GLSL reads 0.1 as float; C++ reads it as double, and glm's scalar overloads are templates that fail deduction on mixed types. GLSL 4.60 accepts the suffix, so 0.1f is valid in both.
  3. No // comments. Stringification collapses the body to one line and a line comment would swallow the remainder.
  4. No std::, no captures, no references, no if constexpr, no templates.
  5. No swizzles. GLM_FORCE_SWIZZLE yields proxy types rather than vectors.

Opening this namespace alongside using namespace std produces ambiguity on max, min and abs. Keep the directive scoped to the namespace where fields are authored.

Verified against glslangValidator -S comp and g++ -std=c++20 for radial attraction, cross-product swirl, sphere distance, smoothstep falloff, a four-iteration accumulation loop, and a ternary-guarded normalisation.

Definition in file ShaderCompat.hpp.