User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

GLSL weirdness / possible bug?

Tue May 22, 2012 8:22 pm

I'm wondering if I've spotted a bug with some sample code I've written.

All I'm doing is rendering a triangle on screen with very simple vertex and fragment shaders. If I set gl_FragColor explicitly in the fragment shader like this...

Code: Select all

//Fragment shader.
void main()
{
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
...then I get a sold red triangle on screen. However, if I use a varying variable for the color and set it in the vertex shader like this...

Code: Select all

//Vertex shader.
attribute vec4 position;
varying vec4 colour;

void main()
{
	colour = vec4(1.0, 0.0, 0.0, 1.0);
	gl_Position = position;
}

//Fragment shader.
varying vec4 colour;

void main()
{
	gl_FragColor = colour;
}
...then I get a semi-transparent red triangle (I can see the terminal commands through it). The rest of the code is identical so I would expect the two cases above to produce exactly the same results.

Interestingly, if I try and use the colour green instead of red then I get a green triangle in the first case but, instead of a semi-transparent green triangle for the second case, I get a fully transparent triangle.

Any ideas?

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 8:51 am

Thinking about it, is this the correct section for this question? Perhaps it should be moved into the feedback section?

User avatar
ArborealSeer
Posts: 300
Joined: Tue Jan 24, 2012 9:48 am
Location: South West, UK

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 9:45 am

have been pushing for a specific GPU (OpenGL ES/OpenVG) section here > http://www.raspberrypi.org/phpBB3/viewt ... =63&t=6239

add your voice :)
Pi Status > Farnell, Arrived 24/5- RS, Arrived 1/6

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 9:53 am

I've added my voice. The reason I suggested it be moved into Feedback is that it's looking like it might actually be a bug. I can't imagine what else it could be but I'm hoping someone can prove me wrong :)

shirro
Posts: 248
Joined: Tue Jan 24, 2012 4:54 am

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 10:18 am

I can't reproduce that here. They both look opaque to me.

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 11:05 am

Crap, I've just figured out what it is. User error as always. *doh!*

It's because I was only passing the following into eglChooseConfig:

Code: Select all

    EGLint const attribList[] = {
        EGL_RED_SIZE, 5,
        EGL_GREEN_SIZE, 6,
        EGL_BLUE_SIZE, 5,
        EGL_NONE
    };
I stupidly assumed that this would default to no alpha but as soon as I added an alpha size like this...

Code: Select all

    EGLint const attribList[] = {
        EGL_RED_SIZE, 5,
        EGL_GREEN_SIZE, 6,
        EGL_BLUE_SIZE, 5,
        EGL_ALPHA_SIZE, 8,
        EGL_NONE
    };
...it now works fine.

Thanks for the help anyway. I'll leave this thread here in case anyone else is stupid enough to do the same as me :D

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

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 3:16 pm

glad you found a workaround. Still looks like a bug to me.

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 4:42 pm

Yeah, I think it probably is. I would expect the GPU to ignore the alpha values given if the configuration doesn't include alpha (which it shouldn't with no alpha size). Moreover, with that kind of configuration it should only ever be possible to have fully opaque primitives.

User avatar
cheery
Posts: 219
Joined: Wed Jan 25, 2012 9:39 pm

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 5:15 pm

Why are there attributes and configs and config negotiation required at all? I've not really understood. Are our videocards still unable to give us about any kind of surface we want?

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

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 11:13 pm

The reason I think it is a bug is twofold
1) The config for GPU is garbage 5,6,5,8 is an unsupported output format. The tilebuffer can write 5,6,5 (16bit) or 8,8,8,? (32bit). I've left the ? as it takes 8bits regardless of whether you have alpha or not.
2) The triangle should not have changed colour using a varying instead of a uniform.

if you issue.

