Example #1
0
void cEffect::SetParam(const std::string &lacName, float lParamValue)
{
	CGparameter lParam = cgGetNamedEffectParameter(mEffect, lacName.c_str() );
	if (lParam)
	{
		cgSetParameter1f(lParam, lParamValue );
	}
}
Example #2
0
void cEffect::SetParam(const std::string &lacName, const cVec4 &lParamValue)
{
	CGparameter lParam = cgGetNamedEffectParameter(mEffect, lacName.c_str() );
	if (lParam)
	{
		cgSetParameter4fv(lParam, lParamValue.AsFloatPointer() );
	}
}
Example #3
0
CGparameter CgEffect::retrieveParameter(const char* name)
{
    CGparameter param = cgGetNamedEffectParameter(effect, name);
    if(!param)
        throw new GeexShaderException("Parameter doesn't exist");

    return param;
}
Example #4
0
void cEffect::SetParam(const std::string &lacName, const cMatrix &lMatrix)
{
	CGparameter lParam = cgGetNamedEffectParameter(mEffect, lacName.c_str() );
	if (lParam)
	{
		cgSetMatrixParameterfc(lParam, lMatrix.AsFloatPointer() );
	}
}
Example #5
0
/*-------------------------------------------------------------------------

  -------------------------------------------------------------------------*/
