Try to centralize the number of components per vertex in shapes

This commit is contained in:
2023-03-14 23:28:21 +00:00
parent cfddd1515f
commit 21f87b96d8
7 changed files with 27 additions and 32 deletions
+1 -1
View File
@@ -54,7 +54,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 , _orthonormalMatUBO :: GLuint -- BufferObject id
, _lightsUBO :: GLuint -- BufferObject id , _lightsUBO :: GLuint -- BufferObject id
, _vboWalls :: VBO , _vboWalls :: VBO
, _vboWindows :: VBO , _vboWindows :: VBO
+3 -7
View File
@@ -116,8 +116,6 @@ doDrawing' win pdata u = do
glClear $ sum [GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT] glClear $ sum [GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT]
glDepthFunc GL_LESS glDepthFunc GL_LESS
-- draw wall occlusions from the camera's point of view -- draw wall occlusions from the camera's point of view
-- glEnable GL_CULL_FACE
-- glCullFace GL_BACK
glUseProgram (pdata ^. lightingWallShadShader . shadName) glUseProgram (pdata ^. lightingWallShadShader . shadName)
glUniform3f (pdata ^?! lightingWallShadShader . shadUnis' . ix 0) vfx vfy 20 glUniform3f (pdata ^?! lightingWallShadShader . shadUnis' . ix 0) vfx vfy 20
glUniform1f (pdata ^?! lightingWallShadShader . shadUnis' . ix 1) 100 glUniform1f (pdata ^?! lightingWallShadShader . shadUnis' . ix 1) 100
@@ -139,7 +137,7 @@ doDrawing' win pdata u = do
glUseProgram (_shadName fs) glUseProgram (_shadName fs)
glBindVertexArray $ fs ^. shadVAO . vaoName glBindVertexArray $ fs ^. shadVAO . vaoName
glDrawElements glDrawElements
(marshalEPrimitiveMode $ _shadPrim' $ fs) (marshalEPrimitiveMode $ _shadPrim' fs)
(fromIntegral nIndices) (fromIntegral nIndices)
GL_UNSIGNED_SHORT GL_UNSIGNED_SHORT
nullPtr nullPtr
@@ -193,9 +191,6 @@ doDrawing' win pdata u = do
glDepthFunc GL_LEQUAL glDepthFunc GL_LEQUAL
glDepthMask GL_FALSE glDepthMask GL_FALSE
glClearColor 0.5 0.5 0.5 0 glClearColor 0.5 0.5 0.5 0
--glBlendFunc GL_SRC_ALPHASaturate,One)
--blendColor $= Color4 0.5 0.5 0.5 0.5
--glBlendFuncSeparate GL_SRC_ALPHASaturate,One) , (One,GL_ONE_MINUS_SRC_ALPHA))
glBlendFuncSeparate GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE GL_ONE_MINUS_SRC_ALPHA glBlendFuncSeparate GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE GL_ONE_MINUS_SRC_ALPHA
withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr
glClear GL_COLOR_BUFFER_BIT glClear GL_COLOR_BUFFER_BIT
@@ -224,6 +219,7 @@ doDrawing' win pdata u = do
(drawCPUShadows pdata ws) (drawCPUShadows pdata ws)
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
glClearColor 0 0 0 0 glClearColor 0 0 0 0
glInvalidateBufferData (pdata ^. vboShapes . vboName)
--apply lightmap to cloud buffer --apply lightmap to cloud buffer
glClearColor 0 0 0 0 glClearColor 0 0 0 0
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata))) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
@@ -279,7 +275,7 @@ 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
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. isoMatUBO) glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. orthonormalMatUBO)
renderLayer FixedCoordLayer shadV layerCounts renderLayer FixedCoordLayer shadV layerCounts
renderFoldable shadV $ fixedCoordPictures u renderFoldable shadV $ fixedCoordPictures u
glDepthMask GL_TRUE glDepthMask GL_TRUE
+13 -11
View File
@@ -5,6 +5,7 @@ module Preload.Render (
cleanUpRenderPreload, cleanUpRenderPreload,
) where ) where
import Shape.Data
import Geometry.Data import Geometry.Data
import MatrixHelper import MatrixHelper
import GLHelp import GLHelp
@@ -32,9 +33,9 @@ preloadRender = do
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 orthonormalUBO <- mglCreate glCreateBuffers
withArray (isoMatrix 0 1 (V2 0 0) (V2 2 2)) $ \ptr -> withArray (isoMatrix 0 1 (V2 0 0) (V2 2 2)) $ \ptr ->
glNamedBufferStorage isoUBO 64 ptr 0 glNamedBufferStorage orthonormalUBO 64 ptr 0
lightsubo <- mglCreate glCreateBuffers lightsubo <- mglCreate glCreateBuffers
glNamedBufferData lightsubo 640 nullPtr GL_STREAM_DRAW glNamedBufferData lightsubo 640 nullPtr GL_STREAM_DRAW
@@ -61,8 +62,8 @@ preloadRender = do
glVertexArrayVertexBuffer wpColVAOname 0 wpVBOname 0 (fromIntegral $ floatSize * 8) glVertexArrayVertexBuffer wpColVAOname 0 wpVBOname 0 (fromIntegral $ floatSize * 8)
setupVertexAttribPointer wpColVAOname 0 4 0 setupVertexAttribPointer wpColVAOname 0 4 0
setupVertexAttribPointer wpColVAOname 1 4 4 setupVertexAttribPointer wpColVAOname 1 4 4
let wpVAO = VAO{_vaoName = wpVAOname, _vaoAttribSizes = [4], _vaoStride = 8} let wpVAO = VAO{_vaoName = wpVAOname}
wpColVAO = VAO{_vaoName = wpColVAOname, _vaoAttribSizes = [4,4], _vaoStride = 8} wpColVAO = VAO{_vaoName = wpColVAOname}
-- setup window points VBO, VAOs and shaders -- setup window points VBO, VAOs and shaders
winVBOname <- mglCreate glCreateBuffers winVBOname <- mglCreate glCreateBuffers
winVBOptr <- mallocArray (8 * numDrawableWalls) winVBOptr <- mallocArray (8 * numDrawableWalls)
@@ -79,7 +80,7 @@ preloadRender = do
setupVertexAttribPointer winColVAOname 0 4 0 setupVertexAttribPointer winColVAOname 0 4 0
setupVertexAttribPointer winColVAOname 1 4 4 setupVertexAttribPointer winColVAOname 1 4 4
let winColVAO = VAO let winColVAO = VAO
{_vaoName = winColVAOname, _vaoAttribSizes = [4,4], _vaoStride = 8} {_vaoName = winColVAOname}
-- setup shape geometry/cap VBO and two VAOs -- setup shape geometry/cap VBO and two VAOs
shEBOptr <- mallocArray numDrawableElements shEBOptr <- mallocArray numDrawableElements
shEBOname <- mglCreate glCreateBuffers shEBOname <- mglCreate glCreateBuffers
@@ -89,17 +90,17 @@ preloadRender = do
nullPtr nullPtr
GL_STREAM_DRAW GL_STREAM_DRAW
let shEBO = EBO{_eboName = shEBOname, _eboPtr = shEBOptr} let shEBO = EBO{_eboName = shEBOname, _eboPtr = shEBOptr}
shVBO <- setupVBO4 8 shVBO <- setupVBO nShapeVerxComp
shPosVAOname <- mglCreate glCreateVertexArrays shPosVAOname <- mglCreate glCreateVertexArrays
glBindVertexArray shPosVAOname glBindVertexArray shPosVAOname
glVertexArrayVertexBuffer shPosVAOname 0 (shVBO ^. vboName) 0 (fromIntegral $ floatSize * 8) glVertexArrayVertexBuffer shPosVAOname 0 (shVBO ^. vboName) 0 (fromIntegral $ floatSize * nShapeVerxComp)
setupVertexAttribPointer shPosVAOname 0 4 0 setupVertexAttribPointer shPosVAOname 0 4 0
glVertexArrayElementBuffer shPosVAOname shEBOname glVertexArrayElementBuffer shPosVAOname shEBOname
let shPosVAO = VAO{_vaoName = shPosVAOname, _vaoAttribSizes = [4], _vaoStride = 8} let shPosVAO = VAO{_vaoName = shPosVAOname}
--setup silhouette edge VAO --setup silhouette edge VAO
shEdgeVAOname <- mglCreate glCreateVertexArrays shEdgeVAOname <- mglCreate glCreateVertexArrays
glBindVertexArray shEdgeVAOname glBindVertexArray shEdgeVAOname
glVertexArrayVertexBuffer shEdgeVAOname 0 (shVBO ^. vboName) 0 (fromIntegral $ floatSize * 8) glVertexArrayVertexBuffer shEdgeVAOname 0 (shVBO ^. vboName) 0 (fromIntegral $ floatSize * nShapeVerxComp)
setupVertexAttribPointer shEdgeVAOname 0 4 0 setupVertexAttribPointer shEdgeVAOname 0 4 0
--setup ebo for silhouette edges --setup ebo for silhouette edges
silEBOname <- mglCreate glCreateBuffers silEBOname <- mglCreate glCreateBuffers
@@ -111,7 +112,7 @@ preloadRender = do
nullPtr nullPtr
GL_STREAM_DRAW GL_STREAM_DRAW
let silEBO = EBO{_eboName = silEBOname, _eboPtr = silEBOptr} let silEBO = EBO{_eboName = silEBOname, _eboPtr = silEBOptr}
shEdgeVAO = VAO{_vaoName = shEdgeVAOname, _vaoAttribSizes = [4], _vaoStride = 8} shEdgeVAO = VAO{_vaoName = shEdgeVAOname}
-- shEdgeVAO is unecessary? -- shEdgeVAO is unecessary?
-- lighting shaders -- lighting shaders
lightingWallShadShad <- lightingWallShadShad <-
@@ -265,7 +266,7 @@ preloadRender = do
, _fboPos = fboPosName , _fboPos = fboPosName
, _rboBaseBloom = rboBaseBloomName , _rboBaseBloom = rboBaseBloomName
, _matUBO = theUBO , _matUBO = theUBO
, _isoMatUBO = isoUBO , _orthonormalMatUBO = orthonormalUBO
, _lightsUBO = lightsubo , _lightsUBO = lightsubo
, _vboWalls = wpVBO , _vboWalls = wpVBO
, _vboWindows = winVBO , _vboWindows = winVBO
@@ -294,6 +295,7 @@ initializeGLState :: IO ()
initializeGLState = do initializeGLState = do
glEnable GL_DEPTH_TEST glEnable GL_DEPTH_TEST
cleanUpRenderPreload :: RenderData -> IO () cleanUpRenderPreload :: RenderData -> IO ()
cleanUpRenderPreload _ = return () cleanUpRenderPreload _ = return ()
--cleanUpRenderPreload pd = do --cleanUpRenderPreload pd = do
+3 -7
View File
@@ -1,5 +1,5 @@
module Shader.Compile ( module Shader.Compile (
setupVBO4, setupVBO,
makeShader, makeShader,
makeShader4, makeShader4,
makeByteStringShaderUsingVAO, makeByteStringShaderUsingVAO,
@@ -67,8 +67,8 @@ makeShader4 s shaderlist sizes pm vbo = do
, _shadUnis' = mempty , _shadUnis' = mempty
} }
setupVBO4 :: Int -> IO VBO setupVBO :: Int -> IO VBO
setupVBO4 vertexsize = do setupVBO vertexsize = do
vboname <- mglCreate glCreateBuffers vboname <- mglCreate glCreateBuffers
thePtr <- mallocArray (vertexsize * numDrawableElements) thePtr <- mallocArray (vertexsize * numDrawableElements)
-- Allocate space -- Allocate space
@@ -170,8 +170,6 @@ setupVAOvbo sizes vbo = do
setupVertexAttribs vbo vaoname sizes setupVertexAttribs vbo vaoname sizes
return $ VAO return $ VAO
{ _vaoName = vaoname { _vaoName = vaoname
, _vaoAttribSizes = sizes
, _vaoStride = sum sizes
} }
setupVAOSized :: Int -> [Int] -> IO (VAO,VBO) setupVAOSized :: Int -> [Int] -> IO (VAO,VBO)
@@ -181,8 +179,6 @@ setupVAOSized ndraw sizes = do
theVBO <- setupVBOSized ndraw vaoname sizes theVBO <- setupVBOSized ndraw vaoname sizes
return ( VAO return ( VAO
{ _vaoName = vaoname { _vaoName = vaoname
, _vaoAttribSizes = sizes
, _vaoStride = sum sizes
} }
, theVBO) , theVBO)
+3 -5
View File
@@ -12,8 +12,8 @@ module Shader.Data
-- | Lens functions -- | Lens functions
, vaoName , vaoName
-- , vaoVBO -- , vaoVBO
, vaoAttribSizes -- , vaoAttribSizes
, vaoStride -- , vaoStride
, vboName , vboName
, vboPtr , vboPtr
@@ -46,10 +46,8 @@ data FullShader = FullShader
} }
{- | Vertex array object: contains the reference to the object, {- | Vertex array object: contains the reference to the object,
and its buffer targets. -} and its buffer targets. -}
data VAO = VAO newtype VAO = VAO
{ _vaoName :: GLuint { _vaoName :: GLuint
, _vaoAttribSizes :: [Int] -- ^ It is not clear to me if this is necessary to store or not
, _vaoStride :: Int
} }
{- | Vertex buffer object: contains the reference to the object, {- | Vertex buffer object: contains the reference to the object,
a pointer to a location with space that can be written to the buffer, a pointer to a location with space that can be written to the buffer,
+1 -1
View File
@@ -181,7 +181,7 @@ pokeJustV ptr nv sh = do
pokeElemOff ptr (off 7) a pokeElemOff ptr (off 7) a
return (nv + 1) return (nv + 1)
where where
off i = nv*8 + i off i = nv*nShapeVerxComp + i
V3 x y z = _svPos sh V3 x y z = _svPos sh
V4 r g b a = _svCol sh V4 r g b a = _svCol sh
+3
View File
@@ -48,6 +48,9 @@ makeLenses ''ShapeType
type Shape = [ShapeObj] type Shape = [ShapeObj]
nShapeVerxComp :: Int
nShapeVerxComp = 8
deriveJSON defaultOptions ''ShapeType deriveJSON defaultOptions ''ShapeType
deriveJSON defaultOptions ''ShapeV deriveJSON defaultOptions ''ShapeV
deriveJSON defaultOptions ''ShapeObj deriveJSON defaultOptions ''ShapeObj