Hi guys!
I am a student and quite new to OpenGL, and this is my first post. I am currently trying to develop a multithreading application (with queueing mechanism) to play YUV video files.
The first and second threads are reading and processing the file, while the third contains the openGL (with freeglut) to render it.
The second thread provides the input data in a buffer for each frame, to be handle then by the 3rd thread. The buffer structure is “y, u, v, y, u, v,…” and so on. The YUV to RGB conversion is done in the shader (cg).
At first i tried to transfer data to GPU in a normal way :
//init method
DATA_SIZE = width * height * 3;
tempBuffer = (GLubyte *) calloc(sizeof(GLubyte),DATA_SIZE);
glBindTexture(GL_TEXTURE_2D, g_textureID[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, tempBuffer);
glBindTexture(GL_TEXTURE_2D, 0);
free(tempBuffer);
//display method, called each frame
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0, 0, g_zoom);
gluLookAt( moveX, moveY, moveZ, g_scroll_X, g_scroll_Y, 0.0, 0.0, 1.0, 0.0 );
glBindTexture(GL_TEXTURE_2D, g_textureID[0]);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE, colorBuffer);
glBegin (GL_QUADS);
glTexCoord2f (0.0f,0.0f);
glVertex3f (-10.0f, -10.0f, 0.0f);
glTexCoord2f (1.0f, 0.0f);
glVertex3f (10.0f, -10.0f, 0.0f);
glTexCoord2f (1.0f, 1.0f);
glVertex3f (10.0f, 10.0f, 0.0f);
glTexCoord2f (0.0f,1.0f);
glVertex3f (-10.0f, 10.0f, 0.0f);
glEnd ();
glBindTexture(GL_TEXTURE_2D, 0);
glutSwapBuffers();
glutPostRedisplay ();
(So, did I make some mistake there? anything i can improve?)
That was working just fine, i can play the input file, except that the speed is slow.
But anyway, since its quite slow (especially for huge-sized input file), its positive that i have to use another method.
After few weeks reading, i find VBO, FBO, and PBO. but still, now im still not sure which one is the best for me (VBO, FBO, PBO?).
Basically my application is streaming the input file, and frequently updating the data in the buffer. Any suggestion?
And, when i tried PBO, something wrong with my glMapBuffer because it returned NULL instead of pointer to memory allocation for the buffer. I have no clue what is wrong…
Btw, I don’t know if this is related, i am using Radeon HD 4670 on Windows XP 32, with C language on Visual Studio.
I’m sorry for my noob-inity, for the bad english, or if similar problem already posted before…
Any help would be appreciated! ^^
Thank you in advance.