elm-community / elm-webgl

Moved to elm-explorations/webgl
http://package.elm-lang.org/packages/elm-explorations/webgl/latest
BSD 3-Clause "New" or "Revised" License
95 stars 22 forks source link

Is is possible to add constants to the vertex array data? #34

Closed 7sharp9 closed 8 years ago

7sharp9 commented 8 years ago

I can see how you create streams of information like vertex and normal position but how do you apply constant data like using a constant vertex attribute. Maybe the intension is that you would use a uniform here?

I cant see any complex examples in this API that sheds any light on this, hence this question.

nphollon commented 8 years ago

Looking at the cube.elm example:

vertexShader : Shader { attr | position:Vec3, color:Vec3 } { unif | rotation:Mat4, perspective:Mat4, camera:Mat4 } { vcolor:Vec3 }

The first record specifies that "position" and "color" are your attributes. Within your GLSL code, these are defined as attributes. Within your Elm code, your "Vertex" type needs to have these defined as fields.

If you wanted to define a new attribute, you would need to change the signature for vertexShader, and add a field to the Vertex type definition.

7sharp9 commented 8 years ago

Oh I can understand that part, its more how would you add interleaved vertex buffers, index buffers, and things like setting a subtexture.

I guess Im just missing a few more examples to grasp the mapping from js based webgl and the elm wrapper.

nphollon commented 8 years ago

It sounds like you might be looking for a finer level of control than the Elm API gives you. There is no Elm counterpart to vertex or index buffers. You pass you attributes to render, and the library decides how to arrange the data in memory.

7sharp9 commented 8 years ago

I was hoping there would be some middle ground where vertex and index buffers could be used.

nphollon commented 8 years ago

What are you trying to accomplish? If you tell us more details about your use case, we may be able to help.

It doesn't sound like there is anything actionable that is related to the original topic, so I am going to close this issue.