PDA

View Full Version : glGetTexImage Write access violation with extension



Zetfire
08-01-2017, 02:25 AM
Hi,

So, i'm trying to retrieve a texture from the gpu to the CPU. This one has been captured thanks the NVAPI so it's using specific format. this is the capture code:


ret = glVideoCaptureNV(m_videoSlot, sequenceNum, captureTime);

//mirror the result in texture
if(m_bStreamToTextures)
{
for (int i = 0; i < m_numVideoObjects; i++) {
// To skip a costly data copy from video buffer to texture we
// can just bind a video buffer to GL_PIXEL_UNPACK_BUFFER_ARB and call
// glTexSubImage2D referencing into the buffer with the PixelData pointer
// set to 0.

glBindTexture(GL_TEXTURE_RECTANGLE_NV, m_videoTextures[i]);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, m_vidBufObj[i]);
glTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, m_videoWidth, m_videoHeight,
m_pixelFormat, GL_UNSIGNED_BYTE, 0);

glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
}
}

But when I try to retrieve this texture with glGetTexImage, i Got "memory could not be written" when not in debug. If i'm in debug, I have a write access violation. Which is strange, i checked the destination variable, it's initialized, i even initialized it just before the call of glGetTexImage but i have the same result.
I thought about the fact that i was trying to read the texture before the capture was finished. But i can paint it and after launch this code, i have the same result...
Here is my code:


int C_anccap::LoopAnimation()
{
// Animation loop.

if (this->CaptureVideo() != GL_FAILURE_NV)
{
Owidget->repaint();
if (this->rec[0].isStarted) {
glEnable(GL_TEXTURE_RECTANGLE_NV);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, this->m_SDIin.GetTextureObjectHandle(0));
GLenum g = glGetError();
//Access violation error
glGetTexImage(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, GL_UNSIGNED_BYTE, this->rec[0].pixels.get());
}
}
return TRUE;
}

//Display code
GLvoid C_anccap::drawOne()
{
// Enable texture
glEnable(GL_TEXTURE_RECTANGLE_NV);

// Bind texture object for first video stream
glBindTexture(GL_TEXTURE_RECTANGLE_NV, m_SDIin.GetTextureObjectHandle(0));

// Draw textured quad in lower left quadrant of graphics window.
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(-1, -1);
glTexCoord2f(0.0, (GLfloat)m_videoHeight); glVertex2f(-1, 1);
glTexCoord2f((GLfloat)m_videoWidth, (GLfloat)m_videoHeight); glVertex2f(1, 1);
glTexCoord2f((GLfloat)m_videoWidth, 0.0); glVertex2f(1, -1);
glEnd();
GLenum g = glGetError();
assert(glGetError() == GL_NO_ERROR);

// Disable texture
glDisable(GL_TEXTURE_RECTANGLE_NV);
}


I know that it's something possible because i was working with the WinAPI and the same code was working fine, but I decide to switch to QT to get a better interface. But I can't figure out where i've missed something...
If you have any clue where i should look
Thanks

-----
EDIT
I've tried to replace the format GL_TEXTURE_RECTANGLE_NV with GL_TEXTURE_2D. I still have the error when I try to retrieve the texture from the GPU so it don't come from the extension. (It's just an other Texture unit so it seems logic but with that I'm sure)
I also try GL_PACK_ALIGNEMENT but it doesn't change anything.