×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    59

    Question OpenGL: How to Optimize Texture Update

    Hello,

    I am trying to show a video as a texture of a surface in openGL. I managed to do that, however I face performance issues. I only get 10 FPS.

    I have a gstreamer pipeline that ends with appsink that manages (without drawing on the screen) get 30 FPS at resolution 640×480. In my application i create an QGlWidget where I initialize a texture which is refreshed in the paintGL function. The texture is painted with paintTexture function.

    Is this the optimal way to do this. I read online that doing it with FBO and inside GLU would make it run faster.

    Questions:
    1.) How to optimize texture update? Is the method shown bellow an optimal way to do so?
    2.) Is the method bellow using the same engine as Frame Buffer Objects?

    Thanks for your help.
    Klen

    Code:
    void GLWidget::initializeGL ()
    {
        glEnable(GL_TEXTURE_2D);
        glGenTextures(1, &m_uiTexture);
        ...
    }
    
    void GLWidget::paintTextured()
    {
    	//refresh_texture();
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, m_uiTexture);
    	GLfloat afVertices[] = {
    		-0.5, -0.5, -0.5, 0.5,-0.5,-0.5,-0.5,0.5,-0.5,
    		0.5, 0.5, -0.5, -0.5,0.5,-0.5,0.5,-0.5,-0.5,
    	};
    	glVertexAttribPointer(vertexAttr2, 3, GL_FLOAT, GL_FALSE, 0, afVertices);
    	glEnableVertexAttribArray(vertexAttr2);
    
    	GLfloat afTexCoord[] = {
    		1.0f,1.0f, 0.0f,1.0f, 1.0f,0.0f,
    		0.0f,0.0f, 1.0f,0.0f, 0.0f,1.0f,
    	};
    	glVertexAttribPointer(texCoordAttr2, 2, GL_FLOAT, GL_FALSE, 0, afTexCoord);
    	glEnableVertexAttribArray(texCoordAttr2);
    
    	GLfloat afNormals[] = {
    		0,0,1, 0,0,1, 0,0,1,
    		0,0,1, 0,0,1, 0,0,1,
    	};
    	glVertexAttribPointer(normalAttr2, 3, GL_FLOAT, GL_FALSE, 0, afNormals);
    	glEnableVertexAttribArray(normalAttr2);
    
    	glUniform1i(textureUniform2, 0);    // use texture unit 0
    
    	glDrawArrays(GL_TRIANGLES, 0, 6);
    
    	glDisableVertexAttribArray(vertexAttr2);
    	glDisableVertexAttribArray(normalAttr2);
    	glDisableVertexAttribArray(texCoordAttr2);
    }
    
    void GLWidget::paintGL()
    {
        QPainter painter;
        painter.begin(this);
      
        glEnable(GL_TEXTURE_2D);
      
        CameraN900::refresh_buffer(); //manually call appsink to fatch for data in the buffer
        unsigned char* data=(unsigned char *) GST_BUFFER_DATA (CameraN900::buffer);
        glBindTexture(GL_TEXTURE_2D, m_uiTexture);
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, buffer_width,buffer_height, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
    
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    
    
        GLfloat modelview[16];
        IdentityMatrix(modelview);
        ScaleMatrix(modelview, 1.8, 1.8, 0);
        glUseProgram(program2);
        glUniformMatrix4fv(matrixUniform2, 1, GL_FALSE, modelview);
        paintTextured();
        glUseProgram(0);
        swapBuffers();
     }

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: OpenGL: How to Optimize Texture Update

    There is OpenGL ES 2.0 example application. It shows on my N900 something around 90fps.
    http://qt.gitorious.org/+qt-develope...gl/hellogl_es2
    Note that making window fullscreen and setting attributes Qt::WA_PaintOnScreen and Qt::WA_NoSystemBackground will fps increase.

  3. #3
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    59

    Re: OpenGL: How to Optimize Texture Update

    Quote Originally Posted by divanov View Post
    There is OpenGL ES 2.0 example application. It shows on my N900 something around 90fps.
    http://qt.gitorious.org/+qt-develope...gl/hellogl_es2
    Note that making window fullscreen and setting attributes Qt::WA_PaintOnScreen and Qt::WA_NoSystemBackground will fps increase.
    You are right it is a slightly modified example application. 90 FPS? I get maximum 30 FPS on original example, however I am running hellogl_es2 for QT 4.5 example. I will upgrade my N900 to QT 4.6 ASAP and report if I also get the same performance. I tried to set Qt::WA_PaintOnScreen and Qt::WA_NoSystemBackground flags, but did not notice much performance improvements.

    Thanks you very much for your reply. They are always very helpful.

    Klen

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: OpenGL: How to Optimize Texture Update


  5. #5
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    59

    Re: OpenGL: How to Optimize Texture Update

    Quote Originally Posted by divanov View Post
    Fantastic performance. After updating to QT 4.6 I get the same performance on the hellogl_es2 example and my camera stream application also runs now at 30 fps .

    Happy Happy Happy. Thanks for your help again. After I finish my app I plan to write a short tutorial.

    Klen

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    16

    Re: OpenGL: How to Optimize Texture Update

    Quote Originally Posted by Klen View Post
    Happy Happy Happy. Thanks for your help again. After I finish my app I plan to write a short tutorial.
    Klen
    Hello and sorry for pumping up an old thread. Is there a tutorial you mention available how to blend a video/capture and Qt images?
    thx

  7. #7
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: OpenGL: How to Optimize Texture Update

    Hi Whome1,
    Did you take a look at this:
    http://blogs.igalia.com/magomez/2010...igicam-and-qt/

  8. #8
    Registered User
    Join Date
    Mar 2005
    Posts
    16

    Re: OpenGL: How to Optimize Texture Update

    Thx I have taken both projects and will study sources. I don't have N900 but maybe it gives me some ideas.

    git clone --verbose http://git.igalia.com/user/magomez/qtcamera.git
    git clone --verbose git://gitorious.org/fremantle-gdigicam/gdigicam.git

  9. #9
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    59

    Re: OpenGL: How to Optimize Texture Update

    Quote Originally Posted by whome1 View Post
    Hello and sorry for pumping up an old thread. Is there a tutorial you mention available how to blend a video/capture and Qt images?
    thx
    Here is the source and a short description on how to start working on Augmeted Reality apps. The source also includes the part how to display the camera video stream as an OpenGL texture.

    Hope this helps.

    http://talk.maemo.org/showthread.php?p=695546#post695546


    Cheers,
    Klen

Similar Threads

  1. Can not change the loaded texture in OpenGL ES
    By MobileVisuals in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2009-09-25, 17:53
  2. Using camera frame as OpenGL texture, problem!!
    By abolfoooud in forum Symbian Media (Closed)
    Replies: 29
    Last Post: 2009-06-18, 02:58
  3. Texture matrix stack on Symbian opengl es?
    By hannu.kononen in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2009-05-08, 07:40
  4. Series 60 BMP Texture Mapping With OpenGL ES Problem
    By abolfoooud in forum Symbian Media (Closed)
    Replies: 7
    Last Post: 2008-06-13, 03:53
  5. Series 60 BMP Texture Mapping With OpenGL ES Problem
    By abolfoooud in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-09-13, 16:13

Posting Permissions

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