glCompressedTexImage2D and mip-maps.

Started by
6 comments, last by petya-kurochkin 13 years, 5 months ago
Hello all! For begin, sorry for my english.
I had tried to load compressed textures and I have done it successfully.
I have dds-texture with the following format:
512x512 DXT5
256x256 DXT5
...
4x4 DXT5.

I was loading compressed data by glCompressedTexImage2D.
It realy loads my texture and do it successfully (glGetError() returns 0 after glCompressedTexImage).
But...
When I try to load data for 1st mipmap level, glGetError() returns 1208 (0x500). What do I do wrong?

I had seen my code with debugger, and I have seen the following calls:

glCompressedTexImage2D(GL_TEXTURE_2D, 0, uiFormatGL,
512, 512,
0, 512*512, pData);

glCompressedTexImage2D(GL_TEXTURE_2D, 0, uiFormatGL,
256, 256,
0, 256*256, pData);

glCompressedTexImage2D(GL_TEXTURE_2D, 0, uiFormatGL,
128, 128,
0, 128*128, pData);

uiFormatGL - it is GL_COMPRESSED_RGBA_S3TC_DXT5_EXT (don't forgive - my picture have dxt5 compression).
Advertisement
Quote:
glCompressedTexImage2D(GL_TEXTURE_2D, 0, uiFormatGL,
256, 256,
0, 256*256, pData);

I don't understand, is this supposed to be the mipmap? You're sending all 3 calls to mipmap level 0. I guess I don't really understand what you're doing, can you post your full code (not just the opengl calls).
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Oh... Sorry, I have posted wrong code, of course.

Full code will not give you anything information. OpenGL call has became return nothing errors, when I did 0 and 1 mipmap levels quivalents:

It's my code:
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_uiTexture);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, header.dwMipMapCount);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLuint width = 512;
GLuint uiDataSize = width*width;
pData = new GLchar[uiDataSize];
file.read((char*)pData, uiDataSize);
glCompressedTexImage2D(GL_TEXTURE_2D, 0, uiFormatGL,
width, width,
0, width*width, pData);
int iError = glGetError();
glCompressedTexImage2D(GL_TEXTURE_2D, 1, uiFormatGL,
width, width,
0, width*width, pData);
iError = glGetError();
width = 256;
uiDataSize = width*width;
pData = new GLchar[uiDataSize];
file.read((char*)pData, uiDataSize);
glCompressedTexImage2D(GL_TEXTURE_2D, 2, uiFormatGL,
width, width,
0, width*width, pData);
iError = glGetError();

It returns nothing errors, but it not use mipmaps... Why?..
Are you sending the same pdata to all mipmap levels? If you want to manually load mipmaps you have to first load a 512x512 texture, then a 256x256 one, then 128x128.

It looks like you're sending a 512x512 data texture to all three levels, which is illegal. If you just want to generate mipmaps, you can use a function to build it for you automatically, you don't have to load them all yourself:

Quote:
Automatic mipmap generation

It is often useful to auto-generate a mipmap set from just the base mipmap level in the previously defined range. How exactly the implementation does filtering for mipmap generation is implementation-dependent. You do not have to call the glTexImage* functions to allocate storage for the mipmaps to be generated; OpenGL will handle that detail for you.

Before you can generate mipmaps, you must set the base mipmap level as above. And you must actually put data in that level. If you are generating mipmaps for cubemaps, you must have put data into all 6 faces of the cubemap.

Then, call this function:

void glGenerateMipmap( GLenum target );

This will cause the texture bound to target to have its mipmap levels below the base level auto-generated. The base level and max level range is observed; the base level will not change, and all levels below it will be generated, down to the max level. Any mipmap levels defined outside of the base/max range will not be changed.


http://www.opengl.org/wiki/Texture#Automatic_mipmap_generation
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
karwosts, oh no, no, no, no, no, no!
I had made mistake at my first post (in code) and you have undestood me wrong!

I try to load a __different__ mip-map levels:
level 0: 512x512.
level 1: 256x256
level 2: 128x128
level 3: 64x64
level 4: 32x32
level 5: 16x16
level 6: 8x8
level 7: 4x4

Therefore, I call "glCompessedTexImage" 8 times. But! After second call glGetError() returns 0x500 (1208) and I don't understand - why?
My code was (in first post a have written whis with error, yes):
glCompressedTexImage2D(GL_TEXTURE_2D, 0, uiFormatGL,
512, 512,
0, 512*512, pData);

glCompressedTexImage2D(GL_TEXTURE_2D, 1, uiFormatGL,
256, 256,
0, 256*256, pData);

glCompressedTexImage2D(GL_TEXTURE_2D, 2, uiFormatGL,
128, 128,
0, 128*128, pData);

But it generates error on second string...
Therefore, I have tried to load equivalents images to 0 and 1 mipmap-level, but in 2,3,4 and other's mip-levels load realy mip-maps, begin from 2.
This doesn't generate error, but it doesn't work.

pData = new GLchar[uiDataSize];
file.read((char*)pData, uiDataSize);
glCompressedTexImage2D(GL_TEXTURE_2D, 0, uiFormatGL,
width, width,
0, width*width, pData);
int iError = glGetError(); //returns 0
glCompressedTexImage2D(GL_TEXTURE_2D, 1, uiFormatGL,
width, width,
0, width*width, pData);
iError = glGetError(); //returns 0
width = 256;
uiDataSize = width*width;
pData = new GLchar[uiDataSize]; //ofcourse, it is memory leak
file.read((char*)pData, uiDataSize);
glCompressedTexImage2D(GL_TEXTURE_2D, 2, uiFormatGL,
width, width,
0, width*width, pData);
iError = glGetError(); //returns 0
It is run without errord, but I see only white rectangle :(

Karwost, I must to load my mip-maps by myself, not automatically, because my mip-maps... Is maps, it is not simply filtrated same texture.

[Edited by - petya-kurochkin on November 12, 2010 11:01:54 PM]
It's full fragment of texture loader:
http://www.everfall.com/paste/id.php?6fg5a8yq8bf3
At now, glGetError is not returning errors (always returns 0), but mip-mapping doesn't work.
I have different (logical) images on different mip-map layers. But it draws (when i'm scaling) only one image.
This line is disabling your mipmapping:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

You need the min filter to be GL_NEAREST_MIPMAP_LINEAR, which is actually it's default state, but you probably grabbed some generic texture code from somewhere where they weren't using mipmaps, so they set the minifying function to be linear.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Karwosts, thanx, bro :) Only you and other one good guy resolved my (common) problem. And I have returned only in order to thanks you. Really! Good bye!

This topic is closed to new replies.

Advertisement