Play with floor textures
This commit is contained in:
@@ -3,7 +3,8 @@ module Shader.AuxAddition
|
||||
, vaddTextureNoFilter
|
||||
, addTextureArray
|
||||
, addUniforms
|
||||
, initTexture
|
||||
, initTexture2D
|
||||
, initTexture2DArray
|
||||
, tilesToLine -- ^ kept in case it is needed in the future
|
||||
) where
|
||||
import Data.Preload.Render
|
||||
@@ -59,12 +60,12 @@ addTexture2D nlev minfilt magfilt texpath shad = do
|
||||
-- glTextureParameteri texname GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
|
||||
-- return $ shad & shadTex' ?~ ShaderTexture
|
||||
-- {_textureObject = texname }
|
||||
initTexture
|
||||
initTexture2D
|
||||
:: GLint -- number of mipmap levels
|
||||
-> GLenum -- minfilter
|
||||
-> GLenum -- magfilter
|
||||
-> String -> IO TO
|
||||
initTexture nlev minfilt magfilt fp = do
|
||||
initTexture2D nlev minfilt magfilt fp = do
|
||||
Right cmap <- readImage fp
|
||||
let texdata = convertRGBA8 cmap
|
||||
let wtex = fromIntegral $ imageWidth texdata
|
||||
@@ -78,6 +79,42 @@ initTexture nlev minfilt magfilt fp = do
|
||||
glTextureParameteri texname GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
|
||||
return $ TO texname
|
||||
|
||||
-- assumes the texture slices are squares with sides as long as the input is
|
||||
-- wide
|
||||
initTexture2DArray
|
||||
:: GLint -- number of mipmap levels
|
||||
-> GLenum -- minfilter
|
||||
-> GLenum -- magfilter
|
||||
-> String -> IO TO
|
||||
initTexture2DArray nlev minfilt magfilt fp = do
|
||||
Right cmap <- readImage fp
|
||||
let texdata = convertRGBA8 cmap
|
||||
let wtex = fromIntegral $ imageWidth texdata
|
||||
htex = fromIntegral $ imageHeight texdata
|
||||
z = htex `div` wtex
|
||||
checkGLError
|
||||
putStrLn "x"
|
||||
texname <- mglCreate $ glCreateTextures GL_TEXTURE_2D_ARRAY
|
||||
checkGLError
|
||||
putStrLn "y"
|
||||
glTextureStorage3D texname nlev GL_RGBA8 wtex wtex z
|
||||
checkGLError
|
||||
putStrLn "z"
|
||||
VS.unsafeWith (imageData texdata) $ \ptr -> do
|
||||
glTextureSubImage3D texname 0 0 0 0 wtex wtex z GL_RGBA GL_UNSIGNED_BYTE ptr
|
||||
checkGLError
|
||||
putStrLn "i"
|
||||
glGenerateTextureMipmap texname
|
||||
checkGLError
|
||||
putStrLn "q"
|
||||
glTextureParameteri texname GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt)
|
||||
checkGLError
|
||||
putStrLn "w"
|
||||
glTextureParameteri texname GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
|
||||
checkGLError
|
||||
putStrLn "e"
|
||||
return $ TO texname
|
||||
|
||||
-- | for transforming a 256x256 image containing 64 tiles of 16x16 pixels into
|
||||
-- an image that was directly readable by glTexSubImage3D, used the
|
||||
-- transformation tilesToLine 8 128 on the underlying pixels.
|
||||
|
||||
@@ -11,7 +11,7 @@ import Foreign
|
||||
|
||||
pokeTile :: Ptr Float -> Int -> Tile -> IO Int
|
||||
pokeTile ptr i t@Tile { _tilePoly = ps } = do
|
||||
foldM (pokeTileVerx ttan (_tileZ t) ptr) i $ triangulate $ zip ps (tileTexCoords t)
|
||||
foldM (pokeTileVerx ttan (_tileArrayZ t) ptr) i $ triangulate $ zip ps (tileTexCoords t)
|
||||
where
|
||||
ttan = _tileTangentPos t - _tileZero t
|
||||
|
||||
|
||||
Reference in New Issue
Block a user