Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: can shaders draw indexed color arrays?

  1. #1

    can shaders draw indexed color arrays?

    I have some questions relating to shaders and whether or not they can perform array lookups fast enough to use them to draw indexed color arrays

    • Is this possible?
    • Would it be fast blitting pixels this way?
    • How would I do this effectivly?
    • Can you post a code example?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Are you talking about using gl*DrawArrays*() to render (effectively) gl*DrawElements*() batches?

    Seems like that would prevent effective use of the post-vertex shader transform cache (to suppress needless vertex shader executions).

    Or are you literally just talking about using an indirect lookup to fetch your vertex colors? Say, store a color index in your vertex color atttribute and then in the shader do a uniform, texture, or buffer lookup using that index. If so, then I would expect this to be pretty fast. Put it in the fastest memory you can afford to based on its size.

  3. #3
    like using actual c# arrays as a indexed bitmap and palette and using shaders to look them up and draw them
    like this..
    Click image for larger version. 

Name:	Indexed_palette.jpg 
Views:	41 
Size:	7.3 KB 
ID:	2828

  4. #4
    Intern Contributor
    Join Date
    Apr 2016
    Berlin / Germany
    I think there are lots of different solutions for this. A simple one would be to use two textures as data-sources. Your sample-image demonstrates, what i mean:
    One texture (might have only 8bit per pixel), where the indices are stored, as in the upper of the three illustrations.
    The second has only one row or column of pixels, containing the colors by index, like in the second illustration.

    In the fragment shader, you can access the first one by the normal gl_TextCoord, to get the color-index, wich is the y-coordinate that you have to pick from the second one, to get the output-color.

    The Fragment-shader might contain code like this:
    Code :
    float colorIndex = texture2D(Texture1, gl_TexCoord[0].st).r;
    color = texture2D(Texture2, vec2(0, colorIndex));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts