object flickering

Started by
6 comments, last by shavitpriens 10 years, 9 months ago

when i use this update code my box flickers and sometimes doesn't appear on the screen.

void Box::update(float dt)
{
D3DXVECTOR3 displacement = Velocity * dt;
if(Velocity != D3DXVECTOR3(0,0,0))
{
Vertex* v = 0;
mVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&v );
for(int i = 0;i < mNumVertices;i++)
v.pos +=displacement;
mVB->Unmap();
}
}
I need help I don't know what to do, I tried to use D3D10Device::CopyResource but it didn't work it crushed the program !
Advertisement

If you don't move the box, does it still flicker? Having constantly sending in new vertices in your dynamic vb may have some performance implications but i don't think the problem is in your update code

If you don't move the box, does it still flicker? Having constantly sending in new vertices in your dynamic vb may have some performance implications but i don't think the problem is in your update codI

I have no flickers when the box doesn't move

D3D10_MAP_WRITE_DISCARD

D3D10_MAP_WRITE_DISCARD

Resource is mapped for writing; the previous contents of the resource will be undefined. The resource must have been created with write access (see D3D10_CPU_ACCESS_WRITE).

You either want to use D3D10_MAP_READ_WRITE (remember that reading from GPU memory is SLOW) or re-generate the vertices from scratch.



D3D10_MAP_WRITE_DISCARD


D3D10_MAP_WRITE_DISCARD

Resource is mapped for writing; the previous contents of the resource will be undefined. The resource must have been created with write access (see D3D10_CPU_ACCESS_WRITE).

You either want to use D3D10_MAP_READ_WRITE (remember that reading from GPU memory is SLOW) or re-generate the vertices from scratch.

Oh wow totally missed that. mdias is right. The data in your Vertex* v is undefined. Your code v.pos+displacement adds a value to v which is undefined. You should have the position value, along with the rest of the data in your vertex buffer, saved in system memory then use those values to assign it to v[].

So it should look something like this:


// This is stored somewhere in system memory
VertexData m_vertices;

Vertex* v = 0;
mVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&v );
 
for(int i = 0;i < mNumVertices;i++)
{
   // Update position
   m_vertices[i].pos += displacement;

   // Replace new data
   v[i].pos = m_vertices[i].pos;
   // Also replace the rest of the attributes as well.. (color, normal, texCoord, etc...)
}

The reason why its probably flickering is that the api will give you a system memory with the values you initially assigned to the vb in one frame then the next frame the api will give you a totally different system memory with garbage values (resulting in a position with crazy values off the screen).

Thanks for the heads up mdias!

D3D10_MAP_WRITE_DISCARD

D3D10_MAP_WRITE_DISCARD

Resource is mapped for writing; the previous contents of the resource will be undefined. The resource must have been created with write access (see D3D10_CPU_ACCESS_WRITE).

You either want to use D3D10_MAP_READ_WRITE (remember that reading from GPU memory is SLOW) or re-generate the vertices from scratch.

Do I need to keep the vertices data in an array and then recreate a vertex buffer?



D3D10_MAP_WRITE_DISCARD


D3D10_MAP_WRITE_DISCARD

Resource is mapped for writing; the previous contents of the resource will be undefined. The resource must have been created with write access (see D3D10_CPU_ACCESS_WRITE).

You either want to use D3D10_MAP_READ_WRITE (remember that reading from GPU memory is SLOW) or re-generate the vertices from scratch.

Oh wow totally missed that. mdias is right. The data in your Vertex* v is undefined. Your code v.pos+displacement adds a value to v which is undefined. You should have the position value, along with the rest of the data in your vertex buffer, saved in system memory then use those values to assign it to v[].

So it should look something like this:


// This is stored somewhere in system memory
VertexData m_vertices;

Vertex* v = 0;
mVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&v );
 
for(int i = 0;i < mNumVertices;i++)
{
   // Update position
   m_vertices[i].pos += displacement;

   // Replace new data
   v[i].pos = m_vertices[i].pos;
   // Also replace the rest of the attributes as well.. (color, normal, texCoord, etc...)
}

The reason why its probably flickering is that the api will give you a system memory with the values you initially assigned to the vb in one frame then the next frame the api will give you a totally different system memory with garbage values (resulting in a position with crazy values off the screen).

Thanks for the heads up mdias!

if the data is undefined so why does the box still moving when i press a key ?

thank a lot it worked but i still don't know why it moved with flickers when the data was not defined

This topic is closed to new replies.

Advertisement