bool CGFXShader::LoadFromFile(const char* szFile) { HRESULT hr = S_OK; char buffer[128]; m_pEffect = cgCreateEffectFromFile( m_pCG, szFile, NULL ); CGerror error; const char *string = cgGetLastErrorString(&error); static char szError[1024]; if( error != CG_NO_ERROR ) { if( error == CG_COMPILER_ERROR ) { sprintf(szError, "Program: %s\n" "Error: %s\n\n" "Cg compiler output...\n%s", szFile, string, cgGetLastListing(m_pCG)); } else { sprintf(szError, "Program: %s\n" "Error: %s", szFile, string); } OutputDebugStringA(szError); OutputDebugStringA("\n"); } if(m_pEffect == NULL) { return false; } CGtechnique pTechnique = cgGetFirstTechnique( m_pEffect ); while( pTechnique && cgValidateTechnique( pTechnique ) == CG_FALSE ) { pTechnique = cgGetNextTechnique( pTechnique ); } if( pTechnique == NULL) { return false; } m_pTechnique = pTechnique; return true; }
void CgEffect::SetTechniqueByName(const char* name) { CGtechnique tech = cgGetFirstTechnique(effect); while(tech) { if(!strcmp(cgGetTechniqueName(tech), name)) break; tech = cgGetNextTechnique(tech); } this->activeTechnique = tech; }
bool cEffect::Init(const std::string &lacNameId, const std::string &lacFile) { //Initialization of the class atributes macFile = lacFile; macLastTechnique = ""; mEffect = NULL; mTechnique = NULL; mCurrentPass = NULL; mbLoaded = false; //Loading of the effect CGcontext lCGContext = cEffectManager::Get().GetCGContext(); mEffect = cgCreateEffectFromFile(lCGContext, lacFile.c_str(), NULL); if (!mEffect) { OutputDebugString("Unable to create effect\n"); const char *lacListing = cgGetLastListing(lCGContext); if (lacListing) { char lacBuffer[512]; sprintf(lacBuffer, "%s\n", lacListing); OutputDebugString(lacBuffer); } return false; } // Check if the techniques are valid CGtechnique lTechnique = cgGetFirstTechnique(mEffect); while (lTechnique) { if (cgValidateTechnique(lTechnique) == CG_FALSE) { char lacBuffer[512]; sprintf(lacBuffer, "Technique %s did not validate. Skipping. \n", cgGetTechniqueName(lTechnique)); OutputDebugString( lacBuffer ); const char *lacListing = cgGetLastListing(lCGContext); if (lacListing) { char lacBuffer[512]; sprintf(lacBuffer, "%s\n", lacListing); OutputDebugString(lacBuffer); } } lTechnique = cgGetNextTechnique(lTechnique); } mbLoaded = true; return true; }
// // An effect // cgfxEffect::cgfxEffect(const MString& fileName, const cgfxProfile* profile) : refcount(0), fEffect(NULL), fTechniques(NULL), fProfile(NULL) { MStringArray fileOptions; cgfxGetFxIncludePath( fileName, fileOptions ); fileOptions.append("-DMAYA_CGFX=1"); if (cgfxProfile::getTexCoordOrientation() == cgfxProfile::TEXCOORD_OPENGL) { fileOptions.append("-DMAYA_TEXCOORD_ORIENTATION_OPENGL=1"); } else { fileOptions.append("-DMAYA_TEXCOORD_ORIENTATION_DIRECTX=1"); } const char *opts[_CGFX_PLUGIN_MAX_COMPILER_ARGS_]; unsigned int numOpts = fileOptions.length(); if (numOpts) { numOpts = (numOpts > _CGFX_PLUGIN_MAX_COMPILER_ARGS_-1) ? _CGFX_PLUGIN_MAX_COMPILER_ARGS_-1 : numOpts; for (unsigned int i=0; i<numOpts; i++) opts[i] = fileOptions[i].asChar(); opts[numOpts] = NULL; } fEffect = cgCreateEffectFromFile(cgfxShaderNode::sCgContext, fileName.asChar(), opts); if (fEffect) { CGtechnique technique = cgGetFirstTechnique(fEffect); cgfxTechnique** nextTechnique = const_cast<cgfxTechnique**>(&fTechniques); while (technique) { *nextTechnique = new cgfxTechnique(technique, profile); nextTechnique = &(*nextTechnique)->fNext; technique = cgGetNextTechnique(technique); } fProfile = profile; } }