@@ -17,7 +17,7 @@ main :: IO ()
1717main = do
1818 [registryPath] <- E. getArgs
1919 let api = API " gl"
20- res <- fmap parseRegistry $ readFile registryPath
20+ res <- parseRegistry toEnumType `fmap` readFile registryPath
2121 case res of
2222 Left msg -> SI. hPutStrLn SI. stderr msg
2323 Right registry -> do
@@ -106,28 +106,36 @@ printFunctions api registry sigMap = do
106106
107107printExtensions :: API -> Registry -> IO ()
108108printExtensions api registry = do
109- -- only consider non-empty supported extensions/modifications for the given API
110- let supportedExtensions =
111- [ nameAndMods
112- | ext <- extensions registry
113- , api `supports` extensionSupported ext
114- , nameAndMods@ (_,(_: _)) <- [nameAndModifications api ext] ]
115- CM. forM_ supportedExtensions $ \ (n,mods) -> do
116- let (" GL" : vendor: extWords) = splitBy (== ' _' ) (unExtensionName n)
117- modSuff = concat (zipWith fixExtensionWord extWords [0 .. ])
109+ CM. forM_ (supportedExtensions api registry) $ \ (n,mods) -> do
110+ let modSuff = concat (zipWith fixExtensionWord (splitBy (== ' _' ) (extensionNameName n)) [0 .. ])
118111 profileAndModuleNameSuffix =
119112 if any isProfileDependent mods
120113 then [(ProfileName p, modSuff ++ capitalize p)
121114 | p <- [" core" , " compatibility" ] ]
122115 else [(ProfileName " core" , modSuff)] -- the actual profile doesn't matter
123- ext = L. intercalate " _" extWords
124116 comment = [" The <https://www.opengl.org/registry/specs/" ++
125- fixRegistryPath (vendor ++ " /" ++ ext ) ++ " .txt " ++
126- vendor ++ " _" ++ ext ++ " > extension." ]
117+ fixRegistryPath (extensionNameCategory n ++ " /" ++ extensionNameName n ) ++ " .txt " ++
118+ extensionNameCategory n ++ " _" ++ extensionNameName n ++ " > extension." ]
127119 CM. forM_ profileAndModuleNameSuffix $ \ (prof, moduleNameSuffix) ->
128- printExtension (Just vendor ) moduleNameSuffix comment $
120+ printExtension (Just (extensionNameCategory n) ) moduleNameSuffix comment $
129121 executeModifications api prof registry mods
130122
123+ -- We only consider non-empty supported extensions/modifications for the given API.
124+ supportedExtensions :: API -> Registry -> [(ExtensionName , [Modification ])]
125+ supportedExtensions api registry =
126+ [ nameAndMods
127+ | ext <- extensions registry
128+ , api `supports` extensionSupported ext
129+ , nameAndMods@ (_,(_: _)) <- [nameAndModifications api ext] ]
130+ where nameAndModifications :: API -> Extension -> (ExtensionName , [Modification ])
131+ nameAndModifications api e =
132+ (extensionName e,
133+ [ conditionalModificationModification cm
134+ | cm <- extensionsRequireRemove e
135+ , api `matches` conditionalModificationAPI cm
136+ -- ARB_compatibility has an empty "require" element only
137+ , not . null . modificationInterfaceElements . conditionalModificationModification $ cm ])
138+
131139fixRegistryPath :: String -> String
132140fixRegistryPath path = case path of
133141 " 3DFX/multisample" -> " 3DFX/3dfx_multisample"
@@ -157,10 +165,10 @@ isProfileDependent :: Modification -> Bool
157165isProfileDependent = DM. isJust . modificationProfile
158166
159167startModule :: Maybe String -> String -> Maybe String -> [String ] -> (String -> SI. Handle -> IO () ) -> IO ()
160- startModule mbVendor moduleNameSuffix mbPragma comments action = do
168+ startModule mbCategory moduleNameSuffix mbPragma comments action = do
161169 let moduleNameParts =
162170 [" Graphics" , " Rendering" , " OpenGL" , " Raw" ] ++
163- maybe [] (\ vendor -> [fixVendor vendor ]) mbVendor ++
171+ maybe [] (\ category -> [fixCategory category ]) mbCategory ++
164172 [moduleNameSuffix]
165173 path = F. joinPath moduleNameParts `F.addExtension` " hs"
166174 moduleName = L. intercalate " ." moduleNameParts
@@ -169,8 +177,8 @@ startModule mbVendor moduleNameSuffix mbPragma comments action = do
169177 printModuleHeader h mbPragma moduleName comments
170178 action moduleName h
171179
172- fixVendor :: String -> String
173- fixVendor v = case v of
180+ fixCategory :: String -> String
181+ fixCategory v = case v of
174182 " 3DFX" -> " ThreeDFX"
175183 _ -> v
176184
@@ -214,15 +222,6 @@ fixExtensionWord w pos = case w of
214222 " ycrcba" -> " YCrCbA"
215223 _ -> capitalize w
216224
217- nameAndModifications :: API -> Extension -> (ExtensionName , [Modification ])
218- nameAndModifications api e =
219- (extensionName e,
220- [ conditionalModificationModification cm
221- | cm <- extensionsRequireRemove e
222- , api `matches` conditionalModificationAPI cm
223- -- ARB_compatibility has an empty "require" element only
224- , not . null . modificationInterfaceElements . conditionalModificationModification $ cm ])
225-
226225supports :: API -> Maybe [API ] -> Bool
227226_ `supports` Nothing = True
228227a `supports` Just apis = a `elem` apis
@@ -235,8 +234,8 @@ separate f = L.intercalate ",\n" . map (" " ++) . map f
235234
236235-- Note that we handle features just like extensions.
237236printExtension :: Maybe String -> String -> [String ] -> ([TypeName ], [Enum' ], [Command ]) -> IO ()
238- printExtension mbVendor moduleNameSuffix comment (ts, es, cs) =
239- startModule mbVendor moduleNameSuffix Nothing comment $ \ moduleName h -> do
237+ printExtension mbCategory moduleNameSuffix comment (ts, es, cs) =
238+ startModule mbCategory moduleNameSuffix Nothing comment $ \ moduleName h -> do
240239 SI. hPutStrLn h $ " module " ++ moduleName ++ " ("
241240 CM. unless (null ts) $ do
242241 SI. hPutStrLn h " -- * Types"
@@ -430,3 +429,35 @@ showComment name sigElem
430429
431430inlineCode :: String -> String
432431inlineCode s = " @" ++ s ++ " @"
432+
433+ -- TODO: Use Either instead of error below?
434+ toEnumType :: ToEnumType
435+ toEnumType eNamespace eGroup eType suffix = TypeName $
436+ case (eNamespace, eGroup, eType, unTypeSuffix `fmap` suffix) of
437+ -- glx.xml
438+ (Just " GLXStrings" , _, _, _) -> " String"
439+ (Just (' G' : ' L' : ' X' : _), _, _, _) -> " CInt"
440+
441+ -- egl.xml
442+ -- TODO: EGLenum for EGL_OPENGL_API, EGL_OPENGL_ES_API, EGL_OPENVG_API, EGL_OPENVG_IMAGE?
443+ (Just (' E' : ' G' : ' L' : _), _, Nothing , Just " ull" ) -> " EGLTime"
444+ (Just (' E' : ' G' : ' L' : _), _, _, _) -> " EGLint"
445+
446+ -- wgl.xml
447+ (Just " WGLLayerPlaneMask" , _, _, _) -> " UINT"
448+ (Just " WGLColorBufferMask" , _, _, _) -> " UINT"
449+ (Just " WGLContextFlagsMask" , _, _, _) -> " INT"
450+ (Just " WGLContextProfileMask" , _, _, _) -> " INT"
451+ (Just " WGLImageBufferMaskI3D" , _, _, _) -> " UINT"
452+ (Just " WGLDXInteropMaskNV" , _, _, _) -> " GLenum"
453+ (Just (' W' : ' G' : ' L' : _), _, _, _) -> " CInt"
454+
455+ -- gl.xml
456+ (Just " OcclusionQueryEventMaskAMD" , _, _, _) -> " GLuint"
457+ (Just " GL" , Just " PathRenderingTokenNV" , _, _) -> " GLubyte"
458+ (Just " GL" , _, Just " bitmask" , _) -> " GLbitfield"
459+ (Just " GL" , _, Nothing , Just " u" ) -> " GLuint"
460+ (Just " GL" , _, Nothing , Just " ull" ) -> " GLuint64"
461+ (Just " GL" , _, Nothing , Nothing ) -> " GLenum"
462+
463+ (_, _, _, _) -> error " can't determine enum type"
0 commit comments