开发者

openGL glUnmapBuffer() returning unknown error code 1280

开发者 https://www.devze.com 2023-04-01 02:44 出处:网络
I am writing some proof-of-concept code. I want to prove that I can write data to a buffer object after the buffer has been created. However, I am getting a a GLenum error code of 1280 when I try to u

I am writing some proof-of-concept code. I want to prove that I can write data to a buffer object after the buffer has been created. However, I am getting a a GLenum error code of 1280 when I try to unmap the buffer after writing to it. I am completely stymied.

I can initialize the buffer the with color data and successfully render it. The problem is that I cannot modify the data in the buffer afterwards. The code is below. It shows how I write the new data to the buffer and then how I try to read it back. The error codes are shown in comments after the glGetError() calls. The variable "cbo" is the color buffer:

//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);

Here is the code where I created the buffer object:

//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);


1280, or 0x0500, is GL_INVALID_ENUM.

glUnmapBuffer takes the enum where the buffer object is bound, not the buffer object to unmap. glUnmapBuffer expects the buffer object to be unmapped to be bound to that binding target. So glUnmapBuffer(GL_ARRAY_BUFFER) will unmap whatever is currently bound to the GL_ARRAY_BUFFER binding.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号