bool Material::loadPass(Technique* technique, Properties* passProperties) { GP_ASSERT(passProperties); GP_ASSERT(technique); // Fetch shader info required to create the effect of this technique. const char* vertexShaderPath = passProperties->getString("vertexShader"); GP_ASSERT(vertexShaderPath); const char* fragmentShaderPath = passProperties->getString("fragmentShader"); GP_ASSERT(fragmentShaderPath); const char* defines = passProperties->getString("defines"); // Create the pass. Pass* pass = Pass::create(passProperties->getId(), technique, vertexShaderPath, fragmentShaderPath, defines); if (!pass) { GP_ERROR("Failed to create pass for technique."); return false; } // Load render state. loadRenderState(pass, passProperties); // Add the new pass to the technique. technique->_passes.push_back(pass); return true; }
bool Material::loadTechnique(Material* material, Properties* techniqueProperties) { GP_ASSERT(material); GP_ASSERT(techniqueProperties); // Create a new technique. Technique* technique = new Technique(techniqueProperties->getId(), material); // Go through all the properties and create passes under this technique. techniqueProperties->rewind(); Properties* passProperties = NULL; while ((passProperties = techniqueProperties->getNextNamespace())) { if (strcmp(passProperties->getNamespace(), "pass") == 0) { // Create and load passes. if (!loadPass(technique, passProperties)) { GP_ERROR("Failed to create pass for technique."); SAFE_RELEASE(technique); return false; } } } // Load uniform value parameters for this technique. loadRenderState(technique, techniqueProperties); // Add the new technique to the material. material->_techniques.push_back(technique); return true; }
Material* Material::create(Properties* materialProperties) { // Check if the Properties is valid and has a valid namespace. if (!materialProperties || !(strcmp(materialProperties->getNamespace(), "material") == 0)) { GP_ERROR("Properties object must be non-null and have namespace equal to 'material'."); return NULL; } // Create new material from the file passed in. Material* material = new Material(); // Go through all the material properties and create techniques under this material. Properties* techniqueProperties = NULL; while ((techniqueProperties = materialProperties->getNextNamespace())) { if (strcmp(techniqueProperties->getNamespace(), "technique") == 0) { if (!loadTechnique(material, techniqueProperties)) { GP_ERROR("Failed to load technique for material."); SAFE_RELEASE(material); return NULL; } } } // Load uniform value parameters for this material. loadRenderState(material, materialProperties); // Set the current technique to the first found technique. if (material->getTechniqueCount() > 0) { Technique* t = material->getTechniqueByIndex(0); if (t) { material->_currentTechnique = t; } } return material; }
Material* Material::create(Properties* materialProperties) { // Check if the Properties is valid and has a valid namespace. assert(materialProperties); if (!materialProperties || !(strcmp(materialProperties->getNamespace(), "material") == 0)) { return NULL; } // Create new material from the file passed in. Material* material = new Material(); // Go through all the material properties and create techniques under this material. Properties* techniqueProperties = NULL; while ((techniqueProperties = materialProperties->getNextNamespace())) { if (strcmp(techniqueProperties->getNamespace(), "technique") == 0) { if (!loadTechnique(material, techniqueProperties)) { SAFE_RELEASE(material); return NULL; } } } // Load uniform value parameters for this material loadRenderState(material, materialProperties); // Set the current technique to the first found technique if (material->getTechniqueCount() > 0) { material->setTechnique((unsigned int)0); } return material; }
bool Material::loadPass(Technique* technique, Properties* passProperties) { // Fetch shader info required to create the effect of this technique. const char* vertexShaderPath = passProperties->getString("vertexShader"); assert(vertexShaderPath); const char* fragmentShaderPath = passProperties->getString("fragmentShader"); assert(fragmentShaderPath); const char* defines = passProperties->getString("defines"); std::string define; if (defines != NULL) { define = defines; define.insert(0, "#define "); unsigned int pos; while ((pos = define.find(';')) != std::string::npos) { define.replace(pos, 1, "\n#define "); } define += "\n"; } // Create the pass Pass* pass = Pass::create(passProperties->getId(), technique, vertexShaderPath, fragmentShaderPath, define.c_str()); if (!pass) { return false; } // Load render state loadRenderState(pass, passProperties); // Add the new pass to the technique technique->_passes.push_back(pass); return true; }