OpenGL.Net icon indicating copy to clipboard operation
OpenGL.Net copied to clipboard

UniformMatrix4f does not seem to work

Open harry-cpp opened this issue 6 years ago • 7 comments

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

harry-cpp avatar Apr 17 '18 15:04 harry-cpp

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?

luca-piccioni avatar Apr 20 '18 06:04 luca-piccioni

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?

harry-cpp avatar Apr 20 '18 08:04 harry-cpp

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

luca-piccioni avatar Apr 20 '18 08:04 luca-piccioni

@luca-piccioni Any update on this?

harry-cpp avatar Apr 23 '18 08:04 harry-cpp

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.

luca-piccioni avatar Apr 29 '18 15:04 luca-piccioni

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 avatar May 15 '18 09:05 harry-cpp

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

harry-cpp avatar Dec 01 '19 17:12 harry-cpp