Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: glGenerateMipmap takes too long

  1. #1
    Junior Member Regular Contributor
    Join Date
    Feb 2007
    Location
    Hungary
    Posts
    168

    glGenerateMipmap takes too long

    Hi,
    My application renders text character by character into separate textures.
    Since the text changes from time to time, I have to make this process as fast as I can, and
    remove as much of it as I can from the GL rendering thread (I use PBOs). However, if I disable
    mipmapping and use only GL_LINEAR, the text does not look too good, and with mipmapping enabled,
    it can take a long time and disrupts rendering.
    glGenerateMipmap takes too much time, up to 100+ msec for text that consists ~30 characters.
    Is there anything I can do to make mipmap generation asynchronous?
    Thanks.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    It doesn't matter how many characters it takes up; what matters is how big the texture is and how many times you're doing it.

    If you're rendering strings of text into a texture to display it, there's really no reason to mipmap it. You should simply render it into the texture at the appropriate resolution you intend to display it.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Feb 2007
    Location
    Hungary
    Posts
    168
    Thanks for the response.
    Unfortunately text can change a lot, it can even be a continuously scrolling information line.
    The height of the characters is arbitrary, I added options from 96 to 384 pixel high. This
    maybe overkill but I wanted it to looked good even if it is magnified to 2-3 times of the original size.
    The average setting for height is 256 pixels. I was very surprised to see that heavy minification (1/4-1/8 of
    the original size) can look quite bad without mipmaps (I attached two pictures to demonstrate. One is with GL_LINEAR
    and the other is with GL_LINEAR_MIPMAP_LINEAR .
    Do you think I have to sacrifice mipmaps or is it a viable option to create mipmaps 'manually'
    and asynchronously using the CPU?
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	SH_0310.jpg 
Views:	36 
Size:	14.0 KB 
ID:	1106   Click image for larger version. 

Name:	SH_0311.jpg 
Views:	36 
Size:	11.4 KB 
ID:	1107  

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    I wanted it to looked good even if it is magnified to 2-3 times of the original size.
    Then you should focus on improving how you're rendering it. For example, you can use this Valve-developed technique for rendering glyphs. That way, you don't have to render them to a texture. You just render glyphs where you want them and they'll scale up.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    Have a look at http://www.angelcode.com/products/bmfont/ for an implementation of Valve's paper

  6. #6
    Junior Member Regular Contributor
    Join Date
    Feb 2007
    Location
    Hungary
    Posts
    168
    I am not sure if this technique helps me with this but I am going to try.
    The problem I have is minification and not magnification. I render text to
    relatively high resolution bitmaps (height can vary from 96-384 pixels) but it is usually viewed at a distance.
    If I don't use mipmapping, the higher the minification the worse it looks. I made some progress with mipmapping (I use
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE) instead of glGenerateMipmap and this seems to
    be easier on the CPU but it is still not good enough. Unfortunately I have to render fonts dynamically, I cannot use pre-rendered bitmaps
    because I want to support all languages without the nightmare of laying out text myself.
    Is it even possible to create all the mipmaps 'manually' (by the application) and upload it with a pbo in another thread?
    Rendering of the fonts is already done in another thread and I only support multiple core CPUs so I don't mind.
    Is it possible to reserve more memory using glBufferData and upload all the mipmaps at once?
    Or do I have to use multiple pbos (one for each mipmap level) and upload its contents to a specific level?
    Thanks.
    Last edited by aronsatie; 08-11-2013 at 05:38 AM.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Feb 2004
    Posts
    248
    You could use a fragment shader to do a custom filtering on your font texture depending on screensize. Works pretty well actually.

    Why exactly can't you render all your characters into textures once on startup? What rendering code do you use?

  8. #8
    Junior Member Regular Contributor
    Join Date
    Feb 2007
    Location
    Hungary
    Posts
    168
    Could you elaborate on custom filtering? I have to support Unicode for all possible languages. I tried a text layout engine (Uniscribe) before but I had some problems with certain fonts and certain languages (e.g. to preconvert a Chinese font consisting of ~30-40.000 glyphs would be more or less impossible) and finally I decided I would let the OS take care of that. I do not even handle text as a series of characters, text is rendered line by line as a series of contours created by Windows and I use these contours to create either polygons (works just fine) or a series of bitmaps from them. The latter is more problematic since the only way I know to make them high quality is to use mipmapping. Which can be slow because much of it happens in the rendering thread.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Nov 2012
    Location
    Bremen, Germany
    Posts
    149
    Let's see if I understand the problem: You have to render some text. This requires to compute Mipmaps when a new text-line is encountered. And that is too slow? How often does you text change then? Assuming that a user needs at least a few seconds to read a line of text it cannot be the case that mipmaps cannot be generated fast enough for this. There has to be another problem - that is a problem in the structure of the problem-solution.
    Have you tried to build up a dictionary of word-textures and stitch words together to form a text-line? I've made good experiences with such an approach. A dictionary of a few thousand distinct words is often more then enough to form a whole page of text (I don't know about asian languages though...). This makes new textures and mipmaps to be generated relatively small and hence should increase performance.

  10. #10
    Junior Member Regular Contributor
    Join Date
    Feb 2007
    Location
    Hungary
    Posts
    168
    Computing mipmaps is only too slow because it happens in the rendering thread. When they are created, one or two frames take much longer to render which causes jumps in the animation. I don't think dictionaries can be used. The application has to support all possible languages, not just one. I need to be able to render ANY text and on the fly. I still think the best approach could be to create all mipmaps in the application but in a separate thread and upload them asynchronously using PBOs. This way it is only a slightly bigger memory transfer which would more than likely not disrupt rendering. The question is (I have never done anything like this, nor did I find any info on the net): do I need to use a separate PBO with its own mapped memory buffer for each mipmap level or is it possible to upload all mipmaps at once as a continuous buffer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •