PDA

View Full Version : reuse Pixel buffer without pointer update



learnopengl-2000
06-18-2009, 05:40 PM
I am new to OpenGL and need help in the application described as follows

In the system, I have a video capture card and a GPU card. I am going to use 4 Pixel buffers for video forwarding. The goal is to implement zero-memory-copy streaming from capture card to GPU.

However I could not rotate and reuse the buffers in GPU side

It seems the host to GPU DMA can only be triggered when I use
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[i]);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, gTexSize, 0, GL_DYNAMIC_DRAW_ARB);

for every frame. But I couldn’t do that because OpenGL could return a new pointer for me and I have to update the DMA setup in capture side dynamically and it consumes CPU time.

I copied pseudo code as follows:
Thanks in advance for the helps

-----------------------------------------------------------------------------------

First, I want to allocate 4 pixel buffers


glGenBuffersARB(4, pboIds);
for (i=0; i<4; ++i) {
void *p;
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[i]);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, gTexSize, 0, GL_DYNAMIC _DRAW_ARB);
p = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_AR B, GL_WRITE_ONLY_ARB);

//now save the pointers to kernel
}

Second, I tell my capture card driver to use these 4 buffers as a circular buffer for video capturing (DMA), this works (I can save the video to persistent storage), For some reason, I cannot update DMA address dynamically (have to setup DMA address once and use it forever)

Third, in Glut display callback function (pseudo code) ( glBindBuffer, glBindTexture, glTexSubImage2D). however DMA (host – GPU) seems never happen repeatly for every new buffer.

{
Buffer_t *vbuf = NULL;
Buffer_t *newvbuf;

if (vbuf) {
//return vbuf to capture driver for reuse;
}

if(!(newvbuf = read_frame(&amp;session)))
{
printf("cannot read a frame, something wrong\n");
exit(1);
}
vbuf = newvbuf;

glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[newvbuf->index]);
glBindTexture(gTarget, textureId);
glTexSubImage2D(gTarget, 0, 0, 0, gTexWidth, gTexHeight, PIXEL_FORMAT, GL_UNSIGNED_BYTE, 0);//vbuf->m.userptr);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

// save the initial ModelView matrix before modifying ModelView matrix
glPushMatrix();

// for Gl Perspective
glTranslatef(0, 0, cameraDistance);
glRotatef(cameraAngleX, 1, 0, 0); // pitch
glRotatef(cameraAngleY, 0, 1, 0); // heading

// draw a point with texture
glColor4f(1, 1, 1, 1);

glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
// gluPerspective
glTexCoord2f(0.0f, gImageHeight); glVertex3f(-1.0f, -gAspectRatio, 0.0f);
glTexCoord2f(gImageWidth, gImageHeight); glVertex3f( 1.0f, -gAspectRatio, 0.0f);
glTexCoord2f(gImageWidth, 0.0f); glVertex3f( 1.0f, gAspectRatio, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, gAspectRatio, 0.0f);

glEnd();

// unbind texture
glBindTexture(gTarget, 0);
glPopMatrix();

glutSwapBuffers();
}

Brolingstanz
06-19-2009, 12:18 PM
Haven't done much of this myself, but if your search the advanced coding forum you'll find some great tips in this area.