Skip to content

Commit 43b059f

Browse files
committed
Use Api enum in Extension and Registry structs
1 parent 5995de1 commit 43b059f

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

gl_generator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ also attempt to load `glGenFramebuffersEXT` as a fallback.
146146
### vX.X.X
147147

148148
- Rename `Ns` to `API`, and expose at the top level
149+
- Use `Api` for `Extension::supported` and `Filter::api` fields
149150

150151
### v0.4.2
151152

gl_generator/generators/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn gen_struct_name(api: Api) -> &'static str {
3434
Api::Glx => "Glx",
3535
Api::Wgl => "Wgl",
3636
Api::Egl => "Egl",
37+
Api::GlCore => "GlCore",
3738
Api::Gles1 => "Gles1",
3839
Api::Gles2 => "Gles2",
3940
}
@@ -109,7 +110,7 @@ pub fn gen_enum_item<W>(enm: &Enum, types_prefix: &str, dest: &mut W) -> io::Res
109110
/// things that we can't obtain from the XML files.
110111
pub fn gen_type_aliases<W>(api: Api, dest: &mut W) -> io::Result<()> where W: io::Write {
111112
match api {
112-
Api::Gl | Api::Gles1 | Api::Gles2 => {
113+
Api::Gl | Api::GlCore | Api::Gles1 | Api::Gles2 => {
113114
try!(ty::build_gl_aliases(dest));
114115
}
115116

@@ -175,7 +176,7 @@ pub fn gen_return_type(cmd: &Cmd) -> String {
175176
/// Example results: `"glClear"`, `"wglCreateContext"`, etc.
176177
pub fn gen_symbol_name(api: Api, cmd: &str) -> String {
177178
match api {
178-
Api::Gl | Api::Gles1 | Api::Gles2 => format!("gl{}", cmd),
179+
Api::Gl | Api::GlCore | Api::Gles1 | Api::Gles2 => format!("gl{}", cmd),
179180
Api::Glx => format!("glX{}", cmd),
180181
Api::Wgl => format!("wgl{}", cmd),
181182
Api::Egl => format!("egl{}", cmd),

gl_generator/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ pub mod generators;
105105
pub mod registry;
106106

107107
/// Public function that generates Rust source code.
108-
pub fn generate_bindings<G, W>(generator: G, ns: registry::Api, fallbacks: Fallbacks, source: &[u8],
108+
pub fn generate_bindings<G, W>(generator: G, api: registry::Api, fallbacks: Fallbacks, source: &[u8],
109109
extensions: Vec<String>, version: &str, profile: &str,
110110
dest: &mut W) -> io::Result<()> where G: Generator, W: io::Write
111111
{
112112
// Get generator field values, using default values if they have not been
113113
// specified
114114
let filter = Some(Filter {
115-
api: ns.to_string(),
115+
api: api,
116116
fallbacks: fallbacks,
117117
extensions: extensions,
118118
version: version.to_string(),
@@ -123,7 +123,7 @@ pub fn generate_bindings<G, W>(generator: G, ns: registry::Api, fallbacks: Fallb
123123
let registry = {
124124
use std::io::BufReader;
125125
let reader = BufReader::new(source);
126-
Registry::from_xml(reader, ns, filter)
126+
Registry::from_xml(reader, api, filter)
127127
};
128128

129129
generator.write(&registry, dest)

gl_generator/registry.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use self::xml::EventReader as XmlEventReader;
2929
use self::xml::attribute::OwnedAttribute;
3030
use self::xml::reader::XmlEvent;
3131

32-
#[derive(Copy, Clone)]
33-
pub enum Api { Gl, Glx, Wgl, Egl, Gles1, Gles2 }
32+
#[derive(Copy, Clone, PartialEq, Eq)]
33+
pub enum Api { Gl, Glx, Wgl, Egl, GlCore, Gles1, Gles2 }
3434

3535
#[derive(Copy, Clone)]
3636
pub enum Fallbacks { All, None }
@@ -39,10 +39,11 @@ impl FromStr for Api {
3939
type Err = ();
4040
fn from_str(s: &str) -> Result<Api, ()> {
4141
match s {
42-
"gl" => Ok(Api::Gl),
42+
"gl" => Ok(Api::Gl),
4343
"glx" => Ok(Api::Glx),
4444
"wgl" => Ok(Api::Wgl),
4545
"egl" => Ok(Api::Egl),
46+
"glcore" => Ok(Api::GlCore),
4647
"gles1" => Ok(Api::Gles1),
4748
"gles2" => Ok(Api::Gles2),
4849
_ => Err(()),
@@ -57,6 +58,7 @@ impl fmt::Display for Api {
5758
Api::Glx => write!(fmt, "glx"),
5859
Api::Wgl => write!(fmt, "wgl"),
5960
Api::Egl => write!(fmt, "egl"),
61+
Api::GlCore => write!(fmt, "glcore"),
6062
Api::Gles1 => write!(fmt, "gles1"),
6163
Api::Gles2 => write!(fmt, "gles2"),
6264
}
@@ -69,7 +71,7 @@ fn trim_str<'a>(s: &'a str, trim: &str) -> &'a str {
6971

7072
fn trim_enum_prefix<'a>(ident: &'a str, api: Api) -> &'a str {
7173
match api {
72-
Api::Gl | Api::Gles1 | Api::Gles2 => trim_str(ident, "GL_"),
74+
Api::Gl | Api::GlCore | Api::Gles1 | Api::Gles2 => trim_str(ident, "GL_"),
7375
Api::Glx => trim_str(ident, "GLX_"),
7476
Api::Wgl => trim_str(ident, "WGL_"),
7577
Api::Egl => trim_str(ident, "EGL_"),
@@ -78,7 +80,7 @@ fn trim_enum_prefix<'a>(ident: &'a str, api: Api) -> &'a str {
7880

7981
fn trim_cmd_prefix<'a>(ident: &'a str, api: Api) -> &'a str {
8082
match api {
81-
Api::Gl | Api::Gles1 | Api::Gles2 => trim_str(ident, "gl"),
83+
Api::Gl | Api::GlCore | Api::Gles1 | Api::Gles2 => trim_str(ident, "gl"),
8284
Api::Glx => trim_str(ident, "glX"),
8385
Api::Wgl => trim_str(ident, "wgl"),
8486
Api::Egl => trim_str(ident, "egl"),
@@ -219,7 +221,7 @@ pub struct Cmd {
219221

220222
#[derive(Clone)]
221223
pub struct Feature {
222-
pub api: String,
224+
pub api: Api,
223225
pub name: String,
224226
pub number: String,
225227
pub requires: Vec<Require>,
@@ -248,7 +250,7 @@ pub struct Remove {
248250
pub struct Extension {
249251
pub name: String,
250252
/// which apis this extension is defined for (see Feature.api)
251-
pub supported: Vec<String>,
253+
pub supported: Vec<Api>,
252254
pub requires: Vec<Require>,
253255
}
254256

@@ -265,11 +267,11 @@ struct RegistryBuilder<R: io::Read> {
265267
}
266268

267269
pub struct Filter {
270+
pub api: Api,
268271
pub fallbacks: Fallbacks,
269272
pub extensions: Vec<String>,
270273
pub profile: String,
271274
pub version: String,
272-
pub api: String,
273275
}
274276

275277
/// A big, ugly, imperative impl with methods that accumulates a Registry struct
@@ -679,9 +681,10 @@ impl FromXml for Remove {
679681
impl FromXml for Feature {
680682
fn convert<R: io::Read>(r: &mut RegistryBuilder<R>, a: &[OwnedAttribute]) -> Feature {
681683
debug!("Doing a FromXml on Feature");
682-
let api = get_attribute(a, "api").unwrap();
683-
let name = get_attribute(a, "name").unwrap();
684-
let number = get_attribute(a, "number").unwrap();
684+
let api = get_attribute(a, "api").unwrap();
685+
let api = Api::from_str(&*api).unwrap();
686+
let name = get_attribute(a, "name").unwrap();
687+
let number = get_attribute(a, "number").unwrap();
685688

686689
debug!("Found api = {}, name = {}, number = {}", api, name, number);
687690

@@ -701,7 +704,11 @@ impl FromXml for Extension {
701704
fn convert<R: io::Read>(r: &mut RegistryBuilder<R>, a: &[OwnedAttribute]) -> Extension {
702705
debug!("Doing a FromXml on Extension");
703706
let name = get_attribute(a, "name").unwrap();
704-
let supported = get_attribute(a, "supported").unwrap().split('|').map(|x| x.to_string()).collect::<Vec<String>>();
707+
let supported = get_attribute(a, "supported").unwrap()
708+
.split('|')
709+
.map(|x| Api::from_str(x))
710+
.map(Result::unwrap)
711+
.collect::<Vec<_>>();
705712
let mut require = Vec::new();
706713
loop {
707714
match r.next() {

0 commit comments

Comments
 (0)