我正在尝试在android上的GLES应用程序上变形一些顶点,glMapBufferRange不断崩溃,出现以下错误:
SIGSEGV (signal SIGSEGV: address access protected (fault address: 0xef13d664))
我或多或少地效仿了这个网站:
http://www.songho.ca/opengl/gl_vbo.html更新但不确定我是否错过了什么
我在初始化时创建了我的vbo,我可以毫无问题地绘制对象。创建代码如下:
void SubObject3D::CreateVBO(VBOInfo &vboInfoIn) {
// m_vboIds[0] - used to store vertex attribute data
// m_vboIds[l] - used to store element indices
glGenBuffers(2, vboInfoIn.vboIds);
// Let the buffer all dynamic for morphing
glBindBuffer(GL_ARRAY_BUFFER, vboInfoIn.vboIds[0]);
glBufferData(GL_ARRAY_BUFFER,
(GLsizeiptr) (vboInfoIn.vertexStride * vboInfoIn.verticesCount),
vboInfoIn.pVertices, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboInfoIn.vboIds[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
(GLsizeiptr) (sizeof(GLushort) * vboInfoIn.indicesCount),
vboInfoIn.pIndices, GL_STATIC_DRAW);
}
struct VBOInfo {
VBOInfo() {
memset(this, 0x00, sizeof(VBOInfo));
vboIds[0] = 0xdeadbeef;
vboIds[1] = 0xdeadbeef;
}
// VertexBufferObject Ids
GLuint vboIds[2];
// Points to the source data
GLfloat *pVertices; // Pointer of original data
GLuint verticesCount;
GLushort *pIndices; // Pointer of original data
GLuint indicesCount;
GLint vertexStride;
};
然后在渲染循环中,我试图获得我的顶点指针如下:
// I stored the information at creation time here:
VBOInfo mVBOGeometryInfo;
//later I call here to get the pointer
GLfloat *SubObject3D::MapVBO() {
GLfloat *pVertices = nullptr;
glBindBuffer(GL_ARRAY_BUFFER, mVBOGeometryInfo.vboIds[0]);
GLsizeiptr length = (GLsizeiptr) (mVBOGeometryInfo.vertexStride *
mVBOGeometryInfo.verticesCount);
pVertices = (GLfloat *) glMapBufferRange(
GL_ARRAY_BUFFER, 0,
length,
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT
);
if (pVertices == nullptr) {
LOGE ("Could not map VBO");
}
return pVertices;
}
但是它在glMapBufferRange处崩溃了
这是一个使用NDK的android应用程序。硬件是三星S6手机。
谢谢!
解决这个问题是相当痛苦的,但是上面的代码本身没有问题。基本上就是包含。我的代码是基于谷歌样本"更多的茶壶"位于这里:
https://github.com/googlesamples/android-ndk/tree/master/teapots我必须遵循他们的模式,将我的include从:
更改为:#include <GLES3/gl3.h>
使用它们的存根:
#include "gl3stub.h"
为什么?我不知道,但可能导致链接器链接错误的代码。