void Vector2::deserialize(TextInput& t) { t.readSymbol("("); x = (float)t.readNumber(); t.readSymbol(","); y = (float)t.readNumber(); t.readSymbol(")"); }
static Vector3 readNormal(TextInput& ti, const Matrix3& normalXform) { Vector3 n; n.x = ti.readNumber(); n.y = ti.readNumber(); n.z = ti.readNumber(); return (normalXform * n).direction(); }
static Vector3 readVertex(TextInput& ti, const Matrix4& xform) { // Vertex Vector4 v; v.x = ti.readNumber(); v.y = ti.readNumber(); v.z = ti.readNumber(); v.w = 1.0f; return (xform * v).xyz(); }
void GPUProgram::BindingTable::parseConstant(TextInput& ti) { if (consumeSymbol(ti, "c") && consumeSymbol(ti, "[")) { // constant Token t = ti.peek(); if (t.type() == Token::NUMBER) { Binding binding; binding.source = CONSTANT; binding.type = FLOAT4; binding.slot = iRound(ti.readNumber()); if (consumeSymbol(ti, "]") && consumeSymbol(ti, "=")) { for (int i = 0; i < 4; ++i) { t = ti.peek(); if (t.type() == Token::NUMBER) { binding.vector[i] = ti.readNumber(); } } bindingArray.append(binding); } } } }
void GPUProgram::BindingTable::parseVariable(TextInput& ti) { std::string name; // #var float4 osLight : : c[4] : 1 : 1 // #var float3 vin.v0 : $vin.POSITION : ATTR0 : 2 : 1 Token t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // get the binding's type ti.readSymbol(); Type type; if (! CgType(t.string(), type)) { alwaysAssertM(false, std::string("Unsupported type: \"") + t.string() + "\""); } t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // read the binding name name = ti.readSymbol(); if (! consumeSymbol(ti, ":")) { goto abort; } // see if it is the vertex or a constant register t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // Sometimes there is an extra token between the colons if (t.string() != ":") { ti.readSymbol(); t = ti.peek(); } if (! consumeSymbol(ti, ":")) { goto abort; } // read the register number t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // Consume the symbol we just peeked ti.readSymbol(); if (t.string() == "texunit") { // We're reading a texture unit } else if (t.string() == "c") { // We're reading a regular variable; parse the open bracket if (! consumeSymbol(ti, "[")) { goto abort; } } else if ((t.type() == Token::SYMBOL) && (t.string() == ":")) { // Unused variable; must be present but is not bound Binding binding; binding.source = VARIABLE; binding.type = type; binding.name = name; binding.slot = Binding::UNASSIGNED; bindingArray.append(binding); return; } else { // Something unexpected happened. goto abort; } t = ti.peek(); if (t.type() == Token::NUMBER) { int slot = iRound(ti.readNumber()); Binding binding; binding.source = VARIABLE; binding.type = type; binding.name = name; binding.slot = slot; bindingArray.append(binding); } abort: ;// Jump here if anything unexpected is encountered during parsing }