Jump to content
  • Advertisement
Sign in to follow this  
Gyiove Sparkle

OpenGL Opengl and 8bit indexed textures color[256][3],colorindex[256]

This topic is 1320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone!


I wanted to ask that how i would make 8bit indexed textures load in opengl and also use them in shader if the struct of image is like this:
{ 255, 0, 0   , 0, 255, 0, ... ( 256 colors ), 1, 0, 3, 4 ... ( color index ) }

 

I would like to use those type of textures only if texture is animated and there are alot of frames.

What i would expect is to somehow bind those colors and then bind image what contains only color indexes.

Also sometimes i dont need 256 colors, sometimes 128 or 64 is needed so im looking for a best way to save memory.
Thanks!

 

Share this post


Link to post
Share on other sites
Advertisement

You can store palette in 1D texture. Shader will read index from texture, calculate location in palette from that index, then read final color from palette texture.

That might be slower though, as gpu's (especially mobile) don't like dependent texture reads.

Share this post


Link to post
Share on other sites

This is going to be highly problematic. If you are doing this to emulate some super retro look and will only be using nearest neighbor filtering, then you are fine. Otherwise you are going to find out really quickly that you cannot utilize hardware texture filtering and are going to have to manually implement bilinear/trilinear filtering. Anisotropic filtering is probably out of the question. Besides, if you aren't doing something retro and are simply looking to save memory, that is what compressed textures are for.

Share this post


Link to post
Share on other sites

Can you tell me more about those compressed textures?
Never heard about them...

( simple few line example how to work with them )

Edit readed about them and i think they are not worth the memory saving or should i use them?
My plan is not to use indexed textures, only normal textures i guess...

Edited by Gyiove Sparkle

Share this post


Link to post
Share on other sites

Most standard aproach is to have an entire animation texture, for example of resolution 2042*2042 and have 256*256 or 128*128 atlased frames in it. It is up to shader to pick and rasterize desired one, through uniform shader value being issued.  If you want to save memory, you can use 16 bit RGB texture format in ogl texture creation (glTexImage2D), though 8 bit pallete textures are not provided. You can create this 16bit RGB texture from any RGB source image (24bit true color jpeg or png or whatever), this would allow you to upload to GPU twice more textures, since aproach of animating by texture frames is expensive over that.

 

In case you would really wish to use 8bit textures, what might be sufficient for your production, then you will need to create a (partialy) custom asset, a png image that carries in its 4 channels for sepparate textures. Then load it standardly as a RGBA texture of 8 bits per channel and use that in shaders. This would be most resources saving, but it would complicate the production, since you would have to create this custom 4 channel 32 bit image from your four 256 color textures - in a custom way.

Share this post


Link to post
Share on other sites
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!