# Accessing mipmap memory

This topic is 4750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I asked a while ago how I could multiply two textures together and add up the results quickly on the GPU. I was advised the best way to do this would be to render a full screen quad, multitexture it with the two images I wanted to multiply (which actually performs the multiply) and then to generate mip maps all the way down to 1x1 to get the average value. Now, I have done all of that except I cannot figure out exactly what code I need to lock the 1x1 mip map memory and extract the result. Can anyone help? Thanks

##### Share on other sites
LPDIRECT3DTEXTURE pTexture = ???;D3DLOCKED_RECT LockedRect;pTexture->LockRect(pTexture->GetLevelCount() - 1, &LockedRect, NULL, D3DLOCK_READONLY);D3DCOLOR Color = ((D3DCOLOR*)LockedRect.pBits)[0];pTexture->UnlockRect(MipMapLevel);

This assumes that the texture uses D3DFMT_A8R8G8B8 or D3DFMT_X8R8G8B8, but the general concept is the same. You'll just have to change how you access pBits if it's different.

##### Share on other sites
Thanks for the speedy response!

I'm using D3DFMT_A16B16G16R16F format. I will try and find out what to change but if anyone can let me know I'd appreciate that very much.

Thanks

##### Share on other sites
Hello flip_mo_kid, I was about to get the GPU generate MIPMAP for me too, until
I got to the stage of accessing the second level MIPMAP, what I ended up with
was a blank MIPMAP (all bits in it are zero). I am not sure if you're gettin
the same problem after you generated your MIPMAP? For more details you can view
my post here.

I can't really help you here, just a little concerned with the D3DFMT, seemed
pretty rare with the cards I have seen, not sure what you are doing with it,
but I would avoid it whenever possible (so that my codes don't fail elsewhere).

##### Share on other sites
Quote:
 Original post by HaywireGuyHello flip_mo_kid, I was about to get the GPU generate MIPMAP for me too, until I got to the stage of accessing the second level MIPMAP, what I ended up with was a blank MIPMAP (all bits in it are zero). I am not sure if you're gettin the same problem after you generated your MIPMAP? For more details you can view my post here.I can't really help you here, just a little concerned with the D3DFMT, seemed pretty rare with the cards I have seen, not sure what you are doing with it, but I would avoid it whenever possible (so that my codes don't fail elsewhere).

Hi, I haven't been able to extract the data at the moment so I am unsure if it is just black or not. At present I am getting access violations when I try to get to the data. I'm not very used to extracting data from surfaces (except with standard A8R8G8B8 format. Can anyone help? (I am using D3DFMT_A16B16G16R16F)

		D3DLOCKED_RECT lockedRect;		dynamicTextureHDR->LockRect(dynamicTextureHDR->GetLevelCount() - 1,								&lockedRect,	// pointer to receive locked data								0,				// lock entire surface								0);				// no lock flags specified		D3DXFLOAT16 *float16Pointer = (D3DXFLOAT16*)lockedRect.pBits;			dynamicTextureHDR->LockRect(dynamicTextureHDR->GetLevelCount() - 1, &lockedRect, NULL, D3DLOCK_READONLY);			b += float16Pointer[1];		//	g += float16Pointer[2];		//	r += float16Pointer[3];		dynamicTextureHDR->UnlockRect(dynamicTextureHDR->GetLevelCount() - 1);

Also, if i want to setTexture with a specific mipmap level, what code do i use for that?

Thanks

• 16
• 9
• 13
• 41
• 15