Get shape shader working using vertex pulling

Seems slow, will try to improve
This commit is contained in:
2025-11-11 18:54:48 +00:00
parent f136d0cd19
commit 7f6e7d2741
4 changed files with 32 additions and 24 deletions
+20 -7
View File
@@ -1,14 +1,27 @@
#version 450 core
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 col;
layout (location = 2) in vec4 norm;
struct PosColNorm { vec4 pos; uint col; vec4 norm; };
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
layout (std430, binding = 3) readonly buffer Data { PosColNorm data[]; };
layout (std430, binding = 4) readonly buffer Indices { uint indices[]; };
out vec4 vCol;
out vec4 vPos;
out vec4 vNorm;
void main() {
gl_Position = theMat * vec4(pos.xyz,1);
vCol = col;
vPos = pos;
vNorm = norm;
vPos = data[indices[gl_VertexID]].pos;
vCol = unpackUnorm4x8(data[indices[gl_VertexID]].col);
vNorm = data[indices[gl_VertexID]].norm;
gl_Position = theMat * vec4(vPos.xyz,1);
}
//layout (location = 0) in vec4 pos;
//layout (location = 1) in vec4 col;
//layout (location = 2) in vec4 norm;
//layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
//out vec4 vCol;
//out vec4 vPos;
//out vec4 vNorm;
//void main() {
// gl_Position = theMat * vec4(pos.xyz,1);
// vCol = col;
// vPos = pos;
// vNorm = norm;
//}
+7 -6
View File
@@ -176,12 +176,13 @@ doDrawing' win pdata u = do
--draw object shapes onto base buffer
let fs = _shapeShader pdata
glUseProgram (_shaderUINT fs)
glBindVertexArray $ fs ^. shaderVAO . vaoName
glDrawElements
(_unPrimitiveMode $ _shaderPrimitive fs)
(fromIntegral nIndices)
GL_UNSIGNED_INT
nullPtr
-- glBindVertexArray $ fs ^. shaderVAO . vaoName
glDrawArrays GL_TRIANGLES 0 (fromIntegral nIndices)
-- glDrawElements
-- (_unPrimitiveMode $ _shaderPrimitive fs)
-- (fromIntegral nIndices)
-- GL_UNSIGNED_INT
-- nullPtr
-- draw chasm shader blocking floor
glUseProgram (pdata ^. chasmShader . shaderUINT)
glBindVertexArray $ pdata ^. chasmShader . shaderVAO . vaoName
+5 -7
View File
@@ -82,14 +82,12 @@ preloadRender = do
shEBO <- setupEBO shPosVAO
-- note the shape shader vao is distinct from the position vao, but they
-- share an EBO
-- shapeshader <- makeShaderUsingVBO "shape/basic" [vert, frag] shapeVerxAttributes
-- pmTriangles
-- shVBO
-- glVertexArrayElementBuffer (shapeshader ^. shaderVAO . vaoName) (shEBO ^. uiboName)
shapeshader <-
makeShaderUsingVBO
"shape/basic"
[vert, frag]
shapeVerxAttributes
pmTriangles
shVBO
glVertexArrayElementBuffer (shapeshader ^. shaderVAO . vaoName) (shEBO ^. uiboName)
makeShaderUsingVAO "shape/basic" [vert, frag] pmTriangles (VAO dummyvao)
putStrLn "Setup wall/windows VBO, VAO, EBO, shader"
-- winvbo <- setupVBO (floatSize * 8)
-4
View File
@@ -29,10 +29,6 @@ bufferEBO :: UintBO -> Int -> IO ()
bufferEBO x i =
glNamedBufferSubData (x ^. uiboName) 0 (fromIntegral $ gluintSize * i) (x ^. uiboPtr)
--bufferFloatBO :: VBO -> Int -> IO ()
--bufferFloatBO x i = undefined
-- glNamedBufferSubData (x ^. uiboName) 0 (fromIntegral $ gluintSize * i) (x ^. uiboPtr)
bufferShaderLayers :: MV.MVector (PrimState IO) (Shader, VBO) -> UMV.MVector (PrimState IO) Int -> IO ()
bufferShaderLayers shads counts = MV.imapM_ f shads
where