Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Is VertexBuffer Lock/Unlock appropriate in this case?


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
6 replies to this topic

#1 Prasoon Pankaj   Members   -  Reputation: 104

Like
0Likes
Like

Posted 17 April 2011 - 01:03 PM

In my render loop I'm trying to change alpha value overtime to make objects to fade-in/out:

var blendedFillColor = /* color remains the same, just changing the alpha value */;
var vertices = (CustomVertex.TransformedColored[])_vertexBuffer.Lock(0, 0);
for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++)
{
    vertices[vertexIndex].Color = blendedFillColor.ToArgb();
}
_vertexBuffer.Unlock();

dxDevice.SetStreamSource(0, _vertexBuffer, 0);
dxDevice.VertexFormat = CustomVertex.TransformedColored.Format;
dxDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

Is Lock() and Unlock() operation on the vertex buffer a performance hit? And also can I avoid it in my case?

Sponsor:

#2 kdmiller3   Members   -  Reputation: 176

Like
1Likes
Like

Posted 17 April 2011 - 01:20 PM

It's a performance cost, but pretty much an unavoidable one. You might be able to change some shared color somewhere or use some clever shader tricks, but building vertices at runtime is pretty much the simplest way to submit sprites and particles. You should be fine as long as you keep the number of Lock() and Unlock() calls to a minimum. For example, Lock() once, submit a bunch of geometry, Unlock(), and then call DrawPrimitive to draw everything.

#3 lotusf1   Members   -  Reputation: 137

Like
1Likes
Like

Posted 17 April 2011 - 01:26 PM

Unlocking/locking the vertex buffer is a bad idea for performance reasons as kdmilller said. This is a perfect example of needing a vertex/pixel shader.

#4 smasherprog   Members   -  Reputation: 432

Like
0Likes
Like

Posted 17 April 2011 - 04:13 PM

Instead of changing the information per vertex, why not set an alpha value per object? There isnt a need to change it per vertex when it can be set in the shader.
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

#5 Prasoon Pankaj   Members   -  Reputation: 104

Like
0Likes
Like

Posted 17 April 2011 - 10:59 PM

Instead of changing the information per vertex, why not set an alpha value per object? There isnt a need to change it per vertex when it can be set in the shader.


Can you please share few links to the stuff you are talking about? Or may be a sample code to illustrate.

#6 smasherprog   Members   -  Reputation: 432

Like
1Likes
Like

Posted 18 April 2011 - 07:20 AM

http://msdn.microsoft.com/en-us/library/bb206368%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/ee416223%28v=vs.85%29.aspx

You should research ID3DEffect for directx
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

#7 Prasoon Pankaj   Members   -  Reputation: 104

Like
0Likes
Like

Posted 22 April 2011 - 11:44 AM

It was giving me some hit. So, I changed the logic to use CustomVertex.Transformed[] and used the following logic in my render loop:

var blendedFillColor = /* color remains the same, just changing the alpha value */;

device.TextureState[0].ConstantColor = blendedFillColor;
device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
device.TextureState[0].ColorArgument1 = TextureArgument.Constant;
device.TextureState[0].AlphaArgument1 = TextureArgument.Constant;

device.SetStreamSource(0, this._vertexBuffer, 0);
device.VertexFormat = CustomVertex.Transformed.Format;
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

Anything you guys wanna suggest?






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