Direct3D Lock/Unlock...

This is a discussion on Direct3D Lock/Unlock... within the Game Programming forums, part of the General Programming Boards category; I'm having a really hard time grasping these simple little things in D3D. Anywho, why does this work: Code: WORD* ...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up Direct3D Lock/Unlock...

    I'm having a really hard time grasping these simple little things in D3D. Anywho, why does this work:

    Code:
    	WORD* k = 0;
    
    	HR(mIB->Lock(0, 0, (void**)&k, 0));
    
    	WORD* b = mesh.GetIndexList();
    
    	// loop through and put in individually
    	for ( UINT i = 0; i < mesh.GetIndexCount(); ++i )
    		k[ i ] = b[ i ];
    
    	HR(mIB->Unlock());
    and this doesn't:

    Code:
    	WORD* k = 0;
    
    	HR(mIB->Lock(0, 0, (void**)&k, 0));
    
    	// put in all at once
    	WORD* k = mesh.GetIndexList();
    
    	HR(mIB->Unlock());
    assuming mesh.GetIndexList() returns a WORD* to an already-prepared array index list. Aren't these doing the same thing or have I got something different wrong altogether?

    Thanks.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    What exactly are you confused about? Since I do not know what GetIndexList() does it is impossible for me to help without more information.

    I will say that the lock()/unlock() is essentially when the data is sent to the graphics card VRAM.

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Hmm... I guess my question is, what does Lock and Unlock do?

    Code:
    	WORD* k = 0;
    
    	HR(mIB->Lock(0, 0, (void**)&k, 0));
    
    	k[0] = 0; k[0] = 1; k[2] = 2;
    
    	HR(mIB->Unlock());
    In this example here, does Lock (the 3rd parameter) change where "k" is pointing to from the RAM to the VRAM? And does this mean the Unlock de-points it back to the RAM?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I guess the difference between your original a and b is that the first is more akin to a memcopy (in fact, I'm pretty sure it could just as easily be a memcopy, assuming there's not something hardware going on) while the second makes k point somewhere else. If k is pointing somewhere specific, then you've just destroyed all that. (I don't actually know anything specific about lock, but if you're passing k in as a **, then presumably at the end of the function, k points somewhere specific.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why use Direct3D?
    By m3rk in forum Tech Board
    Replies: 42
    Last Post: 05-22-2009, 10:08 AM
  2. Need help with getting DirectX 9.0 initilization
    By DarkMortar in forum Windows Programming
    Replies: 7
    Last Post: 05-09-2006, 09:58 PM
  3. Creating a 2D GUI using Direct3D
    By codec in forum Game Programming
    Replies: 8
    Last Post: 09-23-2004, 12:57 PM
  4. DIRECTDRAW DIRECT3d
    By samsam1 in forum Game Programming
    Replies: 3
    Last Post: 01-14-2003, 07:28 PM
  5. Direct3D vs. OpenGL
    By PorkyChop in forum Game Programming
    Replies: 22
    Last Post: 12-08-2002, 12:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21