Sign in to follow this  
flip_mo_kid

creating mip maps with rendertargets

Recommended Posts

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

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
I believe that the auto mip map is generated at texture creation time and may not apply to render targets. Take a look at GenerateMipSubLevels to force the creation of the mips. Though you may not be able to access the sublevels of a texture in graphics memory you really ought to be able either to copy them to a surface you can access or access them directly if they are in system memory. I use D3DXLoadSurfaceFromSurface to copy my render targets from the default to the managed pool. If you really need to do this and are not concerned with performance (if you are reading back a render target you have probably abandoned any idea of perforance already) you can generate the equivelent of a mip level by adjusting the rectangles passed to D3DXLoadSurfaceFromSurface and specifing a filter.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this