luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.
MIT License
568 stars 108 forks source link

UniformMatrix4f does not seem to work #98

Open harry-cpp opened 6 years ago

harry-cpp commented 6 years ago

Unless I am doing something wrong, UniformMatrix4f does not work with System.Numerics.Matrix4x4:

// works 
fixed (Matrix4x4* native = &_mvp)
    Gl.UniformMatrix4(_matrixid, 1, false, (float*)native);

// does not work :(
// Gl.UniformMatrix4f<Matrix4x4>(_matrixid, 1, false, ref _mvp);
luca-piccioni commented 6 years ago

Numerics structure have special JIT management, and the generic functions on some platforms uses the "obscure" __makeref keyword, which assumes that the value is allocate on stack.

On what platform are you running?

Maybe in Debug configuration is it working?

The Numerics structures is have a column-major order? Maybe it is sufficient to transpose the matrix.

The Numerics structure maybe does have the proper StructLayout?

harry-cpp commented 6 years ago

On what platform are you running?

Linux, mono, net471

Maybe in Debug configuration is it working?

Does not work in it.

The Numerics structures is have a column-major order? Maybe it is sufficient to transpose the matrix. The Numerics structure maybe does have the proper StructLayout?

Wouldn't my fixed code fail than?

luca-piccioni commented 6 years ago

Correct. Tonight I'll check with some unit tests...

harry-cpp commented 6 years ago

@luca-piccioni Any update on this?

luca-piccioni commented 6 years ago

I've checked the unit tests for glUniform1-4v, and they are currently calling generic Uniform calls (but not the generic GetUniform calls), and they run successfully on my machine.

I thought to be confident that the UniformMatrix generic calls are fine too since the underlying implementation is essentially the same. I suspect that the issue is strictly related to the Numerics structure.

If you convert the Numerics.Matrix4 structure to the managed Matrix4x4f structure (or any equivalent), is it working? When I'll have some free time I'll write specific test for UniformMatrix calls.

harry-cpp commented 6 years ago

If you convert the Numerics.Matrix4 structure to the managed Matrix4x4f structure (or any equivalent), is it working?

It was not working, I checked before submitting this issue.

harry-cpp commented 4 years ago

Fun note, I found out that the code runs fine on Windows, but not on Linux.