Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. newbie opengl question: rendering into an OGL texture for blitting
QtWS25 Last Chance

newbie opengl question: rendering into an OGL texture for blitting

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 462 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by
      #4

      @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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        davecotter
        wrote on last edited by
        #2

        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);
        
        1 Reply Last reply
        0
        • W Offline
          W Offline
          wrosecrans
          wrote on last edited by
          #3

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            davecotter
            wrote on last edited by
            #4

            @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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved