packages feed

ktx 0.1 → 0.2

raw patch · 2 files changed

+29/−4 lines, 2 filesdep +bytestringPVP ok

version bump matches the API change (PVP)

Dependencies added: bytestring

API changes (from Hackage documentation)

+ Graphics.Rendering.KTX: loadTextureM :: ByteString -> IO TextureObject

Files

ktx.cabal view
@@ -1,5 +1,5 @@ name: ktx-version: 0.1+version: 0.2 cabal-version: >= 1.10 build-type: Simple license: MIT@@ -38,7 +38,8 @@         Haskell2010     build-depends:         base >= 3 && < 5,-        OpenGL >= 2.9 && < 3+        OpenGL >= 2.9 && < 3,+        bytestring >= 0.9 && < 1     ghc-options:         -Wall         -fno-warn-unused-do-bind
src/Graphics/Rendering/KTX.hsc view
@@ -5,14 +5,17 @@     , Dimensions(..)     , initContext     , loadTextureN+    , loadTextureM     ) where  import Control.Exception (Exception, throwIO)+import Data.ByteString (ByteString)+import Data.ByteString.Unsafe (unsafeUseAsCStringLen) import Data.Typeable (Typeable) import Data.Word (Word32) -- constructors were not exported until here #if MIN_VERSION_base(4,5,0)-import Foreign.C.Types (CUInt(CUInt))+import Foreign.C.Types (CUInt(CUInt), CInt(CInt)) #else import Foreign.C.Types (CUInt) #endif@@ -20,7 +23,7 @@ import Foreign.C.String (CString, withCString) import Foreign.Storable (peek) import Foreign.Marshal.Utils (with)-import Foreign.Ptr (Ptr, nullPtr)+import Foreign.Ptr (Ptr, nullPtr, castPtr) import Graphics.Rendering.OpenGL (GLsizei, GLenum, GLuint, GLboolean, TextureObject(TextureObject))  #include <ktx.h>@@ -41,6 +44,18 @@     -> Ptr (Ptr CUChar)     -> IO ErrorCode +foreign import ccall "ktx.h ktxLoadTextureM" ktxLoadTextureM+    :: Ptr ()+    -> GLsizei+    -> Ptr GLuint+    -> Ptr GLenum+    -> Ptr Dimensions+    -> Ptr GLboolean+    -> Ptr GLenum+    -> Ptr CUInt+    -> Ptr (Ptr CUChar)+    -> IO ErrorCode+ data GLEWException = GLEWException GLenum deriving (Eq, Ord, Typeable, Show) instance Exception GLEWException @@ -58,6 +73,15 @@ loadTextureN path = withCString path $ \pathStr -> do     with 0 $ \texPtr -> with 0 $ \bindingPtr -> do         e <- ktxLoadTextureN pathStr texPtr bindingPtr nullPtr nullPtr nullPtr nullPtr nullPtr+        t <- peek texPtr+        case e of+            0 -> return $ TextureObject t+            _ -> throwIO $ KTXException e++loadTextureM :: ByteString -> IO TextureObject+loadTextureM buf = unsafeUseAsCStringLen buf $ \(ptr, len) -> do+    with 0 $ \texPtr -> with 0 $ \bindingPtr -> do+        e <- ktxLoadTextureM (castPtr ptr) (fromIntegral len) texPtr bindingPtr nullPtr nullPtr nullPtr nullPtr nullPtr         t <- peek texPtr         case e of             0 -> return $ TextureObject t