Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

newbie opengl question: rendering into an OGL texture for blitting



  • can i, using just Qt Painter APIs, set pixels in an openGL texture?

    eg: i have a pixel map in HSV format and i want loop over the pixels, converting each to RGB and storing the result directly in an OpenGL texture, then blit that texture. (i'm doing color cycling on the HSV pixels). i'm loathe to load the HSV pixels into OpenGL and write a "shader" cuz that's way outside my area, just hoping there's like a "setpixel" function i can use on an OpenGL texture?..

    just by using a QOpenGLWidget (instead of QGraphicsScene), i get a 2x speedup, but i'm still not getting 30fps. but i'm converting it all in QImage pixels and after all that, blitting using QPainter, i figure it's faster to convert directly to an OGL texture and blit that?



  • @wrosecrans said in newbie opengl question: rendering into an OGL texture for blitting:

    It's way faster to just making a full image in host CPU memory, then upload a finished texture in one big transfer, than to poke individual pixels in GPU memory one at a time.

    i'm doing that now and i DO get a 2x speedup, which is much better than not.

    so it sounds like i have to do all the ops using OGL to get more performance. bummer. i naively thought i could send instructions to opengl one pixel at a time and build the texture there



  • i'm looking for something like this:

    // init code
    QOpenGLTexture		*pixelsP(new QOpenGLTexture(whatever params));
    
    // animation code
    for (loop over x) {
    	for (loop over y) {
    		QPoint		pixLoc(x, y);
    		QColor		pixColor(figure this out);
    		
    		pixelsP->setPixel(pixLoc, pixColor);
    	}
    }
    
    //	somewhere else
    painterP->blit(pixelsP);
    


  • You've got a couple of questions here, that are potentially complicated to answer.

    @davecotter said in newbie opengl question: rendering into an OGL texture for blitting:

    can i, using just Qt Painter APIs, set pixels in an openGL texture?

    Yes, you can use QPainter on a GPU surface using QOpenGLFrameBufferObject as the surface, and then use a QOpenGLTextureBlitter to blit the texture from the FBO. But I don't know if that's actually what you want to do, given...

    eg: i have a pixel map in HSV format and i want loop over the pixels, converting each to RGB and storing the result directly in an OpenGL texture,

    That's... technically possible in some cases, but it's a terrible idea. If you get the GPU memory mapped in a way that you can write to it from the CPU, this is going to be the slowest possible way to do things. By trying to write to GPU memory (an OpenGL texture), you are saying you want to do all of the operations on memory that is as far as possible from the CPU. Then, you want to draw using a texture that is mapped to be writable to the CPU which will mean that it's also the slowest possible texture to draw.

    i'm loathe to load the HSV pixels into OpenGL and write a "shader" cuz that's way outside my area

    Well... Your goals are in opposition. You want to use OpenGL, but you want to do it by not using OpenGL. It's like wanting to get a nice fancy car, but not use any gas. So, you tow your Mercedes behind a bicycle everywhere you go. A shader will be really good at doing a colorspace conversion like that, and it'll work locally on the GPU when drawing the etxture, so it will be fast. You can just send the GPU the current cycle's phase for the color cycling every frame, rather than re-uploading the whole RGB texture.

    just hoping there's like a "setpixel" function i can use on an OpenGL texture?..

    It's way faster to just making a full image in host CPU memory, then upload a finished texture in one big transfer, than to poke individual pixels in GPU memory one at a time.



  • @wrosecrans said in newbie opengl question: rendering into an OGL texture for blitting:

    It's way faster to just making a full image in host CPU memory, then upload a finished texture in one big transfer, than to poke individual pixels in GPU memory one at a time.

    i'm doing that now and i DO get a 2x speedup, which is much better than not.

    so it sounds like i have to do all the ops using OGL to get more performance. bummer. i naively thought i could send instructions to opengl one pixel at a time and build the texture there


Log in to reply