ShaderSystem::ShaderSystem() { cgContext=cgCreateContext(); checkError("creating context"); cgGLSetDebugMode(CG_FALSE); cgSetParameterSettingMode(cgContext,CG_DEFERRED_PARAMETER_SETTING); //profiles vertexProfile=cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(vertexProfile); checkError("selecting vertex profile"); fragmentProfile=cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(fragmentProfile); checkError("selecting fragment profile"); printf("vertex profile: %s\n", cgGetProfileString(cgGLGetLatestProfile(CG_GL_VERTEX))); printf("geometry profile: %s\n", cgGetProfileString(cgGLGetLatestProfile(CG_GL_GEOMETRY))); printf("fragment profile: %s\n", cgGetProfileString(cgGLGetLatestProfile(CG_GL_FRAGMENT))); }
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 GPUProgram::_chooseProfiles(void) { // Do one-time setup only once; setup Cg programs and textures // and set up OpenGL state. vertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); geometryProfile = cgGLGetLatestProfile(CG_GL_GEOMETRY); cgGLSetOptimalOptions(vertexProfile); cgGLSetOptimalOptions(fragmentProfile); cgGLSetOptimalOptions(geometryProfile); }
bool ZZshStartUsingShaders() { cgSetErrorHandler(HandleCgError, NULL); g_cgcontext = cgCreateContext(); cgvProf = CG_PROFILE_ARBVP1; cgfProf = CG_PROFILE_ARBFP1; cgGLEnableProfile(cgvProf); cgGLEnableProfile(cgfProf); cgGLSetOptimalOptions(cgvProf); cgGLSetOptimalOptions(cgfProf); cgGLSetManageTextureParameters(g_cgcontext, CG_FALSE); //cgSetAutoCompile(g_cgcontext, CG_COMPILE_IMMEDIATE); g_fparamFogColor = cgCreateParameter(g_cgcontext, CG_FLOAT4); g_vparamPosXY[0] = cgCreateParameter(g_cgcontext, CG_FLOAT4); g_vparamPosXY[1] = cgCreateParameter(g_cgcontext, CG_FLOAT4); ZZLog::GS_Log("Creating effects."); B_G(LoadEffects(), return false); // create a sample shader clampInfo temp; memset(&temp, 0, sizeof(temp)); temp.wms = 3; temp.wmt = 3; g_nPixelShaderVer = 0;//SHADER_ACCURATE; // test bool bFailed; FRAGMENTSHADER* pfrag = ZZshLoadShadeEffect(0, 1, 1, 1, 1, temp, 0, &bFailed); if( bFailed || pfrag == NULL ) { g_nPixelShaderVer = SHADER_ACCURATE|SHADER_REDUCED; pfrag = ZZshLoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed); if( pfrag != NULL ) cgGLLoadProgram(pfrag->prog); if( bFailed || pfrag == NULL || cgGetError() != CG_NO_ERROR ) { g_nPixelShaderVer = SHADER_REDUCED; ZZLog::Error_Log("Basic shader test failed."); } } if (g_nPixelShaderVer & SHADER_REDUCED) conf.bilinear = 0; ZZLog::GS_Log("Creating extra effects."); B_G(ZZshLoadExtraEffects(), return false); ZZLog::GS_Log("using %s shaders\n", g_pShaders[g_nPixelShaderVer]); return true; }
bool ShaderCG::init(const char* file_v, const char* file_f) { #ifdef HAS_CG CGcontext context = cgCreateContext(); profile_vertex = cgGLGetLatestProfile(CG_GL_VERTEX);; profile_fragment = cgGLGetLatestProfile(CG_GL_FRAGMENT);; cgGLSetOptimalOptions(profile_vertex); cgGLSetOptimalOptions(profile_fragment); program_vertex = cgCreateProgramFromFile(context, CG_SOURCE, file_v, profile_vertex , 0, 0); program_fragment = cgCreateProgramFromFile(context, CG_SOURCE, file_f, profile_fragment, 0, 0); if (!program_vertex || !program_fragment) { ErrorCheck(); use_cg = false; printf("Shaders Disabled\n"); return false; } g_modelViewProjMatrix = cgGetNamedParameter(program_vertex, "ModelViewProj"); g_modelViewMatrix = cgGetNamedParameter(program_vertex, "ModelView"); g_modelViewMatrixI = cgGetNamedParameter(program_vertex, "ModelViewI"); g_modelViewMatrixIT = cgGetNamedParameter(program_vertex, "ModelViewIT"); g_lightPosition = cgGetNamedParameter(program_vertex, "LightPos"); g_lightDiffuse = cgGetNamedParameter(program_fragment, "lightcolor"); //g_lightAmbiente = cgGetNamedParameter(program_vertex, "LightAmbiente"); //g_lightSpecular = cgGetNamedParameter(program_vertex, "LightSpecular"); cgGLLoadProgram(program_vertex); cgGLLoadProgram(program_fragment); ErrorCheck(); printf("Shaders Enabled\n"); return true; #else printf("Shaders Disabled\n"); return false; #endif // HAS_CG }
int createShader ( int n, std::string vname, std::string vfunc, std::string fname, std::string ffunc) { #if 0 char vnbuf[200]; char vfbuf[200]; char fnbuf[200]; char ffbuf[200]; strcpy ( vnbuf, vname.c_str() ); strcpy ( vfbuf, vfunc.c_str() ); strcpy ( fnbuf, fname.c_str() ); strcpy ( ffbuf, ffunc.c_str() ); if ( cgContext == 0 ) { cgSetErrorCallback( cgErrorCallback ); cgContext = cgCreateContext(); } // Select profiles vert_profile = cgGLGetLatestProfile ( CG_GL_VERTEX ); cgGLSetOptimalOptions( vert_profile ); frag_profile = cgGLGetLatestProfile ( CG_GL_FRAGMENT ); cgGLSetOptimalOptions( frag_profile ); printf ( "Vertex profile: %s\n", cgGetProfileString(vert_profile) ); printf ( "Fragment profile: %s\n", cgGetProfileString(frag_profile) ); printf ( " (See http.developer.nvidia.com/Cg/index_profiles.html)\n"); //debug.PrintF ( "rend", "Geometry profile: %s\n", cgGetProfileString(vert_profile) ); printf ( "Loading VP: %s\n", vnbuf ); cgVP = cgCreateProgramFromFile( cgContext, CG_SOURCE, vnbuf, vert_profile, vfbuf, NULL ); cgGLLoadProgram( cgVP ); printf ( "Loading FP: %s\n", fnbuf ); cgFP = cgCreateProgramFromFile( cgContext, CG_SOURCE, fnbuf, frag_profile, ffbuf, NULL ); cgGLLoadProgram( cgFP ); cgGLSetManageTextureParameters ( cgContext, CG_FALSE ); cgGLBindProgram ( cgVP ); cgGLBindProgram ( cgFP ); #endif return 0; }
bool CgShaderProgramGL::compileCg( const io::stringc &SourceCodeString, const io::stringc &EntryPoint, const c8** CompilerOptions) { if (!createProgram(SourceCodeString, EntryPoint, CompilerOptions ? CompilerOptions : cgGLGetOptimalOptions(cgProfile_))) return false; cgGLSetOptimalOptions(cgProfile_); cgGLLoadProgram(cgProgram_); return !CgShaderContext::checkForError("shader program loading"); }
bool Shader::compileSourceCode (CGcontext context, const QString& code, const QString& entryPoint) { d->profile = cgGLGetLatestProfile(d->profileClass); qDebug("profile: %s", cgGetProfileString(d->profile)); cgGLSetOptimalOptions(d->profile); d->program = cgCreateProgram(context, CG_SOURCE, code.toLocal8Bit(), d->profile, entryPoint.toLocal8Bit(), NULL); return true; }
CrtBool CrtInitCg() { // Create a context for the CG programs we are going to load and validate it was successful CrtPrint("Creating CG context\n"); cgContext = cgCreateContext(); if (cgContext == NULL) { // BLahhh exit here MessageBox(NULL, "Failed To Create Cg Context", "Error", MB_OK); return CrtFalse; } // cgSetAutoCompile(cgContext, CG_COMPILE_MANUAL); // Register GL states (ugly crashes if you don't do this) cgGLRegisterStates(cgContext); // Get The Latest GL Vertex Profile cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); // Validate Our Profile Determination Was Successful if (cgVertexProfile == CG_PROFILE_UNKNOWN || cgFragmentProfile == CG_PROFILE_UNKNOWN) { MessageBox(NULL, "Invalid profile type", "Error", MB_OK); return CrtFalse; } // Set The Current Profile cgGLSetOptimalOptions(cgVertexProfile); cgGLSetOptimalOptions(cgFragmentProfile); // Check for errors if(!CrtCheckForCgError()) return CrtFalse; return CrtTrue; }
Shader::Shader(std::string shader_name) { // Be carefull: Cg needs a valid OpenGL context (be sure no shader is created before we have an OpenGL window) if (!cg_context) { cg_context = cgCreateContext(); vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX); // auto-detect best vertex profile cgGLSetOptimalOptions(vertex_profile); fragment_profile = cgGLGetLatestProfile(CG_GL_FRAGMENT); // auto-detect best fragment profile cgGLSetOptimalOptions(fragment_profile); } if (shader_name.length()) { vertex_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, shader_name.c_str(), vertex_profile, "VertexProgram", 0); CGerror vertex_error = cgGetError(); if (vertex_error != CG_NO_ERROR) { printf("Warning: No valid vertex program found in %s: %s\n", shader_name.c_str(), cgGetErrorString(vertex_error)); vertex_program = 0; } else { cgGLLoadProgram(vertex_program); } fragment_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, shader_name.c_str(), fragment_profile, "FragmentProgram", 0); CGerror fragment_error = cgGetError(); if (fragment_error != CG_NO_ERROR) { printf("Warning: No valid fragment program found in %s: %s\n", shader_name.c_str(), cgGetErrorString(fragment_error)); fragment_program = 0; } else { cgGLLoadProgram(fragment_program); } } }
CrtBool CrtInitCg() { CrtPrint("creating CG context\n"); cgContext = cgCreateContext(); if(cgContext == NULL) { printf("Failed to create CG context\n"); return CrtFalse; } // Register GL states cgGLRegisterStates(cgContext); // Get the latest GL Vertex Profile cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); // Was hardcoded to CG_PROFILE_SCE_VP_TYPEB cgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); // Was hardcoded to CG_PROFILE_SCE_FP_TYPEB // Make sure the profiles came back valid if(cgVertexProfile == CG_PROFILE_UNKNOWN || cgFragmentProfile == CG_PROFILE_UNKNOWN) { CrtPrint("Invalid profile type returned from cgGLGetLatestProfile\n"); return CrtFalse; } // Set Optimal Options for this profile cgGLSetOptimalOptions(cgVertexProfile); cgGLSetOptimalOptions(cgFragmentProfile); // Check for Cg errors if ( !CrtCheckForCgError() ) return CrtFalse; CrtPrint("CG context created\n"); return CrtTrue; }
int main(int argc,char** argv) { diff_seconds(); srand(time(NULL)); glutInit(&argc, argv); glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE |GLUT_RGB); glutInitWindowSize (900,600); glutInitWindowPosition (240, 40); glutCreateWindow ("E16 - Partikelsystem"); glutKeyboardFunc(keyboard); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); init(); glutDisplayFunc(display); glutIdleFunc(idle); glEnable(GL_DEPTH_TEST); /********************************************/ cg_context = cgCreateContext(); checkForCgError("creating context"); cg_vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(cg_vertex_profile); checkForCgError("selecting vertex profile"); cg_vertex_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, "vertex.cg", cg_vertex_profile, "more_complex_vertex_shader", NULL); checkForCgError("creating vertex program from file"); cgGLLoadProgram(cg_vertex_program); checkForCgError("loading vertex program"); /**************************************************/ cg_parameter_vertex_velocity = cgGetNamedParameter(cg_vertex_program, "Texture0"); cg_parameter_vertex_time = cgGetNamedParameter(cg_vertex_program, "Texture1"); glutMainLoop(); return 0; }
int main(int argc, char **argv) { glutInitWindowSize(600, 600); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInit(&argc, argv); glutCreateWindow("Per vertex lighting (Gouraud shading)"); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glClearColor(0.0, 0.0, 0.0, 1.0); cg_context = cgCreateContext(); checkForCgError("creating context"); cg_vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(cg_vertex_profile); checkForCgError("selecting vertex profile"); cg_vertex_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, "E12_vertex.cg", cg_vertex_profile, "per_vertex_lighting", NULL); checkForCgError("creating vertex program from file"); cgGLLoadProgram(cg_vertex_program); checkForCgError("loading vertex program"); GET_PARAM(modelview_proj); GET_PARAM(translation); GET_PARAM(ambient_light); GET_PARAM(light_color); GET_PARAM(light_position); GET_PARAM(camera_position); GET_PARAM(Ke); GET_PARAM(Ka); GET_PARAM(Kd); GET_PARAM(Ks); GET_PARAM(exponent); glEnable(GL_DEPTH_TEST); glutMainLoop(); return 0; }
bool GLCgShader::LoadShaderFromString( ShaderContextPtr context, const str_type::string& shaderName, const std::string& codeAsciiString, const SHADER_FOCUS focus, const SHADER_PROFILE profile, const char *entry) { if (entry) m_entry = entry; m_shaderCode = codeAsciiString; m_cgContext = ExtractCgContext(context); m_shaderName = shaderName; m_focus = focus; m_profile = profile; if (focus == Shader::SF_PIXEL) { //CGprofile latestProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); m_cgProfile = CG_PROFILE_ARBFP1; } else { #ifdef MACOSX m_cgProfile = CG_PROFILE_ARBVP1; #else m_cgProfile = cgGLGetLatestProfile(CG_GL_VERTEX); #endif } cgGLSetOptimalOptions(m_cgProfile); if (CheckForError("Shader::LoadShader setting optimal options", m_shaderName)) return false; if (CreateCgProgram()) { m_video->InsertRecoverableResource(this); } else { return false; } return true; }
void FreezeParticle::InitializeFreezeParticleShader() { TextureLoader textureLoader; glTexture FreezeParticleTexture; FreezeParticleProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(FreezeParticleProfile); CheckForCgError("FreezeParticle", "selecting fragment profile"); FreezeParticleProgram = cgCreateProgramFromFile(ShaderContext, CG_SOURCE, "assets/pixelshaders/ps_freezeparticle.cg", FreezeParticleProfile, "pixelMain", 0); CheckForCgError("FreezeParticle", "creating fragment program from file"); cgGLLoadProgram(FreezeParticleProgram); CheckForCgError("FreezeParticle", "loading fragment program"); FreezeParticleCoord0 = cgGetNamedParameter(FreezeParticleProgram, "texcoord0"); textureLoader.LoadTextureFromDisk("assets/textures/weapon/freezeparticle.tga", &FreezeParticleTexture); FreezeParticleText1 = cgGetNamedParameter(FreezeParticleProgram, "text1"); cgGLSetTextureParameter(FreezeParticleText1, FreezeParticleTexture.TextureID); CheckForCgError("FreezeParticle", "setting decal 2D texture"); }
void InitCG(){ mCgContext = cgCreateContext(); checkForCgError("cgCreateContext()"); cgGLSetDebugMode(CG_FALSE); cgSetParameterSettingMode(mCgContext, CG_DEFERRED_PARAMETER_SETTING); checkForCgError("cgSetParameterSettingMode()"); mCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); checkForCgError("cgGLGetLatestProfile()"); cgGLSetOptimalOptions(mCgVertexProfile); checkForCgError("cgGLSetOptimalOptions()"); mCgVertexProgram = cgCreateProgramFromFile(mCgContext, CG_SOURCE, "1tex_skin_mesh.cg", mCgVertexProfile, "skinMeshCG", NULL); checkForCgError("cgCreateProgramFromFile()"); cgGLLoadProgram(mCgVertexProgram); checkForCgError("cgGLLoadProgram()"); mBoneParameter = cgGetNamedParameter(mCgVertexProgram, "boneMatrix"); checkForCgError("cgGetNamedParameter(boneMatrix)"); }
FFxProgram::FFxProgram(CGdomain aProfileDomain, const char* aFileName, const char* aEntry, const char** aArgs) : mProgramFlags(0), mProgram(0), mSourceBuffer(0), mProfileDomain(aProfileDomain) { #ifdef WIN32 if (GDD->GetClassID() == ClassIDZDisplayDeviceDX9) mProfile = (aProfileDomain == CG_VERTEX_DOMAIN) ?cgD3D9GetLatestVertexProfile():cgD3D9GetLatestPixelProfile(); else #endif { mProfile = (aProfileDomain == CG_VERTEX_DOMAIN) ?cgGLGetLatestProfile(CG_GL_VERTEX):cgGLGetLatestProfile(CG_GL_FRAGMENT ); cgGLSetOptimalOptions(mProfile); checkForCgError("setprofile"); } mFileName = aFileName; mEntry = aEntry; // FIXME mArgs //mArgs = aArgs; }
int main(int argc, char **argv) { glutInitWindowSize(400, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInit(&argc, argv); glutCreateWindow(myProgramName); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glClearColor(0.1, 0.3, 0.6, 0.0); /* Blue background */ myCgContext = cgCreateContext(); checkForCgError("creating context"); cgGLSetDebugMode(CG_FALSE); cgSetParameterSettingMode(myCgContext, CG_DEFERRED_PARAMETER_SETTING); myCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(myCgVertexProfile); checkForCgError("selecting vertex profile"); myCgVertexProgram = cgCreateProgramFromFile( myCgContext, /* Cg runtime context */ CG_SOURCE, /* Program in human-readable form */ myVertexProgramFileName.c_str(), /* Name of file containing program */ myCgVertexProfile, /* Profile: OpenGL ARB vertex program */ myVertexProgramName, /* Entry function name */ NULL); /* No extra compiler options */ checkForCgError("creating vertex program from file"); cgGLLoadProgram(myCgVertexProgram); checkForCgError("loading vertex program"); glutMainLoop(); return 0; }
void InitScreenGlowShader(void) { bGlowShaderInitialised = false; // OPENGL EXTENSION LOADING #ifdef _WIN32 pglActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB"); #else pglActiveTextureARB = SDL_GL_GetProcAddress("glActiveTextureARB"); #endif // TEXTURE CREATION unsigned char* pBlankTex = new unsigned char[ScreenWidth*ScreenHeight*3]; memset(pBlankTex, 0, ScreenWidth*ScreenHeight*3); glGenTextures(1, &g_uiSceneTex); glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiSceneTex); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB8, ScreenWidth, ScreenHeight, 0, GL_RGB8, GL_UNSIGNED_BYTE, pBlankTex); glGenTextures(1, &g_uiBlurTex); glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiBlurTex); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB8, ScreenWidth/4, ScreenHeight/4, 0, GL_RGB8, GL_UNSIGNED_BYTE, pBlankTex); delete[] pBlankTex; // CG INITIALISATION g_cgContext = cgCreateContext(); if (!g_cgContext) { #ifdef _WIN32 MessageBox(NULL, "Couldn't make Cg context", NULL, NULL); #else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "CG", "Couldn't make Cg context", NULL); #endif return; } // VERTEX PROFILE g_cgVertProfile = cgGLGetLatestProfile(CG_GL_VERTEX); if (g_cgVertProfile == CG_PROFILE_UNKNOWN) { #ifdef _WIN32 MessageBox(NULL, "Couldn't fetch valid VP profile", NULL, NULL); #else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "CG", "Couldn't fetch valid VP profile", NULL); #endif return; } cgGLSetOptimalOptions(g_cgVertProfile); // VP LOADING if (!LoadProgram(&g_cgVP_GlowDarken, g_cgVertProfile, "cgshaders/glow_darken_vp.cg")) return; if (!LoadProgram(&g_cgVP_GlowBlur, g_cgVertProfile, "cgshaders/glow_blur_vp.cg")) return; if (!LoadProgram(&g_cgVP_GlowCombine, g_cgVertProfile, "cgshaders/glow_combine_vp.cg")) return; // VP PARAM GRABBING g_cgpVP0_ModelViewMatrix = cgGetNamedParameter(g_cgVP_GlowDarken, "ModelViewProj"); g_cgpVP1_ModelViewMatrix = cgGetNamedParameter(g_cgVP_GlowBlur, "ModelViewProj"); g_cgpVP1_XOffset = cgGetNamedParameter(g_cgVP_GlowBlur, "XOffset"); g_cgpVP1_YOffset = cgGetNamedParameter(g_cgVP_GlowBlur, "YOffset"); g_cgpVP2_ModelViewMatrix = cgGetNamedParameter(g_cgVP_GlowCombine, "ModelViewProj"); // FRAGMENT PROFILE g_cgFragProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); if (g_cgFragProfile == CG_PROFILE_UNKNOWN) { #ifdef _WIN32 MessageBox(NULL, "Couldn't fetch valid VP profile", NULL, NULL); #else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "CG", "Couldn't fetch valid VP profile", NULL); #endif return; } cgGLSetOptimalOptions(g_cgFragProfile); // FP LOADING if (!LoadProgram(&g_cgFP_GlowDarken, g_cgFragProfile, "cgshaders/glow_darken_fp.cg")) return; if (!LoadProgram(&g_cgFP_GlowBlur, g_cgFragProfile, "cgshaders/glow_blur_fp.cg")) return; if (!LoadProgram(&g_cgFP_GlowCombine, g_cgFragProfile, "cgshaders/glow_combine_fp.cg")) return; bGlowShaderInitialised = true; }
bool CGLCG::LoadShader(const TCHAR *shaderFile) { CCGShader cgShader; TCHAR shaderPath[MAX_PATH]; TCHAR tempPath[MAX_PATH]; CGprofile vertexProfile, fragmentProfile; GLenum error; if(!fboFunctionsLoaded) { MessageBox(NULL, TEXT("Your OpenGL graphics driver does not support framebuffer objects.\nYou will not be able to use CG shaders in OpenGL mode."), TEXT("CG Error"), MB_OK|MB_ICONEXCLAMATION); return false; } vertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLDisableProfile(vertexProfile); cgGLDisableProfile(fragmentProfile); ClearPasses(); if (shaderFile == NULL || *shaderFile==TEXT('\0')) return true; lstrcpy(shaderPath, shaderFile); ReduceToPath(shaderPath); SetCurrentDirectory(shaderPath); if(!cgShader.LoadShader(_tToChar(shaderFile))) return false; cgGLSetOptimalOptions(vertexProfile); cgGLSetOptimalOptions(fragmentProfile); /* insert dummy pass that will contain the original texture */ shaderPasses.push_back(shaderPass()); for(CCGShader::passVector::iterator it=cgShader.shaderPasses.begin(); it!=cgShader.shaderPasses.end();it++) { shaderPass pass; pass.scaleParams = it->scaleParams; /* if this is the last pass (the only one that can have CG_SCALE_NONE) and no filter has been set use the GUI setting */ if(pass.scaleParams.scaleTypeX==CG_SCALE_NONE && !it->filterSet) { pass.linearFilter = GUI.BilinearFilter; } else { pass.linearFilter = it->linearFilter; } pass.frameCounterMod = it->frameCounterMod; pass.floatFbo = it->floatFbo; // paths in the meta file can be relative _tfullpath(tempPath,_tFromChar(it->cgShaderFile),MAX_PATH); char *fileContents = ReadShaderFileContents(tempPath); if(!fileContents) return false; // individual shader might include files, these should be relative to shader ReduceToPath(tempPath); SetCurrentDirectory(tempPath); pass.cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents, vertexProfile, "main_vertex", NULL); checkForCgError("Compiling vertex program"); pass.cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents, fragmentProfile, "main_fragment", NULL); checkForCgError("Compiling fragment program"); // set path back for next pass SetCurrentDirectory(shaderPath); delete [] fileContents; if(!pass.cgVertexProgram || !pass.cgFragmentProgram) { return false; } cgGLLoadProgram(pass.cgVertexProgram); cgGLLoadProgram(pass.cgFragmentProgram); /* generate framebuffer and texture for this pass and apply default texture settings */ glGenFramebuffers(1,&pass.fbo); glGenTextures(1,&pass.tex); glBindTexture(GL_TEXTURE_2D,pass.tex); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); shaderPasses.push_back(pass); } for(std::vector<CCGShader::lookupTexture>::iterator it=cgShader.lookupTextures.begin();it!=cgShader.lookupTextures.end();it++) { lookupTexture tex; strcpy(tex.id,it->id); /* generate texture for the lut and apply specified filter setting */ glGenTextures(1,&tex.tex); glBindTexture(GL_TEXTURE_2D,tex.tex); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, it->linearfilter?GL_LINEAR:GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, it->linearfilter?GL_LINEAR:GL_NEAREST); _tfullpath(tempPath,_tFromChar(it->texturePath),MAX_PATH); // simple file extension png/tga decision int strLen = strlen(it->texturePath); if(strLen>4) { if(!strcasecmp(&it->texturePath[strLen-4],".png")) { int width, height; bool hasAlpha; GLubyte *texData; if(loadPngImage(tempPath,width,height,hasAlpha,&texData)) { glPixelStorei(GL_UNPACK_ROW_LENGTH, width); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, hasAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, texData); free(texData); } } else if(!strcasecmp(&it->texturePath[strLen-4],".tga")) { STGA stga; if(loadTGA(tempPath,stga)) { glPixelStorei(GL_UNPACK_ROW_LENGTH, stga.width); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, stga.width, stga.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, stga.data); } } } lookupTextures.push_back(tex); } /* enable texture unit 1 for the lookup textures */ glClientActiveTexture(GL_TEXTURE1); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2,GL_FLOAT,0,lut_coords); glClientActiveTexture(GL_TEXTURE0); /* generate textures and set default values for the pref-filled PREV deque. */ for(int i=0;i<prevPasses.size();i++) { glGenTextures(1,&prevPasses[i].tex); glBindTexture(GL_TEXTURE_2D,prevPasses[i].tex); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,NULL); glBindTexture(GL_TEXTURE_2D,0); prevPasses[i].textureSize.x = prevPasses[i].textureSize.y = prevPasses[i].textureSize.x = prevPasses[i].textureSize.y = 0; memset(prevPasses[i].texCoords,0,sizeof(prevPasses[i].texCoords)); } shaderLoaded = true; return true; }
void InitCg() { cgSetErrorCallback(CgErrorCallback); Context = cgCreateContext(); VertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); printf("VertexProfile %s\n", cgGetProfileString(VertexProfile)); cgGLSetOptimalOptions(VertexProfile); FragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); printf("FragmentProfile %s\n", cgGetProfileString(FragmentProfile)); cgGLSetOptimalOptions(FragmentProfile); VP_DrawSites = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_DrawSites.cg", VertexProfile, NULL, NULL); FP_DrawSites = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_DrawSites.cg", FragmentProfile, NULL, NULL); VP_Flood = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_Flood.cg", VertexProfile, NULL, NULL); FP_Flood = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_Flood.cg", FragmentProfile, NULL, NULL); VP_Scatter = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_Scatter.cg", VertexProfile, NULL, NULL); FP_Scatter = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_Scatter.cg", FragmentProfile, NULL, NULL); VP_DrawNewSites = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_DrawNewSites.cg", VertexProfile, NULL, NULL); FP_DrawNewSites = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_DrawNewSites.cg", FragmentProfile, NULL, NULL); VP_DrawSitesOQ = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_DrawSitesOQ.cg", VertexProfile, NULL, NULL); FP_DrawSitesOQ = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_DrawSitesOQ.cg", FragmentProfile, NULL, NULL); VP_FinalRender = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_FinalRender.cg", VertexProfile, NULL, NULL); FP_FinalRender = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_FinalRender.cg", FragmentProfile, NULL, NULL); VP_ComputeEnergy = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_ComputeEnergy.cg", VertexProfile, NULL, NULL); FP_ComputeEnergy = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_ComputeEnergy.cg", FragmentProfile, NULL, NULL); VP_Deduction = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_Deduction.cg", VertexProfile, NULL, NULL); FP_Deduction = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_Deduction.cg", FragmentProfile, NULL, NULL); VP_ComputeEnergyCentroid = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_ComputeEnergyCentroid.cg", VertexProfile, NULL, NULL); FP_ComputeEnergyCentroid = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_ComputeEnergyCentroid.cg", FragmentProfile, NULL, NULL); VP_ScatterCentroid = cgCreateProgramFromFile(Context, CG_SOURCE, "VP_ScatterCentroid.cg", VertexProfile, NULL, NULL); FP_ScatterCentroid = cgCreateProgramFromFile(Context, CG_SOURCE, "FP_ScatterCentroid.cg", FragmentProfile, NULL, NULL); if(VP_DrawSites != NULL) { cgGLLoadProgram(VP_DrawSites); } if(FP_DrawSites != NULL) { cgGLLoadProgram(FP_DrawSites); } if(VP_Flood != NULL) { cgGLLoadProgram(VP_Flood); // Bind parameters to give access to variables in the shader VP_Flood_Steplength = cgGetNamedParameter(VP_Flood, "steplength"); VP_Flood_Size = cgGetNamedParameter(VP_Flood, "size"); } if(FP_Flood != NULL) { cgGLLoadProgram(FP_Flood); } if(VP_Scatter != NULL) { cgGLLoadProgram(VP_Scatter); // Bind parameters to give access to variables in the shader VP_Scatter_Size = cgGetNamedParameter(VP_Scatter, "size"); } if(FP_Scatter != NULL) { cgGLLoadProgram(FP_Scatter); } if(VP_DrawNewSites != NULL) { cgGLLoadProgram(VP_DrawNewSites); // Bind parameters to give access to variables in the shader VP_DrawNewSites_Size = cgGetNamedParameter(VP_DrawNewSites, "size"); } if(FP_DrawNewSites != NULL) { cgGLLoadProgram(FP_DrawNewSites); } if(VP_DrawSitesOQ != NULL) { cgGLLoadProgram(VP_DrawSitesOQ); // Bind parameters to give access to variables in the shader VP_DrawSitesOQ_Size = cgGetNamedParameter(VP_DrawSitesOQ, "size"); } if(FP_DrawSitesOQ != NULL) { cgGLLoadProgram(FP_DrawSitesOQ); } if(VP_FinalRender != NULL) { cgGLLoadProgram(VP_FinalRender); } if(FP_FinalRender != NULL) { cgGLLoadProgram(FP_FinalRender); // Bind parameters to give access to variables in the shader FP_FinalRender_Size = cgGetNamedParameter(FP_FinalRender, "size"); } if(VP_ComputeEnergy != NULL) { cgGLLoadProgram(VP_ComputeEnergy); } if(FP_ComputeEnergy != NULL) { cgGLLoadProgram(FP_ComputeEnergy); // Bind parameters to give access to variables in the shader FP_ComputeEnergy_Size = cgGetNamedParameter(FP_ComputeEnergy, "size"); } if(VP_Deduction != NULL) { cgGLLoadProgram(VP_Deduction); } if(FP_Deduction != NULL) { cgGLLoadProgram(FP_Deduction); } if(VP_ComputeEnergyCentroid != NULL) { cgGLLoadProgram(VP_ComputeEnergyCentroid); } if(FP_ComputeEnergyCentroid != NULL) { cgGLLoadProgram(FP_ComputeEnergyCentroid); // Bind parameters to give access to variables in the shader FP_ComputeEnergyCentroid_Size = cgGetNamedParameter(FP_ComputeEnergyCentroid, "size"); } if(VP_ScatterCentroid != NULL) { cgGLLoadProgram(VP_ScatterCentroid); // Bind parameters to give access to variables in the shader VP_ScatterCentroid_Size = cgGetNamedParameter(VP_ScatterCentroid, "size"); } if(FP_ScatterCentroid != NULL) { cgGLLoadProgram(FP_ScatterCentroid); } }
static bool gl_cg_init(const char *path) { unsigned i; #ifdef HAVE_CG_RUNTIME_COMPILER cgRTCgcInit(); #endif if (!cgCtx) cgCtx = cgCreateContext(); if (cgCtx == NULL) { RARCH_ERR("Failed to create Cg context\n"); return false; } #ifdef RARCH_CG_DEBUG cgGLSetDebugMode(CG_TRUE); cgSetErrorHandler(cg_error_handler, NULL); #endif cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX); if (cgFProf == CG_PROFILE_UNKNOWN || cgVProf == CG_PROFILE_UNKNOWN) { RARCH_ERR("Invalid profile type\n"); goto error; } #ifndef HAVE_RGL RARCH_LOG("[Cg]: Vertex profile: %s\n", cgGetProfileString(cgVProf)); RARCH_LOG("[Cg]: Fragment profile: %s\n", cgGetProfileString(cgFProf)); #endif cgGLSetOptimalOptions(cgFProf); cgGLSetOptimalOptions(cgVProf); cgGLEnableProfile(cgFProf); cgGLEnableProfile(cgVProf); if (path && strcmp(path_get_extension(path), "cgp") == 0) { if (!load_preset(path)) goto error; } else { if (!load_plain(path)) goto error; } prg[0].mvp = cgGetNamedParameter(prg[0].vprg, "IN.mvp_matrix"); for (i = 1; i <= cg_shader->passes; i++) set_program_attributes(i); // If we aren't using last pass non-FBO shader, // this shader will be assumed to be "fixed-function". // Just use prg[0] for that pass, which will be // pass-through. prg[cg_shader->passes + 1] = prg[0]; // No need to apply Android hack in Cg. prg[GL_SHADER_STOCK_BLEND] = prg[0]; cgGLBindProgram(prg[1].fprg); cgGLBindProgram(prg[1].vprg); cg_active = true; return true; error: gl_cg_deinit(); return false; }
void CgCompile () { VShader* s; FShader* fs; unsigned i; //Setup Cg cgContext = cgCreateContext(); checkForCgError (cgGetError(), "Init", "Establishing Cg context"); cgp_fragment = cgGLGetLatestProfile (CG_GL_FRAGMENT); checkForCgError (cgGetError(), "Init", "Establishing Cg Fragment profile"); cgGLEnableProfile (cgp_fragment); cgGLSetOptimalOptions (cgp_fragment); //Now set up our list of shaders for (i = 0; i < FSHADER_COUNT; i++) { fs = &fshader_list[i]; // Load And Compile The Vertex Shader From File fs->program = cgCreateProgramFromFile (cgContext, CG_SOURCE, FSHADER_FILE, cgp_fragment, fshader_function[i], 0); checkForCgError (cgGetError(), fshader_function[i], "Compiling"); // Load The Program cgGLLoadProgram (fs->program); cgGLBindProgram (fs->program); checkForCgError (cgGetError(), fshader_function[i], "Binding"); fs->texture = cgGetNamedParameter (fs->program, "texture2"); fs->fogcolor = cgGetNamedParameter (fs->program, "fogcolor"); fs->data = cgGetNamedParameter (fs->program, "data"); checkForCgError (cgGetError(), fshader_function[i], "Loading variables"); } cgp_vertex = cgGLGetLatestProfile (CG_GL_VERTEX); checkForCgError (cgGetError(), "Init", "Establishing Cg Vertex profile"); cgGLEnableProfile (cgp_vertex); cgGLSetOptimalOptions (cgp_vertex);// Set The Current Profile //Now set up our list of shaders for (i = 0; i < VSHADER_COUNT; i++) { s = &vshader_list[i]; // Load And Compile The Vertex Shader From File s->program = cgCreateProgramFromFile (cgContext, CG_SOURCE, VSHADER_FILE, cgp_vertex, vshader_function[i], 0); checkForCgError (cgGetError(), vshader_function[i], "Compiling"); // Load The Program cgGLLoadProgram (s->program); cgGLBindProgram (s->program); // Get Handles To Each Of Our Parameters So That // We Can Change Them At Will Within Our Code s->position = cgGetNamedParameter(s->program, "IN.position"); s->offset = cgGetNamedParameter(s->program, "offset"); s->lightpos = cgGetNamedParameter(s->program, "lightpos"); s->eyepos = cgGetNamedParameter(s->program, "eyepos"); s->lightcol = cgGetNamedParameter(s->program, "lightcol"); s->ambientcol = cgGetNamedParameter(s->program, "ambientcol"); s->fog = cgGetNamedParameter(s->program, "fogdist"); s->data = cgGetNamedParameter(s->program, "data"); s->matrix = cgGetNamedParameter(s->program, "ModelViewProj"); } cgGLDisableProfile (cgp_fragment); cgGLDisableProfile (cgp_vertex); }
bool cgShader::Reload(){ for(int k = 0; k < 3; k++){ if(cgProgram[k]){ cgDestroyProgram(cgProgram[k]); } } cgProfile[0] = cgProfile[1] = cgProfile[2] = CG_PROFILE_UNKNOWN; cgProgram[0] = cgProgram[1] = cgProgram[2] = NULL; bool ret = true; if(cgGetContext()){ for(int i = 0; i < 3; i++){ if(i == 0 && vpmain == 0){ continue; } if(i == 1 && gpmain == 0){ continue; } if(i == 2 && fpmain == 0){ continue; } switch(i){ case 0: cgProfile[i] = cgGLGetLatestProfile(CG_GL_VERTEX); break; case 1: cgProfile[i] = cgGLGetLatestProfile(CG_GL_GEOMETRY); break; case 2: cgProfile[i] = cgGLGetLatestProfile(CG_GL_FRAGMENT); break; } if (cgProfile[i] == CG_PROFILE_UNKNOWN){ printf("Invalid profile type ("); switch(i){ case 0: printf("CG_GL_VERTEX)\n"); break; case 1: printf("CG_GL_GEOMETRY)\n"); break; case 2: printf("CG_GL_FRAGMENT)\n"); break; } ret = false; continue; } cgGLSetOptimalOptions(cgProfile[i]); if(code){ switch(i){ case 0: cgProgram[i] = cgCreateProgram(cgGetContext(), CG_SOURCE, code, cgProfile[i], vpmain, 0); break; case 1: cgProgram[i] = cgCreateProgram(cgGetContext(), CG_SOURCE, code, cgProfile[i], gpmain, 0); break; case 2: cgProgram[i] = cgCreateProgram(cgGetContext(), CG_SOURCE, code, cgProfile[i], fpmain, 0); break; } } else{ switch(i){ case 0: cgProgram[i] = cgCreateProgramFromFile(cgGetContext(), CG_SOURCE, fname, cgProfile[i], vpmain, 0); break; case 1: cgProgram[i] = cgCreateProgramFromFile(cgGetContext(), CG_SOURCE, fname, cgProfile[i], gpmain, 0); break; case 2: cgProgram[i] = cgCreateProgramFromFile(cgGetContext(), CG_SOURCE, fname, cgProfile[i], fpmain, 0); break; } } if (cgProgram[i] == NULL){ switch(i){ case 0: printf("CG ERROR (VERTEX) : %s\n", cgGetErrorString(cgGetError())); break; case 1: printf("CG ERROR (GEOMETRY) : %s\n",cgGetErrorString(cgGetError())); break; case 2: printf("CG ERROR (FRAGMENT) : %s\n",cgGetErrorString(cgGetError())); break; } ret = false; continue; } cgGLLoadProgram(cgProgram[i]); } } if(loaded){ if(ret){ printf("INFO (cgShader): Reloaded %s successfully\n",fname); } else{ printf("INFO (cgShader): Reloading %s failed\n",fname); } } else{ if(ret){ printf("INFO (cgShader): Loaded %s successfully\n",fname); } else{ printf("INFO (cgShader): Loading %s failed\n",fname); } } loaded = true; return ret; }
bool cgShader_3::Reload(){ for(int k = 0; k < 5; k++){ if(cgProgram[k]){ cgDestroyProgram(cgProgram[k]); } cgProfile[k] = CG_PROFILE_UNKNOWN; cgProgram[k] = NULL; } bool ret = true; if(cgGetContext()){ for(int i = 0; i < 5; i++){ if( main[i] == 0 ){ continue; } switch(i){ case 0: cgProfile[i] = cgGLGetLatestProfile(CG_GL_VERTEX); break; case 1: cgProfile[i] = cgGLGetLatestProfile(CG_GL_TESSELLATION_CONTROL); break; case 2: cgProfile[i] = cgGLGetLatestProfile(CG_GL_TESSELLATION_EVALUATION); break; case 3: cgProfile[i] = cgGLGetLatestProfile(CG_GL_GEOMETRY); break; case 4: cgProfile[i] = cgGLGetLatestProfile(CG_GL_FRAGMENT); break; } if (cgProfile[i] == CG_PROFILE_UNKNOWN){ printf("Invalid profile type ("); switch(i){ case 0: printf("CG_GL_VERTEX)\n"); break; case 1: printf("CG_GL_TESSELLATION_CONTROL)\n"); break; case 2: printf("CG_GL_TESSELLATION_EVALUATION)\n"); break; case 3: printf("CG_GL_GEOMETRY)\n"); break; case 4: printf("CG_GL_FRAGMENT)\n"); break; } ret = false; continue; } cgGLSetOptimalOptions(cgProfile[i]); if(code){ cgProgram[i] = cgCreateProgram(cgGetContext(), CG_SOURCE, code, cgProfile[i], main[i], 0); } else{ cgProgram[i] = cgCreateProgramFromFile(cgGetContext(), CG_SOURCE, fname, cgProfile[i], main[i], 0); } if (cgProgram[i] == NULL){ switch(i){ case 0: printf("CG ERROR (VERTEX) : %s\n", cgGetErrorString(cgGetError())); break; case 1: printf("CG ERROR (TESS_CTRL) : %s\n",cgGetErrorString(cgGetError())); break; case 2: printf("CG ERROR (TESS_EVAL) : %s\n",cgGetErrorString(cgGetError())); break; case 3: printf("CG ERROR (GEOMETRY) : %s\n", cgGetErrorString(cgGetError())); break; case 4: printf("CG ERROR (FRAGMENT) : %s\n", cgGetErrorString(cgGetError())); break; } ret = false; continue; } cgGLLoadProgram(cgProgram[i]); } } if(loaded){ if(ret){ printf("INFO (cgShader): Reloaded %s successfully\n",fname); } else{ printf("INFO (cgShader): Reloading %s failed\n",fname); } } else{ if(ret){ printf("INFO (cgShader): Loaded %s successfully\n",fname); } else{ printf("INFO (cgShader): Loading %s failed\n",fname); } } loaded = true; return ret; }
void Sarge::InitializeSargeShaders() { TextureLoader textureLoader; ///////////////////////////// //Vertex Shader vsSargeProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(vsSargeProfile); CheckForCgError("sarge", "selecting vertex profile"); vsSargeProgram = cgCreateProgramFromFile(ShaderContext, CG_SOURCE, "assets/vertexshaders/vs_sarge.cg", vsSargeProfile, "sargeVertexShader", 0); CheckForCgError("sarge", "creating vertex program from file"); cgGLLoadProgram(vsSargeProgram); CheckForCgError("sarge", "loading vertex program"); ////////////////////////////// //Pixel Shader psSargeProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(psSargeProfile); CheckForCgError("sarge", "selecting pixel profile"); psSargeProgram = cgCreateProgramFromFile(ShaderContext, CG_SOURCE, "assets/pixelshaders/ps_sarge.cg", psSargeProfile, "sargeLightMap", 0); CheckForCgError("sarge", "creating fragment program from file"); cgGLLoadProgram(psSargeProgram); CheckForCgError("sarge", "loading fragment program"); modelViewProj = cgGetNamedParameter(vsSargeProgram, "modelViewProj"); lightViewProj = cgGetNamedParameter(vsSargeProgram, "lightViewProj"); vertin = cgGetNamedParameter(vsSargeProgram, "vertin"); lightPosition = cgGetNamedParameter(vsSargeProgram, "lightPosition"); fragin = cgGetNamedParameter(psSargeProgram, "fragin"); eyevector = cgGetNamedParameter(psSargeProgram, "eyevector"); CheckForCgError("sarge", "getting parameters"); textureLoader.LoadTextureFromDisk("assets/textures/shadermaps/sarge_normalmap.tga", &sargeNormalTexture); textureLoader.LoadTextureFromDisk("assets/textures/shadermaps/sarge_colormap.tga", &sargeColorTexture); //textureLoader.LoadTextureFromDisk("assets/textures/weapon/fire1.tga", &sargeColorTexture); normalmap = cgGetNamedParameter(psSargeProgram, "normalmap"); cgGLSetTextureParameter(normalmap, sargeNormalTexture.TextureID); decalmap = cgGetNamedParameter(psSargeProgram, "decalmap"); cgGLSetTextureParameter(decalmap, sargeColorTexture.TextureID); CheckForCgError("sarge", "setting decal 2D texture"); /* decalmap = cgGetNamedParameter(psSargeProgram, "decalmap"); cgGLSetTextureParameter(text1, sargeColorTexture.TextureID); CheckForCgError("sarge", "setting decal 2D texture"); */ mMeshObject.Scale(1.6f); }
void CG_initialize(void) { cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(cgVertexProfile); cgGLSetOptimalOptions(cgFragmentProfile); cgContext = cgCreateContext(); cgVertexProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "CG_ENVIRO_MAPPING/oglu_per_vertex_reflective_environment_mapping_vs.cg", cgVertexProfile, NULL, NULL); cgGLLoadProgram(cgVertexProgram); enviroCgVertexParam_lightPosition = cgGetNamedParameter(cgVertexProgram, "lightPosition"); enviroCgVertexParam_globalAmbient = cgGetNamedParameter(cgVertexProgram, "globalAmbient"); enviroCgVertexParam_lightColor = cgGetNamedParameter(cgVertexProgram, "lightColor"); //enviroCgVertexParam_Ke = cgGetNamedParameter(cgVertexProgram, "Ke"); enviroCgVertexParam_Ka = cgGetNamedParameter(cgVertexProgram, "Ka"); enviroCgVertexParam_Kd = cgGetNamedParameter(cgVertexProgram, "Kd"); enviroCgVertexParam_Ks = cgGetNamedParameter(cgVertexProgram, "Ks"); enviroCgVertexParam_shininess = cgGetNamedParameter(cgVertexProgram, "shininess"); enviroCgVertexParam_time = cgGetNamedParameter(cgVertexProgram, "time"); cgModelViewProj = cgGetNamedParameter(cgVertexProgram, "ModelViewProj"); cgModelView = cgGetNamedParameter(cgVertexProgram, "ModelView"); cgModelViewI = cgGetNamedParameter(cgVertexProgram, "ModelViewI"); cgModelViewIT = cgGetNamedParameter(cgVertexProgram, "ModelViewIT"); cgPosition = cgGetNamedParameter(cgVertexProgram, "position"); cgNormal = cgGetNamedParameter(cgVertexProgram, "N"); cgTexcoords = cgGetNamedParameter(cgVertexProgram, "texCoord"); cgEyePosition = cgGetNamedParameter(cgVertexProgram, "eyePosition"); cgGLSetParameter3f(cgEyePosition, 0, 0, 0); cgFragmentProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "CG_ENVIRO_MAPPING/oglu_per_vertex_reflective_environment_mapping_ps.cg", cgFragmentProfile, NULL, NULL ); cgGLLoadProgram(cgFragmentProgram); cgEnvironmentMap = cgGetNamedParameter(cgFragmentProgram, "environmentMap"); loadCubeMap(); cgGLSetTextureParameter(cgEnvironmentMap, cubemapTexture[0]); }
int main(int argc, char **argv) { glutInitWindowSize(800, 800); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInit(&argc, argv); glutCreateWindow(myProgramName); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutMouseFunc(mouse); glClearColor(0.1, 0.1, 0.1, 0); /* Gray background. */ glEnable(GL_DEPTH_TEST); /* Hidden surface removal. */ myCgContext = cgCreateContext(); checkForCgError("creating context"); cgGLSetDebugMode( CG_FALSE ); myCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(myCgVertexProfile); checkForCgError("selecting vertex profile"); myCgVertexProgram = cgCreateProgramFromFile( myCgContext, /* Cg runtime context */ CG_SOURCE, /* Program in human-readable form */ myVertexProgramFileName, /* Name of file containing program */ myCgVertexProfile, /* Profile: OpenGL ARB vertex program */ myVertexProgramName, /* Entry function name */ NULL); /* No extra commyPiler options */ checkForCgError("creating vertex program from file"); cgGLLoadProgram(myCgVertexProgram); checkForCgError("loading vertex program"); #define GET_VERTEX_PARAM(name) \ myCgVertexParam_##name = \ cgGetNamedParameter(myCgVertexProgram, #name); \ checkForCgError("could not get " #name " parameter"); GET_VERTEX_PARAM(modelViewProj); myCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(myCgFragmentProfile); checkForCgError("selecting fragment profile"); myCgFragmentProgram = cgCreateProgramFromFile( myCgContext, /* Cg runtime context */ CG_SOURCE, /* Program in human-readable form */ myFragmentProgramFileName, myCgFragmentProfile, /* Profile: latest fragment profile */ myFragmentProgramName, /* Entry function name */ NULL); /* No extra commyPiler options */ checkForCgError("creating fragment program from string"); cgGLLoadProgram(myCgFragmentProgram); checkForCgError("loading fragment program"); #define GET_FRAGMENT_PARAM(name) \ myCgFragmentParam_##name = \ cgGetNamedParameter(myCgFragmentProgram, #name); \ checkForCgError("could not get " #name " parameter"); GET_FRAGMENT_PARAM(globalAmbient); GET_FRAGMENT_PARAM(lightColor); GET_FRAGMENT_PARAM(lightPosition); GET_FRAGMENT_PARAM(eyePosition); GET_FRAGMENT_PARAM(Ke); GET_FRAGMENT_PARAM(Ka); GET_FRAGMENT_PARAM(Kd); GET_FRAGMENT_PARAM(Ks); GET_FRAGMENT_PARAM(shininess); /* Set light source color parameters once. */ cgSetParameter3fv(myCgFragmentParam_globalAmbient, myGlobalAmbient); cgSetParameter3fv(myCgFragmentParam_lightColor, myLightColor); stickangle=90+angle; w.xspeed=0 ; w.zspeed=0; w.x=0;w.y=4;w.z=30; w.r=1;w.g=1;w.b=1; r.x=-34;r.y=4;r.z=-80; r.r=1;r.g=0;r.b=0; b.x=26;b.y=4;b.z=-40; b.r=0;b.g=0;b.b=0; w.flag=1; r.flag=1; b.flag=1; w.xspeed=0; w.zspeed=0; r.zspeed=0; r.xspeed=0; b.xspeed=0; b.zspeed=0; enablestick=1; printf("Billiards! By :\n"); printf("Prabhat Kumar Gupta\t 2007MCS2895\n"); printf("Nidhi Arora\t\t 2007MCS2913\t\n"); printf("-----------------------------------------------\n"); printf("\t\tControls\n"); printf("-----------------------------------------------\n"); printf("Control:\t\tAction\n"); printf("-----------------------------------------------\n"); printf("LeftClick/Spacebar\tEnable Stick and Strike\n"); printf("z\t\t\tRotate Stick Left\n"); printf("x\t\t\tRotate Stick Right\n"); printf("n\t\t\tZoom In\n"); printf("m\t\t\tZoom Out\n"); printf("1\t\t\tCamera 1\n"); printf("2\t\t\tCamera 2\n"); printf("3\t\t\tCamera 3\n"); printf("4\t\t\tCamera 4\n"); printf("-----------------------------------------------\n"); glutCreateMenu(menu); glutAddMenuEntry("[ ] Animate", ' '); glutAddMenuEntry("[ ] Camera1",'1'); glutAddMenuEntry("[ ] Camera2",'2'); glutAddMenuEntry("[ ] Camera3",'3'); glutAddMenuEntry("[ ] Camera4",'4'); glutAttachMenu(GLUT_RIGHT_BUTTON); glutMainLoop(); return 0; }
static void *gl_cg_init(void *data, const char *path) { unsigned i; cg_shader_data_t *cg_data = (cg_shader_data_t*) calloc(1, sizeof(cg_shader_data_t)); if (!cg_data) return NULL; #ifdef HAVE_CG_RUNTIME_COMPILER cgRTCgcInit(); #endif cg_data->cgCtx = cgCreateContext(); if (!cg_data->cgCtx) { RARCH_ERR("Failed to create Cg context.\n"); goto error; } #ifdef RARCH_CG_DEBUG cgGLSetDebugMode(CG_TRUE); cgSetErrorHandler(cg_error_handler, NULL); #endif cg_data->cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); cg_data->cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX); if ( cg_data->cgFProf == CG_PROFILE_UNKNOWN || cg_data->cgVProf == CG_PROFILE_UNKNOWN) { RARCH_ERR("Invalid profile type\n"); free(cg_data); cg_data = NULL; goto error; } RARCH_LOG("[Cg]: Vertex profile: %s\n", cgGetProfileString(cg_data->cgVProf)); RARCH_LOG("[Cg]: Fragment profile: %s\n", cgGetProfileString(cg_data->cgFProf)); cgGLSetOptimalOptions(cg_data->cgFProf); cgGLSetOptimalOptions(cg_data->cgVProf); cgGLEnableProfile(cg_data->cgFProf); cgGLEnableProfile(cg_data->cgVProf); memset(cg_data->cg_alias_define, 0, sizeof(cg_data->cg_alias_define)); if (path && string_is_equal(path_get_extension(path), "cgp")) { if (!gl_cg_load_preset(cg_data, path)) goto error; } else { if (!gl_cg_load_plain(cg_data, path)) goto error; } cg_data->prg[0].mvp = cgGetNamedParameter(cg_data->prg[0].vprg, "IN.mvp_matrix"); for (i = 1; i <= cg_data->shader->passes; i++) gl_cg_set_program_attributes(cg_data, i); /* If we aren't using last pass non-FBO shader, * this shader will be assumed to be "fixed-function". * * Just use prg[0] for that pass, which will be * pass-through. */ cg_data->prg[cg_data->shader->passes + 1] = cg_data->prg[0]; /* No need to apply Android hack in Cg. */ cg_data->prg[GL_SHADER_STOCK_BLEND] = cg_data->prg[0]; cgGLBindProgram(cg_data->prg[1].fprg); cgGLBindProgram(cg_data->prg[1].vprg); return cg_data; error: gl_cg_destroy_resources(cg_data); if (!cg_data) free(cg_data); return NULL; }
void Skydome::InitializeSkydomeShaders() { TextureLoader textureLoader; glTexture daySky, nightSky, redSky, sun, sunMask; textureLoader.LoadTextureFromDisk("assets/textures/sky/clouds2.tga", &daySky); textureLoader.LoadTextureFromDisk("assets/textures/sky/night.tga", &nightSky); textureLoader.LoadTextureFromDisk("assets/textures/sky/red.tga", &redSky); /* //Vertext Shader profile vsSkydomeProfile = cgGLGetLatestProfile(CG_GL_VERTEX); //Set profile cgGLSetOptimalOptions(vsFireballProfile); CheckForCgError("skydome", "selecting vertex profile"); //Load vertex shader vsFireballProgram = cgCreateProgramFromFile(ShaderContext, CG_SOURCE, "assets/vertexshaders/vs_fireball.cg", vsFireballProfile, "vertMain", 0); CheckForCgError("skydome", "creating vertex program from file"); cgGLLoadProgram(vsFireballProgram); CheckForCgError("skydome", "loading vertex program"); texVert = cgGetNamedParameter(vsFireballProgram, "texCoordIN"); position = cgGetNamedParameter(vsFireballProgram, "posIN"); move = cgGetNamedParameter(vsFireballProgram, "move"); mvMatrix = cgGetNamedParameter(vsFireballProgram, "ModelViewProj"); */ ///////////////////////////// //Pixel Shader psSkydomeProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(psSkydomeProfile); CheckForCgError("skydome", "selecting Skydome fragment profile"); psSkydomeProgram = cgCreateProgramFromFile(ShaderContext, CG_SOURCE, "assets/pixelshaders/ps_skydome.cg", psSkydomeProfile, "pixelMain", 0); CheckForCgError("skydome", "creating fragment program from file"); cgGLLoadProgram(psSkydomeProgram); CheckForCgError("skydome", "loading fragment program"); texcoord0 = cgGetNamedParameter(psSkydomeProgram, "texcoord0"); dayTime = cgGetNamedParameter(psSkydomeProgram, "lightdist"); transition = cgGetNamedParameter(psSkydomeProgram, "transition"); text1 = cgGetNamedParameter(psSkydomeProgram, "text1"); cgGLSetTextureParameter(text1, daySky.TextureID); text2 = cgGetNamedParameter(psSkydomeProgram, "text2"); cgGLSetTextureParameter(text2, nightSky.TextureID); text3 = cgGetNamedParameter(psSkydomeProgram, "text3"); cgGLSetTextureParameter(text3, redSky.TextureID); CheckForCgError("skydome", "setting decal 2D texture"); textureLoader.LoadTextureFromDisk("assets/textures/sky/sun.tga", &sun); textureLoader.LoadTextureFromDisk("assets/textures/sky/sunmask.tga", &sunMask); psSkydomeSunProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(psSkydomeSunProfile); CheckForCgError("skydome", "selecting Skydome sun fragment profile"); psSkydomeSunProgram = cgCreateProgramFromFile(ShaderContext, CG_SOURCE, "assets/pixelshaders/ps_skydomeSun.cg", psSkydomeSunProfile, "pixelMain", 0); CheckForCgError("skydome", "creating fragment program from file"); cgGLLoadProgram(psSkydomeSunProgram); CheckForCgError("skydome", "loading fragment program"); texcoord0 = cgGetNamedParameter(psSkydomeSunProgram, "texcoord0"); suntext1 = cgGetNamedParameter(psSkydomeSunProgram, "text1"); cgGLSetTextureParameter(suntext1, sun.TextureID); suntext2 = cgGetNamedParameter(psSkydomeSunProgram, "text2"); cgGLSetTextureParameter(suntext2, sunMask.TextureID); CheckForCgError("skydome", "setting decal 2D texture"); //Temporarily Unbind Texture //glDisable(GL_TEXTURE_2D); //glDisable(GL_BLEND); // Disable Blending //glBindTexture(GL_TEXTURE_2D,0); }