On Oct 14, 2016, at 17:11, Chad Stearns <
chadst...@gmail.com> wrote:
> So Ive got a pretty weird use case, where I want to render onto a 2D view, and I need to specify individual pixel color values. I am pretty familiar with how canvas elements work. Im trying to study up on web-gl, and I understand that its more performant by accessing the clients GPU. Ive got some buggy code that doesnt work right now that renders a flat surface directly in front of the view. Two questions..
>
> 0 Since I just want to specify pixel color data, are there actually any performance gains for my use case by using web-gl?
If you can rewrite your "specifying pixel colors" as a GLSL shader, so that a single shader computes many pixels' colors (on the GPU), then you can get a very large benefit from WebGL.
If your code has to run on the CPU, but you can arrange to write the color values of many pixels into an array (that makes up an image) to be drawn all at once as an image/texture, then this will have decent performance and you can use _either_ 2D-context (ImageData) or WebGL (textures) to do it.
If you really, really have to change lots of non-adjacent pixels at a time, you should use 2D-context because it will be more efficient at that than WebGL.
> 1 Is there a way to do this? How? What I really want in an api where I say something like 'change the color at pixel (x, y) to color B'. Is there any way to use web-gl to do this in a way that has performance advantages from just doing that to a canvas element directly?
In general, "set this pixel to this color" is the _least_ efficient case for _any_ graphics API. You are much better off figuring out how to draw whatever you're drawing in bigger batches.
If you gave more information about exactly what you are drawing and how it is computed, I could be more specific about how you might efficiently draw it.