Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have heard that textures consumes lot of memory but I am surprised how much.... I have 7 textures 1024 16 bit each. And while I will run my app it consumes 57MB of memory. I think that this is "a bit" too much.

I am writing 2D application (no cocos or other framework)

Strange is that while I will compile my app with disabled rendering methods: glDrawArrays than It uses only 27MB.... which is about 30MB less...

Do you have any Idea why?

I am creating textures before rendering of course: rendering looks like this:

 [EAGLContext setCurrentContext:context];
 glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);

 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

 glPushMatrix();
 glEnableClientState(GL_VERTEX_ARRAY);
 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 glEnable(GL_TEXTURE_2D);

 glEnable(GL_BLEND);
 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

 TeksturaObrazek *obrazek_klaw =[[AppDirector sharedAppDirector] obrazek_klaw];
 glBindTexture(GL_TEXTURE_2D, [[obrazek_klaw image_texture] name] );

  glVertexPointer(2, GL_FLOAT, 0,vertex1);
  glTexCoordPointer(2, GL_FLOAT, 0, vertex2);
  glColor4f(1,1,1,alpha);
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

 glDisable(GL_BLEND);
 glDisable(GL_TEXTURE_2D);
 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 glPopMatrix();
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

It looks like standard routine... I have spent about 2 days looking for for answer and I still have no clue.

share|improve this question
1  
The question is a bit unclear. The platform is apparently either osx or (more probably) iphone. No idea how the memory use is measured, or what memory is being discussed (video or system). As to why less memory is consumed if nothing is rendered is due to the way OpenGL may be implemented; the driver may postpone any operations (such as texture conversion, shader compilation, etc) related to resources until they're actually used. –  Jari Komppa Jan 17 '11 at 18:32
    
Any particular reason you're not using PVR compressed textures? They take up significantly less memory, although are lossy. –  Tetrad Jan 17 '11 at 19:23
    
Platform is Iphone. I guess that OpenGL postpone allocating somehow until first usage of the texture. But Why? Why 4Mb per texture? and how to release this memory later. I am not using the PVR because I need to render several semi transparent leyers one on top of another and (as I have never used PVR) I don't know about quality of the result. –  user4707 Jan 18 '11 at 11:33
    
Thank you for Answer, Since yesterday I did some progress and I have loaded images twice. :) stupid mistake. Bit is is not end of the problem. Now It uses about 6MB per texture but 2MB is allocated while I load texture and 4Mb is allocated while I render the pictures. This memory is not released even if I stop rendering while application works. Is there a way to release memory allocated during rendering 4MB per texture? In fact I can load only 4 such textures in order to run this app on Device - Ipod first gen. (3.1.3). If I will load 5 textures (even without rendering I see debugge –  user4707 Jan 18 '11 at 17:24
    
(Mod note: answer to comment migration seems to fail for long answers, here's the rest of his answer) error and app finish) When I load Pictures through Texture2D I release all UIImages. I load 32 bit PNG pictures and convert them in Texture2D to 5551. I am not using mipmaps of course. What do you mean? "you use uncompressed (raw) textures by mistake" So 2 problems I have now: - Why it allocates 4 Mb per texture during rendering and how to release this memory if is not used. - Why after loading more the 4 textures 1024 App break? –  Tetrad Jan 18 '11 at 17:26

2 Answers 2

7 described textures could take as much as 14mb in 16bit, 28mb in 32bit (uncompressed). My ideas:

  • when you disable rendering compiler disables texture creation (pretty weird);

  • you create GL_RGBA textures and they use 32bit per pixel = total of 28mb;

  • you load your textures from "HDD" and pass them to OpenGL, but you forgot to clean up after that, hence you have additional 14mb+ wasting your RAM;

  • you use uncompressed (raw) textures by mistake;

  • creating/using mipmaps may add additional ~30% RAM usage.

share|improve this answer
    
thank youo for answer, –  user4707 Jan 18 '11 at 11:05
  • Why it allocates 4 Mb per texture during rendering and how to release this memory if is not used.

4MB sounds like 1024*1024*4, or 1kx1k 32bit per pixel texture. The reason why such memory would be allocated during rendering is that the GL implementation converts the texture into a more hardware-friendly format. It should get freed when you free the texture. You can try to change the internalFormat of the glTexImage2D call to something more suitable - can't remember which ones are supported in ES, but GL_RGB16 might be it?

  • Why after loading more the 4 textures 1024 App break?

This one I don't know. Maybe you're running out of memory. Why do you need so many of such massive textures anyway for a mobile application?

share|improve this answer
    
1. While I will change internal format it will affect of the rendering quality - I have 16 bit textures but lot of alpha blending on screen. –  user4707 Jan 19 '11 at 9:55
    
2. In fact 4 textures is not much including fact that all of them are in 16 bit. I could understand 4 textures in 32 bits and let's say about 7 textures in 16 bit. but 4 textures in 16 bits is a bit low I would say. –  user4707 Jan 19 '11 at 9:57
    
1. The point 1 was the question. –  user4707 Jan 19 '11 at 9:58
    
I have tried GL_RGB16 but on iPhone 3GS with OpenGl 1.1 it doesn't work :( - From the description above I understand that picture is loaded Texture2D allocate 2MB memory for it and later system allocate another 4Mb memory for it again. So can we release the previous buffer? 2Mb? –  user4707 Jan 20 '11 at 8:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.