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

Wasm support and some cleanup. #18

Closed
wants to merge 6 commits into from
Closed

Wasm support and some cleanup. #18

wants to merge 6 commits into from

Conversation

dbriemann
Copy link

@dbriemann dbriemann commented Oct 28, 2018

Hi,

first of all I don't expect this to get merged already!

This PR adds wasm support via github.com/gopherjs/gopherwasm/js to this package but js via gopherjs should also still work. I also removed a few gl constants that are undefined in webgl. And last I changed TexImage2D to accept a []byte slice as wished in #11 .

Note that the new function (c *Context) initGlConstants() is needed because wasm does not support struct tags. It uses reflection because else we would need to list all gl constants again. If you think this would be better that's no problem to change it. I already have the equivalent function generated and ready.
The struct tags are removed because Gopherjs makes trouble if you try to set a value for a field with struct tag (probably a bug). But we don't need them anyways.

Let me know what you think!

Copy link
Member

@hajimehoshi hajimehoshi left a comment

Choose a reason for hiding this comment

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

sgtm

canvas := document.Call("createElement", "canvas")
if canvas == js.Null() {
fmt.Println("CANVAS IS NULL")
Copy link
Member

Choose a reason for hiding this comment

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

Early return would be nice here.

Copy link
Author

Choose a reason for hiding this comment

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

OK. I was just using the existing example but yea sounds like an improvement. Will add that.

webgl.go Outdated
gl := canvas.Call("getContext", "webgl", attrs)
if gl == nil {
if gl == js.Null() {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be js.Undefined()? I'm not confident on this.

Copy link
Author

Choose a reason for hiding this comment

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

Probably should be!

webgl.go Outdated
gl = canvas.Call("getContext", "experimental-webgl", attrs)
if gl == nil {
if gl == js.Null() {
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

Copy link
Author

Choose a reason for hiding this comment

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

See above.

}
```

webgl_example.html:
js_example.html:
Copy link
Member

Choose a reason for hiding this comment

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

Why was it renamed?

Copy link
Author

Choose a reason for hiding this comment

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

I renamed it to make a clearer distinction between the JS and the WASM example. Webgl seemed ambiguous.

webgl.go Outdated
for i := 0; i < num; i++ {
field := fields.Field(i)
// Ignore the embedded js.Value. All other fields are gl constants.
if field.Name != "Value" {
Copy link
Member

Choose a reason for hiding this comment

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

Early return would make this more readable:

if field.Name == "Value" {
  continue
}
// ...

Wdyt?

Copy link
Author

Choose a reason for hiding this comment

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

Sure for me both are fine. I can change it.

webgl.go Outdated
if field.Name != "Value" {
// Retrieve value from gl context.
jsval := ctx.Get(field.Name)
if jsval.Type() == js.TypeNumber {
Copy link
Member

Choose a reason for hiding this comment

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

When is the type not number? If we cannot expect, should it return error or just panic?

Copy link
Author

Choose a reason for hiding this comment

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

E.g. the type is not a number if the GL constant does not exist in webgl. I discovered a few of them through this and removed them from the constants above.
I checked for "not number" so we can just ignore all missing values. In fact there should be no missing values now. Maybe we should just panic here if something is missing?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I prefer panic since the constants in the spec must be obtained.

It looks like the removed constants might be defined in extensions?

Copy link
Author

Choose a reason for hiding this comment

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

The constants I removed are the following:

INFO_LOG_LENGTH
not needed in webgl.

NUM_COMPRESSED_TEXTURE_FORMATS
maybe related to https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Compressed_texture_formats

SHADER_COMPILER
no idea what this is

SHADER_SOURCE_LENGTH
not needed in webgl

STENCIL_INDEX
not in spec. see KhronosGroup/WebGL#2370 (comment)

@dbriemann
Copy link
Author

@hajimehoshi what do you think about the current state?

Copy link
Member

@hajimehoshi hajimehoshi left a comment

Choose a reason for hiding this comment

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

lgtm, I'd like to know @dmitshur's opinion

@dmitshur
Copy link
Member

Sorry about the slow response.

My concern here is that this project doesn't have an active owner/maintainer. Adding more functionality here makes it even harder to maintain.

This was the very first webgl binding for GopherJS and it has served well, but by now, there are other more active packages that provide webgl access, so I think a good direction could be to freeze and archive this package instead. Per gopherjs/gopherjs#894, we have limited resources.

If the Wasm port lived in another repository where it's more clear who develops/maintains it, that might be a more manageable solution. It would be less constrained by unnecessary backwards compatibility.

Alternatively, if we can add a maintainer to this repo. But I don't know what it means to be breaking API compatibility here, especially after this package has inactive for so long.

@dbriemann dbriemann closed this by deleting the head repository Nov 13, 2022
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.

None yet

3 participants