Exemple #1
0
Shader::Shader(const std::string &filepath, glm::vec2 viewport, GLenum culling,
               GLboolean colormask0, GLboolean colormask1, GLboolean colormask2,
               GLboolean colormask3, GLboolean depthmask, GLbitfield clear) {
	registred.push_back(this);

	this->culling = culling;
	this->colormask[0] = colormask0;
	this->colormask[1] = colormask1;
	this->colormask[2] = colormask2;
	this->colormask[3] = colormask3;
	this->depthmask = depthmask;
	this->clear = clear;
	this->viewport = viewport;

	std::string firstpath = g_System()->GetDataFile(filepath);

	std::string vertexsource, fragmentsource, geometrysource, libraries = "\n";
	GLuint vertexshader, fragmentshader, geometryshader;
	int IsCompiled_VS, IsCompiled_FS, IsCompiled_GS;
	int IsLinked;
	vertexsource = filetobuf(firstpath + ".vert");
	fragmentsource = filetobuf(firstpath + ".frag");
	geometrysource = filetobuf(firstpath + ".geom");
	std::vector<std::string> libs;
	g_System()->GetFilesInDirectory(libs, g_System()->GetDataFile("shaders"));
	for (auto &s : libs) {
		s = "shaders/" + s;
		if (endsWith(s, ".slib")) {
			std::string libsource = filetobuf(g_System()->GetDataFile(s));
			if (libsource.length() == 0)
				continue;
			g_Console()->Info("Shader library loaded " + s);
			libraries += libsource + "\n";
		}
	}
	vertexsource = libraries + vertexsource;
	fragmentsource = libraries + fragmentsource;
	if (geometrysource.length() > 0)
		geometrysource = libraries + geometrysource;

	vertexshader = glCreateShader(GL_VERTEX_SHADER);
	const GLchar* ptr = vertexsource.c_str();
	glShaderSource(vertexshader, 1, (const GLchar **)&ptr, 0);
	glCompileShader(vertexshader);
	glGetShaderiv(vertexshader, GL_COMPILE_STATUS, &IsCompiled_VS);
	if (IsCompiled_VS == GL_FALSE) {
		logShader(vertexshader);
		return;
	}

	fragmentshader = glCreateShader(GL_FRAGMENT_SHADER);
	ptr = fragmentsource.c_str();
	glShaderSource(fragmentshader, 1, (const GLchar **)&ptr, 0);
	glCompileShader(fragmentshader);
	glGetShaderiv(fragmentshader, GL_COMPILE_STATUS, &IsCompiled_FS);
	if (IsCompiled_FS == GL_FALSE) {
		logShader(fragmentshader);
		return;
	}

	if (geometrysource.length() > 0) {
		geometryshader = glCreateShader(GL_GEOMETRY_SHADER);
		ptr = geometrysource.c_str();
		glShaderSource(geometryshader, 1, (const GLchar **)&ptr, 0);
		glCompileShader(geometryshader);
		glGetShaderiv(geometryshader, GL_COMPILE_STATUS, &IsCompiled_GS);
		if (IsCompiled_GS == GL_FALSE) {
			logShader(geometryshader);
			return;
		}
	}

	id = glCreateProgram();
	glAttachShader(id, vertexshader);
	glAttachShader(id, fragmentshader);
	if (geometrysource.length() > 0)
		glAttachShader(id, geometryshader);
	glLinkProgram(id);
	glGetProgramiv(id, GL_LINK_STATUS, (int *)&IsLinked);
	if (IsLinked == GL_FALSE) {
		logProgram(id);
		id = 0;
		return;
	}
	g_Console()->Info("Shader loaded " + filepath);
}
Exemple #2
0
int main ( int argc, char **argv )
{
  int   err = FALSE ;
  int   i, j ;
  int   fullopt = FALSE ;
  int   tidy = FALSE ;
  int   trivopts [ NO_OF_TRIV_LISTS ] ;
  int   titleInfoOpts [ NO_OF_TITLE_INFO_LISTS ] ;
  struct titleSearchRec *combined = NULL, *tchain = NULL ;
  struct titleSearchOptRec options = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;

  logProgram ( argv [ 0 ] ) ;
  options . yearMatch = TRUE ;

  if ( argc == 1 )
    err = TRUE ;

  for ( i = 0 ; i < NO_OF_TRIV_LISTS ; i++ )
    trivopts [ i ] = FALSE ;

  for ( i = 0 ; i < NO_OF_TITLE_INFO_LISTS ; i++ )
    titleInfoOpts [ i ] = FALSE ;

  for ( i = 1; i < argc; i++ )
    if ( strcmp ( "-t", argv[i] ) == 0 )
      if ( ++i < argc )
        tchain = addTitleSearchRec ( tchain, argv [ i ] ) ;
      else
        err = TRUE ;
    else if ( strcmp ( "-i", argv [ i ] ) == 0 )
      options . casesen = TRUE ;
    else if ( strcmp ( "-pl", argv [ i ] ) == 0 )
    {
      options . plotopt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-bus", argv [ i ] ) == 0 )
    {
      options . businessopt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-ld", argv [ i ] ) == 0 )
    {
      options . ldopt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-nold", argv [ i ] ) == 0 )
    {
      options . ldopt = FALSE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-lit", argv [ i ] ) == 0 )
    {
      options . litopt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-ym", argv [ i ] ) == 0 )
    {
      options . yearMatch = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-exact", argv [ i ] ) == 0 )
      options . yearMatch = FALSE ;
    else if ( strcmp ( "-s", argv [ i ] ) == 0 )
    {
      options . substring = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-mrr", argv [ i ] ) == 0 )
    {
      options . mrropt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-yr", argv [ i ] ) == 0 )
    {
      options . yropt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-trivia", argv [ i ] ) == 0 )
    {
      for ( j = 0 ; j < NO_OF_TRIV_LISTS ; j++ )
        trivopts [ j ] = TRUE ;
      for ( j = 0 ; j < NO_OF_TITLE_INFO_LISTS ; j++ )
        titleInfoOpts [ j ] = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-aka", argv [ i ] ) == 0 )
    {
      options . akaopt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-link", argv [ i ] ) == 0 )
    {
      options . linkopt = TRUE ;
      tidy = TRUE ;
    }
    else if ( strcmp ( "-full", argv [ i ] ) == 0 )
    {
      for ( j = 0 ; j < NO_OF_TRIV_LISTS ; j++ )
        trivopts [ j ] = TRUE ;
      for ( j = 0 ; j < NO_OF_TITLE_INFO_LISTS ; j++ )
        titleInfoOpts [ j ] = TRUE ;
      options . mrropt = TRUE ;
      options . yropt = TRUE ;
      options . plotopt = TRUE ;
      options . businessopt = TRUE ;
      options . ldopt = TRUE ;
      options . litopt = TRUE ;
      options . akaopt = TRUE ;
      options . linkopt = TRUE ;
      tidy = TRUE ;
      fullopt = TRUE ;
    }
    else
    {
      (void) fprintf ( stderr, "title: unrecognised option %s\n", argv[i] ) ;
      err = TRUE ;
    }

  if ( err || tchain == NULL )
    moviedbUsage ( TITLE_USAGE1, TITLE_USAGE2, NULL, NULL, NULL, NULL ) ;

  if ( tchain -> next != NULL )
  {
    if ( options . substring )
      moviedbError ("title: -s not available with more than one search" ) ;
    else if ( fullopt )
      moviedbError ( "title: -full not available with more than one search" ) ;
    else if ( options . mrropt )
      moviedbError ( "title: -mrr not available with more than one search" ) ;
    else if ( options . yropt )
      moviedbError ( "title: -yr not available with more than one search" ) ;
    else if ( options . plotopt )
      moviedbError ( "title: -pl not available with more than one search" ) ;
    else if ( options . businessopt )
      moviedbError ( "title: -bus not available with more than one search" ) ;
    else if ( options . ldopt )
      moviedbError ( "title: -ld not available with more than one search" ) ;
    else if ( options . litopt )
      moviedbError ( "title: -lit not available with more than one search" ) ;
    else if ( options . akaopt )
      moviedbError( "title: -aka not available with more than one search" ) ;
    else if ( trivopts [ 0 ] )
      moviedbError( "title: -trivia not available with more than one search" ) ;
    else if ( titleInfoOpts [ 0 ] )
      moviedbError( "title: -info not available with more than one search" ) ;
  }

  if ( tchain != NULL && tchain -> next != NULL )
  {
    addTitleChainOpts ( tchain, options ) ;
    addTitleChainTrivOpts ( tchain, trivopts ) ;
    addTitleChainTitleInfoOpts ( tchain, titleInfoOpts ) ;
    processTitleSearch ( tchain ) ;
    combined = combineTitleResults ( tchain ) ; 
    displayTitleSearchResults ( combined, FALSE ) ; 
    freeTitleChain ( combined ) ; 
  }
  else 
  { 
    addTitleChainOpts ( tchain, options ) ;
    addTitleChainTrivOpts ( tchain, trivopts ) ;
    addTitleChainTitleInfoOpts ( tchain, titleInfoOpts ) ;
    processTitleSearch ( tchain ) ;
    displayTitleMatches ( tchain ) ;
    displayTitleSearchResults ( tchain, tidy ) ; 
  } 

  freeTitleChain ( tchain ) ;

  return ( 0 ) ;
}
Exemple #3
0
int main ( int argc, char **argv )
{
  struct nameSearchRec  *nrec = NULL ;
  struct titleSearchRec *tchain = NULL ;
  struct nameSearchOptRec  noptions = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
  struct titleSearchOptRec  toptions = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
  int    trivopts [ NO_OF_TRIV_LISTS ] ;
  int    titleInfoOpts [ NO_OF_TITLE_INFO_LISTS ] ;
  int    i, j, okopt, err = FALSE ;

  logProgram ( argv [ 0 ] ) ;

  if ( argc == 1 )
    err = TRUE ;

  for ( i = 0 ; i < NO_OF_TRIV_LISTS ; i++ )
    trivopts [ i ] = FALSE ;

  for ( i = 0 ; i < NO_OF_TITLE_INFO_LISTS ; i++ )
    titleInfoOpts [ i ] = FALSE ;

  for ( i = 1; i < argc; i++ )
    if ( strcmp ( "-m", argv[i] ) == 0 )
      noptions . mvsonly = TRUE ;
    else if ( strcmp ( "-yr", argv[i] ) == 0 )
    {
      toptions . yropt = YR ;
      noptions . yropt = YR ;
    }
    else if ( strcmp ( "-aka", argv[i] ) == 0 )
    {
      toptions . akaopt = TRUE ;
      noptions . akaopt = TRUE ;
    }
    else if ( strcmp ( "-chr", argv[i] ) == 0 )
    {
      toptions . chopt = TRUE ;
      noptions . chopt = TRUE ;
    }
    else if ( strcmp ( "-mrr", argv[i] ) == 0 )
      toptions . mrropt = MRR ;
    else if ( strcmp ( "-pl", argv[i] ) == 0 )
      toptions . plotopt = TRUE ;
    else if ( strcmp ( "-bus", argv[i] ) == 0 )
      toptions . businessopt = TRUE ;
    else if ( strcmp ( "-ld", argv[i] ) == 0 )
      toptions . ldopt = TRUE ;
    else if ( strcmp ( "-trivia", argv[i] ) == 0 )
    {
      for ( j = 0 ; j < NO_OF_TRIV_LISTS ; j++ )
        trivopts [ j ] = TRUE ;
      for ( j = 0 ; j < NO_OF_TITLE_INFO_LISTS ; j++ )
        titleInfoOpts [ j ] = TRUE ;
    }
    else if ( strcmp ( "-full", argv[i] ) == 0 )
    {
      for ( j = 0 ; j < NO_OF_TRIV_LISTS ; j++ )
        trivopts [ j ] = TRUE ;
      for ( j = 0 ; j < NO_OF_TITLE_INFO_LISTS ; j++ )
        titleInfoOpts [ j ] = TRUE ;
      toptions . yropt = TRUE ;
      toptions . chopt = TRUE ;
      toptions . mrropt = TRUE ;
      toptions . akaopt = TRUE ;
      toptions . plotopt = TRUE ;
      toptions . businessopt = TRUE ;
      toptions . ldopt = TRUE ;
      toptions . litopt = TRUE ;
      toptions . linkopt = TRUE ;
      noptions . yropt = YR ;
      noptions . akaopt = TRUE ;
      noptions . chopt = TRUE ;
      noptions . biopt = TRUE ;
    }
    else
    {
      okopt = FALSE ;
      for ( j = 0 ; j < NO_OF_SEARCH_OPTS ; j++ )
	if ( strcmp ( filmographyOptions [ j ] . option, argv [ i ] ) == 0 || strcmp ( filmographyOptions [ j ] . oldOption, argv [ i ] ) == 0 )
        {
	  okopt = TRUE ;
          if ( ++i < argc )
          {
            nrec = addNameSearchRec ( nrec, argv [ i ], j ) ;
            if ( j == GLOBAL_NAME_SEARCH )
              noptions . searchall = TRUE ;
          }
          else
          {
            err = TRUE ;
	    break ;
          }
	}
      if ( ! okopt )
      {
         (void) fprintf ( stderr, "ltrace: unrecognised option %s\n", argv[i] ) ;
         err = TRUE ;
      }
    }

  if ( err || nrec == NULL )
    moviedbUsage ( LTRACE_USAGE1, LTRACE_USAGE2, LTRACE_USAGE3, NULL, NULL, NULL ) ;

  if ( nrec -> next != NULL )
    moviedbError ( "ltrace: only one name allowed" ) ;

  addNameChainOpts ( nrec, noptions ) ;
  processFilmographySearch ( nrec ) ;
  sortListResults ( nrec ) ;
  tchain = makeTitleChain ( nrec, toptions, trivopts, noptions, titleInfoOpts ) ;
  if ( tchain != NULL )
  {
    processTitleSearch ( tchain ) ;
    displayNameSearchResults ( nrec, TRUE ) ;
    displayTitleSearchResults ( tchain, TRUE ) ;
    freeTitleChain ( tchain ) ; 
  }
  freeNameSearchChain ( nrec ) ; 

  return ( 0 ) ;
}