diff options
Diffstat (limited to '1.4.0/fx/src')
25 files changed, 10488 insertions, 0 deletions
diff --git a/1.4.0/fx/src/cfxAnnotatable.cpp b/1.4.0/fx/src/cfxAnnotatable.cpp new file mode 100644 index 0000000..2e53c71 --- /dev/null +++ b/1.4.0/fx/src/cfxAnnotatable.cpp @@ -0,0 +1,35 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +#include <cfxAnnotatable.h> +#include <cfxAnnotate.h> + + +// cfxAnnotatable +cfxAnnotatable::cfxAnnotatable() +{ +} + +cfxAnnotatable::~cfxAnnotatable() +{ + for (size_t i=0; i<annotateArray.size(); i++) + { + delete (cfxAnnotate*)(annotateArray[i])->getData(); + delete annotateArray[i]; + } + annotateArray.clear(); +} + +void cfxAnnotatable::pushAnnotate(cfxAnnotate* annotate) +{ + annotateArray.push_back(annotate); +} + +const std::vector<cfxAnnotate*> &cfxAnnotatable::getAnnotateArray() const +{ + return annotateArray; +} diff --git a/1.4.0/fx/src/cfxAnnotate.cpp b/1.4.0/fx/src/cfxAnnotate.cpp new file mode 100644 index 0000000..7a6ea96 --- /dev/null +++ b/1.4.0/fx/src/cfxAnnotate.cpp @@ -0,0 +1,85 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <assert.h> +#include <cfxPlatform.h> +// User includes + +#include <cfxAnnotate.h> +#include <cfxData.h> +#include <cfxEffect.h> +#include <cfxParam.h> +#include <cfxPass.h> +#include <cfxTechnique.h> +#include <cfxShader.h> + + +// cfxAnnotate +cfxAnnotate::cfxAnnotate(cfxData* _data, const std::string& _name) + : data(_data), + name(_name) +{ +} + +cfxAnnotate::~cfxAnnotate() +{ +} + + +bool cfxAnnotate::apply(const cfxEffect* effect) +{ + annotation = cgCreateEffectAnnotation(effect->getEffect(), name.c_str(), data->getType()); + data->apply(this); + return true; +} + +bool cfxAnnotate::apply(const cfxParam* param) +{ + annotation = cgCreateParameterAnnotation(param->getParameter(), name.c_str(), data->getType()); + data->apply(this); + return true; +} + +bool cfxAnnotate::apply(const cfxPass* pass) +{ + annotation = cgCreatePassAnnotation(pass->getPass(), name.c_str(), data->getType()); + data->apply(this); + return true; +} + +bool cfxAnnotate::apply(const cfxTechnique* technique) +{ + annotation = cgCreateTechniqueAnnotation(technique->getTechnique(), name.c_str(), data->getType()); + data->apply(this); + return true; +} + +bool cfxAnnotate::apply(const cfxShader* shader) +{ + annotation = cgCreateProgramAnnotation(shader->getProgram(), name.c_str(), data->getType()); + data->apply(this); + return true; +} + +CGannotation cfxAnnotate::getAnnotation() const +{ + return annotation; +} + +const cfxData *cfxAnnotate::getData() const +{ + return data; +} + +const std::string &cfxAnnotate::getName() const +{ + return name; +} diff --git a/1.4.0/fx/src/cfxBinaryUtil.cpp b/1.4.0/fx/src/cfxBinaryUtil.cpp new file mode 100644 index 0000000..e34f4c0 --- /dev/null +++ b/1.4.0/fx/src/cfxBinaryUtil.cpp @@ -0,0 +1,2294 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +/* + * Binary file importer and exporter for the COLLADA FX loader library. + * Summary of format: + * newlines added for comment readability only + * all string are NULL terminated + * '...' means that the structure before may be repeated as many times as needed + * All *_TOKEN are optional structures, but if they appear they must include data specified after + * + * COLLADA_FX_BIN_ID + * COLLADA_FX_BIN_VER + * platform identifier + * EFFECT_TOKEN effect-name chunk-size + * ANNOTATE_TOKEN annotate-name + * Type_ID data + * ... + * NEWPARAM_TOKEN param-name semantic + * Type_ID data + * ... + * SURFACE_TAG surface-name image-name format + * ... + * TECHNIQUE_TOKEN technique-name + * ANNOTATE + * ... + * INCLUDE_TAG include-name path + * ... + * SURFACE_TAG image-name format + * ... + * NEWPARAM + * ... + * SETPARAM_TOKEN param-name + * Type_ID data + * ... + * PASS_TOKEN pass-name + * ANNOTATE + * ... + * NEWPARAM + * ... + * SETPARAM + * ... + * GL_SETTING_TOKEN setting-Identifier setting-values + * ... + * SHADER_TOKEN vertex-or-fragment-identifier source entry-name + * ANNOTATE_TOKEN + * ... + * CONNECT_PARAM_TOKEN shader-symbol param-name + * ... + * BIND_PARAM_TOKEN shader-symbol Type_ID data + * ... + * ... + * ... + * ... + * ... + * MATERIAL_TOKEN name effect-name size + * SETPARAM_TOKEN param-name + * Type_ID data + * ... + * SURFACE_TAG surface-name image-name format + * ... + * ... + * EOF + */ + +// System includes +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +//#include <Cg/cg.h> +#include <cfxPlatform.h> + +// User includes + +#include <cfxBinaryUtil.h> +#include <cfxAnnotatable.h> +#include <cfxAnnotate.h> +#include <cfxBindParam.h> +#include <cfxCode.h> +#include <cfxConnectParam.h> +#include <cfxData.h> +#include <cfxDataMaker.h> +#include <cfxEffect.h> +#include <cfxGlPipelineSetting.h> +#include <cfxGlPipelineSettingMaker.h> +#include <cfxGlSamplerSetting.h> +#include <cfxMaterial.h> +#include <cfxNewParam.h> +#include <cfxParamable.h> +#include <cfxPass.h> +#include <cfxSampler.h> +#include <cfxSetParam.h> +#include <cfxShader.h> +#include <cfxSurface.h> +#include <cfxTechnique.h> +#include <cfxError.h> +#include <cfxLoader.h> + +#include <dae.h> +#include <dae/daeURI.h> + +//File Header identifiers +#define COLLADA_FX_BIN_ID 0xDAEFEC +#define COLLADA_FX_BIN_VER 0x14 + +#define CFX_BIN_TOKEN_SIZE 2 + +//Chunk Header Tags +#define EFFECT_TOKEN 0xEFEC +#define ANNOTATE_TOKEN 0xA77E +#define NEWPARAM_TOKEN 0x2E39 +#define TECHNIQUE_TOKEN 0x7C2C +#define INCLUDE_TOKEN 0x12CD +#define SURFACE_TOKEN 0x5E2F +#define SETPARAM_TOKEN 0x5E79 +#define PASS_TOKEN 0x9A55 +#define GL_SETTING_TOKEN 0x5E72 +#define SHADER_TOKEN 0x5AD2 +#define CONNECTPARAM_TOKEN 0xC2C7 +#define BINDPARAM_TOKEN 0xB12D +#define MATERIAL_TOKEN 0x3A71 + +//Type Tags +#define CFXBOOL0 0xB000 +#define CFXBOOL1 0xB001 +#define CFXBOOL2 0xB002 +#define CFXBOOL3 0xB003 +#define CFXBOOL4 0xB004 +#define CFXINT0 0x1200 +#define CFXINT1 0x1201 +#define CFXINT2 0x1202 +#define CFXINT3 0x1203 +#define CFXINT4 0x1204 +#define CFXFLOAT0 0xF100 +#define CFXFLOAT1 0xF101 +#define CFXFLOAT2 0xF102 +#define CFXFLOAT3 0xF103 +#define CFXFLOAT4 0xF104 +#define CFXFLOAT2X2 0xF122 +#define CFXFLOAT3X3 0xF133 +#define CFXFLOAT4X4 0xF144 +#define CFXSAMPLER1D 0x5A31 +#define CFXSAMPLER2D 0x5A32 +#define CFXSAMPLER3D 0x5A33 +#define CFXSAMPLERCUBE 0x5A3C +#define CFXSTRING 0x5712 + +std::string cfxBinaryUtil::fileName; +std::string cfxBinaryUtil::remotePath = ""; + +void cfxBinaryUtil::setRemotePath( const std::string &path ) +{ + remotePath = path; +} + +cfxBool cfxBinaryUtil::load(const std::string& file, std::map<std::string, cfxMaterial*>& materials, + std::map<std::string, cfxEffect*>& effects, CGcontext _context) +{ + // Open file for loading + FILE *input = NULL; + + // Load the COLLADA file + std::string fn = remotePath + file; + printf("loading %s\n", fn.c_str()); + input = fopen( fn.c_str(), "rb" ); + if ( input == NULL ) + { + printf( "ERROR: Unable to open file %s!\n", file.c_str() ); + return false; + } + // Load file header + if ( !loadFileHeader( input ) ) + { + printf( "ERROR: Improper file header!\n" ); + return false; + } + + cgSetErrorCallback(cfxCgErrorCallback); + + if (_context == NULL) + { + _context = cgCreateContext(); + cgGLRegisterStates(_context); + } + + short token = 0; + cfxBool trew = true; + while( trew ) { + readToken( token, input ); + if ( feof( input ) ) { + //eof only happens after you try to read past it so try one more token. + break; + } + cfxEffect* effect = NULL; + cfxMaterial *material = NULL; + switch( token ) + { + case (short)EFFECT_TOKEN: + // currently using managed textures to ensure that the texture objects are + // on the correct texture unit where the program expects them to be. + cgGLSetManageTextureParameters(_context, true); + + effect = readEffect( input, _context ); + if ( effect == NULL ) + { + return false; + } + effects.insert(std::make_pair(effect->getName(), effect)); +#ifndef _LIB + effect->apply(); +#endif + break; + case (short)MATERIAL_TOKEN: + material = readMaterial( input, _context, &effects ); + materials.insert(std::make_pair(material->getName(), material)); + break; + default: + printf( "Unexpected Token!" ); + return false; + } + } + fclose( input ); + return true; +} + +size_t cfxBinaryUtil::readString( std::string &str, FILE *input ) +{ + str.clear(); + char currChar[2]; + currChar[1] = '\0'; + size_t count = 0; + do + { + currChar[0] = fgetc( input ); + str.append( currChar ); + ++count; + }while( currChar[0] != '\0' ); + return count; +} + +void cfxBinaryUtil::endianSwap( short *s ) +{ + char temp; + char *bytes = (char *)s; + temp = bytes[0]; + bytes[0] = bytes[1]; + bytes[1] = temp; +} + +void cfxBinaryUtil::endianSwap( cfxInt *i ) +{ + size_t sz = sizeof( cfxInt ); + char temp; + char *bytes = (char *)i; + for ( size_t x = 0; x < sz/2; ++x ) + { + temp = bytes[x]; + bytes[x] = bytes[sz-x-1]; + bytes[sz-x-1] = temp; + } +} + +void cfxBinaryUtil::endianSwap( cfxFloat *f ) +{ + size_t sz = sizeof( cfxFloat ); + char temp; + char *bytes = (char *)f; + for ( size_t x = 0; x < sz/2; ++x ) + { + temp = bytes[x]; + bytes[x] = bytes[sz-x-1]; + bytes[sz-x-1] = temp; + } +} + +size_t cfxBinaryUtil::readBool( cfxBool *buf, size_t count, FILE *input ) +{ + //cfxBool has no endian issues + return fread( buf, sizeof(cfxBool), count, input) * sizeof(cfxBool); +} + +size_t cfxBinaryUtil::readInt( cfxInt *buf, size_t count, FILE *input ) +{ +#ifdef WIN32 + //win32 requires endian swap + size_t sz = fread( buf, sizeof(cfxInt), count, input) * sizeof(cfxInt); + for ( size_t i = 0; i < count; ++i ) + { + endianSwap( buf+i ); + } + return sz; +#else + return fread( buf, sizeof(cfxInt), count, input) * sizeof(cfxInt); +#endif +} + +size_t cfxBinaryUtil::readFloat( cfxFloat *buf, size_t count, FILE *input ) +{ +#ifdef WIN32 +//win32 requires endian swap + size_t sz = fread( buf, sizeof(cfxFloat), count, input) * sizeof(cfxFloat); + for ( size_t i = 0; i < count; ++i ) + { + endianSwap( buf+i ); + } + return sz; +#else + return fread( buf, sizeof(cfxFloat), count, input) * sizeof(cfxFloat); +#endif +} + +size_t cfxBinaryUtil::readToken( short &token, FILE *input) +{ + fread( &token, CFX_BIN_TOKEN_SIZE, 1, input ); +#ifdef WIN32 + endianSwap( &token ); +#endif + return CFX_BIN_TOKEN_SIZE; +} + + +cfxBool cfxBinaryUtil::loadFileHeader( FILE *input ) +{ + if ( input == NULL ) + { + return false; + } + //check type and version + size_t byteCount = 0; + int typenver; + fread( &typenver, 4, 1, input ); +#ifdef WIN32 + endianSwap( &typenver ); +#endif + if ( typenver != (COLLADA_FX_BIN_ID << 8 )+ COLLADA_FX_BIN_VER ) { + printf( "ERROR: Wrong file type or COLLADA_FX Binary version!\n" ); + return false; + } + int offset; + byteCount = 4 + readInt( &offset, 1, input ); + if ( (int)byteCount != offset ) + { + //just have this here because you should be at the start of data now. if not I messed + //something up somewhere + return false; + } + return true; +} + +cfxAnnotate *cfxBinaryUtil::readAnnotate( FILE *input, size_t &size, cfxEffect *effect ) +{ + std::string name; + cfxData *data; + size = readString(name, input); + size += readTypedData( &data, input, effect ); + return new cfxAnnotate( data, name ); +} + +cfxParam *cfxBinaryUtil::readParam( short token, FILE *input, size_t &size, void *other ) +{ + std::string name; + std::string fromName; + std::string semantic; + cfxData *data; + switch ( token ) + { + case (short)BINDPARAM_TOKEN: + size = readString( name, input ); + size += readTypedData( &data, input, ((cfxShader*)other)->getPass()->getTechnique()->getEffect() ); + return new cfxBindParam( name, (cfxShader*)other, data ); + case (short)CONNECTPARAM_TOKEN: + size = readString( name, input ); + size += readString( fromName, input ); + return new cfxConnectParam( name, (cfxShader*)other, fromName ); + case (short)NEWPARAM_TOKEN: + size = readString( name, input ); + size += readString( semantic, input ); + size += readTypedData( &data, input, (cfxEffect*)other ); + return new cfxNewParam( data, name, (cfxEffect*)other, semantic ); + case (short)SETPARAM_TOKEN: + size = readString( name, input ); + size += readTypedData( &data, input, (cfxEffect*)other ); + return new cfxSetParam( data, name, (cfxEffect*)other ); + default: + printf( "ERROR: Unknown param type or bad token!\n" ); + break; + } + size = 0; + return NULL; +} + +size_t cfxBinaryUtil::readTypedData( cfxData **data, FILE *input, cfxEffect *effect ) +{ + short token; + size_t size = readToken( token, input ); + if ( token == (short)CFXBOOL0 ) + { + cfxBool b; + size += readBool( &b, 1, input ); + *data = new cfxDataBool( b ); + } + else if ( token == (short)CFXBOOL1 ) + { + cfxBool1 b; + size += readBool( (cfxBool*)&b, 1, input ); + *data = new cfxDataBool1( b ); + } + else if ( token == (short)CFXBOOL2 ) + { + cfxBool2 b; + size += readBool( (cfxBool*)&b, 2, input ); + *data = new cfxDataBool2( b ); + } + else if ( token == (short)CFXBOOL3 ) + { + cfxBool3 b; + size += readBool( (cfxBool*)&b, 3, input ); + *data = new cfxDataBool3( b ); + } + else if ( token == (short)CFXBOOL4 ) + { + cfxBool4 b; + size += readBool( (cfxBool*)&b, 4, input ); + *data = new cfxDataBool4( b ); + } + else if ( token == (short)CFXINT0 ) + { + cfxInt i; + size += readInt( &i, 1, input ); + *data = new cfxDataInt( i ); + } + else if ( token == (short)CFXINT1 ) + { + cfxInt1 i; + size += readInt( (cfxInt*)&i, 1, input ); + *data = new cfxDataInt1( i ); + } + else if ( token == (short)CFXINT2 ) + { + cfxInt2 i; + size += readInt( (cfxInt*)&i, 2, input ); + *data = new cfxDataInt2( i ); + } + else if ( token == (short)CFXINT3 ) + { + cfxInt3 i; + size += readInt( (cfxInt*)&i, 3, input ); + *data = new cfxDataInt3( i ); + } + else if ( token == (short)CFXINT4 ) + { + cfxInt4 i; + size += readInt( (cfxInt*)&i, 4, input ); + *data = new cfxDataInt4( i ); + } + else if ( token == (short)CFXFLOAT0 ) + { + cfxFloat f; + size += readFloat( &f, 1, input ); + *data = new cfxDataFloat( f ); + } + else if ( token == (short)CFXFLOAT1 ) + { + cfxFloat1 f; + size += readFloat( (cfxFloat*)&f, 1, input ); + *data = new cfxDataFloat1( f ); + } + else if ( token == (short)CFXFLOAT2 ) + { + cfxFloat2 f; + size += readFloat( (cfxFloat*)&f, 2, input ); + *data = new cfxDataFloat2( f ); + } + else if ( token == (short)CFXFLOAT3 ) + { + cfxFloat3 f; + size += readFloat( (cfxFloat*)&f, 3, input ); + *data = new cfxDataFloat3( f ); + } + else if ( token == (short)CFXFLOAT4 ) + { + cfxFloat4 f; + size += readFloat( (cfxFloat*)&f, 4, input ); + *data = new cfxDataFloat4( f ); + } + else if ( token == (short)CFXFLOAT2X2 ) + { + cfxFloat2x2 f; + size += readFloat( (cfxFloat*)&f, 4, input ); + *data = new cfxDataFloat2x2( f ); + } + else if ( token == (short)CFXFLOAT3X3 ) + { + cfxFloat3x3 f; + size += readFloat( (cfxFloat*)&f, 9, input ); + *data = new cfxDataFloat3x3( f ); + } + else if ( token == (short)CFXFLOAT4X4 ) + { + cfxFloat4x4 f; + size += readFloat( (cfxFloat*)&f, 16, input ); + *data = new cfxDataFloat4x4( f ); + } + else if ( token == (short)CFXSAMPLER1D ) + { + cfxSampler *sampler; + std::string source; + int count; + size += readString( source, input ); + size += readInt( &count, 1, input ); + sampler = new cfxSampler( source, effect ); + size_t sz; + for ( int x = 0; x < count; ++x ) + { + sampler->pushSetting( readSamplerSetting( effect, input, sz ) ); + size += sz; + } + *data = new cfxDataSampler1D( sampler ); + } + else if ( token == (short)CFXSAMPLER2D ) + { + cfxSampler *sampler; + std::string source; + int count; + size += readString( source, input ); + size += readInt( &count, 1, input ); + sampler = new cfxSampler( source, effect ); + size_t sz; + for ( int x = 0; x < count; ++x ) + { + sampler->pushSetting( readSamplerSetting( effect, input, sz ) ); + size += sz; + } + *data = new cfxDataSampler2D( sampler ); + } + else if ( token == (short)CFXSAMPLER3D ) + { + cfxSampler *sampler; + std::string source; + int count; + size += readString( source, input ); + size += readInt( &count, 1, input ); + sampler = new cfxSampler( source, effect ); + size_t sz; + for ( int x = 0; x < count; ++x ) + { + sampler->pushSetting( readSamplerSetting( effect, input, sz ) ); + size += sz; + } + *data = new cfxDataSampler3D( sampler ); + } + else if ( token == (short)CFXSAMPLERCUBE ) + { + cfxSampler *sampler; + std::string source; + int count; + size += readString( source, input ); + size += readInt( &count, 1, input ); + sampler = new cfxSampler( source, effect ); + size_t sz; + for ( int x = 0; x < count; ++x ) + { + sampler->pushSetting( readSamplerSetting( effect, input, sz ) ); + size += sz; + } + *data = new cfxDataSamplerCUBE( sampler ); + } + else if ( token == (short)CFXSTRING ) + { + std::string str; + size += readString( str, input ); + *data = new cfxDataString( str ); + } + else + { + *data = NULL; + printf( "ERROR: Unknown data type of invalid token!\n" ); + } + return size; +} + +cfxEffect *cfxBinaryUtil::readEffect( FILE *input, CGcontext _context ) +{ + //read the name + std::string name; + readString( name, input ); + //read size. Its used if you want to skip effects. for now it is unused. + int size = 0; + int currSize = 0; + readInt( &size, 1, input ); + + cfxEffect* effect = new cfxEffect(name, _context); + if ( effect == NULL ) { + printf( "ERROR: Failed to create effect %s!\n", name.c_str() ); + fseek( input, (long)size, SEEK_CUR ); //move to the end + return NULL; + } + if ( size == 0 ) + { + //this is an empty effect. It will probably break when running but return it now to load properly + return effect; + } + short token; + size_t sz; + std::string surfName, surfInit, surfFormat; + do { + currSize += (int)readToken( token, input ); + switch ( token ) { + case (short)ANNOTATE_TOKEN: + effect->pushAnnotate( readAnnotate( input, sz, effect ) ); + currSize += (int)sz; + break; + case (short)NEWPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + effect->pushParam( readParam( token, input, sz, effect ) ); + currSize += (int)sz; + break; + case (short)SURFACE_TOKEN: + currSize += (int)readString( surfName, input ); + currSize += (int)readString( surfInit, input ); + currSize += (int)readString( surfFormat, input ); + effect->addNamedSurface( surfName, new cfxSurface( surfInit, surfFormat ) ); + break; + case (short)TECHNIQUE_TOKEN: + effect->pushTechnique( readTechnique( effect, input, sz ) ); + currSize += (int)sz; + break; + default: + printf( "ERROR: Unexpected Token reading effect %s!\n", name.c_str() ); + fseek( input, (long)size-currSize, SEEK_CUR ); //move to the end + return NULL; + } + }while( currSize < size ); + + return effect; +} + +cfxTechnique *cfxBinaryUtil::readTechnique( cfxEffect *effect, FILE *input, size_t &size ) +{ + std::string name; + size = readString( name, input ); + cfxTechnique *teq = new cfxTechnique( effect, name ); + int m_size = 0; //the size of this technique block after the name + int count = 0; //the amount read so far + size += readInt( &m_size, 1, input ); + if ( teq == NULL ) { + printf( "ERROR: Failed to create technique %s!\n", name.c_str() ); + fseek( input, (long)m_size, SEEK_CUR ); //move to the end + size += m_size; + return NULL; + } + if ( m_size == 0 ) + { + //empty Technique probablt makes everything break. but return it here to continue loading + return teq; + } + short token; + size_t sz; //variable to pass in for return from functions + std::string s1, s2; //temp strings used for include and surface constructors + do { + count += (int)readToken( token, input ); + switch ( token ) { + case (short)ANNOTATE_TOKEN: + teq->pushAnnotate( readAnnotate( input, sz, effect ) ); + count += (int)sz; + break; + case (short)INCLUDE_TOKEN: + count += (int)readString( s1, input ); + count += (int)readString( s2, input ); + s2.insert( 0, remotePath ); + teq->pushInclude( s1, s2 ); + break; + case (short)SURFACE_TOKEN: + count += (int)readString( s1, input ); + count += (int)readString( s2, input ); + teq->pushSurface( new cfxSurface( s1, s2 ) ); + break; + case (short)NEWPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + teq->pushParam( readParam( token, input, sz, effect ) ); + count += (int)sz; + break; + case (short)SETPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + teq->pushParam( readParam( token, input, sz, effect ) ); + count += (int)sz; + break; + case (short)PASS_TOKEN: + teq->pushPass( readPass( teq, input, sz ) ); + count += (int)sz; + break; + default: + printf( "ERROR: Unexpected Token reading teqhnique %s!", name.c_str() ); + fseek( input, (long)m_size-count, SEEK_CUR ); //move to the end + size += m_size; + return NULL; + } + }while( count < m_size ); + size += count; + return teq; +} + +cfxPass *cfxBinaryUtil::readPass( cfxTechnique *teq, FILE *input, size_t &size ) +{ + std::string name; + size = readString( name, input ); + cfxPass *pass = new cfxPass( teq, name ); + int m_size = 0; //the size of this technique block after the name + int count = 0; //the amount read so far + size += readInt( &m_size, 1, input ); + if ( pass == NULL ) { + printf( "ERROR: Failed to create pass %s!\n", name.c_str() ); + fseek( input, (long)m_size, SEEK_CUR ); //move to the end + size += m_size; + return NULL; + } + if ( m_size == 0 ) + { + //empty Pass probablt makes everything break. but return it here to continue loading + return pass; + } + short token; + size_t sz; //variable to pass in for return from functions + do { + count += (int)readToken( token, input ); + switch ( token ) { + case (short)ANNOTATE_TOKEN: + pass->pushAnnotate( readAnnotate( input, sz, teq->getEffect() ) ); + count += (int)sz; + break; + /*case (short)NEWPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + teq->pushParam( readParam( token, input, sz, effect ) ); + count += (int)sz; + break; + case (short)SETPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + teq->pushParam( readParam( token, input, sz, effect ) ); + count += (int)sz; + break;*/ + case (short)GL_SETTING_TOKEN: + pass->pushSetting( readGlSetting( pass, input, sz ) ); + count += (int)sz; + break; + case (short)SHADER_TOKEN: + pass->pushShader( readShader( pass, input, sz ) ); + count += (int)sz; + break; + default: + printf( "ERROR: Unexpected Token reading pass %s!", name.c_str() ); + fseek( input, (long)m_size-count, SEEK_CUR ); //move to the end + size += m_size; + return NULL; + } + }while( count < m_size ); + size += count; + return pass; +} + +cfxShader *cfxBinaryUtil::readShader( cfxPass *pass, FILE *input, size_t &size ) +{ + std::string name, source; + cfxShader::type_enum type; + size = readInt( (cfxInt*) (void*) &type, 1, input ); + size += readString( source, input ); + size += readString( name, input ); + cfxShader *s; + if ( type == cfxShader::VERTEX ) + { + s = new cfxShader( pass, source, name, cgGLGetLatestProfile(CG_GL_VERTEX), type ); + } + else + { + s = new cfxShader( pass, source, name, cgGLGetLatestProfile(CG_GL_FRAGMENT), type ); + } + int m_size = 0; //the size of this technique block after the name + int count = 0; //the amount read so far + size += readInt( &m_size, 1, input ); + if ( s == NULL ) { + printf( "ERROR: Failed to create shader %s - %s!\n", source.c_str(), name.c_str() ); + fseek( input, (long)m_size, SEEK_CUR ); //move to the end + size += m_size; + return NULL; + } + if ( m_size == 0 ) + { + //empty shaders are ok since it can be simple and need not parameters bound + return s; + } + short token; + size_t sz; //variable to pass in for return from functions + do { + count += (int)readToken( token, input ); + switch ( token ) { + case (short)ANNOTATE_TOKEN: + s->pushAnnotate( readAnnotate( input, sz, pass->getTechnique()->getEffect() ) ); + count += (int)sz; + break; + case (short)BINDPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + s->pushParam( readParam( token, input, sz, s ) ); + count += (int)sz; + break; + case (short)CONNECTPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + s->pushParam( readParam( token, input, sz, s ) ); + count += (int)sz; + break; + default: + printf( "ERROR: Unexpected Token reading shader %s - %s!", source.c_str(), name.c_str() ); + fseek( input, (long)m_size-count, SEEK_CUR ); //move to the end + size += m_size; + return NULL; + } + }while( count < m_size ); + size += count; + return s; +} + +cfxGlPipelineSetting *cfxBinaryUtil::readGlSetting( cfxPass *pass, FILE *input, size_t &size ) +{ + cfxGlPipelineSetting::type_enum type; + int i[4]; + float f[4]; + cfxFloat4x4 f4x4; + cfxBool4 b; + cfxSampler *sampler; + std::string source; + size_t sz; + + size = readInt( (cfxInt*)(void*)&type, 1, input ); + switch (type) { + case cfxGlPipelineSetting::ALPHA_FUNC: + size += readInt( i, 1, input ); + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingAlphaFunc(pass, i[0], f[0] ); + + case cfxGlPipelineSetting::BLEND_FUNC: + size += readInt( i, 2, input ); + return new cfxGlPipelineSettingBlendFunc(pass, i[0], i[1] ); + + case cfxGlPipelineSetting::BLEND_FUNC_SEPARATE: + size += readInt( i, 4, input ); + return new cfxGlPipelineSettingBlendFuncSeparate(pass, i[0], i[1], i[2], i[3] ); + + case cfxGlPipelineSetting::BLEND_EQUATION: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingBlendEquation(pass, i[0] ); + + case cfxGlPipelineSetting::BLEND_EQUATION_SEPARATE: + size += readInt( i, 2, input ); + return new cfxGlPipelineSettingBlendEquationSeparate(pass, i[0], i[1] ); + + case cfxGlPipelineSetting::BLEND_COLOR: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingBlendColor(pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::CLEAR_COLOR: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingClearColor(pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::CLEAR_STENCIL: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingClearStencil(pass, i[0]); + + case cfxGlPipelineSetting::CLEAR_DEPTH: + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingClearDepth(pass, f[0] ); + + case cfxGlPipelineSetting::CLIP_PLANE: + size += readInt( i, 1, input ); + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingClipPlane(pass, i[0], *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::COLOR_MASK: + size += readBool( (cfxBool*)&b, 4, input ); + return new cfxGlPipelineSettingColorMask(pass, b ); + + case cfxGlPipelineSetting::COLOR_MATERIAL: + size += readInt( i, 2, input ); + return new cfxGlPipelineSettingColorMaterial(pass, i[0], i[1] ); + + case cfxGlPipelineSetting::CULL_FACE: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingCullFace(pass, i[0] ); + + case cfxGlPipelineSetting::DEPTH_FUNC: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingDepthFunc(pass, i[0] ); + + case cfxGlPipelineSetting::DEPTH_MASK: + size += readBool( (cfxBool*)&b, 1, input ); + return new cfxGlPipelineSettingDepthMask(pass, b.b0 ); + + case cfxGlPipelineSetting::DEPTH_RANGE: + size += readFloat( f, 2, input ); + return new cfxGlPipelineSettingDepthRange(pass, *(cfxFloat2*)(void*)f ); + + case cfxGlPipelineSetting::FOG_MODE: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingFogMode(pass, i[0] ); + + case cfxGlPipelineSetting::FOG_DENSITY: + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingFogDensity(pass, f[0] ); + + case cfxGlPipelineSetting::FOG_START: + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingFogStart(pass, f[0] ); + + case cfxGlPipelineSetting::FOG_END: + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingFogEnd(pass, f[0] ); + + case cfxGlPipelineSetting::FOG_COLOR: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingFogColor(pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::FRONT_FACE: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingFrontFace(pass, i[0] ); + + case cfxGlPipelineSetting::LIGHT_MODEL_AMBEINT: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingLightModelAmbient(pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::LIGHT_AMBIENT: + size += readInt( i, 1, input ); + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingLightAmbient(pass, i[0], *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::LIGHT_CONSTANT_ATTENUATION: + size += readInt( i, 1, input ); + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingLightConstantAttenuation(pass, i[0], f[0] ); + + case cfxGlPipelineSetting::LIGHT_DIFFUSE: + size += readInt( i, 1, input ); + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingLightDiffuse(pass, i[0], *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::LIGHT_LINEAR_ATTENUATION: + size += readInt( i, 1, input ); + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingLightLinearAttenuation(pass, i[0], f[0] ); + + case cfxGlPipelineSetting::LIGHT_POSITION: + size += readInt( i, 1, input ); + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingLightPosition(pass, i[0], *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::LIGHT_QUADRATIC_ATTENUATION: + size += readInt( i, 1, input ); + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingLightQuadraticAttenuation(pass, i[0], f[0] ); + + case cfxGlPipelineSetting::LIGHT_SPECULAR: + size += readInt( i, 1, input ); + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingLightSpecular(pass, i[0], *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::LIGHT_SPOT_CUTOFF: + size += readInt( i, 1, input ); + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingLightSpotCutoff(pass, i[0], f[0] ); + + case cfxGlPipelineSetting::LIGHT_SPOT_DIRECTION: + size += readInt( i, 1, input ); + size += readFloat( f, 3, input ); + return new cfxGlPipelineSettingLightSpotDirection(pass, i[0], *(cfxFloat3*)(void*)f ); + + case cfxGlPipelineSetting::LIGHT_SPOT_EXPONENT: + size += readInt( i, 1, input ); + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingLightSpotCutoff(pass, i[0], f[0] ); + + case cfxGlPipelineSetting::LINE_WIDTH: + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingLineWidth(pass, f[0] ); + + case cfxGlPipelineSetting::LOGIC_OP: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingLogicOp(pass, i[0] ); + + case cfxGlPipelineSetting::MATERIAL_AMBIENT: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingMaterialAmbient(pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::MATERIAL_DIFFUSE: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingMaterialDiffuse(pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::MATERIAL_EMISSION: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingMaterialEmission(pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::MATERIAL_SHININESS: + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingMaterialShininess(pass, f[0] ); + + case cfxGlPipelineSetting::MATERIAL_SPECULAR: + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingMaterialSpecular( pass, *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::MODEL_VIEW_MATRIX: + size += readFloat( (cfxFloat*)&f4x4, 16, input ); + return new cfxGlPipelineSettingModelViewMatrix(pass, f4x4 ); + + case cfxGlPipelineSetting::POINT_SIZE: + size += readFloat( f, 1, input ); + return new cfxGlPipelineSettingPointSize(pass, f[0] ); + + case cfxGlPipelineSetting::POINT_SPRITE_COORD_REPLACE: + break; + + case cfxGlPipelineSetting::POINT_SPRITE_R_MODE: + break; + + case cfxGlPipelineSetting::POLYGON_MODE: + size += readInt( i, 2, input ); + return new cfxGlPipelineSettingPolygonMode(pass, i[0], i[1] ); + + case cfxGlPipelineSetting::POLYGON_OFFSET: + size += readFloat( f, 2, input ); + return new cfxGlPipelineSettingPolygonOffset(pass, *(cfxFloat2*)(void*)f ); + + case cfxGlPipelineSetting::PROJECTION_MATRIX: + size += readFloat( (cfxFloat*)&f4x4, 16, input ); + return new cfxGlPipelineSettingProjectionMatrix(pass, f4x4 ); + + case cfxGlPipelineSetting::SCISSOR: + size += readInt( i, 4, input ); + return new cfxGlPipelineSettingScissor(pass, *(cfxInt4*)(void*)i ); + + case cfxGlPipelineSetting::SHADE_MODEL: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingShadeModel(pass, i[0] ); + + case cfxGlPipelineSetting::STENCIL_FUNC: + size += readInt( i, 3, input ); + return new cfxGlPipelineSettingStencilFunc(pass, i[0], i[1], i[2] ); + + case cfxGlPipelineSetting::STENCIL_MASK: + size += readInt( i, 1, input ); + return new cfxGlPipelineSettingStencilMask(pass, i[0] ); + + case cfxGlPipelineSetting::STENCIL_OP: + size += readInt( i, 3, input ); + return new cfxGlPipelineSettingStencilOp(pass, i[0], i[1], i[2] ); + + case cfxGlPipelineSetting::STENCIL_FUNC_SEPARATE: + size += readInt( i, 4, input ); + return new cfxGlPipelineSettingStencilFuncSeparate(pass, i[0], i[1], i[2], i[3] ); + + case cfxGlPipelineSetting::STENCIL_MASK_SEPARATE: + size += readInt( i, 2, input ); + return new cfxGlPipelineSettingStencilMaskSeparate(pass, i[0], i[1] ); + + case cfxGlPipelineSetting::STENCIL_OP_SEPAREATE: + size += readInt( i, 4, input ); + return new cfxGlPipelineSettingStencilOpSeparate(pass, i[0], i[1], i[2], i[3] ); + + case cfxGlPipelineSetting::TEX_GEN_S_MODE: + break; + + case cfxGlPipelineSetting::TEX_GEN_T_MODE: + break; + + case cfxGlPipelineSetting::TEX_GEN_R_MODE: + break; + + case cfxGlPipelineSetting::TEX_GEN_Q_MODE: + break; + + case cfxGlPipelineSetting::TEX_GEN_S_EYE_PLANE: + break; + + case cfxGlPipelineSetting::TEX_GEN_T_EYE_PLANE: + break; + + case cfxGlPipelineSetting::TEX_GEN_R_EYE_PLANE: + break; + + case cfxGlPipelineSetting::TEX_GEN_Q_EYE_PLANE: + break; + + case cfxGlPipelineSetting::TEX_GEN_S_OBJECT_PLANE: + break; + + case cfxGlPipelineSetting::TEX_GEN_T_OBJECT_PLANE: + break; + + case cfxGlPipelineSetting::TEX_GEN_R_OBJECT_PLANE: + break; + + case cfxGlPipelineSetting::TEX_GEN_Q_OBJECT_PLANE: + break; + + case cfxGlPipelineSetting::TEXTURE_2D: + size += readInt( i, 1, input ); + size += readString( source, input ); + size += readInt( (i+1), 1, input ); + sampler = new cfxSampler( source, pass->getTechnique()->getEffect() ); + for ( int x = 0; x < i[1]; ++x ) + { + sampler->pushSetting( readSamplerSetting( pass->getTechnique()->getEffect(), input, sz ) ); + size += sz; + } + return new cfxGlPipelineSettingTexture2D( pass, i[0], sampler ); + + case cfxGlPipelineSetting::TEXTURE_3D: + size += readInt( i, 1, input ); + size += readString( source, input ); + size += readInt( (i+1), 1, input ); + sampler = new cfxSampler( source, pass->getTechnique()->getEffect() ); + for ( int x = 0; x < i[1]; ++x ) + { + sampler->pushSetting( readSamplerSetting( pass->getTechnique()->getEffect(), input, sz ) ); + size += sz; + } + return new cfxGlPipelineSettingTexture3D( pass, i[0], sampler ); + + case cfxGlPipelineSetting::TEXTURE_CUBE_MAP: + size += readInt( i, 1, input ); + size += readString( source, input ); + size += readInt( (i+1), 1, input ); + sampler = new cfxSampler( source, pass->getTechnique()->getEffect() ); + for ( int x = 0; x < i[1]; ++x ) + { + sampler->pushSetting( readSamplerSetting( pass->getTechnique()->getEffect(), input, sz ) ); + size += sz; + } + return new cfxGlPipelineSettingTextureCubeMap( pass, i[0], sampler ); + + case cfxGlPipelineSetting::TEXTURE_ENV_COLOR: + size += readInt( i, 1, input ); + size += readFloat( f, 4, input ); + return new cfxGlPipelineSettingTextureEnvColor(pass, i[0], *(cfxFloat4*)(void*)f ); + + case cfxGlPipelineSetting::TEXTURE_ENV_MODE: + size += readInt( i, 2, input ); + return new cfxGlPipelineSettingTextureEnvMode(pass, i[0], i[1] ); + + case cfxGlPipelineSetting::ALPHA_TEST_ENABLE: + size += readBool( (cfxBool*)&b, 1, input); + return new cfxGlPipelineSettingAlphaTestEnable(pass, b.b0 ); + + case cfxGlPipelineSetting::BLEND_ENABLE: + size += readBool( (cfxBool*)&b, 1, input); + return new cfxGlPipelineSettingBlendEnable(pass, b.b0 ); + + case cfxGlPipelineSetting::CULL_FACE_ENABLE: + size += readBool( (cfxBool*)&b, 1, input); + return new cfxGlPipelineSettingCullFaceEnable(pass, b.b0 ); + + case cfxGlPipelineSetting::DEPTH_TEST_ENABLE: + size += readBool( (cfxBool*)&b, 1, input); + return new cfxGlPipelineSettingDepthTestEnable(pass, b.b0 ); + + default: + printf( "ERROR: Unknown GL Pipeline Setting or invalid token!\n" ); + break; + } + return NULL; +} + +cfxGlSamplerSetting *cfxBinaryUtil::readSamplerSetting( cfxEffect *effect, FILE *input, size_t &size ) +{ + int i; + float f; + cfxBool b; + cfxFloat4 f4; + + cfxGlSamplerSetting::type_enum type; + size = readInt( (cfxInt*)(void*)&type, 1, input ); + switch ( type ) + { + case cfxGlSamplerSetting::WRAP_S: + size += readInt( &i, 1, input ); + return new cfxGlSamplerSettingWrapS( effect, "WrapS", i ); + case cfxGlSamplerSetting::WRAP_T: + size += readInt( &i, 1, input ); + return new cfxGlSamplerSettingWrapT( effect, "WrapT", i ); + case cfxGlSamplerSetting::MINFILTER: + size += readInt( &i, 1, input ); + return new cfxGlSamplerSettingMinFilter( effect, "MinFilter", i ); + case cfxGlSamplerSetting::MAGFILTER: + size += readInt( &i, 1, input ); + return new cfxGlSamplerSettingMagFilter( effect, "MagFilter", i ); + case cfxGlSamplerSetting::BORDER_COLOR: + size += readFloat( (cfxFloat*)&f4, 4, input ); + return new cfxGlSamplerSettingBorderColor( effect, "BorderColor", f4 ); + case cfxGlSamplerSetting::GENERATE_MIPMAP: + size += readBool( &b, 1, input ); + return new cfxGlSamplerSettingGenerateMipMap( effect, "GenerateMipMap", b ); + case cfxGlSamplerSetting::MAX_MIP_LEVEL: + size += readFloat( &f, 1, input ); + return new cfxGlSamplerSettingMaxMipLevel( effect, "MaxMipLevel", f ); + case cfxGlSamplerSetting::LOD_BIAS: + size += readFloat( &f, 1, input ); + return new cfxGlSamplerSettingLodBias( effect, "LodBias", f ); + default: + printf( "ERROR: Unknown sampler setting type or invalid token!\n" ); + break; + } + return NULL; +} + +cfxMaterial *cfxBinaryUtil::readMaterial( FILE *input, CGcontext _context, const std::map<std::string, cfxEffect*> *effects ) +{ + (void)_context; + //read the name + std::string name, effectName; + readString( name, input ); + readString( effectName, input ); + //read size. Its used if you want to skip effects. for now it is unused. + int size = 0; + int currSize = 0; + readInt( &size, 1, input ); + + cfxEffect* effect = NULL; + + if (effects) + { + std::map<std::string, cfxEffect*>::const_iterator effectFinder = effects->find(effectName); + if (effectFinder != effects->end()) + { + effect = effectFinder->second; + } + } + if ( effect == NULL ) + { + printf( "Could not find effect %s associated with material %s\n", effectName.c_str(), name.c_str() ); + } + + cfxMaterial* material = new cfxMaterial( name, effectName, effect ); + if ( material == NULL ) { + printf( "ERROR: Failed to create material %s!\n", name.c_str() ); + fseek( input, (long)size, SEEK_CUR ); //move to the end + return NULL; + } + if ( size == 0 ) + { + //empty material + return material; + } + std::string surfName, surfInit, surfFormat; + cfxSurface *surface = NULL, *newSurface = NULL; + short token; + size_t sz; + do { + currSize += (int)readToken( token, input ); + switch ( token ) { + case (short)SETPARAM_TOKEN: + //at this time you can only have newparams so pass in effect as other + material->pushParam( readParam( token, input, sz, effect ) ); + currSize += (int)sz; + break; + case (short)SURFACE_TOKEN: + currSize += (int)readString( surfName, input ); + currSize += (int)readString( surfInit, input ); + currSize += (int)readString( surfFormat, input ); + surface = effect->getSurfaceByName(surfName); + newSurface = new cfxSurface( surfInit, surfFormat, surface ); + material->addSurface(newSurface); + break; + default: + printf( "ERROR: Unexpected Token reading material %s!", name.c_str() ); + fseek( input, (long)size-currSize, SEEK_CUR ); //move to the end + return NULL; + } + }while( currSize < size ); + + return material; +} + + + + +cfxBool cfxBinaryUtil::save(const std::string& file, const std::map<std::string, cfxMaterial*>& materials, + const std::map<std::string, cfxEffect*>& effects, cfxBool replace ) +{ + FILE *out = NULL; + if(!replace) + { + FILE *tempfd = fopen(file.c_str(),"r"); + if(tempfd != NULL) + { + // File exists, return error + fclose(tempfd); + printf( "File %s already exists and replace is false.\n", file.c_str() ); + return false; + } + } + out = fopen( file.c_str(), "wb" ); + if ( out == NULL ) + { + printf( "Failed to open %s for writing.\n", file.c_str() ); + return false; + } + // It'd be better if this code just did a getcwd call instead of relying on the DOM for this + DAE dae; + fileName = file; + daeURI tmp( dae, fileName.c_str() ); + tmp.validate(); + fileName = tmp.getURI(); + fileName = fileName.substr( 7 ); //remove the file:// + writeFileHeader( out ); + std::map<std::string, cfxEffect *>::const_iterator effectIter = effects.begin(); + while ( effectIter != effects.end() ) + { + writeEffect( effectIter->second, out ); + effectIter++; + } + + std::map<std::string, cfxMaterial *>::const_iterator matIter = materials.begin(); + while ( matIter != materials.end() ) + { + writeMaterial( matIter->second, out ); + matIter++; + } + + fclose( out ); + return true; + +} + +size_t cfxBinaryUtil::writeString( const std::string &str, FILE *out ) +{ + fputs( str.c_str(), out ); + fputc( '\0', out ); + return str.length() +1; +} + +size_t cfxBinaryUtil::writeBool( const cfxBool *buf, size_t count, FILE *out ) +{ + return fwrite( buf, sizeof(cfxBool), count, out ) * sizeof(cfxBool); +} + +size_t cfxBinaryUtil::writeInt( const cfxInt *buf, size_t count, FILE *out ) +{ +#ifdef WIN32 + //win32 requires endian swap + cfxInt *tempBuf = new cfxInt[count]; //create a temp buffer because of const parameter + memcpy( tempBuf, buf, count * sizeof( cfxInt ) ); + for ( size_t i = 0; i < count; ++i ) + { + endianSwap( tempBuf+i ); + } + size_t sz = fwrite( tempBuf, sizeof(cfxInt), count, out ) * sizeof(cfxInt); + delete[] tempBuf; + return sz; +#else + return fwrite( buf, sizeof(cfxInt), count, out ) * sizeof(cfxInt); +#endif +} + +size_t cfxBinaryUtil::writeFloat( const cfxFloat *buf, size_t count, FILE *out ) +{ +#ifdef WIN32 + //win32 requires endian swap + cfxFloat *tempBuf = new cfxFloat[count]; //create a temp buffer because of const parameter + memcpy( tempBuf, buf, count * sizeof( cfxFloat ) ); + for ( size_t i = 0; i < count; ++i ) + { + endianSwap( tempBuf+i ); + } + size_t sz = fwrite( tempBuf, sizeof(cfxFloat), count, out ) * sizeof(cfxFloat); + delete[] tempBuf; + return sz; +#else + return fwrite( buf, sizeof(cfxFloat), count, out ) * sizeof(cfxFloat); +#endif +} + +size_t cfxBinaryUtil::writeToken( short token, FILE *out ) +{ +#ifdef WIN32 + //win32 requires endian swap + endianSwap( &token ); +#endif + fwrite( &token, CFX_BIN_TOKEN_SIZE, 1, out ); + return CFX_BIN_TOKEN_SIZE; +} + +void cfxBinaryUtil::writeFileHeader( FILE *out ) +{ + size_t byteCount = 4 + sizeof( cfxInt ); // add the space needed for the offset itself + int idnver = (COLLADA_FX_BIN_ID << 8 )+ COLLADA_FX_BIN_VER; +#ifdef WIN32 + endianSwap( &idnver ); +#endif + fwrite( &idnver, 4, 1, out ); //write out the id and version + writeInt( (cfxInt*)(&byteCount), 1, out ); //write the offset + +} + +void cfxBinaryUtil::writeEffect( const cfxEffect *effect, FILE *out ) +{ + size_t size = 0; + writeToken( (short)EFFECT_TOKEN, out ); + writeString( effect->getName(), out ); + fpos_t offsetPos; + fgetpos(out, &offsetPos); //Save the position so we can come back and write the size in later + writeInt( (cfxInt*)(&size), 1, out ); //Write dummy int as temporary size + for ( unsigned int i = 0; i < effect->getAnnotateArray().size(); ++i ) { + size += writeAnnotate( effect->getAnnotateArray()[i], out ); + } + for ( unsigned int i = 0; i < effect->getParamArray().size(); ++i ) { + size += writeParam( effect->getParamArray()[i], out ); + } + std::map<std::string, cfxSurface*>::const_iterator iter = effect->getSurfaceMap().begin(); + while ( iter != effect->getSurfaceMap().end() ) { + const cfxSurface *s = iter->second; + size += writeToken( (short)SURFACE_TOKEN, out ); + size += writeString( iter->first, out ); + size += writeString( s->getInitFrom(), out ); + size += writeString( s->getFormat(), out ); + ++iter; + } + for ( unsigned int i = 0; i < effect->getTechniqueArray().size(); ++i ) { + size += writeTechnique( effect->getTechniqueArray()[i], out ); + } + + fsetpos( out, &offsetPos ); //move back to the offset position + writeInt( (cfxInt*)(&size), 1, out ); //Write out the real size + fseek( out, (long)size, SEEK_CUR ); //move to the end to write more data +} + +size_t cfxBinaryUtil::writeAnnotate( const cfxAnnotate *an, FILE *out ) +{ + size_t sz = writeToken( (short)ANNOTATE_TOKEN, out); + sz += writeString( an->getName(), out ); + sz += writeTypedData( an->getData(), out ); + return sz; +} + +size_t cfxBinaryUtil::writeParam( const cfxParam *p, FILE *out ) +{ + cfxParam::cfxParamTypeEnum type = p->getType(); + const cfxBindParam *bp; + const cfxConnectParam *cp; + const cfxNewParam *np; + const cfxSetParam *sp; + size_t sz = 0; + switch ( type ) + { + case cfxParam::CFXBINDPARAM: + bp = (cfxBindParam*)p; + sz += writeToken( (short)BINDPARAM_TOKEN, out ); + sz += writeString( bp->getName(), out ); + sz += writeTypedData( bp->getData(), out ); + return sz; + + case cfxParam::CFXCONNECTPARAM: + cp = (cfxConnectParam*)p; + sz += writeToken( (short)CONNECTPARAM_TOKEN, out ); + sz += writeString( cp->getName(), out ); + sz += writeString( cp->getFromName(), out ); + return sz; + + case cfxParam::CFXNEWPARAM: + np = (cfxNewParam*)p; + sz += writeToken( (short)NEWPARAM_TOKEN, out ); + sz += writeString( np->getName(), out ); + sz += writeString( np->getSemantic(), out ); + sz += writeTypedData( np->getData(), out ); + return sz; + + case cfxParam::CFXSETPARAM: + sp = (cfxSetParam*)p; + sz += writeToken( (short)SETPARAM_TOKEN, out ); + sz += writeString( sp->getName(), out ); + sz += writeTypedData( sp->getData(), out ); + return sz; + + default: + printf( "Unknown param type!\n"); + break; + } + return 0; +} + +size_t cfxBinaryUtil::writeTypedData( const cfxData *data, FILE *out ) +{ + const cfxSampler *sampler; + size_t count; + size_t size = 0; + + CGtype t = data->getType(); + switch ( t ) + { + case CG_BOOL: + size += writeToken( (short)CFXBOOL0, out ); + size += writeBool( &(((cfxDataBool*)data)->getData()), 1, out ); + return size; + + case CG_BOOL1: + size += writeToken( (short)CFXBOOL1, out ); + size += writeBool( (cfxBool*)&(((cfxDataBool1*)data)->getData()), 1, out ); + return size; + + case CG_BOOL2: + size += writeToken( (short)CFXBOOL2, out ); + size += writeBool( (cfxBool*)&(((cfxDataBool2*)data)->getData()), 2, out ); + return size; + + case CG_BOOL3: + size += writeToken( (short)CFXBOOL3, out ); + size += writeBool( (cfxBool*)&(((cfxDataBool3*)data)->getData()), 3, out ); + return size; + + case CG_BOOL4: + size += writeToken( (short)CFXBOOL4, out ); + size += writeBool( (cfxBool*)&(((cfxDataBool4*)data)->getData()), 4, out ); + return size; + + case CG_INT: + size += writeToken( (short)CFXINT0, out ); + size += writeInt( (cfxInt*)&(((cfxDataInt*)data)->getData()), 1, out ); + return size; + + case CG_INT1: + size += writeToken( (short)CFXINT1, out ); + size += writeInt( (cfxInt*)&(((cfxDataInt1*)data)->getData()), 1, out ); + return size; + + case CG_INT2: + size += writeToken( (short)CFXINT2, out ); + size += writeInt( (cfxInt*)&(((cfxDataInt2*)data)->getData()), 2, out ); + return size; + + case CG_INT3: + size += writeToken( (short)CFXINT3, out ); + size += writeInt( (cfxInt*)&(((cfxDataInt3*)data)->getData()), 3, out ); + return size; + + case CG_INT4: + size += writeToken( (short)CFXINT4, out ); + size += writeInt( (cfxInt*)&(((cfxDataInt4*)data)->getData()), 4, out ); + return size; + + case CG_FLOAT: + size += writeToken( (short)CFXFLOAT0, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat*)data)->getData()), 1, out ); + return size; + + case CG_FLOAT1: + size += writeToken( (short)CFXFLOAT1, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat1*)data)->getData()), 1, out ); + return size; + + case CG_FLOAT2: + size += writeToken( (short)CFXFLOAT2, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat2*)data)->getData()), 2, out ); + return size; + + case CG_FLOAT3: + size += writeToken( (short)CFXFLOAT3, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat3*)data)->getData()), 3, out ); + return size; + + case CG_FLOAT4: + size += writeToken( (short)CFXFLOAT4, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat4*)data)->getData()), 4, out ); + return size; + + case CG_FLOAT2x2: + size += writeToken( (short)CFXFLOAT2X2, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat2x2*)data)->getData()), 4, out ); + return size; + + case CG_FLOAT3x3: + size += writeToken( (short)CFXFLOAT3X3, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat3x3*)data)->getData()), 9, out ); + return size; + + case CG_FLOAT4x4: + size += writeToken( (short)CFXFLOAT4X4, out ); + size += writeFloat( (cfxFloat*)&(((cfxDataFloat4x4*)data)->getData()), 16, out ); + return size; + + case CG_SAMPLER1D: + sampler = ((cfxDataSampler1D*)data)->getData(); + size = writeToken( (short)CFXSAMPLER1D, out ); + size += writeString( sampler->getSource(), out ); + count = sampler->getSettingArray().size(); + size += writeInt( (cfxInt*)&count, 1, out ); + for ( size_t x = 0; x < count; ++x ) { + size += writeSamplerSetting( sampler->getSettingArray()[x], out ); + } + return size; + + case CG_SAMPLER2D: + sampler = ((cfxDataSampler2D*)data)->getData(); + size = writeToken( (short)CFXSAMPLER2D, out ); + size += writeString( sampler->getSource(), out ); + count = sampler->getSettingArray().size(); + size += writeInt( (cfxInt*)&count, 1, out ); + for ( size_t x = 0; x < count; ++x ) { + size += writeSamplerSetting( sampler->getSettingArray()[x], out ); + } + return size; + + case CG_SAMPLER3D: + sampler = ((cfxDataSampler3D*)data)->getData(); + size = writeToken( (short)CFXSAMPLER3D, out ); + size += writeString( sampler->getSource(), out ); + count = sampler->getSettingArray().size(); + size += writeInt( (cfxInt*)&count, 1, out ); + for ( size_t x = 0; x < count; ++x ) { + size += writeSamplerSetting( sampler->getSettingArray()[x], out ); + } + return size; + + case CG_SAMPLERCUBE: + sampler = ((cfxDataSamplerCUBE*)data)->getData(); + size = writeToken( (short)CFXSAMPLERCUBE, out ); + size += writeString( sampler->getSource(), out ); + count = sampler->getSettingArray().size(); + size += writeInt( (cfxInt*)&count, 1, out ); + for ( size_t x = 0; x < count; ++x ) { + size += writeSamplerSetting( sampler->getSettingArray()[x], out ); + } + return size; + + case CG_STRING: + size += writeToken( (short)CFXSTRING, out ); + size += writeString( ((cfxDataString*)data)->getData(), out ); + return size; + + default: + printf( "Unknown data type!\n"); + break; + } + + return 0; +} + +size_t cfxBinaryUtil::writeTechnique( const cfxTechnique *teq, FILE *out ) +{ + size_t size = writeToken( (short)TECHNIQUE_TOKEN, out ); + size += writeString( teq->getName(), out ); + fpos_t offsetPos; + fgetpos(out, &offsetPos); + size_t byteCount = 0; //used to store the size of the technique body + size += writeInt( (cfxInt*)&byteCount, 1, out ); + for ( unsigned int i = 0; i < teq->getAnnotateArray().size(); ++i ) { + byteCount += writeAnnotate( teq->getAnnotateArray()[i], out ); + } + const std::map<std::string, std::string> &inc = teq->getIncludeMap(); + std::map<std::string, std::string>::const_iterator iter = inc.begin(); + while ( iter != inc.end() ) { + byteCount += writeToken( (short)INCLUDE_TOKEN, out ); + byteCount += writeString( iter->first, out ); + byteCount += writeString( makeRelativePath(iter->second, fileName ), out ); + ++iter; + } + for ( unsigned int i = 0; i < teq->getSurfaceArray().size(); ++i ) { + const cfxSurface *s = teq->getSurfaceArray()[i]; + byteCount += writeToken( (short)SURFACE_TOKEN, out ); + byteCount += writeString( s->getInitFrom(), out ); + byteCount += writeString( s->getFormat(), out ); + } + for ( unsigned int i = 0; i < teq->getParamArray().size(); ++i ) { + byteCount += writeParam( teq->getParamArray()[i], out ); + } + for ( unsigned int i = 0; i < teq->getPassArray().size(); ++i ) { + byteCount += writePass( teq->getPassArray()[i], out ); + } + fsetpos( out, &offsetPos ); //move back to the offset position + writeInt( (cfxInt*)(&byteCount), 1, out ); //Write out the real size + fseek( out, (long)byteCount, SEEK_CUR ); //move to the end to write more data + size += byteCount; + return size; +} + +size_t cfxBinaryUtil::writePass( const cfxPass *pass, FILE *out ) +{ + size_t size = writeToken( (short)PASS_TOKEN, out ); + size += writeString( pass->getName(), out ); + fpos_t offsetPos; + fgetpos(out, &offsetPos); + size_t byteCount = 0; //used to store the size of the pass body + size += writeInt( (cfxInt*)&byteCount, 1, out ); + for ( unsigned int i = 0; i < pass->getAnnotateArray().size(); ++i ) { + byteCount += writeAnnotate( pass->getAnnotateArray()[i], out ); + } + for ( unsigned int i = 0; i < pass->getParamArray().size(); ++i ) { + byteCount += writeParam( pass->getParamArray()[i], out ); + } + for ( unsigned int i = 0; i < pass->getSettingArray().size(); ++i ) { + byteCount += writeGLSetting( pass->getSettingArray()[i], out ); + } + for ( unsigned int i = 0; i < pass->getShaderArray().size(); ++i ) { + byteCount += writeShader( pass->getShaderArray()[i], out ); + } + fsetpos( out, &offsetPos ); //move back to the offset position + writeInt( (cfxInt*)(&byteCount), 1, out ); //Write out the real size + fseek( out, (long)byteCount, SEEK_CUR ); //move to the end to write more data + size += byteCount; + return size; +} + +size_t cfxBinaryUtil::writeShader( const cfxShader *shader, FILE *out ) +{ + size_t size = writeToken( (short)SHADER_TOKEN, out ); + cfxShader::type_enum type = shader->getOriginalType(); + size += writeInt( (cfxInt*)(void*)&type, 1, out ); + size += writeString( shader->getSource(), out ); + size += writeString( shader->getName(), out ); + fpos_t offsetPos; + fgetpos(out, &offsetPos); + size_t byteCount = 0; //used to store the size of the pass body + size += writeInt( (cfxInt*)&byteCount, 1, out ); + for ( unsigned int i = 0; i < shader->getAnnotateArray().size(); ++i ) { + byteCount += writeAnnotate( shader->getAnnotateArray()[i], out ); + } + for ( unsigned int i = 0; i < shader->getParamArray().size(); ++i ) { + byteCount += writeParam( shader->getParamArray()[i], out ); + } + fsetpos( out, &offsetPos ); //move back to the offset position + writeInt( (cfxInt*)(&byteCount), 1, out ); //Write out the real size + fseek( out, (long)byteCount, SEEK_CUR ); //move to the end to write more data + size += byteCount; + return size; +} + +size_t cfxBinaryUtil::writeGLSetting( const cfxGlPipelineSetting *s, FILE *out ) +{ + cfxGlPipelineSetting::type_enum type = s->getType(); + size_t size = writeToken( (short)GL_SETTING_TOKEN, out ); + size += writeInt( (cfxInt*)(void*)&type, 1, out ); + + if ( type == cfxGlPipelineSetting::ALPHA_FUNC ) + { + cfxGlPipelineSettingAlphaFunc *gls = (cfxGlPipelineSettingAlphaFunc*)s; + int i = gls->getFunc(); + float f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::BLEND_FUNC ) + { + cfxGlPipelineSettingBlendFunc *gls = (cfxGlPipelineSettingBlendFunc*)s; + int i[2] = { gls->getSrc(), gls->getDst() }; + size += writeInt( i, 2, out ); + } + else if ( type == cfxGlPipelineSetting::BLEND_FUNC_SEPARATE ) + { + cfxGlPipelineSettingBlendFuncSeparate *gls = (cfxGlPipelineSettingBlendFuncSeparate*)s; + int i[4] = { gls->getSrcRGB(), gls->getSrcRGB(), gls->getSrcAlpha(), gls->getDstAlpha() }; + size += writeInt( i, 4, out ); + } + else if ( type == cfxGlPipelineSetting::BLEND_EQUATION ) + { + cfxGlPipelineSettingBlendEquation *gls = (cfxGlPipelineSettingBlendEquation*)s; + int i = gls->getEquation(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::BLEND_EQUATION_SEPARATE ) + { + cfxGlPipelineSettingBlendEquationSeparate *gls = (cfxGlPipelineSettingBlendEquationSeparate*)s; + int i[2] = { gls->getRgb(), gls->getAlpha() }; + size += writeInt( i, 2, out ); + } + else if ( type == cfxGlPipelineSetting::BLEND_COLOR ) + { + cfxGlPipelineSettingBlendColor *gls = (cfxGlPipelineSettingBlendColor*)s; + cfxFloat4 f = gls->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::CLEAR_COLOR ) + { + cfxGlPipelineSettingClearColor *gls = (cfxGlPipelineSettingClearColor*)s; + cfxFloat4 f = gls->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::CLEAR_STENCIL ) + { + cfxGlPipelineSettingClearStencil *gls = (cfxGlPipelineSettingClearStencil*)s; + int i = gls->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::CLEAR_DEPTH ) + { + cfxGlPipelineSettingClearDepth *gls = (cfxGlPipelineSettingClearDepth*)s; + float f = gls->getValue(); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::CLIP_PLANE ) + { + cfxGlPipelineSettingClipPlane *gls = (cfxGlPipelineSettingClipPlane*)s; + int i = gls->getIndex(); + cfxFloat4 f = gls->getValue(); + size += writeInt( &i, 1, out) ; + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::COLOR_MASK ) + { + cfxGlPipelineSettingColorMask *gls = (cfxGlPipelineSettingColorMask*)s; + cfxBool4 b = gls->getValue(); + size += writeBool( (cfxBool*)&b, 4, out ); + } + else if ( type == cfxGlPipelineSetting::COLOR_MATERIAL ) + { + cfxGlPipelineSettingColorMaterial *gls = (cfxGlPipelineSettingColorMaterial*)s; + int i[2] = { gls->getFace(), gls->getMode() }; + size += writeInt( i, 2, out ); + } + else if ( type == cfxGlPipelineSetting::CULL_FACE ) + { + int i = ((cfxGlPipelineSettingCullFace*)s)->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::DEPTH_FUNC ) + { + int i = ((cfxGlPipelineSettingDepthFunc*)s)->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::DEPTH_MASK ) + { + cfxBool b = ((cfxGlPipelineSettingDepthMask*)s)->getValue(); + size += writeBool( &b, 1, out ); + } + else if ( type == cfxGlPipelineSetting::DEPTH_RANGE ) + { + cfxFloat2 f = ((cfxGlPipelineSettingDepthRange*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 2, out ); + } + else if ( type == cfxGlPipelineSetting::FOG_MODE ) + { + int i = ((cfxGlPipelineSettingFogMode*)s)->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::FOG_DENSITY ) + { + float f = ((cfxGlPipelineSettingFogDensity*)s)->getValue(); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::FOG_START ) + { + float f = ((cfxGlPipelineSettingFogStart*)s)->getValue(); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::FOG_END ) + { + float f = ((cfxGlPipelineSettingFogEnd*)s)->getValue(); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::FOG_COLOR ) + { + cfxFloat4 f = ((cfxGlPipelineSettingFogColor*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::FRONT_FACE ) + { + int i = ((cfxGlPipelineSettingFrontFace*)s)->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_MODEL_AMBEINT ) + { + cfxFloat4 f = ((cfxGlPipelineSettingLightModelAmbient*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_AMBIENT ) + { + cfxGlPipelineSettingLightAmbient *gls = (cfxGlPipelineSettingLightAmbient*)s; + int i = gls->getIndex(); + cfxFloat4 f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_CONSTANT_ATTENUATION ) + { + cfxGlPipelineSettingLightConstantAttenuation *gls = (cfxGlPipelineSettingLightConstantAttenuation*)s; + int i = gls->getIndex(); + float f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_DIFFUSE ) + { + cfxGlPipelineSettingLightDiffuse *gls = (cfxGlPipelineSettingLightDiffuse*)s; + int i = gls->getIndex(); + cfxFloat4 f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_LINEAR_ATTENUATION ) + { + cfxGlPipelineSettingLightLinearAttenuation *gls = (cfxGlPipelineSettingLightLinearAttenuation*)s; + int i = gls->getIndex(); + float f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_POSITION ) + { + cfxGlPipelineSettingLightPosition *gls = (cfxGlPipelineSettingLightPosition*)s; + int i = gls->getIndex(); + cfxFloat4 f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_QUADRATIC_ATTENUATION ) + { + cfxGlPipelineSettingLightQuadraticAttenuation *gls = (cfxGlPipelineSettingLightQuadraticAttenuation*)s; + int i = gls->getIndex(); + float f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_SPECULAR ) + { + cfxGlPipelineSettingLightSpecular *gls = (cfxGlPipelineSettingLightSpecular*)s; + int i = gls->getIndex(); + cfxFloat4 f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_SPOT_CUTOFF ) + { + cfxGlPipelineSettingLightSpotCutoff *gls = (cfxGlPipelineSettingLightSpotCutoff*)s; + int i = gls->getIndex(); + float f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_SPOT_DIRECTION ) + { + cfxGlPipelineSettingLightSpotDirection *gls = (cfxGlPipelineSettingLightSpotDirection*)s; + int i = gls->getIndex(); + cfxFloat3 f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( (cfxFloat*)&f, 3, out ); + } + else if ( type == cfxGlPipelineSetting::LIGHT_SPOT_EXPONENT ) + { + cfxGlPipelineSettingLightSpotExponent *gls = (cfxGlPipelineSettingLightSpotExponent*)s; + int i = gls->getIndex(); + float f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::LINE_WIDTH ) + { + float f = ((cfxGlPipelineSettingLineWidth*)s)->getValue(); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::LOGIC_OP ) + { + int i = ((cfxGlPipelineSettingLogicOp*)s)->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::MATERIAL_AMBIENT ) + { + cfxFloat4 f = ((cfxGlPipelineSettingMaterialAmbient*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::MATERIAL_DIFFUSE ) + { + cfxFloat4 f = ((cfxGlPipelineSettingMaterialDiffuse*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::MATERIAL_EMISSION ) + { + cfxFloat4 f = ((cfxGlPipelineSettingMaterialEmission*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::MATERIAL_SHININESS ) + { + float f = ((cfxGlPipelineSettingMaterialShininess*)s)->getValue(); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::MATERIAL_SPECULAR ) + { + cfxFloat4 f = ((cfxGlPipelineSettingMaterialSpecular*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::MODEL_VIEW_MATRIX ) + { + cfxFloat4x4 f = ((cfxGlPipelineSettingModelViewMatrix*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 16, out ); + } + else if ( type == cfxGlPipelineSetting::POINT_SIZE ) + { + float f = ((cfxGlPipelineSettingPointSize*)s)->getValue(); + size += writeFloat( &f, 1, out ); + } + else if ( type == cfxGlPipelineSetting::POINT_SPRITE_COORD_REPLACE ) + { + } + else if ( type == cfxGlPipelineSetting::POINT_SPRITE_R_MODE ) + { + } + else if ( type == cfxGlPipelineSetting::POLYGON_MODE ) + { + cfxGlPipelineSettingPolygonMode *gls = (cfxGlPipelineSettingPolygonMode*)s; + int i[2] = { gls->getFace(), gls->getMode() }; + size += writeInt( i, 2, out ); + } + else if ( type == cfxGlPipelineSetting::POLYGON_OFFSET ) + { + cfxFloat2 f = ((cfxGlPipelineSettingPolygonOffset*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 2, out ); + } + else if ( type == cfxGlPipelineSetting::PROJECTION_MATRIX ) + { + cfxFloat4x4 f = ((cfxGlPipelineSettingProjectionMatrix*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f, 16, out ); + } + else if ( type == cfxGlPipelineSetting::SCISSOR ) + { + cfxInt4 i = ((cfxGlPipelineSettingScissor*)s)->getValue(); + size += writeInt( (cfxInt*)&i, 4, out ); + } + else if ( type == cfxGlPipelineSetting::SHADE_MODEL ) + { + int i = ((cfxGlPipelineSettingShadeModel*)s)->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::STENCIL_FUNC ) + { + cfxGlPipelineSettingStencilFunc *gls = (cfxGlPipelineSettingStencilFunc*)s; + int i[3] = { gls->getFunc(), gls->getRef(), gls->getMask() }; + size += writeInt( i, 3, out ); + } + else if ( type == cfxGlPipelineSetting::STENCIL_MASK ) + { + int i = ((cfxGlPipelineSettingStencilMask*)s)->getValue(); + size += writeInt( &i, 1, out ); + } + else if ( type == cfxGlPipelineSetting::STENCIL_OP ) + { + cfxGlPipelineSettingStencilOp *gls = (cfxGlPipelineSettingStencilOp*)s; + int i[3] = { gls->getFail(), gls->getZFail(), gls->getZPass() }; + size += writeInt( i, 3, out ); + } + else if ( type == cfxGlPipelineSetting::STENCIL_FUNC_SEPARATE ) + { + cfxGlPipelineSettingStencilFuncSeparate *gls = (cfxGlPipelineSettingStencilFuncSeparate*)s; + int i[4] = { gls->getFront(), gls->getBack(), gls->getRef(), gls->getMask() }; + size += writeInt( i, 4, out ); + } + else if ( type == cfxGlPipelineSetting::STENCIL_MASK_SEPARATE ) + { + cfxGlPipelineSettingStencilMaskSeparate *gls = (cfxGlPipelineSettingStencilMaskSeparate*)s; + int i[2] = { gls->getFace(), gls->getMask() }; + size += writeInt( i, 2, out ); + } + else if ( type == cfxGlPipelineSetting::STENCIL_OP_SEPAREATE ) + { + cfxGlPipelineSettingStencilOpSeparate *gls = (cfxGlPipelineSettingStencilOpSeparate*)s; + int i[4] = { gls->getFace(), gls->getFail(), gls->getZFail(), gls->getZPass() }; + size += writeInt( i, 4, out ); + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_S_MODE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_T_MODE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_R_MODE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_Q_MODE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_S_EYE_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_T_EYE_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_R_EYE_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_Q_EYE_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_S_OBJECT_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_T_OBJECT_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_R_OBJECT_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEX_GEN_Q_OBJECT_PLANE ) + { + } + else if ( type == cfxGlPipelineSetting::TEXTURE_2D ) + { + cfxGlPipelineSettingTexture2D *gls = (cfxGlPipelineSettingTexture2D*)s; + int i = gls->getIndex(); + const cfxSampler *sampler = gls->getSampler(); + size_t count = sampler->getSettingArray().size(); + size += writeInt( &i, 1, out ); + size += writeString( sampler->getSource(), out ); + size += writeInt( (cfxInt*)&count, 1, out ); + for ( size_t x = 0; x < count; ++x ) { + size += writeSamplerSetting( sampler->getSettingArray()[x], out ); + } + } + else if ( type == cfxGlPipelineSetting::TEXTURE_3D ) + { + cfxGlPipelineSettingTexture3D *gls = (cfxGlPipelineSettingTexture3D*)s; + int i = gls->getIndex(); + const cfxSampler *sampler = gls->getSampler(); + size_t count = sampler->getSettingArray().size(); + size += writeInt( &i, 1, out ); + size += writeString( sampler->getSource(), out ); + size += writeInt( (cfxInt*)&count, 1, out ); + for ( size_t x = 0; x < count; ++x ) { + size += writeSamplerSetting( sampler->getSettingArray()[x], out ); + } + } + else if ( type == cfxGlPipelineSetting::TEXTURE_CUBE_MAP ) + { + cfxGlPipelineSettingTextureCubeMap *gls = (cfxGlPipelineSettingTextureCubeMap*)s; + int i = gls->getIndex(); + const cfxSampler *sampler = gls->getSampler(); + size_t count = sampler->getSettingArray().size(); + size += writeInt( &i, 1, out ); + size += writeString( sampler->getSource(), out ); + size += writeInt( (cfxInt*)&count, 1, out ); + for ( size_t x = 0; x < count; ++x ) { + size += writeSamplerSetting( sampler->getSettingArray()[x], out ); + } + } + else if ( type == cfxGlPipelineSetting::TEXTURE_ENV_COLOR ) + { + cfxGlPipelineSettingTextureEnvColor *gls = (cfxGlPipelineSettingTextureEnvColor*)s; + int i = gls->getIndex(); + cfxFloat4 f = gls->getValue(); + size += writeInt( &i, 1, out ); + size += writeFloat( (cfxFloat*)&f, 4, out ); + } + else if ( type == cfxGlPipelineSetting::TEXTURE_ENV_MODE ) + { + cfxGlPipelineSettingTextureEnvMode *gls = (cfxGlPipelineSettingTextureEnvMode*)s; + int i[2] = { gls->getIndex(), gls->getValue() }; + size += writeInt( i, 2, out ); + } + else if ( type == cfxGlPipelineSetting::ALPHA_TEST_ENABLE ) + { + cfxBool b = ((cfxGlPipelineSettingAlphaTestEnable*)s)->getValue(); + size += writeBool( &b, 1, out ); + } + else if ( type == cfxGlPipelineSetting::BLEND_ENABLE ) + { + cfxBool b = ((cfxGlPipelineSettingBlendEnable*)s)->getValue(); + size += writeBool( &b, 1, out ); + } + else if ( type == cfxGlPipelineSetting::CULL_FACE_ENABLE ) + { + cfxBool b = ((cfxGlPipelineSettingCullFaceEnable*)s)->getValue(); + size += writeBool( &b, 1, out ); + } + else if ( type == cfxGlPipelineSetting::DEPTH_TEST_ENABLE ) + { + cfxBool b = ((cfxGlPipelineSettingDepthTestEnable*)s)->getValue(); + size += writeBool( &b, 1, out ); + } + return size; +} + +size_t cfxBinaryUtil::writeSamplerSetting( const cfxGlSamplerSetting *s, FILE *out ) +{ + cfxGlSamplerSetting::type_enum type = s->getType(); + size_t size = writeInt( (cfxInt*)(void*)&type, 1, out ); + int i; + float f; + cfxFloat4 f4; + cfxBool b; + + switch ( type ) + { + case cfxGlSamplerSetting::WRAP_S: + i = ((cfxGlSamplerSettingWrapS*)s)->getValue(); + size += writeInt( &i, 1, out ); + break; + case cfxGlSamplerSetting::WRAP_T: + i = ((cfxGlSamplerSettingWrapT*)s)->getValue(); + size += writeInt( &i, 1, out ); + break; + case cfxGlSamplerSetting::MINFILTER: + i = ((cfxGlSamplerSettingMinFilter*)s)->getValue(); + size += writeInt( &i, 1, out ); + break; + case cfxGlSamplerSetting::MAGFILTER: + i = ((cfxGlSamplerSettingMagFilter*)s)->getValue(); + size += writeInt( &i, 1, out ); + break; + case cfxGlSamplerSetting::BORDER_COLOR: + f4 = ((cfxGlSamplerSettingBorderColor*)s)->getValue(); + size += writeFloat( (cfxFloat*)&f4, 4, out ); + break; + case cfxGlSamplerSetting::GENERATE_MIPMAP: + b = ((cfxGlSamplerSettingGenerateMipMap*)s)->getValue(); + size += writeBool( &b, 1, out ); + break; + case cfxGlSamplerSetting::MAX_MIP_LEVEL: + f = ((cfxGlSamplerSettingMaxMipLevel*)s)->getValue(); + size += writeFloat( &f, 1, out ); + break; + case cfxGlSamplerSetting::LOD_BIAS: + f = ((cfxGlSamplerSettingLodBias*)s)->getValue(); + size += writeFloat( &f, 1, out ); + break; + default: + printf( "Unknown sampler setting type or bad token!\n" ); + break; + } + return size; +} + +void cfxBinaryUtil::writeMaterial( const cfxMaterial *material, FILE *out ) +{ + size_t size = 0; + writeToken( (short)MATERIAL_TOKEN, out ); + writeString( material->getName(), out ); + writeString( material->getEffectName(), out ); + fpos_t offsetPos; + fgetpos(out, &offsetPos); //Save the position so we can come back and write the size in later + writeInt( (cfxInt*)(&size), 1, out ); //Write dummy int as temporary size + for ( unsigned int i = 0; i < material->getParamArray().size(); ++i ) + { + size += writeParam( material->getParamArray()[i], out ); + } + for ( unsigned int i = 0; i < material->getSurfaces().size(); ++i ) + { + cfxSurface *s = material->getSurfaces()[i]; + std::string name = material->getEffect()->getSurfaceName( s->getParentSurface() ); + size += writeToken( (short)SURFACE_TOKEN, out ); + size += writeString( name, out ); + size += writeString( s->getInitFrom(), out ); + size += writeString( s->getFormat(), out ); + } + + fsetpos( out, &offsetPos ); //move back to the offset position + writeInt( (cfxInt*)(&size), 1, out ); //Write out the real size + fseek( out, (long)size, SEEK_CUR ); //move to the end to write more data +} + +std::string cfxBinaryUtil::makeRelativePath( const std::string &path, const std::string &relTo ) +{ + const char *this_filepath = path.c_str(); + const char *relativeTo_filepath = relTo.c_str(); + const char *this_slash = this_filepath; + const char *relativeTo_slash = relativeTo_filepath; + + while(*this_filepath == *relativeTo_filepath) + { + if(*this_filepath == '/') + { + this_slash = this_filepath; + relativeTo_slash = relativeTo_filepath; + } + this_filepath++; + relativeTo_filepath++; + } + + // Decide how many ../ segments are needed (Filepath should always end in a /) + int segment_count = 0; + relativeTo_slash++; + while(*relativeTo_slash != 0) + { + if(*relativeTo_slash == '/') + segment_count ++; + relativeTo_slash++; + } + this_slash++; + + std::string newPath; + for(int i = 0; i < segment_count; i++) + { + newPath.append( "../" ); + } + //add rest of original path + if ( cfxLoader::getPlatformString() == "PC-OGL" ) { + newPath.append( this_filepath ); + return newPath; + } + return this_filepath; +} + diff --git a/1.4.0/fx/src/cfxBindParam.cpp b/1.4.0/fx/src/cfxBindParam.cpp new file mode 100644 index 0000000..aea18a2 --- /dev/null +++ b/1.4.0/fx/src/cfxBindParam.cpp @@ -0,0 +1,55 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> + +// User includes + +#include <cfxBindParam.h> +#include <cfxShader.h> +#include <cfxData.h> + +// cfxBindParam +cfxBindParam::cfxBindParam(const std::string& _name, cfxShader* _shader, cfxData* _data) + : cfxParam(_name), + shader(_shader), + data(_data) +{ +} + +bool cfxBindParam::apply() +{ + parameter = cgGetNamedParameter(shader->getProgram(), name.c_str()); + + if (data) + { + data->apply(this); + } + else + { + printf("Value settings not implemented yet for bind params - data must support all cg types for this.\n"); + } + + return true; +} + +bool cfxBindParam::validate() const +{ + return true; +} + +cfxParam::cfxParamTypeEnum cfxBindParam::getType() const +{ + return cfxParam::CFXBINDPARAM; +} + +const cfxData *cfxBindParam::getData() const +{ + return data; +} diff --git a/1.4.0/fx/src/cfxCode.cpp b/1.4.0/fx/src/cfxCode.cpp new file mode 100644 index 0000000..323053a --- /dev/null +++ b/1.4.0/fx/src/cfxCode.cpp @@ -0,0 +1,48 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +// User includes + +#include <cfxCode.h> + + +// cfxCode +cfxCode::cfxCode(cfxEffect* _effect, const std::string& _name, + const std::string& _profile, const std::string& _code) + : effect(_effect), + name(_name), + profile(_profile), + code(_code) +{} + +bool cfxCode::apply() +{ + // there is nothing to do with code until the platform supports compilation at run time + + /* + program = cgCreateProgram(effect->getContext(), + CGenum program_type, + code.c_str(), + CGprofile profile, + const char *entry, + const char **args); + */ + + return true; +} + +bool cfxCode::validate() const +{ + return true; +} + diff --git a/1.4.0/fx/src/cfxConnectParam.cpp b/1.4.0/fx/src/cfxConnectParam.cpp new file mode 100644 index 0000000..331f858 --- /dev/null +++ b/1.4.0/fx/src/cfxConnectParam.cpp @@ -0,0 +1,66 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> + +// User includes + +#include <cfxConnectParam.h> +#include <cfxShader.h> +#include <cfxPass.h> +#include <cfxTechnique.h> +#include <cfxEffect.h> + +// cfxConnectParam +cfxConnectParam::cfxConnectParam(const std::string& _name, cfxShader* _shader, + const std::string& _fromName) + : cfxParam(_name), + shader(_shader), + fromName(_fromName) +{ + // dest parameter intended to be in a program + parameter = cgGetNamedParameter(shader->getProgram(), name.c_str()); + if (parameter == 0) + { + // nothing to stop it from being in an effect + // parameter = cgGetNamedEffectParameter(shader->getPass()->getTechnique()->getEffect()->getEffect(), name.c_str()); + parameter = shader->getPass()->getTechnique()->getEffect()->getParameterByName(name); + } + + // source parameter is from an effect + // fromParameter = cgGetNamedEffectParameter(shader->getPass()->getTechnique()->getEffect()->getEffect(), fromName.c_str()); + fromParameter = shader->getPass()->getTechnique()->getEffect()->getParameterByName(fromName); + + if ( fromParameter ) + { + printf("Connect to param %s %p from param %s %p\n", name.c_str(), parameter, fromName.c_str(), fromParameter); + cgConnectParameter(fromParameter, parameter); + } +} + +bool cfxConnectParam::apply() +{ + return true; +} + +bool cfxConnectParam::validate() const +{ + return true; +} + +cfxParam::cfxParamTypeEnum cfxConnectParam::getType() const +{ + return cfxParam::CFXCONNECTPARAM; +} + +const std::string &cfxConnectParam::getFromName() const +{ + return fromName; +} + diff --git a/1.4.0/fx/src/cfxData.cpp b/1.4.0/fx/src/cfxData.cpp new file mode 100644 index 0000000..e91b1e7 --- /dev/null +++ b/1.4.0/fx/src/cfxData.cpp @@ -0,0 +1,714 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <assert.h> + +// User includes + +#include <cfxData.h> +#include <cfxParam.h> +#include <cfxAnnotate.h> +#include <cfxSampler.h> + +//#ifndef _LIB +#include <Cg/cg.h> +#include <Cg/cgGL.h> +//#else +//#include <cfxNoCg.h> +//#endif + + +// cfxData +bool cfxData::apply(cfxParam* param) +{ + (void)param; + printf("ERROR! Attempted to apply data of a type which is unsupported for parameters.\n"); + return false; +} + +bool cfxData::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("ERROR! Attempted to apply data of a type which is unsupported for annotations.\n"); + return false; +} + + +// cfxDataBool +cfxDataBool::cfxDataBool(const cfxBool& _data) + : data(_data) +{ +} + +CGtype cfxDataBool::getType() const +{ + return CG_BOOL; +} + +bool cfxDataBool::apply(cfxParam* param) +{ + cgSetParameter1f(param->getParameter(), (float)data); + return true; +} + +bool cfxDataBool::apply(cfxAnnotate* annotate) +{ + cgSetBoolAnnotation(annotate->getAnnotation(), data); + return true; +} + +const cfxBool &cfxDataBool::getData() const +{ + return data; +} + + +// cfxDataBool1 +cfxDataBool1::cfxDataBool1(const cfxBool1& _data) + : data(_data) +{ +} + +CGtype cfxDataBool1::getType() const +{ + return CG_BOOL1; +} + +bool cfxDataBool1::apply(cfxParam* param) +{ + cgSetParameter1f(param->getParameter(), (float)data.b0); + return true; +} + +bool cfxDataBool1::apply(cfxAnnotate* annotate) +{ + cgSetBoolAnnotation(annotate->getAnnotation(), data.b0); + return true; +} + +const cfxBool1 &cfxDataBool1::getData() const +{ + return data; +} + + +// cfxDataBool2 +cfxDataBool2::cfxDataBool2(const cfxBool2& _data) + : data(_data) +{ +} + +CGtype cfxDataBool2::getType() const +{ + return CG_BOOL2; +} + +bool cfxDataBool2::apply(cfxParam* param) +{ + cgSetParameter2f(param->getParameter(), (float)data.b0, (float)data.b1); + return true; +} + +bool cfxDataBool2::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_BOOL2 not implemented yet.\n"); + return true; +} + +const cfxBool2 &cfxDataBool2::getData() const +{ + return data; +} + + +// cfxDataBool3 +cfxDataBool3::cfxDataBool3(const cfxBool3& _data) + : data(_data) +{ +} + +CGtype cfxDataBool3::getType() const +{ + return CG_BOOL3; +} + +bool cfxDataBool3::apply(cfxParam* param) +{ + cgSetParameter3f(param->getParameter(), (float)data.b0, (float)data.b1, (float)data.b2); + return true; +} + +bool cfxDataBool3::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_BOOL3 not implemented yet.\n"); + return true; +} + +const cfxBool3 &cfxDataBool3::getData() const +{ + return data; +} + + +// cfxDataBool4 +cfxDataBool4::cfxDataBool4(const cfxBool4& _data) + : data(_data) +{ +} + +CGtype cfxDataBool4::getType() const +{ + return CG_BOOL4; +} + +bool cfxDataBool4::apply(cfxParam* param) +{ + cgSetParameter4f(param->getParameter(), (float)data.b0, (float)data.b1, (float)data.b2, (float)data.b3); + return true; +} + +bool cfxDataBool4::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_BOOL4 not implemented yet.\n"); + return true; +} + +const cfxBool4 &cfxDataBool4::getData() const +{ + return data; +} + + +// cfxDataInt +cfxDataInt::cfxDataInt(const cfxInt& _data) + : data(_data) +{ +} + +CGtype cfxDataInt::getType() const +{ + return CG_INT; +} + +bool cfxDataInt::apply(cfxParam* param) +{ + cgSetParameter1f(param->getParameter(), (float)data); + return true; +} + +bool cfxDataInt::apply(cfxAnnotate* annotate) +{ + cgSetIntAnnotation(annotate->getAnnotation(), data); + return true; +} + +const cfxInt &cfxDataInt::getData() const +{ + return data; +} + + +// cfxDataInt1 +cfxDataInt1::cfxDataInt1(const cfxInt1& _data) + : data(_data) +{ +} + +CGtype cfxDataInt1::getType() const +{ + return CG_INT1; +} + +bool cfxDataInt1::apply(cfxParam* param) +{ + cgSetParameter1f(param->getParameter(), (float)data.i0); + return true; +} + +bool cfxDataInt1::apply(cfxAnnotate* annotate) +{ + cgSetIntAnnotation(annotate->getAnnotation(), data.i0); + return true; +} + +const cfxInt1 &cfxDataInt1::getData() const +{ + return data; +} + + +// cfxDataInt2 +cfxDataInt2::cfxDataInt2(const cfxInt2& _data) + : data(_data) +{ +} + +CGtype cfxDataInt2::getType() const +{ + return CG_INT2; +} + +bool cfxDataInt2::apply(cfxParam* param) +{ + cgSetParameter2f(param->getParameter(), (float)data.i0, (float)data.i1); + return true; +} + +bool cfxDataInt2::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_INT2 not implemented yet.\n"); + return true; +} + +const cfxInt2 &cfxDataInt2::getData() const +{ + return data; +} + + +// cfxDataInt3 +cfxDataInt3::cfxDataInt3(const cfxInt3& _data) + : data(_data) +{ +} + +CGtype cfxDataInt3::getType() const +{ + return CG_INT3; +} + +bool cfxDataInt3::apply(cfxParam* param) +{ + cgSetParameter3f(param->getParameter(), (float)data.i0, (float)data.i1, (float)data.i2); + return true; +} + +bool cfxDataInt3::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_INT3 not implemented yet.\n"); + return true; +} + +const cfxInt3 &cfxDataInt3::getData() const +{ + return data; +} + + +// cfxDataInt4 +cfxDataInt4::cfxDataInt4(const cfxInt4& _data) + : data(_data) +{ +} + +CGtype cfxDataInt4::getType() const +{ + return CG_INT4; +} + +bool cfxDataInt4::apply(cfxParam* param) +{ + cgSetParameter4f(param->getParameter(), (float)data.i0, (float)data.i1, (float)data.i2, (float)data.i3); + return true; +} + +bool cfxDataInt4::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_INT4 not implemented yet.\n"); + return true; +} + +const cfxInt4 &cfxDataInt4::getData() const +{ + return data; +} + + +// cfxDataFloat +cfxDataFloat::cfxDataFloat(const cfxFloat& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat::getType() const +{ + return CG_FLOAT; +} + +bool cfxDataFloat::apply(cfxParam* param) +{ + cgSetParameter1f(param->getParameter(), data); + return true; +} + +bool cfxDataFloat::apply(cfxAnnotate* annotate) +{ + cgSetFloatAnnotation(annotate->getAnnotation(), data); + return true; +} + +const cfxFloat &cfxDataFloat::getData() const +{ + return data; +} + + +// cfxDataFloat1 +cfxDataFloat1::cfxDataFloat1(const cfxFloat1& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat1::getType() const +{ + return CG_FLOAT; +} + +bool cfxDataFloat1::apply(cfxParam* param) +{ + cgSetParameter1f(param->getParameter(), data.f0); + return true; +} + +bool cfxDataFloat1::apply(cfxAnnotate* annotate) +{ + cgSetFloatAnnotation(annotate->getAnnotation(), data.f0); + return true; +} + +const cfxFloat1 &cfxDataFloat1::getData() const +{ + return data; +} + + +// cfxDataFloat2 +cfxDataFloat2::cfxDataFloat2(const cfxFloat2& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat2::getType() const +{ + return CG_FLOAT2; +} + +bool cfxDataFloat2::apply(cfxParam* param) +{ + cgSetParameter2f(param->getParameter(), data.f0, data.f1); + return true; +} + +bool cfxDataFloat2::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_FLOAT2 not implemented yet.\n"); + return true; +} + +const cfxFloat2 &cfxDataFloat2::getData() const +{ + return data; +} + + +// cfxDataFloat3 +cfxDataFloat3::cfxDataFloat3(const cfxFloat3& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat3::getType() const +{ + return CG_FLOAT3; +} + +bool cfxDataFloat3::apply(cfxParam* param) +{ + cgSetParameter3f(param->getParameter(), data.f0, data.f1, data.f2); + return true; +} + +bool cfxDataFloat3::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_FLOAT3 not implemented yet.\n"); + return true; +} + +const cfxFloat3 &cfxDataFloat3::getData() const +{ + return data; +} + + +// cfxDataFloat4 +cfxDataFloat4::cfxDataFloat4(const cfxFloat4& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat4::getType() const +{ + return CG_FLOAT4; +} + +bool cfxDataFloat4::apply(cfxParam* param) +{ + cgSetParameter4f(param->getParameter(), data.f0, data.f1, data.f2, data.f3); + return true; +} + +bool cfxDataFloat4::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_FLOAT4 not implemented yet.\n"); + return true; +} + +const cfxFloat4 &cfxDataFloat4::getData() const +{ + return data; +} + + +// cfxDataFloat2x2 +cfxDataFloat2x2::cfxDataFloat2x2(const cfxFloat2x2& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat2x2::getType() const +{ + return CG_FLOAT2x2; +} + +bool cfxDataFloat2x2::apply(cfxParam* param) +{ + // using column major matrix setting because i think that is what is used by COLLADA + cgSetMatrixParameterfc(param->getParameter(), &data.f00); + return true; +} + +bool cfxDataFloat2x2::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_FLOAT2x2 not implemented yet.\n"); + return true; +} + +const cfxFloat2x2 &cfxDataFloat2x2::getData() const +{ + return data; +} + + +// cfxDataFloat3x3 +cfxDataFloat3x3::cfxDataFloat3x3(const cfxFloat3x3& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat3x3::getType() const +{ + return CG_FLOAT3x3; +} + +bool cfxDataFloat3x3::apply(cfxParam* param) +{ + // using column major matrix setting because i think that is what is used by COLLADA + cgSetMatrixParameterfc(param->getParameter(), &data.f00); + return true; +} + +bool cfxDataFloat3x3::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_FLOAT3x3 not implemented yet.\n"); + return true; +} + +const cfxFloat3x3 &cfxDataFloat3x3::getData() const +{ + return data; +} + + +// cfxDataFloat4x4 +cfxDataFloat4x4::cfxDataFloat4x4(const cfxFloat4x4& _data) + : data(_data) +{ +} + +CGtype cfxDataFloat4x4::getType() const +{ + return CG_FLOAT4x4; +} + +bool cfxDataFloat4x4::apply(cfxParam* param) +{ + // using column major matrix setting because i think that is what is used by COLLADA + cgSetMatrixParameterfc(param->getParameter(), &data.f00); + return true; +} + +bool cfxDataFloat4x4::apply(cfxAnnotate* annotate) +{ + (void)annotate; + printf("API to support annotations of type CG_FLOAT4x4 not implemented yet.\n"); + return true; +} + +const cfxFloat4x4 &cfxDataFloat4x4::getData() const +{ + return data; +} + + +// cfxDataSampler1D +cfxDataSampler1D::cfxDataSampler1D(cfxSampler* _data) + : data(_data) +{ +} + +CGtype cfxDataSampler1D::getType() const +{ + return CG_SAMPLER1D; +} + +bool cfxDataSampler1D::apply(cfxParam* /*param*/) +{ + return true; +} + +const cfxSampler *cfxDataSampler1D::getData() const +{ + return data; +} + +// cfxDataSampler2D +cfxDataSampler2D::cfxDataSampler2D(cfxSampler* _data) + : data(_data) +{ +} +cfxDataSampler2D::~cfxDataSampler2D() +{ + delete data; +} + +CGtype cfxDataSampler2D::getType() const +{ + return CG_SAMPLER2D; +} + +bool cfxDataSampler2D::apply(cfxParam* param) +{ + // get the texture ID from the sampler + GLuint textureId = 0; + + // the sampler really should never be NULL + assert(data); + + // call the sampler apply to + // 1) initialize texture id by resolving source + // 2) have its states and stuff applied + data->apply(param); + + textureId = data->getTextureId(); + + // i think textureId should never be zero + // set the parameter for this sampler's texture id + // using managed textures replaces the need to call enabletextureparameter + cgGLSetTextureParameter(param->getParameter(), textureId); + + if (textureId == 0) + { + printf("ERROR: sampler had texture Id of zero, states not set.\n"); + } + + return true; +} + +const cfxSampler *cfxDataSampler2D::getData() const +{ + return data; +} + +// cfxDataSampler3D +cfxDataSampler3D::cfxDataSampler3D(cfxSampler* _data) + : data(_data) +{ +} + +CGtype cfxDataSampler3D::getType() const +{ + return CG_SAMPLER3D; +} + +bool cfxDataSampler3D::apply(cfxParam* /*param*/) +{ + return true; +} + +const cfxSampler *cfxDataSampler3D::getData() const +{ + return data; +} + +// cfxDataSamplerCUBE +cfxDataSamplerCUBE::cfxDataSamplerCUBE(cfxSampler* _data) + : data(_data) +{ +} + +CGtype cfxDataSamplerCUBE::getType() const +{ + return CG_SAMPLERCUBE; +} + +bool cfxDataSamplerCUBE::apply(cfxParam* /*param*/) +{ + return true; +} + +const cfxSampler *cfxDataSamplerCUBE::getData() const +{ + return data; +} + +// cfxDataString +cfxDataString::cfxDataString(const std::string& _data) + : data(_data) +{ +} + +CGtype cfxDataString::getType() const +{ + return CG_STRING; +} + +bool cfxDataString::apply(cfxAnnotate* annotate) +{ + cgSetStringAnnotation(annotate->getAnnotation(), data.c_str()); + return true; +} + +const std::string &cfxDataString::getData() const +{ + return data; +} + + diff --git a/1.4.0/fx/src/cfxDataMaker.cpp b/1.4.0/fx/src/cfxDataMaker.cpp new file mode 100644 index 0000000..658130e --- /dev/null +++ b/1.4.0/fx/src/cfxDataMaker.cpp @@ -0,0 +1,927 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +#include <cfxDataMaker.h> +#include <cfxData.h> +#include <cfxEffect.h> +#include <cfxGlEnumMaps.h> +#include <cfxSampler.h> +#include <cfxGlSamplerSetting.h> + +#include <dom/domFx_basic_type_common.h> +#include <dom/domCg_param_type.h> +#include <dom/domFx_annotate_type_common.h> +#include <dom/domConstants.h> + + +// cfxDataMaker +std::map<std::string, cfxDataMaker*> cfxDataMaker::mapTypeNameToDataMaker; + +cfxData* cfxDataMaker::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + printf("No support for common parameter data of type: %s\n", paramInitializer->getContents().get(0)->getTypeName()); + return NULL; +} + + +cfxData* cfxDataMaker::makeData(domCg_param_type* paramInitializer, cfxEffect*) +{ + printf("No support for cg parameter data of type: %s\n", paramInitializer->getContents().get(0)->getTypeName()); + return NULL; +} + + +cfxData* cfxDataMaker::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + printf("No support for common annotation data of type: %s\n", annotateInitializer->getContents().get(0)->getTypeName()); + return NULL; +} + +cfxData* cfxDataMaker::makeDataForParam(domFx_basic_type_common* paramInitializer, cfxEffect* effect) +{ + //printf("make data for fx common param\n"); + std::map<std::string, cfxDataMaker*>::iterator iter; + // here is the element which owns the actual data + // it is a choice in schema, so there will be only one element in _contents that exists as the "chosen" item, + // which will be one of the elements in this class + daeElement* dataElement = paramInitializer->getContents().get(0); + // get typename from contents, use this to lookup the factory for the data + //printf("param for type %s\n", dataElement->getTypeName()); + daeString dataTypeName = dataElement->getTypeName(); + iter = mapTypeNameToDataMaker.find(dataTypeName); + if (iter == mapTypeNameToDataMaker.end()) + { + printf("ERROR: cfxDataMaker not found for common param type name %s\n", dataTypeName); + return NULL; + } + return iter->second->makeData(paramInitializer, effect); +} + +cfxData* cfxDataMaker::makeDataForParam(domCg_param_type* paramInitializer, cfxEffect* effect) +{ + //printf("make data for CG param\n"); + std::map<std::string, cfxDataMaker*>::iterator iter; + // here is the element which owns the actual data + // it is a choice in schema, so there will be only one element in _contents that exists as the "chosen" item, + // which will be one of the elements in this class + daeElement* dataElement = paramInitializer->getContents().get(0); + // get typename from contents, use this to lookup the factory for the data + //printf("param for type %s\n", dataElement->getTypeName()); + daeString dataTypeName = dataElement->getTypeName(); + iter = mapTypeNameToDataMaker.find(dataTypeName); + if (iter == mapTypeNameToDataMaker.end()) + { + printf("ERROR: cfxDataMaker not found for cg param type name %s\n", dataTypeName); + return NULL; + } + return iter->second->makeData(paramInitializer, effect); +} + +cfxData* cfxDataMaker::makeDataForAnnotate(domFx_annotate_type_common* annotateInitializer, cfxEffect* effect) +{ + //printf("make data for common annotate\n"); + std::map<std::string, cfxDataMaker*>::iterator iter; + // then here is the element which owns the actual data + // it is a choice in schema, so there will be only one element in _contents that exists as the "chosen" item, + // which will be one of the elements in this class + daeElement* dataElement = annotateInitializer->getContents().get(0); + // get typename from contents, use this to lookup the factory for the data + daeString dataTypeName = dataElement->getTypeName(); + iter = mapTypeNameToDataMaker.find(dataTypeName); + if (iter == mapTypeNameToDataMaker.end()) + { + printf("ERROR: cfxDataMaker not found for common annotate type name %s\n", dataTypeName); + return NULL; + } + return iter->second->makeData(annotateInitializer, effect); +} + + +// BASIC DATA MAKERS + +// cfxDataMakerBool +cfxDataMakerBool::cfxDataMakerBool() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_BOOL, this)); +} + +cfxDataMakerBool cfxDataMakerBool::maker; + +cfxDataBool* newDataBool(const domBool& db) +{ + cfxBool b; + b = db; + cfxDataBool* data = new cfxDataBool(b); + return data; +} + +cfxData* cfxDataMakerBool::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataBool(paramInitializer->getBool()->getValue()); +} + +cfxData* cfxDataMakerBool::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataBool(annotateInitializer->getBool()->getValue()); +} + + +// cfxDataMakerBool1 +cfxDataMakerBool1::cfxDataMakerBool1() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_BOOL1, this)); +} + +cfxDataMakerBool1 cfxDataMakerBool1::maker; + +cfxDataBool1* newDataBool1(const domBool& db) +{ + cfxBool1 b1; + b1.b0 = db; + cfxDataBool1* data = new cfxDataBool1(b1); + return data; +} + +cfxData* cfxDataMakerBool1::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataBool1(paramInitializer->getBool()->getValue()); +} + +cfxData* cfxDataMakerBool1::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataBool1(annotateInitializer->getBool()->getValue()); +} + + +// cfxDataMakerBool2 +cfxDataMakerBool2::cfxDataMakerBool2() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_BOOL2, this)); +} + +cfxDataMakerBool2 cfxDataMakerBool2::maker; + +cfxDataBool2* newDataBool2(const domBool2& db2) +{ + cfxBool2 b2; + b2.b0 = db2.get(0); + b2.b1 = db2.get(1); + cfxDataBool2* data = new cfxDataBool2(b2); + return data; +} + +cfxData* cfxDataMakerBool2::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataBool2(paramInitializer->getBool2()->getValue()); +} + +cfxData* cfxDataMakerBool2::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataBool2(annotateInitializer->getBool2()->getValue()); +} + + +// cfxDataMakerBool3 +cfxDataMakerBool3::cfxDataMakerBool3() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_BOOL3, this)); +} + +cfxDataMakerBool3 cfxDataMakerBool3::maker; + +cfxDataBool3* newDataBool3(const domBool3& db3) +{ + cfxBool3 b3; + b3.b0 = db3.get(0); + b3.b1 = db3.get(1); + b3.b2 = db3.get(2); + cfxDataBool3* data = new cfxDataBool3(b3); + return data; +} + +cfxData* cfxDataMakerBool3::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataBool3(paramInitializer->getBool3()->getValue()); +} + +cfxData* cfxDataMakerBool3::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataBool3(annotateInitializer->getBool3()->getValue()); +} + + +// cfxDataMakerBool4 +cfxDataMakerBool4::cfxDataMakerBool4() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_BOOL4, this)); +} + +cfxDataMakerBool4 cfxDataMakerBool4::maker; + +cfxDataBool4* newDataBool4(const domBool4& db4) +{ + cfxBool4 b4; + b4.b0 = db4.get(0); + b4.b1 = db4.get(1); + b4.b2 = db4.get(2); + b4.b3 = db4.get(3); + cfxDataBool4* data = new cfxDataBool4(b4); + return data; +} + +cfxData* cfxDataMakerBool4::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataBool4(paramInitializer->getBool4()->getValue()); +} + +cfxData* cfxDataMakerBool4::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataBool4(annotateInitializer->getBool4()->getValue()); +} + + +// cfxDataMakerInt +cfxDataMakerInt::cfxDataMakerInt() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_INT, this)); +} + +cfxDataMakerInt cfxDataMakerInt::maker; + +cfxDataInt* newDataInt(const domInt& di) +{ + cfxInt i; + i = (cfxInt) di; + cfxDataInt* data = new cfxDataInt(i); + return data; +} + +cfxData* cfxDataMakerInt::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataInt(paramInitializer->getInt()->getValue()); +} + +cfxData* cfxDataMakerInt::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataInt(annotateInitializer->getInt()->getValue()); +} + + +// cfxDataMakerInt1 +cfxDataMakerInt1::cfxDataMakerInt1() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_INT1, this)); +} + +cfxDataMakerInt1 cfxDataMakerInt1::maker; + +cfxDataInt1* newDataInt1(const domInt& di) +{ + cfxInt1 i1; + i1.i0 = (cfxInt) di; + cfxDataInt1* data = new cfxDataInt1(i1); + return data; +} + +cfxData* cfxDataMakerInt1::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataInt1(paramInitializer->getInt()->getValue()); +} + +cfxData* cfxDataMakerInt1::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataInt1(annotateInitializer->getInt()->getValue()); +} + + +// cfxDataMakerInt2 +cfxDataMakerInt2::cfxDataMakerInt2() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_INT2, this)); +} + +cfxDataMakerInt2 cfxDataMakerInt2::maker; + +cfxDataInt2* newDataInt2(const domInt2& di2) +{ + cfxInt2 i2; + i2.i0 = (cfxInt) di2.get(0); + i2.i1 = (cfxInt) di2.get(1); + cfxDataInt2* data = new cfxDataInt2(i2); + return data; +} + +cfxData* cfxDataMakerInt2::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataInt2(paramInitializer->getInt2()->getValue()); +} + +cfxData* cfxDataMakerInt2::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataInt2(annotateInitializer->getInt2()->getValue()); +} + + +// cfxDataMakerInt3 +cfxDataMakerInt3::cfxDataMakerInt3() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_INT3, this)); +} + +cfxDataMakerInt3 cfxDataMakerInt3::maker; + +cfxDataInt3* newDataInt3(const domInt3& di3) +{ + cfxInt3 i3; + i3.i0 = (cfxInt) di3.get(0); + i3.i1 = (cfxInt) di3.get(1); + i3.i2 = (cfxInt) di3.get(2); + cfxDataInt3* data = new cfxDataInt3(i3); + return data; +} + +cfxData* cfxDataMakerInt3::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataInt3(paramInitializer->getInt3()->getValue()); +} + +cfxData* cfxDataMakerInt3::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataInt3(annotateInitializer->getInt3()->getValue()); +} + + +// cfxDataMakerInt4 +cfxDataMakerInt4::cfxDataMakerInt4() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_INT4, this)); +} + +cfxDataMakerInt4 cfxDataMakerInt4::maker; + +cfxDataInt4* newDataInt4(const domInt4& di4) +{ + cfxInt4 i4; + i4.i0 = (cfxInt) di4.get(0); + i4.i1 = (cfxInt) di4.get(1); + i4.i2 = (cfxInt) di4.get(2); + i4.i3 = (cfxInt) di4.get(3); + cfxDataInt4* data = new cfxDataInt4(i4); + return data; +} + +cfxData* cfxDataMakerInt4::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataInt4(paramInitializer->getInt4()->getValue()); +} + +cfxData* cfxDataMakerInt4::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataInt4(annotateInitializer->getInt4()->getValue()); +} + + +// cfxDataMakerFloat +cfxDataMakerFloat::cfxDataMakerFloat() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT, this)); +} + +cfxDataMakerFloat cfxDataMakerFloat::maker; + +cfxDataFloat* newDataFloat(const domFloat& df) +{ + cfxFloat f; + f = (cfxFloat) df; + cfxDataFloat* data = new cfxDataFloat(f); + return data; +} + +cfxData* cfxDataMakerFloat::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat(paramInitializer->getFloat()->getValue()); +} + +cfxData* cfxDataMakerFloat::makeData(domCg_param_type* paramInitializer, cfxEffect*) +{ + return newDataFloat(paramInitializer->getFloat()->getValue()); +} + +cfxData* cfxDataMakerFloat::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat(annotateInitializer->getFloat()->getValue()); +} + + +// cfxDataMakerFloat1 +cfxDataMakerFloat1::cfxDataMakerFloat1() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT1, this)); +} + +cfxDataMakerFloat1 cfxDataMakerFloat1::maker; + +cfxDataFloat1* newDataFloat1(const domFloat& df) +{ + cfxFloat1 f1; + f1.f0 = (cfxFloat) df; + cfxDataFloat1* data = new cfxDataFloat1(f1); + return data; +} + +cfxData* cfxDataMakerFloat1::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat1(paramInitializer->getFloat()->getValue()); +} + +cfxData* cfxDataMakerFloat1::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat1(annotateInitializer->getFloat()->getValue()); +} + + +// cfxDataMakerFloat2 +cfxDataMakerFloat2::cfxDataMakerFloat2() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT2, this)); +} + +cfxDataMakerFloat2 cfxDataMakerFloat2::maker; + +cfxDataFloat2* newDataFloat2(const domFloat2& df2) +{ + cfxFloat2 f2; + f2.f0 = (cfxFloat) df2.get(0); + f2.f1 = (cfxFloat) df2.get(1); + cfxDataFloat2* data = new cfxDataFloat2(f2); + return data; +} + +cfxData* cfxDataMakerFloat2::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat2(paramInitializer->getFloat2()->getValue()); +} + +cfxData* cfxDataMakerFloat2::makeData(domCg_param_type* paramInitializer, cfxEffect*) +{ + // this can not go through the helper method because in cg param type, + // dom float 4 is actually defined to be a float where as in commmon, + // it is defined to be double. the conversion is not automatic because + // the dom float 4 is actually a templatized container so the types won't convert. + // return newDataFloat3(paramInitializer->getFloat3()->getValue()); + cfxFloat2 f2; + f2.f0 = paramInitializer->getFloat2()->getValue().get(0); + f2.f1 = paramInitializer->getFloat2()->getValue().get(1); + cfxDataFloat2* data = new cfxDataFloat2(f2); + return data; +} + +cfxData* cfxDataMakerFloat2::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat2(annotateInitializer->getFloat2()->getValue()); +} + + +// cfxDataMakerFloat3 +cfxDataMakerFloat3::cfxDataMakerFloat3() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT3, this)); +} + +cfxDataMakerFloat3 cfxDataMakerFloat3::maker; + +cfxDataFloat3* newDataFloat3(const domFloat3& df3) +{ + cfxFloat3 f3; + f3.f0 = (cfxFloat) df3.get(0); + f3.f1 = (cfxFloat) df3.get(1); + f3.f2 = (cfxFloat) df3.get(2); + cfxDataFloat3* data = new cfxDataFloat3(f3); + return data; +} + +cfxData* cfxDataMakerFloat3::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat3(paramInitializer->getFloat3()->getValue()); +} + +cfxData* cfxDataMakerFloat3::makeData(domCg_param_type* paramInitializer, cfxEffect*) +{ + // this can not go through the helper method because in cg param type, + // dom float 4 is actually defined to be a float where as in commmon, + // it is defined to be double. the conversion is not automatic because + // the dom float 4 is actually a templatized container so the types won't convert. + // return newDataFloat3(paramInitializer->getFloat3()->getValue()); + cfxFloat3 f3; + f3.f0 = paramInitializer->getFloat3()->getValue().get(0); + f3.f1 = paramInitializer->getFloat3()->getValue().get(1); + f3.f2 = paramInitializer->getFloat3()->getValue().get(2); + cfxDataFloat3* data = new cfxDataFloat3(f3); + return data; +} + +cfxData* cfxDataMakerFloat3::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat3(annotateInitializer->getFloat3()->getValue()); +} + + +// cfxDataMakerFloat4 +cfxDataMakerFloat4::cfxDataMakerFloat4() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT4, this)); +} + +cfxDataMakerFloat4 cfxDataMakerFloat4::maker; + +cfxDataFloat4* newDataFloat4(const domFloat4& df4) +{ + cfxFloat4 f4; + f4.f0 = (cfxFloat) df4.get(0); + f4.f1 = (cfxFloat) df4.get(1); + f4.f2 = (cfxFloat) df4.get(2); + f4.f3 = (cfxFloat) df4.get(3); + cfxDataFloat4* data = new cfxDataFloat4(f4); + return data; +} + +cfxData* cfxDataMakerFloat4::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat4(paramInitializer->getFloat4()->getValue()); +} + +cfxData* cfxDataMakerFloat4::makeData(domCg_param_type* paramInitializer, cfxEffect*) +{ + // this can not go through the helper method because in cg param type, + // dom float 4 is actually defined to be a float where as in commmon, + // it is defined to be double. the conversion is not automatic because + // the dom float 4 is actually a templatized container so the types won't convert. + // return newDataFloat4(paramInitializer->getFloat4()->getValue()); + cfxFloat4 f4; + f4.f0 = paramInitializer->getFloat4()->getValue().get(0); + f4.f1 = paramInitializer->getFloat4()->getValue().get(1); + f4.f2 = paramInitializer->getFloat4()->getValue().get(2); + f4.f3 = paramInitializer->getFloat4()->getValue().get(3); + cfxDataFloat4* data = new cfxDataFloat4(f4); + return data; +} + +cfxData* cfxDataMakerFloat4::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat4(annotateInitializer->getFloat4()->getValue()); +} + + + + + +// cfxDataMakerFloat2x2 +cfxDataMakerFloat2x2::cfxDataMakerFloat2x2() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT2X2, this)); +} + +cfxDataMakerFloat2x2 cfxDataMakerFloat2x2::maker; + +cfxDataFloat2x2* newDataFloat2x2(const domFloat2x2& df2x2) +{ + cfxFloat2x2 f2x2; + f2x2.f00 = (cfxFloat) df2x2.get(0); + f2x2.f01 = (cfxFloat) df2x2.get(1); + f2x2.f10 = (cfxFloat) df2x2.get(2); + f2x2.f11 = (cfxFloat) df2x2.get(3); + cfxDataFloat2x2* data = new cfxDataFloat2x2(f2x2); + return data; +} + +cfxData* cfxDataMakerFloat2x2::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat2x2(paramInitializer->getFloat2x2()->getValue()); +} + +cfxData* cfxDataMakerFloat2x2::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat2x2(annotateInitializer->getFloat2x2()->getValue()); +} + + +// cfxDataMakerFloat3x3 +cfxDataMakerFloat3x3::cfxDataMakerFloat3x3() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT3X3, this)); +} + +cfxDataMakerFloat3x3 cfxDataMakerFloat3x3::maker; + +cfxDataFloat3x3* newDataFloat3x3(const domFloat3x3& df3x3) +{ + cfxFloat3x3 f3x3; + f3x3.f00 = (cfxFloat) df3x3.get(0); + f3x3.f01 = (cfxFloat) df3x3.get(1); + f3x3.f02 = (cfxFloat) df3x3.get(2); + f3x3.f10 = (cfxFloat) df3x3.get(3); + f3x3.f11 = (cfxFloat) df3x3.get(4); + f3x3.f12 = (cfxFloat) df3x3.get(5); + f3x3.f20 = (cfxFloat) df3x3.get(6); + f3x3.f21 = (cfxFloat) df3x3.get(7); + f3x3.f22 = (cfxFloat) df3x3.get(8); + cfxDataFloat3x3* data = new cfxDataFloat3x3(f3x3); + return data; +} + +cfxData* cfxDataMakerFloat3x3::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat3x3(paramInitializer->getFloat3x3()->getValue()); +} + +cfxData* cfxDataMakerFloat3x3::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat3x3(annotateInitializer->getFloat3x3()->getValue()); +} + + +// cfxDataMakerFloat4x4 +cfxDataMakerFloat4x4::cfxDataMakerFloat4x4() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FLOAT4X4, this)); +} + +cfxDataMakerFloat4x4 cfxDataMakerFloat4x4::maker; + +cfxDataFloat4x4* newDataFloat4x4(const domFloat4x4& df4x4) +{ + cfxFloat4x4 f4x4; + f4x4.f00 = (cfxFloat) df4x4.get(0); + f4x4.f01 = (cfxFloat) df4x4.get(1); + f4x4.f02 = (cfxFloat) df4x4.get(2); + f4x4.f03 = (cfxFloat) df4x4.get(3); + f4x4.f10 = (cfxFloat) df4x4.get(4); + f4x4.f11 = (cfxFloat) df4x4.get(5); + f4x4.f12 = (cfxFloat) df4x4.get(6); + f4x4.f13 = (cfxFloat) df4x4.get(7); + f4x4.f20 = (cfxFloat) df4x4.get(8); + f4x4.f21 = (cfxFloat) df4x4.get(9); + f4x4.f22 = (cfxFloat) df4x4.get(10); + f4x4.f23 = (cfxFloat) df4x4.get(11); + f4x4.f30 = (cfxFloat) df4x4.get(12); + f4x4.f31 = (cfxFloat) df4x4.get(13); + f4x4.f32 = (cfxFloat) df4x4.get(14); + f4x4.f33 = (cfxFloat) df4x4.get(15); + cfxDataFloat4x4* data = new cfxDataFloat4x4(f4x4); + return data; +} + +cfxData* cfxDataMakerFloat4x4::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + return newDataFloat4x4(paramInitializer->getFloat4x4()->getValue()); +} + +cfxData* cfxDataMakerFloat4x4::makeData(domCg_param_type* paramInitializer, cfxEffect*) +{ + // this can not go through the helper method because in cg param type, + // dom float 4x4 is actually defined to be a float where as in commmon, + // it is defined to be double. the conversion is not automatic because + // the dom float 4 is actually a templatized container so the types won't convert. + // return newDataFloat4x4(paramInitializer->getFloat4x4()->getValue()); + cfxFloat4x4 f4x4; + f4x4.f00 = paramInitializer->getFloat4x4()->getValue().get(0); + f4x4.f01 = paramInitializer->getFloat4x4()->getValue().get(1); + f4x4.f02 = paramInitializer->getFloat4x4()->getValue().get(2); + f4x4.f03 = paramInitializer->getFloat4x4()->getValue().get(3); + f4x4.f10 = paramInitializer->getFloat4x4()->getValue().get(4); + f4x4.f11 = paramInitializer->getFloat4x4()->getValue().get(5); + f4x4.f12 = paramInitializer->getFloat4x4()->getValue().get(6); + f4x4.f13 = paramInitializer->getFloat4x4()->getValue().get(7); + f4x4.f20 = paramInitializer->getFloat4x4()->getValue().get(8); + f4x4.f21 = paramInitializer->getFloat4x4()->getValue().get(9); + f4x4.f22 = paramInitializer->getFloat4x4()->getValue().get(10); + f4x4.f23 = paramInitializer->getFloat4x4()->getValue().get(11); + f4x4.f30 = paramInitializer->getFloat4x4()->getValue().get(12); + f4x4.f31 = paramInitializer->getFloat4x4()->getValue().get(13); + f4x4.f32 = paramInitializer->getFloat4x4()->getValue().get(14); + f4x4.f33 = paramInitializer->getFloat4x4()->getValue().get(15); + cfxDataFloat4x4* data = new cfxDataFloat4x4(f4x4); + return data; +} + +cfxData* cfxDataMakerFloat4x4::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + return newDataFloat4x4(annotateInitializer->getFloat4x4()->getValue()); +} + +// PARAM DATA MAKERS + +// cfxDataMakerSampler2D +cfxDataMakerSampler2D::cfxDataMakerSampler2D() +{ + //cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_SAMPLER, this)); + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair("fx_sampler2D_common", this)); + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair("cg_sampler2D", this)); +} + +cfxDataMakerSampler2D cfxDataMakerSampler2D::maker; + +cfxData* cfxDataMakerSampler2D::makeData(domFx_basic_type_common* paramInitializer, cfxEffect* effect) +{ + sampler = new cfxSampler(paramInitializer->getSampler2D()->getSource()->getValue(), effect); + + if (paramInitializer->getSampler2D()->getWrap_s()) + { + int domEnum = paramInitializer->getSampler2D()->getWrap_s()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerWrapTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingWrapS(effect, "WrapS", glEnum)); + } + + if (paramInitializer->getSampler2D()->getWrap_t()) + { + int domEnum = paramInitializer->getSampler2D()->getWrap_t()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerWrapTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingWrapT(effect, "WrapT", glEnum)); + } + + if (paramInitializer->getSampler2D()->getMinfilter()) + { + int domEnum = paramInitializer->getSampler2D()->getMinfilter()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerFilterTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingMinFilter(effect, "MinFilter", glEnum)); + + // the default for mipmap generation is true + // turn it off if the min filter is GL_LINEAR or GL_NEAREST + if (glEnum == GL_LINEAR || glEnum == GL_NEAREST) + sampler->setGenerateMipmaps(false); + } + + if (paramInitializer->getSampler2D()->getMagfilter()) + { + int domEnum = paramInitializer->getSampler2D()->getMagfilter()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerFilterTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingMagFilter(effect, "MagFilter", glEnum)); + } + + if (paramInitializer->getSampler2D()->getMipmap_bias()) + { + float value = paramInitializer->getSampler2D()->getMipmap_bias()->getValue(); + sampler->pushSetting(new cfxGlSamplerSettingLodBias(effect, "LodBias", value)); + } + + return new cfxDataSampler2D(sampler); +} + + + +cfxData* cfxDataMakerSampler2D::makeData(domCg_param_type* paramInitializer, cfxEffect* effect) +{ + sampler = new cfxSampler(paramInitializer->getSampler2D()->getSource()->getValue(), effect); + + if (paramInitializer->getSampler2D()->getWrap_s()) + { + int domEnum = paramInitializer->getSampler2D()->getWrap_s()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerWrapTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingWrapS(effect, "WrapS", glEnum)); + } + + if (paramInitializer->getSampler2D()->getWrap_t()) + { + int domEnum = paramInitializer->getSampler2D()->getWrap_t()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerWrapTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingWrapT(effect, "WrapT", glEnum)); + } + + if (paramInitializer->getSampler2D()->getMinfilter()) + { + int domEnum = paramInitializer->getSampler2D()->getMinfilter()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerFilterTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingMinFilter(effect, "MinFilter", glEnum)); + + // the default for mipmap generation is true + // turn it off if the min filter is GL_LINEAR or GL_NEAREST + if (glEnum == GL_LINEAR || glEnum == GL_NEAREST) + sampler->setGenerateMipmaps(false); + } + + if (paramInitializer->getSampler2D()->getMagfilter()) + { + int domEnum = paramInitializer->getSampler2D()->getMagfilter()->getValue(); + int glEnum = cfxGlEnumMaps::getSamplerFilterTypeEnum(domEnum); + sampler->pushSetting(new cfxGlSamplerSettingMagFilter(effect, "MagFilter", glEnum)); + } + +#if 0 + if (paramInitializer->getSampler2D()->getBorder_color()) + { + cfxFloat4 value; + value.f0 = paramInitializer->getSampler2D()->getBorder_color()->getValue().get(0); + value.f1 = paramInitializer->getSampler2D()->getBorder_color()->getValue().get(1); + value.f2 = paramInitializer->getSampler2D()->getBorder_color()->getValue().get(2); + value.f3 = paramInitializer->getSampler2D()->getBorder_color()->getValue().get(3); + sampler->pushSetting(new cfxGlSamplerSettingBorderColor(effect, "BorderColor", value)); + } + + if (paramInitializer->getSampler2D()->getMipmap_generate()) + { + bool value = paramInitializer->getSampler2D()->getMipmap_generate()->getValue(); + sampler->pushSetting(new cfxGlSamplerSettingGenerateMipMap(effect, "GenerateMipMap", value)); + } + + if (paramInitializer->getSampler2D()->getMipmap_maxlevel()) + { + float value = paramInitializer->getSampler2D()->getMipmap_maxlevel()->getValue(); + sampler->pushSetting(new cfxGlSamplerSettingMaxMipLevel(effect, "MaxMipLevel", value)); + } +#endif + + if (paramInitializer->getSampler2D()->getMipmap_bias()) + { + float value = paramInitializer->getSampler2D()->getMipmap_bias()->getValue(); + sampler->pushSetting(new cfxGlSamplerSettingLodBias(effect, "LodBias", value)); + } + + return new cfxDataSampler2D(sampler); +} + + +// ANNOTATE DATA MAKERS + +// cfxDataMakerString +cfxDataMakerString::cfxDataMakerString() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_STRING, this)); +} + +cfxDataMakerString cfxDataMakerString::maker; + +// not supporting string parameters because they can't really connect to any program params +// so seem a bit useless and are not supported in the cg runtime on PS3 anyway +#if 0 +cfxData* cfxDataMakerString::makeData(domCg_param_type* paramInitializer, cfxEffect*) +{ + cfxDataString* data; + if (paramInitializer->getString()->getValue()) + { + data = new cfxDataString(paramInitializer->getString()->getValue()); + } + else + { + data = new cfxDataString(""); + } + return data; +} +#endif + +cfxData* cfxDataMakerString::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + cfxDataString* data = new cfxDataString(annotateInitializer->getString()->getValue()); + return data; +} + + + + +#if 0 +// cfxDataMakerBasicType +cfxDataMakerBasicType::cfxDataMakerBasicType() +{ + cfxDataMaker::mapTypeNameToDataMaker.insert(std::make_pair(COLLADA_ELEMENT_FX_BASIC_TYPE_COMMON, this)); +} + +cfxDataMakerBasicType cfxDataMakerBasicType::maker; + +cfxData* cfxDataMakerBasicType::makeData(domFx_basic_type_common* paramInitializer, cfxEffect*) +{ + std::map<std::string, cfxDataMaker*>::iterator iter; + // the element which has the actual data is inside basic type common + daeElement* dataElement = paramInitializer->getFx_basic_type_common()->getContents().get(0); + // get typename from contents, use this to lookup the factory for the data + daeString dataTypeName = dataElement->getTypeName(); + iter = mapTypeNameToDataMaker.find(dataTypeName); + if (iter == mapTypeNameToDataMaker.end()) + { + // print error message + return NULL; + } + cfxDataMaker* basicMaker = iter->second; + return basicMaker->makeData(paramInitializer); +} + +cfxData* cfxDataMakerBasicType::makeData(domFx_annotate_type_common* annotateInitializer, cfxEffect*) +{ + std::map<std::string, cfxDataMaker*>::iterator iter; + // the element which has the actual data is inside basic type common + daeElement* dataElement = annotateInitializer->getFx_basic_type_common()->getContents().get(0); + // get typename from contents, use this to lookup the factory for the data + daeString dataTypeName = dataElement->getTypeName(); + iter = mapTypeNameToDataMaker.find(dataTypeName); + if (iter == mapTypeNameToDataMaker.end()) + { + // print error message + return NULL; + } + return iter->second->makeData(annotateInitializer); +} +#endif + + diff --git a/1.4.0/fx/src/cfxEffect.cpp b/1.4.0/fx/src/cfxEffect.cpp new file mode 100644 index 0000000..fcc986b --- /dev/null +++ b/1.4.0/fx/src/cfxEffect.cpp @@ -0,0 +1,305 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdlib.h> +#include <assert.h> +#include <stdio.h> + +// User includes + +#include <cfxEffect.h> +#include <cfxCode.h> +#include <cfxParam.h> +#include <cfxNewParam.h> +#include <cfxTechnique.h> +#include <cfxAnnotate.h> +#include <cfxPass.h> +#include <cfxData.h> + +#include <assert.h> + +// cfxEffect +cfxEffect::cfxEffect(const std::string& _name, CGcontext _context) + : name(_name), + context(_context) +{ + // do lazy context creation, but this may make it difficult to call + // cgDestroyContext later... + if (context == NULL) + context = cgCreateContext(); + // I think cg would always return an error if context was not created so this is probably redundant + assert(context); + + // create the new effect and set its name + effect = cgCreateEffect(context, NULL, NULL); + cgSetEffectName( effect, name.c_str() ); + + assert(effect); +} +cfxEffect::~cfxEffect() +{ +#ifndef SN_TARGET_PS3 + cgDestroyEffect(effect); +#endif + for (size_t i=0; i<codeArray.size(); i++) + { + delete codeArray[i]; + } + codeArray.clear(); + + for (size_t i=0; i<techniqueArray.size(); i++) + { + delete techniqueArray[i]; + } + techniqueArray.clear(); + + std::map<std::string, cfxSurface*>::iterator iter=mapNameToSurfacePtr.begin(); + for (size_t i=0; i<paramArray.size(); i++) + { + cfxNewParam* p = (cfxNewParam*)paramArray[i]; + delete p->data; + + // Check if param was used by cfxSurface object, if so, don't delet it yet, let ~cfxSurface() delete it + bool found = false; + for (iter=mapNameToSurfacePtr.begin(); iter != mapNameToSurfacePtr.end(); iter++) + { + for (size_t i=0; i<iter->second->referencingParams.size(); i++) + if (iter->second->referencingParams[i] == p) + found = true; + } + if (!found) + delete p; + } + paramArray.clear(); + // this is temporary until cg api gets upgraded to set effect parameter names + + mapNameToParameter.clear(); + iter=mapNameToSurfacePtr.begin(); + for (iter=mapNameToSurfacePtr.begin(); iter != mapNameToSurfacePtr.end(); iter++) + { + delete (iter->second); + } + mapNameToSurfacePtr.clear(); + mapSemanticToParameter.clear(); +} + +cfxBool cfxEffect::apply() +{ + std::vector<cfxAnnotate*>::iterator annotateIter = annotateArray.begin(); + while (annotateIter != annotateArray.end()) + { + (*annotateIter)->apply(this); + annotateIter++; + } + + std::vector<cfxParam*>::iterator paramIter = paramArray.begin(); + while (paramIter != paramArray.end()) + { + (*paramIter)->apply(); + paramIter++; + } + + // // // moving technique earlier so the connection can happen before the set because + // // // propagation of parameter value is not quite implemented properly yet. + std::vector<cfxTechnique*>::iterator techniqueIter = techniqueArray.begin(); + while (techniqueIter != techniqueArray.end()) + { + (*techniqueIter)->apply(); + techniqueIter++; + } + + // i think there should be a better place for this, but until i know what that is... + techniqueIter = techniqueArray.begin(); + while (techniqueIter != techniqueArray.end()) + { + cfxBool valid = cgValidateTechnique((*techniqueIter)->getTechnique()); + + if (valid) + { + printf("VALID TECHNIQUE\n"); + } + else + { + printf("ERROR: INVALID TECHNIQUE\n"); + } + + techniqueIter++; + } + + return true; +} + +cfxBool cfxEffect::validate() const +{ + return true; +} + +CGcontext cfxEffect::getContext() const +{ + return context; +} + +CGeffect cfxEffect::getEffect() const +{ + return effect; +} + +const std::string& cfxEffect::getName() const +{ + return name; +} + +void cfxEffect::pushCode(cfxCode* code) +{ + codeArray.push_back(code); +} + +void cfxEffect::pushTechnique(cfxTechnique* technique) +{ + + printf("PushTechnique\n"); + techniqueArray.push_back(technique); +} + + + +void cfxEffect::setPassState(cfxUint techniqueIndex, cfxUint passIndex) +{ + if (techniqueIndex >= techniqueArray.size()) + { + printf("setPassState passIndex=%d\n", passIndex); + printf("ERROR: techniqueIndex invalid: %d\n", techniqueIndex); + return; + } + + techniqueArray[techniqueIndex]->setPassState(passIndex); +} + + +void cfxEffect::resetPassState(cfxUint techniqueIndex, cfxUint passIndex) +{ + if (techniqueIndex >= techniqueArray.size()) + { + printf("resetPassState passIndex=%d\n", passIndex); + printf("ERROR: techniqueIndex invalid: %d\n", techniqueIndex); + return; + } + + techniqueArray[techniqueIndex]->resetPassState(passIndex); +} + + +cfxUint cfxEffect::getTechniqueCount() +{ + return (cfxUint) techniqueArray.size(); +} + + +cfxUint cfxEffect::getPassCount(cfxUint techniqueIndex) +{ + if (techniqueIndex >= techniqueArray.size()) + { + printf("getPassCount\n"); + printf("ERROR: techniqueIndex invalid: %d\n", techniqueIndex); + return 0; + } + + return (techniqueArray[techniqueIndex]->getPassCount()); +} + + +// this is temporary until cg api gets upgraded to set effect parameter names +void cfxEffect::addNamedParameter(const std::string& name, CGparameter param) +{ + mapNameToParameter.insert(make_pair(name, param)); +} + + +CGparameter cfxEffect::getParameterByName(const std::string& name) +{ + CGparameter param = 0; +#if 1 + std::map<std::string, CGparameter>::iterator iter = mapNameToParameter.find(name); + if (iter != mapNameToParameter.end()) + { + param = iter->second; + } + //printf("got effect param: %s %d\n", name.c_str(), param); +#else + param = cgGetNamedEffectParameter(effect, name.c_str()); +#endif + return param; +} + + +void cfxEffect::addNamedSurface(const std::string& name, cfxSurface* surface) +{ + mapNameToSurfacePtr.insert(make_pair(name, surface)); + printf("added surface to map of name %s\n", name.c_str()); +} + +cfxSurface* cfxEffect::getSurfaceByName(const std::string& name) +{ + cfxSurface* surface = 0; + std::map<std::string, cfxSurface*>::iterator iter = mapNameToSurfacePtr.find(name); + if (iter != mapNameToSurfacePtr.end()) + { + surface = iter->second; + } + //printf("got effect surface: %s %p\n", name.c_str(), surface); + return surface; +} + + +void cfxEffect::addSemanticParameter(const std::string& semantic, CGparameter param) +{ + printf("adding semantic pair %s %p\n", semantic.c_str(), param); + mapSemanticToParameter.insert(make_pair(semantic, param)); +} + + +CGparameter cfxEffect::getParameterBySemantic(const std::string& semantic) +{ + CGparameter param = 0; +#if 1 + std::map<std::string, CGparameter>::iterator iter = mapSemanticToParameter.find(semantic); + if (iter != mapSemanticToParameter.end()) + { + param = iter->second; + } + //printf("got semantic param: %s %p\n", semantic.c_str(), param); +#else + param = cgGetEffectParameterBySemantic(effect, semantic.c_str()); +#endif + return param; +} + +const std::vector<cfxTechnique*> &cfxEffect::getTechniqueArray() const +{ + return techniqueArray; +} + +const std::map<std::string, cfxSurface*> &cfxEffect::getSurfaceMap() const +{ + return mapNameToSurfacePtr; +} + +std::string cfxEffect::getSurfaceName( const cfxSurface *surface ) +{ + std::map<std::string, cfxSurface *>::iterator iter = mapNameToSurfacePtr.begin(); + while (iter != mapNameToSurfacePtr.end() ) + { + if ( iter->second == surface ) + { + return iter->first; + } + ++iter; + } + return ""; +} diff --git a/1.4.0/fx/src/cfxError.cpp b/1.4.0/fx/src/cfxError.cpp new file mode 100644 index 0000000..20ae914 --- /dev/null +++ b/1.4.0/fx/src/cfxError.cpp @@ -0,0 +1,47 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdlib.h> +#include <assert.h> +#include <stdio.h> + +#include <cfxError.h> + + +// this is a handy callback for the cg errors +void cfxCgErrorCallback() +{ + CGerror error = cgGetError(); + +#ifndef _LIB + const char* report = cgGetErrorString(error); + printf("CG Error Detected: %s\n", report); + + assert(0 && report); +#endif +} + + +CGerror cfxCheckCgError() +{ + CGerror error = cgGetError(); + + if (error != CG_NO_ERROR) + { + const char* report = cgGetErrorString(error); + printf("CG Error Detected: %s\n", report); + assert(0 && report); + } + + return error; +} + + + + diff --git a/1.4.0/fx/src/cfxGlEnumMaps.cpp b/1.4.0/fx/src/cfxGlEnumMaps.cpp new file mode 100644 index 0000000..792f146 --- /dev/null +++ b/1.4.0/fx/src/cfxGlEnumMaps.cpp @@ -0,0 +1,209 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +#include <cfxGlEnumMaps.h> + +#include <cfxPlatform.h> + + +#if 0 +int cfxGlEnumMaps::blendTypeEnums[GL_BLEND_TYPE_COUNT]; +int cfxGlEnumMaps::faceTypeEnums[GL_FACE_TYPE_COUNT]; +int cfxGlEnumMaps::blendEquationTypeEnums[GL_BLEND_EQUATION_TYPE_COUNT]; +int cfxGlEnumMaps::funcTypeEnums[GL_FUNC_TYPE_COUNT]; +int cfxGlEnumMaps::stencilOpTypeEnums[GL_STENCIL_OP_TYPE_COUNT]; + +int cfxGlEnumMaps::modeTypeEnums[GL_MATERIAL_TYPE_COUNT]; +int cfxGlEnumMaps::fogModeTypeEnums[GL_FOG_TYPE_COUNT]; +#endif + +int cfxGlEnumMaps::samplerWrapTypeEnums[FX_SAMPLER_WRAP_COMMON_COUNT]; +int cfxGlEnumMaps::samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_COUNT]; + +bool cfxGlEnumMaps::initialized = false; + +cfxGlEnumMaps cfxGlEnumMaps::initializer; + + +int cfxGlEnumMaps::getBlendTypeEnum(int domEnum) +{ + return domEnum; + + // if (domEnum < 0 || domEnum >= GL_BLEND_TYPE_COUNT) + // return -1; + // return blendTypeEnums[domEnum]; +} + +int cfxGlEnumMaps::getFaceTypeEnum(int domEnum) +{ + return domEnum; + + // if (domEnum < 0 || domEnum >= GL_FACE_TYPE_COUNT) + // return -1; + // return faceTypeEnums[domEnum]; +} + + +int cfxGlEnumMaps::getBlendEquationTypeEnum(int domEnum) +{ + return domEnum; + + // if (domEnum < 0 || domEnum >= GL_BLEND_EQUATION_TYPE_COUNT) + // return -1; + // return blendEquationTypeEnums[domEnum]; +} + + +int cfxGlEnumMaps::getFuncTypeEnum(int domEnum) +{ + return domEnum; + + // if (domEnum < 0 || domEnum >= GL_FUNC_TYPE_COUNT) + // return -1; + // return funcTypeEnums[domEnum]; +} + + +int cfxGlEnumMaps::getStencilOpTypeEnum(int domEnum) +{ + return domEnum; + + // if (domEnum < 0 || domEnum >= GL_STENCIL_OP_TYPE_COUNT) + // return -1; + // return stencilOpTypeEnums[domEnum]; +} + + +int cfxGlEnumMaps::getModeTypeEnum(int domEnum) +{ + return domEnum; + + // if (domEnum < 0 || domEnum >= GL_MATERIAL_TYPE_COUNT) + // return -1; + // return modeTypeEnums[domEnum]; +} + + +int cfxGlEnumMaps::getFogModeTypeEnum(int domEnum) +{ + return domEnum; + + // if (domEnum < 0 || domEnum >= GL_FOG_TYPE_COUNT) + // return -1; + // return fogModeTypeEnums[domEnum]; +} + + +int cfxGlEnumMaps::getSamplerWrapTypeEnum(int domEnum) +{ + if (domEnum < 0 || domEnum >= FX_SAMPLER_WRAP_COMMON_COUNT) + return -1; + return samplerWrapTypeEnums[domEnum]; +} + + +int cfxGlEnumMaps::getSamplerFilterTypeEnum(int domEnum) +{ + if (domEnum < 0 || domEnum >= FX_SAMPLER_FILTER_COMMON_COUNT) + return -1; + return samplerFilterTypeEnums[domEnum]; +} + + + +// deliberately doing explicit verbose initialization using both the dom and equivalent GL enums so mapping is less fragile +cfxGlEnumMaps::cfxGlEnumMaps() +{ + + if (!initialized) + { +#if 0 + blendTypeEnums[GL_BLEND_TYPE_ZERO] = GL_ZERO; + blendTypeEnums[GL_BLEND_TYPE_ONL_NEAREST_MIPMAP_LINEAE] = GL_ONE; + blendTypeEnums[GL_BLEND_TYPE_SRC_COLOR] = GL_SRC_COLOR; + blendTypeEnums[GL_BLEND_TYPE_ONE_MINUS_SRC_COLOR] = GL_ONE_MINUS_SRC_COLOR; + blendTypeEnums[GL_BLEND_TYPE_DEST_COLOR] = GL_DST_COLOR; + blendTypeEnums[GL_BLEND_TYPE_ONE_MINUS_DEST_COLOR] = GL_ONE_MINUS_DST_COLOR; + blendTypeEnums[GL_BLEND_TYPE_SRC_ALPHA] = GL_SRC_ALPHA; + blendTypeEnums[GL_BLEND_TYPE_ONE_MINUS_SRC_ALPHA] = GL_ONE_MINUS_SRC_ALPHA; + //blendTypeEnums[GL_BLEND_TYPE_DST_ALPHA] = GL_DST_ALPHA; + //blendTypeEnums[GL_BLEND_TYPE_ONE_MINUS_DST_ALPHA] = GL_ONE_MINUS_DST_ALPHA; + //blendTypeEnums[GL_BLEND_TYPE_CONSTANT_COLOR] = GL_CONSTANT_COLOR; + //blendTypeEnums[GL_BLEND_TYPE_ONE_MINUS_CONSTANT_COLOR] = GL_ONE_MINUS_CONSTANT_COLOR; + //blendTypeEnums[GL_BLEND_TYPE_CONSTANT_ALPHA] = GL_CONSTANT_ALPHA; + //blendTypeEnums[GL_BLEND_TYPE_ONE_MINUS_CONSTANT_ALPHA] = GL_ONE_MINUS_CONSTANT_ALPHA; + blendTypeEnums[GL_BLEND_TYPE_SRC_ALPHA_SATURATE] = GL_SRC_ALPHA_SATURATE; + + faceTypeEnums[GL_FACE_TYPE_FRONT] = GL_FRONT; + faceTypeEnums[GL_FACE_TYPE_BACK] = GL_BACK; + faceTypeEnums[GL_FACE_TYPE_FRONT_AND_BACK] = GL_FRONT_AND_BACK; + + // i don't think this is right at all + blendEquationTypeEnums[GL_BLEND_EQUATION_TYPE_FUNC_ADD] = GL_ADD; + blendEquationTypeEnums[GL_BLEND_EQUATION_TYPE_FUNC_SUBTRACT] = GL_SUBTRACT; + blendEquationTypeEnums[GL_BLEND_EQUATION_TYPE_FUNC_REVERSE_SUBTRACT] = GL_REVERSE_SUBTRACT; + blendEquationTypeEnums[GL_BLEND_EQUATION_TYPE_MIN] = GL_MIN; + blendEquationTypeEnums[GL_BLEND_EQUATION_TYPE_MAX] = GL_MAX; + + funcTypeEnums[GL_FUNC_TYPE_NEVER] = GL_NEVER; + funcTypeEnums[GL_FUNC_TYPE_LESS] = GL_LESS; + funcTypeEnums[GL_FUNC_TYPE_LEQUAL] = GL_LEQUAL; + funcTypeEnums[GL_FUNC_TYPE_EQUAL] = GL_EQUAL; + funcTypeEnums[GL_FUNC_TYPE_GREATER] = GL_GREATER; + funcTypeEnums[GL_FUNC_TYPE_NOTEQUAL] = GL_NOTEQUAL; + funcTypeEnums[GL_FUNC_TYPE_GEQUAL] = GL_GEQUAL; + funcTypeEnums[GL_FUNC_TYPE_ALWAYS] = GL_ALWAYS; + + stencilOpTypeEnums[GL_STENCIL_OP_TYPE_KEEP] = GL_KEEP; + stencilOpTypeEnums[GL_STENCIL_OP_TYPE_ZERO] = GL_ZERO; + stencilOpTypeEnums[GL_STENCIL_OP_TYPE_REPLACE] = GL_REPLACE; + stencilOpTypeEnums[GL_STENCIL_OP_TYPE_INCR] = GL_INCR; + stencilOpTypeEnums[GL_STENCIL_OP_TYPE_DECR] = GL_DECR; + stencilOpTypeEnums[GL_STENCIL_OP_TYPE_INVERT] = GL_INVERT; + //stencilOpTypeEnums[GL_STENCIL_OP_TYPE_INCR_WRAP] = GL_INCR_WRAP; + //stencilOpTypeEnums[GL_STENCIL_OP_TYPE_DECR_WRAP] = GL_DECR_WRAP; + + modeTypeEnums[domGl_pipeline_settings::domColor_material::domMode::MODE_EMISSION] = GL_EMISSION; + //modeTypeEnums[domGl_pipeline_settings::domColor_material::domMode::MODE_AMBIENT] = GL_AMBIENT; + //modeTypeEnums[domGl_pipeline_settings::domColor_material::domMode::MODE_DIFFUSE] = GL_DIFFUSE; + //modeTypeEnums[domGl_pipeline_settings::domColor_material::domMode::MODE_SPECULAR] = GL_SPECULAR; + modeTypeEnums[domGl_pipeline_settings::domColor_material::domMode::MODE_AMBIENT_AND_DIFFUSE] = GL_AMBIENT_AND_DIFFUSE; + //modeTypeEnums[domGl_pipeline_settings::domColor_material::domMode::???] = GL_SHININESS; + + //fogModeTypeEnums[domGl_pipeline_settings::domFog_mode::FOG_MODE_LINEAR] = GL_LINEAR; + fogModeTypeEnums[domGl_pipeline_settings::domFog_mode::FOG_MODE_EXP] = GL_FOG_TYPE_EXP; + fogModeTypeEnums[domGl_pipeline_settings::domFog_mode::FOG_MODE_EXP2] = GL_FOG_TYPE_EXP2; +#endif + + int i; + + for (i = 0; i < FX_SAMPLER_WRAP_COMMON_CLAMP; i++) + { + samplerWrapTypeEnums[i] = -1; + } + + //samplerWrapTypeEnums[FX_SAMPLER_WRAP_COMMON_NONE] = ; + samplerWrapTypeEnums[FX_SAMPLER_WRAP_COMMON_WRAP] = GL_REPEAT; + //samplerWrapTypeEnums[FX_SAMPLER_WRAP_COMMON_MIRROR] = ; + samplerWrapTypeEnums[FX_SAMPLER_WRAP_COMMON_CLAMP] = GL_CLAMP_TO_EDGE; + + for (i = 0; i < FX_SAMPLER_FILTER_COMMON_NONE; i++) + { + samplerFilterTypeEnums[i] = -1; + } + + //samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_NONE] = ; + samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_NEAREST] = GL_NEAREST; + samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_LINEAR] = GL_LINEAR; + samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST] = GL_NEAREST_MIPMAP_NEAREST; + samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST] = GL_LINEAR_MIPMAP_NEAREST; + samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR] = GL_NEAREST_MIPMAP_LINEAR; + samplerFilterTypeEnums[FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_LINEAR] = GL_LINEAR_MIPMAP_LINEAR; + } +} + + diff --git a/1.4.0/fx/src/cfxGlPipelineSetting.cpp b/1.4.0/fx/src/cfxGlPipelineSetting.cpp new file mode 100644 index 0000000..10f4a6a --- /dev/null +++ b/1.4.0/fx/src/cfxGlPipelineSetting.cpp @@ -0,0 +1,2035 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <iostream> +#include <cfxPlatform.h> + + +// User includes + +#include <cfxGlPipelineSetting.h> +#include <cfxPass.h> +#include <cfxTechnique.h> +#include <cfxEffect.h> + +// cfxGlPipelineSetting +cfxGlPipelineSetting::cfxGlPipelineSetting(cfxPass* _pass, const char* stateName, int index) + : pass(_pass) +{ + state = cgGetNamedState(_pass->getTechnique()->getEffect()->getContext(), stateName); + if (state != 0) + { + printf("Got state for %s\n", stateName); + } + else + { + printf("ERROR: state not found for %s\n", stateName); + } + + if (index >= 0) + { + assignment = cgCreateStateAssignmentIndex(_pass->getPass(), state, index); + } + else + { + assignment = cgCreateStateAssignment(_pass->getPass(), state); + } +} + +cfxGlPipelineSetting::~cfxGlPipelineSetting() +{ +} + +// cfxGlPipelineSettingAlphaFunc +cfxGlPipelineSettingAlphaFunc::cfxGlPipelineSettingAlphaFunc(cfxPass* _pass, int _func, float _value) + : cfxGlPipelineSetting(_pass, "AlphaFunc"), + func(_func), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingAlphaFunc::apply() +{ + float values[2]; + values[0] = (float)func; + values[1] = value; + cgSetFloatArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingAlphaFunc::getType() const +{ + return cfxGlPipelineSetting::ALPHA_FUNC; +} + +int cfxGlPipelineSettingAlphaFunc::getFunc() const +{ + return func; +} + +float cfxGlPipelineSettingAlphaFunc::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingBlendFunc +cfxGlPipelineSettingBlendFunc::cfxGlPipelineSettingBlendFunc(cfxPass* _pass, int _src, int _dst) + : cfxGlPipelineSetting(_pass, "BlendFunc"), + src(_src), + dst(_dst) +{ +} + +cfxBool cfxGlPipelineSettingBlendFunc::apply() +{ + int values[2]; + values[0] = src; + values[1] = dst; + + if ( src && dst ) + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingBlendFunc::getType() const +{ + return cfxGlPipelineSetting::BLEND_FUNC; +} + +int cfxGlPipelineSettingBlendFunc::getSrc() const +{ + return src; +} + +int cfxGlPipelineSettingBlendFunc::getDst() const +{ + return dst; +} + + +// cfxGlPipelineSettingBlendFuncSeparate +cfxGlPipelineSettingBlendFuncSeparate::cfxGlPipelineSettingBlendFuncSeparate(cfxPass* _pass, int _srcRGB, int _dstRGB, int _srcAlpha, int _dstAlpha) + : cfxGlPipelineSetting(_pass, "BlendFuncSeparate"), + srcRGB(_srcRGB), + dstRGB(_dstRGB), + srcAlpha(_srcAlpha), + dstAlpha(_dstAlpha) +{ +} + +cfxBool cfxGlPipelineSettingBlendFuncSeparate::apply() +{ + int values[4]; + values[0] = srcRGB; + values[1] = dstRGB; + values[2] = srcAlpha; + values[3] = dstAlpha; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingBlendFuncSeparate::getType() const +{ + return cfxGlPipelineSetting::BLEND_FUNC_SEPARATE; +} + +int cfxGlPipelineSettingBlendFuncSeparate::getSrcRGB() const +{ + return srcRGB; +} + +int cfxGlPipelineSettingBlendFuncSeparate::getDstRGD() const +{ + return dstRGB; +} + +int cfxGlPipelineSettingBlendFuncSeparate::getSrcAlpha() const +{ + return srcAlpha; +} + +int cfxGlPipelineSettingBlendFuncSeparate::getDstAlpha() const +{ + return dstAlpha; +} + + +// cfxGlPipelineSettingBlendEquation +cfxGlPipelineSettingBlendEquation::cfxGlPipelineSettingBlendEquation(cfxPass* _pass, int _equation) + : cfxGlPipelineSetting(_pass, "BlendEquation"), + equation(_equation) +{ +} + +cfxBool cfxGlPipelineSettingBlendEquation::apply() +{ + cgSetIntStateAssignment(assignment, equation); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingBlendEquation::getType() const +{ + return cfxGlPipelineSetting::BLEND_EQUATION; +} + +int cfxGlPipelineSettingBlendEquation::getEquation() const +{ + return equation; +} + + +// cfxGlPipelineSettingBlendEquationSeparate +cfxGlPipelineSettingBlendEquationSeparate::cfxGlPipelineSettingBlendEquationSeparate(cfxPass* _pass, int _rgb, int _alpha) + : cfxGlPipelineSetting(_pass, "BlendEquationSeparate"), + rgb(_rgb), + alpha(_alpha) +{ +} + +cfxBool cfxGlPipelineSettingBlendEquationSeparate::apply() +{ + int values[2]; + values[0] = rgb; + values[1] = alpha; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingBlendEquationSeparate::getType() const +{ + return cfxGlPipelineSetting::BLEND_EQUATION_SEPARATE; +} + +int cfxGlPipelineSettingBlendEquationSeparate::getRgb() const +{ + return rgb; +} + +int cfxGlPipelineSettingBlendEquationSeparate::getAlpha() const +{ + return alpha; +} + + +// cfxGlPipelineSettingBlendColor +cfxGlPipelineSettingBlendColor::cfxGlPipelineSettingBlendColor(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "BlendColor"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingBlendColor::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingBlendColor::getType() const +{ + return cfxGlPipelineSetting::BLEND_COLOR; +} + +cfxFloat4 cfxGlPipelineSettingBlendColor::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingClearColor +cfxGlPipelineSettingClearColor::cfxGlPipelineSettingClearColor(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "ClearColor"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingClearColor::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingClearColor::getType() const +{ + return cfxGlPipelineSetting::CLEAR_COLOR; +} + +cfxFloat4 cfxGlPipelineSettingClearColor::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingClearStencil +cfxGlPipelineSettingClearStencil::cfxGlPipelineSettingClearStencil(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "ClearStencil"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingClearStencil::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingClearStencil::getType() const +{ + return cfxGlPipelineSetting::CLEAR_STENCIL; +} + +int cfxGlPipelineSettingClearStencil::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingClearDepth +cfxGlPipelineSettingClearDepth::cfxGlPipelineSettingClearDepth(cfxPass* _pass, float _value) + : cfxGlPipelineSetting(_pass, "ClearDepth"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingClearDepth::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingClearDepth::getType() const +{ + return cfxGlPipelineSetting::CLEAR_DEPTH; +} + +float cfxGlPipelineSettingClearDepth::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingClipPlane +cfxGlPipelineSettingClipPlane::cfxGlPipelineSettingClipPlane(cfxPass* _pass, int _index, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "ClipPlane", _index), + index(_index), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingClipPlane::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingClipPlane::getType() const +{ + return cfxGlPipelineSetting::CLIP_PLANE; +} + +int cfxGlPipelineSettingClipPlane::getIndex() const +{ + return index; +} + +cfxFloat4 cfxGlPipelineSettingClipPlane::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingColorMask +cfxGlPipelineSettingColorMask::cfxGlPipelineSettingColorMask(cfxPass* _pass, cfxBool4& _value) + : cfxGlPipelineSetting(_pass, "ColorMask"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingColorMask::apply() +{ + CGbool cgValues[4]; + cgValues[0] = value.b0; + cgValues[1] = value.b1; + cgValues[2] = value.b2; + cgValues[3] = value.b3; + cgSetBoolArrayStateAssignment(assignment, cgValues); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingColorMask::getType() const +{ + return cfxGlPipelineSetting::COLOR_MASK; +} + +cfxBool4 cfxGlPipelineSettingColorMask::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingColorMaterial +cfxGlPipelineSettingColorMaterial::cfxGlPipelineSettingColorMaterial(cfxPass* _pass, int _face, int _mode) + : cfxGlPipelineSetting(_pass, "ColorMaterial"), + face(_face), + mode(_mode) +{ +} + +cfxBool cfxGlPipelineSettingColorMaterial::apply() +{ + int values[2]; + values[0] = face; + values[1] = mode; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingColorMaterial::getType() const +{ + return cfxGlPipelineSetting::COLOR_MATERIAL; +} + +int cfxGlPipelineSettingColorMaterial::getFace() const +{ + return face; +} + +int cfxGlPipelineSettingColorMaterial::getMode() const +{ + return mode; +} + + +// cfxGlPipelineSettingCullFace +cfxGlPipelineSettingCullFace::cfxGlPipelineSettingCullFace(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "CullFace"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingCullFace::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingCullFace::getType() const +{ + return cfxGlPipelineSetting::CULL_FACE; +} + +int cfxGlPipelineSettingCullFace::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingDepthFunc +cfxGlPipelineSettingDepthFunc::cfxGlPipelineSettingDepthFunc(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "DepthFunc"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingDepthFunc::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingDepthFunc::getType() const +{ + return cfxGlPipelineSetting::DEPTH_FUNC; +} + +int cfxGlPipelineSettingDepthFunc::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingDepthMask +cfxGlPipelineSettingDepthMask::cfxGlPipelineSettingDepthMask(cfxPass* _pass, cfxBool _value) + : cfxGlPipelineSetting(_pass, "DepthMask"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingDepthMask::apply() +{ + cgSetBoolStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingDepthMask::getType() const +{ + return cfxGlPipelineSetting::DEPTH_MASK; +} + +cfxBool cfxGlPipelineSettingDepthMask::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingDepthRange +cfxGlPipelineSettingDepthRange::cfxGlPipelineSettingDepthRange(cfxPass* _pass, cfxFloat2& _value) + : cfxGlPipelineSetting(_pass, "DepthRange"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingDepthRange::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingDepthRange::getType() const +{ + return cfxGlPipelineSetting::DEPTH_RANGE; +} + +cfxFloat2 cfxGlPipelineSettingDepthRange::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingFogMode +cfxGlPipelineSettingFogMode::cfxGlPipelineSettingFogMode(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "FogMode"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingFogMode::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingFogMode::getType() const +{ + return cfxGlPipelineSetting::FOG_MODE; +} + +int cfxGlPipelineSettingFogMode::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingFogDensity +cfxGlPipelineSettingFogDensity::cfxGlPipelineSettingFogDensity(cfxPass* _pass, float _value) + : cfxGlPipelineSetting(_pass, "FogDensity"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingFogDensity::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingFogDensity::getType() const +{ + return cfxGlPipelineSetting::FOG_DENSITY; +} + +float cfxGlPipelineSettingFogDensity::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingFogStart +cfxGlPipelineSettingFogStart::cfxGlPipelineSettingFogStart(cfxPass* _pass, float _value) + : cfxGlPipelineSetting(_pass, "FogStart"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingFogStart::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingFogStart::getType() const +{ + return cfxGlPipelineSetting::FOG_START; +} + +float cfxGlPipelineSettingFogStart::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingFogEnd +cfxGlPipelineSettingFogEnd::cfxGlPipelineSettingFogEnd(cfxPass* _pass, float _value) + : cfxGlPipelineSetting(_pass, "FogEnd"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingFogEnd::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingFogEnd::getType() const +{ + return cfxGlPipelineSetting::FOG_END; +} + +float cfxGlPipelineSettingFogEnd::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingFogColor +cfxGlPipelineSettingFogColor::cfxGlPipelineSettingFogColor(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "FogColor"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingFogColor::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingFogColor::getType() const +{ + return cfxGlPipelineSetting::FOG_COLOR; +} + +cfxFloat4 cfxGlPipelineSettingFogColor::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingFrontFace +cfxGlPipelineSettingFrontFace::cfxGlPipelineSettingFrontFace(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "FrontFace"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingFrontFace::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingFrontFace::getType() const +{ + return cfxGlPipelineSetting::FRONT_FACE; +} + +int cfxGlPipelineSettingFrontFace::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightModelAmbient +cfxGlPipelineSettingLightModelAmbient::cfxGlPipelineSettingLightModelAmbient(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "LightModelAmbient"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingLightModelAmbient::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightModelAmbient::getType() const +{ + return cfxGlPipelineSetting::LIGHT_MODEL_AMBEINT; +} + +cfxFloat4 cfxGlPipelineSettingLightModelAmbient::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightAmbient +cfxGlPipelineSettingLightAmbient::cfxGlPipelineSettingLightAmbient(cfxPass* _pass, int _index, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "LightAmbient", _index), + index(_index), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingLightAmbient::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightAmbient::getType() const +{ + return cfxGlPipelineSetting::LIGHT_AMBIENT; +} + +int cfxGlPipelineSettingLightAmbient::getIndex() const +{ + return index; +} + +cfxFloat4 cfxGlPipelineSettingLightAmbient::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingLightConstantAttenuation +cfxGlPipelineSettingLightConstantAttenuation::cfxGlPipelineSettingLightConstantAttenuation(cfxPass* _pass, int _index, float _value) + : cfxGlPipelineSetting(_pass, "LightConstantAttenuation", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightConstantAttenuation::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightConstantAttenuation::getType() const +{ + return cfxGlPipelineSetting::LIGHT_CONSTANT_ATTENUATION; +} + +int cfxGlPipelineSettingLightConstantAttenuation::getIndex() const +{ + return index; +} + +float cfxGlPipelineSettingLightConstantAttenuation::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingLightDiffuse +cfxGlPipelineSettingLightDiffuse::cfxGlPipelineSettingLightDiffuse(cfxPass* _pass, int _index, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "LightDiffuse", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightDiffuse::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightDiffuse::getType() const +{ + return cfxGlPipelineSetting::LIGHT_DIFFUSE; +} + +int cfxGlPipelineSettingLightDiffuse::getIndex() const +{ + return index; +} + +cfxFloat4 cfxGlPipelineSettingLightDiffuse::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightLinearAttenuation +cfxGlPipelineSettingLightLinearAttenuation::cfxGlPipelineSettingLightLinearAttenuation(cfxPass* _pass, int _index, float _value) + : cfxGlPipelineSetting(_pass, "LightLinearAttenuation", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightLinearAttenuation::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightLinearAttenuation::getType() const +{ + return cfxGlPipelineSetting::LIGHT_LINEAR_ATTENUATION; +} + +int cfxGlPipelineSettingLightLinearAttenuation::getIndex() const +{ + return index; +} + +float cfxGlPipelineSettingLightLinearAttenuation::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightPosition +cfxGlPipelineSettingLightPosition::cfxGlPipelineSettingLightPosition(cfxPass* _pass, int _index, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "LightPosition", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightPosition::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightPosition::getType() const +{ + return cfxGlPipelineSetting::LIGHT_POSITION; +} + +int cfxGlPipelineSettingLightPosition::getIndex() const +{ + return index; +} + +cfxFloat4 cfxGlPipelineSettingLightPosition::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightQuadraticAttenuation +cfxGlPipelineSettingLightQuadraticAttenuation::cfxGlPipelineSettingLightQuadraticAttenuation(cfxPass* _pass, int _index, float _value) + : cfxGlPipelineSetting(_pass, "LightQuadraticAttenuation", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightQuadraticAttenuation::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightQuadraticAttenuation::getType() const +{ + return cfxGlPipelineSetting::LIGHT_QUADRATIC_ATTENUATION; +} + +int cfxGlPipelineSettingLightQuadraticAttenuation::getIndex() const +{ + return index; +} + +float cfxGlPipelineSettingLightQuadraticAttenuation::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightSpecular +cfxGlPipelineSettingLightSpecular::cfxGlPipelineSettingLightSpecular(cfxPass* _pass, int _index, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "LightSpecular", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightSpecular::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightSpecular::getType() const +{ + return cfxGlPipelineSetting::LIGHT_SPECULAR; +} + +int cfxGlPipelineSettingLightSpecular::getIndex() const +{ + return index; +} + +cfxFloat4 cfxGlPipelineSettingLightSpecular::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightSpotCutoff +cfxGlPipelineSettingLightSpotCutoff::cfxGlPipelineSettingLightSpotCutoff(cfxPass* _pass, int _index, float _value) + : cfxGlPipelineSetting(_pass, "LightSpotCutoff", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightSpotCutoff::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightSpotCutoff::getType() const +{ + return cfxGlPipelineSetting::LIGHT_SPOT_CUTOFF; +} + +int cfxGlPipelineSettingLightSpotCutoff::getIndex() const +{ + return index; +} + +float cfxGlPipelineSettingLightSpotCutoff::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightSpotDirection +cfxGlPipelineSettingLightSpotDirection::cfxGlPipelineSettingLightSpotDirection(cfxPass* _pass, int _index, cfxFloat3& _value) + : cfxGlPipelineSetting(_pass, "LightSpotDirection", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightSpotDirection::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightSpotDirection::getType() const +{ + return cfxGlPipelineSetting::LIGHT_SPOT_DIRECTION; +} + +int cfxGlPipelineSettingLightSpotDirection::getIndex() const +{ + return index; +} + +cfxFloat3 cfxGlPipelineSettingLightSpotDirection::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLightSpotExponent +cfxGlPipelineSettingLightSpotExponent::cfxGlPipelineSettingLightSpotExponent(cfxPass* _pass, int _index, float _value) + : cfxGlPipelineSetting(_pass, "LightSpotExponent", _index), + index(_index), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLightSpotExponent::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLightSpotExponent::getType() const +{ + return cfxGlPipelineSetting::LIGHT_SPOT_EXPONENT; +} + +int cfxGlPipelineSettingLightSpotExponent::getIndex() const +{ + return index; +} + +float cfxGlPipelineSettingLightSpotExponent::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLineWidth +cfxGlPipelineSettingLineWidth::cfxGlPipelineSettingLineWidth(cfxPass* _pass, float _value) + : cfxGlPipelineSetting(_pass, "LineWidth"), + value(_value) + +{ +} + +cfxBool cfxGlPipelineSettingLineWidth::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLineWidth::getType() const +{ + return cfxGlPipelineSetting::LINE_WIDTH; +} + +float cfxGlPipelineSettingLineWidth::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingLogicOp +cfxGlPipelineSettingLogicOp::cfxGlPipelineSettingLogicOp(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "LogicOp"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingLogicOp::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingLogicOp::getType() const +{ + return cfxGlPipelineSetting::LOGIC_OP; +} + +int cfxGlPipelineSettingLogicOp::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingMaterialAmbient +cfxGlPipelineSettingMaterialAmbient::cfxGlPipelineSettingMaterialAmbient(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "MaterialAmbient"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingMaterialAmbient::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingMaterialAmbient::getType() const +{ + return cfxGlPipelineSetting::MATERIAL_AMBIENT; +} + +cfxFloat4 cfxGlPipelineSettingMaterialAmbient::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingMaterialDiffuse +cfxGlPipelineSettingMaterialDiffuse::cfxGlPipelineSettingMaterialDiffuse(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "MaterialDiffuse"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingMaterialDiffuse::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingMaterialDiffuse::getType() const +{ + return cfxGlPipelineSetting::MATERIAL_DIFFUSE; +} + +cfxFloat4 cfxGlPipelineSettingMaterialDiffuse::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingMaterialEmission +cfxGlPipelineSettingMaterialEmission::cfxGlPipelineSettingMaterialEmission(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "MaterialEmission"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingMaterialEmission::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingMaterialEmission::getType() const +{ + return cfxGlPipelineSetting::MATERIAL_EMISSION; +} + +cfxFloat4 cfxGlPipelineSettingMaterialEmission::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingMaterialShininess +cfxGlPipelineSettingMaterialShininess::cfxGlPipelineSettingMaterialShininess(cfxPass* _pass, float _value) + : cfxGlPipelineSetting(_pass, "MaterialShininess"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingMaterialShininess::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingMaterialShininess::getType() const +{ + return cfxGlPipelineSetting::MATERIAL_SHININESS; +} + +float cfxGlPipelineSettingMaterialShininess::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingMaterialSpecular +cfxGlPipelineSettingMaterialSpecular::cfxGlPipelineSettingMaterialSpecular(cfxPass* _pass, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "MaterialSpecular"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingMaterialSpecular::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingMaterialSpecular::getType() const +{ + return cfxGlPipelineSetting::MATERIAL_SPECULAR; +} + +cfxFloat4 cfxGlPipelineSettingMaterialSpecular::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingModelViewMatrix +cfxGlPipelineSettingModelViewMatrix::cfxGlPipelineSettingModelViewMatrix(cfxPass* _pass, cfxFloat4x4& _value) + : cfxGlPipelineSetting(_pass, "ModelViewMatrix"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingModelViewMatrix::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f00); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingModelViewMatrix::getType() const +{ + return cfxGlPipelineSetting::MODEL_VIEW_MATRIX; +} + +cfxFloat4x4 cfxGlPipelineSettingModelViewMatrix::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingPointSize +cfxGlPipelineSettingPointSize::cfxGlPipelineSettingPointSize(cfxPass* _pass, float _value) + : cfxGlPipelineSetting(_pass, "PointSize"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingPointSize::apply() +{ + cgSetFloatStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingPointSize::getType() const +{ + return cfxGlPipelineSetting::POINT_SIZE; +} + +float cfxGlPipelineSettingPointSize::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingPointSpriteCoordReplace +cfxGlPipelineSettingPointSpriteCoordReplace::cfxGlPipelineSettingPointSpriteCoordReplace(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "PointSpriteCoordReplace") +{ +} + +cfxBool cfxGlPipelineSettingPointSpriteCoordReplace::apply() +{ + printf("ERROR: Sprite pipeline settings unimplemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingPointSpriteCoordReplace::getType() const +{ + return cfxGlPipelineSetting::POINT_SPRITE_COORD_REPLACE; +} + + +// cfxGlPipelineSettingPointSpriteRMode +cfxGlPipelineSettingPointSpriteRMode::cfxGlPipelineSettingPointSpriteRMode(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "PointSpriteRMode") +{ +} + +cfxBool cfxGlPipelineSettingPointSpriteRMode::apply() +{ + printf("ERROR: Sprite pipeline settings unimplemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingPointSpriteRMode::getType() const +{ + return cfxGlPipelineSetting::POINT_SPRITE_R_MODE; +} + + +// cfxGlPipelineSettingPolygonMode +cfxGlPipelineSettingPolygonMode::cfxGlPipelineSettingPolygonMode(cfxPass* _pass, int _face, int _mode) + : cfxGlPipelineSetting(_pass, "PolygonMode"), + face(_face), + mode(_mode) +{ +} + +cfxBool cfxGlPipelineSettingPolygonMode::apply() +{ + int values[2]; + values[0] = face; + values[1] = mode; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingPolygonMode::getType() const +{ + return cfxGlPipelineSetting::POLYGON_MODE; +} + +int cfxGlPipelineSettingPolygonMode::getFace() const +{ + return face; +} + +int cfxGlPipelineSettingPolygonMode::getMode() const +{ + return mode; +} + + +// cfxGlPipelineSettingPolygonOffset +cfxGlPipelineSettingPolygonOffset::cfxGlPipelineSettingPolygonOffset(cfxPass* _pass, cfxFloat2& _value) + : cfxGlPipelineSetting(_pass, "PolygonOffset"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingPolygonOffset::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingPolygonOffset::getType() const +{ + return cfxGlPipelineSetting::POLYGON_OFFSET; +} + +cfxFloat2 cfxGlPipelineSettingPolygonOffset::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingProjectionMatrix +cfxGlPipelineSettingProjectionMatrix::cfxGlPipelineSettingProjectionMatrix(cfxPass* _pass, cfxFloat4x4& _value) + : cfxGlPipelineSetting(_pass, "ProjectionMatrix"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingProjectionMatrix::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f00); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingProjectionMatrix::getType() const +{ + return cfxGlPipelineSetting::PROJECTION_MATRIX; +} + +cfxFloat4x4 cfxGlPipelineSettingProjectionMatrix::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingScissor +cfxGlPipelineSettingScissor::cfxGlPipelineSettingScissor(cfxPass* _pass, cfxInt4& _value) + : cfxGlPipelineSetting(_pass, "Scissor"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingScissor::apply() +{ + cgSetIntArrayStateAssignment(assignment, &value.i0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingScissor::getType() const +{ + return cfxGlPipelineSetting::SCISSOR; +} + +cfxInt4 cfxGlPipelineSettingScissor::getValue() const +{ + return value; +} + + +// cfxGlPipelineSettingShadeModel +cfxGlPipelineSettingShadeModel::cfxGlPipelineSettingShadeModel(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "ShadeModel"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingShadeModel::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingShadeModel::getType() const +{ + return cfxGlPipelineSetting::SHADE_MODEL; +} + +int cfxGlPipelineSettingShadeModel::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingStencilFunc +cfxGlPipelineSettingStencilFunc::cfxGlPipelineSettingStencilFunc(cfxPass* _pass, int _func, int _ref, int _mask) + : cfxGlPipelineSetting(_pass, "StencilFunc"), + func(_func), + ref(_ref), + mask(_mask) +{ +} + +cfxBool cfxGlPipelineSettingStencilFunc::apply() +{ + int values[3]; + values[0] = func; + values[1] = ref; + values[2] = mask; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingStencilFunc::getType() const +{ + return cfxGlPipelineSetting::STENCIL_FUNC; +} + +int cfxGlPipelineSettingStencilFunc::getFunc() const +{ + return func; +} + +int cfxGlPipelineSettingStencilFunc::getRef() const +{ + return ref; +} + +int cfxGlPipelineSettingStencilFunc::getMask() const +{ + return mask; +} + +// cfxGlPipelineSettingStencilMask +cfxGlPipelineSettingStencilMask::cfxGlPipelineSettingStencilMask(cfxPass* _pass, int _value) + : cfxGlPipelineSetting(_pass, "StencilMask"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingStencilMask::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingStencilMask::getType() const +{ + return cfxGlPipelineSetting::STENCIL_MASK; +} + +int cfxGlPipelineSettingStencilMask::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingStencilOp +cfxGlPipelineSettingStencilOp::cfxGlPipelineSettingStencilOp(cfxPass* _pass, int _fail, int _zFail, int _zPass) + : cfxGlPipelineSetting(_pass, "StencilOp"), + fail(_fail), + zFail(_zFail), + zPass(_zPass) +{ +} + +cfxBool cfxGlPipelineSettingStencilOp::apply() +{ + int values[3]; + values[0] = fail; + values[1] = zFail; + values[2] = zPass; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingStencilOp::getType() const +{ + return cfxGlPipelineSetting::STENCIL_OP; +} + +int cfxGlPipelineSettingStencilOp::getFail() const +{ + return fail; +} + +int cfxGlPipelineSettingStencilOp::getZFail() const +{ + return zFail; +} + +int cfxGlPipelineSettingStencilOp::getZPass() const +{ + return zPass; +} + +// cfxGlPipelineSettingStencilFuncSeparate +cfxGlPipelineSettingStencilFuncSeparate::cfxGlPipelineSettingStencilFuncSeparate(cfxPass* _pass, int _front, int _back, int _ref, int _mask) + : cfxGlPipelineSetting(_pass, "StencilFuncSeparate"), + front(_front), + back(_back), + ref(_ref), + mask(_mask) +{ +} + +cfxBool cfxGlPipelineSettingStencilFuncSeparate::apply() +{ + int values[4]; + values[0] = front; + values[1] = back; + values[2] = ref; + values[3] = mask; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingStencilFuncSeparate::getType() const +{ + return cfxGlPipelineSetting::STENCIL_FUNC_SEPARATE; +} + +int cfxGlPipelineSettingStencilFuncSeparate::getFront() const +{ + return front; +} + +int cfxGlPipelineSettingStencilFuncSeparate::getBack() const +{ + return back; +} + +int cfxGlPipelineSettingStencilFuncSeparate::getRef() const +{ + return ref; +} + +int cfxGlPipelineSettingStencilFuncSeparate::getMask() const +{ + return mask; +} + +// cfxGlPipelineSettingStencilMaskSeparate +cfxGlPipelineSettingStencilMaskSeparate::cfxGlPipelineSettingStencilMaskSeparate(cfxPass* _pass, int _face, int _mask) + : cfxGlPipelineSetting(_pass, "StencilMaskSeparate"), + face(_face), + mask(_mask) +{ +} + +cfxBool cfxGlPipelineSettingStencilMaskSeparate::apply() +{ + int values[2]; + values[0] = face; + values[1] = mask; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingStencilMaskSeparate::getType() const +{ + return cfxGlPipelineSetting::STENCIL_MASK_SEPARATE; +} + +int cfxGlPipelineSettingStencilMaskSeparate::getFace() const +{ + return face; +} + +int cfxGlPipelineSettingStencilMaskSeparate::getMask() const +{ + return mask; +} + + +// cfxGlPipelineSettingStencilOpSeparate +cfxGlPipelineSettingStencilOpSeparate::cfxGlPipelineSettingStencilOpSeparate(cfxPass* _pass, int _face, int _fail, int _zFail, int _zPass) + : cfxGlPipelineSetting(_pass, "StencilOpSeparate"), + face(_face), + fail(_fail), + zFail(_zFail), + zPass(_zPass) +{ +} + +cfxBool cfxGlPipelineSettingStencilOpSeparate::apply() +{ + int values[4]; + values[0] = face; + values[1] = fail; + values[2] = zFail; + values[3] = zPass; + cgSetIntArrayStateAssignment(assignment, values); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingStencilOpSeparate::getType() const +{ + return cfxGlPipelineSetting::STENCIL_OP_SEPAREATE; +} + +int cfxGlPipelineSettingStencilOpSeparate::getFace() const +{ + return face; +} + +int cfxGlPipelineSettingStencilOpSeparate::getFail() const +{ + return fail; +} + +int cfxGlPipelineSettingStencilOpSeparate::getZFail() const +{ + return zFail; +} + +int cfxGlPipelineSettingStencilOpSeparate::getZPass() const +{ + return zPass; +} + +// cfxGlPipelineSettingTexGenSMode +cfxGlPipelineSettingTexGenSMode::cfxGlPipelineSettingTexGenSMode(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenSMode") +{ +} + +cfxBool cfxGlPipelineSettingTexGenSMode::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenSMode::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_S_MODE; +} + + +// cfxGlPipelineSettingTexGenTMode +cfxGlPipelineSettingTexGenTMode::cfxGlPipelineSettingTexGenTMode(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenTMode") +{ +} + +cfxBool cfxGlPipelineSettingTexGenTMode::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenTMode::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_T_MODE; +} + + +// cfxGlPipelineSettingTexGenRMode +cfxGlPipelineSettingTexGenRMode::cfxGlPipelineSettingTexGenRMode(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenRMode") +{ +} + +cfxBool cfxGlPipelineSettingTexGenRMode::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenRMode::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_R_MODE; +} + + +// cfxGlPipelineSettingTexGenQMode +cfxGlPipelineSettingTexGenQMode::cfxGlPipelineSettingTexGenQMode(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenQMode") +{ +} + +cfxBool cfxGlPipelineSettingTexGenQMode::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenQMode::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_Q_MODE; +} + + +// cfxGlPipelineSettingTexGenSEyePlane +cfxGlPipelineSettingTexGenSEyePlane::cfxGlPipelineSettingTexGenSEyePlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenSEyePlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenSEyePlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenSEyePlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_S_EYE_PLANE; +} + + +// cfxGlPipelineSettingTexGenTEyePlane +cfxGlPipelineSettingTexGenTEyePlane::cfxGlPipelineSettingTexGenTEyePlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenTEyePlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenTEyePlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenTEyePlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_T_EYE_PLANE; +} + + +// cfxGlPipelineSettingTexGenREyePlane +cfxGlPipelineSettingTexGenREyePlane::cfxGlPipelineSettingTexGenREyePlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenREyePlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenREyePlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenREyePlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_R_EYE_PLANE; +} + + +// cfxGlPipelineSettingTexGenQEyePlane +cfxGlPipelineSettingTexGenQEyePlane::cfxGlPipelineSettingTexGenQEyePlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenQEyePlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenQEyePlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenQEyePlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_Q_EYE_PLANE; +} + + +// cfxGlPipelineSettingTexGenSObjectPlane +cfxGlPipelineSettingTexGenSObjectPlane::cfxGlPipelineSettingTexGenSObjectPlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenSObjectPlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenSObjectPlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenSObjectPlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_S_OBJECT_PLANE; +} + + +// cfxGlPipelineSettingTexGenTObjectPlane +cfxGlPipelineSettingTexGenTObjectPlane::cfxGlPipelineSettingTexGenTObjectPlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenTObjectPlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenTObjectPlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenTObjectPlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_T_OBJECT_PLANE; +} + + +// cfxGlPipelineSettingTexGenRObjectPlane +cfxGlPipelineSettingTexGenRObjectPlane::cfxGlPipelineSettingTexGenRObjectPlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenRObjectPlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenRObjectPlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenRObjectPlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_R_OBJECT_PLANE; +} + + +// cfxGlPipelineSettingTexGenQObjectPlane +cfxGlPipelineSettingTexGenQObjectPlane::cfxGlPipelineSettingTexGenQObjectPlane(cfxPass* _pass) + : cfxGlPipelineSetting(_pass, "TexGenQObjectPlane") +{ +} + +cfxBool cfxGlPipelineSettingTexGenQObjectPlane::apply() +{ + printf("ERROR: TexGen state Assignments not implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexGenQObjectPlane::getType() const +{ + return cfxGlPipelineSetting::TEX_GEN_Q_OBJECT_PLANE; +} + + +// cfxGlPipelineSettingTexture2D +cfxGlPipelineSettingTexture2D::cfxGlPipelineSettingTexture2D(cfxPass* _pass, int _index, cfxSampler* _sampler) + : cfxGlPipelineSetting(_pass, "Texture2D", _index), + index(_index), + sampler(_sampler) +{ +} + +cfxBool cfxGlPipelineSettingTexture2D::apply() +{ + printf("ERROR: Texture2D state Assignment not completely implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexture2D::getType() const +{ + return cfxGlPipelineSetting::TEXTURE_2D; +} + +int cfxGlPipelineSettingTexture2D::getIndex() const +{ + return index; +} + +const cfxSampler *cfxGlPipelineSettingTexture2D::getSampler() const +{ + return sampler; +} + +// cfxGlPipelineSettingTexture3D +cfxGlPipelineSettingTexture3D::cfxGlPipelineSettingTexture3D(cfxPass* _pass, int _index, cfxSampler* _sampler) + : cfxGlPipelineSetting(_pass, "Texture3D", _index), + index(_index), + sampler(_sampler) +{ +} + +cfxBool cfxGlPipelineSettingTexture3D::apply() +{ + printf("ERROR: Texture3D state Assignment not completely implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTexture3D::getType() const +{ + return cfxGlPipelineSetting::TEXTURE_3D; +} + +int cfxGlPipelineSettingTexture3D::getIndex() const +{ + return index; +} + +const cfxSampler *cfxGlPipelineSettingTexture3D::getSampler() const +{ + return sampler; +} + +// cfxGlPipelineSettingTextureCubeMap +cfxGlPipelineSettingTextureCubeMap::cfxGlPipelineSettingTextureCubeMap(cfxPass* _pass, int _index, cfxSampler* _sampler) + : cfxGlPipelineSetting(_pass, "TextureCubeMap", _index), + index(_index), + sampler(_sampler) + +{ +} + +cfxBool cfxGlPipelineSettingTextureCubeMap::apply() +{ + printf("ERROR: TextureCubeMap state Assignment not completely implemented.\n"); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTextureCubeMap::getType() const +{ + return cfxGlPipelineSetting::TEXTURE_CUBE_MAP; +} + +int cfxGlPipelineSettingTextureCubeMap::getIndex() const +{ + return index; +} + +const cfxSampler *cfxGlPipelineSettingTextureCubeMap::getSampler() const +{ + return sampler; +} + +// cfxGlPipelineSettingTextureEnvColor +cfxGlPipelineSettingTextureEnvColor::cfxGlPipelineSettingTextureEnvColor(cfxPass* _pass, int _index, cfxFloat4& _value) + : cfxGlPipelineSetting(_pass, "TextureEnvColor", _index), + index(_index), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingTextureEnvColor::apply() +{ + cgSetFloatArrayStateAssignment(assignment, &value.f0); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTextureEnvColor::getType() const +{ + return cfxGlPipelineSetting::TEXTURE_ENV_COLOR; +} + +int cfxGlPipelineSettingTextureEnvColor::getIndex() const +{ + return index; +} + +cfxFloat4 cfxGlPipelineSettingTextureEnvColor::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingTextureEnvMode +cfxGlPipelineSettingTextureEnvMode::cfxGlPipelineSettingTextureEnvMode(cfxPass* _pass, int _index, int _value) + : cfxGlPipelineSetting(_pass, "TextureEnvMode", _index), + index(_index), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingTextureEnvMode::apply() +{ + cgSetIntStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingTextureEnvMode::getType() const +{ + return cfxGlPipelineSetting::TEXTURE_ENV_MODE; +} + +int cfxGlPipelineSettingTextureEnvMode::getIndex() const +{ + return index; +} + +int cfxGlPipelineSettingTextureEnvMode::getValue() const +{ + return value; +} + +// ENABLE / DISABLE settings + + +// cfxGlPipelineSettingAlphaTestEnable +cfxGlPipelineSettingAlphaTestEnable::cfxGlPipelineSettingAlphaTestEnable(cfxPass* _pass, cfxBool _value) + : cfxGlPipelineSetting(_pass, "AlphaTestEnable"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingAlphaTestEnable::apply() +{ + cgSetBoolStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingAlphaTestEnable::getType() const +{ + return cfxGlPipelineSetting::ALPHA_TEST_ENABLE; +} + +cfxBool cfxGlPipelineSettingAlphaTestEnable::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingBlendEnable +cfxGlPipelineSettingBlendEnable::cfxGlPipelineSettingBlendEnable(cfxPass* _pass, cfxBool _value) + : cfxGlPipelineSetting(_pass, "BlendEnable"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingBlendEnable::apply() +{ + cgSetBoolStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingBlendEnable::getType() const +{ + return cfxGlPipelineSetting::BLEND_ENABLE; +} + +cfxBool cfxGlPipelineSettingBlendEnable::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingCullFaceEnable +cfxGlPipelineSettingCullFaceEnable::cfxGlPipelineSettingCullFaceEnable(cfxPass* _pass, cfxBool _value) + : cfxGlPipelineSetting(_pass, "CullFaceEnable"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingCullFaceEnable::apply() +{ + cgSetBoolStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingCullFaceEnable::getType() const +{ + return cfxGlPipelineSetting::CULL_FACE_ENABLE; +} + +cfxBool cfxGlPipelineSettingCullFaceEnable::getValue() const +{ + return value; +} + +// cfxGlPipelineSettingDepthTestEnable +cfxGlPipelineSettingDepthTestEnable::cfxGlPipelineSettingDepthTestEnable(cfxPass* _pass, cfxBool _value) + : cfxGlPipelineSetting(_pass, "DepthTestEnable"), + value(_value) +{ +} + +cfxBool cfxGlPipelineSettingDepthTestEnable::apply() +{ + cgSetBoolStateAssignment(assignment, value); + return true; +} + +cfxGlPipelineSetting::type_enum cfxGlPipelineSettingDepthTestEnable::getType() const +{ + return cfxGlPipelineSetting::DEPTH_TEST_ENABLE; +} + +cfxBool cfxGlPipelineSettingDepthTestEnable::getValue() const +{ + return value; +} + +#if 0 // template +// cfxGlPipelineSetting +cfxGlPipelineSetting::cfxGlPipelineSetting(cfxPass* _pass, cfxBool _value) + : cfxGlPipelineSetting(_pass, ""), + value(_value) +{ +} + +cfxBool cfxGlPipelineSetting::apply() +{ + cgSetBoolStateAssignment(assignment, value); + return true; +} + +#endif + diff --git a/1.4.0/fx/src/cfxGlPipelineSettingMaker.cpp b/1.4.0/fx/src/cfxGlPipelineSettingMaker.cpp new file mode 100644 index 0000000..8868418 --- /dev/null +++ b/1.4.0/fx/src/cfxGlPipelineSettingMaker.cpp @@ -0,0 +1,1431 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +#include <cfxGlPipelineSettingMaker.h> +#include <cfxGlPipelineSetting.h> + +#include <cfxGlEnumMaps.h> + +#include <dae/daeDomTypes.h> +#include <dom/domConstants.h> +#include <dom/domGl_pipeline_settings.h> + +//#ifndef _LIB +#include <Cg/cg.h> +//#else +//#include <cfxNoCg.h> +//#endif + + +// cfxGlPipelineSettingMaker +std::map<std::string, cfxGlPipelineSettingMaker*> cfxGlPipelineSettingMaker::mapTypeNameToSettingMaker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMaker::makeGlPipelineSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + std::map<std::string, cfxGlPipelineSettingMaker*>::iterator iter; + // here is the element which owns the actual data + // it is a choice in schema, so there will be only one element in _contents that exists as the "chosen" item, + // which will be one of the elements in this class + daeElement* dataElement = settingInitializer->getContents().get(0); + // get typename from contents, use this to lookup the factory for the data + daeString dataTypeName = dataElement->getTypeName(); + iter = mapTypeNameToSettingMaker.find(dataTypeName); + if (iter == mapTypeNameToSettingMaker.end()) + { + printf("ERROR: Setting maker not found for: %s\n", dataTypeName); + return NULL; + } + printf("Making setting for: %s\n", dataTypeName); + return iter->second->makeSetting(pass, settingInitializer); +} + + +// cfxGlPipelineSettingMakerAlphaFunc +cfxGlPipelineSettingMakerAlphaFunc::cfxGlPipelineSettingMakerAlphaFunc() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_ALPHA_FUNC, this)); +} + +cfxGlPipelineSettingMakerAlphaFunc cfxGlPipelineSettingMakerAlphaFunc::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerAlphaFunc::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domFunc = settingInitializer->getAlpha_func()->getFunc()->getValue(); + int func = cfxGlEnumMaps::getFuncTypeEnum(domFunc); + + float value = settingInitializer->getAlpha_func()->getValue()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingAlphaFunc(pass, func, value); + return setting; +} + + +// cfxGlPipelineSettingMakerBlendFunc +cfxGlPipelineSettingMakerBlendFunc::cfxGlPipelineSettingMakerBlendFunc() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_BLEND_FUNC, this)); +} + +cfxGlPipelineSettingMakerBlendFunc cfxGlPipelineSettingMakerBlendFunc::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerBlendFunc::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domSrc = settingInitializer->getBlend_func()->getSrc()->getValue(); + int src = cfxGlEnumMaps::getBlendTypeEnum(domSrc); + + int domDst = settingInitializer->getBlend_func()->getDest()->getValue(); + int dst = cfxGlEnumMaps::getBlendTypeEnum(domDst); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingBlendFunc(pass, src, dst); + return setting; +} + + +// cfxGlPipelineSettingMakerBlendFuncSeparate +cfxGlPipelineSettingMakerBlendFuncSeparate::cfxGlPipelineSettingMakerBlendFuncSeparate() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_BLEND_FUNC_SEPARATE, this)); +} + +cfxGlPipelineSettingMakerBlendFuncSeparate cfxGlPipelineSettingMakerBlendFuncSeparate::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerBlendFuncSeparate::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domSrcRGB = settingInitializer->getBlend_func_separate()->getSrc_rgb()->getValue(); + int srcRGB = cfxGlEnumMaps::getBlendTypeEnum(domSrcRGB); + + int domDstRGB = settingInitializer->getBlend_func_separate()->getDest_rgb()->getValue(); + int dstRGB = cfxGlEnumMaps::getBlendTypeEnum(domDstRGB); + + int domSrcAlpha = settingInitializer->getBlend_func_separate()->getSrc_alpha()->getValue(); + int srcAlpha = cfxGlEnumMaps::getBlendTypeEnum(domSrcAlpha); + + int domDstAlpha = settingInitializer->getBlend_func_separate()->getDest_alpha()->getValue(); + int dstAlpha = cfxGlEnumMaps::getBlendTypeEnum(domDstAlpha); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingBlendFuncSeparate(pass, srcRGB, dstRGB, srcAlpha, dstAlpha); + return setting; +} + + +// cfxGlPipelineSettingMakerBlendEquation +cfxGlPipelineSettingMakerBlendEquation::cfxGlPipelineSettingMakerBlendEquation() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_BLEND_EQUATION, this)); +} + +cfxGlPipelineSettingMakerBlendEquation cfxGlPipelineSettingMakerBlendEquation::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerBlendEquation::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domEquation = settingInitializer->getBlend_equation()->getValue(); + int equation = cfxGlEnumMaps::getBlendEquationTypeEnum(domEquation); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingBlendEquation(pass, equation); + return setting; +} + + +// cfxGlPipelineSettingMakerBlendEquationSeparate +cfxGlPipelineSettingMakerBlendEquationSeparate::cfxGlPipelineSettingMakerBlendEquationSeparate() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_BLEND_EQUATION_SEPARATE, this)); +} + +cfxGlPipelineSettingMakerBlendEquationSeparate cfxGlPipelineSettingMakerBlendEquationSeparate::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerBlendEquationSeparate::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domRgb = settingInitializer->getBlend_equation_separate()->getRgb()->getValue(); + int rgb = cfxGlEnumMaps::getBlendEquationTypeEnum(domRgb); + + int domAlpha = settingInitializer->getBlend_equation_separate()->getAlpha()->getValue(); + int alpha = cfxGlEnumMaps::getBlendEquationTypeEnum(domAlpha); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingBlendEquationSeparate(pass, rgb, alpha); + return setting; +} + + +// cfxGlPipelineSettingMakerBlendColor +cfxGlPipelineSettingMakerBlendColor::cfxGlPipelineSettingMakerBlendColor() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_BLEND_COLOR, this)); +} + +cfxGlPipelineSettingMakerBlendColor cfxGlPipelineSettingMakerBlendColor::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerBlendColor::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + domFloat4& domValue = settingInitializer->getBlend_color()->getValue(); + cfxFloat4 value; + value.f0 = (cfxFloat) domValue.get(0); + value.f1 = (cfxFloat) domValue.get(1); + value.f2 = (cfxFloat) domValue.get(2); + value.f3 = (cfxFloat) domValue.get(3); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingBlendColor(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerClearColor +cfxGlPipelineSettingMakerClearColor::cfxGlPipelineSettingMakerClearColor() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_CLEAR_COLOR, this)); +} + +cfxGlPipelineSettingMakerClearColor cfxGlPipelineSettingMakerClearColor::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerClearColor::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + domFloat4& domValue = settingInitializer->getClear_color()->getValue(); + cfxFloat4 value; + value.f0 = (cfxFloat) domValue.get(0); + value.f1 = (cfxFloat) domValue.get(1); + value.f2 = (cfxFloat) domValue.get(2); + value.f3 = (cfxFloat) domValue.get(3); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingClearColor(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerClearStencil +cfxGlPipelineSettingMakerClearStencil::cfxGlPipelineSettingMakerClearStencil() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_CLEAR_STENCIL, this)); +} + +cfxGlPipelineSettingMakerClearStencil cfxGlPipelineSettingMakerClearStencil::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerClearStencil::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxInt value = (cfxInt) settingInitializer->getClear_stencil()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingClearStencil(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerClearDepth +cfxGlPipelineSettingMakerClearDepth::cfxGlPipelineSettingMakerClearDepth() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_CLEAR_DEPTH, this)); +} + +cfxGlPipelineSettingMakerClearDepth cfxGlPipelineSettingMakerClearDepth::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerClearDepth::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat value = (cfxFloat) settingInitializer->getClear_depth()->getValue(); + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingClearDepth(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerClipPlane +cfxGlPipelineSettingMakerClipPlane::cfxGlPipelineSettingMakerClipPlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_CLIP_PLANE, this)); +} + +cfxGlPipelineSettingMakerClipPlane cfxGlPipelineSettingMakerClipPlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerClipPlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index = settingInitializer->getClip_plane()->getIndex(); + + domFloat4& domValue = settingInitializer->getClip_plane()->getValue(); + cfxFloat4 value; + value.f0 = (cfxFloat) domValue.get(0); + value.f1 = (cfxFloat) domValue.get(1); + value.f2 = (cfxFloat) domValue.get(2); + value.f3 = (cfxFloat) domValue.get(3); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingClipPlane(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerColorMask +cfxGlPipelineSettingMakerColorMask::cfxGlPipelineSettingMakerColorMask() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_COLOR_MASK, this)); +} + +cfxGlPipelineSettingMakerColorMask cfxGlPipelineSettingMakerColorMask::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerColorMask::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + domBool4& domValue = settingInitializer->getColor_mask()->getValue(); + cfxBool4 value; + value.b0 = domValue.get(0); + value.b1 = domValue.get(1); + value.b2 = domValue.get(2); + value.b3 = domValue.get(3); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingColorMask(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerColorMaterial +cfxGlPipelineSettingMakerColorMaterial::cfxGlPipelineSettingMakerColorMaterial() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_COLOR_MATERIAL, this)); +} + +cfxGlPipelineSettingMakerColorMaterial cfxGlPipelineSettingMakerColorMaterial::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerColorMaterial::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domFace = settingInitializer->getColor_material()->getFace()->getValue(); + int face = cfxGlEnumMaps::getFaceTypeEnum(domFace); + + int domMode = settingInitializer->getColor_material()->getMode()->getValue(); + int mode = cfxGlEnumMaps::getModeTypeEnum(domMode); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingColorMaterial(pass, face, mode); + return setting; +} + + +// cfxGlPipelineSettingMakerCullFace +cfxGlPipelineSettingMakerCullFace::cfxGlPipelineSettingMakerCullFace() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_CULL_FACE, this)); +} + +cfxGlPipelineSettingMakerCullFace cfxGlPipelineSettingMakerCullFace::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerCullFace::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domValue = settingInitializer->getCull_face()->getValue(); + int value = cfxGlEnumMaps::getFaceTypeEnum(domValue); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingCullFace(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerDepthFunc +cfxGlPipelineSettingMakerDepthFunc::cfxGlPipelineSettingMakerDepthFunc() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_DEPTH_FUNC, this)); +} + +cfxGlPipelineSettingMakerDepthFunc cfxGlPipelineSettingMakerDepthFunc::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerDepthFunc::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domValue = settingInitializer->getDepth_func()->getValue(); + int value = cfxGlEnumMaps::getFuncTypeEnum( domValue ); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingDepthFunc(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerDepthMask +cfxGlPipelineSettingMakerDepthMask::cfxGlPipelineSettingMakerDepthMask() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_DEPTH_MASK, this)); +} + +cfxGlPipelineSettingMakerDepthMask cfxGlPipelineSettingMakerDepthMask::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerDepthMask::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + bool value = settingInitializer->getDepth_mask()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingDepthMask(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerDepthRange +cfxGlPipelineSettingMakerDepthRange::cfxGlPipelineSettingMakerDepthRange() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_DEPTH_RANGE, this)); +} + +cfxGlPipelineSettingMakerDepthRange cfxGlPipelineSettingMakerDepthRange::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerDepthRange::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat2 value; + domFloat2& domValue = settingInitializer->getDepth_range()->getValue(); + value.f0 = (cfxFloat) domValue.get(0); + value.f1 = (cfxFloat) domValue.get(1); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingDepthRange(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerFogMode +cfxGlPipelineSettingMakerFogMode::cfxGlPipelineSettingMakerFogMode() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_FOG_MODE, this)); +} + +cfxGlPipelineSettingMakerFogMode cfxGlPipelineSettingMakerFogMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerFogMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int domValue = settingInitializer->getFog_mode()->getValue(); + int value = cfxGlEnumMaps::getFogModeTypeEnum( domValue ); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingFogMode(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerFogDensity +cfxGlPipelineSettingMakerFogDensity::cfxGlPipelineSettingMakerFogDensity() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_FOG_DENSITY, this)); +} + +cfxGlPipelineSettingMakerFogDensity cfxGlPipelineSettingMakerFogDensity::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerFogDensity::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + float value = (float)settingInitializer->getFog_density()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingFogDensity(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerFogStart +cfxGlPipelineSettingMakerFogStart::cfxGlPipelineSettingMakerFogStart() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_FOG_START, this)); +} + +cfxGlPipelineSettingMakerFogStart cfxGlPipelineSettingMakerFogStart::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerFogStart::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + float value = (float)settingInitializer->getFog_start()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingFogStart(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerFogEnd +cfxGlPipelineSettingMakerFogEnd::cfxGlPipelineSettingMakerFogEnd() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_FOG_END, this)); +} + +cfxGlPipelineSettingMakerFogEnd cfxGlPipelineSettingMakerFogEnd::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerFogEnd::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + float value = (float)settingInitializer->getFog_end()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingFogEnd(pass, value); + return setting; +} + + +#if 0 +// these are currently unimplemented due to time constraints +// all that needs to be done is actually pull the values out of +// the DOM and put them into the variables passed to the call to new + +// cfxGlPipelineSettingMakerFogColor +cfxGlPipelineSettingMakerFogColor::cfxGlPipelineSettingMakerFogColor() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_FOG_COLOR, this)); +} + +cfxGlPipelineSettingMakerFogColor cfxGlPipelineSettingMakerFogColor::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerFogColor::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingFogColor(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerFrontFace +cfxGlPipelineSettingMakerFrontFace::cfxGlPipelineSettingMakerFrontFace() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_FRONT_FACE, this)); +} + +cfxGlPipelineSettingMakerFrontFace cfxGlPipelineSettingMakerFrontFace::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerFrontFace::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingFrontFace(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightModelAmbient +cfxGlPipelineSettingMakerLightModelAmbient::cfxGlPipelineSettingMakerLightModelAmbient() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_MODEL_AMBIENT, this)); +} + +cfxGlPipelineSettingMakerLightModelAmbient cfxGlPipelineSettingMakerLightModelAmbient::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightModelAmbient::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightModelAmbient(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightAmbient +cfxGlPipelineSettingMakerLightAmbient::cfxGlPipelineSettingMakerLightAmbient() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_AMBIENT, this)); +} + +cfxGlPipelineSettingMakerLightAmbient cfxGlPipelineSettingMakerLightAmbient::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightAmbient::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightAmbient(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightConstantAttenuation +cfxGlPipelineSettingMakerLightConstantAttenuation::cfxGlPipelineSettingMakerLightConstantAttenuation() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_CONSTANT_ATTENUATION, this)); +} + +cfxGlPipelineSettingMakerLightConstantAttenuation cfxGlPipelineSettingMakerLightConstantAttenuation::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightConstantAttenuation::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightConstantAttenuation(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightDiffuse +cfxGlPipelineSettingMakerLightDiffuse::cfxGlPipelineSettingMakerLightDiffuse() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_DIFFUSE, this)); +} + +cfxGlPipelineSettingMakerLightDiffuse cfxGlPipelineSettingMakerLightDiffuse::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightDiffuse::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightDiffuse(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightLinearAttenuation +cfxGlPipelineSettingMakerLightLinearAttenuation::cfxGlPipelineSettingMakerLightLinearAttenuation() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_LINEAR_ATTENUATION, this)); +} + +cfxGlPipelineSettingMakerLightLinearAttenuation cfxGlPipelineSettingMakerLightLinearAttenuation::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightLinearAttenuation::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightLinearAttenuation(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightPosition +cfxGlPipelineSettingMakerLightPosition::cfxGlPipelineSettingMakerLightPosition() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_POSITION, this)); +} + +cfxGlPipelineSettingMakerLightPosition cfxGlPipelineSettingMakerLightPosition::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightPosition::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightPosition(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightQuadraticAttenuation +cfxGlPipelineSettingMakerLightQuadraticAttenuation::cfxGlPipelineSettingMakerLightQuadraticAttenuation() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_QUADRATIC_ATTENUATION, this)); +} + +cfxGlPipelineSettingMakerLightQuadraticAttenuation cfxGlPipelineSettingMakerLightQuadraticAttenuation::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightQuadraticAttenuation::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightQuadraticAttenuation(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightSpecular +cfxGlPipelineSettingMakerLightSpecular::cfxGlPipelineSettingMakerLightSpecular() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_SPECULAR, this)); +} + +cfxGlPipelineSettingMakerLightSpecular cfxGlPipelineSettingMakerLightSpecular::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightSpecular::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightSpecular(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightSpotCutoff +cfxGlPipelineSettingMakerLightSpotCutoff::cfxGlPipelineSettingMakerLightSpotCutoff() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_SPOT_CUTOFF, this)); +} + +cfxGlPipelineSettingMakerLightSpotCutoff cfxGlPipelineSettingMakerLightSpotCutoff::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightSpotCutoff::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightSpotCutoff(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightSpotDirection +cfxGlPipelineSettingMakerLightSpotDirection::cfxGlPipelineSettingMakerLightSpotDirection() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_SPOT_DIRECTION, this)); +} + +cfxGlPipelineSettingMakerLightSpotDirection cfxGlPipelineSettingMakerLightSpotDirection::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightSpotDirection::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxFloat3 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightSpotDirection(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLightSpotExponent +cfxGlPipelineSettingMakerLightSpotExponent::cfxGlPipelineSettingMakerLightSpotExponent() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LIGHT_SPOT_EXPONENT, this)); +} + +cfxGlPipelineSettingMakerLightSpotExponent cfxGlPipelineSettingMakerLightSpotExponent::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLightSpotExponent::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLightSpotExponent(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLineWidth +cfxGlPipelineSettingMakerLineWidth::cfxGlPipelineSettingMakerLineWidth() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LINE_WIDTH, this)); +} + +cfxGlPipelineSettingMakerLineWidth cfxGlPipelineSettingMakerLineWidth::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLineWidth::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLineWidth(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerLogicOp +cfxGlPipelineSettingMakerLogicOp::cfxGlPipelineSettingMakerLogicOp() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_LOGIC_OP, this)); +} + +cfxGlPipelineSettingMakerLogicOp cfxGlPipelineSettingMakerLogicOp::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerLogicOp::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingLogicOp(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerMaterialAmbient +cfxGlPipelineSettingMakerMaterialAmbient::cfxGlPipelineSettingMakerMaterialAmbient() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_MATERIAL_AMBIENT, this)); +} + +cfxGlPipelineSettingMakerMaterialAmbient cfxGlPipelineSettingMakerMaterialAmbient::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerMaterialAmbient::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingMaterialAmbient(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerMaterialDiffuse +cfxGlPipelineSettingMakerMaterialDiffuse::cfxGlPipelineSettingMakerMaterialDiffuse() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_MATERIAL_DIFFUSE, this)); +} + +cfxGlPipelineSettingMakerMaterialDiffuse cfxGlPipelineSettingMakerMaterialDiffuse::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerMaterialDiffuse::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingMaterialDiffuse(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerMaterialEmission +cfxGlPipelineSettingMakerMaterialEmission::cfxGlPipelineSettingMakerMaterialEmission() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_MATERIAL_EMISSION, this)); +} + +cfxGlPipelineSettingMakerMaterialEmission cfxGlPipelineSettingMakerMaterialEmission::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerMaterialEmission::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingMaterialEmission(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerMaterialShininess +cfxGlPipelineSettingMakerMaterialShininess::cfxGlPipelineSettingMakerMaterialShininess() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_MATERIAL_SHININESS, this)); +} + +cfxGlPipelineSettingMakerMaterialShininess cfxGlPipelineSettingMakerMaterialShininess::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerMaterialShininess::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingMaterialShininess(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerMaterialSpecular +cfxGlPipelineSettingMakerMaterialSpecular::cfxGlPipelineSettingMakerMaterialSpecular() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_MATERIAL_SPECULAR, this)); +} + +cfxGlPipelineSettingMakerMaterialSpecular cfxGlPipelineSettingMakerMaterialSpecular::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerMaterialSpecular::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingMaterialSpecular(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerModelViewMatrix +cfxGlPipelineSettingMakerModelViewMatrix::cfxGlPipelineSettingMakerModelViewMatrix() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_MODEL_VIEW_MATRIX, this)); +} + +cfxGlPipelineSettingMakerModelViewMatrix cfxGlPipelineSettingMakerModelViewMatrix::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerModelViewMatrix::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4x4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingModelViewMatrix(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerPointSize +cfxGlPipelineSettingMakerPointSize::cfxGlPipelineSettingMakerPointSize() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_POINT_SIZE, this)); +} + +cfxGlPipelineSettingMakerPointSize cfxGlPipelineSettingMakerPointSize::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerPointSize::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + float value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingPointSize(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerPointSpriteCoordReplace +cfxGlPipelineSettingMakerPointSpriteCoordReplace::cfxGlPipelineSettingMakerPointSpriteCoordReplace() +{ + //mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_POINT_SPRITE_COORD_REPLACE, this)); +} + +cfxGlPipelineSettingMakerPointSpriteCoordReplace cfxGlPipelineSettingMakerPointSpriteCoordReplace::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerPointSpriteCoordReplace::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingPointSpriteCoordReplace(pass); + return setting; +} + + +// cfxGlPipelineSettingMakerPointSpriteRMode +cfxGlPipelineSettingMakerPointSpriteRMode::cfxGlPipelineSettingMakerPointSpriteRMode() +{ + //mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_POINT_SPRITE_R_MODE, this)); +} + +cfxGlPipelineSettingMakerPointSpriteRMode cfxGlPipelineSettingMakerPointSpriteRMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerPointSpriteRMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingPointSpriteRMode(pass); + return setting; +} + + +// cfxGlPipelineSettingMakerPolygonMode +cfxGlPipelineSettingMakerPolygonMode::cfxGlPipelineSettingMakerPolygonMode() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_POLYGON_MODE, this)); +} + +cfxGlPipelineSettingMakerPolygonMode cfxGlPipelineSettingMakerPolygonMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerPolygonMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int face; + int mode; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingPolygonMode(pass, face, mode); + return setting; +} + + +// cfxGlPipelineSettingMakerPolygonOffset +cfxGlPipelineSettingMakerPolygonOffset::cfxGlPipelineSettingMakerPolygonOffset() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_POLYGON_OFFSET, this)); +} + +cfxGlPipelineSettingMakerPolygonOffset cfxGlPipelineSettingMakerPolygonOffset::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerPolygonOffset::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat2 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingPolygonOffset(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerProjectionMatrix +cfxGlPipelineSettingMakerProjectionMatrix::cfxGlPipelineSettingMakerProjectionMatrix() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_PROJECTION_MATRIX, this)); +} + +cfxGlPipelineSettingMakerProjectionMatrix cfxGlPipelineSettingMakerProjectionMatrix::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerProjectionMatrix::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxFloat4x4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingProjectionMatrix(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerScissor +cfxGlPipelineSettingMakerScissor::cfxGlPipelineSettingMakerScissor() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_SCISSOR, this)); +} + +cfxGlPipelineSettingMakerScissor cfxGlPipelineSettingMakerScissor::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerScissor::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxInt4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingScissor(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerShadeModel +cfxGlPipelineSettingMakerShadeModel::cfxGlPipelineSettingMakerShadeModel() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_SHADE_MODEL, this)); +} + +cfxGlPipelineSettingMakerShadeModel cfxGlPipelineSettingMakerShadeModel::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerShadeModel::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingShadeModel(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerStencilFunc +cfxGlPipelineSettingMakerStencilFunc::cfxGlPipelineSettingMakerStencilFunc() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_STENCIL_FUNC, this)); +} + +cfxGlPipelineSettingMakerStencilFunc cfxGlPipelineSettingMakerStencilFunc::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerStencilFunc::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int func; + int ref; + int mask; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingStencilFunc(pass, func, ref, mask); + return setting; +} + + +// cfxGlPipelineSettingMakerStencilMask +cfxGlPipelineSettingMakerStencilMask::cfxGlPipelineSettingMakerStencilMask() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_STENCIL_MASK, this)); +} + +cfxGlPipelineSettingMakerStencilMask cfxGlPipelineSettingMakerStencilMask::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerStencilMask::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingStencilMask(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerStencilOp +cfxGlPipelineSettingMakerStencilOp::cfxGlPipelineSettingMakerStencilOp() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_STENCIL_OP, this)); +} + +cfxGlPipelineSettingMakerStencilOp cfxGlPipelineSettingMakerStencilOp::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerStencilOp::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int fail; + int zFail; + int zPass; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingStencilOp(pass, fail, zFail, zPass); + return setting; +} + + +// cfxGlPipelineSettingMakerStencilFuncSeparate +cfxGlPipelineSettingMakerStencilFuncSeparate::cfxGlPipelineSettingMakerStencilFuncSeparate() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_STENCIL_FUNC_SEPARATE, this)); +} + +cfxGlPipelineSettingMakerStencilFuncSeparate cfxGlPipelineSettingMakerStencilFuncSeparate::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerStencilFuncSeparate::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int front; + int back; + int ref; + int mask; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingStencilFuncSeparate(pass, front, back, ref, mask); + return setting; +} + + +// cfxGlPipelineSettingMakerStencilMaskSeparate +cfxGlPipelineSettingMakerStencilMaskSeparate::cfxGlPipelineSettingMakerStencilMaskSeparate() +{ + //mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_STENCIL_MASK_SEPARATE, this)); +} + +cfxGlPipelineSettingMakerStencilMaskSeparate cfxGlPipelineSettingMakerStencilMaskSeparate::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerStencilMaskSeparate::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int face; + int mask; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingStencilMaskSeparate(pass, face, mask); + return setting; +} + + +// cfxGlPipelineSettingMakerStencilOpSeparate +cfxGlPipelineSettingMakerStencilOpSeparate::cfxGlPipelineSettingMakerStencilOpSeparate() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_STENCIL_OP_SEPARATE, this)); +} + +cfxGlPipelineSettingMakerStencilOpSeparate cfxGlPipelineSettingMakerStencilOpSeparate::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerStencilOpSeparate::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int face; + int fail; + int zFail; + int zPass; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingStencilOpSeparate(pass, face, fail, zFail, zPass); + return setting; +} + +#endif + + +#if 0 // all texgen makers unimplemented because not in COLLADA yet + +// cfxGlPipelineSettingMakerTexGenSMode +cfxGlPipelineSettingMakerTexGenSMode::cfxGlPipelineSettingMakerTexGenSMode() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenSMode cfxGlPipelineSettingMakerTexGenSMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenSMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenSMode(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenTMode +cfxGlPipelineSettingMakerTexGenTMode::cfxGlPipelineSettingMakerTexGenTMode() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenTMode cfxGlPipelineSettingMakerTexGenTMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenTMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenTMode(pass, ); + return setting; +} + +// cfxGlPipelineSettingMakerTexGenRMode +cfxGlPipelineSettingMakerTexGenRMode::cfxGlPipelineSettingMakerTexGenRMode() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenRMode cfxGlPipelineSettingMakerTexGenRMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenRMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenRMode(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenQMode +cfxGlPipelineSettingMakerTexGenQMode::cfxGlPipelineSettingMakerTexGenQMode() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenQMode cfxGlPipelineSettingMakerTexGenQMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenQMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenQMode(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenSEyePlane +cfxGlPipelineSettingMakerTexGenSEyePlane::cfxGlPipelineSettingMakerTexGenSEyePlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenSEyePlane cfxGlPipelineSettingMakerTexGenSEyePlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenSEyePlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenSEyePlane(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenTEyePlane +cfxGlPipelineSettingMakerTexGenTEyePlane::cfxGlPipelineSettingMakerTexGenTEyePlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenTEyePlane cfxGlPipelineSettingMakerTexGenTEyePlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenTEyePlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenTEyePlane(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenREyePlane +cfxGlPipelineSettingMakerTexGenREyePlane::cfxGlPipelineSettingMakerTexGenREyePlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenREyePlane cfxGlPipelineSettingMakerTexGenREyePlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenREyePlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenREyePlane(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenQEyePlane +cfxGlPipelineSettingMakerTexGenQEyePlane::cfxGlPipelineSettingMakerTexGenQEyePlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenQEyePlane cfxGlPipelineSettingMakerTexGenQEyePlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenQEyePlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenQEyePlane(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenSObjectPlane +cfxGlPipelineSettingMakerTexGenSObjectPlane::cfxGlPipelineSettingMakerTexGenSObjectPlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenSObjectPlane cfxGlPipelineSettingMakerTexGenSObjectPlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenSObjectPlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenSObjectPlane(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenTObjectPlane +cfxGlPipelineSettingMakerTexGenTObjectPlane::cfxGlPipelineSettingMakerTexGenTObjectPlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenTObjectPlane cfxGlPipelineSettingMakerTexGenTObjectPlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenTObjectPlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenTObjectPlane(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenRObjectPlane +cfxGlPipelineSettingMakerTexGenRObjectPlane::cfxGlPipelineSettingMakerTexGenRObjectPlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenRObjectPlane cfxGlPipelineSettingMakerTexGenRObjectPlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenRObjectPlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenRObjectPlane(pass, ); + return setting; +} + + +// cfxGlPipelineSettingMakerTexGenQObjectPlane +cfxGlPipelineSettingMakerTexGenQObjectPlane::cfxGlPipelineSettingMakerTexGenQObjectPlane() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMakerTexGenQObjectPlane cfxGlPipelineSettingMakerTexGenQObjectPlane::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexGenQObjectPlane::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexGenQObjectPlane(pass, ); + return setting; +} + +#endif + + +#if 0 +// these are currently unimplemented due to time constraints +// all that needs to be done is actually pull the values out of +// the DOM and put them into the variables passed to the call to new + +// cfxGlPipelineSettingMakerTexture2D +cfxGlPipelineSettingMakerTexture2D::cfxGlPipelineSettingMakerTexture2D() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_TEXTURE2D, this)); +} + +cfxGlPipelineSettingMakerTexture2D cfxGlPipelineSettingMakerTexture2D::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexture2D::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxSampler* sampler; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexture2D(pass, index, sampler); + return setting; +} + + +// cfxGlPipelineSettingMakerTexture3D +cfxGlPipelineSettingMakerTexture3D::cfxGlPipelineSettingMakerTexture3D() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_TEXTURE3D, this)); +} + +cfxGlPipelineSettingMakerTexture3D cfxGlPipelineSettingMakerTexture3D::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTexture3D::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxSampler* sampler; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTexture3D(pass, index, sampler); + return setting; +} + + +// cfxGlPipelineSettingMakerTextureCubeMap +cfxGlPipelineSettingMakerTextureCubeMap::cfxGlPipelineSettingMakerTextureCubeMap() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_TEXTURECUBE, this)); +} + +cfxGlPipelineSettingMakerTextureCubeMap cfxGlPipelineSettingMakerTextureCubeMap::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTextureCubeMap::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxSampler* sampler; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTextureCubeMap(pass, index, sampler); + return setting; +} + + +// cfxGlPipelineSettingMakerTextureEnvColor +cfxGlPipelineSettingMakerTextureEnvColor::cfxGlPipelineSettingMakerTextureEnvColor() +{ + //mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_TEXTURE_ENV_COLOR, this)); +} + +cfxGlPipelineSettingMakerTextureEnvColor cfxGlPipelineSettingMakerTextureEnvColor::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTextureEnvColor::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + cfxFloat4 value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTextureEnvColor(pass, index, value); + return setting; +} + + +// cfxGlPipelineSettingMakerTextureEnvMode +cfxGlPipelineSettingMakerTextureEnvMode::cfxGlPipelineSettingMakerTextureEnvMode() +{ + //mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_TEXTURE_ENV_MODE, this)); +} + +cfxGlPipelineSettingMakerTextureEnvMode cfxGlPipelineSettingMakerTextureEnvMode::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerTextureEnvMode::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + int index; + int value; + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingTextureEnvMode(pass, index, value); + return setting; +} + +#endif + + +// ENABLE / DISABLE settings + + +// cfxGlPipelineSettingMakerAlphaTestEnable +cfxGlPipelineSettingMakerAlphaTestEnable::cfxGlPipelineSettingMakerAlphaTestEnable() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_ALPHA_TEST_ENABLE, this)); +} + +cfxGlPipelineSettingMakerAlphaTestEnable cfxGlPipelineSettingMakerAlphaTestEnable::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerAlphaTestEnable::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + bool value = settingInitializer->getAlpha_test_enable()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingAlphaTestEnable(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerBlendEnable +cfxGlPipelineSettingMakerBlendEnable::cfxGlPipelineSettingMakerBlendEnable() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_BLEND_ENABLE, this)); +} + +cfxGlPipelineSettingMakerBlendEnable cfxGlPipelineSettingMakerBlendEnable::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerBlendEnable::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + bool value = settingInitializer->getBlend_enable()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingBlendEnable(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerCullFaceEnable +cfxGlPipelineSettingMakerCullFaceEnable::cfxGlPipelineSettingMakerCullFaceEnable() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_CULL_FACE_ENABLE, this)); +} + +cfxGlPipelineSettingMakerCullFaceEnable cfxGlPipelineSettingMakerCullFaceEnable::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerCullFaceEnable::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + bool value = settingInitializer->getCull_face_enable()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingCullFaceEnable(pass, value); + return setting; +} + + +// cfxGlPipelineSettingMakerDepthTestEnable +cfxGlPipelineSettingMakerDepthTestEnable::cfxGlPipelineSettingMakerDepthTestEnable() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_DEPTH_TEST_ENABLE, this)); +} + +cfxGlPipelineSettingMakerDepthTestEnable cfxGlPipelineSettingMakerDepthTestEnable::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMakerDepthTestEnable::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + bool value = settingInitializer->getDepth_test_enable()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSettingDepthTestEnable(pass, value); + return setting; +} + + +#if 0 // template +// cfxGlPipelineSettingMaker +cfxGlPipelineSettingMaker::cfxGlPipelineSettingMaker() +{ + mapTypeNameToSettingMaker.insert(std::make_pair(COLLADA_ELEMENT_, this)); +} + +cfxGlPipelineSettingMaker cfxGlPipelineSettingMaker::maker; + +cfxGlPipelineSetting* cfxGlPipelineSettingMaker::makeSetting(cfxPass* pass, domGl_pipeline_settings* settingInitializer) +{ + bool value = settingInitializer->get_enable()->getValue(); + + cfxGlPipelineSetting* setting = new cfxGlPipelineSetting(pass, value); + return setting; +} +#endif + + + + diff --git a/1.4.0/fx/src/cfxGlSamplerSetting.cpp b/1.4.0/fx/src/cfxGlSamplerSetting.cpp new file mode 100644 index 0000000..f1f4c4e --- /dev/null +++ b/1.4.0/fx/src/cfxGlSamplerSetting.cpp @@ -0,0 +1,283 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +#include <stdlib.h> +#include <stdio.h> + +// !!!tsl request #defines for state names +//#ifndef _LIB +#include <Cg/cg.h> +//#else +//#include <cfxNoCg.h> +//#endif + +// User includes + +#include <cfxGlSamplerSetting.h> +#include <cfxEffect.h> +#include <cfxParam.h> + + +// cfxGlSamplerSetting +cfxGlSamplerSetting::cfxGlSamplerSetting(cfxEffect* effect, const char* stateName) +{ + state = cgGetNamedSamplerState(effect->getContext(), stateName); + if (state == 0) + { + printf("ERROR: Sampler state not found: %s\n", stateName); + } +} + +cfxGlSamplerSetting::~cfxGlSamplerSetting() +{ +} + + + +// cfxGlSamplerSettingWrapS +cfxGlSamplerSettingWrapS::cfxGlSamplerSettingWrapS(cfxEffect* effect, const char* stateName, int _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingWrapS::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetIntStateAssignment(assignment, value); + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingWrapS::getType() const +{ + return cfxGlSamplerSetting::WRAP_S; +} + +int cfxGlSamplerSettingWrapS::getValue() const +{ + return value; +} + +// cfxGlSamplerSettingWrapT +cfxGlSamplerSettingWrapT::cfxGlSamplerSettingWrapT(cfxEffect* effect, const char* stateName, int _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingWrapT::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetIntStateAssignment(assignment, value); + + return true; + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingWrapT::getType() const +{ + return cfxGlSamplerSetting::WRAP_T; +} + +int cfxGlSamplerSettingWrapT::getValue() const +{ + return value; +} + +// cfxGlSamplerSettingMinFilter +cfxGlSamplerSettingMinFilter::cfxGlSamplerSettingMinFilter(cfxEffect* effect, const char* stateName, int _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingMinFilter::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetIntStateAssignment(assignment, value); + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingMinFilter::getType() const +{ + return cfxGlSamplerSetting::MINFILTER; +} + +int cfxGlSamplerSettingMinFilter::getValue() const +{ + return value; +} + + +// cfxGlSamplerSettingMagFilter +cfxGlSamplerSettingMagFilter::cfxGlSamplerSettingMagFilter(cfxEffect* effect, const char* stateName, int _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingMagFilter::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetIntStateAssignment(assignment, value); + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingMagFilter::getType() const +{ + return cfxGlSamplerSetting::MAGFILTER; +} + +int cfxGlSamplerSettingMagFilter::getValue() const +{ + return value; +} + +// cfxGlSamplerSettingBorderColor +cfxGlSamplerSettingBorderColor::cfxGlSamplerSettingBorderColor(cfxEffect* effect, const char* stateName, cfxFloat4& _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingBorderColor::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetFloatArrayStateAssignment(assignment, &value.f0); + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingBorderColor::getType() const +{ + return cfxGlSamplerSetting::BORDER_COLOR; +} + +cfxFloat4 cfxGlSamplerSettingBorderColor::getValue() const +{ + return value; +} + +// cfxGlSamplerSettingGenerateMipMap +cfxGlSamplerSettingGenerateMipMap::cfxGlSamplerSettingGenerateMipMap(cfxEffect* effect, const char* stateName, cfxBool _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingGenerateMipMap::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetBoolStateAssignment(assignment, value); + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingGenerateMipMap::getType() const +{ + return cfxGlSamplerSetting::GENERATE_MIPMAP; +} + +cfxBool cfxGlSamplerSettingGenerateMipMap::getValue() const +{ + return value; +} + +// cfxGlSamplerSettingMaxMipLevel +cfxGlSamplerSettingMaxMipLevel::cfxGlSamplerSettingMaxMipLevel(cfxEffect* effect, const char* stateName, float _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingMaxMipLevel::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetFloatStateAssignment(assignment, value); + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingMaxMipLevel::getType() const +{ + return cfxGlSamplerSetting::BORDER_COLOR; +} + +float cfxGlSamplerSettingMaxMipLevel::getValue() const +{ + return value; +} + +// cfxGlSamplerSettingLodBias +cfxGlSamplerSettingLodBias::cfxGlSamplerSettingLodBias(cfxEffect* effect, const char* stateName, float _value) + : cfxGlSamplerSetting(effect, stateName), + value(_value) +{ +} + +cfxBool cfxGlSamplerSettingLodBias::apply(const cfxParam* param) +{ + cfxBool result = false; + + if (state) + { + assignment = cgCreateSamplerStateAssignment(param->getParameter(), state); + result = cgSetFloatStateAssignment(assignment, value); + } + + return result; +} + +cfxGlSamplerSetting::type_enum cfxGlSamplerSettingLodBias::getType() const +{ + return cfxGlSamplerSetting::BORDER_COLOR; +} + +float cfxGlSamplerSettingLodBias::getValue() const +{ + return value; +} + diff --git a/1.4.0/fx/src/cfxLoader.cpp b/1.4.0/fx/src/cfxLoader.cpp new file mode 100644 index 0000000..e073cd2 --- /dev/null +++ b/1.4.0/fx/src/cfxLoader.cpp @@ -0,0 +1,874 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +//#include <Cg/cg.h> +#include <cfxPlatform.h> + +// User includes + +#include <cfxLoader.h> +#include <cfxAnnotatable.h> +#include <cfxAnnotate.h> +#include <cfxBindParam.h> +#include <cfxCode.h> +#include <cfxConnectParam.h> +#include <cfxDataMaker.h> +#include <cfxEffect.h> +#include <cfxGlPipelineSetting.h> +#include <cfxGlPipelineSettingMaker.h> +#include <cfxMaterial.h> +#include <cfxNewParam.h> +#include <cfxParamable.h> +#include <cfxPass.h> +#include <cfxSetParam.h> +#include <cfxShader.h> +#include <cfxSurface.h> +#include <cfxTechnique.h> +#include <cfxError.h> +#include <cfxBinaryUtil.h> +#include <cfxTypes.h> + +#include <dae.h> + +#include <dom/domEffect.h> +#include <dom/domMaterial.h> +#include <dom/domTypes.h> +#include <dom/domProfile_CG.h> +#include <dom/domCg_surface_type.h> +#include <dom/domConstants.h> + +// the next section used to be in the header as private members of the class +// moved internal so external libraries don't need to deal with the dom stuff + +#include <dom/domFx_newparam_common.h> +#include <dom/domFx_annotate_common.h> + +#include <dom/domInstance_effect.h> + + + // for effects +// static void loadCodeArray(domFx_code_common_Array& codeArrayElement, cfxEffect* effect); + static void loadNewParamArray(domFx_newparam_common_Array& newParamArrayElement, cfxParamable* paramable, cfxEffect* effect); + static void loadNewParamArray(domCg_newparam_Array& newParamArrayElement, cfxParamable* paramable, cfxEffect* effect); + static void loadProfileArray(domFx_profile_abstract_Array& profileArrayElement, cfxEffect* effect); + static void loadAnnotateArray(domFx_annotate_common_Array& annotateArrayElement, cfxAnnotatable* annotatable, cfxEffect* effect); + + static bool hasCGProfile( domEffect *effect ); + + // for materials + static void loadSetParamArray(domInstance_effect::domSetparam_Array& setParamArrayElement, cfxParamable* paramable, cfxEffect* effect, cfxMaterial* material = NULL); + +// the previous section used to be in the header as private members of the class +// moved internal so external libraries don't need to deal with the dom stuff + + +std::string cfxLoader::platformString( DEFAULT_CG_PLATFORM ); + +//This function loads the binary file format for the material and effects libraries. +cfxBool cfxLoader::loadMaterialsAndEffectsFromBinFile(const std::string& file, std::map<std::string, cfxMaterial*>& materials, + std::map<std::string, cfxEffect*>& effects, CGcontext _context ) +{ + return cfxBinaryUtil::load( file, materials, effects, _context ); +} +cfxBool cfxLoader::saveBinFile(const std::string& file, const std::map<std::string, cfxMaterial*>& materials, + const std::map<std::string, cfxEffect*>& effects, cfxBool replace ) +{ + return cfxBinaryUtil::save( file, materials, effects, replace ); +} + +void cfxLoader::setBinaryLoadRemotePath( const std::string &path ) +{ + cfxBinaryUtil::setRemotePath( path ); +} + +void cfxLoader::setPlatformString( const std::string &platform ) +{ + platformString = platform; +} + +std::string &cfxLoader::getPlatformString() +{ + return platformString; +} + + // this routine will load the materials and effects from a COLLADA file and populate the maps + // it will resolve the references from materials to effects + // passing a NULL context will create a new context for this effect +cfxBool cfxLoader::loadMaterialsAndEffectsFromFile(const std::string& filename, std::map<std::string, cfxMaterial*>& materials, + std::map<std::string, cfxEffect*>& effects, CGcontext _context) +{ + // Instantiate the DAE object for the input file + + DAE *input = new DAE; + + // Load the COLLADA file + + cfxPrint("loading %s\n", filename.c_str()); + + cfxError error = input->load(filename.c_str()); + if (error != DAE_OK) + { + cfxPrint("load failed error: %s\n", daeErrorString(error)); + return false; + } + + cfxBool result = loadMaterialsAndEffects(input, materials, effects, _context); + + // delete input; + // DAE::cleanup(); + + return result; +} + + // this routine will load the materials and effects and populate the maps + // it will resolve the references from materials to effects + // passing a NULL context will create a new context for this effect +cfxBool cfxLoader::loadMaterialsAndEffects(DAE *colladaAsset, std::map<std::string, cfxMaterial*>& materials, + std::map<std::string, cfxEffect*>& effects, CGcontext _context) +{ + cfxBool resultEffects, resultMaterials; + resultEffects = loadEffects(colladaAsset, effects, _context); + + if (resultEffects) + { + resultMaterials = loadMaterials(colladaAsset, materials, &effects); + } + else + { + resultMaterials = loadMaterials(colladaAsset, materials, NULL); + } + + return (resultEffects && resultMaterials); +} + + // this routine will load the effects and populate the map + // passing a NULL context will create a new context for this effect +cfxBool cfxLoader::loadEffects(DAE *colladaAsset, std::map<std::string, cfxEffect*>& effects, CGcontext _context) +{ + // How many effect elements are there? + cfxUint effectElementCount = (cfxUint) colladaAsset->getDatabase()->getElementCount(NULL, COLLADA_ELEMENT_EFFECT); + cfxPrint("There are %d effect elements in this file\n", effectElementCount); + + if (effectElementCount > 0) + { + cgSetErrorCallback(cfxCgErrorCallback); + + if (_context == NULL) + { + _context = cgCreateContext(); + cgGLRegisterStates(_context); + } + } + + // Loop over all the effect elements + for(cfxUint currentEffect = 0; currentEffect < effectElementCount; currentEffect++) + { + // Get the next effect element + domEffect *effectElement; + // is the cast to daeElement** needed? tsl +// cfxError error = colladaAsset->getDatabase()->getElement((daeElement**)&effectElement,currentEffect, NULL, COLLADA_ELEMENT_EFFECT); + daeElement * element = 0; + cfxError error = colladaAsset->getDatabase()->getElement( &element,currentEffect, NULL, COLLADA_ELEMENT_EFFECT); + effectElement = (domEffect *) element; + // ERROR CHECK! !!!tsl i'm not sure this is the correct error check for this statement. + if (error != DAE_OK) + { + return false; + } + + // currently using managed textures to ensure that the texture objects are + // on the correct texture unit where the program expects them to be. +#ifndef _LIB + cgGLSetManageTextureParameters(_context, true); +#endif + + if( hasCGProfile( effectElement ) ) + { + + cfxPrint("Loading effect %d\n", currentEffect); + + cfxEffect* effect = new cfxEffect(effectElement->getId(), _context); + + // load all the parts at the effect scope + // <asset> + // <annotate> + // <import> + // <image> + // <newparam> + // <profile_*> + loadAnnotateArray(effectElement->getAnnotate_array(), effect, effect); + loadNewParamArray(effectElement->getNewparam_array(), effect, effect); + loadProfileArray(effectElement->getFx_profile_abstract_array(), effect); +#ifndef _LIB + effect->apply(); +#endif + + effects.insert(std::make_pair(effect->getName(), effect)); + + } + else + { + // An effect with no profiles creates an effect with a name but a zero effect pointers + // this can cause crashes later. + cfxPrint("*** Effect %d with id %s has NO CG profile, this may cause crashes if the effect is used\n",currentEffect, effectElement->getId()); + } + } + + return true; +} + + // this routine will load the materials and populate the material map + // if an effects map is provided it will resolve the references from materials to effects +cfxBool cfxLoader::loadMaterials(DAE *colladaAsset, std::map<std::string, cfxMaterial*>& materials, + const std::map<std::string, cfxEffect*>* effects) +{ + // How many material elements are there? + cfxUint materialElementCount = (cfxUint) colladaAsset->getDatabase()->getElementCount(NULL, COLLADA_ELEMENT_MATERIAL); + + cfxPrint("There are %d material elements in this file\n", materialElementCount); + + // Loop over all the material elements + for(cfxUint currentMaterial = 0; currentMaterial < materialElementCount; currentMaterial++) + { + // Get the next material element + domMaterial *materialElement; + // is the cast to daeElement** needed? tsl +// cfxError error = colladaAsset->getDatabase()->getElement((daeElement**)&materialElement,currentMaterial, NULL, COLLADA_ELEMENT_MATERIAL); + daeElement * element = 0; + cfxError error = colladaAsset->getDatabase()->getElement(&element,currentMaterial, NULL, COLLADA_ELEMENT_MATERIAL); + materialElement = (domMaterial*) element; + // ERROR CHECK! !!!tsl i'm not sure this is the correct error check for this statement. + if (error != DAE_OK) + { + return false; + } + + domInstance_effect* instanceEffectElement = materialElement->getInstance_effect(); + + if ( !instanceEffectElement ) + continue; + + std::string effectId = instanceEffectElement->getUrl().getID(); + + cfxEffect* effect = NULL; + + if (effects) + { + std::map<std::string, cfxEffect*>::const_iterator effectFinder = effects->find(effectId); + if (effectFinder != effects->end()) + { + effect = effectFinder->second; + } + } + + // skip this one if empty + if ( !effect ) + continue; + + cfxMaterial* material = new cfxMaterial(materialElement->getId(), effectId, effect); + + cfxPrint("Created material %p name %s effect %s %p\n", material, materialElement->getName(), effectId.c_str(), effect); + + // now extract the setparams + loadSetParamArray(instanceEffectElement->getSetparam_array(), material, effect, material); + + materials.insert(std::make_pair(material->getName(), material)); + + } + + return true; +} + + + +cfxBool cfxLoader::loadFile(const std::string& file, std::vector<cfxEffect*>& effects, CGcontext _context) +{ + + // Instantiate the DAE object for the input file + + DAE *input = new DAE; + + int error; + + // Load the COLLADA file + + cfxPrint("loading %s\n", file.c_str()); + + error = input->load(file.c_str()); + if (error != DAE_OK) + { + //cerr<<"load failed "<<daeErrorString(error)<<"\n"; + return false; + } + + // How many effect elements are there? + + unsigned int effectElementCount = input->getDatabase()->getElementCount(NULL, COLLADA_ELEMENT_EFFECT); + + cfxPrint("There are %d effect elements in this file\n", effectElementCount); + + if (effectElementCount > 0) + { + cgSetErrorCallback(cfxCgErrorCallback); + + if (_context == NULL) + { + _context = cgCreateContext(); + cgGLRegisterStates(_context); + } + } + // Loop over all the effect elements + + for(unsigned int currentEffect = 0; currentEffect < effectElementCount; currentEffect++) + { + // Get the next effect element + domEffect *effectElement; + // is the cast to daeElement** needed? tsl +// error = input->getDatabase()->getElement((daeElement**)&effectElement,currentEffect, NULL, COLLADA_ELEMENT_EFFECT); + daeElement * element = 0; + error = input->getDatabase()->getElement(&element,currentEffect, NULL, COLLADA_ELEMENT_EFFECT); + effectElement = (domEffect*) element; + // ERROR CHECK! !!!tsl i'm not sure this is the correct error check for this statement. + if (error != DAE_OK) + { + return false; + } + + // currently using managed textures to ensure that the texture objects are + // on the correct texture unit where the program expects them to be. + cgGLSetManageTextureParameters(_context, true); + + unsigned int profileCount = (unsigned int) effectElement->getFx_profile_abstract_array().getCount(); + cfxPrint("effect %d with id %s has %d profiles\n", currentEffect, effectElement->getId(), profileCount); + if (profileCount > 0) + { + + cfxPrint("Loading effect %d\n", currentEffect); + + cfxEffect* effect = new cfxEffect(effectElement->getId(), _context); + + // load all the parts at the effect scope + // <asset> + // <annotate> + // <import> + // <image> + // <newparam> + // <profile_*> + loadAnnotateArray(effectElement->getAnnotate_array(), effect, effect); + loadNewParamArray(effectElement->getNewparam_array(), effect, effect); + loadProfileArray(effectElement->getFx_profile_abstract_array(), effect); + + cfxPrint("Done creating effect\n"); + + effects.push_back(effect); + +#ifndef _LIB + effect->apply(); +#endif + } + } + + cfxPrint("Done resolving effect\n"); + + // delete input; + // DAE::cleanup(); + + return true; +} + + + +void loadAnnotateArray(domFx_annotate_common_Array& annotateArrayElement, cfxAnnotatable* annotatable, cfxEffect* effect) +{ + // utilize annotatable class to create and push annotate into list + cfxUint annotateCount = (cfxUint) annotateArrayElement.getCount(); + + // loop over the annotate blocks + for (cfxUint currentAnnotate = 0; currentAnnotate < annotateCount; currentAnnotate++) + { + // this element has a name and the data as child elements + domFx_annotate_common* annotateElement = annotateArrayElement.get(currentAnnotate); + + // then use the element which holds the actual values to make the data + cfxData* annotateData = cfxDataMaker::makeDataForAnnotate(annotateElement->getFx_annotate_type_common(), effect); + + // make the annotate and push it into the array where it belongs + annotatable->pushAnnotate(new cfxAnnotate(annotateData, std::string(annotateElement->getName()))); + } + +} + + +/* + void cfxLoader::loadCodeArray(domFx_code_common_Array& codeArrayElement, cfxEffect* effect) + { + // code in the effect elements may be used by one or more techniques + int codeCount = codeArrayElement.getCount(); + // loop over the code blocks + for (int currentCode = 0; currentCode < codeCount; currentCode++) + { + domFx_code_common* codeElement = codeArrayElement.get(currentCode); + // since we can't compile, perhaps value is not the right field... I think we want a file pointer to the fpo or vbo. + cfxCode* code = new cfxCode(effect, codeElement->getSid(), codeElement->getProfile(), codeElement->getValue()); + effect->pushCode(code); + } + + } +*/ + + +namespace { + domFx_surface_init_from_common_Array* getInitFromArray(domFx_surface_common_complexType* surface) { + if (surface && surface->getFx_surface_init_common()) + return &surface->getFx_surface_init_common()->getInit_from_array(); + return NULL; + } +} + + +void loadNewParamArray(domFx_newparam_common_Array& newParamArrayElement, cfxParamable* paramable, cfxEffect* effect) +{ + + // the newParam array contains parameters that are not in the shader code + cfxUint newParamCount = (cfxUint) newParamArrayElement.getCount(); + + // loop over the <newparam> objects, looking for <surface> params to extract. + for (cfxUint currentNewParam = 0; currentNewParam < newParamCount; currentNewParam++) + { + domFx_newparam_common* newParamElement = newParamArrayElement.get(currentNewParam); + + domFx_basic_type_common* paramInitializer = newParamElement->getFx_basic_type_common(); + std::string name = paramInitializer->getContents().get(0)->getTypeName(); + + if(name == "fx_surface_common") + { + std::string init_from; + domFx_surface_init_from_common_Array* initFromArray = getInitFromArray(paramInitializer->getSurface()); + if (initFromArray && initFromArray->getCount() > 0) + init_from = initFromArray->get(0)->getValue().get(0).getID(); + cfxSurface* surface = new cfxSurface( + init_from, + paramInitializer->getSurface()->getFormat()->getValue() + ); + effect->addNamedSurface(newParamElement->getSid(), surface); + } + else + { + // then use the element which holds the actual values to make the data + cfxData* newParamData = cfxDataMaker::makeDataForParam(paramInitializer, effect); + + if (newParamData) + { + //cfxPrint("Creating new param: %s\n", newParamElement->getSid()); + + // make the parameter and set the data in the param + std::string newParamSemantic; + if (newParamElement->getSemantic()) + { + newParamSemantic = std::string(newParamElement->getSemantic()->getValue()); + } + + cfxNewParam* newParam = new cfxNewParam(newParamData, std::string(newParamElement->getSid()), effect, newParamSemantic); + + // load the param's annotations + loadAnnotateArray(newParamElement->getAnnotate_array(), newParam, effect); + + paramable->pushParam(newParam); + } + else + { + cfxPrint("Not creating new param because data was not made successfully: %s\n", newParamElement->getSid()); + } + + } + } + +} + + + +void loadNewParamArray(domCg_newparam_Array& newParamArrayElement, cfxParamable* paramable, cfxEffect* effect) +{ + // the newParam array contains parameters that are not in the shader code + cfxUint newParamCount = (cfxUint) newParamArrayElement.getCount(); + + // loop over the <newparam> objects, looking for <surface> params to extract. + for (cfxUint currentNewParam = 0; currentNewParam < newParamCount; currentNewParam++) + { + domCg_newparam* newParamElement = newParamArrayElement.get(currentNewParam); + + domCg_param_type* paramInitializer = newParamElement->getCg_param_type(); + + if ( !paramInitializer ) + continue; + std::string name = paramInitializer->getContents().get(0)->getTypeName(); + + //cfxPrint("newparam %d of %d, named %s\n", currentNewParam, newParamCount, name.c_str()); + + if(name == "cg_surface_type") + { + std::string init_from; + domFx_surface_init_from_common_Array* initFromArray = getInitFromArray(paramInitializer->getSurface()); + if (initFromArray && initFromArray->getCount() > 0) + init_from = initFromArray->get(0)->getValue().get(0).getID(); + cfxSurface* surface = new cfxSurface( + init_from, + paramInitializer->getSurface()->getFormat()->getValue() + ); + effect->addNamedSurface(newParamElement->getSid(), surface); + } + else + { + // then use the element which holds the actual values to make the data + cfxData* newParamData = cfxDataMaker::makeDataForParam(paramInitializer, effect); + + if (newParamData) + { + //cfxPrint("Creating new param: %s\n", newParamElement->getSid()); + + // make the parameter and set the data in the param + std::string newParamSemantic; + if (newParamElement->getSemantic()) + { + newParamSemantic = std::string(newParamElement->getSemantic()->getValue()); + } + + cfxNewParam* newParam = new cfxNewParam(newParamData, std::string(newParamElement->getSid()), effect, newParamSemantic); + + // load the param's annotations + loadAnnotateArray(newParamElement->getAnnotate_array(), newParam, effect); + + paramable->pushParam(newParam); + } + else + { + cfxPrint("Not creating new param because data was not made successfully: %s\n", newParamElement->getSid()); + } + } + } + +} + + +void loadSetParamArray(domInstance_effect::domSetparam_Array& setParamArrayElement, cfxParamable* paramable, cfxEffect* effect, cfxMaterial* material) +{ + // these parameters don't need to be created + // they should exist already from shader code or newparam elements + cfxUint setParamCount = (cfxUint) setParamArrayElement.getCount(); + // loop over the set params + for (cfxUint currentSetParam = 0; currentSetParam < setParamCount; currentSetParam++) + { + domInstance_effect::domSetparam* setParamElement = setParamArrayElement.get(currentSetParam); + + domFx_basic_type_common* paramInitializer = setParamElement->getFx_basic_type_common(); + + if ( !paramInitializer ) + continue; + + std::string name = paramInitializer->getContents().get(0)->getTypeName(); + + if(name == "fx_surface_common") + { + std::string init_from; + domFx_surface_init_from_common_Array* initFromArray = getInitFromArray(paramInitializer->getSurface()); + + if (initFromArray && initFromArray->getCount() > 0) + init_from = initFromArray->get(0)->getValue().get(0).getID(); + // lookup surface by name + cfxSurface* surface = effect->getSurfaceByName(setParamElement->getRef()); + cfxSurface* newSurface = new cfxSurface( + init_from, + paramInitializer->getSurface()->getFormat()->getValue(), + surface + ); + material->addSurface(newSurface); + cfxPrint("Material surface with parent: %s %p\n", init_from.c_str(), surface); + } + else + { + // then use the element which holds the actual values to make the data + cfxData* setParamData = cfxDataMaker::makeDataForParam(setParamElement->getFx_basic_type_common(), effect); + + // make the parameter and set the data in the param + cfxSetParam* setParam = new cfxSetParam(setParamData, setParamElement->getRef(), effect); + + paramable->pushParam(setParam); + } + } + +} + + +void pushTechniqueInclude(cfxTechnique* technique, const char* includeSid, xsAnyURI &uri) +{ + char pathBuffer[1024]; + cfxBool pathOK = uri.getPath(pathBuffer, 1024); + if (pathOK && includeSid) + { + technique->pushInclude(includeSid, pathBuffer); + } + else + { + cfxPrint("ERROR: problem with path, probably too long, include not being added\n"); + } +} + + +void loadProfileArray(domFx_profile_abstract_Array& profileArrayElement, cfxEffect* effect) +{ + // at least one supported profile is needed for the effect to do anything + cfxUint profileCount = (cfxUint) profileArrayElement.getCount(); + + cfxPrint("found %d profiles\n", profileCount); + + // loop over the profiles + for (cfxUint currentProfile = 0; currentProfile < profileCount; currentProfile++) + { + domFx_profile_abstract* profileElement = profileArrayElement.get(currentProfile); + daeString profileName = profileElement->getTypeName(); + + cfxPrint("profile %d named %s\n", currentProfile, profileName); + + // cg profile support + if (strcmp(profileName, COLLADA_ELEMENT_PROFILE_CG) == 0) + { + // take the abstract profile and cast it to cg + // building with exceptions turned off so no rtti + // domProfile_CG* cgProfileElement = dynamic_cast<domProfile_CG*>(abstractProfileElement); + domProfile_CG* cgProfileElement = static_cast<domProfile_CG*>(profileElement); + + daeString platformName = cgProfileElement->getPlatform(); + cfxPrint("loadProfileArray(): platform %s\n", platformName); + + // Check if this is the platform we are interested in + if (strcmp(platformName, cfxLoader::getPlatformString().c_str() ) == 0) + { + // !!!tsl tweaked parameters go into materials, so a whole thing needs to be added for proper support + // also, this adds newparam's to the effect, they should probably be added to the technique instead + cfxPrint("loadProfileArray():load newparams\n"); + loadNewParamArray(cgProfileElement->getNewparam_array(), effect, effect); + + cfxPrint("loadProfileArray():load technique\n"); + + // create and populate a cfxTechnique for every technique in the cg profile + cfxUint techniqueCount = (cfxUint) cgProfileElement->getTechnique_array().getCount(); + // loop over the techniques + for (cfxUint currentTechnique = 0; currentTechnique < techniqueCount; currentTechnique++) + { + domProfile_CG::domTechnique* techniqueElement = cgProfileElement->getTechnique_array().get(currentTechnique); + + // !!!tsl this should be updated to not check for null once sid is made a require attr in the schema + const char* techniqueSid = techniqueElement->getSid(); + + cfxPrint("technique %d\n", currentTechnique); + + // create a cfxTechnique for every technique inside the cg profile + cfxTechnique* technique = new cfxTechnique(effect, techniqueSid ? techniqueSid : ""); + + // we don't do anything with code, mostly because we can't compile cg on ceb yet... + + // includes are used to pair the name of the shader with its actual file name and path + // currently profile and technique are kind of rolled into one with cfxTechnique + // all the includes from both of these will be pushed onto each technique + // this is redundant and probably not the best representation + // it used to be fine when profile was inside technique but now this is reversed and is less appropriate + + cfxUint includeCount = 0; + + // loop over the includes for the profile and push them onto the technique + domFx_include_common_Array &profileIncludeArrayElem = cgProfileElement->getInclude_array(); + includeCount = (cfxUint) profileIncludeArrayElem.getCount(); + cfxPrint(".......profile..includeCount %d\n", includeCount); + for (cfxUint currentInclude = 0; currentInclude < includeCount; currentInclude++) + { + domFx_include_common* includeElement = profileIncludeArrayElem.get(currentInclude); + pushTechniqueInclude(technique, includeElement->getSid(), includeElement->getUrl()); + } + + // loop over the includes for the technique and push them onto the technique + domFx_include_common_Array &techniqueIncludeArrayElem = techniqueElement->getInclude_array(); + includeCount = (cfxUint) techniqueIncludeArrayElem.getCount(); + cfxPrint("........technique.includeCount %d\n", includeCount); + for (cfxUint currentInclude = 0; currentInclude < includeCount; currentInclude++) + { + domFx_include_common* includeElement = techniqueIncludeArrayElem.get(currentInclude); + pushTechniqueInclude(technique, includeElement->getSid(), includeElement->getUrl()); + } + + + // beware, profile and technique params are cg_params + // these have way more type options and are currently unsupported + // all newparams currently must be in effect + // setparams are only valid on cg types, so their current implementation is useless until those types are added + + +#if 0 // <surface> removed from <profile> and <technique> - now a <newparam> type + // surfaces and images, currently only supporting surfaces IF it uses an image + // all surfaces end up in the technique right now + pushTechniqueSurfaces(cgProfileElement->getSurface_array(), technique); + pushTechniqueSurfaces(techniqueElement->getSurface_array(), technique); +#endif + + + // pass itself is ENORMOUS. + domProfile_CG::domTechnique::domPass_Array& passArrayElement = techniqueElement->getPass_array(); + // at least one pass is needed for the technique to do anything + cfxUint passCount = (cfxUint) passArrayElement.getCount(); + // loop over the passes + for (cfxUint currentPass = 0; currentPass < passCount; currentPass++) + { + cfxPrint("Here is a pass!\n"); + + domProfile_CG::domTechnique::domPass* passElement = passArrayElement.get(currentPass); + + // This should be a name, is Sid OK? + cfxPass* pass = new cfxPass(technique, std::string(passElement->getSid())); + + // why is this not an array? it should be. + // passElement->elemAnnotate + // should be + // loadAnnotateArray(passElement->getAnnotate_array(), setParam); + + + // what is the meaning of these targets + // passElement->elemColortarget_array + // passElement->elemDepthstenciltarget_array + // passElement->elemClearcolor_array + // passElement->elemCleardepth_array + // passElement->elemClearstencil_array + + // now for drawing... that isn't cgfx... does it fit here??? + // passElement->elemDraw_array + + // handle the gl pipeline settings + domGl_pipeline_settings_Array& glPipeSettingsArrayElement = passElement->getGl_pipeline_settings_array(); + cfxUint glPipeSettingsCount = (cfxUint) glPipeSettingsArrayElement.getCount(); + // loop over the gl pipeline settings + for (cfxUint currentGlPipeSettings = 0; currentGlPipeSettings < glPipeSettingsCount; currentGlPipeSettings++) + { + domGl_pipeline_settings* glPipeSettingElement = glPipeSettingsArrayElement.get(currentGlPipeSettings); + + cfxGlPipelineSetting* setting = cfxGlPipelineSettingMaker::makeGlPipelineSetting(pass, glPipeSettingElement); + pass->pushSetting(setting); + + // use the meta again to get the class name + // this definitely will be another map lookup to find another maker + // just like data i think... only they can apply their own settings. + + } + + // more cg setparams... where do these get applied??? + // passElement->elemSetParam_array + + // now the shaders + domProfile_CG::domTechnique::domPass::domShader_Array& shaderArrayElement = passElement->getShader_array(); + + // at least one shader is needed for the pass to do anything + cfxUint shaderCount = (cfxUint) shaderArrayElement.getCount(); + // loop over the shaders + for (cfxUint currentShader = 0; currentShader < shaderCount; currentShader++) + { + domProfile_CG::domTechnique::domPass::domShader* shaderElement = shaderArrayElement.get(currentShader); + + domCg_pipeline_stage stage = shaderElement->getStage(); + + cfxShader* shader = NULL; + + // use source (attrib of name) to match the include, may need to check for NULL + if (stage == CG_PIPELINE_STAGE_VERTEX) + { +#ifndef _LIB + shader = new cfxShader(pass, std::string(shaderElement->getName()->getSource()), + std::string(shaderElement->getName()->getValue()), cgGLGetLatestProfile(CG_GL_VERTEX), cfxShader::VERTEX); +#else + shader = new cfxShader(pass, std::string(shaderElement->getName()->getSource()), + std::string(shaderElement->getName()->getValue()), CG_PROFILE_UNKNOWN, cfxShader::VERTEX); +#endif + } + + else //if (stage == CG_PIPELINE_STAGE_FRAGMENT) + { +#ifndef _LIB + shader = new cfxShader(pass, std::string(shaderElement->getName()->getSource()), + std::string(shaderElement->getName()->getValue()), cgGLGetLatestProfile(CG_GL_FRAGMENT), cfxShader::FRAGMENT); +#else + shader = new cfxShader(pass, std::string(shaderElement->getName()->getSource()), + std::string(shaderElement->getName()->getValue()), CG_PROFILE_UNKNOWN, cfxShader::FRAGMENT); +#endif + } + + // load the shader's annotations + loadAnnotateArray(shaderElement->getAnnotate_array(), shader, effect); + + + // load the shader's parameters + domProfile_CG::domTechnique::domPass::domShader::domBind_Array& bindArrayElement = shaderElement->getBind_array(); + + cfxUint bindCount = (cfxUint) bindArrayElement.getCount(); + // loop over the bindings + for (cfxUint currentBind = 0; currentBind < bindCount; currentBind++) + { + domProfile_CG::domTechnique::domPass::domShader::domBind* bindElement = bindArrayElement.get(currentBind); + cfxParam* param; + + // choose whether bind to param or value based on contents + daeElement* content = bindElement->getContents().get(0); + std::string dataTypeName = std::string(content->getTypeName()); + + if (dataTypeName == std::string(COLLADA_ELEMENT_PARAM)) + { + param = new cfxConnectParam(bindElement->getSymbol(), shader, bindElement->getParam()->getRef()); + //cfxPrint("param = %x\n", param); + } + else + { + // !!!tsl still have to add support for building data from all the cg types + cfxData* data = NULL; //cfxDataMaker::makeDataForParam(bindElement->getCg_param_type(), effect); + param = new cfxBindParam(bindElement->getSymbol(), shader, data); + } + + shader->pushParam(param); + } + + pass->pushShader(shader); + } + technique->pushPass(pass); + } + effect->pushTechnique(technique); + + } + } + } + } + +} + +bool hasCGProfile( domEffect *effect ) +{ + cfxUint profileCount = (cfxUint) effect->getFx_profile_abstract_array().getCount(); + + // loop over the profiles + for (cfxUint currentProfile = 0; currentProfile < profileCount; currentProfile++) + { + domFx_profile_abstract* profileElement = effect->getFx_profile_abstract_array().get(currentProfile); + daeString profileName = profileElement->getTypeName(); + + // cg profile support + if (strcmp(profileName, COLLADA_ELEMENT_PROFILE_CG) == 0) + { + return true; + } + } + return false; +} + diff --git a/1.4.0/fx/src/cfxMaterial.cpp b/1.4.0/fx/src/cfxMaterial.cpp new file mode 100644 index 0000000..2c4a7ad --- /dev/null +++ b/1.4.0/fx/src/cfxMaterial.cpp @@ -0,0 +1,152 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdlib.h> +#include <assert.h> +#include <stdio.h> + +// User includes + +#include <cfxMaterial.h> +#include <cfxEffect.h> +#include <cfxParam.h> +#include <cfxSetParam.h> +#include <cfxSurface.h> +#include <cfxPlatform.h> +#include <cfxData.h> + + +// cfxMaterial +cfxMaterial::cfxMaterial(const std::string& _name, const std::string& _effectName, + cfxEffect* _effect) + : name(_name), + effectName(_effectName), + effect(_effect) +{ +} +cfxMaterial::~cfxMaterial() +{ + for (size_t i=0; i< surfaces.size(); i++) + { + delete surfaces[i]; + } + surfaces.clear(); + + for ( size_t i = 0; i < paramArray.size(); ++i ) + { + cfxSetParam* item = (cfxSetParam*)paramArray[i]; + delete item->getData(); + delete paramArray[i]; + } + paramArray.clear(); +} + +const std::string& cfxMaterial::getName() const +{ + return name; +} + +cfxEffect* cfxMaterial::getEffect() const +{ + return effect; +} + +bool cfxMaterial::setParameterValues() +{ + if (effect) + { + std::vector<cfxParam*>::iterator paramIter = paramArray.begin(); + while (paramIter != paramArray.end()) + { + (*paramIter)->apply(); + paramIter++; + } + std::vector<cfxSurface*>::iterator surfaceIter = surfaces.begin(); + while (surfaceIter != surfaces.end()) + { + (*surfaceIter)->apply(); + surfaceIter++; + } + return true; + } + else + { + cfxPrint("Can not setParameterValues with NULL effect for material %s effect %s\n", name.c_str(), effectName.c_str()); + return false; + } +} + + +void cfxMaterial::setEffectPassState(unsigned int techniqueIndex, unsigned int passIndex) +{ + if (effect) + { + effect->setPassState(techniqueIndex, passIndex); + } + else + { + cfxPrint("Can not setPassState with NULL effect for material %s effect %s\n", name.c_str(), effectName.c_str()); + } +} + + +void cfxMaterial::resetEffectPassState(unsigned int techniqueIndex, unsigned int passIndex) +{ + if (effect) + { + effect->resetPassState(techniqueIndex, passIndex); + } + else + { + cfxPrint("Can not resetPassState with NULL effect for material %s effect %s\n", name.c_str(), effectName.c_str()); + } +} + + +unsigned int cfxMaterial::getEffectTechniqueCount() +{ + if (effect) + { + return effect->getTechniqueCount(); + } + else + { + cfxPrint("Can not getEffectTechniqueCount with NULL effect for material %s effect %s\n", name.c_str(), effectName.c_str()); + return 0; + } +} + + +unsigned int cfxMaterial::getEffectPassCount(unsigned int techniqueIndex) +{ + if (effect) + { + return effect->getPassCount(techniqueIndex); + } + else + { + cfxPrint("Can not getEffectPassCount with NULL effect for material %s effect %s\n", name.c_str(), effectName.c_str()); + return 0; + } +} + +const std::string &cfxMaterial::getEffectName() const +{ + return effectName; +} + +void cfxMaterial::addSurface(cfxSurface* surface) +{ + surfaces.push_back(surface); +} + +const std::vector<cfxSurface*> &cfxMaterial::getSurfaces() const +{ + return surfaces; +} diff --git a/1.4.0/fx/src/cfxNewParam.cpp b/1.4.0/fx/src/cfxNewParam.cpp new file mode 100644 index 0000000..7c2711f --- /dev/null +++ b/1.4.0/fx/src/cfxNewParam.cpp @@ -0,0 +1,90 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes +#include <cfxPlatform.h> +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +// User includes + +#include <cfxNewParam.h> +#include <cfxData.h> +#include <cfxEffect.h> +#include <cfxAnnotate.h> +#include <cfxEffect.h> +#include <cfxPlatform.h> + +// cfxNewparam +cfxNewParam::cfxNewParam(cfxData* _data, const std::string& _name, cfxEffect* _effect, + const std::string& _semantic) + : cfxParam(_name), + effect(_effect), + data(_data), + semantic(_semantic) +{ + // ideally, data should always exist, but if the type isn't supported yet, it might be handy not to segfault + if (data) + { + parameter = cgCreateEffectParameter(effect->getEffect(), name.c_str(), data->getType()); + } + + // this is temporary until cg api gets upgraded to set effect parameter names + effect->addNamedParameter(name, parameter); + + cfxPrint("New param %s %p\n", name.c_str(), parameter); + + if (!semantic.empty()) + { + // !!!tsl whoa, this is unimplemented too?! + cgSetParameterSemantic(parameter, semantic.c_str()); + // this is temporary until cg api gets upgraded to set parameter semantics + effect->addSemanticParameter(semantic, parameter); + } + + +} + +bool cfxNewParam::apply() +{ + std::vector<cfxAnnotate*>::iterator annotateIter = annotateArray.begin(); + while (annotateIter != annotateArray.end()) + { + (*annotateIter)->apply(this); + annotateIter++; + } + + //cfxPrint("setting the data for parameter: %s\n", name.c_str()); + // ideally, data should always exist, but if the type isn't supported yet, it might be handy not to segfault + if (data) + { + data->apply(this); + } + + return true; +} + +bool cfxNewParam::validate() const +{ + return true; +} + +cfxParam::cfxParamTypeEnum cfxNewParam::getType() const +{ + return cfxParam::CFXNEWPARAM; +} + +const std::string &cfxNewParam::getSemantic() const +{ + return semantic; +} + +const cfxData *cfxNewParam::getData() const +{ + return data; +} diff --git a/1.4.0/fx/src/cfxParam.cpp b/1.4.0/fx/src/cfxParam.cpp new file mode 100644 index 0000000..6705768 --- /dev/null +++ b/1.4.0/fx/src/cfxParam.cpp @@ -0,0 +1,38 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> + +// User includes + +#include <cfxParam.h> + + +// cfxParam +cfxParam::cfxParam(const std::string& _name) + : name(_name) +{ +} + +cfxParam::~cfxParam() +{ +} + +CGparameter cfxParam::getParameter() const +{ + return parameter; +} + +const std::string &cfxParam::getName() const +{ + return name; +} + + + diff --git a/1.4.0/fx/src/cfxParamable.cpp b/1.4.0/fx/src/cfxParamable.cpp new file mode 100644 index 0000000..528e8e9 --- /dev/null +++ b/1.4.0/fx/src/cfxParamable.cpp @@ -0,0 +1,30 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// User includes + +#include <cfxParamable.h> + + +// cfxParamable +cfxParamable::cfxParamable() +{ +} + +cfxParamable::~cfxParamable() +{ +} + +void cfxParamable::pushParam(cfxParam* param) +{ + paramArray.push_back(param); +} + +const std::vector<cfxParam*> &cfxParamable::getParamArray() const +{ + return paramArray; +} diff --git a/1.4.0/fx/src/cfxPass.cpp b/1.4.0/fx/src/cfxPass.cpp new file mode 100644 index 0000000..f22a195 --- /dev/null +++ b/1.4.0/fx/src/cfxPass.cpp @@ -0,0 +1,104 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +// User includes + +#include <cfxPass.h> +#include <cfxAnnotate.h> +#include <cfxShader.h> +#include <cfxTechnique.h> +#include <cfxGlPipelineSetting.h> + + +// cfxPass +cfxPass::cfxPass(cfxTechnique* _technique, const std::string& _name) + : technique(_technique), + name(_name) +{ + pass = cgCreatePass(technique->getTechnique(), name.c_str()); +} +cfxPass::~cfxPass() +{ + while (!settingArray.empty()) + { + delete(settingArray[0]); + settingArray.erase(settingArray.begin()); + } + + while (!shaderArray.empty()) + { + delete(shaderArray[0]); + shaderArray.erase(shaderArray.begin()); + } + +} +bool cfxPass::apply() +{ + std::vector<cfxGlPipelineSetting*>::iterator settingIter = settingArray.begin(); + while (settingIter != settingArray.end()) + { + (*settingIter)->apply(); + settingIter++; + } + + std::vector<cfxShader*>::iterator shaderIter = shaderArray.begin(); + while (shaderIter != shaderArray.end()) + { + (*shaderIter)->apply(); + shaderIter++; + } + + return true; +} + +bool cfxPass::validate() const +{ + return true; +} + +void cfxPass::pushSetting(cfxGlPipelineSetting* setting) +{ + settingArray.push_back(setting); + printf("setting pushed onto pass\n"); +} + +void cfxPass::pushShader(cfxShader* shader) +{ + shaderArray.push_back(shader); + printf("shader pushed onto pass\n"); +} + +cfxTechnique* cfxPass::getTechnique() const +{ + return technique; +} + +CGpass cfxPass::getPass() const +{ + return pass; +} + +const std::string &cfxPass::getName() const +{ + return name; +} + +const std::vector<cfxGlPipelineSetting*> &cfxPass::getSettingArray() const +{ + return settingArray; +} + +const std::vector<cfxShader*> &cfxPass::getShaderArray() const +{ + return shaderArray; +} diff --git a/1.4.0/fx/src/cfxSampler.cpp b/1.4.0/fx/src/cfxSampler.cpp new file mode 100644 index 0000000..f97e31e --- /dev/null +++ b/1.4.0/fx/src/cfxSampler.cpp @@ -0,0 +1,137 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> + +// User includes + +#include <cfxSampler.h> +#include <cfxEffect.h> +#include <cfxParam.h> +#include <cfxSurface.h> +#include <cfxGlSamplerSetting.h> +#include <cfxPlatform.h> + +// cfxSampler +cfxSampler::cfxSampler(const std::string& _source, cfxEffect* _effect) + : source(_source), + textureId(0), + effect(_effect), + surface(NULL), + generateMipmaps(true) +{ +} + +cfxSampler::~cfxSampler() +{ + while (!settingArray.empty()) + { + delete(settingArray[0]); + settingArray.erase(settingArray.begin()); + } +} + +bool cfxSampler::apply(cfxParam* param) +{ + // lookup source for the matching surface; + if (surface == NULL) + { + surface = effect->getSurfaceByName(source); + + // only go through this if the surface is newly initialized + // this will update the textureId + // bind the texture and initialize the sampler states + // generate mipmaps if needed + if (surface) + { + surface->addReferencingParam(param); + + const std::string surfaceSource = surface->getInitFrom(); + //cfxPrint("Found surface init from %p %s\n", surface, surfaceSource.c_str()); + + // get the texture object from the surface that is its source, or if that can't be found + // just try using texture 1 as the default which is definitely not the solution but may + // be interesting until this feature is fully supported + + // the mechanism to pair a texture with a surface for use by a parameter is in place. + // the support for loading textures, as would probably be done by the surface is out + // of the scope of this library. this is something that needs to exist + // in a lower layer that can do resource management. this is something that + // needs to exist in a layer that allows this other aspect of resource management. + + // this uses a static map (which has its own set of disadvantages) from surface to lookup + // texture ids from images that were loaded elsewhere and pushed into cfx + textureId = cfxSurface::getTexIdByImageId(surfaceSource); + + if (textureId > 0) + { + //cfxPrint("Set sampler state\n"); + // this works on the currently bound texture object + // not important which texture unit is used, we just need to use one to + // allow cgSetSamplerState() to work properly. + cfxPrint("going to bind %d\n", textureId); + glBindTexture(GL_TEXTURE_2D, textureId); + + // apply the state settings + std::vector<cfxGlSamplerSetting*>::iterator settingIter = settingArray.begin(); + while (settingIter != settingArray.end()) + { + (*settingIter)->apply(param); + settingIter++; + } + + // calling this before generate mipmaps is better cause then the call + // to generate mipmaps already has the space set up for it to use + cgSetSamplerState(param->getParameter()); + + if (generateMipmaps) + { +#ifdef SN_TARGET_PS3 + glGenerateMipmapOES(GL_TEXTURE_2D); +#endif + } + } + else + { + cfxPrint("Texture not found for surface: %s\n", surfaceSource.c_str()); + return false; + } + } + } + + return true; +} + + +GLuint cfxSampler::getTextureId() //const +{ + textureId = cfxSurface::getTexIdByImageId(surface->getInitFrom()); + return textureId; +} + + +void cfxSampler::pushSetting(cfxGlSamplerSetting* setting) +{ + settingArray.push_back(setting); +} + +void cfxSampler::setGenerateMipmaps(bool _generateMipmaps) +{ + generateMipmaps = _generateMipmaps; +} + +const std::string &cfxSampler::getSource() const +{ + return source; +} + +const std::vector<cfxGlSamplerSetting*> &cfxSampler::getSettingArray() const +{ + return settingArray; +} diff --git a/1.4.0/fx/src/cfxSetParam.cpp b/1.4.0/fx/src/cfxSetParam.cpp new file mode 100644 index 0000000..19f3d95 --- /dev/null +++ b/1.4.0/fx/src/cfxSetParam.cpp @@ -0,0 +1,74 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +//#ifndef _LIB +#include <Cg/cg.h> +//#else +//#include <cfxNoCg.h> +//#endif + +// User includes + +#include <cfxSetParam.h> +#include <cfxEffect.h> +#include <cfxData.h> + + +// cfxSetparam +cfxSetParam::cfxSetParam(cfxData* _data, const std::string& _name, cfxEffect* _effect) + : cfxParam(_name), + effect(_effect), + data(_data) +{ + if (effect) + { + // !!!tsl this isn't supported properly yet + //parameter = cgGetNamedEffectParameter(effect->getEffect(), name.c_str()); + + // this allows params created in the effect to be set later + parameter = effect->getParameterByName(name); + + printf("setparam created: %s %p\n", name.c_str(), parameter); + } + else + { + printf("setparam created but NULL effect so can not get effect parameter to set: %s\n", name.c_str()); + } +} + +bool cfxSetParam::apply() +{ + + if (data && getParameter()) + { + data->apply(this); + } + + return true; +} + +bool cfxSetParam::validate() const +{ + return true; +} + +cfxParam::cfxParamTypeEnum cfxSetParam::getType() const +{ + return cfxParam::CFXSETPARAM; +} + +const cfxData *cfxSetParam::getData() const +{ + return data; +} + diff --git a/1.4.0/fx/src/cfxShader.cpp b/1.4.0/fx/src/cfxShader.cpp new file mode 100644 index 0000000..4b3b124 --- /dev/null +++ b/1.4.0/fx/src/cfxShader.cpp @@ -0,0 +1,150 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cfxPlatform.h> +// User includes + +#include <cfxTypes.h> +#include <cfxShader.h> +#include <cfxAnnotate.h> +#include <cfxParam.h> +#include <cfxPass.h> +#include <cfxTechnique.h> +#include <cfxEffect.h> + + + +// cfxShader +cfxShader::cfxShader(cfxPass* _pass, const std::string& _source, const std::string& _name, CGprofile _target, type_enum type) + : pass(_pass), + source(_source), + name(_name), + target(_target) +{ + originalType = type; + program = NULL; + const char* fullPath = pass->getTechnique()->mapNameToFullPath(source); + + if (fullPath) + { +#ifndef _LIB +#ifdef NORMAL_OS + + // this needs to cope with absolute paths being returned beginning with a / according to URI RFC + std::string adjustedFullPath(fullPath, 1, strlen(fullPath)); + + printf("program %s at %s has value: %p\n", source.c_str(), fullPath, program); + printf(" adjustedFullPath.c_str() %s \n", adjustedFullPath.c_str()); + // this needs cg files, not cgfx + program = cgCreateProgramFromFile(pass->getTechnique()->getEffect()->getContext(), CG_FILE_TYPE, adjustedFullPath.c_str(), target /*profile*/, name.c_str(), NULL); + + printf("program %s at %s has value: %p\n", source.c_str(), fullPath, program); +#else + unsigned int numCg = 0; + unsigned int indexCg = 0; + fullPath = pass->getTechnique()->getFullPathCg(numCg, indexCg); + + printf("NORMAL_OS 0: PROGRAM %s at %s %s %d\n", source.c_str(), fullPath, name.c_str(), (int)target); + //printf("cgGLGetLatestProfile(CG_GL_VERTEX) vs %d cgGLGetLatestProfile(CG_GL_FRAGMENT) %d \n", + // cgGLGetLatestProfile(CG_GL_VERTEX), cgGLGetLatestProfile(CG_GL_FRAGMENT) ); + + program = cgCreateProgramFromFile(pass->getTechnique()->getEffect()->getContext(), CG_SOURCE, fullPath, target, name.c_str(), NULL); + + printf ("Cg program load successfull\n" ); +#endif +#endif + if (program) + { + if (target == cgGLGetLatestProfile( CG_GL_VERTEX )) + { + printf("vertex program %s\n", source.c_str()); + state = cgGetNamedState(pass->getTechnique()->getEffect()->getContext(), "VertexProgram"); + } + else if (target == cgGLGetLatestProfile( CG_GL_FRAGMENT )) + { + printf("fragment program %s\n", source.c_str()); + state = cgGetNamedState(pass->getTechnique()->getEffect()->getContext(), "FragmentProgram"); + } + else + { + printf("ERROR. Unsupported target profile.\n"); + } + + + assignment = cgCreateStateAssignment(pass->getPass(), state); + + cgSetProgramStateAssignment(assignment, program); + } + else + { + printf("program could not be created: %s\n", fullPath); + } + } + else + { + printf("ERROR: program name not found: %s\n", source.c_str()); + } +} + +cfxShader::~cfxShader() +{ + for (size_t i=0; i<paramArray.size(); i++) + { + //cfxPrint("paramArray[i] = %x\n", paramArray[i]); + delete paramArray[i]; + } + paramArray.clear(); +} +bool cfxShader::apply() +{ + std::vector<cfxParam*>::iterator paramIter = paramArray.begin(); + while (paramIter != paramArray.end()) + { + (*paramIter)->apply(); + paramIter++; + } + + return true; +} + +bool cfxShader::validate() const +{ + return true; +} + +cfxPass* cfxShader::getPass() const +{ + return pass; +} + +CGprogram cfxShader::getProgram() const +{ + return program; +} + +const std::string &cfxShader::getName() const +{ + return name; +} + +const std::string &cfxShader::getSource() const +{ + return source; +} + +const CGprofile &cfxShader::getTarget() const +{ + return target; +} + +cfxShader::type_enum cfxShader::getOriginalType() const +{ + return originalType; +} diff --git a/1.4.0/fx/src/cfxSurface.cpp b/1.4.0/fx/src/cfxSurface.cpp new file mode 100644 index 0000000..a6581ed --- /dev/null +++ b/1.4.0/fx/src/cfxSurface.cpp @@ -0,0 +1,121 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +// User includes + +#include <cfxSurface.h> +#include <cfxPlatform.h> +#include <cfxParam.h> + +// cfxSurface +cfxSurface::cfxSurface(const std::string& _init_from, const std::string& _format, cfxSurface* _parentSurface) + : init_from(_init_from), + format(_format), + parentSurface(_parentSurface) +{ + cfxPrint("Surface created from: %s\n", init_from.c_str()); +} +cfxSurface::~cfxSurface() +{ + for (size_t i=0; i<referencingParams.size(); i++) + { + delete referencingParams[i]; + } + referencingParams.clear(); + //mapImageIdToGlTextureObjectId.clear(); +} + +bool cfxSurface::apply() +{ + if (parentSurface) + { + parentSurface->setSurface(init_from, format); + parentSurface->apply(); + } + else // this is the parent surface + { + // this goes through and calls apply on all the params which reference this surface + // this causes them to update their init_from and texture object to support setparam of surfaces + std::vector<cfxParam*>::iterator iter = referencingParams.begin(); + while (iter != referencingParams.end()) + { + (*iter)->apply(); + iter++; + } + } + return true; +} + +bool cfxSurface::validate() const +{ + return true; +} + + +const std::string& cfxSurface::getInitFrom() const +{ + return init_from; +} + +const std::string& cfxSurface::getFormat() const +{ + return format; +} + +void cfxSurface::addReferencingParam(cfxParam* param) +{ + if (param) + { + referencingParams.push_back(param); + } +} + +void cfxSurface::setSurface(const std::string& _init_from, const std::string& _format) +{ + format = _format; + init_from = _init_from; +} + +std::map<std::string, GLuint> cfxSurface::mapImageIdToGlTextureObjectId; + +GLuint cfxSurface::defaultTexture = 0; + + +void cfxSurface::addImage(const std::string& imageId, GLuint texId) +{ + mapImageIdToGlTextureObjectId.insert(make_pair(imageId, texId)); + cfxPrint("cfxSurface::addImage %s %d\n", imageId.c_str(), texId); +} + +GLuint cfxSurface::getTexIdByImageId(const std::string& imageId) +{ + GLuint texId = defaultTexture; + std::map<std::string, GLuint>::iterator iter = mapImageIdToGlTextureObjectId.find(imageId); + if (iter != mapImageIdToGlTextureObjectId.end()) + { + texId = iter->second; + } + //cfxPrint("cfxSurface::getTexIdByImageId: %s %d\n", imageId.c_str(), texId); + return texId; +} + + +void cfxSurface::setDefaultTexture(GLuint texId) +{ + defaultTexture = texId; +} + +const cfxSurface* cfxSurface::getParentSurface() const +{ + return parentSurface; +} diff --git a/1.4.0/fx/src/cfxTechnique.cpp b/1.4.0/fx/src/cfxTechnique.cpp new file mode 100644 index 0000000..cfc29ed --- /dev/null +++ b/1.4.0/fx/src/cfxTechnique.cpp @@ -0,0 +1,184 @@ +/* +* Copyright 2006 Sony Computer Entertainment Inc. +* +* Licensed under the MIT Open Source License, for details please see license.txt or the website +* http://www.opensource.org/licenses/mit-license.php +* +*/ +// System includes + +#include <stdio.h> +#include <cstdlib> +#include <iostream> + +// User includes + +#include <cfxTechnique.h> +#include <cfxEffect.h> +#include <cfxAnnotate.h> +#include <cfxPass.h> +#include <cfxSurface.h> + + + +cfxTechnique::cfxTechnique(cfxEffect* _effect, const std::string& _name) + : effect(_effect), + name(_name) +{ + technique = cgCreateTechnique(effect->getEffect(), name.c_str()); +} + +cfxTechnique::~cfxTechnique() +{ + for (size_t i=0; i<codeArray.size(); i++) + { + delete codeArray[i]; + } + codeArray.clear(); + + includeMap.clear(); + + for (size_t i=0; i<passArray.size(); i++) + { + delete passArray[i]; + } + passArray.clear(); + + for (size_t i=0; i<surfaceArray.size(); i++) + { + delete surfaceArray[i]; + } + surfaceArray.clear(); +} + +bool cfxTechnique::apply() +{ + std::vector<cfxAnnotate*>::iterator annotateIter = annotateArray.begin(); + while (annotateIter != annotateArray.end()) + { + (*annotateIter)->apply(this); + annotateIter++; + } + + std::vector<cfxPass*>::iterator passIter = passArray.begin(); + while (passIter != passArray.end()) + { + (*passIter)->apply(); + passIter++; + } + + return true; +} + +bool cfxTechnique::validate() const +{ + return true; +} + +cfxEffect* cfxTechnique::getEffect() const +{ + return effect; +} + +CGtechnique cfxTechnique::getTechnique() const +{ + return technique; +} + +const char* cfxTechnique::mapNameToFullPath(const std::string& name) const +{ + std::map<std::string, std::string>::const_iterator includeIter = includeMap.find(name); + if (includeIter == includeMap.end()) + return NULL; + return includeIter->second.c_str(); +} + + +const char* cfxTechnique::getFullPathCg(unsigned int& numCg, unsigned int indexCg) const +{ + const char* fullpath = NULL; + numCg = 0; + std::map<std::string, std::string>::const_iterator includeIter = includeMap.begin(); + while (includeIter != includeMap.end()) + { + const std::string& testpath = includeIter->second; + if (((testpath.at(testpath.length()-3) == '.') && (testpath.at(testpath.length()-2) == 'c') && (testpath.at(testpath.length()-1) == 'g')) || + ((testpath.at(testpath.length()-5) == '.') && (testpath.at(testpath.length()-4) == 'c') && (testpath.at(testpath.length()-3) == 'g') && (testpath.at(testpath.length()-2) == 'f') && (testpath.at(testpath.length()-1) == 'x'))) + { + if (numCg == indexCg) + { + fullpath = testpath.c_str(); + } + numCg++; + } + includeIter++; + } + return fullpath; +} + + +void cfxTechnique::pushPass(cfxPass* pass) +{ + passArray.push_back(pass); +} + + +void cfxTechnique::pushInclude(const std::string& name, const std::string& uri) +{ + includeMap.insert(make_pair(name, uri)); + printf("inserting pair into include map: %s %s\n", name.c_str(), uri.c_str()); +} + + +void cfxTechnique::pushSurface(cfxSurface* surface) +{ + surfaceArray.push_back(surface); +} + +void cfxTechnique::setPassState(unsigned int passIndex) +{ + if (passIndex >= passArray.size()) + { + printf("ERROR: passIndex invalid: %d\n", passIndex); + return; + } + + cgSetPassState(passArray[passIndex]->getPass()); +} + + +void cfxTechnique::resetPassState(unsigned int passIndex) +{ + if (passIndex >= passArray.size()) + { + printf("ERROR: passIndex invalid: %d\n", passIndex); + return; + } + + cgResetPassState(passArray[passIndex]->getPass()); +} + + +unsigned int cfxTechnique::getPassCount() const +{ + return (unsigned int)(passArray.size()); +} + +const std::map<std::string, std::string> &cfxTechnique::getIncludeMap() const +{ + return includeMap; +} + +const std::vector<cfxSurface*> &cfxTechnique::getSurfaceArray() const +{ + return surfaceArray; +} +const std::string &cfxTechnique::getName() const +{ + return name; +} + +const std::vector<cfxPass*> &cfxTechnique::getPassArray() const +{ + return passArray; +} |