array-objects get initialized
- initialized array-objects - still need to be rendered and collected to a VertexBufferObject refs #482 @2h
This commit is contained in:
parent
4d31866256
commit
b5a4d03f8c
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user