//---------------------------------------------------------------------- // //---------------------------------------------------------------------- void LNFXManager::_analyzeXML( const char* xml, size_t size ) { XML::Document xmlDoc; xmlDoc.Parse( xml, size ); // まずは Technique → Pass と作成して、コンパイルする。この中で Variable も作る XML::Element* xmlElement = xmlDoc.FirstChildElement(); while ( xmlElement != NULL ) { // <Technique> if ( strcmp( xmlElement->Name(), TechniqueElementName ) == 0 ) { _analyzeXMLTechniqueElement( xmlElement ); } xmlElement = xmlElement->NextSiblingElement(); } // 次に、作成済みの Variable にアノテーションを割り振る xmlElement = xmlDoc.FirstChildElement(); while ( xmlElement != NULL ) { // <Variable> if ( strcmp( xmlElement->Name(), VariableElementName ) == 0 ) { _analyzeXMLVariableElement( xmlElement ); } xmlElement = xmlElement->NextSiblingElement(); } }
//---------------------------------------------------------------------- // //---------------------------------------------------------------------- void LNFXManager::_analyzeXMLVariableElement( XML::Element* xmlElement ) { // 属性 const char* attrName = xmlElement->Attribute( NameAttributeName ); const char* attrSemantic = xmlElement->Attribute( SemanticAttributeName ); const bool attrShared = xmlElement->BoolAttribute( SharedAttributeName ); const char* attrTexture = xmlElement->Attribute(TextureAttributeName); LN_THROW_InvalidFormat(attrName); // 適用試行 IAnnotatedObject* var = mBuilder->OnTrySetVariableParam( attrName, attrSemantic, attrShared, attrTexture ); if ( var != NULL ) { // 子要素 XML::Element* xmlChild = xmlElement->FirstChildElement(); while ( xmlChild != NULL ) { // <Annotation> if ( strcmp( xmlChild->Name(), AnnotationElementName ) == 0 ) { _analyzeXMLAnnotationElement( xmlChild, var ); } xmlChild = xmlChild->NextSiblingElement(); } } }
//---------------------------------------------------------------------- // //---------------------------------------------------------------------- void LNFXManager::_analyzeXMLPassElement( XML::Element* xmlElement, IAnnotatedObject* parentTech ) { // 属性 const char* attrName = xmlElement->Attribute(NameAttributeName); LN_THROW_InvalidFormat(attrName); IAnnotatedObject* pass = mBuilder->OnCreatePass( parentTech, attrName ); // 子要素 XML::Element* xmlChild = xmlElement->FirstChildElement(); while ( xmlChild != NULL ) { // <VertexShader> if ( strcmp( xmlChild->Name(), VertexShaderElementName ) == 0 ) { attrName = xmlChild->Attribute( EntryPointAttributeName ); GLSLCode* code = _findShaderCode(attrName); LN_THROW_InvalidFormat(code); mBuilder->OnCreateVertexShader( pass, code->Code.c_str(), code->Code.size() ); } // <PixelShader> else if ( strcmp( xmlChild->Name(), PixelShaderElementName ) == 0 ) { attrName = xmlChild->Attribute( EntryPointAttributeName ); GLSLCode* code = _findShaderCode(attrName); LN_THROW_InvalidFormat(code); mBuilder->OnCreatePixelShader( pass, code->Code.c_str(), code->Code.size() ); } // <RenderState> else if ( strcmp( xmlChild->Name(), RenderStateElementName ) == 0 ) { attrName = xmlChild->Attribute(NameAttributeName); LN_THROW_InvalidFormat(attrName); const char* value = xmlChild->Attribute( ValueAttributeName ); mBuilder->OnSetRenderState( pass, attrName, value ); } // <Annotation> else if ( strcmp( xmlChild->Name(), AnnotationElementName ) == 0 ) { _analyzeXMLAnnotationElement( xmlChild, pass ); } xmlChild = xmlChild->NextSiblingElement(); } // link mBuilder->OnEndPass( pass ); }
//---------------------------------------------------------------------- // //---------------------------------------------------------------------- void LNFXManager::_analyzeXMLTechniqueElement( XML::Element* xmlElement ) { // 属性 const char* attrName = xmlElement->Attribute( NameAttributeName ); LN_THROW_InvalidFormat(attrName); IAnnotatedObject* tech = mBuilder->OnCreateTechnique( attrName ); // 子要素 XML::Element* xmlChild = xmlElement->FirstChildElement(); while ( xmlChild != NULL ) { // <Pass> if ( strcmp( xmlChild->Name(), PassElementName ) == 0 ) { _analyzeXMLPassElement( xmlChild, tech ); } // <Annotation> else if ( strcmp( xmlChild->Name(), AnnotationElementName ) == 0 ) { _analyzeXMLAnnotationElement( xmlChild, tech ); } xmlChild = xmlChild->NextSiblingElement(); } }