我有一个使用glTexImage2D创建纹理的Android应用程序,所以我可以稍后使用glTexSubImage2D编辑它:
private void buildTexture()
{
if(canvasTexture[0] != -1)
{
GLES20.glDeleteTextures(1, canvasTexture, 0);
canvasTexture[0] = -1;
}
GLES20.glGenTextures(1, canvasTexture, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, canvasTexture[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, canvasDims.x(), canvasDims.y(), 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, canvasBuffer);
}
尺寸为128x64,canvasBuffer初始化如下:
canvasBuffer = IntBuffer.allocate(canvasDims.x()*canvasDims.y());
基本上我想在一个包含整个图像的本机内存中保留一个IntBuffer,并在需要时和需要时更新它。
以下是问题的起点。我正在尝试更新纹理的一部分,在缓冲区中给出匹配部分:
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, canvasTexture[0]);
canvasBuffer.position(1); //anything but 0 makes it crash
GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, canvasBuffer);
canvasBuffer.position(0);
对glTexSubImage2D的调用会导致崩溃(SIGSEGV - 无效的mem访问),当且仅当在prev中将位置设置为0以外的任何位置时。线。
我的错误在哪里?