@@ -94,7 +94,6 @@ import Foreign
9494 mallocForeignPtr ,
9595 mallocForeignPtrArray ,
9696 newArray ,
97- newForeignPtr ,
9897 peekArray ,
9998 plusPtr ,
10099 pokeArray ,
@@ -112,8 +111,8 @@ import Foreign.C
112111 castCharToCChar ,
113112 peekCString ,
114113 )
115- import Raylib.Internal (Closeable (addToWindowResources , close ), addShaderId , addTextureId , addVaoId , addVboIds , c'rlGetShaderIdDefault , c'rlUnloadShaderProgram , c'rlUnloadTexture , c'rlUnloadVertexArray , c'rlUnloadVertexBuffer )
116- import Raylib.Internal.Foreign (Freeable (rlFreeDependents ), c'free , freeMaybePtr , newMaybeArray , p'free , peekMaybeArray , peekStaticArray , pokeStaticArray , rightPad , rlFree , rlFreeMaybeArray )
114+ import Raylib.Internal (Closeable (addToWindowResources , close ), addShaderId , addTextureId , addVaoId , addVboIds , c'rlGetShaderIdDefault , c'rlGetShaderLocsDefault , c' rlUnloadShaderProgram , c'rlUnloadTexture , c'rlUnloadVertexArray , c'rlUnloadVertexBuffer )
115+ import Raylib.Internal.Foreign (Freeable (rlFreeDependents ), c'free , freeMaybePtr , newMaybeArray , peekMaybeArray , peekStaticArray , pokeStaticArray , rightPad , rlFree , rlFreeMaybeArray )
117116import Raylib.Types.Core (Color , Matrix , Quaternion , Vector2 , Vector3 , Vector4 , pattern Vector2 , pattern Vector3 , pattern Vector4 )
118117import Raylib.Types.Core.Textures (Texture (texture'id ))
119118
@@ -133,7 +132,7 @@ data MaterialMapIndex
133132 | MaterialMapIrradiance
134133 | MaterialMapPrefilter
135134 | MaterialMapBrdf
136- deriving (Eq , Show , Enum )
135+ deriving (Eq , Show , Read , Enum )
137136
138137data DefaultShaderAttributeLocation
139138 = DefaultShaderAttribLocationPosition
@@ -145,7 +144,7 @@ data DefaultShaderAttributeLocation
145144 | DefaultShaderAttribLocationIndices
146145 | DefaultShaderAttribLocationBoneIds
147146 | DefaultShaderAttribLocationBoneWeights
148- deriving (Eq , Show , Enum )
147+ deriving (Eq , Show , Read , Enum )
149148
150149data ShaderLocationIndex
151150 = ShaderLocVertexPosition
@@ -177,7 +176,7 @@ data ShaderLocationIndex
177176 | ShaderLocVertexBoneIds
178177 | ShaderLocVertexBoneWeights
179178 | ShaderLocBoneMatrices
180- deriving (Eq , Show , Enum )
179+ deriving (Eq , Show , Read , Enum )
181180
182181data ShaderUniformDataType
183182 = ShaderUniformFloatType
@@ -189,7 +188,7 @@ data ShaderUniformDataType
189188 | ShaderUniformIVec3Type
190189 | ShaderUniformIVec4Type
191190 | ShaderUniformSampler2DType
192- deriving (Eq , Show , Enum )
191+ deriving (Eq , Show , Read , Enum )
193192
194193data ShaderUniformData
195194 = ShaderUniformFloat Float
@@ -201,7 +200,7 @@ data ShaderUniformData
201200 | ShaderUniformIVec3 (Int , Int , Int )
202201 | ShaderUniformIVec4 (Int , Int , Int , Int )
203202 | ShaderUniformSampler2D Texture
204- deriving (Eq , Show )
203+ deriving (Eq , Show , Read )
205204
206205data ShaderUniformDataV
207206 = ShaderUniformFloatV [Float ]
@@ -213,7 +212,7 @@ data ShaderUniformDataV
213212 | ShaderUniformIVec3V [(Int , Int , Int )]
214213 | ShaderUniformIVec4V [(Int , Int , Int , Int )]
215214 | ShaderUniformSampler2DV [Texture ]
216- deriving (Eq , Show )
215+ deriving (Eq , Show , Read )
217216
218217-- | Internal use
219218unpackShaderUniformData :: ShaderUniformData -> IO (ShaderUniformDataType , ForeignPtr () )
@@ -321,7 +320,7 @@ data ShaderAttributeDataType
321320 | ShaderAttribVec2
322321 | ShaderAttribVec3
323322 | ShaderAttribVec4
324- deriving (Eq , Show , Enum )
323+ deriving (Eq , Show , Read , Enum )
325324
326325---------------------------------------
327326-- models structures ------------------
@@ -331,7 +330,7 @@ data Mesh = Mesh
331330 { mesh'vertexCount :: Int ,
332331 mesh'triangleCount :: Int ,
333332 mesh'vertices :: [Vector3 ],
334- mesh'texcoords :: [Vector2 ],
333+ mesh'texcoords :: Maybe [Vector2 ],
335334 mesh'texcoords2 :: Maybe [Vector2 ],
336335 mesh'normals :: [Vector3 ],
337336 mesh'tangents :: Maybe [Vector4 ],
@@ -347,7 +346,7 @@ data Mesh = Mesh
347346 -- | Use `toEnum` on `DefaultShaderAttributeLocation` for indices
348347 mesh'vboId :: Maybe [Integer ]
349348 }
350- deriving (Eq , Show )
349+ deriving (Eq , Show , Read )
351350
352351instance Storable Mesh where
353352 sizeOf _ = 120
@@ -356,7 +355,7 @@ instance Storable Mesh where
356355 vertexCount <- fromIntegral <$> peek (p'mesh'vertexCount _p)
357356 triangleCount <- fromIntegral <$> peek (p'mesh'triangleCount _p)
358357 vertices <- peekArray vertexCount =<< peek (p'mesh'vertices _p)
359- texcoords <- peekArray vertexCount =<< peek (p'mesh'texcoords _p)
358+ texcoords <- peekMaybeArray vertexCount =<< peek (p'mesh'texcoords _p)
360359 texcoords2 <- peekMaybeArray vertexCount =<< peek (p'mesh'texcoords2 _p)
361360 normals <- peekArray vertexCount =<< peek (p'mesh'normals _p)
362361 tangents <- peekMaybeArray vertexCount =<< peek (p'mesh'tangents _p)
@@ -365,8 +364,8 @@ instance Storable Mesh where
365364 animVertices <- peekMaybeArray vertexCount =<< peek (p'mesh'animVertices _p)
366365 animNormals <- peekMaybeArray vertexCount =<< peek (p'mesh'animNormals _p)
367366 boneCount <- fromIntegral <$> peek (p'mesh'boneCount _p)
368- boneIds <- (map fromIntegral <$> ) <$> (peekMaybeArray boneCount =<< peek (p'mesh'boneIds _p))
369- boneWeights <- (map realToFrac <$> ) <$> (peekMaybeArray boneCount =<< peek (p'mesh'boneWeights _p))
367+ boneIds <- (map fromIntegral <$> ) <$> (peekMaybeArray ( 4 * vertexCount) =<< peek (p'mesh'boneIds _p))
368+ boneWeights <- (map realToFrac <$> ) <$> (peekMaybeArray ( 4 * vertexCount) =<< peek (p'mesh'boneWeights _p))
370369 boneMatrices <- peekMaybeArray boneCount =<< peek (p'mesh'boneMatrices _p)
371370 vaoId <- fromIntegral <$> peek (p'mesh'vaoId _p)
372371 vboId <- (map fromIntegral <$> ) <$> (peekMaybeArray 9 =<< peek (p'mesh'vboId _p))
@@ -375,7 +374,7 @@ instance Storable Mesh where
375374 poke (p'mesh'vertexCount _p) (fromIntegral vertexCount)
376375 poke (p'mesh'triangleCount _p) (fromIntegral triangleCount)
377376 poke (p'mesh'vertices _p) =<< newArray vertices
378- poke (p'mesh'texcoords _p) =<< newArray texcoords
377+ poke (p'mesh'texcoords _p) =<< newMaybeArray texcoords
379378 poke (p'mesh'texcoords2 _p) =<< newMaybeArray texcoords2
380379 poke (p'mesh'normals _p) =<< newArray normals
381380 poke (p'mesh'tangents _p) =<< newMaybeArray tangents
@@ -411,7 +410,7 @@ p'mesh'triangleCount = (`plusPtr` 4)
411410p'mesh'vertices :: Ptr Mesh -> Ptr (Ptr Vector3 )
412411p'mesh'vertices = (`plusPtr` 8 )
413412
414- -- array (mesh'vertexCount)
413+ -- maybe array (mesh'vertexCount)
415414p'mesh'texcoords :: Ptr Mesh -> Ptr (Ptr Vector2 )
416415p'mesh'texcoords = (`plusPtr` 16 )
417416
@@ -496,7 +495,7 @@ data Shader = Shader
496495 { shader'id :: Integer ,
497496 shader'locs :: [Int ]
498497 }
499- deriving (Eq , Show )
498+ deriving (Eq , Show , Read )
500499
501500instance Storable Shader where
502501 sizeOf _ = 16
@@ -507,13 +506,7 @@ instance Storable Shader where
507506 return $ Shader sId locs
508507 poke _p (Shader sId locs) = do
509508 poke (p'shader'id _p) (fromIntegral sId)
510- defaultShaderId <- c'rlGetShaderIdDefault
511- locsArr <- newArray (map fromIntegral locs)
512- if sId == fromIntegral defaultShaderId
513- then do
514- locsPtr <- newForeignPtr p'free locsArr
515- withForeignPtr locsPtr $ poke (p'shader'locs _p)
516- else poke (p'shader'locs _p) locsArr
509+ poke (p'shader'locs _p) =<< newArray (map fromIntegral locs)
517510 return ()
518511
519512instance Closeable Shader where
@@ -531,21 +524,19 @@ p'shader'locs :: Ptr Shader -> Ptr (Ptr CInt)
531524p'shader'locs = (`plusPtr` 8 )
532525
533526instance Freeable Shader where
534- rlFreeDependents val ptr = do
535- defaultShaderId <- c'rlGetShaderIdDefault
527+ rlFreeDependents _ ptr = do
528+ defaultShaderLocs <- c'rlGetShaderLocsDefault
529+ locsPtr <- peek (p'shader'locs ptr)
536530 unless
537- (shader'id val == fromIntegral defaultShaderId)
538- ( do
539- locsPtr <- peek (p'shader'locs ptr)
540- c'free $ castPtr locsPtr
541- )
531+ (locsPtr == defaultShaderLocs)
532+ (c'free $ castPtr locsPtr)
542533
543534data MaterialMap = MaterialMap
544535 { materialMap'texture :: Texture ,
545536 materialMap'color :: Color ,
546537 materialMap'value :: Float
547538 }
548- deriving (Eq , Show , Freeable )
539+ deriving (Eq , Show , Read , Freeable )
549540
550541instance Storable MaterialMap where
551542 sizeOf _ = 28
@@ -575,7 +566,7 @@ data Material = Material
575566 material'maps :: Maybe [MaterialMap ],
576567 material'params :: [Float ]
577568 }
578- deriving (Eq , Show )
569+ deriving (Eq , Show , Read )
579570
580571instance Storable Material where
581572 sizeOf _ = 40
@@ -633,7 +624,7 @@ data Transform = Transform
633624 transform'rotation :: Quaternion ,
634625 transform'scale :: Vector3
635626 }
636- deriving (Eq , Show , Freeable )
627+ deriving (Eq , Show , Read , Freeable )
637628
638629instance Storable Transform where
639630 sizeOf _ = 40
@@ -662,7 +653,7 @@ data BoneInfo = BoneInfo
662653 { boneInfo'name :: String ,
663654 boneInfo'parent :: Int
664655 }
665- deriving (Eq , Show , Freeable )
656+ deriving (Eq , Show , Read , Freeable )
666657
667658instance Storable BoneInfo where
668659 sizeOf _ = 36
@@ -692,7 +683,7 @@ data Model = Model
692683 model'bones :: Maybe [BoneInfo ],
693684 model'bindPose :: Maybe [Transform ]
694685 }
695- deriving (Eq , Show )
686+ deriving (Eq , Show , Read )
696687
697688instance Storable Model where
698689 sizeOf _ = 120
@@ -775,7 +766,7 @@ data ModelAnimation = ModelAnimation
775766 modelAnimation'framePoses :: [[Transform ]],
776767 modelAnimation'name :: String
777768 }
778- deriving (Eq , Show )
769+ deriving (Eq , Show , Read )
779770
780771instance Storable ModelAnimation where
781772 sizeOf _ = 56
@@ -827,7 +818,7 @@ data Ray = Ray
827818 { ray'position :: Vector3 ,
828819 ray'direction :: Vector3
829820 }
830- deriving (Eq , Show , Freeable )
821+ deriving (Eq , Show , Read , Freeable )
831822
832823instance Storable Ray where
833824 sizeOf _ = 24
@@ -853,7 +844,7 @@ data RayCollision = RayCollision
853844 rayCollision'point :: Vector3 ,
854845 rayCollision'normal :: Vector3
855846 }
856- deriving (Eq , Show , Freeable )
847+ deriving (Eq , Show , Read , Freeable )
857848
858849instance Storable RayCollision where
859850 sizeOf _ = 32
@@ -887,7 +878,7 @@ data BoundingBox = BoundingBox
887878 { boundingBox'min :: Vector3 ,
888879 boundingBox'max :: Vector3
889880 }
890- deriving (Eq , Show , Freeable )
881+ deriving (Eq , Show , Read , Freeable )
891882
892883instance Storable BoundingBox where
893884 sizeOf _ = 24
0 commit comments