VertexIdRewrite.h file
Shared rewrite of the engine's gl_VertexID quad-synthesis expressions into reads of vertex attributes, for the emitters targeting a stage language that has no vertex-ID input.
Two backends need exactly the same substitution, which is why it lives here rather than in either of them: the ESSL 100 profile (OpenGL|ES 2.0 has no gl_VertexID, and ESSL 100 additionally has no integer bit/modulo operators) and the Cg dialect emitted for the PS Vita's sceGxm backend (the GXM parameter semantics are the fixed-function-era Cg set — POSITION, TEXCOORD, COLOR, NORMAL, … — with no vertex-index semantic at all, so the corner cannot be recomputed in-shader there either).
Because both consumers substitute the identical expressions, a shader that works on the ES 2.0 profile keeps working on GXM: the runtime already supplies the aQuadCorner / aInstanceIndex attribute streams for the ES 2.0 profile, which the PS Vita build has always used, so the GXM vertex layout is the one the engine already produces.
Namespaces
- namespace ShaderCompiler
- namespace ShaderCompiler::VertexIdRewrite
Functions
-
auto FindSubstring(StringView haystack,
StringView needle) -> std::
size_t - Byte offset of
needleinhaystack, orNpos. - auto ReplaceAllOf(StringView s, StringView from, StringView to) -> String
- Replaces every occurrence of
frominswithto. - auto Apply(StringView src, bool& usedCorner, bool& usedInstance) -> String
Variables
-
std::
size_t Npos constexpr - "Not found" sentinel of the string helpers below
Function documentation
String Apply(StringView src, bool& usedCorner, bool& usedInstance)
Rewrites the engine's gl_VertexID quad-synthesis expressions into reads of the vertex attributes the runtime supplies (a static per-vertex [0,1]² corner, and a per-vertex instance index for the batched six-vertices-per-sprite path). Sets usedCorner / usedInstance so the caller declares only the attributes that end up referenced.
Every single-quad formula is a function of the two terms float(id>>1) and float(id%2); substituting them with (1 - aQuadCorner.x) and aQuadCorner.y reproduces the exact corner of any of them (plain sprite, Lighting's 0.5-offset, TouchCircle) after constant folding, given the runtime supplies aQuadCorner = {(1,0),(1,1),(0,0),(0,1)} for the 4-vertex strip. The batched corner + instance index are fixed expressions replaced wholesale.