module Graphics.Rendering.OpenGL.GL.Shaders.ShaderBinaries (
ShaderBinaryFormat(..), shaderBinaryFormats,
ShaderBinary(..), shaderBinary,
) where
import Data.StateVar
import Foreign.Marshal.Array
import Graphics.Rendering.OpenGL.GL.ByteString
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.Rendering.OpenGL.GL.Shaders.Shader
import Graphics.GL
newtype ShaderBinaryFormat = ShaderBinaryFormat GLenum
deriving ( Eq, Ord, Show )
shaderBinaryFormats :: GettableStateVar [ShaderBinaryFormat]
shaderBinaryFormats =
makeGettableStateVar $ do
n <- getInteger1 fromIntegral GetNumShaderBinaryFormats
getEnumN ShaderBinaryFormat GetShaderBinaryFormats n
data ShaderBinary = ShaderBinary ShaderBinaryFormat ByteString
deriving ( Eq, Ord, Show )
shaderBinary :: [Shader] -> SettableStateVar ShaderBinary
shaderBinary shaders =
makeSettableStateVar $ \(ShaderBinary (ShaderBinaryFormat format) bs) ->
withArrayLen (map shaderID shaders) $ \numShaders shadersBuf ->
withByteString bs $
glShaderBinary (fromIntegral numShaders) shadersBuf format