MonoTouch OpenTK and UniformMatrix4

I'm trying to pass OpenTK Matrix4 to a shader form, but it seems that overload is not suitable for GL.UniformMatrix4. Overloads accept either float, or, float[]or ref float. Similarly, I cannot find a way to convert the Matrix4 instance to a floating-point array - I saw one sample that uses the ToArray method on Matrix4, but this does not seem to be present in the distribution that I use.

Of course, I missed something simple, since it is quite fundamental in order to transfer the model / view / projection matrix to the shader.

I am using the OpenTK delivery version with the latest version of MonoTouch.

+5
source share
2 answers

This helper function works, but seems hacked.

Basically, it just passes the address to Row0, Col0. Since C # gives no guarantees regarding the order of fields in the structure, although theoretically this works as luck more than anything else.

public static void UniformMatrix4(int location, Matrix4 value)
{
    GL.UniformMatrix4(location, 1, false, ref value.Row0.X);
}

Of course, OpenTK should have bindings that allow you to pass Matrix4 directly.

+4
source

Based on the iphone tag, I assume that you are using OpenTK.Graphics.ES20.GL, not a regular desktop OpenTK.Graphics.OpenGL.GL. Linking with OpenGL ES is not as complete as standard desktop bindings that contain overloads for vectors and matrices.

, , OpenGL, , Matrix4 ref, Matrix4 .

FYI, #, StructLayoutAttribute LayoutKind of Sequential, OpenTK .

+3

All Articles