Skip to content

Commit cf05bdf

Browse files
committed
Fixes after shaderSource change.
1 parent 5be6d71 commit cf05bdf

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

examples/Misc/SmoothOpenGL3.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
-}
77

88
import Control.Monad
9+
import qualified Data.ByteString as B
910
import Data.List
11+
import qualified Data.Text as T
12+
import qualified Data.Text.Encoding as TE
1013
import Foreign.Marshal.Array
1114
import Foreign.Ptr
1215
import Foreign.Storable
@@ -67,8 +70,11 @@ initBuffer = do
6770
checkError "initBuffer"
6871
return bufferObject
6972

70-
vertexShaderSource :: String
71-
vertexShaderSource = unlines [
73+
packUtf8 :: String -> B.ByteString
74+
packUtf8 = TE.encodeUtf8 . T.pack
75+
76+
vertexShaderSource :: B.ByteString
77+
vertexShaderSource = packUtf8 . unlines $ [
7278
"#version 140",
7379
"uniform mat4 fg_ProjectionMatrix;",
7480
"in vec4 fg_Color;",
@@ -80,8 +86,8 @@ vertexShaderSource = unlines [
8086
" gl_Position = fg_ProjectionMatrix * fg_Vertex;",
8187
"}" ]
8288

83-
fragmentShaderSource :: String
84-
fragmentShaderSource = unlines [
89+
fragmentShaderSource :: B.ByteString
90+
fragmentShaderSource = packUtf8 . unlines $ [
8591
"#version 140",
8692
"smooth in vec4 fg_SmoothColor;",
8793
"out vec4 fg_FragColor;",
@@ -100,7 +106,7 @@ checked action getStatus getInfoLog message object = do
100106
compileAndCheck :: Shader -> IO ()
101107
compileAndCheck = checked compileShader compileStatus shaderInfoLog "compile"
102108

103-
compileShaderSource :: ShaderType -> String -> IO Shader
109+
compileShaderSource :: ShaderType -> B.ByteString -> IO Shader
104110
compileShaderSource st source = do
105111
shader <- createShader st
106112
shaderSource shader $= source

examples/OrangeBook/ogl2brick/Brick.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Prelude hiding ( sum )
99
import Control.Applicative
1010
import Control.Exception ( IOException, catch )
1111
import Control.Monad
12+
import qualified Data.ByteString as B
1213
import Data.Foldable ( Foldable, sum )
1314
import Data.IORef
1415
import System.Exit
@@ -291,7 +292,7 @@ checkGLSLSupport = do
291292

292293
readAndCompileShader :: ShaderType -> FilePath -> IO Shader
293294
readAndCompileShader st filePath = do
294-
src <- readFile filePath
295+
src <- B.readFile filePath
295296
shader <- createShader st
296297
shaderSource shader $= src
297298
compileShader shader

examples/RedBook8/common/LoadShaders.hs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,42 @@
1414
--------------------------------------------------------------------------------
1515

1616
module LoadShaders (
17-
ShaderSource'(..), ShaderInfo(..), loadShaders
17+
ShaderSource(..), ShaderInfo(..), loadShaders
1818
) where
1919

2020
import Control.Exception
2121
import Control.Monad
22+
import qualified Data.ByteString as B
23+
import qualified Data.Text as T
24+
import qualified Data.Text.Encoding as TE
2225
import Graphics.Rendering.OpenGL
2326

2427
--------------------------------------------------------------------------------
2528

2629
-- | The source of the shader source code.
2730

28-
data ShaderSource' =
29-
FileSource FilePath
30-
-- ^ The shader source code is located in the file at the given 'FilePath'.
31+
data ShaderSource =
32+
ByteStringSource B.ByteString
33+
-- ^ The shader source code is directly given as a 'B.ByteString'.
3134
| StringSource String
3235
-- ^ The shader source code is directly given as a 'String'.
36+
| FileSource FilePath
37+
-- ^ The shader source code is located in the file at the given 'FilePath'.
3338
deriving ( Eq, Ord, Show )
3439

35-
getSource :: ShaderSource' -> IO String
36-
getSource (FileSource path) = readFile path
37-
getSource (StringSource src) = return src
40+
getSource :: ShaderSource -> IO B.ByteString
41+
getSource (ByteStringSource bs) = return bs
42+
getSource (StringSource str) = return $ packUtf8 str
43+
getSource (FileSource path) = B.readFile path
44+
45+
packUtf8 :: String -> B.ByteString
46+
packUtf8 = TE.encodeUtf8 . T.pack
3847

3948
--------------------------------------------------------------------------------
4049

4150
-- | A description of a shader: The type of the shader plus its source code.
4251

43-
data ShaderInfo = ShaderInfo ShaderType ShaderSource'
52+
data ShaderInfo = ShaderInfo ShaderType ShaderSource
4453
deriving ( Eq, Ord, Show )
4554

4655
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)