Example #1
0
static bool AddTechnique(JSON &json, CGtechnique technique, UniformsMap &uniformRemapping)
{
    bool success = true;
    const char * const techniqueName = cgGetTechniqueName(technique);

    if (sVerbose)
    {
        puts(techniqueName);
    }

    json.AddArray(techniqueName);

    CGpass pass = cgGetFirstPass(technique);
    if (NULL == pass)
    {
        success = false;
    }

    while (NULL != pass)
    {
        success &= AddPass(technique, json, pass, uniformRemapping);

        pass = cgGetNextPass(pass);
    }

    json.CloseArray(); // techniqueName

    return success;
}
Example #2
0
	void TMFObject::Render()
	{
		glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VboVertices );
		glVertexPointer( 3, GL_FLOAT, 0, (char*)NULL );
		glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VboNormals );
		glNormalPointer( GL_FLOAT, 0, (char*)NULL );
		glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VboUVs );
		glTexCoordPointer( 2, GL_FLOAT, 0, (char*)NULL );
		glEnableClientState( GL_VERTEX_ARRAY );
		glEnableClientState( GL_NORMAL_ARRAY );
		glEnableClientState( GL_TEXTURE_COORD_ARRAY );

		CGpass pass = m_pShader->GetFirstPass();
		while (pass) 
		{
			m_pShader->UpdateModelViewProjection();
			cgSetPassState(pass);
			glDrawArrays( GL_TRIANGLES, 0, m_NumTriangles * 3 ); 
			cgResetPassState(pass);
			pass = cgGetNextPass(pass);
		}

		glDisableClientState( GL_VERTEX_ARRAY );
		glDisableClientState( GL_NORMAL_ARRAY );
		glDisableClientState( GL_TEXTURE_COORD_ARRAY );
	}
Example #3
0
cgfxTechnique::cgfxTechnique(
    CGtechnique         technique,
    const cgfxProfile*  profile
)
:	fTechnique( technique),
    fValid(false),
	fPasses(NULL),
    fNumPasses(0),
	fNext(NULL)
{
	if (technique)
	{
		fName = cgGetTechniqueName(technique);
		CGpass pass = cgGetFirstPass(technique);
		cgfxPass** nextPass = &fPasses;
		while (pass)
		{
            ++fNumPasses;
            *nextPass = new cgfxPass(pass, profile);
            nextPass = &(*nextPass)->fNext;
			pass = cgGetNextPass(pass);
		}

        fHasBlending = hasBlending(fTechnique);

        setProfile(profile);
	}
}
Example #4
0
    void Effect::gotoNextPass()
    {
        cgResetPassState(currentPass);

        currentPass = cgGetNextPass(currentPass);

        if (currentPass != 0)
        {
            cgSetPassState(currentPass);
        }
    }
Example #5
0
bool CgEffect::ExecutePass()
{
    if(this->currentPass != NULL)
        cgResetPassState(this->currentPass);

    this->currentPass = this->nextPass;

    if(this->currentPass != NULL)
        cgSetPassState(this->currentPass);

    this->nextPass = cgGetNextPass(this->nextPass);

    return this->currentPass != NULL;
}
Example #6
0
bool cEffect::SetNextPass()
{
	if ( mTechnique )
	{
		assert( mCurrentPass );
		cgResetPassState( mCurrentPass );
		mCurrentPass = cgGetNextPass(mCurrentPass);
		if (mCurrentPass)
		{
			cgSetPassState( mCurrentPass );
			return true;
		}
	}
	return false;
}
Example #7
0
bool CgFXTechnique::validate(CgFXMaterial *pMat, 
                             DrawEnv      *pEnv)
{
    if(0x00 == (_uiValidationState & ValidationTried))
    {
#if 0
        fprintf(stderr, "Validate %p\n", _pCGTechnique);
#endif

        _uiValidationState = 0x03;

#if 0
        if(pWin != NULL)
        {
            pWin->activate();
        }
#endif

        if(_pCGTechnique                      == NULL     || 
           cgValidateTechnique(_pCGTechnique) == CG_FALSE  )
        {
            CgFXMaterial::checkForCgError("cgValidateTechnique", NULL);

            _uiValidationState = 0x02;
        }
        else
        {
            CgFXMaterial::checkForCgError("cgValidateTechnique", NULL);

            const CgFXMaterial::MFTexturesType *pTextures = 
                pMat->getMFTextures();

            CGpass pPass = cgGetFirstPass(_pCGTechnique);

            CgFXMaterial::checkForCgError("cgGetFirstPass", NULL);

            for(UInt32 i = 0; i < pTextures->size(); ++i)
            {
                const Char8 *szTexParamName = getName((*pTextures)[i]);
                      Int32  iTexParamVal   = -1;

                const ShaderVariable *pVar = pMat->getVariable(szTexParamName);
                
                OSG_ASSERT(pVar != NULL);

                const CgFXVariableTexObj *pTexVar = 
                    static_cast<const CgFXVariableTexObj *>(pVar);

                OSG_ASSERT(pTexVar != NULL);

                iTexParamVal = pTexVar->getValue();

                if(iTexParamVal == -1)
                {
                    CGparameter pParam = 
                        cgGetNamedEffectParameter(pMat->getEffect(), 
                                                      szTexParamName);

                    CgFXMaterial::checkForCgError("cgGetNamedEffectParameter", 
                                                  NULL);

                    (*pTextures)[i]->activate(pEnv, 0);
                    
                    Window::GLObjectId texObjId = 
                        pEnv->getWindow()->getGLObjectId(
                            (*pTextures)[i]->getGLId());

                    cgGLSetTextureParameter(pParam, texObjId);

                    CgFXMaterial::checkForCgError("cgGLSetTextureParameter", 
                                                  NULL);

                    cgSetSamplerState      (pParam          );

                    CgFXMaterial::checkForCgError("cgSetSamplerState", 
                                                  NULL);

                    CgFXVariableTexObj *pTexVarW = 
                        const_cast<CgFXVariableTexObj *>(pTexVar);
                    
                    pTexVarW->setValue(texObjId);

                    (*pTextures)[i]->deactivate(pEnv);
                }
            }

            int count = 0;
            
            while(pPass)
            {
                StateUnrecPtr         pState = State        ::create();
                CgFXPassChunkUnrecPtr pChunk = CgFXPassChunk::create();

                pChunk->setPass    (pPass);
                pChunk->setMaterial(pMat );

                pState->addChunk(pChunk);

                this->addPassState(pState);

                pPass = cgGetNextPass(pPass);

                CgFXMaterial::checkForCgError("cgGetNextPass", NULL);

                count++;
            }

            pMat->updateUniformVariables();
        }

#if 0
        if(_pCGTechnique != NULL)
        {
            fprintf(stderr, "Validated technique %s : %x\n",
                    cgGetTechniqueName(_pCGTechnique),
                    UInt32(_uiValidationState));
        }
#endif

#if 0
        if(pWin != NULL)
        {
            pWin->deactivate();
        }
#endif
    }

    return (_uiValidationState & TechniqueValid);
}