Jump to content

  • Log In with Google      Sign In   
  • Create Account


loading time


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
39 replies to this topic

#1 q3stanky   Members   -  Reputation: 122

Like
Likes
Like

Posted 31 December 2001 - 12:33 AM

i ve a prob in my opengl project i must load textures (bmp) but i dont know why it takes so long and now i m searching a jpg loader or a way i can load textures faster like in all 3d games (i use the loading engine from http://nehe.gamedev.net) thanks

Sponsor:

#2 Scarab0   Members   -  Reputation: 122

Like
Likes
Like

Posted 31 December 2001 - 03:18 AM

Try the Intel JPEG Library. I use it and find it very fast.
You can download it here:
http://www.intel.com/software/products/perflib/index.htm

To quickly get started with it, search for EncodeJPGFileFromDIB and
DecodeJPGFileToGeneralBuffer in ijlman.pdf.

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 31 December 2001 - 05:14 AM

How many textures are you loading ? And how big are they (resolution, colour depth) ?

- AH

#4 Maximus   Members   -  Reputation: 124

Like
Likes
Like

Posted 31 December 2001 - 04:17 PM

Load times depend on more than just file format. Things like amount of free memory, memory speed, hard disk speed, cpu speed, etc all affect it.

Also, jpegs need to be read in and then decompressed, whereas bitmaps just need to be read in. Jpegs wont have as good quality neither.

-----------------------
0wn 0wn 0wn your goat
gently down the pw33n

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 31 December 2001 - 08:11 PM

You might also like to try DevIL which can be downloaded from http://openil.sourceforge.net/
It can load all sorts of graphic formats, including bmp, jpg, tga and png.

#6 q3stanky   Members   -  Reputation: 122

Like
Likes
Like

Posted 31 December 2001 - 09:43 PM

the textures are all 50 mb big and they are 40 and the biggest resuluton is 1600+1200 (the surface of mars)the textureloading would not be a prob if i can find a way to load text in the opengl engine . when i include text ca 20 lines with 10 words the engine has a performance problem so i would need a solution of this prob too

thanks

#7 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 31 December 2001 - 11:23 PM

> the textures are all 50 mb big and they are 40

You are loading 2GB textures ?!
Or did you mean, they make 50mb alltogether ?

Well I hope you meant the later. At current HD speeds, it would take around 2 to 3 seconds, if you are directly streaming your data to memory.

Something like:

fp = fopen(...);
fread(buffer, 1, 1600*1200*4 + sizeof(header), fp);
fclose(fp);


Will load a 1600*1200 32bit texture to memory in less than a second, depending on your HD speed, transfer mode, etc...
But: It loads the raw texture data, it does not decode, decompress, interprete the data. But it''s always faster to run the decompression or whatever other process you need over a memory buffer, than doing things like:


// Bad and evil example of how to not do it
//
for( y=0; y<ysize; y++) for( x=0; x<xsize; x++) {
fread(&red, 1, 1, fp);
fread(&green, 1, 1, fp);
fread(&blue, 1, 1, fp);
fread(&alpha, 1, 1, fp);
// process rgba
}


This will be slow as hell.

Jpeg might be an alternative, if your HD speed is slow, and the decompressor outperforms your HD. Depends on your HD and CPU speed, and the quality (performance) of the jpeg decompressor.

- AH




#8 q3stanky   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 January 2002 - 12:28 AM

they are 50 MB alltogether

and they need 25 seconds(athlonxp1900+,u-dma 100,7200 rpm, 256 ddr)

and 2 minutes(p3 500, u-dma 66,5400 rpm,64 mb sd ram)

and i load :

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL; if (!Filename) {
return NULL; }
File=fopen(Filename,"r");
if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}

return NULL;
}
.
.
.
.
.
.

bool Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[30]; // Create Storage Space For The Textures
memset(TextureImage,0,sizeof(void *)*30); // Set The Pointer To NULL

