module Shader.Bind ( bufferShaderLayers, bufferPokedVBO, bufferEBO, ) where import Control.Lens import Control.Monad.Primitive import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Unboxed.Mutable as UMV import Foreign hiding (rotate) --import Control.Monad import Graphics.GL.Core45 import Shader.Data import Shader.Parameters bufferPokedVBO :: VBO -> Int -> IO () {-# INLINEABLE bufferPokedVBO #-} bufferPokedVBO theVBO numVs = glNamedBufferSubData (_vboName theVBO) 0 (fromIntegral $ numVs * _vboVertexBytes theVBO) (_vboPtr theVBO) bufferEBO :: EBO -> Int -> IO () bufferEBO ebo numis = glNamedBufferSubData (ebo ^. eboName) 0 (fromIntegral $ glushortSize * numis) (ebo ^. eboPtr) bufferShaderLayers :: MV.MVector (PrimState IO) (Shader, VBO) -> UMV.MVector (PrimState IO) Int -> IO () bufferShaderLayers shads counts = MV.imapM_ f shads where f i shad = do let theVBO = snd shad stride = _vboVertexBytes theVBO `div` floatSize VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5] where g stride theVBO lay = do numVs <- UMV.unsafeRead counts $ lay * 6 + i glNamedBufferSubDataH (_vboName theVBO) (fromIntegral $ floatSize * stride * numSubElements * lay) (fromIntegral $ floatSize * numVs * stride) (_vboPtr theVBO `plusPtr` (floatSize * stride * numSubElements * lay)) glNamedBufferSubDataH :: GLuint -> GLintptr -> GLsizeiptr -> Ptr a -> IO () glNamedBufferSubDataH = glNamedBufferSubData