• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

digitalfreak

question about the IDirect3DVertexBuffer9::Lock(...)method

8 posts in this topic

if I create a vertex buffer with
IDirect3DVertexBuffer9* _vb;
 
then use
_vb->Lock(0, 0, (void**)&v, 0);
 
where v is a pointer to a user defined vertex type. and then is the code to fill in v with vertices data. I don''t understand the relationship between _vb and v. to be precise, why don''t we fill in the vertices data directly to _vb instead of using another piece of memory created at v? we''ve alread set aside memory when creating _vb with the IDirect3DDevice9::CreateVertexBuffer method, didn''t we?
0

Share this post


Link to post
Share on other sites
I''m not sure, but my guess is that you can''t make the CPU write to video memory that easily. Locking, copying to system memory, and then having DX copy that to video memory probably saves you from doing a lot of extra coding to get it into video memory directly.
0

Share this post


Link to post
Share on other sites
Look at it this way: a vertex buffer in D3D isn''t just an array of vertices. It is essentially an extended COM object, and as such, it has a whole bunch of member variables and internal data that it keeps track of. That data is used by D3D internally when you want to render your geometry.

Think of the Lock call as returning a pointer to the chunk of memory inside the D3D Vertex Buffer where all the vertices will actually be stored. With this pointer, you can store specific vertices inside the Vertex Buffer object (which is usually in video memory).

Although you don''t *really* have a pointer to video memory, because video memory cannot be addressed directly by the CPU, the driver takes care of all this and to the programmer, it seems as though they''re writing directly to video memory.

neneboricua
0

Share this post


Link to post
Share on other sites
Hi, I''ve been thinking about almost the same thing, the &v would have been initialised as a void pointer;
VOID *v; //

my question is what does (void++)&v mean, (void**) is a cast, so you are casting the address of v,- &v to a pointer to a pointer, I don''t want to try and get thinhgs confused but that''s is what it seems to me.

Using dx8 it look like this,

VOID* pVertices;
g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 )
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
g_pVB->Unlock();

I''m really trying to get at what happens under the surface, because this is used alot in dx, xof files use it as well to access all the data objects ect.

Thanks.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Stevieboy
...what does (void++)&v mean, (void**) is a cast, so you are casting the address of v,- &v to a pointer to a pointer,


Pretty much, a pointer to a pointer to untyped data (void) to be a bit more specific.

The thing is what is the data in a vertex buffer? It is a list of vertices right, but your vertices are not necessarily of any particular format. They might just be a position (3 floats) they might be a position and a texture coordinate (3+2 floats). Positions, normals, up to 8 texture coordinates, colors, blah, blah ,blah: they have a wide range of formats and sizes. There are several possible ways to deal with this. DirectX usually uses what I think is the C way of doing it. They store the type (FVF) the size in bytes (which given the fvf gives you vertices as well) and store the data as an untyped block of memory (void). Then you have to somehow figure out what the type is before you can use the data (maybe it has a member that describes the fvf? can't remember).

Edit: yea it does have an fvf member.


[edited by - JeffF on March 11, 2004 1:19:17 PM]
0

Share this post


Link to post
Share on other sites
Hi, I've been thinking about almost the same thing, the &v would have been initialised as a void pointer;
VOID *v; //

my question is what does (void**)&v mean, (void**) is a cast, so you are casting &v to a pointer to a pointer, I don't want to try and get thinhgs confused but that's is what it seems to me.

Using dx8 it look like this,

VOID* pVertices;
g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 )
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
g_pVB->Unlock();

I'm really trying to get at what happens under the surface, because this is used alot in dx, xof files use it as well to access all the data objects ect.
Thanks.



sorry about posting twice my browser closed down just as I posted the first time, sorry




sorry about posing twice, my

[edited by - Stevieboy on March 11, 2004 1:22:26 PM]
0

Share this post


Link to post
Share on other sites
quote:
Original post by Stevieboy
my question is what does (void**)&v mean, (void**) is a cast, so you are casting &v to a pointer to a pointer, I don't want to try and get thinhgs confused but that's is what it seems to me.



Yes you are casting &v to a pointer to a pointer (to untyped data).
So clearly v should also be a pointer (usually to the data type you want and know it to be, your vertex type).

Now if you happened to have defined v as void* &v is already a void**, so the cast is redundant.

Typically you want v to be a more usefull type, like your vertex type so you can do the cast just once when getting the data, rather than each time you try to use it.

so it would be:
MyVertex* pvbdata; // somehow I know that _vb is of type MyVertex. Maybe I checked the vertex buffer desc structure, maybe some other way
_vb->Lock(0, 0, (void**)&pvbdata, 0);



Edit: heh ok, well I answered twice already

[edited by - JeffF on March 11, 2004 1:36:44 PM]
0

Share this post


Link to post
Share on other sites
The vertexbuffer hold a chunk of memory, but hides it from you where it actually is. When yuo lock it, especially if you lock it with D3DLOCK_DISCARD it will give you a pointer where you can work with the data. But this can be another location than the last time you used it. You don''t know what it will do, it might transfer the data to the video card, or keep a copy in local memory. When you use D3DLOCK_DISCARD, it will give you a new piece of memory you can fill while holding on to the old data to render while you work with it, then when you unlock it it will discard the old data and work with the new data.
0

Share this post


Link to post
Share on other sites