예제 #1
0
파일: mpdump.cpp 프로젝트: UIKit0/aqsis
// Dump a color
void CqMPDump::dumpCol(const CqColor& c)
{
	TqFloat r = c.r();
	TqFloat g = c.g();
	TqFloat b = c.b();

	size_t len_written = fwrite((void*)&r, sizeof(TqFloat), 1, m_outFile);
	len_written += fwrite((void*)&g, sizeof(TqFloat), 1, m_outFile);
	len_written += fwrite((void*)&b, sizeof(TqFloat), 1, m_outFile);
	if(len_written != 3)
		AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System,
				"Error writing mpdump file");
}
예제 #2
0
/** \brief Extract details about a shader variable.
 *
 * \param shaderVar - variable holding the data to be extracted
 * \param theArgsArray - array into which the shader variable details should be
 *                       stored
 * \param theNArgs - index into theArgsArray.  (Data will be stored in
 *                   theArgsArray[theNArgs] )
 */
static void AddShaderVar( IqShaderData * shaderVar,
                          SLX_VISSYMDEF * theArgsArray, int *theNArgs )
{
	EqVariableType	theType;
	EqVariableClass theClass;
	SLX_TYPE	slxType;
	CqString	varNameCqStr;
	char *	varNameCStr;
	char *	theVarNameStr;
	int nameLength;
	char *	defaultVal = NULL;
	char *	defaultValString = NULL;
	int defaultValLength;
	char * spacename;
	int	arrayLen = 0;
	int	arrayIndex;

	if ( shaderVar != NULL && shaderVar->fParameter() )
	{
		theType = shaderVar->Type();
		theClass = shaderVar->Class();

		varNameCqStr = shaderVar->strName();
		varNameCStr = ( char * ) varNameCqStr.c_str();
		nameLength = strlen( varNameCStr );
		theVarNameStr = ( char * ) malloc( nameLength + 1 );
		strcpy( theVarNameStr, varNameCStr );

		spacename = NULL;

		switch ( theType )
		{
				case type_float:
				{
					TqFloat	aTqFloat;
					RtFloat	aRtFloat;
					slxType = SLX_TYPE_SCALAR;
					if ( !shaderVar->isArray())
					{
						shaderVar->GetFloat( aTqFloat );
						aRtFloat = aTqFloat;
						defaultValLength = sizeof( RtFloat );
						defaultVal = ( char * ) malloc( defaultValLength );
						memcpy( defaultVal, &aRtFloat, defaultValLength );
					}
					else
					{
						arrayLen = shaderVar->ArrayLength();
						defaultValLength = sizeof( RtFloat ) * arrayLen;
						defaultVal = ( char * ) malloc( defaultValLength );
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							shaderVar->ArrayEntry( arrayIndex ) ->GetFloat( aTqFloat );
							aRtFloat = aTqFloat;
							memcpy( defaultVal + ( arrayIndex * sizeof( RtFloat ) ), &aRtFloat, sizeof( RtFloat ) );
						}
					}
					spacename = ( char * ) malloc( 1 );
					*spacename = 0x0;	// NULL string
					StoreShaderArgDef( theArgsArray, *theNArgs, theVarNameStr, slxType,
					                   spacename, defaultVal, arrayLen );
					( *theNArgs ) ++;
				}
				break;
				case type_string:
				{
					CqString	aCqString;
					char *	aCString;
					slxType = SLX_TYPE_STRING;
					if ( !shaderVar->isArray() )
					{
						shaderVar->GetString( aCqString );
						aCString = ( char * ) aCqString.c_str();
						defaultValLength = strlen( aCString ) + 1;
						defaultValString = ( char * ) malloc( defaultValLength );
						strcpy( defaultValString, aCString );
						defaultVal = ( char * ) malloc( sizeof( char * ) );
						memcpy( defaultVal, &defaultValString, sizeof( char * ) );
					}
					else
					{
						arrayLen = shaderVar->ArrayLength();
						defaultValLength = sizeof( char * ) * arrayLen;
						defaultVal = ( char * ) malloc( defaultValLength );
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							shaderVar->ArrayEntry( arrayIndex ) ->GetString( aCqString );
							aCString = ( char * ) aCqString.c_str();
							defaultValLength = strlen( aCString ) + 1;
							defaultValString = ( char * ) malloc( defaultValLength );
							strcpy( defaultValString, aCString );
							memcpy( defaultVal + ( arrayIndex * sizeof( char * ) ), &defaultValString, sizeof( char * ) );
						}
					}
					spacename = ( char * ) malloc( 1 );
					*spacename = 0x0;	// NULL string
					StoreShaderArgDef( theArgsArray, *theNArgs, theVarNameStr, slxType,
					                   spacename, defaultVal, arrayLen );
					( *theNArgs ) ++;
				}
				break;
				case type_point:
				{
					CqVector3D	aCqVector3D;
					RtPoint	aRtPoint;
					slxType = SLX_TYPE_POINT;
					if ( !shaderVar->isArray() )
					{
						shaderVar->GetPoint( aCqVector3D );
						aRtPoint[ 0 ] = aCqVector3D[ 0 ];
						aRtPoint[ 1 ] = aCqVector3D[ 1 ];
						aRtPoint[ 2 ] = aCqVector3D[ 2 ];
						defaultValLength = sizeof( RtPoint );
						defaultVal = ( char * ) malloc( defaultValLength );
						memcpy( defaultVal, &aRtPoint, defaultValLength );
					}
					else
					{
						arrayLen = shaderVar->ArrayLength();
						defaultValLength = sizeof( RtPoint ) * arrayLen;
						defaultVal = ( char * ) malloc( defaultValLength );
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							shaderVar->ArrayEntry( arrayIndex ) ->GetPoint( aCqVector3D );
							aRtPoint[ 0 ] = aCqVector3D[ 0 ];
							aRtPoint[ 1 ] = aCqVector3D[ 1 ];
							aRtPoint[ 2 ] = aCqVector3D[ 2 ];
							memcpy( defaultVal + ( arrayIndex * sizeof( RtPoint ) ), &aRtPoint, sizeof( RtPoint ) );
						}
					}

					// shader evaluation space - RI_CURRENT, RI_SHADER, RI_EYE or RI_NDC
					// just go with RI_CURRENT for now
					spacename = ( char * ) malloc( sizeof( "current" ) + 1 );
					strcpy( spacename, "current" );

					StoreShaderArgDef( theArgsArray, *theNArgs, theVarNameStr, slxType,
					                   spacename, defaultVal, arrayLen );
					( *theNArgs ) ++;
				}
				break;
				case type_normal:
				{
					CqVector3D	aCqVector3D;
					RtPoint	aRtPoint;
					slxType = SLX_TYPE_NORMAL;
					if ( !shaderVar->isArray() )
					{
						shaderVar->GetNormal( aCqVector3D );
						aRtPoint[ 0 ] = aCqVector3D[ 0 ];
						aRtPoint[ 1 ] = aCqVector3D[ 1 ];
						aRtPoint[ 2 ] = aCqVector3D[ 2 ];
						defaultValLength = sizeof( RtPoint );
						defaultVal = ( char * ) malloc( defaultValLength );
						memcpy( defaultVal, &aRtPoint, defaultValLength );
					}
					else
					{
						arrayLen = shaderVar->ArrayLength();
						defaultValLength = sizeof( RtPoint ) * arrayLen;
						defaultVal = ( char * ) malloc( defaultValLength );
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							shaderVar->ArrayEntry( arrayIndex ) ->GetNormal( aCqVector3D );
							aRtPoint[ 0 ] = aCqVector3D[ 0 ];
							aRtPoint[ 1 ] = aCqVector3D[ 1 ];
							aRtPoint[ 2 ] = aCqVector3D[ 2 ];
							memcpy( defaultVal + ( arrayIndex * sizeof( RtPoint ) ), &aRtPoint, sizeof( RtPoint ) );
						}
					}

					// shader evaluation space - RI_CURRENT, RI_SHADER, RI_EYE or RI_NDC
					// just go with RI_CURRENT for now
					spacename = ( char * ) malloc( sizeof( "current" ) + 1 );
					strcpy( spacename, "current" );

					StoreShaderArgDef( theArgsArray, *theNArgs, theVarNameStr, slxType,
					                   spacename, defaultVal, arrayLen );
					( *theNArgs ) ++;
				}
				break;
				case type_vector:
				{
					CqVector3D	aCqVector3D;
					RtPoint	aRtPoint;
					slxType = SLX_TYPE_VECTOR;
					if ( !shaderVar->isArray() )
					{
						shaderVar->GetPoint( aCqVector3D );
						aRtPoint[ 0 ] = aCqVector3D[ 0 ];
						aRtPoint[ 1 ] = aCqVector3D[ 1 ];
						aRtPoint[ 2 ] = aCqVector3D[ 2 ];
						defaultValLength = sizeof( RtPoint );
						defaultVal = ( char * ) malloc( defaultValLength );
						memcpy( defaultVal, &aRtPoint, defaultValLength );
					}
					else
					{
						arrayLen = shaderVar->ArrayLength();
						defaultValLength = sizeof( RtPoint ) * arrayLen;
						defaultVal = ( char * ) malloc( defaultValLength );
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							shaderVar->ArrayEntry( arrayIndex ) ->GetPoint( aCqVector3D );
							aRtPoint[ 0 ] = aCqVector3D[ 0 ];
							aRtPoint[ 1 ] = aCqVector3D[ 1 ];
							aRtPoint[ 2 ] = aCqVector3D[ 2 ];
							memcpy( defaultVal + ( arrayIndex * sizeof( RtPoint ) ), &aRtPoint, sizeof( RtPoint ) );
						}
					}

					// shader evaluation space - RI_CURRENT, RI_SHADER, RI_EYE or RI_NDC
					// just go with RI_CURRENT for now
					spacename = ( char * ) malloc( sizeof( "current" ) + 1 );
					strcpy( spacename, "current" );

					StoreShaderArgDef( theArgsArray, *theNArgs, theVarNameStr, slxType,
					                   spacename, defaultVal, arrayLen );
					( *theNArgs ) ++;
				}
				break;
				case type_color:
				{
					CqColor	aCqColor;
					RtColor	aRtColor;
					slxType = SLX_TYPE_COLOR;
					if ( !shaderVar->isArray() )
					{
						shaderVar->GetColor( aCqColor );
						aRtColor[ 0 ] = aCqColor.r();
						aRtColor[ 1 ] = aCqColor.g();
						aRtColor[ 2 ] = aCqColor.b();
						defaultValLength = sizeof( RtColor );
						defaultVal = ( char * ) malloc( defaultValLength );
						memcpy( defaultVal, &aRtColor, defaultValLength );
					}
					else
					{
						arrayLen = shaderVar->ArrayLength();
						defaultValLength = sizeof( RtColor ) * arrayLen;
						defaultVal = ( char * ) malloc( defaultValLength );
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							shaderVar->ArrayEntry( arrayIndex ) ->GetColor( aCqColor );
							aRtColor[ 0 ] = aCqColor[ 0 ];
							aRtColor[ 1 ] = aCqColor[ 1 ];
							aRtColor[ 2 ] = aCqColor[ 2 ];
							memcpy( defaultVal + ( arrayIndex * sizeof( RtColor ) ), &aRtColor, sizeof( RtColor ) );
						}
					}

					// shader evaluation space - RI_RGB, RI_RGBA, RI_RGBZ, RI_RGBAZ, RI_A, RI_Z or RI_AZ
					// just go with RI_RGB for now
					spacename = ( char * ) malloc( sizeof( "rgb" ) + 1 );
					strcpy( spacename, "rgb" );

					StoreShaderArgDef( theArgsArray, *theNArgs, theVarNameStr, slxType,
					                   spacename, defaultVal, arrayLen );
					( *theNArgs ) ++;
				}
				break;
				case type_matrix:
				{
					CqMatrix	aCqMatrix;
					RtMatrix	aRtMatrix;
					slxType = SLX_TYPE_MATRIX;
					if ( !shaderVar->isArray() )
					{
						shaderVar->GetMatrix( aCqMatrix );
						aRtMatrix[ 0 ][ 0 ] = aCqMatrix[ 0 ][ 0 ];
						aRtMatrix[ 0 ][ 1 ] = aCqMatrix[ 0 ][ 1 ];
						aRtMatrix[ 0 ][ 2 ] = aCqMatrix[ 0 ][ 2 ];
						aRtMatrix[ 0 ][ 3 ] = aCqMatrix[ 0 ][ 3 ];
						aRtMatrix[ 1 ][ 0 ] = aCqMatrix[ 1 ][ 0 ];
						aRtMatrix[ 1 ][ 1 ] = aCqMatrix[ 1 ][ 1 ];
						aRtMatrix[ 1 ][ 2 ] = aCqMatrix[ 1 ][ 2 ];
						aRtMatrix[ 1 ][ 3 ] = aCqMatrix[ 1 ][ 3 ];
						aRtMatrix[ 2 ][ 0 ] = aCqMatrix[ 2 ][ 0 ];
						aRtMatrix[ 2 ][ 1 ] = aCqMatrix[ 2 ][ 1 ];
						aRtMatrix[ 2 ][ 2 ] = aCqMatrix[ 2 ][ 2 ];
						aRtMatrix[ 2 ][ 3 ] = aCqMatrix[ 2 ][ 3 ];
						aRtMatrix[ 3 ][ 0 ] = aCqMatrix[ 3 ][ 0 ];
						aRtMatrix[ 3 ][ 1 ] = aCqMatrix[ 3 ][ 1 ];
						aRtMatrix[ 3 ][ 2 ] = aCqMatrix[ 3 ][ 2 ];
						aRtMatrix[ 3 ][ 3 ] = aCqMatrix[ 3 ][ 3 ];
						defaultValLength = sizeof( RtMatrix );
						defaultVal = ( char * ) malloc( defaultValLength );
						memcpy( defaultVal, &aRtMatrix, defaultValLength );
					}
					else
					{
						arrayLen = shaderVar->ArrayLength();
						defaultValLength = sizeof( RtMatrix ) * arrayLen;
						defaultVal = ( char * ) malloc( defaultValLength );
						for ( arrayIndex = 0; arrayIndex < arrayLen; arrayIndex++ )
						{
							shaderVar->ArrayEntry( arrayIndex ) ->GetMatrix( aCqMatrix );
							aRtMatrix[ 0 ][ 0 ] = aCqMatrix[ 0 ][ 0 ];
							aRtMatrix[ 0 ][ 1 ] = aCqMatrix[ 0 ][ 1 ];
							aRtMatrix[ 0 ][ 2 ] = aCqMatrix[ 0 ][ 2 ];
							aRtMatrix[ 0 ][ 3 ] = aCqMatrix[ 0 ][ 3 ];
							aRtMatrix[ 1 ][ 0 ] = aCqMatrix[ 1 ][ 0 ];
							aRtMatrix[ 1 ][ 1 ] = aCqMatrix[ 1 ][ 1 ];
							aRtMatrix[ 1 ][ 2 ] = aCqMatrix[ 1 ][ 2 ];
							aRtMatrix[ 1 ][ 3 ] = aCqMatrix[ 1 ][ 3 ];
							aRtMatrix[ 2 ][ 0 ] = aCqMatrix[ 2 ][ 0 ];
							aRtMatrix[ 2 ][ 1 ] = aCqMatrix[ 2 ][ 1 ];
							aRtMatrix[ 2 ][ 2 ] = aCqMatrix[ 2 ][ 2 ];
							aRtMatrix[ 2 ][ 3 ] = aCqMatrix[ 2 ][ 3 ];
							aRtMatrix[ 3 ][ 0 ] = aCqMatrix[ 3 ][ 0 ];
							aRtMatrix[ 3 ][ 1 ] = aCqMatrix[ 3 ][ 1 ];
							aRtMatrix[ 3 ][ 2 ] = aCqMatrix[ 3 ][ 2 ];
							aRtMatrix[ 3 ][ 3 ] = aCqMatrix[ 3 ][ 3 ];
							memcpy( defaultVal + ( arrayIndex * sizeof( RtMatrix ) ), &aRtMatrix, sizeof( RtMatrix ) );
						}
					}

					// shader evaluation space - RI_CURRENT, RI_SHADER, RI_EYE or RI_NDC
					// just go with RI_CURRENT for now
					spacename = ( char * ) malloc( sizeof( "current" ) + 1 );
					strcpy( spacename, "current" );

					StoreShaderArgDef( theArgsArray, *theNArgs, theVarNameStr, slxType,
					                   spacename, defaultVal, arrayLen );
					( *theNArgs ) ++;
				}
				break;
				default:
				break;
		}
	}
}