Sign in to follow this  

Setting texture coords at runtime

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Currently, I have a vertex array then update their u, v coords, lock vertex buffer, copy vertices to buffer, unlock buffer, the usual stuff. Is this correct? Am I doing it right? Is there a better way to do this?

Share this post


Link to post
Share on other sites
Your method should work.

You can also set the coords directly using the buffer pointer returned by Lock.

Something like:

YOURVERTEXTYPE *pV;

VB->Lock(0,sizeofBuffer,&pV,0);

pV[numberOfVertexToUpdate]->texCoord = D3DXVECTOR2(newTU, newTV);

VB->Unlock();

That would save copying time.

Share this post


Link to post
Share on other sites
depends on how you do it. Use dynamic buffers, lock with nooverwrite as much as you can. Google has plenty on this topic as well as the d3d documentation if you don't mind doing a little search.

Share this post


Link to post
Share on other sites
Your method should work as BuckEye suggested.
You always want to decrease locking/unlocking to the minimum. Doing any calculation per frame is not performant.

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
1a. I agree with amigocz. If what you want to do to the texture coordinates can be expressed as a matrix transformation (scrolling/translation, scaling, rotation, projection, etc) then you can simply apply the matrix to any texture coordinates in a vertex shader. The matrix goes in a shader parameter and the vertex shader does the work.

1b. If you're stuck with the legacy DX9 fixed function pipeline for some reason, then that supports some texture coordinate transformation too (check out the "Texture Coordinate Transformations (Direct3D 9)" section of the DirectX SDK docs).

1c. If you're using shaders, you are of course not limited to simple linear transformations - many things you can do to a locked vertex buffer in C/C++/C# can be expressed in HLSL in a shader.


2a. Vertex buffer locks are not slow. But badly used vertex buffer locks can cause serious performance problems. A badly used lock can cause the GPU to stall waiting for the CPU, the CPU to stall waiting for the GPU, and generally throw away any parallelism you gain from having the GPU do any work.

2b. To not lock badly/stall you need to use dynamic vertex buffers and use them properly take a look at the "What's a good usage pattern for vertex buffers if I'm generating dynamic data?" topic in the "DirectX Frequently Asked Questions" technical article in the DirectX SDK documentation.

Share this post


Link to post
Share on other sites

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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