Implement static VBO/VAO
This commit is contained in:
@@ -124,14 +124,15 @@ preloadRender = do
|
|||||||
--initTexture2DArray 50 "data/texture/charMapVertBig.png" 2 32 64 95 GL_LINEAR_MIPMAP_NEAREST GL_LINEAR
|
--initTexture2DArray 50 "data/texture/charMapVertBig.png" 2 32 64 95 GL_LINEAR_MIPMAP_NEAREST GL_LINEAR
|
||||||
|
|
||||||
putStrLn "Setup full screen shaders"
|
putStrLn "Setup full screen shaders"
|
||||||
screentexturevbo <- mglCreate glCreateBuffers
|
-- screentexturevbo <- mglCreate glCreateBuffers
|
||||||
withArray (concat cornerList) $ \ptr ->
|
-- withArray (concat cornerList) $ \ptr ->
|
||||||
glNamedBufferStorage
|
-- glNamedBufferStorage
|
||||||
screentexturevbo
|
-- screentexturevbo
|
||||||
(fromIntegral $ floatSize * length (concat cornerList))
|
-- (fromIntegral $ floatSize * length (concat cornerList))
|
||||||
ptr
|
-- ptr
|
||||||
0
|
-- 0
|
||||||
screentexturevao <- setupVAOvbo (toFloatVAs [2, 2]) 4 screentexturevbo
|
-- screentexturevao <- setupVAOvbo (toFloatVAs [2, 2]) 4 screentexturevbo
|
||||||
|
(_,screentexturevao) <- setupStaticVBO (toFloatVAs [2,2]) (concat cornerList)
|
||||||
alphadivideshader <- makeShaderUsingVAO "texture2D/alphaDivide" [vert, frag] pmTriangleStrip screentexturevao
|
alphadivideshader <- makeShaderUsingVAO "texture2D/alphaDivide" [vert, frag] pmTriangleStrip screentexturevao
|
||||||
fsShad <- makeShaderUsingVAO "texture/simple" [vert, frag] pmTriangleStrip screentexturevao
|
fsShad <- makeShaderUsingVAO "texture/simple" [vert, frag] pmTriangleStrip screentexturevao
|
||||||
bloomBlurShad <- makeShaderUsingVAO "texture/bloomBlur" [vert, frag] pmTriangleStrip screentexturevao
|
bloomBlurShad <- makeShaderUsingVAO "texture/bloomBlur" [vert, frag] pmTriangleStrip screentexturevao
|
||||||
|
|||||||
+20
-15
@@ -13,8 +13,10 @@ module Shader.Compile (
|
|||||||
setupVertexAttribPointer,
|
setupVertexAttribPointer,
|
||||||
makeSourcedShader,
|
makeSourcedShader,
|
||||||
toFloatVAs,
|
toFloatVAs,
|
||||||
|
setupStaticVBO
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Foreign.C.Types
|
||||||
import Graphics.GL.Types
|
import Graphics.GL.Types
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
@@ -99,21 +101,24 @@ setupVBO vertexsize = do
|
|||||||
GL_STREAM_DRAW
|
GL_STREAM_DRAW
|
||||||
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexBytes = floatSize * vertexsize}
|
return VBO{_vboName = vboname, _vboPtr = thePtr, _vboVertexBytes = floatSize * vertexsize}
|
||||||
|
|
||||||
---- the input ptr is assumed to contain the correct amount of data according to
|
-- the input ptr is assumed to contain the correct amount of data according to
|
||||||
---- the specified number and type of vertices
|
-- the specified number and type of vertices
|
||||||
---- note the VBO here does not have a sensible ptr value
|
-- note the VBO here does not have a sensible ptr value
|
||||||
--setupStaticVBO :: Int -> [VertexAttribute] -> Ptr a -> IO (VBO,VAO)
|
setupStaticVBO :: Storable a => [VertexAttribute] -> [a] -> IO (VBO,VAO)
|
||||||
--setupStaticVBO numvs vas vdata = do
|
setupStaticVBO vas vdata = withArrayLen vdata $ \i ptr -> do
|
||||||
-- vboname <- mglCreate glCreateBuffers
|
vboname <- mglCreate glCreateBuffers
|
||||||
-- glNamedBufferStorage
|
glNamedBufferStorage
|
||||||
-- vboname
|
vboname
|
||||||
-- (CPtrdiff (fromIntegral (vasTightStride vas)))
|
(CPtrdiff (fromIntegral (i * sizeOf (head vdata))))
|
||||||
-- vdata
|
ptr
|
||||||
-- 0
|
0
|
||||||
-- let vbo = VBO
|
let vbo = VBO
|
||||||
-- { _vboName = vboname
|
{ _vboName = vboname
|
||||||
-- , _vboPtr = nullPtr
|
, _vboPtr = nullPtr
|
||||||
-- , _vboVertexSize =
|
, _vboVertexBytes = vasTightStride vas
|
||||||
|
}
|
||||||
|
vao <- setupVAOUsingVBO vas vbo
|
||||||
|
return (vbo,vao)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user