Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Seeking advice for transfer data to GPU

  1. #1
    Junior Member Newbie
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    14

    Seeking advice for transfer data to GPU

    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 :
    Code :
    //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.

  2. #2
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Czech Republic
    Posts
    317

    Re: Seeking advice for transfer data to GPU


    Use PBO.

    there are several discussions about this topis, for example this:

    http://www.opengl.org/discussion_boa...234947&fpart=1

  3. #3
    Junior Member Newbie
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    14

    Re: Seeking advice for transfer data to GPU

    i'm checking that discussion now, i have similar problem, my PBO just now working on the single thread app, but only shows green (green = 0 + YUV to RGB conversion) on the multithreading app.

    thanks!

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Seeking advice for transfer data to GPU

    Why you use GL_DEPTH_BUFFER_BIT glVertex3f as
    it's not needed
    Perhaps(I am just beginner)
    and i see that z axis is zero in code
    try
    replace it
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    with
    glClear (GL_COLOR_BUFFER_BIT);
    and
    all of
    glVertex3f(blaX,blaY,blaZ);
    with
    glVertex2f(blaX,blaY);//blaZ is gone from life
    please don't take it on heart
    cause heart diseases are in majority
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  5. #5
    Junior Member Newbie
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    14

    Re: Seeking advice for transfer data to GPU

    hey! thanks! no worry, none taken

    thank you, i changed the glvertex3f into glvertex2f, thanks for the advice!

    but i keep the GL_DEPTH_BUFFER_BIT as without it, it just shows black. (perhaps because i also do something with the depth, like zooming and scrolling the texture?).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •