Draw chasms using vertex pulling

This commit is contained in:
2025-11-13 21:58:40 +00:00
parent ec1216e7eb
commit 836c0ba772
6 changed files with 25 additions and 22 deletions
+6
View File
@@ -0,0 +1,6 @@
#version 450 core
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
layout (std430, binding = 7) readonly buffer Pos { vec2 pos[]; };
void main() {
gl_Position = theMat * vec4(pos[gl_VertexID],0,1);
}
+1 -1
View File
@@ -44,7 +44,7 @@ data RenderData = RenderData
, _floorVBO :: VBO
, _floorShader :: Shader
, _chasmVBO :: VBO
, _chasmShader :: Shader
, _chasmShader :: GLuint
, _winVBO :: VBO
, _wallVBO :: VBO
, _cloudVBO :: VBO
+2 -6
View File
@@ -145,16 +145,12 @@ doDrawing' win pdata u = do
glUseProgram fs
glDrawArrays GL_TRIANGLES 0 (fromIntegral nIndices)
-- draw chasm shader blocking floor
glUseProgram (pdata ^. chasmShader . shaderUINT)
glBindVertexArray $ pdata ^. chasmShader . shaderVAO . vaoName
glUseProgram (pdata ^. chasmShader)
glDepthMask GL_FALSE
glDrawBuffer GL_NONE
glStencilOp GL_KEEP GL_KEEP GL_INCR
with 0 $ glClearNamedFramebufferiv (pdata ^. fboBase . _1 . unFBO) GL_STENCIL 0
glDrawArrays
(_unPrimitiveMode $ pdata ^. chasmShader . shaderPrimitive)
0
(fromIntegral nchs)
glDrawArrays GL_TRIANGLES 0 (fromIntegral nchs)
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
glNamedFramebufferDrawBuffers (pdata ^. fboBase . _1 . unFBO) 3
glDepthMask GL_TRUE
+8 -2
View File
@@ -1,5 +1,7 @@
module Dodge.WorldLoad (postUniverseLoadSideEffect) where
import Shader.Parameters
import Graphics.GL.Core45
import Control.Lens
import Control.Monad
import Data.Preload.Render
@@ -16,8 +18,12 @@ postWorldLoad :: RenderData -> CWorld -> IO CWorld
postWorldLoad rdata cw = do
nfloorvxs <- foldM (pokeTile (rdata ^. floorVBO . vboPtr)) 0 (cw ^. cwTiles)
bufferPokedVBO (rdata ^. floorVBO) nfloorvxs
nchasmvxs <- foldM (pokeChasm (rdata ^. chasmVBO . vboPtr)) 0 (cw ^. chasms)
bufferPokedVBO (rdata ^. chasmVBO) nchasmvxs
let chbo = rdata ^. chasmVBO . vboName
chptr = rdata ^. chasmVBO . vboPtr
nchasmvxs <- foldM (pokeChasm chptr) 0 (cw ^. chasms)
glInvalidateBufferData chbo
glNamedBufferStorage chbo (fromIntegral $ 2 * nchasmvxs * floatSize) chptr 0
glBindBufferBase GL_SHADER_STORAGE_BUFFER 7 chbo
return $
cw & numberFloorVerxs .~ nfloorvxs
& numberChasmVerxs .~ nchasmvxs
+4 -9
View File
@@ -137,15 +137,10 @@ preloadRender = do
initTexture2DArraySquare 41 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/normalArray.png"
putStrLn "Setup chasm VBO, shader"
let chasmverxstrd = 3
chasmvbo <- setupVBOStatic (floatSize * chasmverxstrd)
chasmshader <-
makeShaderUsingVBO
"positional/blank"
[vert, frag]
(toFloatVAs [3])
pmTriangles
chasmvbo
chvbo <- mglCreate glCreateBuffers
chptr <- mallocArray (2 * 65536)
let chasmvbo = VBO chvbo chptr floatSize
chasmshader <- makeSourcedShader "chasm" [vert]
framebuf2 <- newTextureFramebuffer
framebuf3 <- newTextureFramebuffer
+4 -4
View File
@@ -3,6 +3,7 @@ module Shader.Poke.Floor (
pokeChasm,
) where
import Shader.Parameters
import Control.Monad
import Data.Tile
import Foreign
@@ -22,10 +23,9 @@ pokeTileVerx tangent tilez ptr i (V2 x y, V2 s t) = do
return $ i + 1
pokeChasm :: Ptr Float -> Int -> [Point2] -> IO Int
pokeChasm ptr i ps =
foldM (pokeChasmVerx ptr) i $ polyToTris ps
pokeChasm ptr i ps = foldM (pokeChasmVerx ptr) i $ polyToTris ps
pokeChasmVerx :: Ptr Float -> Int -> Point2 -> IO Int
pokeChasmVerx ptr i (V2 x y) = do
zipWithM_ (\off -> pokeElemOff ptr (i * 3 + off)) [0 ..] [x, y, 0]
pokeChasmVerx ptr i p = do
pokeByteOff ptr (floatSize*i*2) p
return $ i + 1