First implementation of SSBO, vertex pulling

This commit is contained in:
2025-11-10 11:58:11 +00:00
parent 187751ec26
commit 5e93c7631d
7 changed files with 201 additions and 131 deletions
+4 -1
View File
@@ -18,6 +18,7 @@ data RenderData = RenderData
, _ceilingStencilShader :: Shader
, _alphaDivideShader :: Shader
, _windowShader :: Shader
, _windowPullShader :: Shader
, _fullscreenShader :: Shader
, _transparencyCompShader :: Shader
, _bloomBlurShader :: Shader
@@ -40,7 +41,8 @@ data RenderData = RenderData
, _fboLighting :: (FBO, TO)
, _rboBaseBloom :: GLuint -- RenderbufferObject id
, _matUBO :: GLuint -- BufferObject id
, _lightsUBO :: GLuint -- BufferObject id
, _winSSBO :: GLuint
-- , _lightsUBO :: GLuint -- BufferObject id
, _vboWindows :: VBO
, _vboShapes :: VBO
, _floorVBO :: VBO
@@ -53,6 +55,7 @@ data RenderData = RenderData
, _cloudShader :: Shader
, _cloudEBO :: EBO
, _screenTextureVAO :: VAO
, _dummyVAO :: VAO
}
makeLenses ''RenderData
+9 -1
View File
@@ -110,6 +110,9 @@ doDrawing' win pdata u = do
]
-- set the coordinate uniform ready for drawing elements using world coordinates
bufferPerspectiveMatrixUBO cfig (w ^. wCam) (pdata ^. matUBO)
glNamedBufferSubData (pdata ^. winSSBO) 0
(fromIntegral $ nWins * sizeOf (0::Float) * 8)
(pdata ^. vboWindows . vboPtr)
setViewport _gr_world_res cfig
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
glDepthMask GL_TRUE
@@ -373,7 +376,12 @@ doDrawing' win pdata u = do
glDepthFunc GL_LEQUAL
glCullFace GL_BACK
glDisable GL_BLEND
drawShader (_windowShader pdata) nWins
glDepthFunc GL_ALWAYS
glDisable GL_CULL_FACE
glUseProgram $ pdata ^. windowPullShader . shaderUINT
glBindVertexArray $ pdata ^. dummyVAO . vaoName
glDrawArrays GL_TRIANGLES 0 (fromIntegral nWins * 6)
--drawShader (_windowShader pdata) nWins
glDisable GL_DEPTH_CLAMP
glDisable GL_CULL_FACE
glInvalidateBufferData (pdata ^. vboShapes . vboName)
+3 -6
View File
@@ -1,4 +1,4 @@
module GLHelp where
module GLHelp (mglCreate,mglDelete,checkGLError) where
import Foreign.Marshal
import Foreign.Ptr
@@ -6,13 +6,10 @@ import Foreign.Storable
import Graphics.GL.Core45
mglCreate :: (GLsizei -> Ptr GLuint -> IO ()) -> IO GLuint
mglCreate f =
alloca $ \nameptr -> do
f 1 nameptr
peek nameptr
mglCreate f = alloca $ \ptr -> f 1 ptr >> peek ptr
mglDelete :: (GLsizei -> Ptr GLuint -> IO ()) -> GLuint -> IO ()
mglDelete f i = with i $ \ptr -> f 1 ptr
mglDelete f i = with i $ f 1
checkGLError :: String -> IO ()
checkGLError s = do
+21 -5
View File
@@ -35,12 +35,25 @@ preloadRender = do
-- set up uniform buffer object
putStrLn "Setup UBO"
theUBO <- mglCreate glCreateBuffers
glNamedBufferData theUBO 64 nullPtr GL_STREAM_DRAW
--glNamedBufferData theUBO 64 nullPtr GL_STREAM_DRAW
glNamedBufferStorage theUBO 64 nullPtr GL_DYNAMIC_STORAGE_BIT
glBindBufferBase GL_UNIFORM_BUFFER 0 theUBO
lightsubo <- mglCreate glCreateBuffers
glNamedBufferData lightsubo 640 nullPtr GL_STREAM_DRAW
glBindBufferBase GL_UNIFORM_BUFFER 1 lightsubo
winssbo <- mglCreate glCreateBuffers
let winssbosize = sizeOf (0::Float) * 8 * 1024
-- winssboptr <- mallocBytes winssbosize
glNamedBufferStorage winssbo (fromIntegral winssbosize) nullPtr GL_DYNAMIC_STORAGE_BIT
glBindBufferBase GL_SHADER_STORAGE_BUFFER 1 winssbo
--dummyvao <- mglCreate glCreateVertexArrays
dummyvao <- mglCreate glGenVertexArrays
winpull <- makeShaderUsingVAO "pull/window" [vert,frag] pmTriangles (VAO dummyvao)
-- lightsubo <- mglCreate glCreateBuffers
-- --glNamedBufferData lightsubo 640 nullPtr GL_STREAM_DRAW
-- glNamedBufferStorage lightsubo 640 nullPtr GL_DYNAMIC_STORAGE_BIT
-- glBindBufferBase GL_UNIFORM_BUFFER 1 lightsubo
-- setup shape geometry/cap VBO and two VAOs
putStrLn "Setup shape VBO, VAO, EBO"
@@ -181,6 +194,7 @@ preloadRender = do
, _lightingWallShadShader = lightingWallShadShad
, _ceilingStencilShader = ceilingstencilshader
, _windowShader = windowshader
, _windowPullShader = winpull
, _fullscreenShader = fsShad
, _transparencyCompShader = transcompshader
, _alphaDivideShader = alphadivideshader
@@ -201,7 +215,8 @@ preloadRender = do
, _fboPos = fboPosName
, _rboBaseBloom = rboBaseBloomName
, _matUBO = theUBO
, _lightsUBO = lightsubo
, _winSSBO = winssbo
-- , _lightsUBO = lightsubo
, _vboWindows = winvbo
, _vboShapes = shVBO
, _floorVBO = floorvbo
@@ -214,6 +229,7 @@ preloadRender = do
, _cloudShader = cloudshader
, _cloudEBO = cloudebo
, _screenTextureVAO = screentexturevao
, _dummyVAO = VAO dummyvao
}
--------------------end preloadRender