Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
*.[oa]
*.hi
dist/
Setup.*
Setup
!Setup.hs
*~
*.swp
cabal-dev
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: haskell
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Build Status](https://travis-ci.org/Laar/opengl-api.png)](https://travis-ci.org/Laar/opengl-api)
# opengl-api

Represent and parse spec files from the OpenGL [registry][].
Expand Down
26 changes: 20 additions & 6 deletions Text/OpenGL/Api.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Text.OpenGL.Api where

import Data.List (partition)
import Data.List (partition, find)
import qualified Data.Map as M

import qualified Text.OpenGL.Spec as Spec
Expand All @@ -13,6 +13,7 @@ data Function = Function
, funName :: String
, funParameters :: [Parameter]
, funCategory :: Category
, funProfile :: (Maybe Profile)
, funOldCategory :: Maybe Category
, funSubcategory :: Maybe String
, funVersion :: Maybe (Int,Int)
Expand Down Expand Up @@ -47,6 +48,7 @@ mkFunction a b (Spec.Return r:ps) =
, funName = a
, funParameters = args
, funCategory = c
, funProfile = extractProfile ps''
, funOldCategory = c'
, funSubcategory = extractSubcategory ps''
, funVersion = extractFVersion ps''
Expand All @@ -73,11 +75,17 @@ mkFunction a b (Spec.Return r:ps) =
f _ = False
h (Spec.Category _ _) = True
h _ = False
args = zipWith g b params
g x0 (Spec.Param x1 (Spec.ParamType x y z))
| x0 == x1 = Parameter x0 x y z
| otherwise = error "argument and parameter don't match"
g _ _ = error "can't happen"
args = map (lookupParam params) b
lookupParam pars arg =
case find (\(Spec.Param x1 _) -> x1 == arg) pars of
Just (Spec.Param _ (Spec.ParamType x y z)) -> Parameter arg x y z
Nothing -> error $ "opengl-api -> mkFunction: parameter not found " ++ arg ++ " for function " ++ a
Just _ -> error "opengl-api -> mkFunction: impossible"
-- args = zipWith g b params
-- g x0 (Spec.Param x1 (Spec.ParamType x y z))
-- | x0 == x1 = Parameter x0 x y z
-- | otherwise = error "argument and parameter don't match"
-- g _ _ = error "can't happen"

mkFunction _ _ _ =
error "The list of properties doesn't begin with the return type."
Expand Down Expand Up @@ -114,6 +122,12 @@ extractSubcategory l = case filter isSubcategory l of
[Spec.Subcategory s] -> Just s
_ -> error "More than one element"

extractProfile :: [Spec.Prop] -> Maybe Profile
extractProfile l = case filter isProfile l of
[] -> Nothing
[Spec.FProfile p] -> Just p
_ -> error "More than one element"

extractFVersion :: [Spec.Prop] -> Maybe (Int, Int)
extractFVersion l = case filter isFVersion l of
[] -> Nothing
Expand Down
6 changes: 5 additions & 1 deletion Text/OpenGL/ExtHeader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
-- of using the one provided by Text.OpenGL.Api). This is necessary as
-- the passthru lines get output to the glext.h file (the representation
-- used in Text.OpenGL.Api drops those lines).
--
-- TODO: The profiles are dropped, is this correct
module Text.OpenGL.ExtHeader where

import Data.List (intersperse, nubBy)
Expand Down Expand Up @@ -149,7 +151,7 @@ showValue v = case v of
Spec.Deci i -> show i
Spec.Identifier x -> x

showHex' :: Integral a => Int -> a -> String
showHex' :: (Show a, Integral a) => Int -> a -> String
showHex' l i = replicate (l - length h) '0' ++ h
where h = map toUpper (showHex i "")

Expand All @@ -162,9 +164,11 @@ groupEnums xs = go xs
go (Spec.Passthru _ : _) = error "encountering a Passthru before a Start"
go (Spec.Enum _ _ _ : _) = error "encoutering an Enum before a Start"
go (Spec.Use _ _ : _) = error "encoutering a Use before a Start"
go (Spec.Profile _ : _) = error "encountering a Profile before a Start"
go [] = []
goS e (Spec.Comment _ : zs) = goS e zs
goS e (Spec.BlankLine : zs) = goS e zs
goS e (Spec.Profile _ : zs) = goS e zs
goS e (Spec.Start se _ : zs) = e : goS (se, []) zs
goS (se, es) (Spec.Passthru str : zs) =
goS (se, (es++[EPassthru str])) zs
Expand Down
2 changes: 2 additions & 0 deletions Text/OpenGL/GenChecks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ cFormat tm (Parameter _ t _ p) = t'
GLbyte -> "%d"
GLchar -> "%d"
GLcharARB -> "%d"
GLcharStarConst -> "%p"
GLclampd -> "%f"
GLclampf -> "%f"
GLdouble -> "%f"
Expand Down Expand Up @@ -161,6 +162,7 @@ cFormat tm (Parameter _ t _ p) = t'
UnderscoreGLfuncptr -> "%p"
GLvoidStarConst -> "%p"
GLvdpauSurfaceNV -> "%td" -- typedef GLintptr GLvdpauSurfaceNV;
GLdebugproc -> "GLDEBUGPROC"
GLdebugprocAMD -> "GLDEBUGPROCAMD"
GLdebugprocARB -> "GLDEBUGPROCARB"

Loading