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

Make constants typed #86

Open
Grief opened this issue Jul 15, 2017 · 5 comments
Open

Make constants typed #86

Grief opened this issue Jul 15, 2017 · 5 comments

Comments

@Grief
Copy link

Grief commented Jul 15, 2017

While it is possible to achieve type safety for constants passed to GL functions, I think it would be a breaking change.

What I ask for is to declare a type, e.g. type GLConst int32 and define constants as

const (
	ACTIVE_ATOMIC_COUNTER_BUFFERS GLConst = 0x92D9
	ACTIVE_ATTRIBUTES             GLConst = 0x8B89
	ACTIVE_ATTRIBUTE_MAX_LENGTH   GLConst = 0x8B8A
        ...
)

Then it would be possible to use stringer to generate the code which would convert a value (returned by gl.GetError, for example) to constant name. I think it would be pretty neat for debugging and exception displaying

@dmitshur
Copy link
Member

At first glance, this looks somewhat viable. But I think the best way to learn more is to prototype the change and see what works, what doesn't.

But some consts won't fit in int32:

const TIMEOUT_IGNORED = 0xFFFFFFFFFFFFFFFF

Then it would be possible to use stringer to generate the code which would convert a value (returned by gl.GetError, for example) to constant name. I think it would be pretty neat for debugging and exception displaying

It might be possible to achieve that in a different way, just by creating a helper that takes a GL constant value and returns its string representation. That way, it can even live in a separate package, one that people who don't want debug info (which increases binary size) can avoid.

@errcw, what's your take on this idea?

@errcw
Copy link
Member

errcw commented Jul 17, 2017

Fundamentally, the problem would be identifying function parameters that would take GLConst instead of GLenum or GLint some other type. The OpenGL XML specifications do not indicate whether any particular parameter takes a constant or a user-specified numeric type. Given the constraints of glow (i.e., bindings are auto-generated based on the specs) I'm not sure this feature is feasible.

That said it would be possible to build a stringer that converts from constant value to constant name.

@dmitshur
Copy link
Member

Fundamentally, the problem would be identifying function parameters that would take GLConst instead of GLenum or GLint some other type. The OpenGL XML specifications do not indicate whether any particular parameter takes a constant or a user-specified numeric type. Given the constraints of glow (i.e., bindings are auto-generated based on the specs) I'm not sure this feature is feasible.

I suspected that could be the case, making this not possible. Thanks for confirming.

@Grief
Copy link
Author

Grief commented Jul 24, 2017

Ok, I got it.

That said it would be possible to build a stringer that converts from constant value to constant name.

I guess it would be handy if the stringer code is shipped with the library

@dmitshur
Copy link
Member

I think only it's viable to put it in the same package if not using it means it gets dead code eliminated. Otherwise, we'd be increasing all production binary sizes.

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

No branches or pull requests

3 participants