if ((TextureImage[ 0]=LoadBMP("Data/mars.bmp")) &&
(TextureImage[ 1]=LoadBMP("Data/sonne2.bmp")) &&
(TextureImage[ 2]=LoadBMP("Data/merkur.bmp")) &&
(TextureImage[ 3]=LoadBMP("Data/venus.bmp")) &&
(TextureImage[ 4]=LoadBMP("Data/erde.bmp")) &&
(TextureImage[ 5]=LoadBMP("Data/mars.bmp")) &&
(TextureImage[ 6]=LoadBMP("Data/jupiter.bmp")) &&
(TextureImage[ 7]=LoadBMP("Data/saturn.bmp")) &&
(TextureImage[ 8]=LoadBMP("Data/uranus.bmp")) &&
(TextureImage[ 9]=LoadBMP("Data/neptun.bmp")) &&
(TextureImage[10]=LoadBMP("Data/pluto.bmp")) &&
(TextureImage[11]=LoadBMP("Data/saturn_ringe.bmp")) &&
(TextureImage[12]=LoadBMP("Data/korona.bmp")) &&
(TextureImage[13]=LoadBMP("Data/button.bmp")) &&
(TextureImage[14]=LoadBMP("Data/button2.bmp")) &&
(TextureImage[15]=LoadBMP("Data/button3.bmp")) &&
(TextureImage[16]=LoadBMP("Data/light2.bmp")) &&
(TextureImage[17]=LoadBMP("Data/mond.bmp")) &&
(TextureImage[18]=LoadBMP("Data/flare.bmp")) &&
(TextureImage[19]=LoadBMP("Data/erde2.bmp")) &&
(TextureImage[20]=LoadBMP("Data/wolken.bmp")) &&
(TextureImage[21]=LoadBMP("Data/white.bmp")) &&
(TextureImage[22]=LoadBMP("Data/satring.bmp")) &&
(TextureImage[23]=LoadBMP("Data/s1.bmp")) &&
(TextureImage[24]=LoadBMP("Data/s2.bmp")) &&
(TextureImage[25]=LoadBMP("Data/s3.bmp")) &&
(TextureImage[26]=LoadBMP("Data/s4.bmp")) &&
(TextureImage[27]=LoadBMP("Data/s5.bmp")) &&
(TextureImage[28]=LoadBMP("Data/s6.bmp")) &&
(TextureImage[29]=LoadBMP("Data/satri.bmp")))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(30, &texture[0]); // Create Five Textures

for (loop=0; loop<30; loop++) // Loop Through All 5 Textures
{

glBindTexture(GL_TEXTURE_2D, texture[loop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);

/* // Create Linear Filtered Texturez
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[loop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
*/ }
}
for (loop=0; loop<30; loop++) // Loop Through All 5 Textures
{
if (TextureImage[loop]) // If Texture Exists
{
if (TextureImage[loop]->data) // If Texture Image Exists
{
free(TextureImage[loop]->data); // Free The Texture Image Memory
}
free(TextureImage[loop]); // Free The Image Structure
}

#9 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 January 2002 - 03:55 AM

Well, I just flew over your code, and at a first glance, I can see 3 problems:

1) Remove this *HUGE* if statement ! Replace it with a loop. It won''t affect performance (very much), but this is just horrible

2) auxDIBImageLoad(): never trust Microsoft API calls, if you are interested in speed. Make your own BMP or TGA loader, it''s very easy, and faster.

3) gluBuild2DMipmaps(): This one *kills* performance. Esp. with huge textures. I think, it is the main reason for your slow loading. Professional games do the mipmap level filtering in a precalc step, and store them along with the texture. They are then directly loaded at runtime. Though you will need your own proprietary texture fileformat for that - but it will most definitely speed things up (alot).

- AH

#10 q3stanky   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 January 2002 - 08:17 AM

thanks for this tip but i dont know how to make a compatiple bmp loader


and i dont understand tip 3



thanks

#11 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 January 2002 - 02:18 PM

AH,
Can you please explain how someone would precalc the mipmaps. Do you save multiple versions of the texure in the file.
I''m not positive of how mipmapping works. Maybe I''m thinking of the wrong thing. But is mipmapping changng the texture to make it look better from all distances?
-anonymous

#12 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 01 January 2002 - 03:21 PM

tne reason glumipmaps is slow is cause it rescales the images with a slow rescale image function.
solution. rescale the images with a faster method i believe theres a new mipmap function out there that is much faster sgis_mipmaps or something or write your own optimized rescaling function or do as AH saiz + rescale the images say with gimp and save those as well thus u read the original size texture + copies of it all the way down to 1x1 off the harddisk

http://uk.geocities.com/sloppyturds/gotterdammerung.html

#13 smitty1276   Members   -  Reputation: 560

Like
Likes
Like

Posted 01 January 2002 - 04:22 PM

Also, are you binding the textures? Or are you just loading them all one at a time?


#14 ironfroggy   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 January 2002 - 05:52 PM

can you just save each scale of the mipmapped textures as seperate images (jpegs preferably) and load them like that?

// God.c
void main() {
WORLD Earth;
LIFE People = Earth.CreateLife(HUMAN);
GiveHope(&People);
delete Earth;
EvilCackle();
}

#15 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 January 2002 - 10:04 PM

Just a little reminder, how mipmapping works:

You have your original texture (say 1024*1024, to make it easier). If the texture is scaled down alot by texturing, eg. your polygon is far away or small, then you would notice sparkeling artifacts, because the 3D hardware can only resmaple 4 textes at a time.

This is why mipmaps are used: they are scaled versions of your original texture, in such a way, that the 3D card only needs to interpolate among 4 texels at most, in any circumstance.
You create them by scaling down (resizing) your orginal texture many times, always cutting it''s size to one quarter (half resolution). Each resized version is called a mipmap level.

Example:
Original texture (level 0): 1024*1024
Mipmap level 1: 512*512
Mipmap level 2: 256*256
Mipmap level 3: 128*128
Mipmap level 4: 64*64
Mipmap level 5: 32*32
Mipmap level 6: 16*16
Mipmap level 7: 8*8
Mipmap level 8: 4*4
Mipmap level 9: 2*2
( Mipmap level 10: 1*1 ) This one isn''t really needed, but it''s in the OGL specs, so we do it anyway.

This would be a complete mipmap hierarchy. This is done for each texture. Now you can imagine, that all this scaling takes time, especially, if complex (high quality) scaling filters are used, such as bicubic interpolation. This is why gluBuild2DMipmaps() is slow.

Now, you can prebuild your mipmaps and store them along with your texture. Just create all the levels for each texture, and store them sequentially in your own texture fileformat. At runtime, you load them in, and simply bind the texture incl. all mipmaps. No gluBuild2DMipmaps() needed.

You *could* create them by hand, eg. with Photoshop or Gimp, but that''s a *lot* of work. Write a small programm that loads your original texture, and performs the resampling. It''s easy, for each level, take the level before and average 4 texels. This average value creates the new texel in your current level.

quote:

But is mipmapping changng the texture to make it look better from all distances?



Yes, that''s it.

quote:

can you just save each scale of the mipmapped textures as seperate images (jpegs preferably) and load them like that?



Yes, you could. But I would stay away from jpeg''s for mipmaps. They are +-OK for original level 0 textures, that get resampled at startup, but don''t use them as mipmap levels. The Jpeg compressor uses an internal resampling and filtering system, that defeats the purpose of well adjusted mipmaps. You will reintroduce those ugly sparkeling effects, since some frequencies are missing in the mipmap level, due to jpeg compression. PNG''s are well suited, they compress rather well (although not as good as jpeg, obviously), but they are lossless.

- AH


#16 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 January 2002 - 10:23 PM

I thought, I''d just provide a small mipmap filter. It''s not so great quality (only linear filtering), but it does the job rather well (I think just as good as gluBuild2DMipmaps). It only works for isotropic textures.

  
static void FilterMipmapsLinear(iRGBA *Src, iRGBA *Dst, int size)
{
int x, y, l, psize;

psize = size*2; // size of previous mipmap level


for(y=0;y<size;y++) for(x=0;x<size;x++) {
l=y*2*psize+x*2;
Dst[y*size+x].r = (Src[l].r+Src[l+1].r+Src[l+psize].r+Src[l+psize+1].r)/4;
Dst[y*size+x].g = (Src[l].g+Src[l+1].g+Src[l+psize].g+Src[l+psize+1].g)/4;
Dst[y*size+x].b = (Src[l].b+Src[l+1].b+Src[l+psize].b+Src[l+psize+1].b)/4;
Dst[y*size+x].a = (Src[l].a+Src[l+1].a+Src[l+psize].a+Src[l+psize+1].a)/4;
}
}


Use it like that (eg. for a 1024*1024 texture):

FilterMipmapsLinear( OriginalTexture, Level1Mipmap, 512 );
FilterMipmapsLinear( Level1Mipmap, Level2Mipmap, 256 );
FilterMipmapsLinear( Level2Mipmap, Level3Mipmap, 128);
FilterMipmapsLinear( Level3Mipmap, Level4Mipmap, 64);
etc...

- AH

#17 q3stanky   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 January 2002 - 12:04 AM

when i mipmap the textures in this way it takes 2 min at a system what took 20 seconds before

i think thats logical because now i''m loading effectly 30*10 =300 textures

#18 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 02 January 2002 - 12:52 AM

> when i mipmap the textures in this way it takes 2 min at a system what took 20 seconds before

Well, you did something wrong then.

On my engine, it takes around 4 seconds to load 70MBtextures pre-mipmaped with the function above. I use my own texture format, where I sequentially store the mipmap levels, and load them all at once with a single fread().

- AH

#19 q3stanky   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 January 2002 - 02:05 AM

no it doesnt work but i thank you very much for these tips

#20 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 02 January 2002 - 05:56 AM

So, does mipmapping improve the image quality, or the speed?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS