11 // ////////////////////////////////////////////////////////////////////////// //
20 string
getName (Element nr
) {
21 auto ne
= nr
.querySelector("name");
23 auto res
= ne
.innerText
.xstrip
;
28 string
textNoNameIntr (Element el
) {
30 foreach (Element child
; el
.children
) {
31 if (child
.tagName
== "name") continue;
32 if (child
.nodeType
!= NodeType
.Text
) s
~= textNoNameIntr(child
); else s
~= child
.nodeValue();
37 string
fixTypes (string s
) {
46 static Repl
[$] replaces
= [
47 Repl(ctRegex
!(`^(Display|DMparams|XVisualInfo|GLXVideoCaptureDeviceNV)\s*\*$`), "/*$1*/void*"),
48 Repl(ctRegex
!(`^(GLXFBConfigSGIX|GLXFBConfig|GLXContext)\s*\*$`), "/*$1*/void**"),
49 Repl(ctRegex
!(`^(GLXFBConfigSGIX|GLXFBConfig|GLXContext)$`), "/*$1*/void*"),
51 Repl(ctRegex
!(`^(HVIDEOINPUTDEVICENV|HVIDEOOUTPUTDEVICENV|HGPUNV|HPVIDEODEV)\s*\*$`), "/*$1*/void**"),
52 Repl(ctRegex
!(`^(HPBUFFERARB|HPBUFFEREXT|HVIDEOOUTPUTDEVICENV|HPVIDEODEV|HPGPUNV|HGPUNV|HVIDEOINPUTDEVICENV|PGPU_DEVICE)$`), "/*$1*/void*"),
53 Repl(ctRegex
!(`^const\s+(HGPUNV)\s*\*$`), "/*$1*/const(void)**"),
55 Repl(ctRegex
!(`^const\s+(GLXContext)$`), "/*$1*/const(void)*"),
56 Repl(ctRegex
!(`\bunsigned\s+int\b`), "uint", true),
57 Repl(ctRegex
!(`\bunsigned\s+long\b`), "c_ulong", true),
58 Repl(ctRegex
!(`\blong\b`), "c_long", true),
59 Repl(ctRegex
!(`\bBool\b`), "int", true),
60 Repl(ctRegex
!(`\bint32_t\b`), "int", true),
61 Repl(ctRegex
!(`\bint64_t\b`), "long", true),
62 Repl(ctRegex
!(`\bGLXVideoDeviceNV\b`), "uint", true), // unsigned int
63 Repl(ctRegex
!(`^(Status|Font|GLXPbufferSGIX|Window|GLXDrawable|GLXVideoCaptureDeviceNV|GLXPbuffer|GLXPixmap|Pixmap|Colormap|GLXVideoSourceSGIX|GLXWindow|GLXVideoCaptureDeviceNV|GLXContextID)$`), "/*$1*/c_ulong"), // XID
64 //Repl(ctRegex!(`^(GLXVideoCaptureDeviceNV)$`), "/*$1*/c_ulong"), // XID
65 Repl(ctRegex
!(`^(DMbuffer)$`), "/*$1*/void*"),
66 Repl(ctRegex
!(`^const\s+([^\s*]+)\s*(\*+)$`), "const($1)$2"),
69 //if (s.indexOf("Display") >= 0) stderr.writeln("|", s, "|");
71 foreach (ref repl
; replaces
[]) {
72 auto mt
= s
.matchFirst(repl
.re
);
74 s
= s
.replaceAll(repl
.re
, repl
.repl
);
75 if (!repl
.cont
) break;
79 auto pos
= s
.indexOf("* ");
82 while (pos
< s
.length
&& s
[pos
] == ' ') s
= s
[0..pos
]~s
[pos
+1..$];
85 auto pos
= s
.indexOf(" *");
87 while (pos
> 0 && s
[pos
-1] == ' ') --pos
;
88 while (pos
< s
.length
&& s
[pos
] == ' ') s
= s
[0..pos
]~s
[pos
+1..$];
90 if (s
== "const GLchar*const*") s
= "const(GLchar)**";
91 if (s
== "const void*const*") s
= "const(void)**";
95 string
textNoName (Element el
) {
96 return fixTypes(textNoNameIntr(el
));
100 if (name
== "ref" || name
== "in" || name
== "out" || name
== "version" || name
== "align") name
~= "_";
102 type
= textNoName(pp
);
103 needReturn
= (type
!= "void");
108 // ////////////////////////////////////////////////////////////////////////// //
109 void parseCommand (Element cmd
) {
110 assert(cmd
!is null);
111 auto nameres
= cmd
.querySelector("proto");
112 assert(nameres
!is null);
114 auto fntype
= TypeAndName(nameres
);
116 switch (fntype
.name
) {
117 case "glCreateSyncFromCLeventARB": return;
118 case "glPathGlyphIndexRangeNV": return; // [2]
119 case "SwapBuffers": return; // shitdoze
120 case "ChoosePixelFormat": return; // shitdoze
121 case "DescribePixelFormat": return; // shitdoze
122 case "GetPixelFormat": return; // shitdoze
123 case "SetPixelFormat": return; // shitdoze
124 case "wglGetProcAddress": return; // shitdoze
125 case "glXGetProcAddress": return;
126 case "glXGetProcAddressARB": return;
130 if (fntype
.name
.endsWith("SGIX")) {
131 //stderr.writeln(fntype.name);
136 foreach (Element param
; cmd
.querySelectorAll("param")) args
~= TypeAndName(param
);
138 if (fntype
.name
== "glXChooseVisual") {
139 args
[2].type
= "const(int)*";
142 if (fntype
.name
== "glXGetProcAddress" || fntype
.name
== "glXGetProcAddressARB") {
143 args
[0].type
= "const(char)*";
148 bool needComma
= false;
149 foreach (const ref TypeAndName tn
; args
) {
150 if (needComma
) res
~= ", "; else needComma
= true;
161 bool needComma
= false;
162 foreach (const ref TypeAndName tn
; args
) {
163 if (needComma
) res
~= ", "; else needComma
= true;
170 string intrName
= fntype
.name
~"_Z_Z_";
171 string ldrName
= intrName
~"_loader_";
173 writeln("alias ", fntype
.name
, " = ", intrName
, ";");
174 writeln("__gshared ", intrName
, " = function ", fntype
.type
, " ", getArgs(), " { ", (fntype
.needReturn ?
"return " : ""), ldrName
, getCall(), "; };");
176 writeln("private ", fntype
.type
, " ", ldrName
, " ", getArgs(), " {");
177 writeln(" *cast(void**)&", intrName
, " = glbindGetProcAddress(`", fntype
.name
, "`);");
178 writeln(" if (*cast(void**)&", intrName
, " is null) assert(0, `OpenGL function '", fntype
.name
, "' not found!`);");
179 writeln(" ", (fntype
.needReturn ?
"return " : ""), intrName
, getCall(), ";");
183 private const(char)* glbfn_glGetString_loader (uint a00) {
184 *cast(void**)&glGetString_Z = glbindGetProcAddress(`glGetString`);
185 if (*cast(void**)&glGetString_Z is null) assert(0, `OpenGL function 'glGetString' not found!`);
186 return glGetString_Z(a00,);
191 write(fixPointers(nameres.innerText.xstrip), "_Z_Z (");
192 bool needComma = false;
193 foreach (Element param; cmd.querySelectorAll("param")) {
194 if (needComma) write(", "); else needComma = true;
195 write(fixPointers(param.innerText.xstrip));
202 void main (string
[] args
) {
203 gldom
= new XmlDocument(readTextFile(args
.length
== 1 ?
"gl.xml" : args
[1]));
205 foreach (Element glenum
; gldom
.querySelectorAll("enums")) {
206 //writeln(glenum.getAttribute("namespace"), ":", glenum.getAttribute("group"), " -- ", glenum.getAttribute("comment"));
207 //<enum value="0x00000001" name="GL_CURRENT_BIT"/>
208 foreach (Element it
; glenum
.querySelectorAll("enum[value][name]")) {
209 string name
= it
.getAttribute("name").xstrip
;
211 if (name
[0] == '_') continue;
212 if (name
.endsWith("SGIX")) continue;
213 string value
= it
.getAttribute("value").xstrip
;
214 assert(value
.length
);
215 if (value
[0] == '"') continue;
216 string api
= it
.getAttribute("api");
217 if (api
== "gles2") continue; // fuck off
218 if (api
.length
&& api
!= "gl") {
219 if (api
.length
) assert(0, api
);
221 string type
= it
.getAttribute("type");
223 if (type
.length
== 0 || type
== "u") {
225 } else if (type
== "ull") {
228 } else if (type
.length
) {
231 writeln("enum ", type
, " ", name
, " = ", value
, pfx
, ";");
236 foreach (Element cmd
; gldom
.querySelectorAll("commands > command")) {
239 } catch (Throwable e
) {
240 writeln("-------------------------");
241 writeln(cmd
.outerHTML
);
242 writeln("-------------------------");
251 <proto>void <name>glApplyTextureEXT</name></proto>
252 <param group="LightTextureModeEXT"><ptype>GLenum</ptype> <name>mode</name></param>
255 <proto><ptype>GLboolean</ptype> <name>glAcquireKeyedMutexWin32EXT</name></proto>
256 <param><ptype>GLuint</ptype> <name>memory</name></param>
257 <param><ptype>GLuint64</ptype> <name>key</name></param>
258 <param><ptype>GLuint</ptype> <name>timeout</name></param>