Implement texture atlas, details on why it works unclear
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
module Shader.AuxAddition
|
||||
( addTexture
|
||||
, addTextureArray
|
||||
, addUniforms
|
||||
) where
|
||||
import Shader.Data
|
||||
|
||||
import Data.List.Extra
|
||||
import Foreign
|
||||
import Codec.Picture
|
||||
import qualified Data.Vector.Storable as V
|
||||
@@ -29,6 +31,31 @@ addTexture texturePath shad = do
|
||||
textureFilter Texture2D $= ((Linear',Just Linear') , Nearest)
|
||||
return $ shad & shaderTexture ?~ ShaderTexture {_textureObject = textureOb}
|
||||
|
||||
addTextureArray :: String -> FullShader -> IO (FullShader)
|
||||
addTextureArray texturePath shad = do
|
||||
Right cmap <- readImage texturePath
|
||||
let tex = convertRGBA8 cmap
|
||||
textureOb <- genObjectName
|
||||
textureBinding Texture2DArray $= Just textureOb
|
||||
let texData = tilesToLine 128 32 8 .
|
||||
V.toList $ imageData tex
|
||||
--wtex = fromIntegral $ imageWidth tex
|
||||
--htex = fromIntegral $ imageHeight tex
|
||||
withArray texData $ \ptr -> do
|
||||
texImage3D Texture2DArray NoProxy 0 RGBA8 (TextureSize3D 32 32 64) 0
|
||||
(PixelData RGBA UnsignedByte ptr)
|
||||
textureFilter Texture2DArray $= ((Linear',Just Linear') , Linear')
|
||||
generateMipmap' Texture2DArray
|
||||
return $ shad & shaderTexture ?~ ShaderTexture {_textureObject = textureOb}
|
||||
|
||||
-- I am completely unclear on why this works with its current parameters
|
||||
tilesToLine
|
||||
:: Int -- ^ Tile width
|
||||
-> Int -- ^ Tile height
|
||||
-> Int -- ^ Number of tiles per line
|
||||
-> [a]
|
||||
-> [a]
|
||||
tilesToLine w h n = concat . concat . transpose . chunksOf n . chunksOf w
|
||||
|
||||
addUniforms :: [String] -> FullShader -> IO (FullShader)
|
||||
addUniforms uniStrings shad = do
|
||||
|
||||
Reference in New Issue
Block a user