-------------------------------------------------------------------------------- -- | -- Module : Graphics.Rendering.OGL.GLU.Mipmapping -- Copyright : (c) Sven Panne 2002-2006 -- License : BSD-style (see the file libraries/OpenGL/LICENSE) -- -- Maintainer : sven.panne@aedion.de -- Stability : stable -- Portability : portable -- -- This module corresponds to chapter 3 (Mipmapping) of the GLU specs. -- -------------------------------------------------------------------------------- module Graphics.Rendering.OGL.GLU.Mipmapping ( scaleImage, build1DMipmaps, build2DMipmaps ) where import Foreign.Ptr ( Ptr ) import Graphics.Rendering.OGL.Monad import Graphics.Rendering.OGL.GL.BasicTypes ( GLsizei, GLint, GLenum ) import Graphics.Rendering.OGL.GL.CoordTrans ( Size(..) ) import Graphics.Rendering.OGL.GL.PixelData ( PixelData, withPixelData ) import Graphics.Rendering.OGL.GL.Texturing.PixelInternalFormat ( PixelInternalFormat, marshalPixelInternalFormat ) import Graphics.Rendering.OGL.GL.Texturing.TextureTarget ( TextureTarget, marshalTextureTarget ) import Graphics.Rendering.OGL.GLU.ErrorsInternal ( recordInvalidValue ) -------------------------------------------------------------------------------- -- Section 3.1 (Image Scaling) scaleImage :: Size -> PixelData a -> Size -> PixelData b -> GL () scaleImage (Size widthIn heightIn) pdIn (Size widthOut heightOut) pdOut = liftIO . withPixelData pdIn $ \fIn dIn pIn -> withPixelData pdOut $ \fOut dOut pOut -> if fIn == fOut then gluScaleImage fIn widthIn heightIn dIn pIn widthOut heightOut dOut pOut else recordInvalidValue foreign import CALLCONV unsafe "gluScaleImage" gluScaleImage :: GLenum -> GLsizei -> GLsizei -> GLenum -> Ptr a -> GLsizei -> GLsizei -> GLenum -> Ptr b -> IO () -------------------------------------------------------------------------------- -- Section 3.2 (Automatic Mipmapping) -- Missing for GLU 1.3: gluBuild3DMipmaps, gluBuild{1,2,3}DMipmapLevels build1DMipmaps :: TextureTarget -> PixelInternalFormat -> GLsizei -> PixelData a -> GL () build1DMipmaps target internalFormat height pd = liftIO $ do withPixelData pd $ gluBuild1DMipmaps (marshalTextureTarget target) (marshalPixelInternalFormat internalFormat) height return () -- TODO: Should we use the return value? foreign import CALLCONV unsafe "gluBuild1DMipmaps" gluBuild1DMipmaps :: GLenum -> GLint -> GLsizei -> GLenum -> GLenum -> Ptr a -> IO GLint -------------------------------------------------------------------------------- build2DMipmaps :: TextureTarget -> PixelInternalFormat -> GLsizei -> GLsizei -> PixelData a -> GL () build2DMipmaps target internalFormat width height pd = liftIO $ do withPixelData pd $ gluBuild2DMipmaps (marshalTextureTarget target) (marshalPixelInternalFormat internalFormat) width height return () -- TODO: Should we use the return value? foreign import CALLCONV unsafe "gluBuild2DMipmaps" gluBuild2DMipmaps :: GLenum -> GLint -> GLsizei -> GLsizei -> GLenum -> GLenum -> Ptr a -> IO GLint