bool FilterBox::Initialize(int w, int h)
{
  bufw = w;
  bufh = h;
  //
  // FBO
  //
  glGenFramebuffersEXT(2, fb);
  glGenTextures(2, textureID);
  glGenRenderbuffersEXT(1, &depth_rb);
  initRT(0, w, h);
  initRT(1, w, h);
  //
  // initialize depth renderbuffer
  //
  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, w, h);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, 
                                GL_RENDERBUFFER_EXT, depth_rb);
  CheckFramebufferStatus();

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  //
  // CGFX things
  //
  cgContext = cgCreateContext();
  cgGLRegisterStates(cgContext);
  std::string resolved_path;

        cgEffect = cgCreateEffectFromFile(cgContext, "data/shaders/FilterBox.cgfx", NULL);
        if(!cgEffect)
        {
			exit(0);
            const char * pszErrors = NULL;
            fprintf(stderr, "CgFx Parse error : %s", pszErrors);
            const char *listing = cgGetLastListing(cgContext);
            bValid = false;
            return false;
        }
  cgTechnique = cgGetNamedTechnique(cgEffect, "Filter");
  cgPassFilterH = cgGetNamedPass(cgTechnique, "verticalPass");
  cgPassFilterV = cgGetNamedPass(cgTechnique, "horizontalPass");
  cgPassBlend   = cgGetNamedPass(cgTechnique, "drawFinal");
  cgBlendFactor = cgGetNamedEffectParameter(cgEffect, "blendFactor");
  cgGlowFactor  = cgGetNamedEffectParameter(cgEffect, "glowFactor");
  srcSampler    = cgGetNamedEffectParameter(cgEffect, "srcSampler");
  tempSampler   = cgGetNamedEffectParameter(cgEffect, "tempSampler");
  finalSampler  = cgGetNamedEffectParameter(cgEffect, "finalSampler");
  verticalDir   = cgGetNamedEffectParameter(cgEffect, "verticalDir");
  horizontalDir = cgGetNamedEffectParameter(cgEffect, "horizontalDir");

  cgGLSetParameter2f(verticalDir, 0,1.0f/(float)h);
  cgGLSetParameter2f(horizontalDir, 1.0f/(float)w, 0);

  bValid = true;
  return true;
}
Example #6
0
void cEffect::SetParam(const std::string &lacName, cResourceHandle lParamValue)
{
	CGparameter lParam = cgGetNamedEffectParameter(mEffect, lacName.c_str() );
	if (lParam)
	{
		assert(lParamValue.IsValidHandle() );
		cTexture *lpTexture = (cTexture*)lParamValue.GetResource();
		unsigned luiTextureHandle = lpTexture->GetTextureHandle();
		cgGLSetupSampler(lParam, luiTextureHandle);
	}
}
Example #7
0
void cEffect::SetParam(const std::string &lacName, const float * lfParam, int liCount )
{
   static const unsigned kuiAuxiliarBuffer = 256 * 4;
   static float gFullArray[kuiAuxiliarBuffer];
   CGparameter lParam = cgGetNamedEffectParameter(mEffect, lacName.c_str());
   if (lParam)
   {
      int liNRows = cgGetParameterRows(lParam);
	  int liNCols = cgGetParameterColumns(lParam);
	  int liASize = cgGetArrayTotalSize(lParam);
	  int liNTotal = liNRows*liNCols;

	  if (liASize > 0)
	  {
		  liNTotal *= liASize;
		  if ( liCount < liNTotal )
		  {
			  assert(kuiAuxiliarBuffer > liNTotal);
			  assert(kuiAuxiliarBuffer > liCount);

			  memcpy(gFullArray, lfParam, sizeof(float) * liCount);
			  cgSetParameterValuefr(lParam, liNTotal, gFullArray);
		  }
		  else
		  {
			  cgSetParameterValuefr(lParam, liCount, lfParam);
		  }
		  
		  CGerror err = cgGetError();

		  if (err != CG_NO_ERROR)
		  {
			OutputDebugStr(cgGetErrorString( err ));
			OutputDebugStr("\n");
		  }
	  }
   }
}
void Effect::setMatrix( const char *_name, const float *_matrix ) {
  CGparameter param = cgGetNamedEffectParameter( effect, _name );
  cgGLSetMatrixParameterfr( param, _matrix );
}
void Effect::setParam( const char *_name, float _x ) {
  CGparameter param = cgGetNamedEffectParameter( effect, _name );
  cgGLSetParameter1f( param, _x );
}
void Effect::setParam( const char *_name, float _x, float _y, float _z ) {
  CGparameter param = cgGetNamedEffectParameter( effect, _name );
  cgGLSetParameter3f( param, _x, _y, _z );
}
void Effect::setTexture( const char *_name, GLuint _texture ) {
  CGparameter texture = cgGetNamedEffectParameter( effect, _name );
  cgGLSetTextureParameter( texture, _texture );
}
Example #12
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);
}
void CgFXPassChunk::updateStateUniforms(DrawEnv  *pEnv)
{
    CgFXMaterial *pMat = _sfMaterial.getValue();

    OSG_ASSERT(pMat != NULL);

          CGeffect     pEffect        = pMat->getEffect        ();
          UInt32       uiStateVars    = pMat->getStateVariables();
    const std::string *vStateVarNames = pMat->getStateVarNames ();

          UInt32       uiMask         = 0x0001;


    OSG_ASSERT(pEffect != NULL);

    Matrix mObj2World = pEnv->getObjectToWorld();

    std::string szTmp;

    for(UInt32 i = 0; i < CgFXMaterial::NumStateVars; ++i)
    {
        if(uiStateVars == 0x0000)
            break;
        
        switch(uiStateVars & uiMask)
        {
            case CgFXMaterial::CgProjectionMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgProjection].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(
                    pMatrixParam,
                    pEnv->_openGLState.getProjection().getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", NULL);
            }
            break;

            case CgFXMaterial::CgModelViewProjectionMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModelViewProjection].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mWorld2Scrn = pEnv->getWorldToScreen();

                mWorld2Scrn.mult(mObj2World);                

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mWorld2Scrn.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;


            // -------------
            // Model | World
            // -------------
            case CgFXMaterial::CgModelMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModel].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mObj2World.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;

            case CgFXMaterial::CgModelIMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModelI].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mModelI = mObj2World;

                mModelI.invert();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mModelI.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;

            case CgFXMaterial::CgModelITMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModelIT].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mModelIT = mObj2World;

                mModelIT.invert   ();
                mModelIT.transpose();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mModelIT.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;


            // ---------------------
            // ModelView | WorldView
            // ---------------------
            case CgFXMaterial::CgModelViewMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[CgFXMaterial::CgModelView].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.mult(mObj2World);
                
                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;

            case CgFXMaterial::CgModelViewIMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[CgFXMaterial::CgModelViewI].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.mult(mObj2World);
                mCameraViewing.invert();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;

            case CgFXMaterial::CgModelViewITMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[CgFXMaterial::CgModelViewIT].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.mult     (mObj2World);
                mCameraViewing.invert   (          );
                mCameraViewing.transpose(          );

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;


            // -------------
            // View
            // -------------
            case CgFXMaterial::CgViewMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgView].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         pEnv->getCameraViewing().getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;

            case CgFXMaterial::CgViewIMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgViewI].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                OSG::Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.invert();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;

            case CgFXMaterial::CgViewITMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgViewIT].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                OSG::Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.invert   ();
                mCameraViewing.transpose();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;


            case CgFXMaterial::CgViewProjectionMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgViewProjection].c_str());

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

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         pEnv->getWorldToScreen().getValues());

                CgFXMaterial::checkForCgError("cgGLSetMatrixParameterfc", 
                                              NULL);
            }
            break;
    
            case CgFXMaterial::CgTimeMask:
            {
                CGparameter pTime = 
                    cgGetNamedEffectParameter(
                        pEffect,
                        vStateVarNames[
                            CgFXMaterial::CgTime].c_str());


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

                OSG_ASSERT(pTime != NULL);

                static const UInt16 MaxLeftDecDigits(4);

                // getSystemTime() returns a time value as a 64-bit floating
                // point number.  But the time value taken by Cg is a 32-bit
                // float.  This can cause a problem with precision when
                // getSystemTime() returns large values, that truncate when cast
                // to a 32-bit float.
                //
                // To deal with this, we are removing the most significant
                // decimal digits left of the decimal points after the
                // MaxLeftDecDigits one

                Time tSysTime(OSG::getSystemTime());

                Time tBase10Shift(osgPow<Time>(10, MaxLeftDecDigits));
                Time tTruncValue(
                    tSysTime - 
                    (floor(tSysTime / tBase10Shift) * tBase10Shift));
                
                cgSetParameter1f(pTime, static_cast<Real32>(tTruncValue));
            }
            break;

            default:
                break;
        };

        uiStateVars &= ~uiMask;
        uiMask      =   uiMask << 1;
    }
}
void CgFXPassChunk::updateStateUniforms(DrawEnv  *pEnv)
{
    CgFXMaterial *pMat = _sfMaterial.getValue();

    OSG_ASSERT(pMat != NULL);

          CGeffect     pEffect        = pMat->getEffect        ();
          UInt32       uiStateVars    = pMat->getStateVariables();
    const std::string *vStateVarNames = pMat->getStateVarNames ();

          UInt32       uiMask         = 0x0001;


    OSG_ASSERT(pEffect != NULL);

    Matrix mObj2World = pEnv->getObjectToWorld();

    std::string szTmp;

    for(UInt32 i = 0; i < CgFXMaterial::NumStateVars; ++i)
    {
        if(uiStateVars == 0x0000)
            break;
        
        switch(uiStateVars & uiMask)
        {
            case CgFXMaterial::CgProjectionMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgProjection].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(
                    pMatrixParam,
                    pEnv->_openGLState.getProjection().getValues());
            }
            break;

            case CgFXMaterial::CgModelViewProjectionMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModelViewProjection].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mWorld2Scrn = pEnv->getWorldToScreen();

                mWorld2Scrn.mult(mObj2World);                

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mWorld2Scrn.getValues());
            }
            break;


            // -------------
            // Model | World
            // -------------
            case CgFXMaterial::CgModelMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModel].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mObj2World.getValues());
            }
            break;
            case CgFXMaterial::CgModelIMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModelI].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mModelI = mObj2World;

                mModelI.invert();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mModelI.getValues());
           }
            break;
            case CgFXMaterial::CgModelITMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgModelIT].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mModelIT = mObj2World;

                mModelIT.invert   ();
                mModelIT.transpose();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mModelIT.getValues());
            }
            break;


            // ---------------------
            // ModelView | WorldView
            // ---------------------
            case CgFXMaterial::CgModelViewMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[CgFXMaterial::CgModelView].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.mult(mObj2World);
                
                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());
            }
            break;
            case CgFXMaterial::CgModelViewIMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[CgFXMaterial::CgModelViewI].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.mult(mObj2World);
                mCameraViewing.invert();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());
            }
            break;
            case CgFXMaterial::CgModelViewITMask:
            {
                CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[CgFXMaterial::CgModelViewIT].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.mult     (mObj2World);
                mCameraViewing.invert   (          );
                mCameraViewing.transpose(          );

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());
            }
            break;


            // -------------
            // View
            // -------------
            case CgFXMaterial::CgViewMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgView].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         pEnv->getCameraViewing().getValues());
            }
            break;
            case CgFXMaterial::CgViewIMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgViewI].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                OSG::Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.invert();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());
            }
            break;
            case CgFXMaterial::CgViewITMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgViewIT].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                OSG::Matrix mCameraViewing = pEnv->getCameraViewing();

                mCameraViewing.invert   ();
                mCameraViewing.transpose();

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         mCameraViewing.getValues());
            }
            break;


            case CgFXMaterial::CgViewProjectionMask:
            {
                 CGparameter pMatrixParam = 
                    cgGetNamedEffectParameter(
                        pEffect, 
                        vStateVarNames[
                            CgFXMaterial::CgViewProjection].c_str());

                OSG_ASSERT(pMatrixParam != NULL);

                cgGLSetMatrixParameterfc(pMatrixParam,
                                         pEnv->getWorldToScreen().getValues());
            }
            break;

            default:
                break;
        };

        uiStateVars &= ~uiMask;
        uiMask      =   uiMask << 1;
    }
}
Example #15
0
 ShaderParameterCg::ShaderParameterCg(ShaderProgramCg& program, std::string const& identifier)
 {
     this->_param = cgGetNamedEffectParameter(program.GetEffect(), identifier.c_str());
 }