bool cgfxProfile::isSupported() const { return (fVtx == CG_PROFILE_UNKNOWN || cgGLIsProfileSupported(fVtx)) && (fGeom == CG_PROFILE_UNKNOWN || cgGLIsProfileSupported(fGeom)) && (fFrag == CG_PROFILE_UNKNOWN || cgGLIsProfileSupported(fFrag)); }
void CGlutCgWindow::chooseProfiles() { // Make sure that the appropriate profiles are available on the // user's system. if (cgGLIsProfileSupported(CG_PROFILE_VP40)) s_vertexProfile = CG_PROFILE_VP40; else { // try VP30 if (cgGLIsProfileSupported(CG_PROFILE_VP30)) s_vertexProfile = CG_PROFILE_VP30; else { fprintf(stderr, "Neither arbvp1 or vp30 vertex profiles supported on this system.\n"); exit(1); } } cgGLSetOptimalOptions(s_vertexProfile); if (cgGLIsProfileSupported(CG_PROFILE_FP40)) s_fragmentProfile = CG_PROFILE_FP40; else { // try FP30 if (cgGLIsProfileSupported(CG_PROFILE_FP30)) s_fragmentProfile = CG_PROFILE_FP30; else { fprintf(stderr, "Neither arbfp1 or fp30 fragment profiles supported on this system.\n"); exit(1); } } cgGLSetOptimalOptions(s_fragmentProfile); }
void ParticleShaderDiskDevelop::setupCG() { if (cgGLIsProfileSupported(CG_PROFILE_VP30)) vProfile = CG_PROFILE_VP30; else exit(-1); if (cgGLIsProfileSupported(CG_PROFILE_FP30)) fProfile = CG_PROFILE_FP30; else exit(-1); // Create the Cg context CGcontext cgContext = cgCreateContext(); // Create the vertex program vProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "../Particles/vertex.cg", vProfile, NULL, NULL); cgGLLoadProgram(vProgram); // Create the fragment programs fProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "../Particles/clip_frag_d.cg", fProfile, NULL, NULL); cgGLLoadProgram(fProgram); }
bool ZZshCheckProfilesSupport() { // load the effect, find the best profiles (if any) if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE) { ZZLog::Error_Log("arbvp1 not supported."); return false; } if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE) { ZZLog::Error_Log("arbfp1 not supported."); return false; } return true; }
void InitCG() { if( cgGLIsProfileSupported(CG_PROFILE_ARBVP1) ) g_CGprofile_vertex = CG_PROFILE_ARBVP1; else if( cgGLIsProfileSupported(CG_PROFILE_VP40) ) g_CGprofile_vertex = CG_PROFILE_VP40; else { ShaderWater=false; return; } if( cgGLIsProfileSupported(CG_PROFILE_ARBFP1) ) g_CGprofile_pixel = CG_PROFILE_ARBFP1; else if( cgGLIsProfileSupported(CG_PROFILE_FP30) ) g_CGprofile_pixel = CG_PROFILE_FP30; else if( cgGLIsProfileSupported(CG_PROFILE_FP20) ) g_CGprofile_pixel = CG_PROFILE_FP20; else { ShaderWater=false; return; } g_CGcontext = cgCreateContext(); g_Sea_vertex = cgCreateProgramFromFile( g_CGcontext, CG_SOURCE, "Sea_vertex.cg", g_CGprofile_vertex, NULL, NULL ); cgGLLoadProgram(g_Sea_vertex); CGerror GetCGerror=cgGetError(); if(GetCGerror!=CG_NO_ERROR) MessageBox (HWND_DESKTOP, "vertex shader Error!", "Error", MB_OK | MB_ICONEXCLAMATION); g_Sea_pixel = cgCreateProgramFromFile( g_CGcontext, CG_SOURCE, "Sea_pixel.cg", g_CGprofile_pixel, NULL, NULL ); cgGLLoadProgram(g_Sea_pixel); GetCGerror=cgGetError(); if(GetCGerror!=CG_NO_ERROR) MessageBox (HWND_DESKTOP, "pixel shader Error!", "Error", MB_OK | MB_ICONEXCLAMATION); }
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; } }
//--------------------------------------------------------------------------------- // init // this function load and compile a vertex/fragment program on the specified context // if the source file is not found, it assigns a default GREEN color shader // if the compile failed, it assigns a default RED color shader //--------------------------------------------------------------------------------- bool FFxProgram::init(CGcontext aContext) { CGenum fileType; // remove existing program (in case a program is already loaded) if (mProgram) { cgDestroyProgram(mProgram); mProgram = 0; } fileType = CG_SOURCE; #ifdef WIN32 HRESULT hr; if (GDD->GetClassID() == ClassIDZDisplayDeviceDX9) { const char** profileOpts; profileOpts = cgD3D9GetOptimalOptions(mProfile); const char *nOpts[16]; nOpts[0] = COMPILE_ARGS[0]; int idx =1; while ( (idx<15) && profileOpts[idx-1]) { nOpts[idx] = profileOpts[idx-1]; idx++; } nOpts[idx] = 0; const char *szDXprofile = NULL; if (mProfile == CG_PROFILE_VS_2_0) { szDXprofile = D3DXGetVertexShaderProfile(GDD->GetD3D9Device()); } else { szDXprofile = D3DXGetPixelShaderProfile(GDD->GetD3D9Device()); } /* //LPD3DXBUFFER mDXShader; D3DXCompileShader( mSourceBuffer, strlen(mSourceBuffer), NULL, NULL, mEntry.c_str(), szDXprofile, 0, &mDXShader, NULL, NULL ); */ mProgram = cgCreateProgram(aContext, fileType, mSourceBuffer, mProfile, mEntry.c_str(), nOpts); hr = cgD3D9LoadProgram(mProgram, true, 0); } else #endif { // opengl //mProgram = cgCreateProgram(aContext, fileType, mSourceBuffer, mProfile, mEntry.c_str(), COMPILE_ARGS); mProfile = (mProfileDomain == CG_VERTEX_DOMAIN) ?cgGLGetLatestProfile(CG_GL_VERTEX):cgGLGetLatestProfile(CG_GL_FRAGMENT ); assert(cgGLIsProfileSupported(mProfile)); mProgram = cgCreateProgramFromFile(aContext, fileType, mFileName, mProfile, mEntry.c_str(), COMPILE_ARGS); if (mProgram == NULL) { CGerror error; const char* errTxt = cgGetLastErrorString(&error); LOG ("ERROR %x: can't compile %s : %s\n", error, mFileName.c_str(), errTxt); useDefaultProgram(aContext); assert(false); return false; } cgGLLoadProgram(mProgram); checkForCgError("loadprog"); } if (mProgram == 0) { CGerror error = cgGetError(); LOG ("ERROR %x: can't load or compile %s : %s\n", error, mFileName.c_str(), cgGetLastErrorString(&error)); useDefaultProgram(aContext); assert(false); return false; } return true; }
iShaderProgram::CacheLoadResult csShaderGLCGCommon::LoadFromCache ( iHierarchicalCache* cache, iBase* previous, iDocumentNode* node, csRef<iString>* failReason, csRef<iString>* tag, ProfileLimitsPair* cacheLimits) { if (!cache) return iShaderProgram::loadFail; csRef<iShaderProgramCG> prevCG (scfQueryInterfaceSafe<iShaderProgramCG> ( previous)); csRef<iStringArray> allCachedPrograms; if ((programType == progVP) && prevCG.IsValid()) { csShaderGLCGFP* prevFP = static_cast<csShaderGLCGFP*> ( (iShaderProgramCG*)prevCG); csString tagStr ("CG"); tagStr += prevFP->cacheLimits.ToString(); if (failReason) failReason->AttachNew ( new scfString ("paired cached programs not found")); allCachedPrograms.AttachNew (new scfStringArray); allCachedPrograms->Push (tagStr); } else allCachedPrograms = cache->GetSubItems ("/"); if (!allCachedPrograms.IsValid() || (allCachedPrograms->GetSize() == 0)) { if (failReason) failReason->AttachNew ( new scfString ("no cached programs found")); return iShaderProgram::loadFail; } if (!GetProgramNode (node)) return iShaderProgram::loadFail; csRef<iDataBuffer> programBuffer = GetProgramData(); CS::Utility::Checksum::MD5::Digest progHash = CS::Utility::Checksum::MD5::Encode ( programBuffer->GetData(), programBuffer->GetSize()); csArray<CachedShaderWrapper> cachedProgWrappers; for (size_t i = 0; i < allCachedPrograms->GetSize(); i++) { const char* tag = allCachedPrograms->Get (i); if ((tag[0] != 'C') || (tag[1] != 'G')) continue; CachedShaderWrapper wrapper; if (!wrapper.limits.FromString (tag+2)) continue; wrapper.name = tag; csString cachePath ("/"); cachePath.Append (tag); csRef<iDataBuffer> cacheBuf = cache->ReadCache (cachePath); if (!cacheBuf.IsValid()) continue; csRef<iFile> cacheFile; cacheFile.AttachNew (new csMemFile (cacheBuf, true)); wrapper.cacheFile = cacheFile; uint32 diskMagic; if (cacheFile->Read ((char*)&diskMagic, sizeof (diskMagic)) != sizeof (diskMagic)) continue; if (csLittleEndian::UInt32 (diskMagic) != cacheFileMagic) continue; CS::Utility::Checksum::MD5::Digest diskHash; if (cacheFile->Read ((char*)&diskHash, sizeof (diskHash)) != sizeof (diskHash)) continue; if (diskHash != progHash) continue; cachedProgWrappers.Push (wrapper); } if (cachedProgWrappers.GetSize() == 0) { if (failReason && !*failReason) failReason->AttachNew ( new scfString ("all cached programs failed to read")); return iShaderProgram::loadFail; } cachedProgWrappers.Sort (); ProfileLimits currentLimits ( (programType == progVP) ? shaderPlug->currentLimits.vp : shaderPlug->currentLimits.fp); bool strictMatch = (programType == progVP) ? shaderPlug->strictMatchVP : shaderPlug->strictMatchFP; const char* progTypeNode = 0; switch (programType) { case progVP: progTypeNode = "cgvp"; break; case progFP: progTypeNode = "cgfp"; break; } csString allReasons; bool oneReadCorrectly = false; ProfileLimits bestLimits ( CS::PluginCommon::ShaderProgramPluginGL::Other, CG_PROFILE_UNKNOWN); bool bestLimitsSet = false; for (size_t i = cachedProgWrappers.GetSize(); i-- > 0;) { const CachedShaderWrapper& wrapper = cachedProgWrappers[i]; const ProfileLimits& limits = (programType == progVP) ? wrapper.limits.vp : wrapper.limits.fp; if (!bestLimitsSet) { bestLimits = limits; bestLimitsSet = true; } if (strictMatch && (limits != currentLimits)) { allReasons += wrapper.name; allReasons += ": strict mismatch; "; continue; } bool profileSupported = (shaderPlug->ProfileNeedsRouting (limits.profile) && shaderPlug->IsRoutedProfileSupported (limits.profile)) || cgGLIsProfileSupported (limits.profile); if (!profileSupported) { allReasons += wrapper.name; allReasons += ": Profile unsupported; "; continue; } if ((limits.vendor != currentLimits.vendor) && (limits.vendor != CS::PluginCommon::ShaderProgramPluginGL::Other)) { allReasons += wrapper.name; allReasons += ": vendor mismatch; "; continue; } bool limitsSupported = currentLimits >= limits; if (!limitsSupported) { allReasons += wrapper.name; allReasons += ": Limits exceeded; "; continue; } iFile* cacheFile = wrapper.cacheFile; { uint32 diskState; if (cacheFile->Read ((char*)&diskState, sizeof (diskState)) != sizeof (diskState)) continue; if (csLittleEndian::UInt32 (diskState) != cpsValid) { oneReadCorrectly = true; continue; } } description = CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile); bool breakFail = false; csRef<iDocumentNode> cgNode = node->GetNode (progTypeNode); if (!cgNode.IsValid()) continue; csRef<iDocumentNodeIterator> nodes = cgNode->GetNodes(); while(nodes->HasNext() && !breakFail) { csRef<iDocumentNode> child = nodes->Next(); if(child->GetType() != CS_NODE_ELEMENT) continue; const char* value = child->GetValue (); csStringID id = xmltokens.Request (value); switch(id) { case XMLTOKEN_VARIABLEMAP: if (!ParseVmap (child)) breakFail = true; break; case XMLTOKEN_CLIP: if (!ParseClip (child)) breakFail = true; break; default: /* Ignore unknown nodes. Invalid nodes would have been caught by the first (not from cache) parsing */ break; } } if (breakFail) continue; csString objectCodeCachePathArc = CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile); if (objectCodeCachePathArc.IsEmpty()) continue; csString objectCodeCachePathItem = CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile); if (objectCodeCachePathItem.IsEmpty()) continue; ProgramObjectID progId (objectCodeCachePathArc, objectCodeCachePathItem); ProgramObject programObj; //if (!LoadObjectCodeFromCompileCache (limits, cache)) if (!shaderPlug->progCache.LoadObject (progId, programObj)) continue; oneReadCorrectly = true; if (program) { cgDestroyProgram (program); program = 0; } if (!programObj.IsValid()) continue; cgGetError(); // Clear error program = cgCreateProgram (shaderPlug->context, CG_OBJECT, programObj.GetObjectCode(), limits.profile, 0, 0); if (!program) continue; CGerror err = cgGetError(); if (err != CG_NO_ERROR) { const char* errStr = cgGetErrorString (err); shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING, "Cg error %s", errStr); continue; } programProfile = limits.profile; programPositionInvariant = programObj.GetFlags() & ProgramObject::flagPositionInvariant; unusedParams = programObj.GetUnusedParams(); ClipsToVmap(); GetParamsFromVmap(); bool doLoadToGL = !shaderPlug->ProfileNeedsRouting (programProfile); cgGetError(); // Clear error if (doLoadToGL) { cgGLLoadProgram (program); } else { cgCompileProgram (program); } shaderPlug->PrintAnyListing(); err = cgGetError(); if ((err != CG_NO_ERROR) || (doLoadToGL && !cgGLIsProgramLoaded (program))) { //if (shaderPlug->debugDump) //DoDebugDump(); const char* errStr = cgGetErrorString (err); shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING, "Cg error %s", errStr); if (shaderPlug->doVerbose && (((programType == progVP) && (programProfile >= CG_PROFILE_ARBVP1)) || ((programType == progFP) && (programProfile >= CG_PROFILE_ARBFP1)))) { const char* err = (char*)glGetString (GL_PROGRAM_ERROR_STRING_ARB); shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING, "OpenGL error string: %s", err); } shaderPlug->SetCompiledSource (0); continue; } GetPostCompileParamProps (); if (shaderPlug->debugDump) DoDebugDump(); tag->AttachNew (new scfString (wrapper.name)); if (cacheLimits != 0) *cacheLimits = wrapper.limits; bool loaded = !shaderPlug->ProfileNeedsRouting (programProfile) || LoadProgramWithPS1 (); if (loaded && (bestLimits < currentLimits)) { /* The best found program is worse than the current limits, so pretend that the shader program failed (instead just being 'invalid') - that will make xmlshader try to load the program from scratch, ie with current limits, which may just work. */ if (failReason) failReason->AttachNew (new scfString ("Provoking clean load with current limits")); return iShaderProgram::loadFail; } return loaded ? iShaderProgram::loadSuccessShaderValid : iShaderProgram::loadSuccessShaderInvalid; } if (oneReadCorrectly) { if (bestLimits < currentLimits) { /* The 'invalid' programs may compile with the current limits - so again, provoke clean load */ if (failReason) failReason->AttachNew (new scfString ("Provoking clean load with current limits")); return iShaderProgram::loadFail; } else return iShaderProgram::loadSuccessShaderInvalid; } else return iShaderProgram::loadFail; }
// // Constructor // CCgShader::CCgShader( CGenum SourceType, const string& SourceStr, CGprofile Profile, CGGLenum ProfileClass, const string& Entry, const string& Arguments ): m_Program( NULL ) { if (SourceType != CG_SOURCE && SourceType != CG_OBJECT) throw Sys::CDeveloperException( "GL::CCgShader", "::CCgShader() : Invalid <SourceType> parameter." ); if (SourceStr.length() == 0) throw Sys::CDeveloperException( "GL::CCgShader", "::CCgShader() : Invalid <SourceStr> parameter." ); CCgContext::AddRef(); if (Profile == CG_PROFILE_UNKNOWN) Profile = cgGLGetLatestProfile( ProfileClass ); else { CheckDomain( Profile, ProfileClass ); if (cgGLIsProfileSupported( Profile ) == CG_FALSE) { const char *ProfileName = GetProfileName( Profile ); if (!ProfileName) throw Sys::CException( 0, "GL::CCgShader", "::CCgShader() : Unknown shader profile." ); else { throw Sys::CException( 0, "GL::CCgShader", "::CCgShader() : Profile %s unsupported.\n" "A profile may not be supported if required OpenGL extension is not available.", ProfileName ); } } } try { const char *TypeName = NULL; switch (ProfileClass) { case CG_GL_VERTEX: TypeName = "vertex"; break; case CG_GL_GEOMETRY: TypeName = "geometry"; break; case CG_GL_FRAGMENT: TypeName = "fragment"; break; } const char *Args[ 2 ] = { Arguments.c_str(), NULL }; m_Program = cgCreateProgram( CCgContext::GetContext(), SourceType, SourceStr.c_str(), Profile, (Entry.length() == 0) ? NULL : Entry.c_str(), (Arguments.length() == 0) ? NULL : Args ); if (!m_Program) { m_LastListing = CCgContext::GetLastListing(); #ifdef _DEBUG OutputDebugLog(); #endif throw CCgException( "GL::CCgShader", cgGetError(), "::CCgShader() : Failed to create Cg %s shader.\nSee program log for more details.", TypeName ); } cgCompileProgram( m_Program ); CGerror Error = cgGetError(); if (Error != CG_NO_ERROR) { m_LastListing = CCgContext::GetLastListing(); #ifdef _DEBUG OutputDebugLog(); #endif throw CCgException( "GL::CCgShader", Error, "::CCgShader() : Failed to compile Cg %s shader.\nSee program log for more details.", TypeName ); } } catch (const Sys::CException& Ex) { if (cgIsProgram( m_Program )) cgDestroyProgram( m_Program ); CCgContext::Release(); throw Ex; } }
void GLWindow::initializeGL() { mInitialized = true; if( checkGLError() ) LOG_TRACE // Set up the rendering context, define display lists etc.: glClearColor( 8/256.0, 5/256.0, 76/256.0, 0.0 ); glDisable(GL_DEPTH_TEST); if( checkGLError() ) LOG_TRACE #ifdef COMPILE_CG if( mUseCG && cgGLIsProfileSupported( CG_PROFILE_FP20 ) ){ //LOG_3("Using Cg"); // This is the most basic fragment profile, should run on quite a few cards cgFragmentProfile = CG_PROFILE_FP20; cgSetErrorCallback(cgErrorCallback); cgContext = cgCreateContext(); // TODO: Include the shader source in the executable cgProgram = cgCreateProgram( cgContext, CG_SOURCE, FRAGMENT_SHADER, cgFragmentProfile, 0, 0); cgGLLoadProgram( cgProgram ); cgImageParam = cgGetNamedParameter( cgProgram, "image" ); cgColorClampParam = cgGetNamedParameter( cgProgram, "colorClamp" ); cgGLBindProgram( cgProgram ); }else #endif { //LOG_3("Using stock OpenGL"); mUseCG = false; } // GL_TEXTURE_ENV_MODE defaults to GL_MODULATE // GL_TEXTURE_ENV_COLOR defaults to (0,0,0,0) #ifdef GL_NV_texture_rectangle mUseGL_NV_texture_rectangle = isExtensionSupported( "GL_NV_texture_rectangle" ); if( checkGLError() ) LOG_TRACE #endif // GL_NV_texture_rectangle #ifdef GL_NV_texture_rectangle if( mUseGL_NV_texture_rectangle ){ //LOG_5( "Using GL_TEXTURE_RECTANGLE_NV" ); mTextureMode = GL_TEXTURE_RECTANGLE_NV; // Only try to use cg, if texture_rectangle is supported // 4/23/04 WHY? mUseCG = true; } else #endif // GL_NV_texture_rectangle { //qWarning("NOT USING GL_TEXTURE_RECTANGLE_NV"); mTextureMode = GL_TEXTURE_2D; // Set up the texturing params GLint wrapMode = GL_CLAMP; int glMajor, glMinor; glVersion(glMajor,glMinor); if( glMajor >= 1 && glMinor >=2 ) wrapMode = GL_CLAMP_TO_EDGE; glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, wrapMode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, wrapMode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); } }
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; } } }
void cgtk::init() { cout << "glew init " << endl; GLenum err = glewInit(); // initialize all the OpenGL extensions glewGetExtension("glMultiTexCoord2fvARB"); if(glewGetExtension("GL_EXT_framebuffer_object") )cout << "GL_EXT_framebuffer_object support " << endl; if(glewGetExtension("GL_EXT_renderbuffer_object"))cout << "GL_EXT_renderbuffer_object support " << endl; if(glewGetExtension("GL_ARB_vertex_buffer_object")) cout << "GL_ARB_vertex_buffer_object support" << endl; if(GL_ARB_multitexture)cout << "GL_ARB_multitexture support " << endl; if (glewGetExtension("GL_ARB_fragment_shader") != GL_TRUE || glewGetExtension("GL_ARB_vertex_shader") != GL_TRUE || glewGetExtension("GL_ARB_shader_objects") != GL_TRUE || glewGetExtension("GL_ARB_shading_language_100") != GL_TRUE) { cout << "Driver does not support OpenGL Shading Language" << endl; exit(1); } //glEnable(GL_CULL_FACE); glClearColor(0.0, 0.0, 0.0, 0); create_volumetexture(); //load_volumetexture_k("data\\output31_int.bin"); //load_volumetexture_step("data\\step_by_step2.bin"); // CG init //cgSetErrorCallback(cgErrorCallback); context = cgCreateContext(); if (cgGLIsProfileSupported(CG_PROFILE_VP40)) { vertexProfile = CG_PROFILE_VP40; cout << "CG_PROFILE_VP40 supported." << endl; } else { if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1)) vertexProfile = CG_PROFILE_ARBVP1; else { cout << "Neither arbvp1 or vp40 vertex profiles supported on this system." << endl; exit(1); } } if (cgGLIsProfileSupported(CG_PROFILE_FP40)) { fragmentProfile = CG_PROFILE_FP40; cout << "CG_PROFILE_FP40 supported." << endl; } else { if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1)) fragmentProfile = CG_PROFILE_ARBFP1; else { cout << "Neither arbfp1 or fp40 fragment profiles supported on this system." << endl; exit(1); } } // load the vertex and fragment raycasting programs load_vertex_program(vertex_main,"raycasting_shader.cg","vertex_main"); cgErrorCallback(); load_fragment_program(fragment_main,"raycasting_shader.cg","fragment_main"); cgErrorCallback(); // Create the to FBO's one for the backside of the volumecube and one for the finalimage rendering glGenFramebuffersEXT(1, &framebuffer); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,framebuffer); glGenTextures(1, &backface_buffer); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, backface_buffer); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,GL_RGBA16F_ARB, WINDOW_SIZE_W, WINDOW_SIZE_H, 0, GL_RGBA, GL_FLOAT, NULL); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, backface_buffer, 0); glGenTextures(1, &final_image); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, final_image); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,GL_RGBA16F_ARB, WINDOW_SIZE_W, WINDOW_SIZE_H, 0, GL_RGBA, GL_FLOAT, NULL); glGenRenderbuffersEXT(1, &renderbuffer); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbuffer); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, WINDOW_SIZE_W, WINDOW_SIZE_H); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderbuffer); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); }