eglGetConfigAttrib(s_eglDisplay, eglConfig, EGL_RED_SIZE, &red_size);
eglGetConfigAttrib(s_eglDisplay, eglConfig, EGL_GREEN_SIZE, &green_size);
eglGetConfigAttrib(s_eglDisplay, eglConfig, EGL_BLUE_SIZE, &blue_size);
eglGetConfigAttrib(s_eglDisplay, eglConfig, EGL_ALPHA_SIZE, &alpha_size);
eglGetConfigAttrib(s_eglDisplay, eglConfig, EGL_DEPTH_SIZE, &depth_size);
eglGetConfigAttrib(s_eglDisplay, eglConfig, EGL_STENCIL_SIZE, &stencil_size);

after you have selected the config (5,6,5,8), what does it return you for the various values?

My pi is not hooked up to a display at the moment..... I guess I could use readpixels :-(

Jim

User avatar
patrikg
Posts: 168
Joined: Sun Mar 18, 2012 10:19 pm

Re: GLSL weirdness / possible bug?

Wed May 23, 2012 11:40 pm

I don't know... but framebuffer.
Could you use fbcat to take screenshots ??
For more easy way to describe the problem.

robthebloke
Posts: 8
Joined: Fri Mar 09, 2012 1:30 pm

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 6:20 am

Moreover, with that kind of configuration it should only ever be possible to have fully opaque primitives.
Transparency is usually done with the SRC_ALPHA, ONE_MINUS_SRC_ALPHA, where SRC is the primative colour. The framebuffer lacking alpha is only a problem if you use DST_ALPHA/DST_COLOR in your blend params. Framebuffer config is a red herring imho.

As for the problem at hand, you have set the colour varying using a glVertexAttrib method? (not trying to set it as a uniform for example?).

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 8:56 am

dattrax wrote:1) The config for GPU is garbage 5,6,5,8 is an unsupported output format.
Yeah, I saw what I'd done after I posted my reply. I actually changed it to 4, 4, 4, 4 though so it's 16 bit with alpha.
dattrax wrote:if you issue.
...
after you have selected the config (5,6,5,8), what does it return you for the various values?
I tested it with three different configs and have posted the results below:

With my original 5, 6, 5 RGB config:

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 0
Stencil: 0

With my borked 5, 6, 5, 8 RGBA config:

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 0
Stencil: 0

With my new 4, 4, 4, 4, RGBA config:

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 0
Stencil: 0

It does seem funny that it's always using 8 bits per channel even when I'm requesting otherwise. But I did assume that eglChooseConfig only used the attributes you supply as a hint and it would acquire the closest supporting config.

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 9:26 am

I've just run eglGetConfigs to return a list of all the supported configs and this is the output:

Code: Select all

Num configs: 28

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 24
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 24
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 24
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 24
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 0
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 0
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 0
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 0
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 24
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 24
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 24
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 24
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 0
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 0
Stencil: 8

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 0
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 0
Stencil: 0

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 24
Stencil: 8

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 24
Stencil: 0

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 0
Stencil: 8

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 0
Stencil: 0

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 24
Stencil: 8

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 24
Stencil: 0

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 0
Stencil: 8

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 0
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 8
Depth: 0
Stencil: 0

Red: 8
Green: 8
Blue: 8
Alpha: 0
Depth: 0
Stencil: 0

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 0
Stencil: 0

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 16
Stencil: 0
So firstly it doesn't look like I should be using 4, 4, 4, 4 but, more importantly, I'm confused as to why when I specify I want just RGB 5, 6, 5 it isn't picking the config that's:

Red: 5
Green: 6
Blue: 5
Alpha: 0
Depth: 0
Stencil: 0

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5372
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 10:36 am

I don't believe eglGetConfigs makes any promises about the order of the returned configs.
You just get all the configs that satisfy your request (i.e. attributes are >= request).
I believe you have to then search the list for the "best" match.

finnw
Posts: 24
Joined: Wed May 16, 2012 7:05 pm

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 1:17 pm

dom wrote:I don't believe eglGetConfigs makes any promises about the order of the returned configs.
You just get all the configs that satisfy your request (i.e. attributes are >= request).
I believe you have to then search the list for the "best" match.
I think this may be a bug, as the Khronos docs (e.g. http://www.khronos.org/registry/egl/sdk ... onfig.html, http://www.khronos.org/files/egl-1-4-qu ... e-card.pdf) claim the configs should be sorted, and that smaller buffer sizes are preferred.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5372
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 2:46 pm

From 3D guy:
"We do sort the configs according to the spec, it's just that the spec is a bit retarded: (for EGL_RED/GREEN/BLUE/ALPHA_SIZE) "If this value is zero, color buffers with the smallest red/green/blue/alpha component size are preferred. Otherwise, color buffers with the largest red/green/blue/alpha component of at least the specified size are preferred. The default value is zero."

So if you specify 5/6/5 we're supposed to prefer 8/8/8.

I got so annoyed with this that I implemented eglSaneChooseConfigBRCM, which is basically the same as eglChooseConfig, but it always sorts things smallest first, so you get 5/6/5 if you ask for it."

finnw
Posts: 24
Joined: Wed May 16, 2012 7:05 pm

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 5:04 pm

Another workaround might be to specify:

Code: Select all

{
      EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
      EGL_BUFFER_SIZE, 15,
      EGL_NONE
}
That lets you portably specify a minimum depth overall but without specifying depths for any components (R,G,B,A) which would mess up the default sort order.

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 10:45 pm

I learned a lonnng time ago that ASSUME makes an A ... well, you probably know that old saw.

Although it doesn't apply in this case, there are a lot of things in GL/OGL/OGLES where it appears you can leave some things out, but, there doesn't seem to be a logical rhyme or reason in the individual cases when that's true. There are some cases where transparency/alpha-channel is optional but, IIRC, at lower levels, it's always required. There are some situations where some kinds of values are automagically set to a particular value (1 and 1.0 are popular do-nothing or default values) as if a uniform had been set without having to actually set it, and other situations where you have to supply values, set a uniform, etc., or weirdness ensues. I've just gotten into the habit of being explicit as that's how life was back in the early days of Original Flavor GL.

It appears that the higher-level, newer APIs tend to be more forgiving, especially in C++ implementations, but, the lower-level, older APIs cut you absolutely no slack, even if they compile without any errors. There can be differences between language implementations, too, even between C and C++, and I don't understand how they both can be spec-compliant.

If I didn't know any better, I would say that some spec authors were being inconsistent just so people would have to buy their inevitable GL bibles and how-to books, but, if I really believed that, I'd be called paranoid (just because we're paranoid doesn't mean they aren't out to get us! ;) ). As I suspect is true for Dom, I sometimes dream of meeting certain spec authors in a dark alley late at night ... insert standard lawyer-required disclaimer that no spec authors were actually harmed in the creation of this comment ... :evil:
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

robthebloke
Posts: 8
Joined: Fri Mar 09, 2012 1:30 pm

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 10:51 pm

Guys!

Why are you blaming the DST params (the framebuffer) for defects visible in the SRC params (the vertex attributes)?

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: GLSL weirdness / possible bug?

Thu May 24, 2012 11:05 pm

BTW, I've found it useful to verify sanity by trying out the same APIs in as different implementations as possible, e.g., OGLES on the Pi and in WebGL via a Chrome browser, or C/C++, on Windoze and Linux laptops/desktops. In fact, since it's pretty much functionally one-for-one identical to OGLES, doing bits and pieces in WebGL for trying APIs out quickly and other forms of rapid prototyping can be pretty productive if you're more interested in figuring out how an API actually works rather than having to mess around with the associated C/C++ code. Of course, when you're using WebGL on a Windoze or Linux laptop or desktop, the appropriate API, data structure, etc., parts you get figured out need to be copied and pasted into Pi code via VNC, ssh, sftp-transferred files, etc.
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Return to “C/C++”