Sign in to follow this  
irreversible

Manually mipmapping 3D textures

Recommended Posts

I'm successfully using 3D multitexturing. To reduce visual clutter I thought I'd mipmap the damn thing. It seems I underestimated the problem: 1) generating mipmaps using glTexParameteri(GL_TEXTURE_3D, GL_GENERATE_MIPMAP, TRUE) works, but looks quite simply horrible. Well, that was my test case anyway to see if the Intel GMA I'm on actually supports something as fancy as 3D mipmaps. It does. 2) I know that maintaining the R dimension is not supported when creating 3D mipmaps (which is also what causes the above case to look horrible. However, I did remember noticing something about an extension that might be useful to fight that. But I don't know what it is. Something about anisotropic filtering AFAIR.) 3) Using shaders, which would be my first choice, is out right now because of the Intel GMA is what I'm on (which doesn't support shaders). And I can't really upgrade the card for a few reasons. Truth is that doesn't even matter - it seems to me it's not impossible to get this working without shaders and I'dlike to accomplish that. 4) I did write the code to create the mipmaps manually (both with depth reduction and without - see below), and it turned my texture blank white. Sample code: creates the depth reduced mipmaps. In its current state it's making each mipmap a different color (for testing purposes). Does not work - turns the texture white. Original 3D texture depth is 4.
        iNumMipMapLevels = 1;
	BYTE clr[5][3] = { { 255, 128, 255 }, { 255, 0, 0 }, { 255, 255, 0 }, { 255, 0, 255 }, { 0, 255, 255 } };
        WIDTH = 128;
        HEIGHT = 128;
        DEPTH = 4;

        //... successfully load and create the 3D texture ...

	for(DWORD miplevel = 0; miplevel < iNumMipMapLevels; miplevel++)
		{
		DWORD iMipWidth = WIDTH >> (miplevel + 1);
		DWORD iMipHeight = HEIGHT >> (miplevel + 1);
		DWORD iMipDepth = DEPTH >> (miplevel + 1);

                //over-allocation - I'm aware of this :P
		BYTE* mipmap = new BYTE[iMipWidth * iMipHeight * DEPTH * 3];

                //fill the mip image with a color
		for(DWORD y = 0, index = 0, srcindex = 0; y < iMipHeight; y++)
			{
			for(DWORD x = 0; x < iMipWidth; x++, index += 3)
				{
				for(DWORD i = 0; i < 3; i++)
					{ mipmap[index] = clr[miplevel][i]; }
                                }
			}

		glTexImage3D(GL_TEXTURE_3D, miplevel + 1, GL_RGB8, iMipWidth, iMipHeight, iMipDepth, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmap);
		}

Does anyone have any experience regarding this? Or, to recap the problem: how do I get manual 3D mipmaps working without using shaders?

Share this post


Link to post
Share on other sites
I havent done it but that codes not gonna work

try something like (u can improve speed lots), also obviously u need to change from 1d to 3d


for (all mipmap levels )
{
int width_ratio = width / mipmap_width;
glubyte *image = new glubyte[ mipmap_width ];

for ( int I=0; I<mipmap_width; I++ )
{
image[I] = 0;
for ( int i=I*width_ratio; i<(I+1)*width_ratio; i++ )
image[I] += originalimage[i] / width_ratio;

}
glTexImage3D(GL_TEXTURE_3D, miplevel + 1, GL_RGB8, iMipWidth, iMipHeight, iMipDepth, 0, GL_RGB, GL_UNSIGNED_BYTE, image);




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