diff options
Diffstat (limited to 'Graphics')
-rw-r--r-- | Graphics/Glyph/ExtendedGL.hs | 30 | ||||
-rw-r--r-- | Graphics/Glyph/Shaders.hs | 34 | ||||
-rw-r--r-- | Graphics/Glyph/Util.hs | 4 |
3 files changed, 56 insertions, 12 deletions
diff --git a/Graphics/Glyph/ExtendedGL.hs b/Graphics/Glyph/ExtendedGL.hs index d42e973..7742ba8 100644 --- a/Graphics/Glyph/ExtendedGL.hs +++ b/Graphics/Glyph/ExtendedGL.hs @@ -4,6 +4,14 @@ import Graphics.Rendering.OpenGL import Graphics.Rendering.OpenGL.Raw.Core31 import Graphics.Rendering.OpenGL.Raw.ARB +import Foreign.Marshal.Alloc +import Foreign.Ptr +import Foreign.Storable +import Foreign.C.Types + +import System.IO.Unsafe +import Control.Monad + marshalPrimitiveMode :: PrimitiveMode -> GLenum marshalPrimitiveMode x = case x of Points -> 0x0 @@ -24,3 +32,25 @@ vertexAttributeDivisor :: AttribLocation -> SettableStateVar GLuint vertexAttributeDivisor (AttribLocation loc) = makeSettableStateVar $ \val -> glVertexAttribDivisor loc val + +patchVertices :: (Integral a) => SettableStateVar a +patchVertices = + makeSettableStateVar $ \val -> + glPatchParameteri gl_PATCH_VERTICES $ fromIntegral val + +maxPatchVertices :: IO CInt +maxPatchVertices = + alloca $ \ptr -> do + glGetIntegerv gl_MAX_PATCH_VERTICES ptr + peek ptr + +getGLVersion :: IO String +getGLVersion = + let lift2 (a,b) = do + x <- a ; y <- b ; return (x,y) + in + alloca $ \ptr1 -> alloca $ \ptr2 -> do + glGetIntegerv gl_MAJOR_VERSION ptr1 + glGetIntegerv gl_MINOR_VERSION ptr2 + (v1,v2) <- lift2 (peek ptr1, peek ptr2) + return ("OpenGL " ++ show v1 ++ "." ++ show v2) diff --git a/Graphics/Glyph/Shaders.hs b/Graphics/Glyph/Shaders.hs index 01f27b6..c11886d 100644 --- a/Graphics/Glyph/Shaders.hs +++ b/Graphics/Glyph/Shaders.hs @@ -89,21 +89,31 @@ getUniformLocation name = get currentProgram >>= maybe (return Nothing) (\prog -> liftM Just (get $ uniformLocation prog name) ) -loadProgramSafe :: - (IsShaderSource a, - IsShaderSource b, - IsShaderSource c) => - a -> b -> Maybe c -> IO (Maybe Program) -loadProgramSafe vert frag geom = do +loadProgramFullSafe :: + (IsShaderSource tc, + IsShaderSource te, + IsShaderSource g, + IsShaderSource v, + IsShaderSource f) => Maybe (tc,te) -> Maybe g -> v -> f -> IO (Maybe Program) +loadProgramFullSafe tess geometry vert frag = do + let (ts1,ts2) = distribMaybe tess shaders <- sequence $ catMaybes [ - Just $ loadShader VertexShader vert, - Just $ loadShader FragmentShader frag, - liftM (loadShader GeometryShader) geom] - -- mapM_ (putStrLn . fst) shaders - (linklog, maybeProg) <- createShaderProgramSafe shaders - + Just $ loadShader VertexShader vert, + Just $ loadShader FragmentShader frag, + liftM (loadShader GeometryShader) geometry, + liftM (loadShader TessControlShader) ts1, + liftM (loadShader TessEvaluationShader) ts2] + (linklog,maybeProg) <- createShaderProgramSafe shaders if isNothing maybeProg then do putStrLn "Failed to link program" putStrLn linklog return Nothing else return maybeProg + + +loadProgramSafe :: + (IsShaderSource a, + IsShaderSource b, + IsShaderSource c) => + a -> b -> Maybe c -> IO (Maybe Program) +loadProgramSafe vert frag geom = loadProgramFullSafe (Nothing::Maybe(String,String)) geom vert frag diff --git a/Graphics/Glyph/Util.hs b/Graphics/Glyph/Util.hs index 61cd3f0..78fd053 100644 --- a/Graphics/Glyph/Util.hs +++ b/Graphics/Glyph/Util.hs @@ -306,3 +306,7 @@ untilM2 cond ini bod = do for :: [a] -> (a -> b) -> [b] for = flip map + +distribMaybe :: Maybe (a,b) -> (Maybe a, Maybe b) +distribMaybe Nothing = (Nothing,Nothing) +distribMaybe (Just (a,b)) = (Just a, Just b) |