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