openGL glUnmapBuffer()返回未知错误代码1280

时间:2011-08-31 04:40:56

标签: opengl vertex-buffer

我正在编写一些概念验证代码。我想证明我可以在创建缓冲区后将数据写入缓冲区对象。但是,当我尝试在写入缓冲区后取消映射缓冲区时,我得到的是GLenum错误代码1280。我完全陷入了困境。

我可以使用颜色数据初始化缓冲区并成功渲染它。问题是我之后无法修改缓冲区中的数据。代码如下。它显示了我如何将新数据写入缓冲区,然后我如何尝试将其读回。 glGetError()调用后,错误代码显示在注释中。变量“cbo”是颜色缓冲区:

//NEW COLOR DATA
GLubyte colorData2[9] = {255,255,0, 0,128,255, 255,0,255};

//WRITE THE DATA TO THE COLOR BUFFER OBJECT (variable cbo)
glBindBuffer(GL_ARRAY_BUFFER, cbo);
int err1 = glGetError();  //Error code 0

//Oddly, glMapBuffer always returns and invalid pointer.
//GLvoid * pColor = glMapBuffer(GL_ARRAY_BUFFER, GL_MAP_WRITE_BIT); 

//However, glMapBufferRange return a pointer that looks good 
GLvoid * pColor = glMapBufferRange(GL_ARRAY_BUFFER, 0, 9, GL_MAP_WRITE_BIT);
int err2 = glGetError(); //Error code 0

// Copy colors from host to device
memcpy(pColor, colorData2, 9);

//Unmap to force host to device copy
glUnmapBuffer(cbo);
int err3 = glGetError(); //Error code 1280

//Unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);
int err4 = glGetError(); //Error code 0

//******TEST THE WRITE******
GLubyte readbackData[9];
glBindBuffer(GL_ARRAY_BUFFER, cbo);
int err5 = glGetError(); //Error code 0
GLvoid * pColorX = glMapBufferRange(GL_ARRAY_BUFFER, 0, 9, GL_MAP_READ_BIT);
int err6 = glGetError(); //Error code 1282

//Mem copy halts because of a memory exception. 
memcpy(readbackData, pColorX, 9);

glUnmapBuffer(cbo);
glBindBuffer(GL_ARRAY_BUFFER, 0);

以下是我创建缓冲区对象的代码:

//Create color buffer
glGenBuffers(1, &cbo);
glBindBuffer(GL_ARRAY_BUFFER, cbo);

//Create space for three RGB 8-bit color objects
colorBufferSize = 3 * numColorChannels * sizeof(GLubyte);
glBufferData(GL_ARRAY_BUFFER, colorBufferSize, colorData, GL_DYNAMIC_DRAW);

//Unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);

1 个答案:

答案 0 :(得分:2)

1280或0x0500是GL_INVALID_ENUM

glUnmapBuffer获取绑定缓冲区对象的枚举,而不是取消映射的缓冲区对象。 glUnmapBuffer期望将未映射的缓冲区对象绑定到该绑定目标。因此glUnmapBuffer(GL_ARRAY_BUFFER)将取消映射当前绑定到GL_ARRAY_BUFFER绑定的任何内容。