creating mip maps with rendertargets

Started by
9 comments, last by turnpast 18 years, 11 months ago
Hi, I've tried creating mipmaps (by using autogen and by specifying the number of levels) with rendertargets but when I call getLevelCount() it always returns 1. I've read that it is possible to do this but it doesn't work on either my 9600Pro or my 6600GT. Can anyone give me a code snippet or information on how to set this up? Thanks
Advertisement
hi flip_mo_kid,
could you please paste your code so we can have a look at it?

Code snippit from the SDK Docs:
// This code example assumes that m_d3dDevice is a
// valid pointer to a IDirect3DDevice9 interface

IDirect3DTexture9 * pMipMap;
m_pD3DDevice->CreateTexture(256, 256, 5, 0, D3DFMT_R8G8B8,
D3DPOOL_MANAGED, &pMipMap);

I work within my engine with Textures as RenderTargets.
Following code for creating the Texture delivers also correct
Mipmap count with <GetLevelCount>.

unsigned nMipLevels = 2;// sTextureTree.nMipLevels;
HRESULT hr = m_pDeviceD3D->CreateTexture( nWidth, nHeight, nMipLevels, D3DUSAGE_RENDERTARGET, dwFormatD3D, D3DPOOL_DEFAULT, &pTextureD3D, NULL );

Wilfried
sorry it seems to me,that my post haven't been sent,
now it appears more than enough ;-)

Wilfried
You need to set D3DUSAGE_AUTOGENMIPMAP in addition to D3DUSAGE_RENDERTARGET if you want automatic mipmapping.

Niko Suni

EDIT:: Actually,
hr = D3DXCreateTexture( Device, 		Pixels, 		Pixels, 		0, 		D3DUSAGE_AUTOGENMIPMAP & D3DUSAGE_RENDERTARGET, 		D3DFMT_A8R8G8B8,		D3DPOOL_DEFAULT, 		&dynamicTexture);


works.. I was writing to the wrong main file (I had two open in my project as I was copying code from one to the other) WHOOPS!!

However, I am trying to copy out the pixel colour in the smallest mipmap and I have written this:

HRESULT hr;LPDIRECT3DSURFACE9 surface;LPDIRECT3DSURFACE9 tempSurface;hr = dynamicTexture->GetSurfaceLevel(dynamicTexture->GetLevelCount()-1, &surface);if( FAILED(hr) ){ // does something }D3DSURFACE_DESC desc;surface->GetDesc(&desc);Device->CreateOffscreenPlainSurface(desc.Width,                desc.Height,                desc.Format,                D3DPOOL_SYSTEMMEM,                &tempSurface,                NULL);hr = Device->GetRenderTargetData(surface, tempSurface);


and it is failing. Does anyone know if this should work?

Thanks again!

[Edited by - flip_mo_kid on May 29, 2005 12:13:06 PM]
I would think this line from the SDK docs (Automatic Generation of Mipmaps) would answer that question:

Only the top texture level is accessible to the application; the texture sublevels are not accessible since they will be created only when needed by the driver.
Quote:Original post by flip_mo_kid
D3DUSAGE_AUTOGENMIPMAP & D3DUSAGE_RENDERTARGET,


When combining multiple flags use the bitwsie or '|' operator not the bitwise and '&' perhaps counterinitutive, but that is the way that it is.
Quote:Original post by turnpast
Quote:Original post by flip_mo_kid
D3DUSAGE_AUTOGENMIPMAP & D3DUSAGE_RENDERTARGET,


When combining multiple flags use the bitwsie or '|' operator not the bitwise and '&' perhaps counterinitutive, but that is the way that it is.


I did that first actually and the level count was still 1! When I changed to the & (the first time I've ever done this to cover all bases) it worked. Rather odd really.
Very odd indeed as using the '&' most likely produces an empty flag set or 0.

This topic is closed to new replies.

Advertisement