//----------------------------------------------------------------------- void CgProgram::selectProfile(void) { mSelectedProfile.clear(); mSelectedCgProfile = CG_PROFILE_UNKNOWN; StringVector::iterator i, iend; iend = mProfiles.end(); GpuProgramManager& gpuMgr = GpuProgramManager::getSingleton(); for (i = mProfiles.begin(); i != iend; ++i) { if (gpuMgr.isSyntaxSupported(*i)) { mSelectedProfile = *i; mSelectedCgProfile = cgGetProfile(mSelectedProfile.c_str()); // Check for errors checkForCgError("CgProgram::selectProfile", "Unable to find CG profile enum for program " + mName + ": ", mCgContext); break; } } }
bool FragmentShaderCg::SetSourceCode(const String &sSourceCode, const String &sProfile, const String &sArguments, const String &sEntry) { // Destroy the previous Cg fragment program, if there's one if (m_pCgFragmentProgram) { cgDestroyProgram(m_pCgFragmentProgram); m_pCgFragmentProgram = nullptr; } // Get the profile from a user given string m_pCgProfile = cgGetProfile(sProfile.GetLength() ? sProfile : "glslf"); // We're using a GLSL profile as default so ATI users have reasonable shader support when using Cg // On unknown or invalid profile, choose a fallback profile if (m_pCgProfile == CG_PROFILE_UNKNOWN || (!cgGetProfileProperty(m_pCgProfile, CG_IS_FRAGMENT_PROFILE) && m_pCgProfile != CG_PROFILE_GLSLF)) { m_pCgProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); if (m_pCgProfile == CG_PROFILE_UNKNOWN && cgGLIsProfileSupported(CG_PROFILE_GLSLF)) m_pCgProfile = CG_PROFILE_GLSLF; } // Create the Cg fragment program if (m_pCgProfile != CG_PROFILE_UNKNOWN) m_pCgFragmentProgram = CgContext::CreateCgProgram(m_pCgProfile, sSourceCode, sArguments, sEntry); // Was the Cg program created successfully? if (m_pCgFragmentProgram) { // Backup the optional shader compiler arguments and the user defined entry point m_sArguments = sArguments; m_sEntry = sEntry; // Done return true; } else { m_pCgProfile = CG_PROFILE_UNKNOWN; m_sArguments = ""; m_sEntry = ""; // Error! return false; } }
static sBool sCompileCg(sCompileResult &result, sInt stype, sInt dtype, sInt flags, const sChar8 *src, sInt len, const sChar8 *name) { #if sCOMP_CG_ENABLE if(result.Cg.Program) cgDestroyProgram(result.Cg.Program); sChar8 *src8 = new sChar8[len]; sCopyString(src8,src,len); CGprofile prof = cgGetProfile(GetProfile(dtype)); CGprogram program = cgCreateProgram(CGC,CG_SOURCE,src8,prof,name,0); if(GetCgError(result.Errors)) goto error; cgCompileProgram(program); if(GetCgError(result.Errors)) goto error; const sChar8 *out8 = cgGetProgramString(program,CG_COMPILED_PROGRAM); if(GetCgError(result.Errors)) goto error; sInt size = 0; while(out8[size]) size++; sAddShaderBlob(result.ShaderBlobs,dtype,size,(const sU8*)out8); result.Valid = sTRUE; sDeleteArray(src8); return sTRUE; error: result.Valid = sFALSE; sDeleteArray(src8); return sFALSE; #else sLogF(L"asc",L"sCOMP_CG_ENABLE == 0 no cg compiler available\n"); return sFALSE; #endif // sCOMP_CG_ENABLE }
void cgfxProfile::initialize() { // Determine the texture coordinate orientation. { MStatus status; MString str = MCommonSystemUtils::getEnv("MAYA_TEXCOORD_ORIENTATION", &status); if (status) { if (str == "OPENGL" || str == "") sTexCoordOrientation = TEXCOORD_OPENGL; else if (str == "DIRECTX") sTexCoordOrientation = TEXCOORD_DIRECTX; else { MString es = "cgfxShader : The value "; es += str; es += " of the MAYA_TEXCOORD_ORIENTATION environment variable is unsupported. "; es += "Supported values are OPENGL and DIRECTX"; MGlobal::displayWarning( es ); } } } // Determine the list of available Cg profiles. { const int nbKnownProfiles = sizeof(CgGLProfileList)/sizeof(const char*[4]); cgfxProfile** currentEntry = &sProfileList; for (int i=0; i<nbKnownProfiles; ++i) { const char* shortName = CgGLProfileList[i][0]; const char* vtxProfileName = CgGLProfileList[i][1]; const char* geomProfileName = CgGLProfileList[i][2]; const char* fragProfileName = CgGLProfileList[i][3]; CGprofile vtxProfile = cgGetProfile(vtxProfileName); CGprofile geomProfile = cgGetProfile(geomProfileName); CGprofile fragProfile = cgGetProfile(fragProfileName); // The geometry profile support is optional. if ( cgGLIsProfileSupported(vtxProfile) && (geomProfileName[0] == '\0' || cgGLIsProfileSupported(geomProfile)) && cgGLIsProfileSupported(fragProfile) ) { *currentEntry = new cgfxProfile( shortName, vtxProfile, geomProfile, fragProfile); currentEntry = &(*currentEntry)->fNext; } } } // Set the shader profile strings to the latest supported one. if (sProfileList == NULL) { sBestProfile = NULL; } else if (sProfileList->fNext == NULL) { // Only one profile is available we must chose it. sBestProfile = sProfileList; } else { if (sProfileList->fName == "glsl") { // The GLSL profile does not handle properly the semantic // annotations on top-level uniform variable // declarations. We therefore try to avoid it by default. sBestProfile = sProfileList->fNext; } else { sBestProfile = sProfileList; } } }
bool ProfileLimits::FromString (const char* str) { csStringArray components; components.SplitString (str, "."); if (components.GetSize() == 0) return false; size_t i = 0; profile = cgGetProfile (components[i++]); if (profile == CG_PROFILE_UNKNOWN) return false; if (i >= components.GetSize()) return false; vendor = CS::PluginCommon::ShaderProgramPluginGL::VendorFromString ( components[i++]); FixupVendor(); if (vendor == CS::PluginCommon::ShaderProgramPluginGL::Invalid) return false; uint usedLimits = 0; uint usedExts = 0; #define PROFILE_BEGIN(PROFILE) \ case CG_PROFILE_ ## PROFILE: \ { #define PROFILE_END(PROFILE) \ } \ break; #define LIMIT(Limit, glLimit, cgDefault, cgMax) \ usedLimits |= 1 << lim ## Limit; #define USESEXT(X, defaultPresent) \ usedExts |= ext ## X; switch (profile) { PROFILES default: break; } #undef PROFILE_BEGIN #undef PROFILE_END #undef LIMIT #undef USESEXT if (usedExts != 0) { if (i >= components.GetSize()) return false; uint v; char dummy; if (sscanf (components[i++], "%u%c", &v, &dummy) != 1) return false; extensions = v; } #define EMIT(Limit) \ if (usedLimits & (1 << lim ## Limit)) \ { \ if (i >= components.GetSize()) return false; \ int v; \ char dummy; \ if (sscanf (components[i++], "%d%c", &v, &dummy) != 1) return false; \ Limit = v; \ } EMIT (MaxInstructions); EMIT (NumInstructionSlots); EMIT (NumMathInstructionSlots); EMIT (NumTexInstructionSlots); EMIT (NumTemps); EMIT (MaxLocalParams); EMIT (MaxTexIndirections); EMIT (MaxAddressRegs); #undef EMIT return i == components.GetSize(); };