问题描述
我正在尝试将OpenTK Matrix4传递给着色器统一体,但是GL.UniformMatrix4似乎没有合适的重载.重载接受float
或float[]
或ref float
.同样,我找不到将Matrix4实例转换为浮点数组的方法-我已经看到一个示例,该示例在Matrix4上使用ToArray方法,但似乎在我使用的发行版中不存在.
I'm trying to pass an OpenTK Matrix4 to a shader uniform, but there doesn't seem to be a suitable overload for GL.UniformMatrix4. The overloads accept either float
or float[]
or ref float
. Similarly I can't find a way to convert a Matrix4 instance to a float array - I've seen one sample that uses a ToArray method on the Matrix4, but that doesn't seem to be present in the distribution I'm using.
当然,我缺少一些简单的东西,因为这对于将模型/视图/投影矩阵传递给着色器非常重要.
Sure I'm missing something simple as this is pretty fundamental to being able to pass a model/view/projection matrix to a shader.
我将OpenTK附带的版本与MonoTouch的最新版本一起使用.
I'm using the version of OpenTK shipping with the lastest version of MonoTouch.
推荐答案
此帮助程序功能有效,但似乎很容易破解.
This helper function works, but seems like a hack.
基本上,它只是传递Row0,Col0的地址.由于C#不能保证结构中字段的顺序,因此从理论上讲,运气比什么都重要.
Basically it's just passing the address of Row0,Col0. Since C# makes no guarantees about the order of fields in a structure though, theoretically it's working by luck more than anything.
public static void UniformMatrix4(int location, Matrix4 value)
{
GL.UniformMatrix4(location, 1, false, ref value.Row0.X);
}
当然,OpenTK应该具有允许直接传递Matrix4的绑定.
Surely OpenTK should have bindings to allowing passing a Matrix4 directly.
这篇关于MonoTouch OpenTK和UniformMatrix4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!