Translate VAOs to DSA
This commit is contained in:
+4
-2
@@ -110,7 +110,8 @@ doDrawing win pdata u = do
|
||||
-- uniform (_shadUnis lwShad V.! 0) $= viewFrom3d
|
||||
glUseProgram (lwShad ^. shadProg')
|
||||
glUniform3f (_shadUnis' lwShad V.! 0) vfx vfy 20
|
||||
bindVertexArrayObject $= lwShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwShad)
|
||||
--bindVertexArrayObject $= lwShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwShad)
|
||||
glBindVertexArray $ lwShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwShad)
|
||||
unless (debugOn Remove_LOS cfig) $
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode $ _shadPrim' lwShad)
|
||||
@@ -126,7 +127,8 @@ doDrawing win pdata u = do
|
||||
let fs = _shapeShader pdata
|
||||
--currentProgram $= Just (_shadProg fs)
|
||||
glUseProgram (_shadProg' fs)
|
||||
bindVertexArrayObject $= fs ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO fs)
|
||||
--bindVertexArrayObject $= fs ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO fs)
|
||||
glBindVertexArray $ fs ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO fs)
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ _shadPrim' fs)
|
||||
(fromIntegral nIndices)
|
||||
|
||||
@@ -32,7 +32,8 @@ drawCPUShadows pdata s pos rad = do
|
||||
(theshad ^. shadVAO' . vaoVBO . vboPtr)
|
||||
--currentProgram $= theshad ^? shadProg
|
||||
glUseProgram (theshad ^. shadProg')
|
||||
bindVertexArrayObject $= Just (_vaoName $ _shadVAO' theshad)
|
||||
--bindVertexArrayObject $= Just (_vaoName $ _shadVAO' theshad)
|
||||
glBindVertexArray $ (_vaoName $ _shadVAO' theshad)
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode $ _shadPrim' theshad)
|
||||
0
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ import Foreign.Storable
|
||||
import Graphics.GL.Core45
|
||||
|
||||
|
||||
mglCreateSingle :: (Ptr GLuint -> IO ()) -> IO GLuint
|
||||
mglCreateSingle :: (GLsizei -> Ptr GLuint -> IO ()) -> IO GLuint
|
||||
mglCreateSingle f = do
|
||||
alloca $ \nameptr -> do
|
||||
f nameptr
|
||||
f 1 nameptr
|
||||
peek nameptr
|
||||
|
||||
+26
-12
@@ -5,6 +5,7 @@ module Preload.Render (
|
||||
cleanUpRenderPreload,
|
||||
) where
|
||||
|
||||
import GLHelp
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Preload.Render
|
||||
@@ -18,6 +19,7 @@ import Shader.Bind
|
||||
import Shader.Compile
|
||||
import Shader.Data
|
||||
import Shader.Parameters
|
||||
import Graphics.GL.Core45
|
||||
|
||||
numDrawableWalls :: Int
|
||||
numDrawableWalls = 5000
|
||||
@@ -39,12 +41,16 @@ preloadRender = do
|
||||
, StreamDraw
|
||||
)
|
||||
let wpVBO = VBO{_vbo = wpVBOname, _vboPtr = wpVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8}
|
||||
wpVAOname <- genObjectName
|
||||
bindVertexArrayObject $= Just wpVAOname
|
||||
-- wpVAOname <- genObjectName
|
||||
-- bindVertexArrayObject $= Just wpVAOname
|
||||
wpVAOname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray wpVAOname
|
||||
bindBuffer ArrayBuffer $= Just wpVBOname
|
||||
setupVertexAttribPointer 0 4 8 0
|
||||
wpColVAOname <- genObjectName
|
||||
bindVertexArrayObject $= Just wpColVAOname
|
||||
--wpColVAOname <- genObjectName
|
||||
--bindVertexArrayObject $= Just wpColVAOname
|
||||
wpColVAOname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray wpColVAOname
|
||||
setupVertexAttribPointer 0 4 8 0
|
||||
setupVertexAttribPointer 1 4 8 4
|
||||
let wpVAO = VAO{_vaoName = wpVAOname, _vaoVBO = wpVBO}
|
||||
@@ -59,8 +65,10 @@ preloadRender = do
|
||||
, StreamDraw
|
||||
)
|
||||
let winVBO = VBO{_vbo = winVBOname, _vboPtr = winVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8}
|
||||
winColVAOname <- genObjectName
|
||||
bindVertexArrayObject $= Just winColVAOname
|
||||
--winColVAOname <- genObjectName
|
||||
--bindVertexArrayObject $= Just winColVAOname
|
||||
winColVAOname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray winColVAOname
|
||||
setupVertexAttribPointer 0 4 8 0
|
||||
setupVertexAttribPointer 1 4 8 4
|
||||
let winColVAO = VAO{_vaoName = winColVAOname, _vaoVBO = winVBO}
|
||||
@@ -83,22 +91,28 @@ preloadRender = do
|
||||
, StreamDraw
|
||||
)
|
||||
let shVBO = VBO{_vbo = shVBOname, _vboPtr = shVBOptr, _vboAttribSizes = [4, 4], _vboStride = 8}
|
||||
shPosColVAOname <- genObjectName
|
||||
bindVertexArrayObject $= Just shPosColVAOname
|
||||
--shPosColVAOname <- genObjectName
|
||||
--bindVertexArrayObject $= Just shPosColVAOname
|
||||
shPosColVAOname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray shPosColVAOname
|
||||
bindBuffer ArrayBuffer $= Just shVBOname
|
||||
setupVertexAttribPointer 0 3 7 0
|
||||
setupVertexAttribPointer 1 4 7 3
|
||||
bindBuffer ElementArrayBuffer $= Just shEBOname
|
||||
shPosVAOname <- genObjectName
|
||||
bindVertexArrayObject $= Just shPosVAOname
|
||||
--shPosVAOname <- genObjectName
|
||||
--bindVertexArrayObject $= Just shPosVAOname
|
||||
shPosVAOname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray shPosVAOname
|
||||
bindBuffer ArrayBuffer $= Just shVBOname
|
||||
setupVertexAttribPointer 0 3 7 0
|
||||
bindBuffer ElementArrayBuffer $= Just shEBOname
|
||||
let shPosColVAO = VAO{_vaoName = shPosColVAOname, _vaoVBO = shVBO}
|
||||
shPosVAO = VAO{_vaoName = shPosVAOname, _vaoVBO = shVBO}
|
||||
--setup silhouette edge VAO
|
||||
shEdgeVAOname <- genObjectName
|
||||
bindVertexArrayObject $= Just shEdgeVAOname
|
||||
--shEdgeVAOname <- genObjectName
|
||||
--bindVertexArrayObject $= Just shEdgeVAOname
|
||||
shEdgeVAOname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray shEdgeVAOname
|
||||
bindBuffer ArrayBuffer $= Just shVBOname
|
||||
setupVertexAttribPointer 0 3 7 0
|
||||
--setup ebo for silhouette edges
|
||||
|
||||
+8
-4
@@ -81,7 +81,8 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
|
||||
--uniform (_shadUnis lwallShad V.! 0)
|
||||
-- $= Vector3 x y z
|
||||
glUniform3f (_shadUnis' lwallShad V.! 0) x y z
|
||||
bindVertexArrayObject $= lwallShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
--bindVertexArrayObject $= lwallShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode $ _shadPrim' lwallShad)
|
||||
0
|
||||
@@ -95,7 +96,8 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
|
||||
glUseProgram (_shadProg' llinesShad)
|
||||
glUniform3f (_shadUnis' llinesShad V.! 0) x y z
|
||||
glUniform1f (_shadUnis' llinesShad V.! 1) rad
|
||||
bindVertexArrayObject $= Just (_vaoName $ _shadVAO' llinesShad)
|
||||
--bindVertexArrayObject $= Just (_vaoName $ _shadVAO' llinesShad)
|
||||
glBindVertexArray (_vaoName $ _shadVAO' llinesShad)
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ _shadPrim' llinesShad)
|
||||
(fromIntegral nSils)
|
||||
@@ -107,7 +109,8 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
|
||||
--uniform (_shadUnis lcapShad V.! 0) $= Vector3 x y z
|
||||
glUseProgram (_shadProg' lcapShad)
|
||||
glUniform3f (_shadUnis' lcapShad V.! 0) x y z
|
||||
bindVertexArrayObject $= lcapShad ^? shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
|
||||
--bindVertexArrayObject $= lcapShad ^? shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
|
||||
glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ _shadPrim' lcapShad)
|
||||
(fromIntegral nCaps)
|
||||
@@ -128,7 +131,8 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
|
||||
glUseProgram (ltextShad ^. shadProg') --Just (_shadProg ltextShad)
|
||||
glUniform3f (_shadUnis' ltextShad V.! 0) x y z
|
||||
glUniform4f (_shadUnis' ltextShad V.! 1) r g b rad
|
||||
bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
|
||||
--bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
|
||||
glBindVertexArray $ ltextShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode (_shadPrim' ltextShad))
|
||||
0
|
||||
|
||||
+5
-2
@@ -7,6 +7,7 @@ module Shader
|
||||
, pokeBindFoldable
|
||||
, pokeBindFoldableLayer
|
||||
) where
|
||||
import Control.Lens
|
||||
import Shader.Data
|
||||
import Shader.Parameters
|
||||
import Shader.ExtraPrimitive
|
||||
@@ -27,7 +28,8 @@ drawShaderLay l countsVector shadIn fs = do
|
||||
i <- UMV.read countsVector shadIn
|
||||
--currentProgram $= Just (_shadProg' fs)
|
||||
glUseProgram (_shadProg' fs)
|
||||
bindVertexArrayObject $= Just (_vaoName $ _shadVAO' fs)
|
||||
glBindVertexArray $ fs ^. shadVAO' . vaoName
|
||||
--bindVertexArrayObject $= Just (_vaoName $ _shadVAO' fs)
|
||||
case _shadTex' fs of
|
||||
Just ShaderTexture{_textureObject = txo} --, _textureTarget = tt}
|
||||
-- -> textureBinding Texture2D $= Just txo
|
||||
@@ -44,7 +46,8 @@ drawShader :: FullShader' -> Int -> IO ()
|
||||
drawShader fs i = do
|
||||
--currentProgram $= Just (_shadProg fs)
|
||||
glUseProgram (_shadProg' fs)
|
||||
bindVertexArrayObject $= Just (_vaoName $ _shadVAO' fs)
|
||||
glBindVertexArray $ fs ^. shadVAO' . vaoName
|
||||
--bindVertexArrayObject $= Just (_vaoName $ _shadVAO' fs)
|
||||
case _shadTex' fs of
|
||||
Just ShaderTexture{_textureObject = txo
|
||||
} --, _textureTarget = tt }
|
||||
|
||||
@@ -38,7 +38,7 @@ addTexture2D nlev minfilt magfilt texpath shad = do
|
||||
let texdata = convertRGBA8 cmap
|
||||
let wtex = fromIntegral $ imageWidth texdata
|
||||
htex = fromIntegral $ imageHeight texdata
|
||||
texname <- mglCreateSingle $ glCreateTextures GL_TEXTURE_2D 1
|
||||
texname <- mglCreateSingle $ glCreateTextures GL_TEXTURE_2D
|
||||
glTextureStorage2D texname nlev GL_RGBA8 wtex htex
|
||||
VS.unsafeWith (imageData texdata) $ \ptr -> do
|
||||
glTextureSubImage2D texname 0 0 0 wtex htex GL_RGBA GL_UNSIGNED_BYTE ptr
|
||||
@@ -69,7 +69,7 @@ addTextureArray texturePath shad = do
|
||||
print err
|
||||
Right cmap <- readImage texturePath
|
||||
let texdata = convertRGBA8 cmap
|
||||
texname <- mglCreateSingle $ glCreateTextures GL_TEXTURE_2D_ARRAY 1
|
||||
texname <- mglCreateSingle $ glCreateTextures GL_TEXTURE_2D_ARRAY
|
||||
glTextureStorage3D texname 3 GL_RGBA8 32 32 64
|
||||
VS.unsafeWith (imageData texdata) $ \ptr -> do
|
||||
glTextureSubImage3D texname 0 0 0 0 32 32 64 GL_RGBA GL_UNSIGNED_BYTE ptr
|
||||
|
||||
+11
-6
@@ -8,6 +8,7 @@ module Shader.Compile (
|
||||
setupVertexAttribPointer,
|
||||
) where
|
||||
|
||||
import GLHelp
|
||||
import Control.Monad
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.Unsafe as BU
|
||||
@@ -129,23 +130,27 @@ 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
|
||||
--theVAO <- genObjectName
|
||||
--bindVertexArrayObject $= Just theVAO
|
||||
vaoname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray vaoname
|
||||
theVBO <- setupVBO sizes
|
||||
return $
|
||||
VAO
|
||||
{ _vaoName = theVAO
|
||||
{ _vaoName = vaoname
|
||||
, _vaoVBO = theVBO
|
||||
}
|
||||
|
||||
setupVAOSized :: [Int] -> Int -> IO VAO
|
||||
setupVAOSized sizes ndraw = do
|
||||
theVAO <- genObjectName
|
||||
bindVertexArrayObject $= Just theVAO
|
||||
vaoname <- mglCreateSingle glGenVertexArrays
|
||||
glBindVertexArray vaoname
|
||||
-- theVAO <- genObjectName
|
||||
--bindVertexArrayObject $= Just theVAO
|
||||
theVBO <- setupVBOSized sizes ndraw
|
||||
return $
|
||||
VAO
|
||||
{ _vaoName = theVAO
|
||||
{ _vaoName = vaoname
|
||||
, _vaoVBO = theVBO
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ data FullShader' = FullShader'
|
||||
{- | Vertex array object: contains the reference to the object,
|
||||
and its buffer targets. -}
|
||||
data VAO = VAO
|
||||
{ _vaoName :: VertexArrayObject
|
||||
{ _vaoName :: GLuint
|
||||
, _vaoVBO :: VBO
|
||||
}
|
||||
{- | Vertex buffer object: contains the reference to the object,
|
||||
|
||||
Reference in New Issue
Block a user