Вопрос по opengl – OpenGL - рисовать пиксели на экране?


Я хочу нарисовать двумерный массив данных пикселей (значения RGB / оттенки серого) на экране как можно быстрее, используя OpenGL. Данные пикселей часто меняются.

Я надеялся, что найду простую функцию, которая позволит мне вставить указатель на массив, представляющий данные пикселей, поскольку это, вероятно, самый быстрый подход. К сожалению, я не нашел такой функции.

Каков наилучший способ выполнить эту задачу?

Error: User Rate Limit Exceededstackoverflow.com/questions/6151135/… Ciro Santilli 新疆改造中心 六四事件 法轮功

Ваш Ответ

3   ответа

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded


Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded


Error: User Rate Limit Exceeded

  • use glTexImage2D and glTexSubImage2D to upload the data to the texture (ie bind the texture (and texture unit, if applicable) before calling that)

  • in my case as the video frame rate (usually about 24 fps) is lower than the framerate of my application (aimed at 60 fps), in order to avoid uploading the same data again I use a framebuffer object (check out glGenFramebuffers/glBindFramebuffer/glDeleteFramebuffers) and link my texture with the framebuffer (glFramebufferTexture2D). I then upload that texture once, and draw the same frame multiple times (just normal texture access with glBindTexture)

  • I don't know which platform you are using, but as I am targetting Mac I use some Apple extensions to ensure the data transfer to the VRAM happens through DMA (ie make glTexSubImage2D return immediately to let the CPU do other work) - please feel free to ask me for more info if you are using Mac too

  • also as you are using just grayscale, you might want to consider just using a GL_LUMINANCE texture (ie 1 byte per pixel) rather than RGB based format to make the upload faster (but that depends on the size of your texture data, I was streaming HD 1920x1080 video so I needed to make sure to keep it down)

  • also be aware of the format your hardware is using to avoid unnecessary data conversions (ie normally it seems better to use BGRA data than for example just RGB)

  • finally, in my code I replaced all the fixed pipeline functionality with shaders (in particular the conversion of the data from grayscale or YUV format to RGB), but again all that depends on the size of your data, and the workload of your CPU or GPU

Error: User Rate Limit Exceeded

Похожие вопросы