Skip to content

Commit 6b4bace

Browse files
committed
More steps towards extension generation.
1 parent eea866e commit 6b4bace

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

RegistryProcessor/src/Main.hs

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ main = do
5252
Left msg -> putStrLn msg
5353
Right registry -> do
5454
CM.when (PrintFeature `elem` opts) $ do
55-
let modName = "Graphics.Rendering.OpenGL.Raw." ++
56-
capitalize (unProfileName profile) ++
55+
let relName = capitalize (unProfileName profile) ++
5756
show (major version) ++ show (minor version)
58-
(ts,es,cs) = fixedReplay api version profile registry
59-
printMod modName ts es cs
57+
modName = buildModulePath Nothing [relName]
58+
printMod modName $ fixedReplay api version profile registry
6059
CM.when (PrintTokens `elem` opts) $ do
6160
putStrLn "--------------------------------------------------------------------------------"
6261
putStrLn "-- |"
@@ -126,39 +125,44 @@ main = do
126125
| ext <- extensions registry
127126
, api `supports` extensionSupported ext
128127
, nameAndMods@(_,(_:_)) <- [nameAndModifications api ext] ]
129-
130-
let (profileDependent, profileIndependent) =
131-
L.partition (any (DM.isJust . modificationProfile) . snd) supportedExtensions
132-
putStrLn "======================================== profile-dependent extensions"
133-
CM.forM_ ["core", "compatibility"] $ \prof -> do
134-
CM.forM_ profileDependent $ \(n,mods) -> do
135-
let (_vendor, modName) = mangleExtensionName (extendExtensionName n (ProfileName prof))
136-
(ts,es,cs) = executeModifications api (ProfileName prof) registry mods
137-
printMod modName ts es cs
138-
139-
putStrLn "======================================== profile-independent extensions"
140-
CM.forM_ profileIndependent $ \(n,mods) -> do
141-
let (_vendor, modName) = mangleExtensionName n
142-
(ts,es,cs) = executeModifications api profile registry mods
143-
printMod modName ts es cs
144-
145-
extendExtensionName :: ExtensionName -> ProfileName -> ExtensionName
128+
CM.forM_ supportedExtensions $ \(n,mods) -> do
129+
let profileAndModName =
130+
if isProfileDependent (n,mods)
131+
then [(ProfileName p, extendExtensionName n p)
132+
| p <- ["core", "compatibility"] ]
133+
else [(profile, n)]
134+
CM.forM_ profileAndModName $ \(prof, modName) -> do
135+
printMod (mangleExtensionName modName) $
136+
executeModifications api prof registry mods
137+
138+
isProfileDependent :: (ExtensionName, [Modification]) -> Bool
139+
isProfileDependent = any (DM.isJust . modificationProfile) . snd
140+
141+
extendExtensionName :: ExtensionName -> String -> ExtensionName
146142
extendExtensionName n profile =
147-
ExtensionName . (++ ("_" ++ unProfileName profile)). unExtensionName $ n
143+
ExtensionName . (++ ("_" ++ profile)). unExtensionName $ n
144+
145+
mangleExtensionName :: ExtensionName -> String
146+
mangleExtensionName n = buildModulePath (Just vendor) extWords
147+
where ("GL":vendor:extWords) = splitBy (== '_') (unExtensionName n)
148+
149+
buildModulePath :: Maybe String -> [String] -> String
150+
buildModulePath mbVendor extWords =
151+
modulePath ++ "." ++
152+
maybe "" (\vendor -> fixVendor vendor ++ ".") mbVendor ++
153+
concat (zipWith fixExtensionWord extWords [0 ..])
148154

149-
mangleExtensionName :: ExtensionName -> (String,String)
150-
mangleExtensionName n = (vendor, modName)
151-
where ("GL":vendor:rest) = splitBy (== '_') (unExtensionName n)
152-
modName = "Graphics.Rendering.OpenGL.Raw." ++ fixVendor vendor ++ "." ++ concatMap fixExtensionWord rest
155+
modulePath :: String
156+
modulePath = "Graphics.Rendering.OpenGL.Raw"
153157

154158
fixVendor :: String -> String
155159
fixVendor v = case v of
156160
"3DFX" -> "ThreeDFX"
157161
_ -> v
158162

159-
fixExtensionWord :: String -> String
160-
fixExtensionWord w = case w of
161-
"422" -> "FourTwoTwo" -- !!!!!!!!!!!!!!!!!!!
163+
fixExtensionWord :: String -> Int -> String
164+
fixExtensionWord w pos = case w of
165+
"422" | pos == 0-> "FourTwoTwo"
162166
"64bit" -> "64Bit"
163167
"ES2" -> "ES2"
164168
"ES3" -> "ES3"
@@ -182,11 +186,11 @@ fixExtensionWord w = case w of
182186
"rg" -> "RG"
183187
"rgb" -> "RGB"
184188
"rgb10" -> "RGB10"
189+
"rgb32" -> "RGB32"
185190
"rgtc" -> "RGTC"
186191
"s3tc" -> "S3TC"
187192
"sRGB" -> "SRGB"
188193
"snorm" -> "SNorm"
189-
"tbuffer" -> "TBuffer"
190194
"texture3D" -> "Texture3D"
191195
"texture4D" -> "Texture4D"
192196
"vdpau" -> "VDPAU"
@@ -212,8 +216,8 @@ capitalize str = C.toUpper (head str) : map C.toLower (tail str)
212216
separate :: (a -> String) -> [a] -> String
213217
separate f = L.intercalate ",\n" . map (" " ++) . map f
214218

215-
printMod :: String -> [TypeName] -> [Enum'] -> [Command] -> IO ()
216-
printMod modName ts es cs= do
219+
printMod :: String -> ([TypeName], [Enum'], [Command]) -> IO ()
220+
printMod modName (ts, es, cs) = do
217221
putStrLn "--------------------------------------------------------------------------------"
218222
putStrLn "-- |"
219223
putStrLn $ "-- Module : " ++ modName
@@ -251,7 +255,7 @@ printMod modName ts es cs= do
251255
-- Annoyingly enough, the OpenGL registry doesn't contain any enums for
252256
-- OpenGL 1.0, so let's just use the OpenGL 1.1 ones. Furthermore, features
253257
-- don't explicitly list the types referenced by commands, so we add them.
254-
fixedReplay :: API -> Version -> ProfileName -> Registry -> ([TypeName],[Enum'],[Command])
258+
fixedReplay :: API -> Version -> ProfileName -> Registry -> ([TypeName], [Enum'], [Command])
255259
fixedReplay api version profile registry
256260
| api == API "gl" && version == read "1.0" = (ts', es11, cs)
257261
| otherwise = (ts', es, cs)
@@ -261,7 +265,7 @@ fixedReplay api version profile registry
261265

262266
-- Here is the heart of the feature construction logic: Chronologically replay
263267
-- the whole version history for the given API/version/profile triple.
264-
replay :: API -> Version -> ProfileName -> Registry -> ([TypeName],[Enum'],[Command])
268+
replay :: API -> Version -> ProfileName -> Registry -> ([TypeName], [Enum'], [Command])
265269
replay api version profile registry =
266270
executeModifications api profile registry modifications
267271
where modifications = concatMap modificationsFor history

0 commit comments

Comments
 (0)