Use texture array for character rendering, condense rendering

This commit is contained in:
2023-03-23 14:08:07 +00:00
parent 68b43f29ff
commit 3350a8dc30
9 changed files with 80 additions and 42 deletions
+15
View File
@@ -2,6 +2,7 @@ module Shader.AuxAddition
( addSamplerTexture2D
, vaddTextureNoFilter
, addTextureArray
, addTextureArray'
, initTexture2D
, initTexture2DArray
, tilesToLine
@@ -127,6 +128,20 @@ addTextureArray texturePath (shad,vbo) = do
return (shad & shaderTextures .:~ TO texname
, vbo)
addTextureArray' :: String -> GLsizei -> GLsizei -> GLsizei -> GLsizei -> GLenum -> GLenum
-> Shader -> IO Shader
addTextureArray' fp nlev w h d minfilt magfilt shad = do
Right cmap <- readImage fp
let texdata = convertRGBA8 cmap
texname <- mglCreate $ glCreateTextures GL_TEXTURE_2D_ARRAY
glTextureStorage3D texname nlev GL_RGBA8 w h d
VS.unsafeWith (imageData texdata) $ \ptr -> do
glTextureSubImage3D texname 0 0 0 0 w h d GL_RGBA GL_UNSIGNED_BYTE ptr
glGenerateTextureMipmap texname
glTextureParameteri texname GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt)
glTextureParameteri texname GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
return (shad & shaderTextures .:~ TO texname )
tilesToLine
:: Int -- ^ Parameter a
-> Int -- ^ Parameter b
+11 -11
View File
@@ -34,15 +34,15 @@ pokeVerxs ::
pokeVerxs vbos count = VFSM.mapM_ (pokeVerx vbos count) . VFSM.fromList
pokeVerx :: MV.MVector (PrimState IO) (Shader, VBO) -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
pokeVerx vbos offsets Verx{_vxPos = thePos, _vxCol = theCol, _vxExt = ext, _vxShadNum = theShadNum} = do
pokeVerx vbos offsets Verx{_vxPos = thePos, _vxCol = theCol, _vxExt = ext, _vxShadNum = shadnum} = do
typeOff <- UMV.unsafeRead offsets sn
basePtr <- _vboPtr . snd <$> MV.unsafeRead vbos sn
let thePtr = plusPtr basePtr (typeOff * pokeStride sn * floatSize)
let thePtr = plusPtr basePtr (typeOff * pokeStride shadnum * floatSize)
poke34 thePtr thePos theCol
pokeArrayOff thePtr 7 ext
UMV.unsafeModify offsets (+ 1) sn
where
sn = _unShadNum theShadNum
sn = _unShadNum shadnum
pokeWallsWindows ::
Ptr Float ->
@@ -416,21 +416,21 @@ pokeLayVerx vbos counts vx = do
pokeArrayOff thePtr 7 (_vxExt vx)
UMV.unsafeModify counts (+ 1) vecPos
where
sn = _unShadNum (_vxShadNum vx)
sn = _unShadNum shadnum
shadnum = _vxShadNum vx
vecPos = theLayer * numLayers + sn
theLayer = layerNum $ _vxLayer vx
thePos = _vxPos vx
theCol = _vxCol vx
layOff = theLayer * numSubElements
theStride = pokeStride sn
theStride = pokeStride shadnum
pokeStride :: Int -> Int
pokeStride :: ShadNum -> Int
{-# INLINE pokeStride #-}
pokeStride 0 = 7
pokeStride 1 = 9
pokeStride 2 = 10
pokeStride 3 = 7
pokeStride _ = undefined
pokeStride PolyShad = 7
pokeStride TextShad = 11
pokeStride ArcShad = 10
pokeStride EllShad = 7
poke34 :: Ptr Float -> Point3 -> Point4 -> IO ()
{-# INLINE poke34 #-}