diff --git a/src/Importer/IQM/Parser.hs b/src/Importer/IQM/Parser.hs index 1d5b9fe..e68ad95 100644 --- a/src/Importer/IQM/Parser.hs +++ b/src/Importer/IQM/Parser.hs @@ -13,6 +13,8 @@ import Data.ByteString.Char8 (pack) import Data.ByteString (split, null, ByteString) import Data.ByteString.Unsafe (unsafeUseAsCString) import qualified Data.ByteString as B +import Graphics.GLUtil +import Graphics.Rendering.OpenGL.GL.BufferObjects import Data.Word import Data.Int import Unsafe.Coerce @@ -211,10 +213,29 @@ parseIQM a = -- Fill Vertex-Arrays with data of Offsets let va = vertexArrays raw va' <- mapM (readInVAO f) va - return $ raw { - vertexArrays = va' + vbo <- sequence $ map toVBOfromVAO va + return $ raw + { vertexArrays = va' + , vertexArrayObjects = vbo } +-- | Creates a BufferObject on the Graphicscard for each BufferObject + +toVBOfromVAO :: IQMVertexArray -> IO BufferObject +toVBOfromVAO (IQMVertexArray type' _ _ num _ ptr) = + fromPtr (toBufferTargetfromVAType type') (fromIntegral num) ptr + +-- | translates from VA-type to BufferTarget + +toBufferTargetfromVAType :: IQMVertexArrayType -> BufferTarget +toBufferTargetfromVAType IQMPosition = ArrayBuffer +toBufferTargetfromVAType IQMTexCoord = TextureBuffer +toBufferTargetfromVAType IQMNormal = ArrayBuffer +toBufferTargetfromVAType IQMBlendIndexes = ElementArrayBuffer +toBufferTargetfromVAType IQMBlendWeights = ArrayBuffer +toBufferTargetfromVAType IQMColor = ArrayBuffer +toBufferTargetfromVAType _ = ArrayBuffer + -- | Allocates memory for the Vertex-data and copies it over there -- from the given input-String -- @@ -254,6 +275,7 @@ doIQMparse = , texts = filter (not.null) (split (unsafeCoerce '\0') text) , meshes = meshes' , vertexArrays = vaf + , vertexArrayObjects = [] --initialized later, after vaf get allocated. } -- | Helper-Function for Extracting a random substring out of a Bytestring diff --git a/src/Importer/IQM/Types.hs b/src/Importer/IQM/Types.hs index 847320f..0692398 100644 --- a/src/Importer/IQM/Types.hs +++ b/src/Importer/IQM/Types.hs @@ -13,6 +13,7 @@ import Graphics.Rendering.OpenGL.Raw.Types import Prelude as P import Foreign.Storable import Foreign.C.Types +import Graphics.Rendering.OpenGL.GL.BufferObjects hiding (Offset) -- | Mesh-Indices to distinguish the meshes referenced newtype Mesh = Mesh Word32 deriving (Show, Eq) @@ -108,6 +109,7 @@ data IQM = IQM , texts :: [ByteString] , meshes :: [IQMMesh] , vertexArrays :: [IQMVertexArray] + , vertexArrayObjects :: [BufferObject] } deriving (Show, Eq) -- | Different Vertex-Array-Types in IQM diff --git a/src/Render/Misc.hs b/src/Render/Misc.hs index f7163a5..a00a408 100644 --- a/src/Render/Misc.hs +++ b/src/Render/Misc.hs @@ -138,8 +138,3 @@ genColorData :: Int -- ^ Amount -> [Int8] -- ^ [r,g,b,a], [r,g,b] - whatever should be repeatet. -> [Int8] genColorData n c = take (length c*n) (cycle c) - --- from GLUtil --- |Allocate and fill a 'BufferObject' from a list of 'Storable's. -makeBuffer :: Storable a => BufferTarget -> [a] -> IO BufferObject -makeBuffer target elems = makeBufferLen target (length elems) elems