Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gl_generator: implement fallbacks based on aliases #204

Merged
merged 4 commits into from Nov 5, 2014

Conversation

emberian
Copy link
Collaborator

@emberian emberian commented Nov 5, 2014

These aliases are already present in the XML, so we might as well use them! As
OpenGL evolves and is extended, it frequently occurs that a vendor introduces
an extension, giving a function a name like glFooNV or glFooAMD. Then, it
gets proposed to the ARB and is renamed glFooEXT. Then, this extension gets
standardized and is placed in the core profile and is once again renamed to
its final name, glFoo.

For Mesa, they implement various extensions and then finally support an OpenGL
version once all extensions have been implemented. Many OpenGL features can be
implemented entirely in the driver, or on most hardware even if the hardware
doesn't support enough features for a specific OpenGL version. So you get
situations where older GPUs only expose OpenGL 2.1, but implement almost every
extension that is present in OpenGL 3.3.

So, when glFoo can't be loaded but it has known aliases, try also loading
those aliases before giving up.

Closes #150

These aliases are already present in the XML, so we might as well use them! As
OpenGL evolves and is extended, it frequently occurs that a vendor introduces
an extension, giving a function a name like `glFooNV` or `glFooAMD`. Then, it
gets proposed to the ARB and is renamed `glFooEXT`. Then, this extension gets
standardized and is placed in the core profile and is once again renamed to
its final name, `glFoo`.

For Mesa, they implement various extensions and then finally support an OpenGL
version once all extensions have been implemented. Many OpenGL features can be
implemented entirely in the driver, or on most hardware even if the hardware
doesn't support enough features for a specific OpenGL version. So you get
situations where older GPUs only expose OpenGL 2.1, but implement almost every
extension that is present in OpenGL 3.3.

So, when `glFoo` can't be loaded but it has known aliases, try also loading
those aliases before giving up.

Closes brendanzab#150
@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

r? @bjz @tomaka

@tomaka
Copy link
Collaborator

tomaka commented Nov 5, 2014

The code looks good (r+), however I'm wondering if it's really that useful. For example searching for alias name="glNamed in gl.h doesn't give any result, even though the direct_state_access functions should be there.

@tomaka
Copy link
Collaborator

tomaka commented Nov 5, 2014

Maybe a test could be added, with a closure that gives null for a real function and a real function pointer for an alias.

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

@tomaka it's useful at the very least for gfx-rs/gfx#231

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

@tomaka I suspect the DSA stuff is just a bug with the xml

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

@tomaka I'm not sure how to differentiate the real function and an alias for the test, what exactly do you mean? (Note that at least on mesa, the EXT and regular function have the same address since they are the same)

@tomaka
Copy link
Collaborator

tomaka commented Nov 5, 2014

Something like this:

extern fn dummy() {}

let loader = |name| -> *const libc::c_void {
    match name {
        "glMyFunction" => 0,
        "glMyFunctionEXT" => dummy,
        _ => panic!()
    }
};

gl::MyFunction::load_with(loader);
gl::MyFunction();   // should call `dummy`

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

Oh, duh! Will add :)

for (k, v) in b.into_iter() {
match a.entry(k) {
Occupied(mut ent) => { ent.get_mut().extend(v.into_iter()); },
Vacant(ent) => { ent.set(v); }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the new entry API exactly for this :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gankro and @aturon!

@brendanzab
Copy link
Owner

Ok, this looks good to me. I am just not following the back and forth between you guys. Are you talking about redoing some of the internal logic, or exposing something else in the API?

Also, could you add some documentation to the README saying that this is going on behind the scenes?

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

@tomaka test added

@bjz docs added. We were just talking about whether this feature is useful, and about adding a test.

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

@bjz Revised the docs to say what you suggested

@tomaka
Copy link
Collaborator

tomaka commented Nov 5, 2014

Oh, it would also be nice if aliases were written in the doccomments of each function.
So for example when you run cargo doc on gl-rs, you can see what the aliases of each function can be.

But that doesn't have to be part of this PR.

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

@tomaka adding...

@emberian
Copy link
Collaborator Author

emberian commented Nov 5, 2014

Alright, :shipit:?

tomaka added a commit that referenced this pull request Nov 5, 2014
gl_generator: implement fallbacks based on aliases
@tomaka tomaka merged commit 91635f8 into brendanzab:master Nov 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add fallbacks for identical but renamed functions
3 participants