h-raylib 4.5.3.1 → 4.5.3.2
raw patch · 22 files changed
+2470/−169 lines, 22 filesdep ~basenew-component:exe:basic-rlglbinary-addedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Raylib.Types: GLComputeShader :: GLShaderType
+ Raylib.Types: GLFragmentShader :: GLShaderType
+ Raylib.Types: GLGeometryShader :: GLShaderType
+ Raylib.Types: GLVertexShader :: GLShaderType
+ Raylib.Types: RLAttachmentColorChannel0 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentColorChannel1 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentColorChannel2 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentColorChannel3 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentColorChannel4 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentColorChannel5 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentColorChannel6 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentColorChannel7 :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentCubemapNegativeX :: RLFramebufferAttachTextureType
+ Raylib.Types: RLAttachmentCubemapNegativeY :: RLFramebufferAttachTextureType
+ Raylib.Types: RLAttachmentCubemapNegativeZ :: RLFramebufferAttachTextureType
+ Raylib.Types: RLAttachmentCubemapPositiveX :: RLFramebufferAttachTextureType
+ Raylib.Types: RLAttachmentCubemapPositiveY :: RLFramebufferAttachTextureType
+ Raylib.Types: RLAttachmentCubemapPositiveZ :: RLFramebufferAttachTextureType
+ Raylib.Types: RLAttachmentDepth :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentRenderBuffer :: RLFramebufferAttachTextureType
+ Raylib.Types: RLAttachmentStencil :: RLFramebufferAttachType
+ Raylib.Types: RLAttachmentTexture2D :: RLFramebufferAttachTextureType
+ Raylib.Types: RLBufferHintDynamicCopy :: RLBufferHint
+ Raylib.Types: RLBufferHintDynamicDraw :: RLBufferHint
+ Raylib.Types: RLBufferHintDynamicRead :: RLBufferHint
+ Raylib.Types: RLBufferHintStaticCopy :: RLBufferHint
+ Raylib.Types: RLBufferHintStaticDraw :: RLBufferHint
+ Raylib.Types: RLBufferHintStaticRead :: RLBufferHint
+ Raylib.Types: RLBufferHintStreamCopy :: RLBufferHint
+ Raylib.Types: RLBufferHintStreamDraw :: RLBufferHint
+ Raylib.Types: RLBufferHintStreamRead :: RLBufferHint
+ Raylib.Types: RLCullFaceBack :: RLCullMode
+ Raylib.Types: RLCullFaceFront :: RLCullMode
+ Raylib.Types: RLDrawCall :: RLDrawMode -> Int -> Int -> Integer -> RLDrawCall
+ Raylib.Types: RLLines :: RLDrawMode
+ Raylib.Types: RLLogAll :: RLTraceLogLevel
+ Raylib.Types: RLLogDebug :: RLTraceLogLevel
+ Raylib.Types: RLLogError :: RLTraceLogLevel
+ Raylib.Types: RLLogFatal :: RLTraceLogLevel
+ Raylib.Types: RLLogInfo :: RLTraceLogLevel
+ Raylib.Types: RLLogNone :: RLTraceLogLevel
+ Raylib.Types: RLLogTrace :: RLTraceLogLevel
+ Raylib.Types: RLLogWarning :: RLTraceLogLevel
+ Raylib.Types: RLModelView :: RLMatrixMode
+ Raylib.Types: RLOpenGL11 :: RLGLVersion
+ Raylib.Types: RLOpenGL21 :: RLGLVersion
+ Raylib.Types: RLOpenGL33 :: RLGLVersion
+ Raylib.Types: RLOpenGL43 :: RLGLVersion
+ Raylib.Types: RLOpenGLES20 :: RLGLVersion
+ Raylib.Types: RLPixelFormatCompressedAstc4x4Rgba :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedAstc8x8Rgba :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedDxt1Rgb :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedDxt1Rgba :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedDxt3Rgba :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedDxt5Rgba :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedEtc1Rgb :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedEtc2EacRgba :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedEtc2Rgb :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedPvrtRgb :: RLPixelFormat
+ Raylib.Types: RLPixelFormatCompressedPvrtRgba :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedGrayAlpha :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedGrayscale :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR32 :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR32G32B32 :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR32G32B32A32 :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR4G4B4A4 :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR5G5B5A1 :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR5G6B5 :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR8G8B8 :: RLPixelFormat
+ Raylib.Types: RLPixelFormatUncompressedR8G8B8A8 :: RLPixelFormat
+ Raylib.Types: RLProjection :: RLMatrixMode
+ Raylib.Types: RLQuads :: RLDrawMode
+ Raylib.Types: RLRenderBatch :: Int -> Int -> [RLVertexBuffer] -> [RLDrawCall] -> Int -> Float -> RLRenderBatch
+ Raylib.Types: RLShaderAttribFloat :: RLShaderAttributeDataType
+ Raylib.Types: RLShaderAttribVec2 :: RLShaderAttributeDataType
+ Raylib.Types: RLShaderAttribVec3 :: RLShaderAttributeDataType
+ Raylib.Types: RLShaderAttribVec4 :: RLShaderAttributeDataType
+ Raylib.Types: RLShaderLocColorAmbient :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocColorDiffuse :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocColorSpecular :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapAlbedo :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapBRDF :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapCubemap :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapEmission :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapHeight :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapIrradiance :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapMetalness :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapNormal :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapOcclusion :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapPrefilter :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMapRoughness :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMatrixMVP :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMatrixModel :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMatrixNormal :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMatrixProjection :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocMatrixView :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocVectorView :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocVertexColor :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocVertexNormal :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocVertexPosition :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocVertexTangent :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocVertexTexcoord01 :: RLShaderLocationIndex
+ Raylib.Types: RLShaderLocVertexTexcoord02 :: RLShaderLocationIndex
+ Raylib.Types: RLShaderUniformFloat :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformIVec2 :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformIVec3 :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformIVec4 :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformInt :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformSampler2D :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformVec2 :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformVec3 :: RLShaderUniformDataType
+ Raylib.Types: RLShaderUniformVec4 :: RLShaderUniformDataType
+ Raylib.Types: RLTexture :: RLMatrixMode
+ Raylib.Types: RLTextureFilterAnisotropic16x :: RLTextureFilter
+ Raylib.Types: RLTextureFilterAnisotropic4x :: RLTextureFilter
+ Raylib.Types: RLTextureFilterAnisotropic8x :: RLTextureFilter
+ Raylib.Types: RLTextureFilterBilinear :: RLTextureFilter
+ Raylib.Types: RLTextureFilterPoint :: RLTextureFilter
+ Raylib.Types: RLTextureFilterTrilinear :: RLTextureFilter
+ Raylib.Types: RLTextureParamFilterAnisotropic :: RLTextureParam
+ Raylib.Types: RLTextureParamFilterLinear :: RLTextureParam
+ Raylib.Types: RLTextureParamFilterLinearMipNearest :: RLTextureParam
+ Raylib.Types: RLTextureParamFilterMipLinear :: RLTextureParam
+ Raylib.Types: RLTextureParamFilterMipNearest :: RLTextureParam
+ Raylib.Types: RLTextureParamFilterNearest :: RLTextureParam
+ Raylib.Types: RLTextureParamFilterNearestMipLinear :: RLTextureParam
+ Raylib.Types: RLTextureParamMagFilter :: RLTextureParam
+ Raylib.Types: RLTextureParamMinFilter :: RLTextureParam
+ Raylib.Types: RLTextureParamMipmapBiasRatio :: RLTextureParam
+ Raylib.Types: RLTextureParamWrapS :: RLTextureParam
+ Raylib.Types: RLTextureParamWrapT :: RLTextureParam
+ Raylib.Types: RLTriangles :: RLDrawMode
+ Raylib.Types: RLVertexBuffer :: Int -> [Vector3] -> [Vector2] -> [Color] -> [Integer] -> Integer -> [Integer] -> RLVertexBuffer
+ Raylib.Types: RlBlendAddColors :: RLBlendMode
+ Raylib.Types: RlBlendAdditive :: RLBlendMode
+ Raylib.Types: RlBlendAlpha :: RLBlendMode
+ Raylib.Types: RlBlendAlphaPremultiply :: RLBlendMode
+ Raylib.Types: RlBlendCustom :: RLBlendMode
+ Raylib.Types: RlBlendCustomSeparate :: RLBlendMode
+ Raylib.Types: RlBlendMultiplied :: RLBlendMode
+ Raylib.Types: RlBlendSubtractColors :: RLBlendMode
+ Raylib.Types: [rlDrawCall'mode] :: RLDrawCall -> RLDrawMode
+ Raylib.Types: [rlDrawCall'textureId] :: RLDrawCall -> Integer
+ Raylib.Types: [rlDrawCall'vertexAlignment] :: RLDrawCall -> Int
+ Raylib.Types: [rlDrawCall'vertexCount] :: RLDrawCall -> Int
+ Raylib.Types: [rlRenderBatch'bufferCount] :: RLRenderBatch -> Int
+ Raylib.Types: [rlRenderBatch'currentBuffer] :: RLRenderBatch -> Int
+ Raylib.Types: [rlRenderBatch'currentDepth] :: RLRenderBatch -> Float
+ Raylib.Types: [rlRenderBatch'drawCounter] :: RLRenderBatch -> Int
+ Raylib.Types: [rlRenderBatch'draws] :: RLRenderBatch -> [RLDrawCall]
+ Raylib.Types: [rlRenderBatch'vertexBuffers] :: RLRenderBatch -> [RLVertexBuffer]
+ Raylib.Types: [rlVertexBuffer'colors] :: RLVertexBuffer -> [Color]
+ Raylib.Types: [rlVertexBuffer'elementCount] :: RLVertexBuffer -> Int
+ Raylib.Types: [rlVertexBuffer'indices] :: RLVertexBuffer -> [Integer]
+ Raylib.Types: [rlVertexBuffer'texcoords] :: RLVertexBuffer -> [Vector2]
+ Raylib.Types: [rlVertexBuffer'vaoId] :: RLVertexBuffer -> Integer
+ Raylib.Types: [rlVertexBuffer'vboId] :: RLVertexBuffer -> [Integer]
+ Raylib.Types: [rlVertexBuffer'vertices] :: RLVertexBuffer -> [Vector3]
+ Raylib.Types: data GLShaderType
+ Raylib.Types: data RLBlendMode
+ Raylib.Types: data RLBufferHint
+ Raylib.Types: data RLCullMode
+ Raylib.Types: data RLDrawCall
+ Raylib.Types: data RLDrawMode
+ Raylib.Types: data RLFramebufferAttachTextureType
+ Raylib.Types: data RLFramebufferAttachType
+ Raylib.Types: data RLGLVersion
+ Raylib.Types: data RLMatrixMode
+ Raylib.Types: data RLPixelFormat
+ Raylib.Types: data RLRenderBatch
+ Raylib.Types: data RLShaderAttributeDataType
+ Raylib.Types: data RLShaderLocationIndex
+ Raylib.Types: data RLShaderUniformDataType
+ Raylib.Types: data RLTextureFilter
+ Raylib.Types: data RLTextureParam
+ Raylib.Types: data RLTraceLogLevel
+ Raylib.Types: data RLVertexBuffer
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.GLShaderType
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLBlendMode
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLBufferHint
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLCullMode
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLDrawCall
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLDrawMode
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLFramebufferAttachTextureType
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLFramebufferAttachType
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLGLVersion
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLMatrixMode
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLPixelFormat
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLRenderBatch
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLShaderAttributeDataType
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLShaderLocationIndex
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLShaderUniformDataType
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLTextureFilter
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLTextureParam
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLTraceLogLevel
+ Raylib.Types: instance Foreign.Storable.Storable Raylib.Types.RLVertexBuffer
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.GLShaderType
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLBlendMode
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLBufferHint
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLCullMode
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLDrawCall
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLDrawMode
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLFramebufferAttachTextureType
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLFramebufferAttachType
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLGLVersion
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLMatrixMode
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLPixelFormat
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLRenderBatch
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLShaderAttributeDataType
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLShaderLocationIndex
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLShaderUniformDataType
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLTextureFilter
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLTextureParam
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLTraceLogLevel
+ Raylib.Types: instance GHC.Classes.Eq Raylib.Types.RLVertexBuffer
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.GLShaderType
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLBlendMode
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLBufferHint
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLCullMode
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLDrawMode
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLFramebufferAttachTextureType
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLFramebufferAttachType
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLGLVersion
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLMatrixMode
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLPixelFormat
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLShaderAttributeDataType
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLShaderLocationIndex
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLShaderUniformDataType
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLTextureFilter
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLTextureParam
+ Raylib.Types: instance GHC.Enum.Enum Raylib.Types.RLTraceLogLevel
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.GLShaderType
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLBlendMode
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLBufferHint
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLCullMode
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLDrawCall
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLDrawMode
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLFramebufferAttachTextureType
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLFramebufferAttachType
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLGLVersion
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLMatrixMode
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLPixelFormat
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLRenderBatch
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLShaderAttributeDataType
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLShaderLocationIndex
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLShaderUniformDataType
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLTextureFilter
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLTextureParam
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLTraceLogLevel
+ Raylib.Types: instance GHC.Show.Show Raylib.Types.RLVertexBuffer
+ Raylib.Types: instance Raylib.ForeignUtil.Freeable Raylib.Types.RLDrawCall
+ Raylib.Types: instance Raylib.ForeignUtil.Freeable Raylib.Types.RLRenderBatch
+ Raylib.Types: instance Raylib.ForeignUtil.Freeable Raylib.Types.RLVertexBuffer
+ Raylib.Util.RLGL: rlActiveDrawBuffers :: Int -> IO ()
+ Raylib.Util.RLGL: rlActiveTextureSlot :: Int -> IO ()
+ Raylib.Util.RLGL: rlBegin :: RLDrawMode -> IO ()
+ Raylib.Util.RLGL: rlBindImageTexture :: Integer -> Integer -> RLPixelFormat -> Bool -> IO ()
+ Raylib.Util.RLGL: rlBindShaderBuffer :: Integer -> Integer -> IO ()
+ Raylib.Util.RLGL: rlCheckErrors :: IO ()
+ Raylib.Util.RLGL: rlCheckRenderBatchLimit :: Int -> IO Bool
+ Raylib.Util.RLGL: rlClearColor :: Word8 -> Word8 -> Word8 -> Word8 -> IO ()
+ Raylib.Util.RLGL: rlClearScreenBuffers :: IO ()
+ Raylib.Util.RLGL: rlColor3f :: Float -> Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlColor4f :: Float -> Float -> Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlColor4ub :: Word8 -> Word8 -> Word8 -> Word8 -> IO ()
+ Raylib.Util.RLGL: rlCompileShader :: String -> GLShaderType -> IO Integer
+ Raylib.Util.RLGL: rlComputeShaderDispatch :: Integer -> Integer -> Integer -> IO ()
+ Raylib.Util.RLGL: rlCopyShaderBuffer :: Integer -> Integer -> Integer -> Integer -> Integer -> IO ()
+ Raylib.Util.RLGL: rlCubemapParameters :: Integer -> RLTextureParam -> Int -> IO ()
+ Raylib.Util.RLGL: rlDisableBackfaceCulling :: IO ()
+ Raylib.Util.RLGL: rlDisableColorBlend :: IO ()
+ Raylib.Util.RLGL: rlDisableDepthMask :: IO ()
+ Raylib.Util.RLGL: rlDisableDepthTest :: IO ()
+ Raylib.Util.RLGL: rlDisableFramebuffer :: IO ()
+ Raylib.Util.RLGL: rlDisableScissorTest :: IO ()
+ Raylib.Util.RLGL: rlDisableShader :: IO ()
+ Raylib.Util.RLGL: rlDisableSmoothLines :: IO ()
+ Raylib.Util.RLGL: rlDisableStereoRender :: IO ()
+ Raylib.Util.RLGL: rlDisableTexture :: IO ()
+ Raylib.Util.RLGL: rlDisableTextureCubemap :: IO ()
+ Raylib.Util.RLGL: rlDisableVertexArray :: IO ()
+ Raylib.Util.RLGL: rlDisableVertexAttribute :: Integer -> IO ()
+ Raylib.Util.RLGL: rlDisableVertexBuffer :: IO ()
+ Raylib.Util.RLGL: rlDisableVertexBufferElement :: IO ()
+ Raylib.Util.RLGL: rlDisableWireMode :: IO ()
+ Raylib.Util.RLGL: rlDrawRenderBatch :: RLRenderBatch -> IO RLRenderBatch
+ Raylib.Util.RLGL: rlDrawRenderBatchActive :: IO ()
+ Raylib.Util.RLGL: rlDrawVertexArray :: Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlDrawVertexArrayElements :: Int -> [Int] -> IO ()
+ Raylib.Util.RLGL: rlDrawVertexArrayElementsInstanced :: Int -> [Int] -> Int -> IO ()
+ Raylib.Util.RLGL: rlDrawVertexArrayInstanced :: Int -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlEnableBackfaceCulling :: IO ()
+ Raylib.Util.RLGL: rlEnableColorBlend :: IO ()
+ Raylib.Util.RLGL: rlEnableDepthMask :: IO ()
+ Raylib.Util.RLGL: rlEnableDepthTest :: IO ()
+ Raylib.Util.RLGL: rlEnableFramebuffer :: Integer -> IO ()
+ Raylib.Util.RLGL: rlEnableScissorTest :: IO ()
+ Raylib.Util.RLGL: rlEnableShader :: Integer -> IO ()
+ Raylib.Util.RLGL: rlEnableSmoothLines :: IO ()
+ Raylib.Util.RLGL: rlEnableStereoRender :: IO ()
+ Raylib.Util.RLGL: rlEnableTexture :: Integer -> IO ()
+ Raylib.Util.RLGL: rlEnableTextureCubemap :: Integer -> IO ()
+ Raylib.Util.RLGL: rlEnableVertexArray :: Integer -> IO Bool
+ Raylib.Util.RLGL: rlEnableVertexAttribute :: Integer -> IO ()
+ Raylib.Util.RLGL: rlEnableVertexBuffer :: Integer -> IO ()
+ Raylib.Util.RLGL: rlEnableVertexBufferElement :: Integer -> IO ()
+ Raylib.Util.RLGL: rlEnableWireMode :: IO ()
+ Raylib.Util.RLGL: rlEnd :: IO ()
+ Raylib.Util.RLGL: rlFramebufferAttach :: Integer -> Integer -> RLFramebufferAttachType -> RLFramebufferAttachTextureType -> Int -> IO ()
+ Raylib.Util.RLGL: rlFramebufferComplete :: Integer -> IO Bool
+ Raylib.Util.RLGL: rlFrustum :: Double -> Double -> Double -> Double -> Double -> Double -> IO ()
+ Raylib.Util.RLGL: rlGenTextureMipmaps :: Integer -> Int -> Int -> RLPixelFormat -> IO Int
+ Raylib.Util.RLGL: rlGetFramebufferHeight :: IO Int
+ Raylib.Util.RLGL: rlGetFramebufferWidth :: IO Int
+ Raylib.Util.RLGL: rlGetGlTextureFormats :: RLPixelFormat -> IO (Integer, Integer, Integer)
+ Raylib.Util.RLGL: rlGetLineWidth :: IO Float
+ Raylib.Util.RLGL: rlGetLocationAttrib :: Integer -> String -> IO Int
+ Raylib.Util.RLGL: rlGetLocationUniform :: Integer -> String -> IO Int
+ Raylib.Util.RLGL: rlGetMatrixModelview :: IO Matrix
+ Raylib.Util.RLGL: rlGetMatrixProjection :: IO Matrix
+ Raylib.Util.RLGL: rlGetMatrixProjectionStereo :: Int -> IO Matrix
+ Raylib.Util.RLGL: rlGetMatrixTransform :: IO Matrix
+ Raylib.Util.RLGL: rlGetMatrixViewOffsetStereo :: Int -> IO Matrix
+ Raylib.Util.RLGL: rlGetPixelFormatName :: RLPixelFormat -> String
+ Raylib.Util.RLGL: rlGetShaderBufferSize :: Integer -> IO Integer
+ Raylib.Util.RLGL: rlGetShaderIdDefault :: IO Integer
+ Raylib.Util.RLGL: rlGetShaderLocsDefault :: IO [Int]
+ Raylib.Util.RLGL: rlGetTextureIdDefault :: IO Integer
+ Raylib.Util.RLGL: rlGetVersion :: IO Int
+ Raylib.Util.RLGL: rlIsStereoRenderEnabled :: IO Bool
+ Raylib.Util.RLGL: rlLoadComputeShaderProgram :: Integer -> IO Integer
+ Raylib.Util.RLGL: rlLoadDrawCube :: IO ()
+ Raylib.Util.RLGL: rlLoadDrawQuad :: IO ()
+ Raylib.Util.RLGL: rlLoadExtensions :: Ptr () -> IO ()
+ Raylib.Util.RLGL: rlLoadFramebuffer :: Int -> Int -> IO Integer
+ Raylib.Util.RLGL: rlLoadIdentity :: IO ()
+ Raylib.Util.RLGL: rlLoadRenderBatch :: Int -> Int -> IO RLRenderBatch
+ Raylib.Util.RLGL: rlLoadShaderBuffer :: (Freeable a, Storable a) => Integer -> [a] -> RLBufferHint -> IO Integer
+ Raylib.Util.RLGL: rlLoadShaderCode :: String -> String -> IO Integer
+ Raylib.Util.RLGL: rlLoadShaderProgram :: Integer -> Integer -> IO Integer
+ Raylib.Util.RLGL: rlLoadTexture :: [Int] -> Int -> Int -> RLPixelFormat -> Int -> IO Integer
+ Raylib.Util.RLGL: rlLoadTextureCubemap :: [Int] -> RLPixelFormat -> IO Integer
+ Raylib.Util.RLGL: rlLoadTextureDepth :: Int -> Int -> Bool -> IO Integer
+ Raylib.Util.RLGL: rlLoadVertexArray :: IO Integer
+ Raylib.Util.RLGL: rlLoadVertexBuffer :: (Freeable a, Storable a) => [a] -> Int -> Bool -> IO Integer
+ Raylib.Util.RLGL: rlLoadVertexBufferElement :: (Freeable a, Storable a) => [a] -> Int -> Bool -> IO Integer
+ Raylib.Util.RLGL: rlMatrixMode :: RLMatrixMode -> IO ()
+ Raylib.Util.RLGL: rlMultMatrixf :: [Float] -> IO ()
+ Raylib.Util.RLGL: rlNormal3f :: Float -> Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlOrtho :: Double -> Double -> Double -> Double -> Double -> Double -> IO ()
+ Raylib.Util.RLGL: rlPopMatrix :: IO ()
+ Raylib.Util.RLGL: rlPushMatrix :: IO ()
+ Raylib.Util.RLGL: rlReadScreenPixels :: Int -> Int -> IO [Word8]
+ Raylib.Util.RLGL: rlReadTexturePixels :: Integer -> Int -> Int -> RLPixelFormat -> IO [Word8]
+ Raylib.Util.RLGL: rlRotatef :: Float -> Float -> Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlScalef :: Float -> Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlScissor :: Int -> Int -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlSetBlendFactors :: Int -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlSetBlendFactorsSeparate :: Int -> Int -> Int -> Int -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlSetBlendMode :: RLBlendMode -> IO ()
+ Raylib.Util.RLGL: rlSetCullFace :: RLCullMode -> IO ()
+ Raylib.Util.RLGL: rlSetFramebufferHeight :: Int -> IO ()
+ Raylib.Util.RLGL: rlSetFramebufferWidth :: Int -> IO ()
+ Raylib.Util.RLGL: rlSetLineWidth :: Float -> IO ()
+ Raylib.Util.RLGL: rlSetMatrixModelview :: Matrix -> IO ()
+ Raylib.Util.RLGL: rlSetMatrixProjection :: Matrix -> IO ()
+ Raylib.Util.RLGL: rlSetMatrixProjectionStereo :: Matrix -> Matrix -> IO ()
+ Raylib.Util.RLGL: rlSetMatrixViewOffsetStereo :: Matrix -> Matrix -> IO ()
+ Raylib.Util.RLGL: rlSetRenderBatchActive :: Maybe RLRenderBatch -> IO ()
+ Raylib.Util.RLGL: rlSetShader :: Integer -> [Int] -> IO ()
+ Raylib.Util.RLGL: rlSetTexture :: Integer -> IO ()
+ Raylib.Util.RLGL: rlSetUniform :: Int -> ShaderUniformDataV -> IO ()
+ Raylib.Util.RLGL: rlSetUniformMatrix :: Int -> Matrix -> IO ()
+ Raylib.Util.RLGL: rlSetUniformSampler :: Int -> Integer -> IO ()
+ Raylib.Util.RLGL: rlSetVertexAttribute :: Integer -> Int -> Int -> Bool -> Int -> Ptr () -> IO ()
+ Raylib.Util.RLGL: rlSetVertexAttributeDefault :: Int -> Ptr () -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlSetVertexAttributeDivisor :: Integer -> Int -> IO ()
+ Raylib.Util.RLGL: rlTexCoord2f :: Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlTextureParameters :: Integer -> RLTextureParam -> Int -> IO ()
+ Raylib.Util.RLGL: rlTranslatef :: Float -> Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlUnloadFramebuffer :: Integer -> IO ()
+ Raylib.Util.RLGL: rlUnloadRenderBatch :: RLRenderBatch -> IO ()
+ Raylib.Util.RLGL: rlUnloadShaderBuffer :: Integer -> IO ()
+ Raylib.Util.RLGL: rlUnloadShaderProgram :: Integer -> IO ()
+ Raylib.Util.RLGL: rlUnloadTexture :: Integer -> IO ()
+ Raylib.Util.RLGL: rlUnloadVertexArray :: Integer -> IO ()
+ Raylib.Util.RLGL: rlUnloadVertexBuffer :: Integer -> IO ()
+ Raylib.Util.RLGL: rlUpdateShaderBuffer :: (Freeable a, Storable a) => Integer -> a -> Integer -> IO ()
+ Raylib.Util.RLGL: rlUpdateTexture :: (Freeable a, Storable a) => Integer -> Int -> Int -> Int -> Int -> RLPixelFormat -> [a] -> IO ()
+ Raylib.Util.RLGL: rlUpdateVertexBuffer :: (Freeable a, Storable a) => Integer -> [a] -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlUpdateVertexBufferElements :: (Freeable a, Storable a) => Integer -> [a] -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlVertex2f :: Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlVertex2i :: Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlVertex3f :: Float -> Float -> Float -> IO ()
+ Raylib.Util.RLGL: rlViewport :: Int -> Int -> Int -> Int -> IO ()
+ Raylib.Util.RLGL: rlglClose :: IO ()
+ Raylib.Util.RLGL: rlglInit :: Int -> Int -> IO ()
- Raylib.Types: ShaderUniformSampler2D :: Integer -> ShaderUniformData
+ Raylib.Types: ShaderUniformSampler2D :: Texture -> ShaderUniformData
- Raylib.Types: ShaderUniformSampler2DV :: [Integer] -> ShaderUniformDataV
+ Raylib.Types: ShaderUniformSampler2DV :: [Texture] -> ShaderUniformDataV
Files
- CHANGELOG.md +7/−0
- CONTRIBUTING.md +3/−3
- ROADMAP.md +2/−2
- examples/basic-images/assets/raylib-logo.png binary
- examples/basic-rlgl/assets/cubicmap_atlas.png binary
- examples/basic-rlgl/src/Main.hs +192/−0
- h-raylib.cabal +11/−7
- lib/rl_bindings.c +19/−11
- lib/rl_internal.c +71/−3
- lib/rl_internal.h +3/−0
- lib/rlgl_bindings.c +57/−0
- lib/rlgl_bindings.h +25/−0
- src/Raylib/Core.hs +7/−9
- src/Raylib/Core/Audio.hs +8/−8
- src/Raylib/Core/Models.hs +3/−5
- src/Raylib/Core/Shapes.hs +5/−5
- src/Raylib/Core/Text.hs +15/−15
- src/Raylib/Core/Textures.hs +2/−2
- src/Raylib/ForeignUtil.hs +40/−15
- src/Raylib/Native.hs +232/−76
- src/Raylib/Types.hs +824/−8
- src/Raylib/Util/RLGL.hs +944/−0
CHANGELOG.md view
@@ -1,5 +1,12 @@ # h-raylib changelog +## Version 4.5.3.2 +_1 March, 2023_ + +\[[#12](https://github.com/Anut-py/h-raylib/pull/12)\] + +- Added rlgl bindings (`Raylib.Util.RLGL`) + ## Version 4.5.3.1 _27 February, 2023_
CONTRIBUTING.md view
@@ -12,7 +12,7 @@ _This section only contains h-raylib specific information. For information about raylib in general, view the [raylib wiki](https://github.com/raysan5/raylib/wiki)._ -This project is split into 9 public modules. `Raylib.Types` contains all of raylib's types and low-level code to convert them to and from raw bytes. `Raylib.Util` contains miscellaneous utility functions. `Raylib.Util.Colors` contains some colors defined by raylib. The other 6 public modules, `Raylib.Core`, `Raylib.Core.Shapes`, `Raylib.Core.Textures`, `Raylib.Core.Text`, `Raylib.Core.Models`, and `Raylib.Core.Audio`, correspond to their respective raylib modules. +This project is split into 10 public modules. `Raylib.Types` contains all of raylib's types and low-level code to convert them to and from raw bytes. `Raylib.Util` contains miscellaneous utility functions. `Raylib.Util.Colors` contains some colors defined by raylib. The other 7 public modules, `Raylib.Core`, `Raylib.Core.Shapes`, `Raylib.Core.Textures`, `Raylib.Core.Text`, `Raylib.Core.Models`, `Raylib.Core.Audio`, and `Raylib.Util.RLGL`, correspond to their respective raylib modules. The functions in h-raylib are an almost one-to-one mapping to their corresponding raylib functions. The types are, in some cases, slightly modified if it is possible to utilize Haskell features. @@ -22,7 +22,7 @@ `Raylib.Types` has 4 sections: one for enumerations, one for typeclasses, one for structures, and one for callbacks. -The enumerations section contains Haskell sum types that are instances of `Enum`. Each of these types corresponds to a raylib `enum`. The `fromEnum` and `toEnum` functions for these types use the numbers associated with these values in the C `enum`s. Most of these types are instances of `Storable` so they can be converted to raw bytes and passed to a C function. _NOTE: Some of these Haskell types correspond to C `enum`s that are in C source files, rather than `raylib.h`._ +The enumerations section contains Haskell sum types that are instances of `Enum`. Each of these types corresponds to a raylib `enum` or set of `define`s. The `fromEnum` and `toEnum` functions for these types use the numbers associated with these values in the C `enum`s. Most of these types are instances of `Storable` so they can be converted to raw bytes and passed to a C function. _NOTE: Some of these Haskell types correspond to C `enum`s that are in C source files, rather than header files._ The typeclasses section contains Haskell typeclasses that are derived by some of the types in the structures section. @@ -38,7 +38,7 @@ `Raylib.Util.Colors` is very simple: it declares 26 colors defined in `raylib.h`, namely `lightGray`, `gray`, `darkGray`, `yellow`, `gold`, `orange`, `pink`, `red`, `maroon`, `green`, `lime`, `darkGreen`, `skyBlue`, `blue`, `darkBlue`, `purple`, `violet`, `darkPurple`, `beige`, `brown`, `darkBrown`, `white`, `black`, `blank`, `magenta`, and `rayWhite`. -### The other 6 modules +### The other 7 modules These modules contain only functions. Each of these functions corresponds to a C function. The `unload*` functions are optional; even if you do not call them, all assets used by a program will be automatically be unloaded when it terminates (see the "Memory management" section). For some types (e.g. `Image`), there is no unloading function because the memory used by the type can be unloaded in function calls.
ROADMAP.md view
@@ -3,11 +3,11 @@ Items higher on the list have higher priority. ## Uncompleted -- Bind `rlgl` - Bind `rcamera` - Bind `raymath` - Bind `raygui` ## Completed - Make it easier to pass shader parameters (Added in `4.5.3.0`) -- Allow manual unloading of assets for larger projects (Not published to hackage) +- Allow manual unloading of assets for larger projects (Added in `4.5.3.1`) +- Bind `rlgl` (Not published to Hackage)
+ examples/basic-images/assets/raylib-logo.png view
binary file changed (absent → 3760 bytes)
+ examples/basic-rlgl/assets/cubicmap_atlas.png view
binary file changed (absent → 37160 bytes)
+ examples/basic-rlgl/src/Main.hs view
@@ -0,0 +1,192 @@+{-# OPTIONS -Wall #-} +module Main where + +import Raylib.Core (beginDrawing, beginMode3D, changeDirectory, clearBackground, closeWindow, endDrawing, endMode3D, getApplicationDirectory, initWindow, setTargetFPS) +import Raylib.Core.Models (drawGrid) +import Raylib.Core.Textures (loadTexture) +import Raylib.Types (Camera3D (Camera3D), CameraProjection (CameraPerspective), Color (Color), RLDrawMode (RLQuads), Rectangle (Rectangle), Texture (texture'height, texture'id, texture'width), Vector3 (Vector3)) +import Raylib.Util (whileWindowOpen0) +import Raylib.Util.Colors (rayWhite, white) +import Raylib.Util.RLGL (rlBegin, rlColor4ub, rlEnd, rlNormal3f, rlPopMatrix, rlSetTexture, rlTexCoord2f, rlVertex3f, rlPushMatrix, rlTranslatef, rlRotatef, rlScalef) +import Prelude hiding (length) + +texturePath :: String +texturePath = "../../../../../../../../../examples/basic-rlgl/assets/cubicmap_atlas.png" + +main :: IO () +main = do + initWindow 650 400 "raylib [rlgl] example - basic rlgl" + setTargetFPS 60 + _ <- getApplicationDirectory >>= changeDirectory + + let camera = Camera3D (Vector3 0 10 10) (Vector3 0 0 0) (Vector3 0 1 0) 45 CameraPerspective + + texture <- loadTexture texturePath + + whileWindowOpen0 + (do + beginDrawing + clearBackground rayWhite + + beginMode3D camera + + drawCubeTexture texture (Vector3 (-2) 2 0) 2 4 2 white + drawCubeTextureRec + texture + (Rectangle 0 (fromIntegral (texture'height texture) / 2.0) (fromIntegral (texture'width texture) / 2.0) (fromIntegral (texture'height texture) / 2.0)) + (Vector3 2 1 0) + 2 + 2 + 2 + white + drawGrid 10 1 + + endMode3D + + endDrawing + ) + + closeWindow + +drawCubeTexture :: Texture -> Vector3 -> Float -> Float -> Float -> Color -> IO () +drawCubeTexture texture (Vector3 x y z) width height length (Color r g b a) = do + rlSetTexture $ texture'id texture + + rlPushMatrix + + -- NOTE: Transformation is applied in inverse order (scale -> rotate -> translate) + rlTranslatef (-1) 0 0 + rlRotatef 45 0 1 0 + rlScalef 1.5 1.5 1.5 + + rlBegin RLQuads + rlColor4ub r g b a + + -- Front Face + rlNormal3f 0 0 1 -- Normal Pointing Towards Viewer + rlTexCoord2f 0 0 >> rlVertex3f (x - width / 2) (y - height / 2) (z + length / 2) -- Bottom Left Of The Texture and Quad + rlTexCoord2f 1 0 >> rlVertex3f (x + width / 2) (y - height / 2) (z + length / 2) -- Bottom Right Of The Texture and Quad + rlTexCoord2f 1 1 >> rlVertex3f (x + width / 2) (y + height / 2) (z + length / 2) -- Top Right Of The Texture and Quad + rlTexCoord2f 0 1 >> rlVertex3f (x - width / 2) (y + height / 2) (z + length / 2) -- Top Left Of The Texture and Quad + + -- Back Face + rlNormal3f 0 0 (-1) -- Normal Pointing Away From Viewer + rlTexCoord2f 1 0 >> rlVertex3f (x - width / 2) (y - height / 2) (z - length / 2) -- Bottom Right Of The Texture and Quad + rlTexCoord2f 1 1 >> rlVertex3f (x - width / 2) (y + height / 2) (z - length / 2) -- Top Right Of The Texture and Quad + rlTexCoord2f 0 1 >> rlVertex3f (x + width / 2) (y + height / 2) (z - length / 2) -- Top Left Of The Texture and Quad + rlTexCoord2f 0 0 >> rlVertex3f (x + width / 2) (y - height / 2) (z - length / 2) -- Bottom Left Of The Texture and Quad + + -- Top Face + rlNormal3f 0 1 0 -- Normal Pointing Up + rlTexCoord2f 0 1 >> rlVertex3f (x - width / 2) (y + height / 2) (z - length / 2) -- Top Left Of The Texture and Quad + rlTexCoord2f 0 0 >> rlVertex3f (x - width / 2) (y + height / 2) (z + length / 2) -- Bottom Left Of The Texture and Quad + rlTexCoord2f 1 0 >> rlVertex3f (x + width / 2) (y + height / 2) (z + length / 2) -- Bottom Right Of The Texture and Quad + rlTexCoord2f 1 1 >> rlVertex3f (x + width / 2) (y + height / 2) (z - length / 2) -- Top Right Of The Texture and Quad + + -- Bottom Face + rlNormal3f 0 (-1) 0 -- Normal Pointing Down + rlTexCoord2f 1 1 >> rlVertex3f (x - width / 2) (y - height / 2) (z - length / 2) -- Top Right Of The Texture and Quad + rlTexCoord2f 0 1 >> rlVertex3f (x + width / 2) (y - height / 2) (z - length / 2) -- Top Left Of The Texture and Quad + rlTexCoord2f 0 0 >> rlVertex3f (x + width / 2) (y - height / 2) (z + length / 2) -- Bottom Left Of The Texture and Quad + rlTexCoord2f 1 0 >> rlVertex3f (x - width / 2) (y - height / 2) (z + length / 2) -- Bottom Right Of The Texture and Quad + + -- Right face + rlNormal3f 1 0 0 -- Normal Pointing Right + rlTexCoord2f 1 0 >> rlVertex3f (x + width / 2) (y - height / 2) (z - length / 2) -- Bottom Right Of The Texture and Quad + rlTexCoord2f 1 1 >> rlVertex3f (x + width / 2) (y + height / 2) (z - length / 2) -- Top Right Of The Texture and Quad + rlTexCoord2f 0 1 >> rlVertex3f (x + width / 2) (y + height / 2) (z + length / 2) -- Top Left Of The Texture and Quad + rlTexCoord2f 0 0 >> rlVertex3f (x + width / 2) (y - height / 2) (z + length / 2) -- Bottom Left Of The Texture and Quad + + -- Left Face + rlNormal3f (-1) 0 0 -- Normal Pointing Left + rlTexCoord2f 0 0 >> rlVertex3f (x - width / 2) (y - height / 2) (z - length / 2) -- Bottom Left Of The Texture and Quad + rlTexCoord2f 1 0 >> rlVertex3f (x - width / 2) (y - height / 2) (z + length / 2) -- Bottom Right Of The Texture and Quad + rlTexCoord2f 1 1 >> rlVertex3f (x - width / 2) (y + height / 2) (z + length / 2) -- Top Right Of The Texture and Quad + rlTexCoord2f 0 1 >> rlVertex3f (x - width / 2) (y + height / 2) (z - length / 2) -- Top Left Of The Texture and Quad + + rlEnd + rlPopMatrix + + rlSetTexture 0 + +drawCubeTextureRec :: Texture -> Rectangle -> Vector3 -> Float -> Float -> Float -> Color -> IO () +drawCubeTextureRec texture (Rectangle sX sY sW sH) (Vector3 x y z) width height length (Color r g b a) = do + let texWidth = realToFrac $ texture'width texture :: Float + texHeight = realToFrac $ texture'height texture :: Float + + rlSetTexture $ texture'id texture + + -- We calculate the normalized texture coordinates for the desired texture-source-rectangle + -- It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent + rlBegin RLQuads + rlColor4ub r g b a + + -- Front face + rlNormal3f 0 0 1 + rlTexCoord2f (sX / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x - width / 2) (y - height / 2) (z + length / 2) + rlTexCoord2f ((sX + sW) / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x + width / 2) (y - height / 2) (z + length / 2) + rlTexCoord2f ((sX + sW) / texWidth) (sY / texHeight) + rlVertex3f (x + width / 2) (y + height / 2) (z + length / 2) + rlTexCoord2f (sX / texWidth) (sY / texHeight) + rlVertex3f (x - width / 2) (y + height / 2) (z + length / 2) + + -- Back face + rlNormal3f 0 0 (-1) + rlTexCoord2f ((sX + sW) / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x - width / 2) (y - height / 2) (z - length / 2) + rlTexCoord2f ((sX + sW) / texWidth) (sY / texHeight) + rlVertex3f (x - width / 2) (y + height / 2) (z - length / 2) + rlTexCoord2f (sX / texWidth) (sY / texHeight) + rlVertex3f (x + width / 2) (y + height / 2) (z - length / 2) + rlTexCoord2f (sX / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x + width / 2) (y - height / 2) (z - length / 2) + + -- Top face + rlNormal3f 0 1 0 + rlTexCoord2f (sX / texWidth) (sY / texHeight) + rlVertex3f (x - width / 2) (y + height / 2) (z - length / 2) + rlTexCoord2f (sX / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x - width / 2) (y + height / 2) (z + length / 2) + rlTexCoord2f ((sX + sW) / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x + width / 2) (y + height / 2) (z + length / 2) + rlTexCoord2f ((sX + sW) / texWidth) (sY / texHeight) + rlVertex3f (x + width / 2) (y + height / 2) (z - length / 2) + + -- Bottom face + rlNormal3f 0 (-1) 0 + rlTexCoord2f ((sX + sW) / texWidth) (sY / texHeight) + rlVertex3f (x - width / 2) (y - height / 2) (z - length / 2) + rlTexCoord2f (sX / texWidth) (sY / texHeight) + rlVertex3f (x + width / 2) (y - height / 2) (z - length / 2) + rlTexCoord2f (sX / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x + width / 2) (y - height / 2) (z + length / 2) + rlTexCoord2f ((sX + sW) / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x - width / 2) (y - height / 2) (z + length / 2) + + -- Right face + rlNormal3f 1 0 0 + rlTexCoord2f ((sX + sW) / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x + width / 2) (y - height / 2) (z - length / 2) + rlTexCoord2f ((sX + sW) / texWidth) (sY / texHeight) + rlVertex3f (x + width / 2) (y + height / 2) (z - length / 2) + rlTexCoord2f (sX / texWidth) (sY / texHeight) + rlVertex3f (x + width / 2) (y + height / 2) (z + length / 2) + rlTexCoord2f (sX / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x + width / 2) (y - height / 2) (z + length / 2) + + -- Left face + rlNormal3f (-1) 0 0 + rlTexCoord2f (sX / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x - width / 2) (y - height / 2) (z - length / 2) + rlTexCoord2f ((sX + sW) / texWidth) ((sY + sH) / texHeight) + rlVertex3f (x - width / 2) (y - height / 2) (z + length / 2) + rlTexCoord2f ((sX + sW) / texWidth) (sY / texHeight) + rlVertex3f (x - width / 2) (y + height / 2) (z + length / 2) + rlTexCoord2f (sX / texWidth) (sY / texHeight) + rlVertex3f (x - width / 2) (y + height / 2) (z - length / 2) + + rlEnd + + rlSetTexture 0
h-raylib.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: h-raylib -version: 4.5.3.1 +version: 4.5.3.2 synopsis: Raylib bindings for Haskell category: graphics description: @@ -22,6 +22,7 @@ examples/**/*.mtl examples/**/*.obj examples/**/*.vert + examples/**/*.png lib/*.c lib/*.h lib/rglfw.m @@ -80,7 +81,6 @@ , h-raylib -- core - executable basic-window import: example-options hs-source-dirs: examples/basic-window/src @@ -97,28 +97,24 @@ main-is: Main.hs -- textures - executable basic-images import: example-options hs-source-dirs: examples/basic-images/src main-is: Main.hs -- text - executable custom-font-text import: example-options hs-source-dirs: examples/custom-font-text/src main-is: Main.hs -- models - executable basic-models import: example-options hs-source-dirs: examples/basic-models/src main-is: Main.hs -- shaders - executable basic-shaders import: example-options hs-source-dirs: examples/basic-shaders/src @@ -130,12 +126,17 @@ main-is: Main.hs -- audio - executable basic-audio import: example-options hs-source-dirs: examples/basic-audio/src main-is: Main.hs +-- rlgl +executable basic-rlgl + import: example-options + hs-source-dirs: examples/basic-rlgl/src + main-is: Main.hs + library exposed-modules: Raylib.Core @@ -147,6 +148,7 @@ Raylib.Types Raylib.Util Raylib.Util.Colors + Raylib.Util.RLGL other-modules: Raylib.ForeignUtil @@ -222,6 +224,7 @@ lib/rglfw.m lib/rl_bindings.c lib/rl_internal.c + lib/rlgl_bindings.c raylib/src/raudio.c raylib/src/rcore.c raylib/src/rmodels.c @@ -234,6 +237,7 @@ c-sources: lib/rl_bindings.c lib/rl_internal.c + lib/rlgl_bindings.c raylib/src/raudio.c raylib/src/rcore.c raylib/src/rglfw.c
lib/rl_bindings.c view
@@ -806,7 +806,8 @@ return ptr; } -bool IsTextureReady_(Texture* a) { +bool IsTextureReady_(Texture *a) +{ return IsTextureReady(*a); } @@ -815,7 +816,8 @@ UnloadTexture(*a); } -bool IsRenderTextureReady_(RenderTexture* a) { +bool IsRenderTextureReady_(RenderTexture *a) +{ return IsRenderTextureReady(*a); } @@ -914,21 +916,21 @@ return ptr; } -Color *ColorTint_(Color* a, Color* b) +Color *ColorTint_(Color *a, Color *b) { Color *ptr = (Color *)malloc(sizeof(Color)); *ptr = ColorTint(*a, *b); return ptr; } -Color *ColorBrightness_(Color* a, float b) +Color *ColorBrightness_(Color *a, float b) { Color *ptr = (Color *)malloc(sizeof(Color)); *ptr = ColorBrightness(*a, b); return ptr; } -Color *ColorContrast_(Color* a, float b) +Color *ColorContrast_(Color *a, float b) { Color *ptr = (Color *)malloc(sizeof(Color)); *ptr = ColorContrast(*a, b); @@ -1481,7 +1483,8 @@ UpdateSound(*a, b, c); } -bool IsWaveReady_(Wave *a) { +bool IsWaveReady_(Wave *a) +{ return IsWaveReady(*a); } @@ -1490,7 +1493,8 @@ UnloadWave(*a); } -bool IsSoundReady_(Sound *a) { +bool IsSoundReady_(Sound *a) +{ return IsSoundReady(*a); } @@ -1580,7 +1584,8 @@ return ptr; } -bool IsMusicReady_(Music *a) { +bool IsMusicReady_(Music *a) +{ return IsMusicReady(*a); } @@ -1656,7 +1661,8 @@ return ptr; } -bool IsAudioStreamReady_(AudioStream *a) { +bool IsAudioStreamReady_(AudioStream *a) +{ return IsAudioStreamReady(*a); } @@ -1730,10 +1736,12 @@ DetachAudioStreamProcessor(*a, *b); } -void AttachAudioMixedProcessor_(AudioCallback *a) { +void AttachAudioMixedProcessor_(AudioCallback *a) +{ AttachAudioMixedProcessor(*a); } -void DetachAudioMixedProcessor_(AudioCallback *a) { +void DetachAudioMixedProcessor_(AudioCallback *a) +{ DetachAudioMixedProcessor(*a); }
lib/rl_internal.c view
@@ -5,16 +5,84 @@ #pragma GCC diagnostic ignored "-Wimplicit-function-declaration" #include "rl_internal.h" #include <config.h> -#include <utils.h> -void UnloadAudioBuffer_(rAudioBuffer *buffer) { +void UnloadAudioBuffer_(rAudioBuffer *buffer) +{ UnloadAudioBuffer(buffer); } -void UnloadMusicStreamData(int ctxType, void *ctxData) { +void UnloadMusicStreamData(int ctxType, void *ctxData) +{ Music music = {0}; music.ctxData = ctxData; music.ctxType = ctxType; UnloadMusicStream(music); +} + +int rlGetPixelDataSize(int width, int height, int format) +{ + int dataSize = 0; // Size in bytes + int bpp = 0; // Bits per pixel + + switch (format) + { + case RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: + bpp = 8; + break; + case RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: + case RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5: + case RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: + case RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: + bpp = 16; + break; + case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: + bpp = 32; + break; + case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8: + bpp = 24; + break; + case RL_PIXELFORMAT_UNCOMPRESSED_R32: + bpp = 32; + break; + case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32: + bpp = 32 * 3; + break; + case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: + bpp = 32 * 4; + break; + case RL_PIXELFORMAT_COMPRESSED_DXT1_RGB: + case RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA: + case RL_PIXELFORMAT_COMPRESSED_ETC1_RGB: + case RL_PIXELFORMAT_COMPRESSED_ETC2_RGB: + case RL_PIXELFORMAT_COMPRESSED_PVRT_RGB: + case RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA: + bpp = 4; + break; + case RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA: + case RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA: + case RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA: + case RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: + bpp = 8; + break; + case RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: + bpp = 2; + break; + default: + break; + } + + dataSize = width * height * bpp / 8; // Total data size in bytes + + // Most compressed formats works on 4x4 blocks, + // if texture is smaller, minimum dataSize is 8 or 16 + if ((width < 4) && (height < 4)) + { + if ((format >= RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) && (format < RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA)) + dataSize = 8; + else if ((format >= RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA) && (format < RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA)) + dataSize = 16; + } + + return dataSize; }
lib/rl_internal.h view
@@ -4,7 +4,10 @@ * @brief Additional functions required for C/Haskell FFI */ #include <raylib.h> +#include <rlgl.h> void UnloadAudioBuffer_(rAudioBuffer *buffer); void UnloadMusicStreamData(int ctxType, void *ctxData); + +int rlGetPixelDataSize(int width, int height, int format);
+ lib/rlgl_bindings.c view
@@ -0,0 +1,57 @@+/** + * See rlgl_bindings.h + */ + +#include "rlgl_bindings.h" +#include <stdlib.h> + +rlRenderBatch *rlLoadRenderBatch_(int numBuffers, int bufferElements) +{ + rlRenderBatch *ptr = (rlRenderBatch *)malloc(sizeof(rlRenderBatch)); + *ptr = rlLoadRenderBatch(numBuffers, bufferElements); + return ptr; +} + +void rlUnloadRenderBatch_(rlRenderBatch *batch) +{ + rlUnloadRenderBatch(*batch); +} + +void rlSetUniformMatrix_(int locIndex, Matrix *mat) +{ + rlSetUniformMatrix(locIndex, *mat); +} + +Matrix *rlGetMatrixProjectionStereo_(int eye) +{ + Matrix *ptr = (Matrix *)malloc(sizeof(Matrix)); + *ptr = rlGetMatrixProjectionStereo(eye); + return ptr; +} + +Matrix *rlGetMatrixViewOffsetStereo_(int eye) +{ + Matrix *ptr = (Matrix *)malloc(sizeof(Matrix)); + *ptr = rlGetMatrixViewOffsetStereo(eye); + return ptr; +} + +void rlSetMatrixProjection_(Matrix *proj) +{ + rlSetMatrixProjection(*proj); +} + +void rlSetMatrixModelview_(Matrix *view) +{ + rlSetMatrixModelview(*view); +} + +void rlSetMatrixProjectionStereo_(Matrix *right, Matrix *left) +{ + rlSetMatrixProjectionStereo(*right, *left); +} + +void rlSetMatrixViewOffsetStereo_(Matrix *right, Matrix *left) +{ + rlSetMatrixViewOffsetStereo(*right, *left); +}
+ lib/rlgl_bindings.h view
@@ -0,0 +1,25 @@+/** + * @file rlgl_bindings.h + * @author Anut-py + * @brief Required methods for binding Haskell to rlgl + */ + +#include <rlgl.h> + +rlRenderBatch *rlLoadRenderBatch_(int numBuffers, int bufferElements); + +void rlUnloadRenderBatch_(rlRenderBatch *batch); + +void rlSetUniformMatrix_(int locIndex, Matrix *mat); + +Matrix *rlGetMatrixProjectionStereo_(int eye); + +Matrix *rlGetMatrixViewOffsetStereo_(int eye); + +void rlSetMatrixProjection_(Matrix *proj); + +void rlSetMatrixModelview_(Matrix *view); + +void rlSetMatrixProjectionStereo_(Matrix *right, Matrix *left); + +void rlSetMatrixViewOffsetStereo_(Matrix *right, Matrix *left);
src/Raylib/Core.hs view
@@ -12,8 +12,6 @@ fromBool, peekArray, toBool, - withArray, - withArrayLen, ) import Foreign.C ( CInt (CInt), @@ -22,7 +20,7 @@ peekCString, withCString, ) -import Raylib.ForeignUtil (c'free, configsToBitflag, pop, popCArray, popCString, withFreeable, withMaybeCString) +import Raylib.ForeignUtil (c'free, configsToBitflag, pop, popCArray, popCString, withFreeable, withFreeableArray, withFreeableArrayLen, withMaybeCString) import Raylib.Internal (addShaderId, shaderLocations, unloadFrameBuffers, unloadShaders, unloadSingleShader, unloadTextures, unloadVaoIds, unloadVboIds) import Raylib.Native ( c'beginBlendMode, @@ -275,7 +273,7 @@ setWindowIcon image = withFreeable image c'setWindowIcon setWindowIcons :: [Image] -> IO () -setWindowIcons images = withArrayLen images (\l ptr -> c'setWindowIcons ptr (fromIntegral l)) +setWindowIcons images = withFreeableArrayLen images (\l ptr -> c'setWindowIcons ptr (fromIntegral l)) setWindowTitle :: String -> IO () setWindowTitle title = withCString title c'setWindowTitle @@ -618,7 +616,7 @@ exportDataAsCode :: [Integer] -> Integer -> String -> IO Bool exportDataAsCode contents size fileName = - toBool <$> withArray (map fromInteger contents) (\c -> withCString fileName (c'exportDataAsCode c (fromIntegral size))) + toBool <$> withFreeableArray (map fromInteger contents) (\c -> withCString fileName (c'exportDataAsCode c (fromIntegral size))) loadFileText :: String -> IO String loadFileText fileName = withCString fileName c'loadFileText >>= popCString @@ -683,7 +681,7 @@ compressData :: [Integer] -> IO [Integer] compressData contents = do - withArrayLen + withFreeableArrayLen (map fromIntegral contents) ( \size c -> do withFreeable @@ -698,7 +696,7 @@ decompressData :: [Integer] -> IO [Integer] decompressData compressedData = do - withArrayLen + withFreeableArrayLen (map fromIntegral compressedData) ( \size c -> do withFreeable @@ -713,7 +711,7 @@ encodeDataBase64 :: [Integer] -> IO [Integer] encodeDataBase64 contents = do - withArrayLen + withFreeableArrayLen (map fromIntegral contents) ( \size c -> do withFreeable @@ -728,7 +726,7 @@ decodeDataBase64 :: [Integer] -> IO [Integer] decodeDataBase64 encodedData = do - withArray + withFreeableArray (map fromIntegral encodedData) ( \c -> do withFreeable
src/Raylib/Core/Audio.hs view
@@ -8,9 +8,14 @@ Storable (peek, sizeOf), castPtr, toBool, - withArrayLen, ) import Foreign.C (CUChar, withCString) +import Raylib.ForeignUtil + ( pop, + popCArray, + withFreeable, + withFreeableArrayLen, + ) import Raylib.Internal (addAudioBuffer, addCtxData, unloadAudioBuffers, unloadCtxData, unloadSingleAudioBuffer, unloadSingleCtxDataPtr) import Raylib.Native ( c'closeAudioDevice, @@ -73,11 +78,6 @@ Sound (sound'stream), Wave (wave'channels, wave'frameCount), ) -import Raylib.ForeignUtil - ( pop, - popCArray, - withFreeable, - ) foreign import ccall safe "raylib.h InitAudioDevice" initAudioDevice :: @@ -96,7 +96,7 @@ loadWave fileName = withCString fileName c'loadWave >>= pop loadWaveFromMemory :: String -> [Integer] -> IO Wave -loadWaveFromMemory fileType fileData = withCString fileType (\f -> withArrayLen (map fromIntegral fileData) (\size d -> c'loadWaveFromMemory f d (fromIntegral $ size * sizeOf (0 :: CUChar)))) >>= pop +loadWaveFromMemory fileType fileData = withCString fileType (\f -> withFreeableArrayLen (map fromIntegral fileData) (\size d -> c'loadWaveFromMemory f d (fromIntegral $ size * sizeOf (0 :: CUChar)))) >>= pop loadSound :: String -> IO Sound loadSound fileName = withCString fileName c'loadSound >>= pop @@ -188,7 +188,7 @@ loadMusicStreamFromMemory :: String -> [Integer] -> IO Music loadMusicStreamFromMemory fileType streamData = do - music <- withCString fileType (\t -> withArrayLen (map fromIntegral streamData) (\size d -> c'loadMusicStreamFromMemory t d (fromIntegral $ size * sizeOf (0 :: CUChar)))) >>= pop + music <- withCString fileType (\t -> withFreeableArrayLen (map fromIntegral streamData) (\size d -> c'loadMusicStreamFromMemory t d (fromIntegral $ size * sizeOf (0 :: CUChar)))) >>= pop addAudioBuffer $ castPtr (audioStream'buffer $ music'stream music) addCtxData (fromEnum $ music'ctxType music) (music'ctxData music) return music
src/Raylib/Core/Models.hs view
@@ -11,8 +11,6 @@ malloc, peekArray, toBool, - withArray, - withArrayLen, ) import Foreign.C (CFloat, withCString) import GHC.IO (unsafePerformIO) @@ -20,7 +18,7 @@ ( c'free, pop, popCArray, - withFreeable, + withFreeable, withFreeableArray, withFreeableArrayLen ) import Raylib.Internal (addShaderId, addTextureId, addVaoId, addVboIds, unloadSingleShader, unloadSingleTexture, unloadSingleVaoId, unloadSingleVboIdList) import Raylib.Native @@ -126,7 +124,7 @@ drawTriangle3D v1 v2 v3 color = withFreeable v1 (\p1 -> withFreeable v2 (\p2 -> withFreeable v3 (withFreeable color . c'drawTriangle3D p1 p2))) drawTriangleStrip3D :: [Vector3] -> Int -> Color -> IO () -drawTriangleStrip3D points pointCount color = withArray points (\p -> withFreeable color (c'drawTriangleStrip3D p (fromIntegral pointCount))) +drawTriangleStrip3D points pointCount color = withFreeableArray points (\p -> withFreeable color (c'drawTriangleStrip3D p (fromIntegral pointCount))) drawCube :: Vector3 -> Float -> Float -> Float -> Color -> IO () drawCube position width height length color = withFreeable position (\p -> withFreeable color (c'drawCube p (realToFrac width) (realToFrac height) (realToFrac length))) @@ -266,7 +264,7 @@ drawMesh mesh material transform = withFreeable mesh (\m -> withFreeable material (withFreeable transform . c'drawMesh m)) drawMeshInstanced :: Mesh -> Material -> [Matrix] -> IO () -drawMeshInstanced mesh material transforms = withFreeable mesh (\m -> withFreeable material (\mat -> withArrayLen transforms (\size t -> c'drawMeshInstanced m mat t (fromIntegral size)))) +drawMeshInstanced mesh material transforms = withFreeable mesh (\m -> withFreeable material (\mat -> withFreeableArrayLen transforms (\size t -> c'drawMeshInstanced m mat t (fromIntegral size)))) exportMesh :: Mesh -> String -> IO Bool exportMesh mesh fileName = toBool <$> withFreeable mesh (withCString fileName . c'exportMesh)
src/Raylib/Core/Shapes.hs view
@@ -3,8 +3,9 @@ module Raylib.Core.Shapes where import Data.List (genericLength) -import Foreign (Storable (peek), toBool, withArray) +import Foreign (Storable (peek), toBool) import GHC.IO (unsafePerformIO) +import Raylib.ForeignUtil (pop, withFreeable, withFreeableArray) import Raylib.Native ( c'checkCollisionCircleRec, c'checkCollisionCircles, @@ -55,7 +56,6 @@ c'setShapesTexture, ) import Raylib.Types (Color, Rectangle, Texture, Vector2 (Vector2)) -import Raylib.ForeignUtil (pop, withFreeable) setShapesTexture :: Texture -> Rectangle -> IO () setShapesTexture tex source = withFreeable tex (withFreeable source . c'setShapesTexture) @@ -109,7 +109,7 @@ ) drawLineStrip :: [Vector2] -> Color -> IO () -drawLineStrip points color = withArray points (\p -> withFreeable color $ c'drawLineStrip p (genericLength points)) +drawLineStrip points color = withFreeableArray points (\p -> withFreeable color $ c'drawLineStrip p (genericLength points)) drawCircle :: Int -> Int -> Float -> Color -> IO () drawCircle centerX centerY radius color = withFreeable color (c'drawCircle (fromIntegral centerX) (fromIntegral centerY) (realToFrac radius)) @@ -283,11 +283,11 @@ ) drawTriangleFan :: [Vector2] -> Color -> IO () -drawTriangleFan points color = withArray points (\p -> withFreeable color $ c'drawTriangleFan p (genericLength points)) +drawTriangleFan points color = withFreeableArray points (\p -> withFreeable color $ c'drawTriangleFan p (genericLength points)) drawTriangleStrip :: [Vector2] -> Color -> IO () drawTriangleStrip points color = - withArray points (\p -> withFreeable color $ c'drawTriangleStrip p (genericLength points)) + withFreeableArray points (\p -> withFreeable color $ c'drawTriangleStrip p (genericLength points)) drawPoly :: Vector2 -> Int -> Float -> Float -> Color -> IO () drawPoly center sides radius rotation color =
src/Raylib/Core/Text.hs view
@@ -5,14 +5,21 @@ import Foreign ( Storable (peek, sizeOf), toBool, - withArray, - withArrayLen, ) import Foreign.C ( CUChar, peekCString, withCString, ) +import Raylib.ForeignUtil + ( pop, + popCArray, + popCString, + withFreeableArray2D, + withFreeable, + withFreeableArray, + withFreeableArrayLen, + ) import Raylib.Internal (addTextureId, unloadSingleTexture) import Raylib.Native ( c'codepointToUTF8, @@ -52,13 +59,6 @@ Texture (texture'id), Vector2, ) -import Raylib.ForeignUtil - ( pop, - popCArray, - popCString, - withArray2D, - withFreeable, - ) getFontDefault :: IO Font getFontDefault = c'getFontDefault >>= pop @@ -71,7 +71,7 @@ loadFontEx :: String -> Int -> [Int] -> Int -> IO Font loadFontEx fileName fontSize fontChars glyphCount = do - font <- withCString fileName (\f -> withArray (map fromIntegral fontChars) (\c -> c'loadFontEx f (fromIntegral fontSize) c (fromIntegral glyphCount))) >>= pop + font <- withCString fileName (\f -> withFreeableArray (map fromIntegral fontChars) (\c -> c'loadFontEx f (fromIntegral fontSize) c (fromIntegral glyphCount))) >>= pop addTextureId $ texture'id $ font'texture font return font @@ -83,15 +83,15 @@ loadFontFromMemory :: String -> [Integer] -> Int -> [Int] -> Int -> IO Font loadFontFromMemory fileType fileData fontSize fontChars glyphCount = do - font <- withCString fileType (\t -> withArrayLen (map fromIntegral fileData) (\size d -> withArray (map fromIntegral fontChars) (\c -> c'loadFontFromMemory t d (fromIntegral $ size * sizeOf (0 :: CUChar)) (fromIntegral fontSize) c (fromIntegral glyphCount)))) >>= pop + font <- withCString fileType (\t -> withFreeableArrayLen (map fromIntegral fileData) (\size d -> withFreeableArray (map fromIntegral fontChars) (\c -> c'loadFontFromMemory t d (fromIntegral $ size * sizeOf (0 :: CUChar)) (fromIntegral fontSize) c (fromIntegral glyphCount)))) >>= pop addTextureId $ texture'id $ font'texture font return font loadFontData :: [Integer] -> Int -> [Int] -> Int -> FontType -> IO GlyphInfo -loadFontData fileData fontSize fontChars glyphCount fontType = withArrayLen (map fromIntegral fileData) (\size d -> withArray (map fromIntegral fontChars) (\c -> c'loadFontData d (fromIntegral $ size * sizeOf (0 :: CUChar)) (fromIntegral fontSize) c (fromIntegral glyphCount) (fromIntegral $ fromEnum fontType))) >>= pop +loadFontData fileData fontSize fontChars glyphCount fontType = withFreeableArrayLen (map fromIntegral fileData) (\size d -> withFreeableArray (map fromIntegral fontChars) (\c -> c'loadFontData d (fromIntegral $ size * sizeOf (0 :: CUChar)) (fromIntegral fontSize) c (fromIntegral glyphCount) (fromIntegral $ fromEnum fontType))) >>= pop genImageFontAtlas :: [GlyphInfo] -> [[Rectangle]] -> Int -> Int -> Int -> Int -> IO Image -genImageFontAtlas chars recs glyphCount fontSize padding packMethod = withArray chars (\c -> withArray2D recs (\r -> c'genImageFontAtlas c r (fromIntegral glyphCount) (fromIntegral fontSize) (fromIntegral padding) (fromIntegral packMethod))) >>= pop +genImageFontAtlas chars recs glyphCount fontSize padding packMethod = withFreeableArray chars (\c -> withFreeableArray2D recs (\r -> c'genImageFontAtlas c r (fromIntegral glyphCount) (fromIntegral fontSize) (fromIntegral padding) (fromIntegral packMethod))) >>= pop -- | Unloads a font from GPU memory (VRAM). Fonts are automatically unloaded -- when `closeWindow` is called, so manually unloading fonts is not required. @@ -122,7 +122,7 @@ drawTextCodepoint font codepoint position fontSize tint = withFreeable font (\f -> withFreeable position (\p -> withFreeable tint (c'drawTextCodepoint f (fromIntegral codepoint) p (realToFrac fontSize)))) drawTextCodepoints :: Font -> [Int] -> Vector2 -> Float -> Float -> Color -> IO () -drawTextCodepoints font codepoints position fontSize spacing tint = withFreeable font (\f -> withArrayLen (map fromIntegral codepoints) (\count cp -> withFreeable position (\p -> withFreeable tint (c'drawTextCodepoints f cp (fromIntegral count) p (realToFrac fontSize) (realToFrac spacing))))) +drawTextCodepoints font codepoints position fontSize spacing tint = withFreeable font (\f -> withFreeableArrayLen (map fromIntegral codepoints) (\count cp -> withFreeable position (\p -> withFreeable tint (c'drawTextCodepoints f cp (fromIntegral count) p (realToFrac fontSize) (realToFrac spacing))))) measureText :: String -> Int -> IO Int measureText text fontSize = fromIntegral <$> withCString text (\t -> c'measureText t (fromIntegral fontSize)) @@ -141,7 +141,7 @@ loadUTF8 :: [Integer] -> IO String loadUTF8 codepoints = - withArrayLen + withFreeableArrayLen (map fromIntegral codepoints) ( \size c -> c'loadUTF8 c (fromIntegral size)
src/Raylib/Core/Textures.hs view
@@ -7,7 +7,6 @@ ( Ptr, Storable (peek, sizeOf), toBool, - withArrayLen, ) import Foreign.C (CUChar, withCString) import GHC.IO (unsafePerformIO) @@ -15,6 +14,7 @@ ( pop, popCArray, withFreeable, + withFreeableArrayLen, ) import Raylib.Internal (addFrameBuffer, addTextureId, unloadSingleFrameBuffer, unloadSingleTexture) import Raylib.Native @@ -156,7 +156,7 @@ loadImageFromMemory :: String -> [Integer] -> IO Image loadImageFromMemory fileType fileData = - withCString fileType (\ft -> withArrayLen (map fromIntegral fileData) (\size fd -> c'loadImageFromMemory ft fd (fromIntegral $ size * sizeOf (0 :: CUChar)))) >>= pop + withCString fileType (\ft -> withFreeableArrayLen (map fromIntegral fileData) (\size fd -> c'loadImageFromMemory ft fd (fromIntegral $ size * sizeOf (0 :: CUChar)))) >>= pop loadImageFromTexture :: Texture -> IO Image loadImageFromTexture tex = withFreeable tex c'loadImageFromTexture >>= pop
src/Raylib/ForeignUtil.hs view
@@ -1,11 +1,12 @@ {-# OPTIONS -Wall #-} -module Raylib.ForeignUtil (c'free, p'free, freeMaybePtr, Freeable (..), rlFreeArray, rlFreeMaybeArray, pop, popCArray, popCString, withFreeable, withArray2D, configsToBitflag, withMaybe, withMaybeCString, peekMaybe, peekMaybeOff, pokeMaybe, pokeMaybeOff, peekMaybeArray, newMaybeArray, peekStaticArray, peekStaticArrayOff, pokeStaticArray, pokeStaticArrayOff, rightPad) where +module Raylib.ForeignUtil (c'free, p'free, freeMaybePtr, Freeable (..), rlFreeArray, rlFreeMaybeArray, pop, popCArray, popCString, withFreeable, withFreeableArray, withFreeableArrayLen, withFreeableArray2D, configsToBitflag, withMaybe, withMaybeCString, peekMaybe, peekMaybeOff, pokeMaybe, pokeMaybeOff, peekMaybeArray, newMaybeArray, peekStaticArray, peekStaticArrayOff, pokeStaticArray, pokeStaticArrayOff, rightPad) where import Control.Monad (forM_, unless) import Data.Bits ((.|.)) -import Foreign (FunPtr, Ptr, Storable (peek, peekByteOff, poke, sizeOf), castPtr, free, malloc, newArray, nullPtr, peekArray, plusPtr, with) +import Foreign (FunPtr, Ptr, Storable (peek, peekByteOff, poke, sizeOf), castPtr, malloc, newArray, nullPtr, peekArray, plusPtr, with) import Foreign.C (CFloat, CInt, CString, CUChar, CUInt, peekCString, withCString) +import Foreign.C.Types (CBool, CChar, CShort, CUShort) -- Internal utility functions @@ -23,22 +24,32 @@ rlFree :: a -> Ptr a -> IO () rlFree val ptr = rlFreeDependents val ptr >> c'free (castPtr ptr) +instance Freeable CBool + +instance Freeable CChar + +instance Freeable CFloat + instance Freeable CInt -instance Freeable CUInt +instance Freeable CShort instance Freeable CUChar -instance Freeable CFloat +instance Freeable CUInt +instance Freeable CUShort + +instance (Freeable a, Storable a) => Freeable [a] where + rlFreeDependents arr ptr = + forM_ + [0 .. length arr - 1] + ( \i -> do + let val = arr !! i in rlFreeDependents val (plusPtr ptr (i * sizeOf val)) + ) + rlFreeArray :: (Freeable a, Storable a) => [a] -> Ptr a -> IO () -rlFreeArray arr ptr = do - forM_ - [0 .. length arr - 1] - ( \i -> do - let val = arr !! i in rlFreeDependents val (plusPtr ptr (i * sizeOf val)) - ) - c'free $ castPtr ptr +rlFreeArray arr ptr = rlFree arr (castPtr ptr) rlFreeMaybeArray :: (Freeable a, Storable a) => Maybe [a] -> Ptr a -> IO () rlFreeMaybeArray Nothing _ = return () @@ -70,13 +81,27 @@ rlFree val ptr return result -withArray2D :: (Storable a) => [[a]] -> (Ptr (Ptr a) -> IO b) -> IO b -withArray2D arr func = do +withFreeableArray :: (Freeable a, Storable a) => [a] -> (Ptr a -> IO b) -> IO b +withFreeableArray arr f = do + ptr <- newArray arr + result <- f ptr + rlFreeArray arr ptr + return result + +withFreeableArrayLen :: (Freeable a, Storable a) => [a] -> (Int -> Ptr a -> IO b) -> IO b +withFreeableArrayLen arr f = do + ptr <- newArray arr + result <- f (length arr) ptr + rlFreeArray arr ptr + return result + +withFreeableArray2D :: (Freeable a, Storable a) => [[a]] -> (Ptr (Ptr a) -> IO b) -> IO b +withFreeableArray2D arr func = do arrays <- mapM newArray arr ptr <- newArray arrays res <- func ptr - forM_ arrays free - free ptr + forM_ (zip [0..] arrays) (\(i, a) -> rlFreeArray (arr !! i) a) + c'free $ castPtr ptr return res configsToBitflag :: (Enum a) => [a] -> Integer
src/Raylib/Native.hs view
@@ -12,7 +12,7 @@ CInt (..), CLong (..), CString, - CUChar, + CUChar (..), CUInt (..), ) import Raylib.Types @@ -49,10 +49,12 @@ Vector4, VrDeviceInfo, VrStereoConfig, - Wave, + Wave, RLRenderBatch ) import Prelude hiding (length) +---- raylib.h + -- foreign import ccall safe "wrapper" -- mk'TraceLogCallback :: -- (CInt -> CString -> __builtin_va_list -> IO ()) -> IO TraceLogCallback @@ -1044,80 +1046,6 @@ c'codepointToUTF8 :: CInt -> Ptr CInt -> IO CString --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextCopy" --- textCopy :: --- CString -> CString -> IO CInt - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextIsEqual" --- textIsEqual :: --- CString -> CString -> IO CInt - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextLength" --- textLength :: --- CString -> IO CUInt - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextFormat" --- textFormat :: --- CString -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextSubtext" --- textSubtext :: --- CString -> CInt -> CInt -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextReplace" --- textReplace :: --- CString -> CString -> CString -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextInsert" --- textInsert :: --- CString -> CString -> CInt -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextJoin" --- textJoin :: --- Ptr CString -> CInt -> CString -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextSplit" --- textSplit :: --- CString -> CChar -> Ptr CInt -> IO (Ptr CString) - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextAppend" --- textAppend :: --- CString -> CString -> Ptr CInt -> IO () - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextFindIndex" --- textFindIndex :: --- CString -> CString -> IO CInt - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextToUpper" --- textToUpper :: --- CString -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextToLower" --- textToLower :: --- CString -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextToPascal" --- textToPascal :: --- CString -> IO CString - --- | Not required in Haskell --- foreign import ccall safe "raylib.h TextToInteger" --- textToInteger :: --- CString -> IO CInt foreign import ccall safe "rl_bindings.h DrawLine3D_" c'drawLine3D :: Ptr Vector3 -> Ptr Vector3 -> Ptr Color -> IO () foreign import ccall safe "rl_bindings.h DrawPoint3D_" c'drawPoint3D :: Ptr Vector3 -> Ptr Color -> IO () @@ -1430,3 +1358,231 @@ foreign import ccall safe "rl_bindings.h AttachAudioMixedProcessor_" c'attachAudioMixedProcessor :: Ptr AudioCallback -> IO () foreign import ccall safe "rl_bindings.h DetachAudioMixedProcessor_" c'detachAudioMixedProcessor :: Ptr AudioCallback -> IO () + +---- rlgl.h + +foreign import ccall safe "rlgl.h rlMatrixMode" c'rlMatrixMode :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlTranslatef" c'rlTranslatef :: CFloat -> CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlRotatef" c'rlRotatef :: CFloat -> CFloat -> CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlScalef" c'rlScalef :: CFloat -> CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlMultMatrixf" c'rlMultMatrixf :: Ptr CFloat -> IO () + +foreign import ccall safe "rlgl.h rlFrustum" c'rlFrustum :: CDouble -> CDouble -> CDouble -> CDouble -> CDouble -> CDouble -> IO () + +foreign import ccall safe "rlgl.h rlOrtho" c'rlOrtho :: CDouble -> CDouble -> CDouble -> CDouble -> CDouble -> CDouble -> IO () + +foreign import ccall safe "rlgl.h rlViewport" c'rlViewport :: CInt -> CInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlBegin" c'rlBegin :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlVertex2i" c'rlVertex2i :: CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlVertex2f" c'rlVertex2f :: CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlVertex3f" c'rlVertex3f :: CFloat -> CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlTexCoord2f" c'rlTexCoord2f :: CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlNormal3f" c'rlNormal3f :: CFloat -> CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlColor4ub" c'rlColor4ub :: CUChar -> CUChar -> CUChar -> CUChar -> IO () + +foreign import ccall safe "rlgl.h rlColor3f" c'rlColor3f :: CFloat -> CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlColor4f" c'rlColor4f :: CFloat -> CFloat -> CFloat -> CFloat -> IO () + +foreign import ccall safe "rlgl.h rlEnableVertexArray" c'rlEnableVertexArray :: CUInt -> IO CBool + +foreign import ccall safe "rlgl.h rlEnableVertexBuffer" c'rlEnableVertexBuffer :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlEnableVertexBufferElement" c'rlEnableVertexBufferElement :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlEnableVertexAttribute" c'rlEnableVertexAttribute :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlDisableVertexAttribute" c'rlDisableVertexAttribute :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlActiveTextureSlot" c'rlActiveTextureSlot :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlEnableTexture" c'rlEnableTexture :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlEnableTextureCubemap" c'rlEnableTextureCubemap :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlTextureParameters" c'rlTextureParameters :: CUInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlCubemapParameters" c'rlCubemapParameters :: CUInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlEnableShader" c'rlEnableShader :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlEnableFramebuffer" c'rlEnableFramebuffer :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlActiveDrawBuffers" c'rlActiveDrawBuffers :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlSetCullFace" c'rlSetCullFace :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlScissor" c'rlScissor :: CInt -> CInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlSetLineWidth" c'rlSetLineWidth :: CFloat -> IO () + +foreign import ccall safe "rlgl.h rlGetLineWidth" c'rlGetLineWidth :: IO CFloat + +foreign import ccall safe "rlgl.h rlIsStereoRenderEnabled" c'rlIsStereoRenderEnabled :: IO CBool + +foreign import ccall safe "rlgl.h rlClearColor" c'rlClearColor :: CUChar -> CUChar -> CUChar -> CUChar -> IO () + +foreign import ccall safe "rlgl.h rlSetBlendMode" c'rlSetBlendMode :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlSetBlendFactors" c'rlSetBlendFactors :: CInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlSetBlendFactorsSeparate" c'rlSetBlendFactorsSeparate :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlglInit" c'rlglInit :: CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlLoadExtensions" c'rlLoadExtensions :: Ptr () -> IO () + +foreign import ccall safe "rlgl.h rlGetVersion" c'rlGetVersion :: IO CInt + +foreign import ccall safe "rlgl.h rlSetFramebufferWidth" c'rlSetFramebufferWidth :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlGetFramebufferWidth" c'rlGetFramebufferWidth :: IO CInt + +foreign import ccall safe "rlgl.h rlSetFramebufferHeight" c'rlSetFramebufferHeight :: CInt -> IO () + +foreign import ccall safe "rlgl.h rlGetFramebufferHeight" c'rlGetFramebufferHeight :: IO CInt + +foreign import ccall safe "rlgl.h rlGetTextureIdDefault" c'rlGetTextureIdDefault :: IO CUInt + +foreign import ccall safe "rlgl.h rlGetShaderIdDefault" c'rlGetShaderIdDefault :: IO CUInt + +foreign import ccall safe "rlgl.h rlGetShaderLocsDefault" c'rlGetShaderLocsDefault :: IO (Ptr CInt) + +foreign import ccall safe "rlgl_bindings.h rlLoadRenderBatch_" c'rlLoadRenderBatch :: CInt -> CInt -> IO (Ptr RLRenderBatch) + +foreign import ccall safe "rlgl_bindings.h rlUnloadRenderBatch_" c'rlUnloadRenderBatch :: Ptr RLRenderBatch -> IO () + +foreign import ccall safe "rlgl.h rlDrawRenderBatch" c'rlDrawRenderBatch :: Ptr RLRenderBatch -> IO () + +foreign import ccall safe "rlgl.h rlSetRenderBatchActive" c'rlSetRenderBatchActive :: Ptr RLRenderBatch -> IO () + +foreign import ccall safe "rlgl.h rlCheckRenderBatchLimit" c'rlCheckRenderBatchLimit :: CInt -> IO CBool + +foreign import ccall safe "rlgl.h rlSetTexture" c'rlSetTexture :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlLoadVertexArray" c'rlLoadVertexArray :: IO CUInt + +foreign import ccall safe "rlgl.h rlLoadVertexBuffer" c'rlLoadVertexBuffer :: Ptr () -> CInt -> CBool -> IO CUInt + +foreign import ccall safe "rlgl.h rlLoadVertexBufferElement" c'rlLoadVertexBufferElement :: Ptr () -> CInt -> CBool -> IO CUInt + +foreign import ccall safe "rlgl.h rlUpdateVertexBuffer" c'rlUpdateVertexBuffer :: CUInt -> Ptr () -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlUpdateVertexBufferElements" c'rlUpdateVertexBufferElements :: CUInt -> Ptr () -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlUnloadVertexArray" c'rlUnloadVertexArray :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlUnloadVertexBuffer" c'rlUnloadVertexBuffer :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlSetVertexAttribute" c'rlSetVertexAttribute :: CUInt -> CInt -> CInt -> CBool -> CInt -> Ptr () -> IO () + +foreign import ccall safe "rlgl.h rlSetVertexAttributeDivisor" c'rlSetVertexAttributeDivisor :: CUInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlSetVertexAttributeDefault" c'rlSetVertexAttributeDefault :: CInt -> Ptr () -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlDrawVertexArray" c'rlDrawVertexArray :: CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlDrawVertexArrayElements" c'rlDrawVertexArrayElements :: CInt -> CInt -> Ptr () -> IO () + +foreign import ccall safe "rlgl.h rlDrawVertexArrayInstanced" c'rlDrawVertexArrayInstanced :: CInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlDrawVertexArrayElementsInstanced" c'rlDrawVertexArrayElementsInstanced :: CInt -> CInt -> Ptr () -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlLoadTexture" c'rlLoadTexture :: Ptr () -> CInt -> CInt -> CInt -> CInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlLoadTextureDepth" c'rlLoadTextureDepth :: CInt -> CInt -> CBool -> IO CUInt + +foreign import ccall safe "rlgl.h rlLoadTextureCubemap" c'rlLoadTextureCubemap :: Ptr () -> CInt -> CInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlUpdateTexture" c'rlUpdateTexture :: CUInt -> CInt -> CInt -> CInt -> CInt -> CInt -> Ptr () -> IO () + +foreign import ccall safe "rlgl.h rlGetGlTextureFormats" c'rlGetGlTextureFormats :: CInt -> Ptr CUInt -> Ptr CUInt -> Ptr CUInt -> IO () + +foreign import ccall safe "rlgl.h rlGetPixelFormatName" c'rlGetPixelFormatName :: CUInt -> IO CString + +foreign import ccall safe "rlgl.h rlUnloadTexture" c'rlUnloadTexture :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlGenTextureMipmaps" c'rlGenTextureMipmaps :: CUInt -> CInt -> CInt -> CInt -> Ptr CInt -> IO () + +foreign import ccall safe "rlgl.h rlReadTexturePixels" c'rlReadTexturePixels :: CUInt -> CInt -> CInt -> CInt -> IO (Ptr ()) + +foreign import ccall safe "rlgl.h rlReadScreenPixels" c'rlReadScreenPixels :: CInt -> CInt -> IO (Ptr CUChar) + +foreign import ccall safe "rlgl.h rlLoadFramebuffer" c'rlLoadFramebuffer :: CInt -> CInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlFramebufferAttach" c'rlFramebufferAttach :: CUInt -> CUInt -> CInt -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl.h rlFramebufferComplete" c'rlFramebufferComplete :: CUInt -> IO CBool + +foreign import ccall safe "rlgl.h rlUnloadFramebuffer" c'rlUnloadFramebuffer :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlLoadShaderCode" c'rlLoadShaderCode :: CString -> CString -> IO CUInt + +foreign import ccall safe "rlgl.h rlCompileShader" c'rlCompileShader :: CString -> CInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlLoadShaderProgram" c'rlLoadShaderProgram :: CUInt -> CUInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlUnloadShaderProgram" c'rlUnloadShaderProgram :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlGetLocationUniform" c'rlGetLocationUniform :: CUInt -> CString -> IO CInt + +foreign import ccall safe "rlgl.h rlGetLocationAttrib" c'rlGetLocationAttrib :: CUInt -> CString -> IO CInt + +foreign import ccall safe "rlgl.h rlSetUniform" c'rlSetUniform :: CInt -> Ptr () -> CInt -> CInt -> IO () + +foreign import ccall safe "rlgl_bindings.h rlSetUniformMatrix_" c'rlSetUniformMatrix :: CInt -> Ptr Matrix -> IO () + +foreign import ccall safe "rlgl.h rlSetUniformSampler" c'rlSetUniformSampler :: CInt -> CUInt -> IO () + +foreign import ccall safe "rlgl.h rlSetShader" c'rlSetShader :: CUInt -> Ptr CInt -> IO () + +foreign import ccall safe "rlgl.h rlLoadComputeShaderProgram" c'rlLoadComputeShaderProgram :: CUInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlComputeShaderDispatch" c'rlComputeShaderDispatch :: CUInt -> CUInt -> CUInt -> IO () + +foreign import ccall safe "rlgl.h rlLoadShaderBuffer" c'rlLoadShaderBuffer :: CUInt -> Ptr () -> CInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlUnloadShaderBuffer" c'rlUnloadShaderBuffer :: CUInt -> IO () + +foreign import ccall safe "rlgl.h rlUpdateShaderBuffer" c'rlUpdateShaderBuffer :: CUInt -> Ptr () -> CUInt -> CUInt -> IO () + +foreign import ccall safe "rlgl.h rlBindShaderBuffer" c'rlBindShaderBuffer :: CUInt -> CUInt -> IO () + +foreign import ccall safe "rlgl.h rlReadShaderBuffer" c'rlReadShaderBuffer :: CUInt -> Ptr () -> CUInt -> CUInt -> IO () + +foreign import ccall safe "rlgl.h rlCopyShaderBuffer" c'rlCopyShaderBuffer :: CUInt -> CUInt -> CUInt -> CUInt -> CUInt -> IO () + +foreign import ccall safe "rlgl.h rlGetShaderBufferSize" c'rlGetShaderBufferSize :: CUInt -> IO CUInt + +foreign import ccall safe "rlgl.h rlBindImageTexture" c'rlBindImageTexture :: CUInt -> CUInt -> CInt -> CBool -> IO () + +foreign import ccall safe "rlgl.h rlGetMatrixModelview" c'rlGetMatrixModelview :: IO (Ptr Matrix) + +foreign import ccall safe "rlgl.h rlGetMatrixProjection" c'rlGetMatrixProjection :: IO (Ptr Matrix) + +foreign import ccall safe "rlgl.h rlGetMatrixTransform" c'rlGetMatrixTransform :: IO (Ptr Matrix) + +foreign import ccall safe "rlgl_bindings.h rlGetMatrixProjectionStereo_" c'rlGetMatrixProjectionStereo :: CInt -> IO (Ptr Matrix) + +foreign import ccall safe "rlgl_bindings.h rlGetMatrixViewOffsetStereo_" c'rlGetMatrixViewOffsetStereo :: CInt -> IO (Ptr Matrix) + +foreign import ccall safe "rlgl_bindings.h rlSetMatrixProjection_" c'rlSetMatrixProjection :: Ptr Matrix -> IO () + +foreign import ccall safe "rlgl_bindings.h rlSetMatrixModelview_" c'rlSetMatrixModelview :: Ptr Matrix -> IO () + +foreign import ccall safe "rlgl_bindings.h rlSetMatrixProjectionStereo_" c'rlSetMatrixProjectionStereo :: Ptr Matrix -> Ptr Matrix -> IO () + +foreign import ccall safe "rlgl_bindings.h rlSetMatrixViewOffsetStereo_" c'rlSetMatrixViewOffsetStereo :: Ptr Matrix -> Ptr Matrix -> IO () + +foreign import ccall safe "rl_internal.h rlGetPixelDataSize" c'rlGetPixelDataSize :: CInt -> CInt -> CInt -> IO CInt
src/Raylib/Types.hs view
@@ -36,13 +36,15 @@ peekCString, ) import Foreign.C.String (castCCharToChar) -import Raylib.Internal (c'rlGetShaderIdDefault, getPixelDataSize) import Raylib.ForeignUtil (Freeable (rlFreeDependents), c'free, freeMaybePtr, newMaybeArray, p'free, peekMaybeArray, peekStaticArray, peekStaticArrayOff, pokeMaybeOff, pokeStaticArray, pokeStaticArrayOff, rightPad, rlFreeArray, rlFreeMaybeArray) +import Raylib.Internal (c'rlGetShaderIdDefault, getPixelDataSize) ------------------------------------------------ -- Raylib enumerations ------------------------- ------------------------------------------------ +---- raylib.h + data ConfigFlag = VsyncHint | FullscreenMode @@ -558,7 +560,7 @@ | ShaderUniformIVec2 (Int, Int) | ShaderUniformIVec3 (Int, Int, Int) | ShaderUniformIVec4 (Int, Int, Int, Int) - | ShaderUniformSampler2D Integer -- I believe this takes a texture ID as the argument + | ShaderUniformSampler2D Texture deriving (Eq, Show) data ShaderUniformDataV @@ -570,7 +572,7 @@ | ShaderUniformIVec2V [(Int, Int)] | ShaderUniformIVec3V [(Int, Int, Int)] | ShaderUniformIVec4V [(Int, Int, Int, Int)] - | ShaderUniformSampler2DV [Integer] + | ShaderUniformSampler2DV [Texture] deriving (Eq, Show) -- I don't know if there's a cleaner way to do this @@ -611,10 +613,10 @@ do ptr <- newArray (map fromIntegral [i1, i2, i3, i4] :: [CInt]) return (ShaderUniformIVec4Type, castPtr ptr) - (ShaderUniformSampler2D sId) -> + (ShaderUniformSampler2D texture) -> do ptr <- malloc - poke ptr (fromIntegral sId :: CInt) + poke ptr (fromIntegral $ texture'id texture :: CInt) return (ShaderUniformSampler2DType, castPtr ptr) unpackShaderUniformDataV :: ShaderUniformDataV -> IO (ShaderUniformDataType, Ptr (), Int) @@ -652,10 +654,10 @@ do ptr <- newArray (map fromIntegral $ concatMap (\(x, y, z, w) -> [x, y, z, w]) is :: [CInt]) return (ShaderUniformIVec4Type, castPtr ptr, length is) - (ShaderUniformSampler2DV sIds) -> + (ShaderUniformSampler2DV textures) -> do - ptr <- newArray (map fromIntegral sIds :: [CInt]) - return (ShaderUniformSampler2DType, castPtr ptr, length sIds) + ptr <- newArray (map (fromIntegral . texture'id) textures :: [CInt]) + return (ShaderUniformSampler2DType, castPtr ptr, length textures) -- I genuinely have no idea where this is used. data ShaderAttributeDataType @@ -876,6 +878,682 @@ return $ toEnum $ fromEnum (val :: CInt) poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) +---- rlgl.h + +-- | OpenGL version +data RLGLVersion + = -- | OpenGL 1.1 + RLOpenGL11 + | -- | OpenGL 2.1 (GLSL 120) + RLOpenGL21 + | -- | OpenGL 3.3 (GLSL 330) + RLOpenGL33 + | -- | OpenGL 4.3 (using GLSL 330) + RLOpenGL43 + | -- | OpenGL ES 2.0 (GLSL 100) + RLOpenGLES20 + deriving (Eq, Show) + +instance Enum RLGLVersion where + fromEnum n = case n of + RLOpenGL11 -> 0 + RLOpenGL21 -> 1 + RLOpenGL33 -> 2 + RLOpenGL43 -> 3 + RLOpenGLES20 -> 4 + toEnum n = case n of + 0 -> RLOpenGL11 + 1 -> RLOpenGL21 + 2 -> RLOpenGL33 + 3 -> RLOpenGL43 + 4 -> RLOpenGLES20 + _ -> error $ "(RLGLVersion.toEnum) Invalid value: " ++ show n + +instance Storable RLGLVersion where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Trace log level. +-- NOTE: Organized by priority level +data RLTraceLogLevel + = -- | Display all logs + RLLogAll + | -- | Trace logging, intended for internal use only + RLLogTrace + | -- | Debug logging, used for internal debugging, it should be disabled on release builds + RLLogDebug + | -- | Info logging, used for program execution info + RLLogInfo + | -- | Warning logging, used on recoverable failures + RLLogWarning + | -- | Error logging, used on unrecoverable failures + RLLogError + | -- | Fatal logging, used to abort program: exit(EXIT_FAILURE) + RLLogFatal + | -- | Disable logging + RLLogNone + deriving (Eq, Show, Enum) + +instance Storable RLTraceLogLevel where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Texture pixel formats. +-- NOTE: Support depends on OpenGL version +data RLPixelFormat + = -- | 8 bit per pixel (no alpha) + RLPixelFormatUncompressedGrayscale + | -- | 8*2 bpp (2 channels) + RLPixelFormatUncompressedGrayAlpha + | -- | 16 bpp + RLPixelFormatUncompressedR5G6B5 + | -- | 24 bpp + RLPixelFormatUncompressedR8G8B8 + | -- | 16 bpp (1 bit alpha) + RLPixelFormatUncompressedR5G5B5A1 + | -- | 16 bpp (4 bit alpha) + RLPixelFormatUncompressedR4G4B4A4 + | -- | 32 bpp + RLPixelFormatUncompressedR8G8B8A8 + | -- | 32 bpp (1 channel - float) + RLPixelFormatUncompressedR32 + | -- | 32*3 bpp (3 channels - float) + RLPixelFormatUncompressedR32G32B32 + | -- | 32*4 bpp (4 channels - float) + RLPixelFormatUncompressedR32G32B32A32 + | -- | 4 bpp (no alpha) + RLPixelFormatCompressedDxt1Rgb + | -- | 4 bpp (1 bit alpha) + RLPixelFormatCompressedDxt1Rgba + | -- | 8 bpp + RLPixelFormatCompressedDxt3Rgba + | -- | 8 bpp + RLPixelFormatCompressedDxt5Rgba + | -- | 4 bpp + RLPixelFormatCompressedEtc1Rgb + | -- | 4 bpp + RLPixelFormatCompressedEtc2Rgb + | -- | 8 bpp + RLPixelFormatCompressedEtc2EacRgba + | -- | 4 bpp + RLPixelFormatCompressedPvrtRgb + | -- | 4 bpp + RLPixelFormatCompressedPvrtRgba + | -- | 8 bpp + RLPixelFormatCompressedAstc4x4Rgba + | -- | 2 bpp + RLPixelFormatCompressedAstc8x8Rgba + deriving (Eq, Show) + +instance Enum RLPixelFormat where + fromEnum n = case n of + RLPixelFormatUncompressedGrayscale -> 1 + RLPixelFormatUncompressedGrayAlpha -> 2 + RLPixelFormatUncompressedR5G6B5 -> 3 + RLPixelFormatUncompressedR8G8B8 -> 4 + RLPixelFormatUncompressedR5G5B5A1 -> 5 + RLPixelFormatUncompressedR4G4B4A4 -> 6 + RLPixelFormatUncompressedR8G8B8A8 -> 7 + RLPixelFormatUncompressedR32 -> 8 + RLPixelFormatUncompressedR32G32B32 -> 9 + RLPixelFormatUncompressedR32G32B32A32 -> 10 + RLPixelFormatCompressedDxt1Rgb -> 11 + RLPixelFormatCompressedDxt1Rgba -> 12 + RLPixelFormatCompressedDxt3Rgba -> 13 + RLPixelFormatCompressedDxt5Rgba -> 14 + RLPixelFormatCompressedEtc1Rgb -> 15 + RLPixelFormatCompressedEtc2Rgb -> 16 + RLPixelFormatCompressedEtc2EacRgba -> 17 + RLPixelFormatCompressedPvrtRgb -> 18 + RLPixelFormatCompressedPvrtRgba -> 19 + RLPixelFormatCompressedAstc4x4Rgba -> 20 + RLPixelFormatCompressedAstc8x8Rgba -> 21 + + toEnum n = case n of + 1 -> RLPixelFormatUncompressedGrayscale + 2 -> RLPixelFormatUncompressedGrayAlpha + 3 -> RLPixelFormatUncompressedR5G6B5 + 4 -> RLPixelFormatUncompressedR8G8B8 + 5 -> RLPixelFormatUncompressedR5G5B5A1 + 6 -> RLPixelFormatUncompressedR4G4B4A4 + 7 -> RLPixelFormatUncompressedR8G8B8A8 + 8 -> RLPixelFormatUncompressedR32 + 9 -> RLPixelFormatUncompressedR32G32B32 + 10 -> RLPixelFormatUncompressedR32G32B32A32 + 11 -> RLPixelFormatCompressedDxt1Rgb + 12 -> RLPixelFormatCompressedDxt1Rgba + 13 -> RLPixelFormatCompressedDxt3Rgba + 14 -> RLPixelFormatCompressedDxt5Rgba + 15 -> RLPixelFormatCompressedEtc1Rgb + 16 -> RLPixelFormatCompressedEtc2Rgb + 17 -> RLPixelFormatCompressedEtc2EacRgba + 18 -> RLPixelFormatCompressedPvrtRgb + 19 -> RLPixelFormatCompressedPvrtRgba + 20 -> RLPixelFormatCompressedAstc4x4Rgba + 21 -> RLPixelFormatCompressedAstc8x8Rgba + _ -> error $ "(RLPixelFormat.toEnum) Invalid value: " ++ show n + +instance Storable RLPixelFormat where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Texture parameters: filter mode. +-- NOTE 1: Filtering considers mipmaps if available in the texture. +-- NOTE 2: Filter is accordingly set for minification and magnification. +data RLTextureFilter + = -- | No filter, just pixel approximation + RLTextureFilterPoint + | -- | Linear filtering + RLTextureFilterBilinear + | -- | Trilinear filtering (linear with mipmaps) + RLTextureFilterTrilinear + | -- | Anisotropic filtering 4x + RLTextureFilterAnisotropic4x + | -- | Anisotropic filtering 8x + RLTextureFilterAnisotropic8x + | -- | Anisotropic filtering 16x + RLTextureFilterAnisotropic16x + deriving (Eq, Show, Enum) + +instance Storable RLTextureFilter where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Color blending modes (pre-defined) +data RLBlendMode + = -- | Blend textures considering alpha (default) + RlBlendAlpha + | -- | Blend textures adding colors + RlBlendAdditive + | -- | Blend textures multiplying colors + RlBlendMultiplied + | -- | Blend textures adding colors (alternative) + RlBlendAddColors + | -- | Blend textures subtracting colors (alternative) + RlBlendSubtractColors + | -- | Blend premultiplied textures considering alpha + RlBlendAlphaPremultiply + | -- | Blend textures using custom src/dst factors (use rlSetBlendFactors()) + RlBlendCustom + | -- | Blend textures using custom src/dst factors (use rlSetBlendFactorsSeparate()) + RlBlendCustomSeparate + deriving (Eq, Show, Enum) + +instance Storable RLBlendMode where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Shader location point type +data RLShaderLocationIndex + = -- | Shader location: vertex attribute: position + RLShaderLocVertexPosition + | -- | Shader location: vertex attribute: texcoord01 + RLShaderLocVertexTexcoord01 + | -- | Shader location: vertex attribute: texcoord02 + RLShaderLocVertexTexcoord02 + | -- | Shader location: vertex attribute: normal + RLShaderLocVertexNormal + | -- | Shader location: vertex attribute: tangent + RLShaderLocVertexTangent + | -- | Shader location: vertex attribute: color + RLShaderLocVertexColor + | -- | Shader location: matrix uniform: model-view-projection + RLShaderLocMatrixMVP + | -- | Shader location: matrix uniform: view (camera transform) + RLShaderLocMatrixView + | -- | Shader location: matrix uniform: projection + RLShaderLocMatrixProjection + | -- | Shader location: matrix uniform: model (transform) + RLShaderLocMatrixModel + | -- | Shader location: matrix uniform: normal + RLShaderLocMatrixNormal + | -- | Shader location: vector uniform: view + RLShaderLocVectorView + | -- | Shader location: vector uniform: diffuse color + RLShaderLocColorDiffuse + | -- | Shader location: vector uniform: specular color + RLShaderLocColorSpecular + | -- | Shader location: vector uniform: ambient color + RLShaderLocColorAmbient + | -- | Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE) + RLShaderLocMapAlbedo + | -- | Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR) + RLShaderLocMapMetalness + | -- | Shader location: sampler2d texture: normal + RLShaderLocMapNormal + | -- | Shader location: sampler2d texture: roughness + RLShaderLocMapRoughness + | -- | Shader location: sampler2d texture: occlusion + RLShaderLocMapOcclusion + | -- | Shader location: sampler2d texture: emission + RLShaderLocMapEmission + | -- | Shader location: sampler2d texture: height + RLShaderLocMapHeight + | -- | Shader location: samplerCube texture: cubemap + RLShaderLocMapCubemap + | -- | Shader location: samplerCube texture: irradiance + RLShaderLocMapIrradiance + | -- | Shader location: samplerCube texture: prefilter + RLShaderLocMapPrefilter + | -- | Shader location: sampler2d texture: brdf + RLShaderLocMapBRDF + deriving (Eq, Show, Enum) + +instance Storable RLShaderLocationIndex where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Shader uniform data type +data RLShaderUniformDataType + = -- | Shader uniform type: float + RLShaderUniformFloat + | -- | Shader uniform type: vec2 (2 float) + RLShaderUniformVec2 + | -- | Shader uniform type: vec3 (3 float) + RLShaderUniformVec3 + | -- | Shader uniform type: vec4 (4 float) + RLShaderUniformVec4 + | -- | Shader uniform type: int + RLShaderUniformInt + | -- | Shader uniform type: ivec2 (2 int) + RLShaderUniformIVec2 + | -- | Shader uniform type: ivec3 (3 int) + RLShaderUniformIVec3 + | -- | Shader uniform type: ivec4 (4 int) + RLShaderUniformIVec4 + | -- | Shader uniform type: sampler2d + RLShaderUniformSampler2D + deriving (Eq, Show, Enum) + +instance Storable RLShaderUniformDataType where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Shader attribute data types +data RLShaderAttributeDataType + = -- | Shader attribute type: float + RLShaderAttribFloat + | -- | Shader attribute type: vec2 (2 float) + RLShaderAttribVec2 + | -- | Shader attribute type: vec3 (3 float) + RLShaderAttribVec3 + | -- | Shader attribute type: vec4 (4 float) + RLShaderAttribVec4 + deriving (Eq, Show, Enum) + +instance Storable RLShaderAttributeDataType where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Framebuffer attachment type. +-- NOTE: By default up to 8 color channels are defined, but it can be more +data RLFramebufferAttachType + = -- | Framebuffer attachment type: color 0 + RLAttachmentColorChannel0 + | -- | Framebuffer attachment type: color 1 + RLAttachmentColorChannel1 + | -- | Framebuffer attachment type: color 2 + RLAttachmentColorChannel2 + | -- | Framebuffer attachment type: color 3 + RLAttachmentColorChannel3 + | -- | Framebuffer attachment type: color 4 + RLAttachmentColorChannel4 + | -- | Framebuffer attachment type: color 5 + RLAttachmentColorChannel5 + | -- | Framebuffer attachment type: color 6 + RLAttachmentColorChannel6 + | -- | Framebuffer attachment type: color 7 + RLAttachmentColorChannel7 + | -- | Framebuffer attachment type: depth + RLAttachmentDepth + | -- | Framebuffer attachment type: stencil + RLAttachmentStencil + deriving (Eq, Show) + +instance Enum RLFramebufferAttachType where + fromEnum n = case n of + RLAttachmentColorChannel0 -> 0 + RLAttachmentColorChannel1 -> 1 + RLAttachmentColorChannel2 -> 2 + RLAttachmentColorChannel3 -> 3 + RLAttachmentColorChannel4 -> 4 + RLAttachmentColorChannel5 -> 5 + RLAttachmentColorChannel6 -> 6 + RLAttachmentColorChannel7 -> 7 + RLAttachmentDepth -> 100 + RLAttachmentStencil -> 200 + + toEnum n = case n of + 0 -> RLAttachmentColorChannel0 + 1 -> RLAttachmentColorChannel1 + 2 -> RLAttachmentColorChannel2 + 3 -> RLAttachmentColorChannel3 + 4 -> RLAttachmentColorChannel4 + 5 -> RLAttachmentColorChannel5 + 6 -> RLAttachmentColorChannel6 + 7 -> RLAttachmentColorChannel7 + 100 -> RLAttachmentDepth + 200 -> RLAttachmentStencil + _ -> error $ "(RLFramebufferAttachType.toEnum) Invalid value: " ++ show n + +instance Storable RLFramebufferAttachType where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Framebuffer texture attachment type +data RLFramebufferAttachTextureType + = -- | Framebuffer texture attachment type: cubemap, +X side + RLAttachmentCubemapPositiveX + | -- | Framebuffer texture attachment type: cubemap, -X side + RLAttachmentCubemapNegativeX + | -- | Framebuffer texture attachment type: cubemap, +Y side + RLAttachmentCubemapPositiveY + | -- | Framebuffer texture attachment type: cubemap, -Y side + RLAttachmentCubemapNegativeY + | -- | Framebuffer texture attachment type: cubemap, +Z side + RLAttachmentCubemapPositiveZ + | -- | Framebuffer texture attachment type: cubemap, -Z side + RLAttachmentCubemapNegativeZ + | -- | Framebuffer texture attachment type: texture2d + RLAttachmentTexture2D + | -- | Framebuffer texture attachment type: renderbuffer + RLAttachmentRenderBuffer + deriving (Eq, Show) + +instance Enum RLFramebufferAttachTextureType where + fromEnum n = case n of + RLAttachmentCubemapPositiveX -> 0 + RLAttachmentCubemapNegativeX -> 1 + RLAttachmentCubemapPositiveY -> 2 + RLAttachmentCubemapNegativeY -> 3 + RLAttachmentCubemapPositiveZ -> 4 + RLAttachmentCubemapNegativeZ -> 5 + RLAttachmentTexture2D -> 100 + RLAttachmentRenderBuffer -> 200 + + toEnum n = case n of + 0 -> RLAttachmentCubemapPositiveX + 1 -> RLAttachmentCubemapNegativeX + 2 -> RLAttachmentCubemapPositiveY + 3 -> RLAttachmentCubemapNegativeY + 4 -> RLAttachmentCubemapPositiveZ + 5 -> RLAttachmentCubemapNegativeZ + 100 -> RLAttachmentTexture2D + 200 -> RLAttachmentRenderBuffer + _ -> error $ "(RLFramebufferAttachTextureType.toEnum) Invalid value: " ++ show n + +instance Storable RLFramebufferAttachTextureType where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Face culling mode +data RLCullMode + = RLCullFaceFront + | RLCullFaceBack + deriving (Eq, Show, Enum) + +instance Storable RLCullMode where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Matrix modes (equivalent to OpenGL) +data RLMatrixMode + -- | GL_MODELVIEW + = RLModelView + -- | GL_PROJECTION + | RLProjection + -- | GL_TEXTURE + | RLTexture + deriving (Eq, Show) + +instance Enum RLMatrixMode where + fromEnum n = case n of + RLModelView -> 0x1700 + RLProjection -> 0x1701 + RLTexture -> 0x1702 + + toEnum n = case n of + 0x1700 -> RLModelView + 0x1701 -> RLProjection + 0x1702 -> RLTexture + _ -> error $ "(RLMatrixMode.toEnum) Invalid value: " ++ show n + +instance Storable RLMatrixMode where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Primitive assembly draw modes +data RLDrawMode + -- | GL_LINES + = RLLines + -- | GL_TRIANGLES + | RLTriangles + -- | GL_QUADS + | RLQuads + deriving (Eq, Show) + +instance Enum RLDrawMode where + fromEnum n = case n of + RLLines -> 0x0001 + RLTriangles -> 0x0004 + RLQuads -> 0x0007 + + toEnum n = case n of + 0x0001 -> RLLines + 0x0004 -> RLTriangles + 0x0007 -> RLQuads + _ -> error $ "(RLDrawMode.toEnum) Invalid value: " ++ show n + +instance Storable RLDrawMode where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | Texture parameters (equivalent to OpenGL defines) +data RLTextureParam + -- | GL_TEXTURE_WRAP_S + = RLTextureParamWrapS + -- | GL_TEXTURE_WRAP_T + | RLTextureParamWrapT + -- | GL_TEXTURE_MAG_FILTER + | RLTextureParamMagFilter + -- | GL_TEXTURE_MIN_FILTER + | RLTextureParamMinFilter + -- | GL_NEAREST + | RLTextureParamFilterNearest + -- | GL_LINEAR + | RLTextureParamFilterLinear + -- | GL_NEAREST_MIPMAP_NEAREST + | RLTextureParamFilterMipNearest + -- | GL_NEAREST_MIPMAP_LINEAR + | RLTextureParamFilterNearestMipLinear + -- | GL_LINEAR_MIPMAP_NEAREST + | RLTextureParamFilterLinearMipNearest + -- | GL_LINEAR_MIPMAP_LINEAR + | RLTextureParamFilterMipLinear + -- | Anisotropic filter (custom identifier) + | RLTextureParamFilterAnisotropic + -- | Texture mipmap bias, percentage ratio (custom identifier) + | RLTextureParamMipmapBiasRatio + deriving (Eq, Show) + +instance Enum RLTextureParam where + fromEnum n = case n of + RLTextureParamWrapS -> 0x2802 + RLTextureParamWrapT -> 0x2803 + RLTextureParamMagFilter -> 0x2800 + RLTextureParamMinFilter -> 0x2801 + RLTextureParamFilterNearest -> 0x2600 + RLTextureParamFilterLinear -> 0x2601 + RLTextureParamFilterMipNearest -> 0x2700 + RLTextureParamFilterNearestMipLinear -> 0x2702 + RLTextureParamFilterLinearMipNearest -> 0x2701 + RLTextureParamFilterMipLinear -> 0x2703 + RLTextureParamFilterAnisotropic -> 0x3000 + RLTextureParamMipmapBiasRatio -> 0x4000 + + toEnum n = case n of + 0x2802 -> RLTextureParamWrapS + 0x2803 -> RLTextureParamWrapT + 0x2800 -> RLTextureParamMagFilter + 0x2801 -> RLTextureParamMinFilter + 0x2600 -> RLTextureParamFilterNearest + 0x2601 -> RLTextureParamFilterLinear + 0x2700 -> RLTextureParamFilterMipNearest + 0x2702 -> RLTextureParamFilterNearestMipLinear + 0x2701 -> RLTextureParamFilterLinearMipNearest + 0x2703 -> RLTextureParamFilterMipLinear + 0x3000 -> RLTextureParamFilterAnisotropic + 0x4000 -> RLTextureParamMipmapBiasRatio + _ -> error $ "(RLTextureParam.toEnum) Invalid value: " ++ show n + +instance Storable RLTextureParam where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | OpenGL shader type +data GLShaderType + -- | GL_FRAGMENT_SHADER + = GLFragmentShader + -- | GL_VERTEX_SHADER + | GLVertexShader + -- | GL_GEOMETRY_SHADER + | GLGeometryShader + -- | GL_COMPUTE_SHADER + | GLComputeShader + deriving (Eq, Show) + +instance Enum GLShaderType where + fromEnum n = case n of + GLFragmentShader -> 0x8B30 + GLVertexShader -> 0x8B31 + GLGeometryShader -> 0x8DD9 + GLComputeShader -> 0x91B9 + + toEnum n = case n of + 0x8B30 -> GLFragmentShader + 0x8B31 -> GLVertexShader + 0x8DD9 -> GLGeometryShader + 0x91B9 -> GLComputeShader + _ -> error $ "(GLShaderType.toEnum) Invalid value: " ++ show n + +instance Storable GLShaderType where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + +-- | GL buffer usage hint +data RLBufferHint + -- | GL_STREAM_DRAW + = RLBufferHintStreamDraw + -- | GL_STREAM_READ + | RLBufferHintStreamRead + -- | GL_STREAM_COPY + | RLBufferHintStreamCopy + -- | GL_STATIC_DRAW + | RLBufferHintStaticDraw + -- | GL_STATIC_READ + | RLBufferHintStaticRead + -- | GL_STATIC_COPY + | RLBufferHintStaticCopy + -- | GL_DYNAMIC_DRAW + | RLBufferHintDynamicDraw + -- | GL_DYNAMIC_READ + | RLBufferHintDynamicRead + -- | GL_DYNAMIC_COPY + | RLBufferHintDynamicCopy + deriving (Eq, Show) + +instance Enum RLBufferHint where + fromEnum n = case n of + RLBufferHintStreamDraw -> 0x88E0 + RLBufferHintStreamRead -> 0x88E1 + RLBufferHintStreamCopy -> 0x88E2 + RLBufferHintStaticDraw -> 0x88E4 + RLBufferHintStaticRead -> 0x88E5 + RLBufferHintStaticCopy -> 0x88E6 + RLBufferHintDynamicDraw -> 0x88E8 + RLBufferHintDynamicRead -> 0x88E9 + RLBufferHintDynamicCopy -> 0x88EA + + toEnum n = case n of + 0x88E0 -> RLBufferHintStreamDraw + 0x88E1 -> RLBufferHintStreamRead + 0x88E2 -> RLBufferHintStreamCopy + 0x88E4 -> RLBufferHintStaticDraw + 0x88E5 -> RLBufferHintStaticRead + 0x88E6 -> RLBufferHintStaticCopy + 0x88E8 -> RLBufferHintDynamicDraw + 0x88E9 -> RLBufferHintDynamicRead + 0x88EA -> RLBufferHintDynamicCopy + _ -> error $ "(RLBufferHint.toEnum) Invalid value: " ++ show n + +instance Storable RLBufferHint where + sizeOf _ = 4 + alignment _ = 4 + peek ptr = do + val <- peek (castPtr ptr) + return $ toEnum $ fromEnum (val :: CInt) + poke ptr v = poke (castPtr ptr) (fromIntegral (fromEnum v) :: CInt) + ------------------------------------------------ -- Raylib typeclasses -------------------------- ------------------------------------------------ @@ -919,6 +1597,8 @@ -- Raylib structures --------------------------- ------------------------------------------------ +---- raylib.h + data Vector2 = Vector2 { vector2'x :: Float, vector2'y :: Float @@ -2151,6 +2831,142 @@ pathsCStrings <- peekArray (length $ filePathList'paths val) pathsPtr mapM_ (c'free . castPtr) pathsCStrings c'free $ castPtr pathsPtr + +---- rlgl.h + +-- | Dynamic vertex buffers (position + texcoords + colors + indices arrays) +data RLVertexBuffer = RLVertexBuffer + { -- | Number of elements in the buffer (QUADS) + rlVertexBuffer'elementCount :: Int, + -- | Vertex position (shader-location = 0) + rlVertexBuffer'vertices :: [Vector3], + -- | Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1) + rlVertexBuffer'texcoords :: [Vector2], + -- | Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) + rlVertexBuffer'colors :: [Color], + -- | Vertex indices (in case vertex data comes indexed) (6 indices per quad) + rlVertexBuffer'indices :: [Integer], + -- | OpenGL Vertex Array Object id + rlVertexBuffer'vaoId :: Integer, + -- | OpenGL Vertex Buffer Objects id (4 types of vertex data) + rlVertexBuffer'vboId :: [Integer] + } + deriving (Eq, Show) + +instance Storable RLVertexBuffer where + sizeOf _ = 64 + alignment _ = 8 + peek _p = do + elementCount <- fromIntegral <$> (peekByteOff _p 0 :: IO CInt) + verticesPtr <- (peekByteOff _p 8 :: IO (Ptr Vector3)) + vertices <- peekArray elementCount verticesPtr + texcoordsPtr <- (peekByteOff _p 16 :: IO (Ptr Vector2)) + texcoords <- peekArray elementCount texcoordsPtr + colorsPtr <- (peekByteOff _p 24 :: IO (Ptr Color)) + colors <- peekArray elementCount colorsPtr + indicesPtr <- (peekByteOff _p 32 :: IO (Ptr CUInt)) + indices <- map fromIntegral <$> peekArray elementCount indicesPtr + vaoId <- fromIntegral <$> (peekByteOff _p 40 :: IO CUInt) + vboId <- map fromIntegral <$> peekStaticArrayOff 4 (castPtr _p :: Ptr CUInt) 44 + return $ RLVertexBuffer elementCount vertices texcoords colors indices vaoId vboId + poke _p (RLVertexBuffer elementCount vertices texcoords colors indices vaoId vboId) = do + pokeByteOff _p 0 (fromIntegral elementCount :: CInt) + pokeByteOff _p 8 =<< newArray vertices + pokeByteOff _p 16 =<< newArray texcoords + pokeByteOff _p 24 =<< newArray colors + pokeByteOff _p 32 =<< newArray (map fromIntegral indices :: [CUInt]) + pokeByteOff _p 40 (fromIntegral vaoId :: CUInt) + pokeStaticArrayOff (castPtr _p) 44 (map fromIntegral vboId :: [CUInt]) + return () + +instance Freeable RLVertexBuffer where + rlFreeDependents _ ptr = do + verticesPtr <- (peekByteOff ptr 8 :: IO (Ptr Vector3)) + c'free $ castPtr verticesPtr + texcoordsPtr <- (peekByteOff ptr 16 :: IO (Ptr Vector2)) + c'free $ castPtr texcoordsPtr + colorsPtr <- (peekByteOff ptr 24 :: IO (Ptr Color)) + c'free $ castPtr colorsPtr + indicesPtr <- (peekByteOff ptr 32 :: IO (Ptr CUInt)) + c'free $ castPtr indicesPtr + +-- | Draw call type. +-- NOTE: Only texture changes register a new draw, other state-change-related elements are not +-- used at this moment (vaoId, shaderId, matrices), raylib just forces a batch draw call if any +-- of those state changes happen (this is done in the core module). +data RLDrawCall = RLDrawCall + { -- | Drawing mode: LINES, TRIANGLES, QUADS + rlDrawCall'mode :: RLDrawMode, + -- | Number of vertices of the draw + rlDrawCall'vertexCount :: Int, + -- | Number of vertices required for index alignment (LINES, TRIANGLES) + rlDrawCall'vertexAlignment :: Int, + -- | Texture id to be used on the draw -> Used to create new draw call if changed + rlDrawCall'textureId :: Integer + } + deriving (Eq, Show, Freeable) + +instance Storable RLDrawCall where + sizeOf _ = 16 + alignment _ = 8 + peek _p = do + mode <- peekByteOff _p 0 + vertexCount <- fromIntegral <$> (peekByteOff _p 4 :: IO CInt) + vertexAlignment <- fromIntegral <$> (peekByteOff _p 8 :: IO CInt) + textureId <- fromIntegral <$> (peekByteOff _p 12 :: IO CUInt) + return $ RLDrawCall mode vertexCount vertexAlignment textureId + poke _p (RLDrawCall mode vertexCount vertexAlignment textureId) = do + pokeByteOff _p 0 mode + pokeByteOff _p 4 (fromIntegral vertexCount :: CInt) + pokeByteOff _p 8 (fromIntegral vertexAlignment :: CInt) + pokeByteOff _p 12 (fromIntegral textureId :: CUInt) + return () + +-- rlRenderBatch type +data RLRenderBatch = RLRenderBatch + { -- | Number of vertex buffers (multi-buffering support) + rlRenderBatch'bufferCount :: Int, + -- | Current buffer tracking in case of multi-buffering + rlRenderBatch'currentBuffer :: Int, + -- | Dynamic buffer(s) for vertex data + rlRenderBatch'vertexBuffers :: [RLVertexBuffer], + -- | Draw calls array, depends on textureId + rlRenderBatch'draws :: [RLDrawCall], + -- | Draw calls counter + rlRenderBatch'drawCounter :: Int, + -- | Current depth value for next draw + rlRenderBatch'currentDepth :: Float + } + deriving (Eq, Show) + +instance Storable RLRenderBatch where + sizeOf _ = 32 + alignment _ = 8 + peek _p = do + bufferCount <- fromIntegral <$> (peekByteOff _p 0 :: IO CInt) + currentBuffer <- fromIntegral <$> (peekByteOff _p 4 :: IO CInt) + vertexBuffersPtr <- (peekByteOff _p 8 :: IO (Ptr RLVertexBuffer)) + vertexBuffers <- peekArray bufferCount vertexBuffersPtr + drawsPtr <- (peekByteOff _p 16 :: IO (Ptr RLDrawCall)) + draws <- peekArray 256 drawsPtr + drawCounter <- fromIntegral <$> (peekByteOff _p 24 :: IO CInt) + currentDepth <- realToFrac <$> (peekByteOff _p 28 :: IO CFloat) + return $ RLRenderBatch bufferCount currentBuffer vertexBuffers draws drawCounter currentDepth + poke _p (RLRenderBatch bufferCount currentBuffer vertexBuffers draws drawCounter currentDepth) = do + pokeByteOff _p 0 (fromIntegral bufferCount :: CInt) + pokeByteOff _p 4 (fromIntegral currentBuffer :: CInt) + pokeByteOff _p 8 =<< newArray vertexBuffers + pokeByteOff _p 16 =<< newArray draws + pokeByteOff _p 24 (fromIntegral drawCounter :: CInt) + pokeByteOff _p 28 (realToFrac currentDepth :: CFloat) + return () + +instance Freeable RLRenderBatch where + rlFreeDependents val ptr = do + vertexBuffersPtr <- (peekByteOff ptr 8 :: IO (Ptr RLVertexBuffer)) + rlFreeArray (rlRenderBatch'vertexBuffers val) vertexBuffersPtr + drawsPtr <- (peekByteOff ptr 16 :: IO (Ptr RLDrawCall)) + c'free $ castPtr drawsPtr ------------------------------------------------ -- Raylib callbacks ----------------------------
+ src/Raylib/Util/RLGL.hs view
@@ -0,0 +1,944 @@+{-# OPTIONS -Wall #-} +{-# LANGUAGE ForeignFunctionInterface #-} + +module Raylib.Util.RLGL + ( rlMatrixMode, + rlPushMatrix, + rlPopMatrix, + rlLoadIdentity, + rlTranslatef, + rlRotatef, + rlScalef, + rlMultMatrixf, + rlFrustum, + rlOrtho, + rlViewport, + rlBegin, + rlEnd, + rlVertex2i, + rlVertex2f, + rlVertex3f, + rlTexCoord2f, + rlNormal3f, + rlColor4ub, + rlColor3f, + rlColor4f, + rlEnableVertexArray, + rlDisableVertexArray, + rlEnableVertexBuffer, + rlDisableVertexBuffer, + rlEnableVertexBufferElement, + rlDisableVertexBufferElement, + rlEnableVertexAttribute, + rlDisableVertexAttribute, + rlActiveTextureSlot, + rlEnableTexture, + rlDisableTexture, + rlEnableTextureCubemap, + rlDisableTextureCubemap, + rlTextureParameters, + rlCubemapParameters, + rlEnableShader, + rlDisableShader, + rlEnableFramebuffer, + rlDisableFramebuffer, + rlActiveDrawBuffers, + rlEnableColorBlend, + rlDisableColorBlend, + rlEnableDepthTest, + rlDisableDepthTest, + rlEnableDepthMask, + rlDisableDepthMask, + rlEnableBackfaceCulling, + rlDisableBackfaceCulling, + rlSetCullFace, + rlEnableScissorTest, + rlDisableScissorTest, + rlScissor, + rlEnableWireMode, + rlDisableWireMode, + rlSetLineWidth, + rlGetLineWidth, + rlEnableSmoothLines, + rlDisableSmoothLines, + rlEnableStereoRender, + rlDisableStereoRender, + rlIsStereoRenderEnabled, + rlClearColor, + rlClearScreenBuffers, + rlCheckErrors, + rlSetBlendMode, + rlSetBlendFactors, + rlSetBlendFactorsSeparate, + rlglInit, + rlglClose, + rlLoadExtensions, + rlGetVersion, + rlSetFramebufferWidth, + rlGetFramebufferWidth, + rlSetFramebufferHeight, + rlGetFramebufferHeight, + rlGetTextureIdDefault, + rlGetShaderIdDefault, + rlGetShaderLocsDefault, + rlLoadRenderBatch, + rlUnloadRenderBatch, + rlDrawRenderBatch, + rlSetRenderBatchActive, + rlDrawRenderBatchActive, + rlCheckRenderBatchLimit, + rlSetTexture, + rlLoadVertexArray, + rlLoadVertexBuffer, + rlLoadVertexBufferElement, + rlUpdateVertexBuffer, + rlUpdateVertexBufferElements, + rlUnloadVertexArray, + rlUnloadVertexBuffer, + rlSetVertexAttribute, + rlSetVertexAttributeDivisor, + rlSetVertexAttributeDefault, + rlDrawVertexArray, + rlDrawVertexArrayElements, + rlDrawVertexArrayInstanced, + rlDrawVertexArrayElementsInstanced, + rlLoadTexture, + rlLoadTextureDepth, + rlLoadTextureCubemap, + rlUpdateTexture, + rlGetGlTextureFormats, + rlGetPixelFormatName, + rlUnloadTexture, + rlGenTextureMipmaps, + rlReadTexturePixels, + rlReadScreenPixels, + rlLoadFramebuffer, + rlFramebufferAttach, + rlFramebufferComplete, + rlUnloadFramebuffer, + rlLoadShaderCode, + rlCompileShader, + rlLoadShaderProgram, + rlUnloadShaderProgram, + rlGetLocationUniform, + rlGetLocationAttrib, + rlSetUniform, + rlSetUniformMatrix, + rlSetUniformSampler, + rlSetShader, + rlLoadComputeShaderProgram, + rlComputeShaderDispatch, + rlLoadShaderBuffer, + rlUnloadShaderBuffer, + rlUpdateShaderBuffer, + rlBindShaderBuffer, + rlCopyShaderBuffer, + rlGetShaderBufferSize, + rlBindImageTexture, + rlGetMatrixModelview, + rlGetMatrixProjection, + rlGetMatrixTransform, + rlGetMatrixProjectionStereo, + rlGetMatrixViewOffsetStereo, + rlSetMatrixProjection, + rlSetMatrixModelview, + rlSetMatrixProjectionStereo, + rlSetMatrixViewOffsetStereo, + rlLoadDrawCube, + rlLoadDrawQuad, + ) +where + +import Foreign + ( Ptr, + Storable(sizeOf, poke, peek), + malloc, + fromBool, + toBool, + castPtr, + nullPtr, Word8 ) +import Foreign.C ( CUInt, CInt, CUChar, withCString, CUShort ) +import Raylib.ForeignUtil + ( pop, + popCArray, + withFreeable, + Freeable, + withFreeableArray, + withFreeableArrayLen ) +import Raylib.Native + ( c'rlSetMatrixViewOffsetStereo, + c'rlSetMatrixProjectionStereo, + c'rlSetMatrixModelview, + c'rlSetMatrixProjection, + c'rlGetMatrixViewOffsetStereo, + c'rlGetMatrixProjectionStereo, + c'rlGetMatrixTransform, + c'rlGetMatrixProjection, + c'rlGetMatrixModelview, + c'rlBindImageTexture, + c'rlGetShaderBufferSize, + c'rlCopyShaderBuffer, + c'rlBindShaderBuffer, + c'rlUpdateShaderBuffer, + c'rlUnloadShaderBuffer, + c'rlLoadShaderBuffer, + c'rlComputeShaderDispatch, + c'rlLoadComputeShaderProgram, + c'rlSetShader, + c'rlSetUniformSampler, + c'rlSetUniformMatrix, + c'rlSetUniform, + c'rlGetLocationAttrib, + c'rlGetLocationUniform, + c'rlUnloadShaderProgram, + c'rlLoadShaderProgram, + c'rlCompileShader, + c'rlLoadShaderCode, + c'rlUnloadFramebuffer, + c'rlFramebufferComplete, + c'rlFramebufferAttach, + c'rlLoadFramebuffer, + c'rlReadScreenPixels, + c'rlReadTexturePixels, + c'rlGenTextureMipmaps, + c'rlUnloadTexture, + c'rlGetGlTextureFormats, + c'rlUpdateTexture, + c'rlLoadTextureCubemap, + c'rlLoadTextureDepth, + c'rlLoadTexture, + c'rlDrawVertexArrayElementsInstanced, + c'rlDrawVertexArrayInstanced, + c'rlDrawVertexArrayElements, + c'rlDrawVertexArray, + c'rlSetVertexAttributeDefault, + c'rlSetVertexAttributeDivisor, + c'rlSetVertexAttribute, + c'rlUnloadVertexBuffer, + c'rlUnloadVertexArray, + c'rlUpdateVertexBufferElements, + c'rlUpdateVertexBuffer, + c'rlLoadVertexBufferElement, + c'rlLoadVertexBuffer, + c'rlLoadVertexArray, + c'rlSetTexture, + c'rlCheckRenderBatchLimit, + c'rlSetRenderBatchActive, + c'rlDrawRenderBatch, + c'rlUnloadRenderBatch, + c'rlLoadRenderBatch, + c'rlGetShaderLocsDefault, + c'rlGetShaderIdDefault, + c'rlGetTextureIdDefault, + c'rlGetFramebufferHeight, + c'rlSetFramebufferHeight, + c'rlGetFramebufferWidth, + c'rlSetFramebufferWidth, + c'rlGetVersion, + c'rlLoadExtensions, + c'rlglInit, + c'rlSetBlendFactorsSeparate, + c'rlSetBlendFactors, + c'rlSetBlendMode, + c'rlClearColor, + c'rlIsStereoRenderEnabled, + c'rlGetLineWidth, + c'rlSetLineWidth, + c'rlScissor, + c'rlSetCullFace, + c'rlActiveDrawBuffers, + c'rlEnableFramebuffer, + c'rlEnableShader, + c'rlCubemapParameters, + c'rlTextureParameters, + c'rlEnableTextureCubemap, + c'rlEnableTexture, + c'rlActiveTextureSlot, + c'rlDisableVertexAttribute, + c'rlEnableVertexAttribute, + c'rlEnableVertexBufferElement, + c'rlEnableVertexBuffer, + c'rlEnableVertexArray, + c'rlColor4f, + c'rlColor3f, + c'rlColor4ub, + c'rlNormal3f, + c'rlTexCoord2f, + c'rlVertex3f, + c'rlVertex2f, + c'rlVertex2i, + c'rlBegin, + c'rlViewport, + c'rlOrtho, + c'rlFrustum, + c'rlMultMatrixf, + c'rlScalef, + c'rlRotatef, + c'rlTranslatef, + c'rlMatrixMode, + c'rlGetPixelDataSize ) +import Raylib.Types + ( unpackShaderUniformDataV, + Matrix, + RLBlendMode, + RLCullMode, + RLFramebufferAttachTextureType, + RLFramebufferAttachType, + RLPixelFormat(..), + RLRenderBatch, + ShaderUniformDataV, + RLMatrixMode, + RLDrawMode, + RLTextureParam, + GLShaderType, + RLBufferHint ) + +-- | Choose the current matrix to be transformed +rlMatrixMode :: RLMatrixMode -> IO () +rlMatrixMode mode = c'rlMatrixMode (fromIntegral $ fromEnum mode) + +-- | Push the current matrix to stack +foreign import ccall safe "rlgl.h rlPushMatrix" rlPushMatrix :: IO () + +-- | Pop latest inserted matrix from stack +foreign import ccall safe "rlgl.h rlPopMatrix" rlPopMatrix :: IO () + +-- | Reset current matrix to identity matrix +foreign import ccall safe "rlgl.h rlLoadIdentity" rlLoadIdentity :: IO () + +-- | Multiply the current matrix by a translation matrix +rlTranslatef :: Float -> Float -> Float -> IO () +rlTranslatef x y z = c'rlTranslatef (realToFrac x) (realToFrac y) (realToFrac z) + +-- | Multiply the current matrix by a rotation matrix +rlRotatef :: Float -> Float -> Float -> Float -> IO () +rlRotatef angle x y z = c'rlRotatef (realToFrac angle) (realToFrac x) (realToFrac y) (realToFrac z) + +-- | Multiply the current matrix by a scaling matrix +rlScalef :: Float -> Float -> Float -> IO () +rlScalef x y z = c'rlScalef (realToFrac x) (realToFrac y) (realToFrac z) + +-- | Multiply the current matrix by another matrix +rlMultMatrixf :: [Float] -> IO () +rlMultMatrixf matf = withFreeableArray (map realToFrac matf) c'rlMultMatrixf + +-- | Multiply the current matrix by a perspective matrix generated by parameters +rlFrustum :: Double -> Double -> Double -> Double -> Double -> Double -> IO () +rlFrustum left right bottom top znear zfar = c'rlFrustum (realToFrac left) (realToFrac right) (realToFrac bottom) (realToFrac top) (realToFrac znear) (realToFrac zfar) + +-- | Multiply the current matrix by an orthographic matrix generated by parameters +rlOrtho :: Double -> Double -> Double -> Double -> Double -> Double -> IO () +rlOrtho left right bottom top znear zfar = c'rlOrtho (realToFrac left) (realToFrac right) (realToFrac bottom) (realToFrac top) (realToFrac znear) (realToFrac zfar) + +-- | Set the viewport area +rlViewport :: Int -> Int -> Int -> Int -> IO () +rlViewport x y width height = c'rlViewport (fromIntegral x) (fromIntegral y) (fromIntegral width) (fromIntegral height) + +-- | Initialize drawing mode (how to organize vertex) +rlBegin :: RLDrawMode -> IO () +rlBegin mode = c'rlBegin (fromIntegral $ fromEnum mode) + +-- | Finish vertex providing +foreign import ccall safe "rlgl.h rlEnd" rlEnd :: IO () + +-- | Define one vertex (position) - 2 int +rlVertex2i :: Int -> Int -> IO () +rlVertex2i x y = c'rlVertex2i (fromIntegral x) (fromIntegral y) + +-- | Define one vertex (position) - 2 float +rlVertex2f :: Float -> Float -> IO () +rlVertex2f x y = c'rlVertex2f (realToFrac x) (realToFrac y) + +-- | Define one vertex (position) - 3 float +rlVertex3f :: Float -> Float -> Float -> IO () +rlVertex3f x y z = c'rlVertex3f (realToFrac x) (realToFrac y) (realToFrac z) + +-- | Define one vertex (texture coordinate) - 2 float +rlTexCoord2f :: Float -> Float -> IO () +rlTexCoord2f x y = c'rlTexCoord2f (realToFrac x) (realToFrac y) + +-- | Define one vertex (normal) - 3 float +rlNormal3f :: Float -> Float -> Float -> IO () +rlNormal3f x y z = c'rlNormal3f (realToFrac x) (realToFrac y) (realToFrac z) + +-- | Define one vertex (color) - 4 byte +rlColor4ub :: Word8 -> Word8 -> Word8 -> Word8 -> IO () +rlColor4ub r g b a = c'rlColor4ub (fromIntegral r) (fromIntegral g) (fromIntegral b) (fromIntegral a) + +-- | Define one vertex (color) - 3 float +rlColor3f :: Float -> Float -> Float -> IO () +rlColor3f r g b = c'rlColor3f (realToFrac r) (realToFrac g) (realToFrac b) + +-- | Define one vertex (color) - 4 float +rlColor4f :: Float -> Float -> Float -> Float -> IO () +rlColor4f r g b a = c'rlColor4f (realToFrac r) (realToFrac g) (realToFrac b) (realToFrac a) + +-- | Enable vertex array (VAO, if supported) +rlEnableVertexArray :: Integer -> IO Bool +rlEnableVertexArray vaoId = toBool <$> c'rlEnableVertexArray (fromIntegral vaoId) + +-- | Disable vertex array (VAO, if supported) +foreign import ccall safe "rlgl.h rlDisableVertexArray" rlDisableVertexArray :: IO () + +-- | Enable vertex buffer (VBO) +rlEnableVertexBuffer :: Integer -> IO () +rlEnableVertexBuffer vboId = c'rlEnableVertexBuffer (fromIntegral vboId) + +-- | Disable vertex buffer (VBO) +foreign import ccall safe "rlgl.h rlDisableVertexBuffer" rlDisableVertexBuffer :: IO () + +-- | Enable vertex buffer element (VBO element) +rlEnableVertexBufferElement :: Integer -> IO () +rlEnableVertexBufferElement vboeId = c'rlEnableVertexBufferElement (fromIntegral vboeId) + +-- | Disable vertex buffer element (VBO element) +foreign import ccall safe "rlgl.h rlDisableVertexBufferElement" rlDisableVertexBufferElement :: IO () + +-- | Enable vertex attribute index +rlEnableVertexAttribute :: Integer -> IO () +rlEnableVertexAttribute index = c'rlEnableVertexAttribute (fromIntegral index) + +-- | Disable vertex attribute index +rlDisableVertexAttribute :: Integer -> IO () +rlDisableVertexAttribute index = c'rlDisableVertexAttribute (fromIntegral index) + +-- OpenGL 1.1 only, not implemented +-- -- | Enable attribute state pointer +-- rlEnableStatePointer :: Int -> Ptr () -> IO () + +-- -- | Disable attribute state pointer +-- rlDisableStatePointer :: Int -> IO () + +-- | Select and active a texture slot +rlActiveTextureSlot :: Int -> IO () +rlActiveTextureSlot slot = c'rlActiveTextureSlot (fromIntegral slot) + +-- | Enable texture +rlEnableTexture :: Integer -> IO () +rlEnableTexture tId = c'rlEnableTexture (fromIntegral tId) + +-- | Disable texture +foreign import ccall safe "rlgl.h rlDisableTexture" rlDisableTexture :: IO () + +-- | Enable texture cubemap +rlEnableTextureCubemap :: Integer -> IO () +rlEnableTextureCubemap tId = c'rlEnableTextureCubemap (fromIntegral tId) + +-- | Disable texture cubemap +foreign import ccall safe "rlgl.h rlDisableTextureCubemap" rlDisableTextureCubemap :: IO () + +-- | Set texture parameters (filter, wrap) +rlTextureParameters :: Integer -> RLTextureParam -> Int -> IO () +rlTextureParameters tId param value = c'rlTextureParameters (fromIntegral tId) (fromIntegral $ fromEnum param) (fromIntegral value) + +-- | Set cubemap parameters (filter, wrap) +rlCubemapParameters :: Integer -> RLTextureParam -> Int -> IO () +rlCubemapParameters tId param value = c'rlCubemapParameters (fromIntegral tId) (fromIntegral $ fromEnum param) (fromIntegral value) + +-- | Enable shader program +rlEnableShader :: Integer -> IO () +rlEnableShader sId = c'rlEnableShader (fromIntegral sId) + +-- | Disable shader program +foreign import ccall safe "rlgl.h rlDisableShader" rlDisableShader :: IO () + +-- | Enable render texture (fbo) +rlEnableFramebuffer :: Integer -> IO () +rlEnableFramebuffer fboId = c'rlEnableFramebuffer (fromIntegral fboId) + +-- | Disable render texture (fbo), return to default framebuffer +foreign import ccall safe "rlgl.h rlDisableFramebuffer" rlDisableFramebuffer :: IO () + +-- | Activate multiple draw color buffers +rlActiveDrawBuffers :: Int -> IO () +rlActiveDrawBuffers count = c'rlActiveDrawBuffers (fromIntegral count) + +-- | Enable color blending +foreign import ccall safe "rlgl.h rlEnableColorBlend" rlEnableColorBlend :: IO () + +-- | Disable color blending +foreign import ccall safe "rlgl.h rlDisableColorBlend" rlDisableColorBlend :: IO () + +-- | Enable depth test +foreign import ccall safe "rlgl.h rlEnableDepthTest" rlEnableDepthTest :: IO () + +-- | Disable depth test +foreign import ccall safe "rlgl.h rlDisableDepthTest" rlDisableDepthTest :: IO () + +-- | Enable depth write +foreign import ccall safe "rlgl.h rlEnableDepthMask" rlEnableDepthMask :: IO () + +-- | Disable depth write +foreign import ccall safe "rlgl.h rlDisableDepthMask" rlDisableDepthMask :: IO () + +-- | Enable backface culling +foreign import ccall safe "rlgl.h rlEnableBackfaceCulling" rlEnableBackfaceCulling :: IO () + +-- | Disable backface culling +foreign import ccall safe "rlgl.h rlDisableBackfaceCulling" rlDisableBackfaceCulling :: IO () + +-- | Set face culling mode +rlSetCullFace :: RLCullMode -> IO () +rlSetCullFace mode = c'rlSetCullFace (fromIntegral $ fromEnum mode) + +-- | Enable scissor test +foreign import ccall safe "rlgl.h rlEnableScissorTest" rlEnableScissorTest :: IO () + +-- | Disable scissor test +foreign import ccall safe "rlgl.h rlDisableScissorTest" rlDisableScissorTest :: IO () + +-- | Scissor test +rlScissor :: Int -> Int -> Int -> Int -> IO () +rlScissor x y width height = c'rlScissor (fromIntegral x) (fromIntegral y) (fromIntegral width) (fromIntegral height) + +-- | Enable wire mode +foreign import ccall safe "rlgl.h rlEnableWireMode" rlEnableWireMode :: IO () + +-- | Disable wire mode +foreign import ccall safe "rlgl.h rlDisableWireMode" rlDisableWireMode :: IO () + +-- | Set the line drawing width +rlSetLineWidth :: Float -> IO () +rlSetLineWidth width = c'rlSetLineWidth (realToFrac width) + +-- | Get the line drawing width +rlGetLineWidth :: IO Float +rlGetLineWidth = realToFrac <$> c'rlGetLineWidth + +-- | Enable line aliasing +foreign import ccall safe "rlgl.h rlEnableSmoothLines" rlEnableSmoothLines :: IO () + +-- | Disable line aliasing +foreign import ccall safe "rlgl.h rlDisableSmoothLines" rlDisableSmoothLines :: IO () + +-- | Enable stereo rendering +foreign import ccall safe "rlgl.h rlEnableStereoRender" rlEnableStereoRender :: IO () + +-- | Disable stereo rendering +foreign import ccall safe "rlgl.h rlDisableStereoRender" rlDisableStereoRender :: IO () + +-- | Check if stereo render is enabled +rlIsStereoRenderEnabled :: IO Bool +rlIsStereoRenderEnabled = toBool <$> c'rlIsStereoRenderEnabled + +-- | Clear color buffer with color +rlClearColor :: Word8 -> Word8 -> Word8 -> Word8 -> IO () +rlClearColor r g b a = c'rlClearColor (fromIntegral r) (fromIntegral g) (fromIntegral b) (fromIntegral a) + +-- | Clear used screen buffers (color and depth) +foreign import ccall safe "rlgl.h rlClearScreenBuffers" rlClearScreenBuffers :: IO () + +-- | Check and log OpenGL error codes +foreign import ccall safe "rlgl.h rlCheckErrors" rlCheckErrors :: IO () + +-- | Set blending mode +rlSetBlendMode :: RLBlendMode -> IO () +rlSetBlendMode mode = c'rlSetBlendMode (fromIntegral $ fromEnum mode) + +-- | Set blending mode factor and equation (using OpenGL factors) +rlSetBlendFactors :: Int -> Int -> Int -> IO () +rlSetBlendFactors glSrcFactor glDstFactor glEquation = c'rlSetBlendFactors (fromIntegral glSrcFactor) (fromIntegral glDstFactor) (fromIntegral glEquation) + +-- | Set blending mode factors and equations separately (using OpenGL factors) +rlSetBlendFactorsSeparate :: Int -> Int -> Int -> Int -> Int -> Int -> IO () +rlSetBlendFactorsSeparate glSrcRGB glDstRGB glSrcAlpha glDstAlpha glEqRGB glEqAlpha = + c'rlSetBlendFactorsSeparate (fromIntegral glSrcRGB) (fromIntegral glDstRGB) (fromIntegral glSrcAlpha) (fromIntegral glDstAlpha) (fromIntegral glEqRGB) (fromIntegral glEqAlpha) + +-- | Initialize rlgl (buffers, shaders, textures, states) +rlglInit :: Int -> Int -> IO () +rlglInit width height = c'rlglInit (fromIntegral width) (fromIntegral height) + +-- | De-initialize rlgl (buffers, shaders, textures) +foreign import ccall safe "rlgl.h rlglClose" rlglClose :: IO () + +-- | Load OpenGL extensions (loader function required) +rlLoadExtensions :: Ptr () -> IO () +rlLoadExtensions = c'rlLoadExtensions + +-- | Get current OpenGL version +rlGetVersion :: IO Int +rlGetVersion = fromIntegral <$> c'rlGetVersion + +-- | Set current framebuffer width +rlSetFramebufferWidth :: Int -> IO () +rlSetFramebufferWidth width = c'rlSetFramebufferWidth (fromIntegral width) + +-- | Get default framebuffer width +rlGetFramebufferWidth :: IO Int +rlGetFramebufferWidth = fromIntegral <$> c'rlGetFramebufferWidth + +-- | Set current framebuffer height +rlSetFramebufferHeight :: Int -> IO () +rlSetFramebufferHeight height = c'rlSetFramebufferHeight (fromIntegral height) + +-- | Get default framebuffer height +rlGetFramebufferHeight :: IO Int +rlGetFramebufferHeight = fromIntegral <$> c'rlGetFramebufferHeight + +-- | Get default texture id +rlGetTextureIdDefault :: IO Integer +rlGetTextureIdDefault = fromIntegral <$> c'rlGetTextureIdDefault + +-- | Get default shader id +rlGetShaderIdDefault :: IO Integer +rlGetShaderIdDefault = fromIntegral <$> c'rlGetShaderIdDefault + +-- | Get default shader locations +rlGetShaderLocsDefault :: IO [Int] +rlGetShaderLocsDefault = map fromIntegral <$> (popCArray 32 =<< c'rlGetShaderLocsDefault) + +-- | Load a render batch system +rlLoadRenderBatch :: Int -> Int -> IO RLRenderBatch +rlLoadRenderBatch numBuffers bufferElements = c'rlLoadRenderBatch (fromIntegral numBuffers) (fromIntegral bufferElements) >>= pop + +-- | Unload render batch system +rlUnloadRenderBatch :: RLRenderBatch -> IO () +rlUnloadRenderBatch batch = withFreeable batch c'rlUnloadRenderBatch + +-- | Draw render batch data (Update->Draw->Reset) +rlDrawRenderBatch :: RLRenderBatch -> IO RLRenderBatch +rlDrawRenderBatch batch = withFreeable batch (\p -> c'rlDrawRenderBatch p >> peek p) + +-- | Set the active render batch for rlgl (NULL for default internal) +rlSetRenderBatchActive :: Maybe RLRenderBatch -> IO () +rlSetRenderBatchActive Nothing = c'rlSetRenderBatchActive nullPtr +rlSetRenderBatchActive (Just val) = do + ptr <- malloc + poke ptr val + c'rlSetRenderBatchActive ptr + +-- | Update and draw internal render batch +foreign import ccall safe "rlgl.h rlDrawRenderBatchActive" rlDrawRenderBatchActive :: IO () + +-- | Check internal buffer overflow for a given number of vertex +rlCheckRenderBatchLimit :: Int -> IO Bool +rlCheckRenderBatchLimit vCount = toBool <$> c'rlCheckRenderBatchLimit (fromIntegral vCount) + +-- | Set current texture for render batch and check buffers limits +rlSetTexture :: Integer -> IO () +rlSetTexture tId = c'rlSetTexture (fromIntegral tId) + +-- | Load vertex array (vao) if supported +rlLoadVertexArray :: IO Integer +rlLoadVertexArray = fromIntegral <$> c'rlLoadVertexArray + +-- | Load a vertex buffer attribute +rlLoadVertexBuffer :: (Freeable a, Storable a) => [a] -> Int -> Bool -> IO Integer +rlLoadVertexBuffer buffer size dynamic = + fromIntegral <$> withFreeableArray buffer (\p -> c'rlLoadVertexBuffer (castPtr p) (fromIntegral size) (fromBool dynamic)) + +-- | Load a new attributes element buffer (typically the buffer data will be a list of `Int`s) +rlLoadVertexBufferElement :: (Freeable a, Storable a) => [a] -> Int -> Bool -> IO Integer +rlLoadVertexBufferElement buffer size dynamic = + fromIntegral <$> withFreeableArray buffer (\p -> c'rlLoadVertexBufferElement (castPtr p) (fromIntegral size) (fromBool dynamic)) + +-- | Update GPU buffer with new data. +-- WARNING: Fails on empty list +rlUpdateVertexBuffer :: (Freeable a, Storable a) => Integer -> [a] -> Int -> Int -> IO () +rlUpdateVertexBuffer bufferId bufferData size offset = + withFreeableArray bufferData (\p -> c'rlUpdateVertexBuffer (fromIntegral bufferId) (castPtr p) (fromIntegral size) (fromIntegral offset)) + +-- | Update vertex buffer elements with new data (typically the buffer data will be a list of `Int`s). +-- WARNING: Fails on empty list +rlUpdateVertexBufferElements :: (Freeable a, Storable a) => Integer -> [a] -> Int -> Int -> IO () +rlUpdateVertexBufferElements bufferId bufferData size offset = + withFreeableArray bufferData (\p -> c'rlUpdateVertexBufferElements (fromIntegral bufferId) (castPtr p) (fromIntegral size) (fromIntegral offset)) + +-- | Unload vertex array object (VAO) +rlUnloadVertexArray :: Integer -> IO () +rlUnloadVertexArray vaoId = c'rlUnloadVertexArray (fromIntegral vaoId) + +-- | Unload vertex buffer (VBO) +rlUnloadVertexBuffer :: Integer -> IO () +rlUnloadVertexBuffer vboId = c'rlUnloadVertexBuffer (fromIntegral vboId) + +-- TODO: improve types for the functions below + +-- | Set vertex attribute (the type must be a valid GLenum value) +rlSetVertexAttribute :: Integer -> Int -> Int -> Bool -> Int -> Ptr () -> IO () +rlSetVertexAttribute index compSize aType normalized stride = + c'rlSetVertexAttribute (fromIntegral index) (fromIntegral compSize) (fromIntegral aType) (fromBool normalized) (fromIntegral stride) + +-- | Set vertex attribute divisor +rlSetVertexAttributeDivisor :: Integer -> Int -> IO () +rlSetVertexAttributeDivisor index divisor = c'rlSetVertexAttributeDivisor (fromIntegral index) (fromIntegral divisor) + +-- | Set vertex attribute default value +rlSetVertexAttributeDefault :: Int -> Ptr () -> Int -> Int -> IO () +rlSetVertexAttributeDefault locIndex value attribType count = + c'rlSetVertexAttributeDefault (fromIntegral locIndex) value (fromIntegral attribType) (fromIntegral count) + +-- | Draw vertex array +rlDrawVertexArray :: Int -> Int -> IO () +rlDrawVertexArray offset count = c'rlDrawVertexArray (fromIntegral offset) (fromIntegral count) + +-- | Draw vertex array elements +rlDrawVertexArrayElements :: Int -> [Int] -> IO () +rlDrawVertexArrayElements offset buffer = + withFreeableArray + (map fromIntegral buffer :: [CUShort]) + (c'rlDrawVertexArrayElements (fromIntegral offset) (fromIntegral $ length buffer) . castPtr) + +-- | Draw vertex array instanced +rlDrawVertexArrayInstanced :: Int -> Int -> Int -> IO () +rlDrawVertexArrayInstanced offset count instances = c'rlDrawVertexArrayInstanced (fromIntegral offset) (fromIntegral count) (fromIntegral instances) + +-- | Draw vertex array elements instanced +rlDrawVertexArrayElementsInstanced :: Int -> [Int] -> Int -> IO () +rlDrawVertexArrayElementsInstanced offset buffer instances = + withFreeableArray + (map fromIntegral buffer :: [CUShort]) + ( \p -> + c'rlDrawVertexArrayElementsInstanced (fromIntegral offset) (fromIntegral $ length buffer) (castPtr p) (fromIntegral instances) + ) + +-- | Load texture in GPU +rlLoadTexture :: [Int] -> Int -> Int -> RLPixelFormat -> Int -> IO Integer +rlLoadTexture tData width height format mipmapCount = + fromIntegral + <$> withFreeableArray + (map fromIntegral tData :: [CUShort]) + (\p -> c'rlLoadTexture (castPtr p) (fromIntegral width) (fromIntegral height) (fromIntegral $ fromEnum format) (fromIntegral mipmapCount)) + +-- | Load depth texture/renderbuffer (to be attached to fbo) +rlLoadTextureDepth :: Int -> Int -> Bool -> IO Integer +rlLoadTextureDepth width height useRenderBuffer = fromIntegral <$> c'rlLoadTextureDepth (fromIntegral width) (fromIntegral height) (fromBool useRenderBuffer) + +-- | Load texture cubemap +rlLoadTextureCubemap :: [Int] -> RLPixelFormat -> IO Integer +rlLoadTextureCubemap tData format = + fromIntegral + <$> withFreeableArrayLen (map fromIntegral tData :: [CUShort]) (\l p -> c'rlLoadTextureCubemap (castPtr p) (fromIntegral $ l * sizeOf (0 :: CUShort)) (fromIntegral $ fromEnum format)) + +-- | Update GPU texture with new data +rlUpdateTexture :: (Freeable a, Storable a) => Integer -> Int -> Int -> Int -> Int -> RLPixelFormat -> [a] -> IO () +rlUpdateTexture tId offsetX offsetY width height format tData = + withFreeableArray tData (c'rlUpdateTexture (fromIntegral tId) (fromIntegral offsetX) (fromIntegral offsetY) (fromIntegral width) (fromIntegral height) (fromIntegral $ fromEnum format) . castPtr) + +-- | Get OpenGL internal formats +rlGetGlTextureFormats :: + RLPixelFormat -> + -- | Return type as tuple: (glInternalFormat, glFormat, glType) + IO (Integer, Integer, Integer) +rlGetGlTextureFormats format = + withFreeable + (0 :: CUInt) + ( \gif -> + withFreeable + (0 :: CUInt) + ( \gf -> + withFreeable + (0 :: CUInt) + ( \gt -> do + c'rlGetGlTextureFormats (fromIntegral $ fromEnum format) gif gf gt + glInternalFormat <- fromIntegral <$> peek gif + glFormat <- fromIntegral <$> peek gf + glType <- fromIntegral <$> peek gt + return (glInternalFormat, glFormat, glType) + ) + ) + ) + +-- | Get name string for pixel format +rlGetPixelFormatName :: RLPixelFormat -> String +rlGetPixelFormatName format = + case format of + RLPixelFormatUncompressedGrayscale -> "GRAYSCALE" + RLPixelFormatUncompressedGrayAlpha -> "GRAY_ALPHA" + RLPixelFormatUncompressedR5G6B5 -> "R5G6B5" + RLPixelFormatUncompressedR8G8B8 -> "R8G8B8" + RLPixelFormatUncompressedR5G5B5A1 -> "R5G5B5A1" + RLPixelFormatUncompressedR4G4B4A4 -> "R4G4B4A4" + RLPixelFormatUncompressedR8G8B8A8 -> "R8G8B8A8" + RLPixelFormatUncompressedR32 -> "R32" + RLPixelFormatUncompressedR32G32B32 -> "R32G32B32" + RLPixelFormatUncompressedR32G32B32A32 -> "R32G32B32A32" + RLPixelFormatCompressedDxt1Rgb -> "DXT1_RGB" + RLPixelFormatCompressedDxt1Rgba -> "DXT1_RGBA" + RLPixelFormatCompressedDxt3Rgba -> "DXT3_RGBA" + RLPixelFormatCompressedDxt5Rgba -> "DXT5_RGBA" + RLPixelFormatCompressedEtc1Rgb -> "ETC1_RGB" + RLPixelFormatCompressedEtc2Rgb -> "ETC2_RGB" + RLPixelFormatCompressedEtc2EacRgba -> "ETC2_RGBA" + RLPixelFormatCompressedPvrtRgb -> "PVRT_RGB" + RLPixelFormatCompressedPvrtRgba -> "PVRT_RGBA" + RLPixelFormatCompressedAstc4x4Rgba -> "ASTC_4x4_RGBA" + RLPixelFormatCompressedAstc8x8Rgba -> "ASTC_8x8_RGBA" + +-- | Unload texture from GPU memory +rlUnloadTexture :: Integer -> IO () +rlUnloadTexture tId = c'rlUnloadTexture (fromIntegral tId) + +-- | Generate mipmap data for selected texture +rlGenTextureMipmaps :: + Integer -> + Int -> + Int -> + RLPixelFormat -> + -- | The number of mipmaps generated + IO Int +rlGenTextureMipmaps tId width height format = + fromIntegral <$> withFreeable (0 :: CInt) (\p -> c'rlGenTextureMipmaps (fromIntegral tId) (fromIntegral width) (fromIntegral height) (fromIntegral $ fromEnum format) p >> peek p) + +-- | Read texture pixel data +rlReadTexturePixels :: Integer -> Int -> Int -> RLPixelFormat -> IO [Word8] +rlReadTexturePixels tId width height format = do + ptr <- c'rlReadTexturePixels (fromIntegral tId) (fromIntegral width) (fromIntegral height) (fromIntegral $ fromEnum format) + size <- fromIntegral <$> c'rlGetPixelDataSize (fromIntegral width) (fromIntegral height) (fromIntegral $ fromEnum format) + map fromIntegral <$> popCArray size (castPtr ptr :: Ptr CUChar) + +-- | Read screen pixel data (color buffer) +rlReadScreenPixels :: Int -> Int -> IO [Word8] +rlReadScreenPixels width height = + map fromIntegral <$> (c'rlReadScreenPixels (fromIntegral width) (fromIntegral height) >>= popCArray (width * height * 4)) + +-- | Load an empty framebuffer +rlLoadFramebuffer :: Int -> Int -> IO Integer +rlLoadFramebuffer width height = fromIntegral <$> c'rlLoadFramebuffer (fromIntegral width) (fromIntegral height) + +-- | Attach texture/renderbuffer to a framebuffer +rlFramebufferAttach :: Integer -> Integer -> RLFramebufferAttachType -> RLFramebufferAttachTextureType -> Int -> IO () +rlFramebufferAttach fboId texId attachType texType mipLevel = + c'rlFramebufferAttach (fromIntegral fboId) (fromIntegral texId) (fromIntegral $ fromEnum attachType) (fromIntegral $ fromEnum texType) (fromIntegral mipLevel) + +-- | Verify framebuffer is complete +rlFramebufferComplete :: Integer -> IO Bool +rlFramebufferComplete fboId = toBool <$> c'rlFramebufferComplete (fromIntegral fboId) + +-- | Delete framebuffer from GPU +rlUnloadFramebuffer :: Integer -> IO () +rlUnloadFramebuffer fboId = c'rlUnloadFramebuffer (fromIntegral fboId) + +-- | Load shader from code strings +rlLoadShaderCode :: String -> String -> IO Integer +rlLoadShaderCode vsCode fsCode = + fromIntegral <$> withCString vsCode (withCString fsCode . c'rlLoadShaderCode) + +-- | Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER) +rlCompileShader :: String -> GLShaderType -> IO Integer +rlCompileShader shaderCode shaderType = + fromIntegral <$> withCString shaderCode (\s -> c'rlCompileShader s (fromIntegral $ fromEnum shaderType)) + +-- | Load custom shader program +rlLoadShaderProgram :: Integer -> Integer -> IO Integer +rlLoadShaderProgram vsShaderId fsShaderId = + fromIntegral <$> c'rlLoadShaderProgram (fromIntegral vsShaderId) (fromIntegral fsShaderId) + +-- | Unload shader program +rlUnloadShaderProgram :: Integer -> IO () +rlUnloadShaderProgram shaderId = c'rlUnloadShaderProgram (fromIntegral shaderId) + +-- | Get shader location uniform +rlGetLocationUniform :: Integer -> String -> IO Int +rlGetLocationUniform shaderId uniformName = + fromIntegral <$> withCString uniformName (c'rlGetLocationUniform (fromIntegral shaderId)) + +-- | Get shader location attribute +rlGetLocationAttrib :: Integer -> String -> IO Int +rlGetLocationAttrib shaderId attribName = + fromIntegral <$> withCString attribName (c'rlGetLocationAttrib (fromIntegral shaderId)) + +-- | Set shader value uniform +rlSetUniform :: Int -> ShaderUniformDataV -> IO () +rlSetUniform locIndex value = do + (dataType, ptr, count) <- unpackShaderUniformDataV value + c'rlSetUniform (fromIntegral locIndex) ptr (fromIntegral $ fromEnum dataType) (fromIntegral count) + +-- | Set shader value matrix +rlSetUniformMatrix :: Int -> Matrix -> IO () +rlSetUniformMatrix locIndex mat = withFreeable mat (c'rlSetUniformMatrix (fromIntegral locIndex)) + +-- | Set shader value sampler +rlSetUniformSampler :: Int -> Integer -> IO () +rlSetUniformSampler locIndex textureId = c'rlSetUniformSampler (fromIntegral locIndex) (fromIntegral textureId) + +-- | Set shader currently active (id and locations) +rlSetShader :: Integer -> [Int] -> IO () +rlSetShader shaderId locs = withFreeableArray (map fromIntegral locs :: [CInt]) (c'rlSetShader (fromIntegral shaderId)) + +-- | Load compute shader program +rlLoadComputeShaderProgram :: Integer -> IO Integer +rlLoadComputeShaderProgram shaderId = fromIntegral <$> c'rlLoadComputeShaderProgram (fromIntegral shaderId) + +-- | Dispatch compute shader (equivalent to *draw* for graphics pipeline) +rlComputeShaderDispatch :: Integer -> Integer -> Integer -> IO () +rlComputeShaderDispatch groupX groupY groupZ = + c'rlComputeShaderDispatch (fromIntegral groupX) (fromIntegral groupY) (fromIntegral groupZ) + +-- | Load shader storage buffer object (SSBO). +-- WARNING: Fails if list is empty +rlLoadShaderBuffer :: (Freeable a, Storable a) => Integer -> [a] -> RLBufferHint -> IO Integer +rlLoadShaderBuffer size bufferData hint = + fromIntegral <$> withFreeableArray bufferData (\p -> c'rlLoadShaderBuffer (fromIntegral size) (castPtr p) (fromIntegral $ fromEnum hint)) + +-- | Unload shader storage buffer object (SSBO) +rlUnloadShaderBuffer :: Integer -> IO () +rlUnloadShaderBuffer ssboId = c'rlUnloadShaderBuffer (fromIntegral ssboId) + +-- | Update SSBO buffer data +rlUpdateShaderBuffer :: (Freeable a, Storable a) => Integer -> a -> Integer -> IO () +rlUpdateShaderBuffer ssboId sbData offset = + withFreeable sbData (\p -> c'rlUpdateShaderBuffer (fromIntegral ssboId) (castPtr p) (fromIntegral $ sizeOf sbData) (fromIntegral offset)) + +-- | Bind SSBO buffer +rlBindShaderBuffer :: Integer -> Integer -> IO () +rlBindShaderBuffer ssboId index = c'rlBindShaderBuffer (fromIntegral ssboId) (fromIntegral index) + +-- Read SSBO buffer data (GPU->CPU) +-- Skipped because I'm not sure how to bind this correctly +-- rlReadShaderBuffer :: Integer -> Integer -> Integer -> IO (Ptr ()) +-- rlReadShaderBuffer ssboId count offset = undefined + +-- | Copy SSBO data between buffers +rlCopyShaderBuffer :: Integer -> Integer -> Integer -> Integer -> Integer -> IO () +rlCopyShaderBuffer destId srcId destOffset srcOffset count = c'rlCopyShaderBuffer (fromIntegral destId) (fromIntegral srcId) (fromIntegral destOffset) (fromIntegral srcOffset) (fromIntegral count) + +-- | Get SSBO buffer size +rlGetShaderBufferSize :: Integer -> IO Integer +rlGetShaderBufferSize ssboId = fromIntegral <$> c'rlGetShaderBufferSize (fromIntegral ssboId) + +-- | Bind image texture +rlBindImageTexture :: Integer -> Integer -> RLPixelFormat -> Bool -> IO () +rlBindImageTexture tId index format readonly = c'rlBindImageTexture (fromIntegral tId) (fromIntegral index) (fromIntegral $ fromEnum format) (fromBool readonly) + +-- | Get internal modelview matrix +rlGetMatrixModelview :: IO Matrix +rlGetMatrixModelview = c'rlGetMatrixModelview >>= pop + +-- | Get internal projection matrix +rlGetMatrixProjection :: IO Matrix +rlGetMatrixProjection = c'rlGetMatrixProjection >>= pop + +-- | Get internal accumulated transform matrix +rlGetMatrixTransform :: IO Matrix +rlGetMatrixTransform = c'rlGetMatrixTransform >>= pop + +-- | Get internal projection matrix for stereo render (selected eye) +rlGetMatrixProjectionStereo :: Int -> IO Matrix +rlGetMatrixProjectionStereo eye = c'rlGetMatrixProjectionStereo (fromIntegral eye) >>= pop + +-- | Get internal view offset matrix for stereo render (selected eye) +rlGetMatrixViewOffsetStereo :: Int -> IO Matrix +rlGetMatrixViewOffsetStereo eye = c'rlGetMatrixViewOffsetStereo (fromIntegral eye) >>= pop + +-- | Set a custom projection matrix (replaces internal projection matrix) +rlSetMatrixProjection :: Matrix -> IO () +rlSetMatrixProjection matrix = withFreeable matrix c'rlSetMatrixProjection + +-- | Set a custom modelview matrix (replaces internal modelview matrix) +rlSetMatrixModelview :: Matrix -> IO () +rlSetMatrixModelview matrix = withFreeable matrix c'rlSetMatrixModelview + +-- | Set eyes projection matrices for stereo rendering +rlSetMatrixProjectionStereo :: Matrix -> Matrix -> IO () +rlSetMatrixProjectionStereo right left = withFreeable right (withFreeable left . c'rlSetMatrixProjectionStereo) + +-- | Set eyes view offsets matrices for stereo rendering +rlSetMatrixViewOffsetStereo :: Matrix -> Matrix -> IO () +rlSetMatrixViewOffsetStereo right left = withFreeable right (withFreeable left . c'rlSetMatrixViewOffsetStereo) + +-- | Load and draw a cube +foreign import ccall safe "rlgl.h rlLoadDrawCube" rlLoadDrawCube :: IO () + +-- | Load and draw a quad +foreign import ccall safe "rlgl.h rlLoadDrawQuad" rlLoadDrawQuad :: IO ()