Commit with working graphics but slow, will attempt to change text
This commit is contained in:
+29
-36
@@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE Strict #-}
|
||||
--{-# LANGUAGE Strict #-}
|
||||
module Picture.Render
|
||||
where
|
||||
import Control.Lens
|
||||
@@ -29,63 +29,56 @@ toVec2 (x,y) = Vector2 x y
|
||||
toVec3 (x,y,z) = Vector3 x y z
|
||||
toVec4 (x,y,z,w) = Vector4 x y z w
|
||||
|
||||
flat2 (x,y) = DL.fromList [x,y]
|
||||
flat3 (x,y,z) = DL.fromList [x,y,z]
|
||||
flat4 (x,y,z,w) = DL.fromList [x,y,z,w]
|
||||
flat2 (x,y) = toVC [x,y]
|
||||
flat3 (x,y,z) = toVC [x,y,z]
|
||||
flat4 (x,y,z,w) = toVC [x,y,z,w]
|
||||
|
||||
mapFlat :: (NFData b) => (a -> DL.DList b) -> DL.DList a -> [b]
|
||||
mapFlat f = force . DL.toList . foldMap f
|
||||
mapFlat :: (NFData b) => (a -> VerticesContainer b) -> VerticesContainer a -> [b]
|
||||
mapFlat f = fromVC . foldMap f
|
||||
|
||||
--marshallVs = V.unsafeWith . V.fromList
|
||||
--marshallVs = withArray
|
||||
|
||||
renderPicture' :: PreloadData -> Picture -> IO ()
|
||||
renderPicture' pdata (Scene posTri' colTri' posChar' colChar' texChar') = do
|
||||
let posTri = DL.toList posTri'
|
||||
colTri = DL.toList colTri'
|
||||
posChar = DL.toList posChar'
|
||||
colChar = DL.toList colChar'
|
||||
texChar = DL.toList texChar'
|
||||
renderPicture' pdata (Scene posTri colTri posChar colChar texChar) = do
|
||||
currentProgram $= Just (_basicShader pdata)
|
||||
bindVertexArrayObject $= Just (_basicVAO pdata)
|
||||
bindBuffer ArrayBuffer $= Just (_posVBO pdata)
|
||||
let firstIndex = 0
|
||||
let vertices :: [Float]
|
||||
vertices = mapFlat flat3 posTri'
|
||||
numVertices = length vertices
|
||||
vertices = mapFlat flat3 posTri
|
||||
numVertices = length posTri
|
||||
vertexSize = sizeOf (head vertices)
|
||||
pokeArray (_ptrPosVBO pdata) vertices
|
||||
bufferData ArrayBuffer $= (fromIntegral (numVertices * vertexSize), _ptrPosVBO pdata, StreamDraw)
|
||||
bufferData ArrayBuffer $= (fromIntegral (3 * numVertices * vertexSize), _ptrPosVBO pdata, StreamDraw)
|
||||
-- marshallVs vertices $ \ptr -> do
|
||||
-- bufferData ArrayBuffer $= (fromIntegral (numVertices * vertexSize), ptr, StreamDraw)
|
||||
bindBuffer ArrayBuffer $= Just (_colVBO pdata)
|
||||
let colVs = mapFlat flat4 colTri'
|
||||
let colVs = mapFlat flat4 colTri
|
||||
colVsize = sizeOf $ head colVs
|
||||
pokeArray (_ptrColVBO pdata) colVs
|
||||
bufferData ArrayBuffer $= (fromIntegral (div (4 * numVertices * colVsize) 3), _ptrColVBO pdata, StreamDraw)
|
||||
bufferData ArrayBuffer $= (fromIntegral (4 * numVertices * colVsize), _ptrColVBO pdata, StreamDraw)
|
||||
-- marshallVs colVs $ \ptr -> do
|
||||
-- bufferData ArrayBuffer $= (fromIntegral (div (4 * numVertices * colVsize) 3), ptr, StreamDraw)
|
||||
drawArrays Triangles (fromIntegral firstIndex) (fromIntegral $ numVertices)
|
||||
|
||||
-- currentProgram $= Just (_textShader pdata)
|
||||
-- bindVertexArrayObject $= Just (_textVAO pdata)
|
||||
-- bindBuffer ArrayBuffer $= Just (_posVBO pdata)
|
||||
-- let vertices' = mapFlat flat3 posChar'
|
||||
-- numVertices' = length vertices'
|
||||
-- vertexSize' = sizeOf $ head vertices'
|
||||
-- withArray vertices' $ \ptr -> do
|
||||
-- bufferData ArrayBuffer $= (fromIntegral (numVertices' * vertexSize'), ptr, StreamDraw)
|
||||
-- bindBuffer ArrayBuffer $= Just (_colVBO pdata)
|
||||
-- let colVsT = mapFlat flat4 colChar'
|
||||
-- colVsTsize = sizeOf $ head colVsT
|
||||
-- withArrayLen colVsT $ \numV' ptr -> do
|
||||
-- bufferData ArrayBuffer $= (fromIntegral (numVertices' * colVsTsize), ptr, StreamDraw)
|
||||
-- bindBuffer ArrayBuffer $= Just (_texVBO pdata)
|
||||
-- let texVsT = mapFlat flat2 texChar'
|
||||
-- texVsTsize = sizeOf $ head texVsT
|
||||
-- withArrayLen texVsT $ \numV' ptr -> do
|
||||
-- bufferData ArrayBuffer $= (fromIntegral (numVertices' * texVsTsize), ptr, StreamDraw)
|
||||
-- drawArrays Triangles (fromIntegral firstIndex) (fromIntegral $ numVertices')
|
||||
currentProgram $= Just (_textShader pdata)
|
||||
bindVertexArrayObject $= Just (_textVAO pdata)
|
||||
bindBuffer ArrayBuffer $= Just (_posVBO pdata)
|
||||
let vertices' = mapFlat flat3 posChar
|
||||
numVertices' = length posChar
|
||||
vertexSize' = sizeOf $ head vertices'
|
||||
pokeArray (_ptrPosVBO pdata) vertices'
|
||||
bufferData ArrayBuffer $= (fromIntegral (3 * numVertices' * vertexSize'), _ptrPosVBO pdata, StreamDraw)
|
||||
--withArray vertices' $ \ptr -> do
|
||||
-- bufferData ArrayBuffer $= (fromIntegral (3 * numVertices' * vertexSize'), ptr, StreamDraw)
|
||||
bindBuffer ArrayBuffer $= Just (_colVBO pdata)
|
||||
pokeArray (_ptrColVBO pdata) $ mapFlat flat4 colChar
|
||||
bufferData ArrayBuffer $= (fromIntegral (4 * numVertices' * vertexSize'), _ptrColVBO pdata, StreamDraw)
|
||||
bindBuffer ArrayBuffer $= Just (_texVBO pdata)
|
||||
pokeArray (_ptrTexVBO pdata) $ mapFlat flat2 texChar
|
||||
bufferData ArrayBuffer $= (fromIntegral (2 * numVertices' * vertexSize'), _ptrTexVBO pdata, StreamDraw)
|
||||
drawArrays Triangles (fromIntegral firstIndex) (fromIntegral $ numVertices')
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user