Texture Resources
  • Texture resources are finite and the amount of available texture varies among implementations 
  • An application may evaluate whether sufficient resources exist
    • glGetIntegerv(GL_MAX_TEXTURE_SIZE, ...) will show the total texture memory
    • Be aware that pixel format will greatly affect texture utilization (as well as mipmaps and borders)
  • A texture proxy is a place holder which allows more accurate queries

  •  

     
     
     

        glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA8,
                    64, 64, 0,
                    GL_RGBA, GL_UNSIGNED_BYTE, NULL);
       glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, 
                                GL_TEXTURE_INTERNAL_FORMAT,
                                &proxyComponents);
       printf ("Proxying 64x64 level 0 RGBA8 texture (level 0)\n");
       if (proxyComponents == GL_RGBA8)
          printf ("proxy allocation succeeded\n");
       else
          printf ("proxy allocation failed\n");
     

  •  Unfortunately proxies to not report existing texture usage

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Replacing All or Part of a Texture Image
  • Creating an entirely new texture may be more computationally expensive than modifying an existing one 


  •  
  • glTexSubImage2D() may be used to replace portions of the texture data 
    • Not restricted to powers of two(!)
  • glCopyTexSubImage2D() in a similar fashion

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Using a Texture's Borders

Image from http://www.terrex.com/www/netpages/downloadpage.htm
  • Scene with texture requirements larger than graphics hardware can be rendered
    • Texture loads and re-loads must be done per frame
    • Since a single texture map is available at a time (in this scenario) problems can occur at the edges of the image (for blending)
    • Specifying textures which share border pixels will resolve this issue
    • The border values may be used when the texture does not completely cover a primitive (clamping)

     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Multiple Levels of Detail
  • Objects farther away from the viewpoint will have several texels which may map to a pixel in the framebuffer
    • Causes annoying "texture swimming"
  • Multiple pre-filtered versions of a texture (mipmaps) allow for the appropriate resolution image to be applied to a primitive

  •  

     
     
     

  •  To use mipmapping all sizes of the texture in powers of two must be provided down to 1x1 pixel -- using glTexImage2D()

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Filtering


  • Texture maps are rectangular, but there is rarely a one-to-one mapping of texels to pixels in the framebuffer
  • A single pixel can refer to:
    • a fraction of a texel (magnification)
    • a collection of texels (minification)
  • OpenGL allows specification of the filtering options
    • NOTE! This can have a critical effect on the image quality for some applications
  • Some cases result in minification in one axis and magnification in another (avoid this situation) - OpenGL will choose

  •  

     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Specifying Filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
           GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
           GL_NEAREST);
     
  • First parameter is GL_TEXTURE_2D or GL_TEXTURE_1D
  • Second parameters specifies minification or magnification
  • Third specifies one of the following:


  •  
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Specifiying Filtering (cont)
  • perhaps picture from tutorial ...
  • GL_NEAREST - The texel nearest to the center of the pixel is seleted
    • NOTE! this can cause aliasing artifacts
  • GL_LINEAR - a weighted linear average of the 2x2 texels nearest to the center of the pixel
    • NOTE!  the texel coordinates may extend beyond the defined texture - GL_REPEAT or GL_CLAMP (and the border) will affect the result
    • GL_LINEAR produces a "smoother" texturing (this may or may not be good)
    • GL_NEAREST requires less computation

     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Mipmaps and Filtering
  • Magnification always uses the largest mipmap (level 0) if defined
  • Minification chooses a filter between the appropriate mipmap (or mipmaps)
  • GL_NEAREST_MIPMAP_NEAREST specifies GL_NEAREST for the nearest mipmap
  • GL_LINEAR_MIPMAP_NEAREST specifies GL_LINEAR for the nearest mipmap
  • To interpolate between the nearest two mipmaps:
    • GL_NEAREST_MIPMAP_LINEAR
    • GL_LINEAR_MIPMAP_LINEAR
    • higher quality = more computation

     
     
     
     
  •  

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 9

  •  

     
     
     
     
     

  •  

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Homework
  • Compile and execute the texture tutor (homework.tar)


  •  
  •  Extra Credit:
    • (yeah, right ...)