summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2016-02-13 15:33:21 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2016-02-13 15:33:21 +0100
commit8e20bf8f814f22b7de0cba325e87e381f3e32a28 (patch)
treeaabec778eb1131fd602cd546abad4fe2402004cb /src
parent5ca4d7845df57242e4a2c85030693faab9b17822 (diff)
improve uploadTexture2DToGPU'
Diffstat (limited to 'src')
-rw-r--r--src/LambdaCube/GL/Data.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/LambdaCube/GL/Data.hs b/src/LambdaCube/GL/Data.hs
index 3e0f963..c1e2737 100644
--- a/src/LambdaCube/GL/Data.hs
+++ b/src/LambdaCube/GL/Data.hs
@@ -63,10 +63,10 @@ disposeTexture (TextureData to) = withArray [to] $ glDeleteTextures 1
63 63
64-- FIXME: Temporary implemenation 64-- FIXME: Temporary implemenation
65uploadTexture2DToGPU :: DynamicImage -> IO TextureData 65uploadTexture2DToGPU :: DynamicImage -> IO TextureData
66uploadTexture2DToGPU = uploadTexture2DToGPU' False True False 66uploadTexture2DToGPU = uploadTexture2DToGPU' True False True False
67 67
68uploadTexture2DToGPU' :: Bool -> Bool -> Bool -> DynamicImage -> IO TextureData 68uploadTexture2DToGPU' :: Bool -> Bool -> Bool -> Bool -> DynamicImage -> IO TextureData
69uploadTexture2DToGPU' isSRGB isMip isClamped bitmap' = do 69uploadTexture2DToGPU' isFiltered isSRGB isMip isClamped bitmap' = do
70 let bitmap = case bitmap' of 70 let bitmap = case bitmap' of
71 ImageRGB8 i@(Image w h _) -> bitmap' -- pixelFoldMap (\(PixelRGB8 r g b) -> [PixelRGBA8 r g b maxBound]) i 71 ImageRGB8 i@(Image w h _) -> bitmap' -- pixelFoldMap (\(PixelRGB8 r g b) -> [PixelRGBA8 r g b maxBound]) i
72 ImageRGBA8 i@(Image w h _) -> bitmap' -- pixelFoldMap (\(PixelRGBA8 r g b a) -> [PixelRGBA8 r g b a]) i 72 ImageRGBA8 i@(Image w h _) -> bitmap' -- pixelFoldMap (\(PixelRGBA8 r g b a) -> [PixelRGBA8 r g b a]) i
@@ -93,16 +93,17 @@ uploadTexture2DToGPU' isSRGB isMip isClamped bitmap' = do
93 withBitmap (ImageRGB8 (Image w h v)) f = SV.unsafeWith v $ f (w,h) 3 0 93 withBitmap (ImageRGB8 (Image w h v)) f = SV.unsafeWith v $ f (w,h) 3 0
94 withBitmap (ImageRGBA8 (Image w h v)) f = SV.unsafeWith v $ f (w,h) 4 0 94 withBitmap (ImageRGBA8 (Image w h v)) f = SV.unsafeWith v $ f (w,h) 4 0
95 withBitmap _ _ = error "unsupported image type :(" 95 withBitmap _ _ = error "unsupported image type :("
96 texFilter = if isFiltered then GL_LINEAR else GL_NEAREST
96 wrapMode = case isClamped of 97 wrapMode = case isClamped of
97 True -> GL_CLAMP_TO_EDGE 98 True -> GL_CLAMP_TO_EDGE
98 False -> GL_REPEAT 99 False -> GL_REPEAT
99 (minFilter,maxLevel) = case isMip of 100 (minFilter,maxLevel) = case isFiltered && isMip of
100 False -> (GL_LINEAR,0) 101 False -> (texFilter,0)
101 True -> (GL_LINEAR_MIPMAP_LINEAR, floor $ log (fromIntegral $ max width height) / log 2) 102 True -> (GL_LINEAR_MIPMAP_LINEAR, floor $ log (fromIntegral $ max width height) / log 2)
102 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_S $ fromIntegral wrapMode 103 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_S $ fromIntegral wrapMode
103 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_T $ fromIntegral wrapMode 104 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_T $ fromIntegral wrapMode
104 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER $ fromIntegral minFilter 105 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER $ fromIntegral minFilter
105 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER $ fromIntegral GL_LINEAR 106 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER $ fromIntegral texFilter
106 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_BASE_LEVEL 0 107 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_BASE_LEVEL 0
107 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAX_LEVEL $ fromIntegral maxLevel 108 glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAX_LEVEL $ fromIntegral maxLevel
108 withBitmap bitmap $ \(w,h) nchn 0 ptr -> do 109 withBitmap bitmap $ \(w,h) nchn 0 ptr -> do