简体   繁体   中英

OpenGL SetPixel with a fragment shader

So, I'm trying to modify a specific pixel of a sprite. Currently I've made it work by creating myself a SetPixel(int x, int y, Color color) function. It works by modifying texture's info(RGBA values) and than passing it to a sprite. But this is slow:

  1. Using CPU instead of GPU where (I HOPE) I could use shaders to improve my performance.
  2. I have to re-upload modified texture every time I modify a single pixel.

This question is big to me. How do I use shaders in order to modify a specific pixel? I only can modify color per Vertex which is not what I want.

Any suggestions?

First of all you don't have to upload all texture and after every pixel update. You can cache changes and update smallest rectangle with glCopyTextSubImage .

If you really want to try GPU updates, you can use compute shaders (however, some old hardware doesn't support them) or bind your texture data as SSBO and write directly to it without using separate framebuffer object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM