This commit is contained in:
2023-03-09 10:20:18 +00:00
parent 7b797dfdb4
commit 2fc08a4d96
3 changed files with 10 additions and 50 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ module Dodge.Render.Shadow where
import Shader.Parameters import Shader.Parameters
import Shader.ExtraPrimitive import Shader.ExtraPrimitive
import Graphics.Rendering.OpenGL ( ($=), bindVertexArrayObject, bindBuffer import Graphics.Rendering.OpenGL ( ($=), bindBuffer
, BufferTarget (..), bufferSubData, TransferDirection (..) , BufferTarget (..), bufferSubData, TransferDirection (..)
) )
import Graphics.GL.Core43 import Graphics.GL.Core43
-1
View File
@@ -19,7 +19,6 @@ import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Mutable as MV
import Control.Monad.Primitive import Control.Monad.Primitive
import Foreign import Foreign
import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight)
import Graphics.GL.Core45 import Graphics.GL.Core45
drawShaderLay :: Int -> UMV.MVector (PrimState IO) Int -> Int -> FullShader' -> IO () drawShaderLay :: Int -> UMV.MVector (PrimState IO) Int -> Int -> FullShader' -> IO ()
+9 -48
View File
@@ -2,20 +2,17 @@ module Shader.Compile (
makeShader, makeShader,
makeByteStringShaderUsingVAO, makeByteStringShaderUsingVAO,
makeShaderSized, makeShaderSized,
-- makeShaderUsingShaderVAO,
makeShaderUsingVAO, makeShaderUsingVAO,
setupVAO, setupVAO,
setupVertexAttribPointer, setupVertexAttribPointer,
) where ) where
import GLHelp
import Control.Monad import Control.Monad
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BU import qualified Data.ByteString.Unsafe as BU
import Foreign import Foreign
import Foreign.C.String import Foreign.C.String
--import Control.Lens import GLHelp
import Graphics.GL.Core45 import Graphics.GL.Core45
import Graphics.Rendering.OpenGL hiding (Point, imageHeight, scale, translate) import Graphics.Rendering.OpenGL hiding (Point, imageHeight, scale, translate)
import Shader.Data import Shader.Data
@@ -102,7 +99,7 @@ makeShaderSized ::
IO FullShader' IO FullShader'
makeShaderSized s shaderlist sizes ndraw pm = do makeShaderSized s shaderlist sizes ndraw pm = do
prog <- makeSourcedShader s shaderlist prog <- makeSourcedShader s shaderlist
vaob <- setupVAOSized sizes ndraw vaob <- setupVAOSized ndraw sizes
return $ return $
FullShader' FullShader'
{ _shadProg' = prog { _shadProg' = prog
@@ -129,57 +126,21 @@ shaderTypeExt' _ = undefined
-- I think that this requires that the correct shader program is bound? -- I think that this requires that the correct shader program is bound?
setupVAO :: [Int] -> IO VAO setupVAO :: [Int] -> IO VAO
setupVAO sizes = do setupVAO = setupVAOSized numDrawableElements
--theVAO <- genObjectName
--bindVertexArrayObject $= Just theVAO setupVAOSized :: Int -> [Int] -> IO VAO
setupVAOSized ndraw sizes = do
vaoname <- mglCreateSingle glGenVertexArrays vaoname <- mglCreateSingle glGenVertexArrays
glBindVertexArray vaoname glBindVertexArray vaoname
theVBO <- setupVBO sizes theVBO <- setupVBOSized ndraw sizes
return $ return $
VAO VAO
{ _vaoName = vaoname { _vaoName = vaoname
, _vaoVBO = theVBO , _vaoVBO = theVBO
} }
setupVAOSized :: [Int] -> Int -> IO VAO setupVBOSized :: Int -> [Int] -> IO VBO
setupVAOSized sizes ndraw = do setupVBOSized ndraw sizes = do
vaoname <- mglCreateSingle glGenVertexArrays
glBindVertexArray vaoname
-- theVAO <- genObjectName
--bindVertexArrayObject $= Just theVAO
theVBO <- setupVBOSized sizes ndraw
return $
VAO
{ _vaoName = vaoname
, _vaoVBO = theVBO
}
setupVBO :: [Int] -> IO VBO
setupVBO sizes = do
vboName <- genObjectName
bindBuffer ArrayBuffer $= Just vboName
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do
setupVertexAttribPointer loc siz strd off
thePtr <- mallocArray (strd * numDrawableElements)
-- Allocate space
bufferData ArrayBuffer
$= ( fromIntegral $ floatSize * numDrawableElements * strd
, nullPtr
, StreamDraw
)
return $
VBO
{ _vbo = vboName
, _vboPtr = thePtr
, _vboAttribSizes = sizes
, _vboStride = sum sizes
}
where
strd = sum sizes
offs = scanl (+) 0 sizes
setupVBOSized :: [Int] -> Int -> IO VBO
setupVBOSized sizes ndraw = do
vboName <- genObjectName vboName <- genObjectName
bindBuffer ArrayBuffer $= Just vboName bindBuffer ArrayBuffer $= Just vboName
forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do