Jump to content

  • Log In with Google      Sign In   
  • Create Account

object flickering


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 shavitpriens   Members   -  Reputation: 128

Like
0Likes
Like

Posted 26 July 2013 - 10:16 AM

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[i].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 ! 


Sponsor:

#2 BrentChua   Crossbones+   -  Reputation: 1066

Like
0Likes
Like

Posted 26 July 2013 - 11:13 AM

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


Edited by BrentChua, 26 July 2013 - 11:13 AM.


#3 shavitpriens   Members   -  Reputation: 128

Like
0Likes
Like

Posted 26 July 2013 - 11:19 AM

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


Edited by shavitpriens, 26 July 2013 - 11:25 AM.


#4 mdias   Members   -  Reputation: 792

Like
1Likes
Like

Posted 26 July 2013 - 12:17 PM

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.


Edited by mdias, 26 July 2013 - 12:19 PM.


#5 BrentChua   Crossbones+   -  Reputation: 1066

Like
1Likes
Like

Posted 26 July 2013 - 12:28 PM



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[i].pos+displacement adds a value to v[i] 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!


Edited by BrentChua, 26 July 2013 - 12:29 PM.


#6 shavitpriens   Members   -  Reputation: 128

Like
0Likes
Like

Posted 26 July 2013 - 12:35 PM

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?



#7 shavitpriens   Members   -  Reputation: 128

Like
0Likes
Like

Posted 26 July 2013 - 12:46 PM

 



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[i].pos+displacement adds a value to v[i] 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 ?



#8 shavitpriens   Members   -  Reputation: 128

Like
0Likes
Like

Posted 26 July 2013 - 12:55 PM

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


Edited by shavitpriens, 26 July 2013 - 12:58 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS