void process_args(int argc, char *argv[]) { char line[MAXLINELEN]; petit_args.argv = argv; petit_args.argc = argc; petit_args.FileName = NULL; petit_args.doOEcompare=0; petit_args.depPrintFilter=0; petit_args.DDalgorithm = DDalg_omega_preproc; petit_args.DepWrFile[0] = 0; petit_args.omitScalars = 0; petit_args.omitTopLevel = 0; petit_args.graph_by_statement=true; petit_args.graph_write_dd_as_graph=false; petit_args.hpp_mode=false; petit_args.hpp_only=false; petit_args.motif_display=true; petit_args.zappable_interesting_distance=4; petit_args.normalize = 0; struct option *popt; #if ! defined NDEBUG char popt_already_found[256]; memset(popt_already_found, 0, 256); #endif for(popt=&options[0]; popt->pflag; popt++) { #if ! defined NDEBUG assert(popt_already_found[popt->symbol]++ == 0); #endif *(popt->pflag) = popt->def_value; } for(int i=0; i<argc; i++) { int c, j; char *arg; if(i==0) /* read ~/.petitrc file for flags */ { FILE *fin; sprintf(line, "%s/.petitrc", getenv("HOME")); fin = fopen(line, "r"); if(fin) { for(j=0; j<MAXLINELEN; j++) { int c = fgetc(fin); if(c==EOF || c=='\n') break; line[j] = c; } line[j] = 0; fclose(fin); arg = line; } else continue; } else arg = argv[i]; if(arg[0] == '-') { j = 1; while((c=arg[j++]) != 0) { switch(c) { case ' ': { while(arg[j] == ' ') j++; if(arg[j] == '-') { j++; continue; } if(arg[j] == 0) break; Error("file name in .petitrc file"); break; } case '?': { printf("%s", describe_options()); Exit(0); } case 'w': { petit_args.zappable_interesting_distance = atoi(&arg[j]); while(arg[j] != 0) j++; break; } case 'D': { if((c=arg[j])>='0' && c<='9') { int level = c-'0'; petit_args.dep_analysis_debug = level; j++; } else petit_args.dep_analysis_debug = 2; break; } case 'F': { while ((c=arg[j]) != ' ' && c) { switch(c) { case 'v': petit_args.depPrintFilter |= ddval; break; case 'm': petit_args.depPrintFilter |= ddmem; break; case 'c': petit_args.depPrintFilter |= ddloopCarried; break; case 'f': petit_args.depPrintFilter |= ddIsFlow; break; case 'o': petit_args.depPrintFilter |= ddIsOutput; break; case 'a': petit_args.depPrintFilter |= ddIsAnti; break; default: break; } j++; } break; } case 'P': { if (! process_pres_debugging_flags(arg,j)) { fprintf(stderr, "use Omega Library debugging like: " "{-P[facility][level]...}\n" " a = all debugging flags\n" " c = omega code\n" " g = code generation\n" " l = calculator\n" " p = presburger functions\n" " r = relational operators\n" " All debugging output goes to trace.out"); Error("badly formed Omega Library debug options"); } break; } case 'O': { if((c=arg[j])>='0' && c<='3') { omega_core_debug = c-'0'; j++; } else omega_core_debug = 1; break; } case 'W': { petit_args.uniform = 1; petit_args.normalize = 1; petit_args.zappable_interesting_distance = 0; petit_args.skipping_omega5 = 1; petit_args.makeReductionOps = 1; int jj = 0; while ( jj < MAX_UNIFORM_ARG_LENGTH && arg[j] != '\0') petit_args.uniform_args[jj++] = arg[j++]; petit_args.uniform_args[jj] = '\0'; break; } case 'X': { petit_args.li2_only = true; pres_legal_negations = one_geq_or_eq; } case 'J': { petit_args.hpp_mode = true; petit_args.hpp_only = true; } break; case 'M': { // set all presburger flags but not omega flags if((c=arg[j])>='0' && c<='3') { int level = c-'0'; pres_debug= relation_debug= code_gen_debug = level; j++; } else pres_debug= relation_debug= code_gen_debug = 1; break; } case 'a': { petit_args.DDalgorithm = 0; while((c=arg[j]) >= '0' && c <= '9') { petit_args.DDalgorithm = petit_args.DDalgorithm*10 + c-'0'; j++; } if( petit_args.DDalgorithm <= 0 ) petit_args.DDalgorithm = DDalg_omega_preproc; break; } case 'm': { petit_args.max_conjuncts = 0; while((c=arg[j]) >= '0' && c <= '9') { petit_args.max_conjuncts = petit_args.max_conjuncts*10 + c-'0'; j++; } break; } case 'x': { petit_args.doArrayExpn = 1; petit_args.expandlimit = MAXINT; petit_args.lowerdefault = 0; petit_args.upperdefault = 127; while((c = arg[j]) != 0) { j++; switch(c) { case 'd': { petit_args.expandlimit = 0; while((c=arg[j]) >= '0' && c <= '9') { petit_args.expandlimit = petit_args.expandlimit*10 + c-'0'; j++; } break; } case 'l': { petit_args.lowerdefault = 0; while((c=arg[j]) >= '0' && c <= '9') { petit_args.lowerdefault = petit_args.lowerdefault*10 + c-'0'; j++; } break; } case 'u': { petit_args.upperdefault = 0; while((c=arg[j]) >= '0' && c <= '9') { petit_args.upperdefault = petit_args.upperdefault*10 + c-'0'; j++; } break; } default: Error("bad argument for array expansion\n"); } } break; } case 'R': { // -R-name like old -Sname; -R--name like old -Vname if (arg[j] == '-') { j++; petit_args.graph_write_dd_as_graph=true; petit_args.graph_by_statement=true; if (arg[j] == '-') { j++; petit_args.graph_by_statement=false; } } int len=strlen(&arg[j]); if (len>=DEPWRNAMELEN) ErrAssert("Write file name too long"); strcpy(petit_args.DepWrFile, &arg[j]); j += len; break; } case 'T': { int n=0; petit_args.valueClosure=0; petit_args.testClosure=1; if (arg[j]=='h') { print_closure_help(); Exit(0); } while ((c=arg[j]) >= '0' && c<='9') { n=n*10+c-'0'; j++; } if (arg[j]=='v') { petit_args.valueClosure=1; j++; } set_closure_flags(n); break; } case 'Q': { petit_args.DDalgorithm=DDalg_omega; petit_args.doOEcompare=1; break; } default: { for(popt=&options[0]; popt->pflag; popt++) { if(popt->symbol == c) { *(popt->pflag) = 1 - *(popt->pflag); goto FlagFound; } } sprintf(line, "Unknown flag -%c", c); Error(line); } FlagFound:; } } } else { UserAssert(i>=1, "File name is not allowed in .petitrc file"); UserAssert(petit_args.FileName==NULL, "Only one source file name is allowed"); petit_args.FileName = arg; } } petit_args.motif_display = (!petit_args.uniform && !petit_args.hpp_only && !petit_args.DepWrFile[0]); } /* process_args */
/** * * CTexture class LoadFromTarga * * @author Christopher Howlett * @param _pRenderer OpenGLRenderer * @param _pcFilename texture filename * @param _uiTextureUnit Texture ID * @return Returns success * */ bool Texture::LoadFromPNG( const char* _pcFilename, unsigned int _uiTextureUnit) { bool bResult = false; std::vector< unsigned char > imageData; unsigned int iWidth; unsigned int iHeight; bResult = ( lodepng::decode( imageData, iWidth, iHeight, _pcFilename ) == 0 ); ErrAssert( bResult, L"Could not load PNG" ); char* pData = new char[imageData.size()]; for ( unsigned int i = 0; i < imageData.size( ); i += 4 ) { pData[i] = imageData[i]; pData[i + 1] = imageData[i + 1]; pData[i + 2] = imageData[i + 2]; pData[i + 3] = imageData[i + 3]; } //Setup openGL Texture glEnable( GL_TEXTURE_2D ); glActiveTexture( GL_TEXTURE0 + _uiTextureUnit ); glGenTextures( 1, &m_uiResourceID ); glBindTexture( GL_TEXTURE_2D, m_uiResourceID ); //Bind texture to ID glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, static_cast<int>( iWidth ), static_cast<int>( iHeight ), 0, GL_RGBA, GL_UNSIGNED_BYTE, pData ); //Set to Wrap texture //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP ); //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP ); //Set texture filtering glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); //Generate mipmaps glGenerateMipmap( GL_TEXTURE_2D ); printf( "Loaded %s %iBit texture (%i x %i) at [%i]\n", _pcFilename, 32, iWidth, iHeight, m_uiResourceID ); m_bIsLoaded = true; SAFEDELETEARRAY( pData ); return bResult; // // //std::vector<unsigned char> imageData; //unsigned int iWidth; //unsigned int iHeight; //lodepng::decode(imageData, iWidth, iHeight, _pcFilename); // ////Copy data to a buffer //unsigned char* pcBuffer = new unsigned char[imageData.size()]; //for (unsigned int iChar = 0; iChar < imageData.size(); ++iChar) //{ // pcBuffer[iChar] = imageData[iChar]; //} // ////Setup openGL Texture //glActiveTexture(GL_TEXTURE0 + _uiTextureUnit); //glGenTextures( 1, &m_uiTextureID); //glBindTexture( GL_TEXTURE_2D, m_uiTextureID); //Bind texture to ID //glTexImage2D( GL_TEXTURE_2D, // 0, // GL_RGBA, // static_cast<int>(iWidth), // static_cast<int>(iHeight), // 0, // GL_BGRA, // GL_UNSIGNED_BYTE, // pcBuffer); // ////Set to Wrap texture //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // ////Set texture filtering //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // ////Generate mipmaps //glGenerateMipmap(GL_TEXTURE_2D); // //if (m_uiTextureID == 0) //{ // printf("Failed to load PNG: %s\n", _pcFilename); // bResult = false; //} //else //{ // printf("Loaded Texture: %s (%i x %i)\n", _pcFilename, iWidth, iHeight); // m_bIsLoaded = true; //} //delete[] pcBuffer; //pcBuffer = 0; return bResult; }