Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Technique Class Reference

#include <technique.h>

Classes

class  Pass
 

Public Member Functions

 Technique (const std::string &name)
 
 Technique (const Technique &src)
 
 ~Technique ()
 
const std::string & getName () const
 
const std::string & getFallback () const
 
bool isCompiled () const
 
bool isCompiled (int programVersion) const
 
void compile ()
 
int getNumPasses () const
 
const PassgetPass (int idx) const
 
PassgetPass (int idx)
 

Static Public Member Functions

static TechniquePtr getTechnique (const std::string &name)
 

Protected Types

typedef std::vector< PassPassList
 

Protected Attributes

PassList passes
 

Detailed Description

Definition at line 14 of file technique.h.

Member Typedef Documentation

typedef std::vector< Pass > Technique::PassList
protected

Definition at line 386 of file technique.h.

Constructor & Destructor Documentation

Technique::Technique ( const std::string &  name)
explicit

Create a technique by loading and parsing the definition in [name].technique

Referenced by getTechnique().

Technique::Technique ( const Technique src)
explicit

Create a technique by copying another technique

Definition at line 601 of file technique.cpp.

601  :
602  name( src.name )
603  , fallback( src.fallback )
604  , compiled( false )
605  , programVersion( 0 )
606  , passes( src.passes )
607 {
608  // Not much else to do
609  // Compiled techniques are still valid, and setting any parameter
610  // that would invalidate it would result in recompilation
611  // FIXME: should result in recompilation, not necessarily true now
612 }
Technique::~Technique ( )

Definition at line 614 of file technique.cpp.

615 {
616 }

Member Function Documentation

void Technique::compile ( )

Definition at line 618 of file technique.cpp.

References GFXGetProgramVersion(), and passes.

619 {
620  if (!compiled || (GFXGetProgramVersion() != programVersion)) {
621  for (PassList::iterator it = passes.begin(); it != passes.end(); ++it)
622  it->compile();
623  compiled = true;
625  }
626 }
const std::string& Technique::getFallback ( ) const
inline

Definition at line 402 of file technique.h.

403  {
404  return fallback;
405  }
const std::string& Technique::getName ( ) const
inline

Definition at line 398 of file technique.h.

399  {
400  return name;
401  }
int Technique::getNumPasses ( ) const
inline

Definition at line 421 of file technique.h.

References passes.

422  {
423  return passes.size();
424  }
const Pass& Technique::getPass ( int  idx) const
inline

Definition at line 425 of file technique.h.

References passes.

426  {
427  return passes[idx];
428  }
Pass& Technique::getPass ( int  idx)
inline

Definition at line 429 of file technique.h.

References passes.

430  {
431  return passes[idx];
432  }
TechniquePtr Technique::getTechnique ( const std::string &  name)
static

Cached technique factory function

Definition at line 631 of file technique.cpp.

References Technique(), techniqueCache, VSFileSystem::vs_fprintf(), and __impl::Exception::what().

Referenced by Mesh::initTechnique().

632 {
633  TechniqueMap::const_iterator it = techniqueCache.find( name );
634  if ( it != techniqueCache.end() ) {
635  return it->second;
636  } else {
637  TechniquePtr ptr( new Technique( name ) );
638  while ( !ptr->isCompiled() ) {
639  try {
640  ptr->compile();
641  VSFileSystem::vs_fprintf( stdout,
642  "Compilation of technique %s successful\n",
643  ptr->getName().c_str() );
644  }
645  catch (ProgramCompileError e) {
646  std::string fallback = ptr->getFallback();
647  VSFileSystem::vs_fprintf( stderr,
648  "Compilation of technique %s failed... trying %s\n"
649  "Cause: %s\n",
650  ptr->getName().c_str(),
651  fallback.c_str(),
652  e.what() );
653  if (!fallback.empty() && fallback != name)
654  ptr = getTechnique( fallback );
655  else
656  break;
657  }
658  }
659  if ( ptr->isCompiled() )
660  techniqueCache[name] = ptr;
661  else
662  throw InvalidParameters( "Could not compile any technique for \""+name+"\"" );
663  return ptr;
664  }
665 }
bool Technique::isCompiled ( ) const
inline

returns true if the technique has been compiled

Definition at line 408 of file technique.h.

409  {
410  return compiled;
411  }
bool Technique::isCompiled ( int  programVersion) const
inline

returns true if the technique has been compiled with a matching program version

Definition at line 414 of file technique.h.

415  {
416  return compiled && this->programVersion == programVersion;
417  }

Member Data Documentation

PassList Technique::passes
protected

Definition at line 387 of file technique.h.

Referenced by compile(), getNumPasses(), and getPass().


The documentation for this class was generated from the following files: