Jump to content
  • Advertisement
Sign in to follow this  

OpenGL ES best way to render to grayscale texture in OpenGL (es 2)

Recommended Posts

I'm interested in rendering a grayscale output from a shader, to save into a texture for later use. I only want an 1 channel 8 bit texture rather than RGBA, to save memory etc.

I can think of a number of possible ways of doing this in OpenGL off the top of my head, just wondering what you guys think is the best / easiest / most compatible way, before I dive into coding? This has to work on old android OpenGL ES2 phones / tablets etc, so nothing too funky.

  1. Is there some way of rendering to a normal RGBA frame buffer, then using glCopyTexSubImage2D or similar to copy + translate the RGBA to a grayscale texture? This would seem the most obvious, and the docs kind of suggest it might work.
  2. Creating an 8 bit framebuffer. If this is possible / a good option?
  3. Rendering out RGBA, using glReadPixels, translating on the CPU to grayscale then reuploading as a fresh texture. Slow and horrible but this is a preprocess, and would be a good option is this is more guaranteed to work than other methods.

Share this post

Link to post
Share on other sites

If you look at glTexImage2D's documentation, it notes that texture images can only be stored as "GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA". While other versions of OpenGL do support diffrent internal formats for image data, (The OpenGL 4 documentation specifies internal formats such as GL_R8, which I think is what you would be looking for), OpenGL ES2 does not seem to support this.

While compressed internal formats do not seem to be available in base OpenGL ES2, extensions do exist that allow this to be achieved, if you have them. Consider the following:



Now, I couldn't find any extensions that offer an 8-bit internal format from briefly looking through the list of extensions, that were also compatible with OpenGL ES2. This extension also might be useful, however it is only compatible with OpenGL ES3 and does not give the option to store an 8-bit internal format:




Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!