Create post world load function

This commit is contained in:
2023-03-18 09:37:09 +00:00
parent d8fb7a1f99
commit 77c88f68a7
14 changed files with 80 additions and 48 deletions
+13
View File
@@ -1,5 +1,6 @@
module Shader.Compile (
setupVBO,
setupVBO',
makeShader,
makeShader4,
makeByteStringShaderUsingVAO,
@@ -80,6 +81,17 @@ setupVBO vertexsize = do
GL_STREAM_DRAW
return VBO {_vboName = vboname, _vboPtr = thePtr, _vboVertexSize = vertexsize}
setupVBO' :: Int -> IO VBO
setupVBO' vertexsize = do
vboname <- mglCreate glCreateBuffers
thePtr <- mallocArray (vertexsize * numDrawableElements)
-- Allocate space
glNamedBufferData vboname
( fromIntegral $ floatSize * numDrawableElements * vertexsize)
nullPtr
GL_STATIC_DRAW
return VBO {_vboName = vboname, _vboPtr = thePtr, _vboVertexSize = vertexsize}
makeByteStringShaderUsingVAO ::
-- | (Arbitrary) name of the shader
String ->
@@ -269,6 +281,7 @@ checkErrorGL str f g x statustype =
char <- peekCString charPtr
error $ str ++ show char
-- use glCreateShaderProgramv here
compileAndCheckShader :: String -> (GLenum, BS.ByteString) -> IO GLuint
compileAndCheckShader str (theShaderType, sourceCode) = do
theShader <- glCreateShader theShaderType
+13 -9
View File
@@ -4,10 +4,12 @@ module Shader.Poke (
pokeArrayOff,
pokeShape,
pokeWallsWindowsFloor,
pokeWallsWindows,
memoTopPrismEdgeIndices,
pokeFloors
) where
import Shader.Poke.Triangulate
import Control.Monad.Primitive
import qualified Data.Vector as V
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
@@ -55,6 +57,17 @@ pokeWallsWindowsFloor wlptr wiptr flptr wls wis fls = do
flcounts <- VFSM.foldlM' (pokeF flptr) 0 (VFSM.fromList fls)
return (wlcounts1, wlcounts2, flcounts)
pokeWallsWindows ::
Ptr Float ->
Ptr Float ->
[((Point2, Point2), Point4)] ->
[((Point2, Point2), Point4)] ->
IO (Int, Int)
pokeWallsWindows wlptr wiptr wls wis = do
wlcounts1 <- VFSM.foldlM' (pokeW wlptr) 0 (VFSM.fromList wls)
wlcounts2 <- VFSM.foldlM' (pokeW wiptr) 0 (VFSM.fromList wis)
return (wlcounts1, wlcounts2)
pokeFloors :: Ptr Float ->
[(Point3, Point3)] ->
IO Int
@@ -240,15 +253,6 @@ pokeIndex nv eiptr ni ioff = do
pokeElemOff eiptr ni (fromIntegral $ nv + ioff)
return $ ni + 1
triangulate :: [Int] -> [Int]
triangulate is = V.toList . V.backpermute (V.fromList is) . V.fromList $ triangulateIndices (length is)
triangulateIndices :: Int -> [Int]
triangulateIndices i = concatMap f [0 .. i -3]
where
f x
| even x = [0, x + 1, x + 2]
| otherwise = [0, x + 2, x + 1]
memoFlatIndices :: V.Vector (UV.Vector Int)
memoFlatIndices =