luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UniformMatrix4f does not seem to work

harry-cpp opened this issue · comments

commented

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);

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?

commented

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?

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

commented

@luca-piccioni Any update on this?

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.

commented

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.

commented

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