OpenGL-ArrayIndexOutOfBoundsException: remaining() < count < needed
来源:互联网 发布:模式识别 算法 编辑:程序博客网 时间:2024/06/05 17:03
解决方式就是
FloatBuffer.position(0);//FloatBuffer.flip();ShortBuffer.position(0);//ShortBuffer.flip();
无论如何这难以自圆其说,以下分析纯属扯淡。敬待高论!!
06-08 11:20:09.772 E/Adreno-ES11: <qglDrvAPI_glEnableClientState:1675>: GL_INVALID_ENUM06-08 11:20:09.794 E/AndroidRuntime: FATAL EXCEPTION: GLThread 3592 Process: com.example.a3d_study_2, PID: 15266 java.lang.ArrayIndexOutOfBoundsException: remaining() < count < needed at com.google.android.gles_jni.GLImpl.glDrawElements(Native Method) at com.example.a3d_study_2.No_4.NonRenderer.onDrawFrame(NonRenderer.java:115) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
我的现状:目标是要绘制一个正方形。
private FloatBuffer vertexBuffer;private ShortBuffer orderBufferSquare, orderBufferRectange, orderBufferParallelogram; private final float[] vertexArray = { //遵循:右上→右下→左下→左上 的点序。 //First Square 4f, 4f, 0f, 4f, -4f, 0f, -4f, -4f, 0f, -4f, 4f, 0f, //Second rectangle 8f, 7f, 0f, 8f, 6f, 0f, 6f, 6f, 0f, 6f, 7f, 0f, //Third Parallelogram 15f, 13f, 0f, 14f, 9f, 0f, 10f, 9f, 0f, 11f, 13f, 0f, }; private final short[] orderArraySquare = {0, 1, 2, 0, 2, 3}; private final short[] orderArrayRectange = {4, 5, 6, 4, 6, 7}; private final short[] orderArrayParallelogram = {8, 9, 10, 8, 10, 11};
- 把定点坐标放到 FloatBuffer 中。
ByteBuffer bbVertex = ByteBuffer.allocateDirect(this.vertexArray.length * 4); bbVertex.order(ByteOrder.nativeOrder()); this.vertexBuffer = bbVertex.asFloatBuffer(); this.vertexBuffer.put(this.vertexArray); ByteBuffer bbOrderSquare = ByteBuffer.allocateDirect(this.orderArraySquare.length * 2); bbOrderSquare.order(ByteOrder.nativeOrder()); this.orderBufferSquare = bbOrderSquare.asShortBuffer(); this.orderBufferSquare.put(this.orderArraySquare);
FloatBuffer继承Buffer,并且通过getter/setter方法可以享用父类的参数position,limit等。
limit在ByteBuffer.allocateDirect(this.vertexArray.length * 4)
已经确定。
伴随着this.vertexBuffer.put(this.vertexArray);
操作 position还会变化为 vertexArray.length
所以执行完上述代码后
vertexBuffer.position == vertexArray.length//12orderBufferSquare.position == orderArraySquare.length//6
- 执行到下述代码
@Override public void onDrawFrame(GL10 gl) { // Clears the screen and depth buffer. gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);// OpenGL docs. gl.glLoadIdentity(); gl.glTranslatef(0, 0, -14); gl.glEnableClientState(GL10.GL_TRIANGLES); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, this.vertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, this.orderArraySquare.length, GL10.GL_UNSIGNED_SHORT, this.orderBufferSquare); }}
glVertexPointer
从 vertexBuffer.position()
处开始读取顶点数据,所以从一开始就没有读到数据(也就是说要绘制的顶点并没有被系统获取到)。这到不会导致报错。 glDrawElements
真正要绘制this.orderArraySquare.length
个定点所构成的图形时候,就需要从上一步获取到的顶点按this.orderBufferSquare
顺序逐个取出来了,发现我们给定的索引导致了 ArrayIndexOutOfBoundsException
阅读全文
0 0
- OpenGL-ArrayIndexOutOfBoundsException: remaining() < count < needed
- ArrayIndexOutOfBoundsException
- ByteBuffer remaining 简介
- Exception:ArrayIndexOutOfBoundsException
- ArrayIndexOutOfBoundsException: 16384
- ArrayIndexOutOfBoundsException: 48188
- ArrayIndexOutOfBoundsException:26
- ArrayIndexOutOfBoundsException异常
- LSP剩余时间(Remaining Lifetime)
- Count
- COUNT
- count
- Count
- count
- count
- count
- count
- Count
- HDU 2001
- vs2015的asp.net项目用vs2010打开
- TBS腾讯浏览服务的SDK接入-Android studio
- 百度地图2.0离线版的制作
- deep-learning 笔记
- OpenGL-ArrayIndexOutOfBoundsException: remaining() < count < needed
- 线程等待执行完毕
- 值栈背后的故事
- JSON 教程
- js中 数字千位分隔符
- okhttp的使用
- Oracle 角色及权限整理
- spring简单理解
- 整理了一点php mb开头的方法与非mb开头方法的区别