Pack shape normals into a word8
This commit is contained in:
@@ -44,8 +44,8 @@ data RenderData = RenderData
|
||||
, _matUBO :: GLuint -- BufferObject id
|
||||
-- , _winSSBO :: GLuint
|
||||
-- , _wallSSBO :: GLuint
|
||||
, _shapeSSBO :: GLuint
|
||||
, _ishapeSSBO :: GLuint
|
||||
-- , _shapeSSBO :: GLuint
|
||||
-- , _ishapeSSBO :: GLuint
|
||||
, _vboShapes :: VBO
|
||||
, _floorVBO :: VBO
|
||||
, _floorShader :: Shader
|
||||
|
||||
+4
-9
@@ -4,6 +4,7 @@ module Dodge.Render (
|
||||
getWindowSize,
|
||||
) where
|
||||
|
||||
import Shape.Parameters
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import qualified Control.Monad.Parallel as MP
|
||||
@@ -114,10 +115,10 @@ doDrawing' win pdata u = do
|
||||
glNamedBufferSubData (pdata ^. wallVBO . vboName) 0
|
||||
(fromIntegral $ trueNWalls * sizeOf (0::Float) * 8)
|
||||
(pdata ^. wallVBO . vboPtr)
|
||||
glNamedBufferSubData (pdata ^. shapeSSBO) 0
|
||||
(fromIntegral $ nShapeVs * (sizeOf (0::Float)*12))
|
||||
glNamedBufferSubData (pdata ^. vboShapes . vboName) 0
|
||||
(fromIntegral $ nShapeVs * shapeVerxSize)
|
||||
(pdata ^. vboShapes . vboPtr)
|
||||
glNamedBufferSubData (pdata ^. ishapeSSBO) 0
|
||||
glNamedBufferSubData (pdata ^. shapeEBO . uiboName) 0
|
||||
(fromIntegral $ nIndices * (sizeOf (0::GLuint)))
|
||||
(pdata ^. shapeEBO . uiboPtr)
|
||||
bufferEBO (pdata ^. silhouetteEBO) nSilIndices
|
||||
@@ -176,13 +177,7 @@ doDrawing' win pdata u = do
|
||||
--draw object shapes onto base buffer
|
||||
let fs = _shapeShader pdata
|
||||
glUseProgram (_shaderUINT fs)
|
||||
-- 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
|
||||
|
||||
+2
-2
@@ -4,12 +4,12 @@ module Preload (
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Data.Preload
|
||||
import Preload.Render
|
||||
--import Preload.Render
|
||||
import qualified SDL.Mixer as Mix
|
||||
|
||||
cleanUpPreload :: PreloadData -> IO ()
|
||||
cleanUpPreload pd = do
|
||||
cleanUpRenderPreload $ _renderData pd
|
||||
-- cleanUpRenderPreload $ _renderData pd
|
||||
cleanUpSoundPreload $ _soundData pd
|
||||
|
||||
cleanUpSoundPreload :: IM.IntMap Mix.Chunk -> IO ()
|
||||
|
||||
+16
-12
@@ -2,11 +2,12 @@
|
||||
--{-# OPTIONS_GHC -Wno-unused-top-binds #-}
|
||||
module Preload.Render (
|
||||
preloadRender,
|
||||
cleanUpRenderPreload,
|
||||
-- cleanUpRenderPreload,
|
||||
) where
|
||||
|
||||
import Shape.Parameters
|
||||
import Control.Concurrent
|
||||
import Control.Lens
|
||||
--import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Preload.Render
|
||||
import qualified Data.Vector.Mutable as MV
|
||||
@@ -18,7 +19,7 @@ import Shader.AuxAddition
|
||||
import Shader.Compile
|
||||
import Shader.Data
|
||||
import Shader.Parameters
|
||||
import Shape.Parameters
|
||||
--import Shape.Parameters
|
||||
|
||||
{- BINDING LIST:
|
||||
0 base
|
||||
@@ -35,7 +36,6 @@ preloadRender = do
|
||||
-- set up uniform buffer object
|
||||
putStrLn "Setup UBO"
|
||||
theUBO <- mglCreate glCreateBuffers
|
||||
--glNamedBufferData theUBO 64 nullPtr GL_STREAM_DRAW
|
||||
glNamedBufferStorage theUBO 64 nullPtr GL_DYNAMIC_STORAGE_BIT
|
||||
glBindBufferBase GL_UNIFORM_BUFFER 0 theUBO
|
||||
|
||||
@@ -55,14 +55,18 @@ preloadRender = do
|
||||
let wallvbo = VBO wallssbo wallssboptr 8
|
||||
|
||||
shapessbo <- mglCreate glCreateBuffers
|
||||
let shapessbosize = fromIntegral (sizeOf (0::Float) * 12) * 65536
|
||||
let shapessbosize = fromIntegral shapeVerxSize * 65536
|
||||
glNamedBufferStorage shapessbo shapessbosize nullPtr GL_DYNAMIC_STORAGE_BIT
|
||||
glBindBufferBase GL_SHADER_STORAGE_BUFFER 3 shapessbo
|
||||
shptr <- mallocArray (fromIntegral shapessbosize)
|
||||
let shVBO = VBO shapessbo shptr shapeVerxSize
|
||||
|
||||
ishapessbo <- mglCreate glCreateBuffers
|
||||
let ishapessbosize = fromIntegral (sizeOf (0::GLuint) * 65536)
|
||||
glNamedBufferStorage ishapessbo ishapessbosize nullPtr GL_DYNAMIC_STORAGE_BIT
|
||||
glBindBufferBase GL_SHADER_STORAGE_BUFFER 4 ishapessbo
|
||||
ishptr <- mallocArray 65536
|
||||
let shEBO = UintBO ishapessbo ishptr
|
||||
|
||||
ieshapessbo <- mglCreate glCreateBuffers
|
||||
let ieshapessbosize = fromIntegral (sizeOf (0::GLuint) * 65536)
|
||||
@@ -77,9 +81,9 @@ preloadRender = do
|
||||
wallpull <- makeShaderUsingVAO "pull/wall" [vert,frag] pmTriangles (VAO dummyvao)
|
||||
|
||||
putStrLn "Setup shape VBO, VAO, EBO"
|
||||
shVBO <- setupVBO shapeVerxSize
|
||||
shPosVAO <- setupVAOUsingVBO [VertexAttribute 4 GL_FLOAT GL_FALSE 0] shVBO
|
||||
shEBO <- setupEBO shPosVAO
|
||||
-- shVBO <- setupVBO shapeVerxSize
|
||||
-- shPosVAO <- setupVAOUsingVBO [VertexAttribute 4 GL_FLOAT GL_FALSE 0] shVBO
|
||||
-- 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
|
||||
@@ -221,8 +225,8 @@ preloadRender = do
|
||||
, _matUBO = theUBO
|
||||
-- , _winSSBO = winssbo
|
||||
-- , _wallSSBO = wallssbo
|
||||
, _shapeSSBO = shapessbo
|
||||
, _ishapeSSBO = ishapessbo
|
||||
-- , _shapeSSBO = shapessbo
|
||||
-- , _ishapeSSBO = ishapessbo
|
||||
-- , _ieshapeSSBO = ieshapessbo
|
||||
-- , _lightsUBO = lightsubo
|
||||
-- , _vboWindows = winvbo
|
||||
@@ -265,8 +269,8 @@ initializeGLState = do
|
||||
glEnable GL_DEPTH_TEST
|
||||
glEnable GL_STENCIL_TEST
|
||||
|
||||
cleanUpRenderPreload :: RenderData -> IO ()
|
||||
cleanUpRenderPreload _ = return ()
|
||||
--cleanUpRenderPreload :: RenderData -> IO ()
|
||||
--cleanUpRenderPreload _ = return ()
|
||||
|
||||
--cleanUpRenderPreload pd = do
|
||||
-- TODO fix this
|
||||
|
||||
+17
-18
@@ -8,6 +8,8 @@ module Shader.Poke (
|
||||
pokeFloors,
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
import Linear
|
||||
import Shape.Parameters
|
||||
import Color
|
||||
import Control.Monad.Primitive
|
||||
@@ -22,7 +24,6 @@ import Geometry.Data
|
||||
import Geometry.Triangulate
|
||||
import Geometry.Vector
|
||||
import Graphics.GL.Core45
|
||||
import Linear.V3 (cross)
|
||||
import Picture.Data
|
||||
import Shader.Data
|
||||
import Shader.Parameters
|
||||
@@ -263,7 +264,7 @@ pokeBoxSurface :: Float -> Point4 -> Ptr Float -> UV.Vector Point3 -> Int -> [In
|
||||
{-# INLINE pokeBoxSurface #-}
|
||||
pokeBoxSurface xdata col ptr vs n is =
|
||||
UV.foldM'
|
||||
(pokeFlatV xdata norm col ptr)
|
||||
(pokeFlatV xdata pnorm col ptr)
|
||||
n
|
||||
v
|
||||
where
|
||||
@@ -271,7 +272,7 @@ pokeBoxSurface xdata col ptr vs n is =
|
||||
x = v UV.! 0
|
||||
y = v UV.! 1
|
||||
z = v UV.! 2
|
||||
norm = negate $ cross (x - y) (z - y)
|
||||
pnorm = negate $ cross (x - y) (z - y)
|
||||
|
||||
-- should probably memoize this
|
||||
boxSurfaces :: Int -> [[Int]]
|
||||
@@ -434,23 +435,16 @@ topPrismIndices n =
|
||||
]
|
||||
|
||||
-- consider changing the position to a vec4
|
||||
pokeJustV ::
|
||||
Float ->
|
||||
Point3 ->
|
||||
Point4 ->
|
||||
Ptr Float ->
|
||||
Int ->
|
||||
Point3 ->
|
||||
IO Int
|
||||
pokeJustV :: Float -> Point3 -> Point4 -> Ptr Float -> Int -> Point3 -> IO Int
|
||||
{-# INLINE pokeJustV #-}
|
||||
pokeJustV xdata cp col ptr nv sh = do
|
||||
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (toColor8 col)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 8 * floatSize) (V4 nx ny nz 1)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalToColor8 $ V4 nx ny nz 1)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 8 * floatSize) (toColor8 col)
|
||||
return (nv + 1)
|
||||
where
|
||||
V3 x y z = sh
|
||||
V3 nx ny nz = cp
|
||||
V3 nx ny nz = cp - sh
|
||||
|
||||
pokeFlatV ::
|
||||
Float ->
|
||||
@@ -461,14 +455,19 @@ pokeFlatV ::
|
||||
Point3 ->
|
||||
IO Int
|
||||
{-# INLINE pokeFlatV #-}
|
||||
pokeFlatV xdata norm col ptr nv sh = do
|
||||
pokeFlatV xdata pnorm col ptr nv sh = do
|
||||
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (toColor8 col)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 8 * floatSize) (V4 nx ny nz 1)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalToColor8 $ V4 nx ny nz 1)
|
||||
pokeByteOff ptr (nv *shapeVerxSize + 8 * floatSize) (toColor8 col)
|
||||
return (nv + 1)
|
||||
where
|
||||
V3 x y z = sh
|
||||
V3 nx ny nz = sh - norm
|
||||
V3 nx ny nz = (sh - pnorm) - V3 x y z
|
||||
|
||||
normalToColor8 :: Point4 -> Color8
|
||||
normalToColor8 = over each f . normalize
|
||||
where
|
||||
f x = floor $ (x + 1) * 127.5
|
||||
|
||||
pokeLayVerxs ::
|
||||
MV.MVector (PrimState IO) (Shader, VBO) ->
|
||||
|
||||
+9
-13
@@ -1,20 +1,16 @@
|
||||
module Shape.Parameters
|
||||
(shapeVerxSize,shapeVerxAttributes)
|
||||
where
|
||||
module Shape.Parameters (shapeVerxSize) where
|
||||
-- ,shapeVerxAttributes) where
|
||||
|
||||
import Shader.Parameters
|
||||
import Shader.Data
|
||||
--import Data.Word
|
||||
import Foreign.Storable
|
||||
import Graphics.GL.Core45
|
||||
|
||||
shapeVerxSize :: Int
|
||||
{-# INLINE shapeVerxSize #-}
|
||||
shapeVerxSize = sizeOf (0 :: Float) * 12
|
||||
|
||||
shapeVerxAttributes :: [VertexAttribute]
|
||||
shapeVerxAttributes =
|
||||
[VertexAttribute 4 GL_FLOAT GL_FALSE 0
|
||||
,VertexAttribute 4 GL_UNSIGNED_BYTE GL_TRUE (fromIntegral (4 :: Int) * fromIntegral floatSize)
|
||||
,VertexAttribute 4 GL_FLOAT GL_FALSE (fromIntegral (8 :: Int) * fromIntegral (floatSize))
|
||||
]
|
||||
--shapeVerxAttributes :: [VertexAttribute]
|
||||
--shapeVerxAttributes =
|
||||
-- [VertexAttribute 4 GL_FLOAT GL_FALSE 0
|
||||
-- ,VertexAttribute 4 GL_UNSIGNED_BYTE GL_TRUE (fromIntegral (4 :: Int) * fromIntegral floatSize)
|
||||
-- ,VertexAttribute 4 GL_FLOAT GL_FALSE (fromIntegral (8 :: Int) * fromIntegral (floatSize))
|
||||
-- ]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user