elm-explorations / webgl

Functional rendering with WebGL in Elm
https://package.elm-lang.org/packages/elm-explorations/webgl/latest/
BSD 3-Clause "New" or "Revised" License
117 stars 17 forks source link

Add WebGL.Texture.loadBytesWith #13

Open justgook opened 5 years ago

justgook commented 5 years ago

adding ability to create textures out of bytes, this is task less api, for future it will allow as create custom image / scene format loaders, create default texture without waiting for task.

        pixelBytes =
            List.repeat 2 (Bytes.unsignedInt32 Bytes.BE 0xFF0000FF)
                |> (++) (List.repeat 18 (Bytes.unsignedInt32 Bytes.BE 0xFFFF))
                |> Bytes.sequence
                |> Bytes.encode

        resultTexture =
            WebGL.loadBytesWith WebGL.nonPowerOfTwoOptions ( 2, 10 ) RGBA pixelBytes
folkertdev commented 5 years ago

I think much of the js/Kernel code in this PR could be moved into pure elm without any performance cost. Having less kernel code might increase the chances of this PR getting accepted.

In particular, an elm implementation of getByteCount would not be slower than the current kernel version. Then all size/dimension validation could happen on the elm side, and the Kernel code only deals with the actual creation of the webgl texture from a Bytes.

Herteby commented 4 years ago

Would be nice to have this merged, if the issues have been fixed :slightly_smiling_face:

w0rm commented 4 years ago

@Herteby https://github.com/elm-explorations/webgl/blob/master/CONTRIBUTING.md

Herteby commented 4 years ago

Oh I see, so Evan needs to approve anything beyond patches.

w0rm commented 4 years ago

@Herteby my understanding is that the same rules apply for this package, as for any other browser integrations and changes to the core elm packages.