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.


RECT rect not being enforced.


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

#1 DarkRonin   Members   -  Reputation: 614

Like
0Likes
Like

Posted 24 February 2014 - 10:30 PM

Hi Guys,

I am in the process of making a dynamic texture using LockRect() which is all working well. Except the boundaries of the rectangle are not being enforced.

I have specified the 'rect' to be 8x8 (so a total of 64 pixels).

With the following code I would expect it to give me an 8x8 white cube. But, all I get is a single line that is 64 pixels long.
 
RECT rect;
rect.top=0;
rect.left=0;
rect.right=8;
rect.bottom=8;

D3DLOCKED_RECT lockedRect={0};
hr=mRenderer->textureVideoGet()->LockRect(0,&lockedRect,&rect,0);
if(FAILED(hr))
{
	std::cout<<hr<<"\r\n";
	system("PAUSE");
	return 0;
}

unsigned char* bytes=(unsigned char*)lockedRect.pBits;

for(i=0;i<64*4;i++)			// 64*4 = 4 bits per pixel ARGB
{
	bytes[i]=255;			//b
	bytes[i+1]=255;			//g
	bytes[i+2]=255;			//r
	bytes[i+3]=255;			//a
}

mRenderer->textureVideoGet()->UnlockRect(0);
Any ideas as to why the 'rect' isn't being enforced would be awesome!

Edited by lonewolff, 24 February 2014 - 10:32 PM.


Sponsor:

#2 Nik02   Crossbones+   -  Reputation: 2881

Like
0Likes
Like

Posted 24 February 2014 - 10:52 PM

You (incorrectly) assume that the pitch of the locked area equals (locked area width*bytes per pixel).


Edited by Nik02, 24 February 2014 - 10:53 PM.

Niko Suni


#3 DarkRonin   Members   -  Reputation: 614

Like
0Likes
Like

Posted 24 February 2014 - 11:01 PM

You are correct.

I had added pitch to my code a few minutes ago. But in this case the assumption was correct, so that is not the root cause of this particular problem, unfortunately.

#4 Nik02   Crossbones+   -  Reputation: 2881

Like
0Likes
Like

Posted 24 February 2014 - 11:21 PM

The pitch is the scanline width of the whole surface, regardless of the dimensions of the locked rectangle.

 

The pointer you get from lock is to the whole surface data, offset by the rectangle's top left (even if you specify a rectangle), but you can only expect meaningful access to those pixels that fall inside your rectangle. Writing outside the rect (which is what you happen to do) results in unspecified behavior. In this case, the GPU or driver just doesn't care, since you still write to that resource's memory - even though all of it is not within your rect.


Edited by Nik02, 24 February 2014 - 11:29 PM.

Niko Suni


#5 fastcall22   Crossbones+   -  Reputation: 4387

Like
0Likes
Like

Posted 24 February 2014 - 11:26 PM

It won't help, but you've a bug and a buffer overrun in your code:

for ( i=0; i+3 < 64*4; i+=4 ) {
	bytes[i] = 255;
	bytes[i+1] = 255;
	bytes[i+2] = 255;
	bytes[i+3] = 255;
}
Have you checked the HRESULT of UnlockRect?
c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#6 mhagain   Crossbones+   -  Reputation: 8141

Like
0Likes
Like

Posted 25 February 2014 - 12:46 AM

For this kind of update you may find it easier to Lock the entire texture with D3DLOCK_NO_DIRTY_UPDATE then call AddDirtyRect when done.  That can be useful if you're updating more than one region of the texture - instead of multiple updates, everything is consolidated into a single update and can run much faster.  Use the Windows SetRect call to initialize a RECT representing a region on the texture, and UnionRect to accumulate RECTs representing the entire dirty region.  Don't worry too much if the final full RECT contains portions of the texture that you didn't touch - a single big update is going to be MUCH faster than many many small updates, even if it contains unnecessary extra data.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





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