Fence problem

Hi…
My code looks a little like this:

for each face
{
if deform
apply deformation to vertices

  for each pass
      {
      'apply' pass
      glDrawElements
      'remove' pass
      }

   if deform
      remove deformation

}

But all my data is stored using VAR, so in order to the changes of the deformations being OK, I apply a fence just before the deformation, and then query it before removing the deformation. I wait until the fence is complete, then, only then, do I remove the deformation… but this doesn’t work.

And I don’t change the vertex data in the passes, just textures, lightmaps, some rotates to the texture matrix, etc…

Althought I may know why this happens: fences are used to know if a GL command as finished (making it possible to syncronize with the CPU). But what I’m doing is writing to memory, so even applying the fence, how would the GPU know that I finished writing?

I’m a bit confused here… please HELP!!!
Oh and sorry for my porr english
Well, thanks anyway…

Please insert where you set the fence and query the fence into your psuedo code - so we can spot the mistake.

This is what I think you should be doing:-

for each face
{
wait_for_fence_to_finish

if deformed_previously
remove deformation

if deform
apply deformation to vertices

for each pass
{
‘apply’ pass
glDrawElements
‘remove’ pass
}

set_fence
}

I don’t know how to put the code like you did…

for each face
{
if deform
{
set fence
apply deformation to vertices
}

for each pass
{
‘apply’ pass
glDrawElements
‘remove’ pass
}

if deform
{
wait for fence
remove deformation
}

}

To get the code to look like code, just do this:-
{CODE}
Do some code
{/CODE}

…only, change the curly brackets to [ and ]

BTW,
you’re not using fences as they’re intended to be used.