Archived

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

Raloth

setting bytes in a locked texture

Recommended Posts

Raloth    379
I've gone over this code twenty times, searched all over, and I can't find what is wrong.
	D3DLOCKED_RECT texture;
	alphamap->LockRect(0,&texture,NULL,D3DLOCK_DISCARD);
	BYTE* pBits = (BYTE*)(texture.pBits);
	for(int i=0;i<256;i++) {
		for(int j=0;j<256;j++) {
			pBits[j*texture.Pitch + i*4 + 2] = alphavalues[0][ i ][j];
			pBits[j*texture.Pitch + i*4 + 1] = alphavalues[1][ i ][j];
			pBits[j*texture.Pitch + i*4 + 0] = alphavalues[2][ i ][j];
			pBits[j*texture.Pitch + i*4 + 3] = alphavalues[3][ i ][j];
		}
	}
	alphamap->UnlockRect(0);  
The alphavalues array is made of BYTEs. Nothing crashes and it ends up filling all the data, but it isn't in the right place. It ends up scattered around the texture at equal intervals. What am I missing? [edited by - Raloth on January 24, 2004 6:49:06 PM]

Share this post


Link to post
Share on other sites
Morten    139
for(int i=0;i<256;i++)
{
for(int j=0;j<256;j++)
{
pBits[(j * texture.Pitch + i) * 4 + 2] = alphavalues[0][ i ][j];
pBits[(j * texture.Pitch + i) * 4 + 1] = alphavalues[1][ i ][j];
pBits[(j * texture.Pitch + i) * 4 + 0] = alphavalues[2][ i ][j];
pBits[(j * texture.Pitch + i) * 4 + 3] = alphavalues[3][ i ][j];
}
}


Should work better, I think..

-Morten-

Share this post


Link to post
Share on other sites
Morten    139
When the texture gets uploaded to video memory it usually gets swizzled, so it better fits the texel-cache hardware. I was just wondering if the driver got it wrong doing that operation. If there''s a problem with that, though, I''d be very surprised (needs a bug doing some fancy page fault thing to mark the area of the texture you''ve just scribbled to).

-Morten-

Share this post


Link to post
Share on other sites
Raloth    379
Here''s a screenshot of the problem:

http://www20.brinkster.com/raloth/texturelock.jpg

It''s supposed to be all red with a 32x32 bit of yellow in the top left, but it comes out like that. Making the 32x32 bit bigger makes the dots get bigger.

Share this post


Link to post
Share on other sites
Morten    139
How is the alphavalues array made?
What does it look like if you run :

memset(alphavalues, 255, 256 * 256 * 4);
for(int i = 0; i < 32; ++i)
for(int j = 0; j < 32; ++j)
alphavalues[2][ i ][j] = 0;

with the original indexing?

If that looks fine (all white with some "secondary colour" 32x32 square), the array isn't layed out like you think it is.

-Morten-

[edited by - morten on January 24, 2004 10:04:15 PM]

[edited by - morten on January 24, 2004 10:08:48 PM]

Share this post


Link to post
Share on other sites
Raloth    379
Nope, still all spotted. I did the same thing to get my red/yellow spots.

[edit] Out of desparation I put it on the reference driver. Instead of being spotted now, it crashes as soon as I try setting the bytes in the texture.

[edited by - Raloth on January 24, 2004 10:17:54 PM]

Share this post


Link to post
Share on other sites
Morten    139
alphavalues type _is_ BYTE alphavalues[4][256][256]?

(just making sure..)

Either way, what does this do?

BYTE* pBits = (BYTE*)(texture.pBits);

for(int i = 0; i < 256; ++i)
memset(pBits + i * texture.Pitch, 255, 256 * 4);

for(int i = 0; i < 32; ++i)
for(int j = 0; j < 32; ++j)
pBits[j*texture.Pitch + i*4 + 2] = 0;

(with the lock ofcourse..)


-Morten-

Share this post


Link to post
Share on other sites
Raloth    379
< insert every swear word out of every language ever >

I had forgotten I told my texture to repeat across the quad. It has been working this entire time...

[edit] unedited, it was fine again

[edited by - Raloth on January 24, 2004 10:35:43 PM]

Share this post


Link to post
Share on other sites