From 2fc08a4d966776f50346e9e4b13ea0039ef3203b Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 9 Mar 2023 10:20:18 +0000 Subject: [PATCH] Cleanup --- src/Dodge/Render/Shadow.hs | 2 +- src/Shader.hs | 1 - src/Shader/Compile.hs | 57 ++++++-------------------------------- 3 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/Dodge/Render/Shadow.hs b/src/Dodge/Render/Shadow.hs index ab0bb31f0..047fa9305 100644 --- a/src/Dodge/Render/Shadow.hs +++ b/src/Dodge/Render/Shadow.hs @@ -2,7 +2,7 @@ module Dodge.Render.Shadow where import Shader.Parameters import Shader.ExtraPrimitive -import Graphics.Rendering.OpenGL ( ($=), bindVertexArrayObject, bindBuffer +import Graphics.Rendering.OpenGL ( ($=), bindBuffer , BufferTarget (..), bufferSubData, TransferDirection (..) ) import Graphics.GL.Core43 diff --git a/src/Shader.hs b/src/Shader.hs index 94775b046..03b8440af 100644 --- a/src/Shader.hs +++ b/src/Shader.hs @@ -19,7 +19,6 @@ import qualified Data.Vector.Unboxed.Mutable as UMV import qualified Data.Vector.Mutable as MV import Control.Monad.Primitive import Foreign -import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight) import Graphics.GL.Core45 drawShaderLay :: Int -> UMV.MVector (PrimState IO) Int -> Int -> FullShader' -> IO () diff --git a/src/Shader/Compile.hs b/src/Shader/Compile.hs index c33ed404f..a8df4fc31 100644 --- a/src/Shader/Compile.hs +++ b/src/Shader/Compile.hs @@ -2,20 +2,17 @@ module Shader.Compile ( makeShader, makeByteStringShaderUsingVAO, makeShaderSized, - -- makeShaderUsingShaderVAO, makeShaderUsingVAO, setupVAO, setupVertexAttribPointer, ) where -import GLHelp import Control.Monad import qualified Data.ByteString as BS import qualified Data.ByteString.Unsafe as BU import Foreign import Foreign.C.String ---import Control.Lens - +import GLHelp import Graphics.GL.Core45 import Graphics.Rendering.OpenGL hiding (Point, imageHeight, scale, translate) import Shader.Data @@ -102,7 +99,7 @@ makeShaderSized :: IO FullShader' makeShaderSized s shaderlist sizes ndraw pm = do prog <- makeSourcedShader s shaderlist - vaob <- setupVAOSized sizes ndraw + vaob <- setupVAOSized ndraw sizes return $ FullShader' { _shadProg' = prog @@ -129,57 +126,21 @@ shaderTypeExt' _ = undefined -- I think that this requires that the correct shader program is bound? setupVAO :: [Int] -> IO VAO -setupVAO sizes = do - --theVAO <- genObjectName - --bindVertexArrayObject $= Just theVAO +setupVAO = setupVAOSized numDrawableElements + +setupVAOSized :: Int -> [Int] -> IO VAO +setupVAOSized ndraw sizes = do vaoname <- mglCreateSingle glGenVertexArrays glBindVertexArray vaoname - theVBO <- setupVBO sizes + theVBO <- setupVBOSized ndraw sizes return $ VAO { _vaoName = vaoname , _vaoVBO = theVBO } -setupVAOSized :: [Int] -> Int -> IO VAO -setupVAOSized sizes ndraw = 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 +setupVBOSized :: Int -> [Int] -> IO VBO +setupVBOSized ndraw sizes = do vboName <- genObjectName bindBuffer ArrayBuffer $= Just vboName forM_ (zip3 [0 ..] sizes offs) $ \(loc, siz, off) -> do