webgl icon indicating copy to clipboard operation
webgl copied to clipboard

New features that would need a compiler change

Open Zinggi opened this issue 7 years ago • 3 comments

In this issue I want to collect new features that would require a compiler change, as the compiler only infers certain types from a [glsl| |] block.

The types that are currently supported are:

GLSL Elm
float Float
int Int
vec2 Math.Vector2.Vec2
vec3 Math.Vector3.Vec3
vec4 Math.Vector3.Vec4
mat4 Math.Matrix4.Mat4
sampler2D WebGL.Texture

Things that would be nice to have:

GLSL Elm Reason
bool Bool To toggle stuff on and off
mat3 Math.Matrix.Mat3 For 2d games, normal matrix for 3d shading, etc.
mat2 Math.Matrix.Mat2
samplerCube WebGL.CubeTexture For reflections, etc.
type name[] Array.Array a Arrays are needed for multiple light sources, GPU skinning, etc.
struct Name {..} type alias Name {..} Structs are nice for grouping. Click here for more info.

The relevant lines for the compiler are here.

Interestingly, we can actually pass in types that the compiler doesn't support and it still works. However, the compiler won't be able to infer types and catch errors this way.
(To confirm this statement, try passing in a Bool. It works as expected, but you don't get a compiler error if you leave it out or pass a String instead.)

Once it's clear what types we actually need, I could open an issue or a pull request to the compiler.

Zinggi avatar Dec 21 '16 14:12 Zinggi

Also, because we've moved the Texture into WebGL.Texture, it may be worth changing it in the compiler from "WebGL.Texture" to "WebGL.Texture.Texture".

w0rm avatar Dec 21 '16 14:12 w0rm

I think it's also worth discussing changing Math.VectorN.VecN to WebGL.Math.VecN etc. via integrating just the constructors for these types into webgl directly. (kinda like I did here).

This way you could still use linear-algebra, but you could also use my library or some other library that operates on {x: Float, y: Float}.

Zinggi avatar Dec 21 '16 15:12 Zinggi

One argument for including the linear algebra types in webgl is this issue: https://github.com/elm-community/linear-algebra/issues/8 that broke the implicit contract between two libraries by changing the internal native representation.

w0rm avatar Feb 26 '17 20:02 w0rm