Skip to main content
gamedev.net
🔒 Locked

D3DVertexBufferSetData

Started by Tom 2 replies 350+ views
Original Post
Tom
Tom
Hi. My working environment is DX8 and VB6. The documentation on D3DVertexBufferSetData (D3DX) looks basically like this: D3DVertexBuffer8SetData( _ VBuffer As Direct3DVertexBuffer8, _ Offset As Long, _ Size As Long, _ Flags As Long, _ Data As Any) As Long The SDK makes absolutely no mention of how this method is used, so here''s what I''m assuming: I can pass an array of any data type (hence the keyword "Any") and specify how many bytes I want copied in the Size parameter. D3DX will then copy that number of bytes into my vertex buffer at the given offset. Is this correct? Thanks for your help.
GDNet+. It's only $5 a month. You know you want it.
Tom
Tom
Now that I think of it, would it be faster to Lock a vertex buffer, iteratively add data to it, and Unlock it; or would it be faster to iteratively assign my vertex to an array, and then add it all in one shot using D3DVertexBufferSetData? I don''t know how optimized D3DVertexBufferSetData is.
GDNet+. It's only $5 a month. You know you want it.
Tom
Tom
I was mistaken about D3DVertexBufferSetData being part of D3DX; it''s actually one of D3D''s built-in functions.

You''re right on the money: the SDK mentions no C++ equivalent. Apparently D3DVertexBufferSetData is the Visual Basic equivalent of locking a buffer in C++. Visual Basic has no type-casting mechanism built into the language, which makes a Lock call all but useless since the data type it returns is Long, and most vertex data is Single (float).

Short answer: the only solution is to dump my vertices into an intermediate array and call D3DVertexBufferSetData to copy it over to a vertex buffer. This is incredibly wasteful, but it appears to be my only option short of jumping through hoops to do a type-cast. I have one last question, however:

Do I need to provide a correct size for my buffer when I create it? Or will DirectX automatically resize buffers created with D3DUSAGE_DYNAMIC during the D3DVertexBufferSetData call? This would be very convenient, but somehow I don''t expect it.

Thanks for your help.
GDNet+. It's only $5 a month. You know you want it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.