Map an "isometric" matrix to a static buffer

This commit is contained in:
2023-03-09 23:29:58 +00:00
parent d72033c562
commit b1750ad028
6 changed files with 14 additions and 13 deletions
+1
View File
@@ -49,6 +49,7 @@ data RenderData = RenderData
, _fboShadow :: (FBO, (TO, TO)) , _fboShadow :: (FBO, (TO, TO))
, _rboBaseBloom :: GLuint -- RenderbufferObject id , _rboBaseBloom :: GLuint -- RenderbufferObject id
, _matUBO :: GLuint -- BufferObject id , _matUBO :: GLuint -- BufferObject id
, _isoMatUBO :: GLuint -- BufferObject id
} }
makeLenses ''RenderData makeLenses ''RenderData
+3 -1
View File
@@ -94,6 +94,7 @@ doDrawing win pdata u = do
(fromIntegral $ glushortSize * nSilIndices) (fromIntegral $ glushortSize * nSilIndices)
(_eboPtr $ _silhouetteEBO pdata) (_eboPtr $ _silhouetteEBO pdata)
-- set the coordinate uniform ready for drawing elements using world coordinates -- set the coordinate uniform ready for drawing elements using world coordinates
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
bufferUBO (pdata ^. matUBO) $ perspectiveMatrixb rot camzoom trans wins viewFroms bufferUBO (pdata ^. matUBO) $ perspectiveMatrixb rot camzoom trans wins viewFroms
setViewportSize (round winx `div` resFact) (round winy `div` resFact) setViewportSize (round winx `div` resFact) (round winy `div` resFact)
--bindFramebuffer Framebuffer $= fst (_fboBase pdata) --bindFramebuffer Framebuffer $= fst (_fboBase pdata)
@@ -286,7 +287,8 @@ doDrawing win pdata u = do
glDepthMask GL_FALSE glDepthMask GL_FALSE
glEnable GL_BLEND glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
bufferUBO (pdata ^. matUBO) $ isoMatrix 0 1 (V2 0 0) (V2 2 2) --bufferUBO (pdata ^. matUBO) $ isoMatrix 0 1 (V2 0 0) (V2 2 2)
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. isoMatUBO)
renderLayer FixedCoordLayer shadV layerCounts renderLayer FixedCoordLayer shadV layerCounts
renderFoldable shadV $ fixedCoordPictures u renderFoldable shadV $ fixedCoordPictures u
glDepthMask GL_TRUE glDepthMask GL_TRUE
+10 -1
View File
@@ -5,6 +5,8 @@ module Preload.Render (
cleanUpRenderPreload, cleanUpRenderPreload,
) where ) where
import Geometry.Data
import MatrixHelper
import GLHelp import GLHelp
import Control.Lens import Control.Lens
import Control.Monad import Control.Monad
@@ -29,6 +31,12 @@ preloadRender = do
theUBO <- mglCreate glCreateBuffers theUBO <- mglCreate glCreateBuffers
glNamedBufferData theUBO 64 nullPtr GL_STREAM_DRAW glNamedBufferData theUBO 64 nullPtr GL_STREAM_DRAW
glBindBufferBase GL_UNIFORM_BUFFER 0 theUBO glBindBufferBase GL_UNIFORM_BUFFER 0 theUBO
isoUBO <- mglCreate glCreateBuffers
withArray (isoMatrix 0 1 (V2 0 0) (V2 2 2)) $ \ptr ->
glNamedBufferStorage isoUBO 64 ptr 0
glBindBufferBase GL_UNIFORM_BUFFER 1 theUBO
-- setup wall points VBO, VAOs and shaders -- setup wall points VBO, VAOs and shaders
wpVBOname <- mglCreate glCreateBuffers wpVBOname <- mglCreate glCreateBuffers
wpVBOptr <- mallocArray (8 * numDrawableWalls) wpVBOptr <- mallocArray (8 * numDrawableWalls)
@@ -170,7 +178,7 @@ preloadRender = do
>>= addTextureArray "data/texture/ayene_wooden_floor_transformed.png" >>= addTextureArray "data/texture/ayene_wooden_floor_transformed.png"
-- >>= addTextureArray "data/texture/ayene_wooden_floor.png" -- >>= addTextureArray "data/texture/ayene_wooden_floor.png"
-- bind fixed vertex data -- bind fixed vertex data
bindShaderBuffers' [fsShad] [4, 4] bindShaderBuffers [fsShad] [4, 4]
framebuf2 <- setupTextureFramebuffer 800 600 framebuf2 <- setupTextureFramebuffer 800 600
framebuf3 <- setupTextureFramebuffer 800 600 framebuf3 <- setupTextureFramebuffer 800 600
@@ -248,6 +256,7 @@ preloadRender = do
, _fboPos = fboPosName , _fboPos = fboPosName
, _rboBaseBloom = rboBaseBloomName , _rboBaseBloom = rboBaseBloomName
, _matUBO = theUBO , _matUBO = theUBO
, _isoMatUBO = isoUBO
} }
--------------------end preloadRender --------------------end preloadRender
-1
View File
@@ -30,7 +30,6 @@ import Shader.ExtraPrimitive
createLightMap :: createLightMap ::
RenderData -> RenderData ->
[(Point3, Float, Point3)] -> -- Lights [(Point3, Float, Point3)] -> -- Lights
-- | number of walls -- | number of walls
Int -> Int ->
-- | number of silhoutte lines to draw -- | number of silhoutte lines to draw
-9
View File
@@ -1,7 +1,6 @@
module Shader.Bind module Shader.Bind
( bindShaderLayers ( bindShaderLayers
, bindShaderBuffers , bindShaderBuffers
, bindShaderBuffers'
, bindShader , bindShader
) where ) where
import Shader.Data import Shader.Data
@@ -29,10 +28,7 @@ bindShaderLayers shads counts = MV.imapM_ f shads
f i shad = do f i shad = do
let theVBO = _vaoVBO $ _shadVAO' shad let theVBO = _vaoVBO $ _shadVAO' shad
stride = sum $ _vboAttribSizes theVBO stride = sum $ _vboAttribSizes theVBO
glBindBuffer GL_ARRAY_BUFFER (_vboName theVBO)
VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5] VFSM.mapM_ (g stride theVBO) $ VFSM.enumFromStepN 0 1 6 -- [0..5]
--S.mapM_ (g stride theVBO) $ S.each [0..5]
where where
g stride theVBO lay = do g stride theVBO lay = do
numVs <- UMV.unsafeRead counts $ lay * 6 + i numVs <- UMV.unsafeRead counts $ lay * 6 + i
@@ -54,8 +50,3 @@ bindShaderBuffers :: [FullShader] -> [Int] -> IO ()
bindShaderBuffers = zipWithM_ f bindShaderBuffers = zipWithM_ f
where where
f fs i = bindArrayBuffers i $ _vaoVBO $ _shadVAO' fs f fs i = bindArrayBuffers i $ _vaoVBO $ _shadVAO' fs
bindShaderBuffers' :: [FullShader] -> [Int] -> IO ()
bindShaderBuffers' = zipWithM_ f
where
f fs i = bindArrayBuffers i $ _vaoVBO $ _shadVAO' fs
-1
View File
@@ -143,7 +143,6 @@ setupVBOSized ndraw vao sizes = do
--vboName <- genObjectName --vboName <- genObjectName
--bindBuffer ArrayBuffer $= Just vboName --bindBuffer ArrayBuffer $= Just vboName
vboname <- mglCreate glCreateBuffers vboname <- mglCreate glCreateBuffers
glBindBuffer GL_ARRAY_BUFFER vboname
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
setupVertexAttribPointer vao vboname loc siz strd off setupVertexAttribPointer vao vboname loc siz strd off
thePtr <- mallocArray (strd * ndraw) thePtr <- mallocArray (strd * ndraw)