module Graphics.LambdaCube.HardwareVertexBuffer where
import Data.IntMap
import Data.Word
import Foreign.C.Types
import Foreign.Storable
import Graphics.LambdaCube.HardwareBuffer
class HardwareBuffer a => HardwareVertexBuffer a where
getVertexSize :: a -> Int
getNumVertices :: a -> Int
data VertexElementSemantic
= VES_POSITION
| VES_BLEND_WEIGHTS
| VES_BLEND_INDICES
| VES_NORMAL
| VES_DIFFUSE
| VES_SPECULAR
| VES_TEXTURE_COORDINATES
| VES_BINORMAL
| VES_TANGENT
deriving (Enum,Eq,Ord,Show)
data VertexElementType
= VET_FLOAT1
| VET_FLOAT2
| VET_FLOAT3
| VET_FLOAT4
| VET_SHORT1
| VET_SHORT2
| VET_SHORT3
| VET_SHORT4
| VET_UBYTE4
| VET_COLOUR_ARGB
| VET_COLOUR_ABGR
deriving (Eq,Ord,Show)
data VertexElement
= VertexElement
{ veSource :: Int
, veOffset :: Int
, veType :: VertexElementType
, veSemantic :: VertexElementSemantic
, veIndex :: Int
}
deriving (Eq,Ord,Show)
getTypeSize :: VertexElementType -> Int
getTypeSize etype = case etype of
VET_COLOUR_ABGR -> sizeOf (undefined::Word32)
VET_COLOUR_ARGB -> sizeOf (undefined::Word32)
VET_FLOAT1 -> sizeOf (undefined::CFloat)
VET_FLOAT2 -> 2 * sizeOf (undefined::CFloat)
VET_FLOAT3 -> 3 * sizeOf (undefined::CFloat)
VET_FLOAT4 -> 4 * sizeOf (undefined::CFloat)
VET_SHORT1 -> sizeOf (undefined::CShort)
VET_SHORT2 -> 2 * sizeOf (undefined::CShort)
VET_SHORT3 -> 3 * sizeOf (undefined::CShort)
VET_SHORT4 -> 4 * sizeOf (undefined::CShort)
VET_UBYTE4 -> 4 * sizeOf (undefined::CUChar)
getTypeCount :: VertexElementType -> Int
getTypeCount etype = case etype of
VET_COLOUR_ABGR -> 4
VET_COLOUR_ARGB -> 4
VET_FLOAT1 -> 1
VET_FLOAT2 -> 2
VET_FLOAT3 -> 3
VET_FLOAT4 -> 4
VET_SHORT1 -> 1
VET_SHORT2 -> 2
VET_SHORT3 -> 3
VET_SHORT4 -> 4
VET_UBYTE4 -> 4
multiplyTypeCount :: VertexElementType -> Int -> VertexElementType
multiplyTypeCount baseType count = case baseType of
VET_FLOAT1 -> case count of
1 -> VET_FLOAT1
2 -> VET_FLOAT2
3 -> VET_FLOAT3
4 -> VET_FLOAT4
_ -> error $ "multiplyTypeCount: Invalid VET_FLOAT type " ++ show count
VET_SHORT1 -> case count of
1 -> VET_SHORT1
2 -> VET_SHORT2
3 -> VET_SHORT3
4 -> VET_SHORT4
_ -> error $ "multiplyTypeCount: Invalid VET_FLOAT type " ++ show count
_ -> error $ "multiplyTypeCount: Invalid base type " ++ show baseType
getBaseType :: VertexElementType -> VertexElementType
getBaseType multiType = case multiType of
VET_FLOAT1 -> VET_FLOAT1
VET_FLOAT2 -> VET_FLOAT1
VET_FLOAT3 -> VET_FLOAT1
VET_FLOAT4 -> VET_FLOAT1
VET_SHORT1 -> VET_SHORT1
VET_SHORT2 -> VET_SHORT1
VET_SHORT3 -> VET_SHORT1
VET_SHORT4 -> VET_SHORT1
mt -> mt
data VertexDeclaration
= VertexDeclaration
{ vdElementList :: [VertexElement]
}
deriving (Eq,Ord,Show)
data HardwareVertexBuffer vb => VertexBufferBinding vb
= VertexBufferBinding
{ vbbBindingMap :: IntMap vb
}
deriving (Eq,Ord)