Esempio n. 1
0
cgfxPass::cgfxPass(
    CGpass                  pass,
    const cgfxProfile*      profile
)
 :	fPass( pass),
	fProgram( NULL),
	fParameters( NULL),
    fDefaultProfile("default", pass),
	fNext( NULL)
{
	if( pass)
	{
		fName = cgGetPassName( pass);
		CGstateassignment stateAssignment = cgGetFirstStateAssignment( pass);
		cgfxVaryingParameter** nextParameter = &fParameters;
		while( stateAssignment )
		{
			CGstate state = cgGetStateAssignmentState( stateAssignment);
			if( cgGetStateType( state) == CG_PROGRAM_TYPE && 
					( stricmp( cgGetStateName( state), "vertexProgram") == 0 ||
					  stricmp( cgGetStateName( state), "vertexShader") == 0))
			{
				fProgram = cgGetProgramStateAssignmentValue( stateAssignment);
				if( fProgram)
				{
					CGparameter parameter = cgGetFirstParameter( fProgram, CG_PROGRAM);
					while( parameter)
					{
                        cgfxVaryingParameter::addRecursive( parameter, nextParameter);
						parameter = cgGetNextParameter( parameter);
					}
				}
			}
            setProfile(profile);
			stateAssignment = cgGetNextStateAssignment( stateAssignment);
		}
	}
}
Esempio n. 2
0
static bool AddState(JSON &json, CGstateassignment sa)
{
    const CGstate state = cgGetStateAssignmentState(sa);
    const char * const stateName = cgGetStateName(state);
    if (false == IsValidState(stateName))
    {
        ErrorMessage("Invalid state for OpenGL ES 2.0 %s", stateName);
        return false;
    }

    const CGtype type = cgGetStateType(state);
    int nValues;
    switch (type)
    {
    case CG_PROGRAM_TYPE:
        return true;

    case CG_FLOAT:
    case CG_FLOAT1:
        {
            const float * const fvalues = cgGetFloatStateAssignmentValues(sa, &nValues);
            json.AddValue(stateName, fvalues[0]);
        }
        break;

    case CG_FLOAT2:
    case CG_FLOAT3:
    case CG_FLOAT4:
        {
            const float * const fvalues = cgGetFloatStateAssignmentValues(sa, &nValues);
            json.AddArray(stateName, true);
            json.BeginData(true);
            for (int n = 0; n < nValues; ++n)
            {
                json.AddData(fvalues[n]);
            }
            json.EndData();
            json.CloseArray(true);
        }
        break;

    case CG_INT:
    case CG_INT1:
        {
            const int * const ivalues = cgGetIntStateAssignmentValues(sa, &nValues);
            json.AddValue(stateName, ivalues[0]);
        }
        break;

    case CG_INT2:
    case CG_INT3:
    case CG_INT4:
        {
            const int * const ivalues = cgGetIntStateAssignmentValues(sa, &nValues);
            json.AddArray(stateName, true);
            json.BeginData(true);
            for (int n = 0; n < nValues; ++n)
            {
                json.AddData(ivalues[n]);
            }
            json.EndData();
            json.CloseArray(true);
        }
        break;

    case CG_BOOL:
    case CG_BOOL1:
        {
            const CGbool * const bvalues = cgGetBoolStateAssignmentValues(sa, &nValues);
            json.AddBoolean(stateName, (bvalues[0] ? true : false));
        }
        break;

    case CG_BOOL2:
    case CG_BOOL3:
    case CG_BOOL4:
        {
            const CGbool * const bvalues = cgGetBoolStateAssignmentValues(sa, &nValues);
            json.AddArray(stateName, true);
            json.BeginData(true);
            for (int n = 0; n < nValues; ++n)
            {
                json.AddData(bvalues[n]);
            }
            json.EndData();
            json.CloseArray(true);
        }
        break;

    case CG_STRING:
        json.AddString(stateName, cgGetStringStateAssignmentValue(sa));
        break;

    default:
        ErrorMessage("UNEXPECTED State Assignment Type: %s 0x%x (%d)\n",
                        cgGetTypeString(type), type, type);
        return false;
    }
    return true;
}
Esempio n. 3
0
//
// Scan the technique for passes which use blending
//
bool cgfxTechnique::hasBlending(CGtechnique technique)
{
	// Assume not blending
	bool hasBlending = false;

	// Check for : BlendEnable=true, BlendFunc=something valid on the first pass only.
	//
	// We ignore any depth enable and functions for now...
	//
	CGpass cgPass = cgGetFirstPass(technique);
	bool foundBlendEnabled = false;
	bool foundBlendFunc = false;
	if (cgPass)
	{
		CGstateassignment stateAssignment = cgGetFirstStateAssignment(cgPass);
		while ( stateAssignment )
		{
			CGstate state = cgGetStateAssignmentState( stateAssignment);
			const char *stateName = cgGetStateName(state);

			// Check for blend enabled.
			if (!foundBlendEnabled && stricmp( stateName, "BlendEnable") == 0)
			{
				int numValues = 0;
				const CGbool *values = cgGetBoolStateAssignmentValues(stateAssignment, &numValues);
				if (values && numValues)
				{
					if (values[0])
					{
						foundBlendEnabled = true;
					}
				}
			}

			// Check for valid blend function
			else if (!foundBlendFunc && ( stricmp( stateName, "BlendFunc") == 0 ||
										  stricmp( stateName, "BlendFuncSeparate") == 0 ))
			{
				int numValues = 0;
				const int * values = cgGetIntStateAssignmentValues(stateAssignment, &numValues);
				if (values)
				{
#if defined(CGFX_DEBUG_BLEND_FUNCTIONS)
					/*
					#define GL_SRC_COLOR                      0x0300 = 768
					#define GL_ONE_MINUS_SRC_COLOR            0x0301 = 769
					#define GL_SRC_ALPHA                      0x0302 = 770
					#define GL_ONE_MINUS_SRC_ALPHA            0x0303 = 771
					#define GL_DST_ALPHA                      0x0304 = 772
					#define GL_ONE_MINUS_DST_ALPHA            0x0305 = 773
					*/
					MString blendStringTable[6] =
					{
						"GL_SRC_COLOR", // SrcColor
						"GL_ONE_MINUS_SRC_COLOR", // OneMinusSrcColor
						"GL_SRC_ALPHA", // SrcAlpha
						"GL_ONE_MINUS_SRC_ALPHA", // OneMinusSrcAlpha
						"GL_DST_ALPHA", // DstAlpha
						"GL_ONE_MINUS_DST_ALPHA" // OneMinusDstAlpha
					};
#endif
					for (int i=0; i<numValues; i++)
					{
						if ((values[i] >= GL_SRC_COLOR) && (values[i] <= GL_ONE_MINUS_DST_ALPHA))
						{
#if defined(CGFX_DEBUG_BLEND_FUNCTIONS)
							printf("Found blend function = %s, %s\n",
							blendStringTable[ values[0]-GL_SRC_COLOR].asChar(),
							blendStringTable[ values[1]-GL_SRC_COLOR].asChar());
#endif
							foundBlendFunc = true;
							break;
						}
					}
				}
			}
			hasBlending = foundBlendEnabled && foundBlendFunc;
			if (hasBlending)
				break;
			stateAssignment = cgGetNextStateAssignment( stateAssignment);
		}
	}

    return hasBlending;
}