haskell-opengl / OpenGL

Haskell bindings to OpenGL
http://www.haskell.org/haskellwiki/OpenGL
BSD 3-Clause "New" or "Revised" License
147 stars 26 forks source link

No binding for glUniformMatrix* #33

Closed thiago-negri closed 8 years ago

thiago-negri commented 11 years ago

I can't find any function for performing a glUniformMatrix*.

Laar commented 11 years ago

If I remember correctly I looked into it (partially) as the same problem was brought forward by #14 . The problem with extending the current implementation for vectors is that there is no specific datatype for matrices. So far I've thought of two possible solutions.

  1. Define a datatype ourselves (maybe as extension of the rather small tensor package), say Mat4x4 a = Vec4 (Vec4 a). But should we tie the users to a specific implementation for matrices and could we maintain it?
  2. Define a typeclass for matrices. This is the current implementation for matrices in .../CoordTrans.hs. It doesn't restrict the user to a specific matrix implementation but might result in performance issues. Furthermore I don't know if this doable without language extensions and how it would scale to the whole set of matrix sizes.
jan3er commented 11 years ago

How about supporting Data.Vect.Float? I'm not quite familiar with both libraries, but they appear to complement each other well. There is a Data.Vect.Float Module for using the libraries vectors and matrices in OpenGL context, but it's only tailored towards the old pipeline and not glUniformMatrix*.

pakanek commented 10 years ago

In OpenGL-2.9 binding, where UniformLocation type constructor is exported

(UniformLocation mvp) <- get (uniformLocation prog "mvp")

can be used with OpenGLRaw. If you store matrix in Data.Vector.Storable then

-- mvpVec :: Vector GLfloat
unsafeWith mvpVec (\ptr -> glUniformMatrix4fv mvp 1 0 ptr)

can be used to upload matrix to the shader uniform.

schell commented 10 years ago

I'm not sure of the difference, but you can also use

withArray mvpVec (\ptr -> glUniformMatrix4fv mvp 1 0 ptr)

Maybe it's 'less unsafe' ?

pakanek commented 10 years ago

It is probably unsafe function because pointer should be used only to read - not to write - into that memory. It should be okay when you are just sending data to OpenGL. But I am not so sure about differences between Array/Vector/Repa... in FP/Haskell either. I use Vector in my math package.

bgamari commented 10 years ago

I have some Uniform instances in my linear-opengl package that may be of interest here.

svenpanne commented 8 years ago

This has been fixed in b1b50031f7880b918fc6ec056342c5c89f118213, I'm about to make a new release on Hackage.