User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

RGB565 when RGB888 reqested

Thu Dec 13, 2012 8:20 pm

In the call to CreateEGLContext I pass an attrib list like this....

EGLint attribList[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
.......
EGL_NONE
};

I'm using "colour picking" to identify objects under the mouse cursor, but the return values from glReadPixels suggest there are only 5 bits of Red and Blue and 6 bits of Green (i.e. RGB 565)

Q1) Does the GPU support 24 bit colour ?
Q2) If so, how do I get EGL to give me a 24bit context ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: RGB565 when RGB888 reqested

Fri Dec 14, 2012 12:10 pm

The answer to question 1 is 'yes' - works perfect using either 'plain' framebuffer code or dispmanx.

Unfortunately I don't know EGL yet... based on 'educated guessing' it might be that those parameters are not enough to force the color-mode on EGL or you get the pixel-values from some other component that is still in the RPi default 16bit/565 mode...
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

dattrax
Posts: 52
Joined: Sat Dec 24, 2011 5:09 pm

Re: RGB565 when RGB888 reqested

Fri Dec 14, 2012 1:22 pm

Q1) Does the GPU support 24 bit colour ?
not really as a packed pixel format, you need to think of it as XBGR, 24valid bits in a 32bit word
Q2) If so, how do I get EGL to give me a 24bit context ?
EGL has a sort order for the configs returned.

you need to do something like this

Code: Select all

      if (!eglGetConfigs(p->display, NULL, 0, &numberConfigs))
      {
         errno = ECONNREFUSED;
         return -1;
      }

      eglConfigs = (EGLConfig *)alloca(numberConfigs * sizeof(EGLConfig));

      if (!eglChooseConfig(p->display, configAttributes, eglConfigs, numberConfigs, &numberConfigs) || (numberConfigs == 0))
      {
         errno = ECONNREFUSED;
         return -1;
      }

      for (i = 0; i < numberConfigs; i++)
      {
         EGLint redSize, greenSize, blueSize, alphaSize, depthSize;
         eglGetConfigAttrib(p->display, eglConfigs[i], EGL_RED_SIZE, &redSize);
         eglGetConfigAttrib(p->display, eglConfigs[i], EGL_GREEN_SIZE, &greenSize);
         eglGetConfigAttrib(p->display, eglConfigs[i], EGL_BLUE_SIZE, &blueSize);
         eglGetConfigAttrib(p->display, eglConfigs[i], EGL_ALPHA_SIZE, &alphaSize);
         eglGetConfigAttrib(p->display, eglConfigs[i], EGL_DEPTH_SIZE, &depthSize);

         if (p->bpp == (redSize + greenSize + blueSize + alphaSize))
            break;
      }
      selectedConfig = i;

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: RGB565 when RGB888 reqested

Fri Dec 14, 2012 2:37 pm

Thought I had seen something related... the hello_triangle example (triangle.c):

Code: Select all

   static const EGLint attribute_list[] =
   ...

   ...
   // get an appropriate EGL frame buffer configuration
   result = eglChooseConfig(state->display, attribute_list, &config, 1, &num_config);
   assert(EGL_FALSE != result);

   // create an EGL rendering context
   state->context = eglCreateContext(state->display, config, EGL_NO_CONTEXT, NULL);
   assert(state->context!=EGL_NO_CONTEXT);
   ...
PeterO: I assume you may have started from this? Are you saying the eglChooseConfig does not work for you?
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: RGB565 when RGB888 reqested

Fri Dec 14, 2012 8:07 pm

dattrax wrote:
you need to do something like this
I tried you code. It returns nonsense values for reg/green/blue sizes :-(
More work needed here .....
........<few minutes pass>.....
And now it is returning sensible values.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: RGB565 when RGB888 reqested

Fri Dec 14, 2012 8:36 pm

OK, so this says I am choosing a 32 bit/pixel configuration, but the values read back through colour picking STILL show 565 bits for RGB.... :?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dattrax
Posts: 52
Joined: Sat Dec 24, 2011 5:09 pm

Re: RGB565 when RGB888 reqested

Sat Dec 15, 2012 10:08 am

the values read back through colour picking STILL show 565 bits for RGB
What arguments are you using to glReadPixels()?

Jim

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: RGB565 when RGB888 reqested

Sat Dec 15, 2012 9:40 pm

dattrax wrote:What arguments are you using to glReadPixels()?
Jim
The right ones (I think) :lol:
glReadPixels( esContext->width/2 ,esContext->height/2,1,1,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: RGB565 when RGB888 reqested

Sun Dec 16, 2012 7:54 am

!!!! D'OH !!!! :oops:
For colour picking I had forgotten that my code renders the scene into a frame buffer object to avoid an annoying on screen flash.....

Code: Select all

glRenderbufferStorage(GL_RENDERBUFFER,GL_RGB565, esContext.width ,esContext.height); 
                                      ^^^^^^^^^
Hmmmmmm... Seems the only options for frame buffer object are

#define GL_RGBA4 0x8056
#define GL_RGB5_A1 0x8057
#define GL_RGB565 0x8D62

I'll give GL_RGB5_A1 a try. At least that should give consistent behaviour for all three colour channels.

Actually, thinking more about this, I'm stuck with RGB565 as I think I need a 16 bit depth buffer so that the scene is rendered the same (in terms of z buffering) in the frame buffer object and on the screen.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

fxmaker
Posts: 43
Joined: Fri Dec 07, 2012 6:37 pm

Re: RGB565 when RGB888 reqested

Wed Dec 19, 2012 6:23 pm

For reference, here are the configs reported on my Pi (B).

Code: Select all

EGLConfig(1) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 24
EGLConfig(2) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 24
EGLConfig(3) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 24
EGLConfig(4) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 24
EGLConfig(5) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 0
EGLConfig(6) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 0
EGLConfig(7) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 0
EGLConfig(8) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 0
EGLConfig(9) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 24
EGLConfig(10) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 24
EGLConfig(11) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 24
EGLConfig(12) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 24
EGLConfig(13) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 0
EGLConfig(14) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 0
EGLConfig(15) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 0
EGLConfig(16) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 0
EGLConfig(17) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 24
EGLConfig(18) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 24
EGLConfig(19) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 0
EGLConfig(20) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 0
EGLConfig(21) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 24
EGLConfig(22) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 24
EGLConfig(23) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 0
EGLConfig(24) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 0
EGLConfig(25) Red: 8 Green: 8 Blue: 8 Alpha: 8 Depth: 0
EGLConfig(26) Red: 8 Green: 8 Blue: 8 Alpha: 0 Depth: 0
EGLConfig(27) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 0
EGLConfig(28) Red: 5 Green: 6 Blue: 5 Alpha: 0 Depth: 16

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: RGB565 when RGB888 reqested

Wed Dec 19, 2012 7:08 pm

Those are the "modes" available for the frame buffer. Frame buffer objects (= off screen frame buffers) have a much more restricted set of available modes. That's where my problem came from.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

fxmaker
Posts: 43
Joined: Fri Dec 07, 2012 6:37 pm

Re: RGB565 when RGB888 reqested

Wed Dec 19, 2012 7:16 pm

PeterO wrote:Those are the "modes" available for the frame buffer. Frame buffer objects (= off screen frame buffers) have a much more restricted set of available modes. That's where my problem came from.
PeterO
Indeed. My post was poorly placed in reference to: dattrax » Fri Dec 14, 2012 7:22 am.

To save me trouble later, how limited are the Pi's FBO's?

Multisample? Float? Multisample and float?

Thanks

Return to “OpenGLES”