Sign in to follow this  
Julian Spillane

[CgFX] Problem Updating Parameters...

Recommended Posts

Hey all, We're currently using Cg 1.5 final in our engine. We've implemented a whole system based around CgFX but have run into some issues. I was just wondering if it was possible to disable parameter shadowing with effects. With parameter shadowing enabled we have to wait until the next update in order for parameters to be updated. I wish for the parameter value to be updated as it is set (as can be done by disabling parameter shadowing in normal Cg). Hopefully this sample code will give you some insight into my dilemma. Just for clarification we're using this with Direct3D:
CGpass curPass = cgGetFirstPass(m_pDevice->m_vEffects[m_pDevice->m_nActiveEffectID].m_technique);

 while (curPass)
 {     
  cgSetPassState(curPass);

  for (int i = 0; i < MAX_CACHES; i++)
  {
   if (m_pCaches[i].m_nCurrentVertices > 0)
   {
    m_pDevice->setEffectParameterMatrixFloat(m_pDevice->m_nActiveEffectID, "fn_worldView", true, m_pCaches[i].m_matWV.getColumnMajor());
    m_pDevice->setEffectParameterMatrixFloat(m_pDevice->m_nActiveEffectID, "fn_worldViewProjection", true, m_pCaches[i].m_matWVP.getColumnMajor());
    m_pDevice->setEffectParameterMatrixFloat(m_pDevice->m_nActiveEffectID, "fn_worldViewInverseTranspose", true, m_pCaches[i].m_matWVIT.getColumnMajor());

    m_pDevice->m_pD3DDevice->SetStreamSource(0, m_pCaches[i].m_pVB, 0, m_pCaches[i].m_nStride);

    if (m_pCaches[i].m_nCurrentIndices > 0)
    {
     m_pDevice->m_pD3DDevice->SetIndices(m_pCaches[i].m_pIB);

     m_pDevice->m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_pCaches[i].m_nCurrentVertices, 0, m_pCaches[i].m_nCurrentIndices / 3);
    }
    else
    {
     m_pDevice->m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, m_pCaches[i].m_nCurrentVertices / 3);
    }
   }
  }
  cgResetPassState(curPass);

  curPass = cgGetNextPass(curPass);
 }

This code is part of our dynamic rendering system. Geometry that is rendered dynamically is grouped into caches according to material. This geometry is further sorted into sub caches with the same transformation matrix. During my rendering loop I wish to bind the vertex and pixel shader once and then draw all of the sub caches with their appropriate transformation matrix. This is quite efficient as only one bind has to take place for all of the geometry that is rendered subsequently. Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
In CgFX there is no way to control the shadowing when using D3D.

We are working on this issue for all of Cg so stay tuned. :)

You could also look into rolling your own state callbacks. Look into cgSetStateCallbacks.

This way you can control the loading of programs in your own callback code and handle shadowing yourself. NVSG uses this user callback mechanism since they want to control everything on their own.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this