Android OpenGL ES 1.0 的 int 数组到 intbuffer 中?
我最近在 Badlogicgames.com 上读到一篇关于加快将信息添加到顶点缓冲区(或任何其他 intbuffer)的过程的文章,它确实提高了我的项目的速度,但我不太明白
“注意到 IntBuffer.put( int[] src ) 没有受到该问题的影响”
声明......如果不需要浮点,是否可以将 int[] 数组输入 IntBuffer 来提高速度数字?每次我尝试将 int[] 放入缓冲区时;什么都没有渲染...
这是我当前用法的一个示例:
dMesh[i].putVertexBuffer(coords); //function being called
public void putVertexBuffer(int[] input) //actual function
{
ByteBuffer tC = ByteBuffer.allocateDirect(input.length *4);
tC.order(ByteOrder.nativeOrder());
_vertexBuffer = tC.asIntBuffer();
_vertexBuffer.put(input);
_vertexBuffer.position(0);
}
现在,如果 int 数组“coords”填充了使用“Float.floatToIntBits(float value)”将浮点数转换为整数的变量;这很好...但是标准整数数组没有显示任何内容... 但是如果我只有一个 float[] 数组并将“asIntBuffer()”更改为“asFloatBuffer()”,这有效吗?我很困惑。是否需要转换? 提前感谢任何提供见解的人。
快速编辑: 我差点忘了...这是我引用的文章: http://www.badlogicgames.com/wiki/index.php/Direct_Bulk_FloatBuffer.put_is_slow
I recently read an article on Badlogicgames.com about speeding up the process of adding information into vertex buffers (or any other intbuffer) and it did increase the speed of my project, but I didn't quite understand the
"Noticing the IntBuffer.put( int[] src ) was not affected by the problem"
statement.... Is it possible to feed an int[] array into an IntBuffer to get a speed increase if you have no need for floating point numbers? Every time I try and put an int[] into the buffer; nothing is rendered...
Here is an example of my current usage:
dMesh[i].putVertexBuffer(coords); //function being called
public void putVertexBuffer(int[] input) //actual function
{
ByteBuffer tC = ByteBuffer.allocateDirect(input.length *4);
tC.order(ByteOrder.nativeOrder());
_vertexBuffer = tC.asIntBuffer();
_vertexBuffer.put(input);
_vertexBuffer.position(0);
}
Now if the int array "coords" is filled with variables that were floating point numbers converted into integers using "Float.floatToIntBits(float value)"; this is fine... but an Array of standard integers does not show anything...
But if I just have a float[] array and change "asIntBuffer()" to "asFloatBuffer()", this works? I'm confused. Is there a conversion required?
Thankyou in advance to anyone who gives any insight.
Quick edit:
I nearly forgot... this is the article I referenced:
http://www.badlogicgames.com/wiki/index.php/Direct_Bulk_FloatBuffer.put_is_slow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您尝试使用整数时,您是否还更改了使用数组消耗整数而不是浮点数的代码?我在这里遇到了各种各样的问题。
我之前的问题/答案可能有帮助 - 它在这个区域:
在 Android 游戏中将 java.nio.IntBuffer 传递给 C 函数
When you tried ints, did you also change the code which used the array to consume ints instead of floats? I had all sorts of problems here.
It's possible my previous question/answer helps - it's in this area:
Passing java.nio.IntBuffer to C function in an Android game
您没有在
glVertexPointer
调用中使用参数为GL_FLOAT
的 int 数组作为类型,是吗?在这种情况下,我不会对这种行为感到好奇。使用整数作为顶点位置时,请务必使用GL_INT
类型作为glVertexPointer
(或任何此类属性数组函数)中的类型参数。You are not using an int array with a parameter of
GL_FLOAT
for the type in theglVertexPointer
call, are you? In this case I wouldn't wonder about the behaviour. When using ints as vertex poistions, be sure to use a type ofGL_INT
as type parameter inglVertexPointer
(or any such attribute array function).