eglCreatePBufferSurface

Hi , when i try creating a pBuffer Surface i get an error EGL_BAD_CONTEXT.And the PBuffer is NULL always…below is the code :

int h = 400, w =200;
EGLint attr[]={
EGL_WIDTH, w,
EGL_HEIGHT,h,
EGL_TEXTURE_FORMAT,EGL_TEXTURE_RGB,
EGL_TEXTURE_TARGET<EGL_TEXTURE_2D,
EGL_NONE
};
EGLSurface pBuffer = eglCreatePbufferSurface(eglDisplay,eglConfig,attr);

Plesae tell what could be the possible raeson.Both egldisplay and eglConfig have proper values.

Could you please keep related problems in one thread instead of starting new threads?

The ‘<’ should be a comma, otherwise you’ll get all kinds of undefined behaviour because the attribute list is not properly terminated. In case that’s just a copy&paste error, did you make sure the error is raised by eglCreatePbufferSurface and not some previous EGL call?

Hi,

Sorry < was a typo for ,comma.
Do we need to call eglChooseConfig () beforeeglCreatepBufferSurface() ?

When i did eglChooseConfig() with the attrib list listed in previous post , i got it as NULL.

While when i used the attrib list as below, i was able to get config.

static const int attrib_list[]={

EGL_RED_SIZE, 5,
EGL_GREEN_SIZE,6,
EGL_BLUE_SIZE,5,
EGL_ALPHA_SIZE,0,
EGL_SURFACE_TYPE,EGL_WINDOW_BIT,
EGL_NONE
};

But when i used this config in eglCreatepBufferSurface, it again gave me the same error(EGL_BAD_MATCH);

I have read that we get this error when we dont use proper color space values. Should i try with different attrib_list values or is there some other problem ?

By the way what all attributes should the attrib_list have ideally ?

Of course you need to select a valid configuration first. And the attribute list for the config needs to contain EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, otherwise you may get a config that doesn’t support pbuffers.

Additionally, the width and height attributes passed to eglCreatePbufferSurface must be powers of two, just like for any other texture.

For all possible attributes, see the EGL specification:
http://www.khronos.org/registry/egl/

If I were doing a normal texture upload, my initialisation was (this is on a windows sample. there is no opengl related code prior to this):

eglDisplay = eglGetDisplay(hDC);
eglInitialize(eglDisplay, NULL, NULL); //major -1 minor -1
eglGetConfigs(eglDisplay, NULL, 0, &iConfigs);

i = 0;
pConfigAttributes[i++] = EGL_RED_SIZE;
pConfigAttributes[i++] = 5;
pConfigAttributes[i++] = EGL_GREEN_SIZE;
pConfigAttributes[i++] = 6;
pConfigAttributes[i++] = EGL_BLUE_SIZE;
pConfigAttributes[i++] = 5;
pConfigAttributes[i++] = EGL_ALPHA_SIZE;
pConfigAttributes[i++] = 0;
pConfigAttributes[i++] = EGL_SURFACE_TYPE;
pConfigAttributes[i++] = EGL_WINDOW_BIT;
pConfigAttributes[i++] = EGL_NONE;

eglChooseConfig(eglDisplay, pConfigAttributes, &eglConfig, 1, &iConfigs);

eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, eglWindow, NULL);

eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);

eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);

Now for pBuffers I make the following change:

....
pConfigAttributes[i++] = EGL_WINDOW_BIT|EGL_PBUFFER_BIT;
....
int err = eglGetError(); //RETURNS SUCESS
EGLSurface pBuffer = eglCreatePBuffer(eglDisplay, eglConfig, pConfigAttributes);
err = eglGetError(); //RETURNS EGL_BAD_MATCH

if I add:

pConfigAttributes[i++] = EGL_TEXTURE_FORMAT;
pConfigAttributes[i++] = EGL_TEXTURE_RGB;
pConfigAttributes[i++] = EGL_TEXTURE_TARGET;
pConfigAttributes[i++] = EGL_TEXTURE_2D;

before EGL_NONE, eglChooseConfig fails.

What modifications do I make to the initialization to get eglCreatePBuffer working? Whats wrong in my config attributes?

Thanks for your help.

You’re passing the wrong attributes to eglCreatePbufferSurface. You need two different attribute lists, one for the config and one for the pbuffer.

eglCreatePbufferSurface accepts the following attributes: EGL WIDTH, EGL HEIGHT, EGL LARGEST PBUFFER,
EGL TEXTURE FORMAT, EGL TEXTURE TARGET, EGL MIPMAP TEXTURE,
EGL COLORSPACE, and EGL ALPHA FORMAT.
They’re all explained in the spec.

Hmm… whatever I try I seem to be getting an EGL_BAD_MATCH…

Here’s the updated code:

eglDisplay(..);
eglIinitialize(...);
eglGetConfigs(..);
eglChooseConfig(...,&eglConfig,..);
eglSurface = eglCreatewindowSurface(...);
eglContext = eglCreateContext(..,eglConfig,..);
eglMakecurrent(....); 

static const int pBufferAttribs[] = {
.....
};
pbuffer = eglCreatePbufferSurface(eglDisplay, eglConfig, pBufferAttribs);
int err = eglGetError(); //every time returns 3009 - EGL_BAD_MATCH

Here are the different combinations of pBufferAttribs I used:
(1)

{
EGL_WIDTH, 2, 
EGL_HEIGHT, 2, 
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, 
EGL_LARGEST_BUFFER, EGL_FALSE, 
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, 
EGL_MIPMAP_TEXTURE, EGL_FALSE, 
EGL_NONE
}

(2)

{
EGL_WIDTH, 2, 
EGL_HEIGHT, 2, 
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, 
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, 
EGL_MIPMAP_TEXTURE, EGL_FALSE, 
EGL_NONE
}

(3)

{
EGL_WIDTH, 2, 
EGL_HEIGHT, 2, 
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 
EGL_NONE
}

(4)

{
EGL_WIDTH, 2, 
EGL_HEIGHT, 2, 
EGL_NONE
}

(5)

{
EGL_NONE
}

(6)

NULL

Every time, the same error right after eglCreatePbufferSurface.

I normally use a 16 bit 5_6_5 RGB texture, w-1024 h-512.
Am I missing something?

EGL_SURFACE_TYPE is not a pbuffer attribute.

Try to find a config with the following attributes

EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE

Then try to create a pbuffer with these attributes:

EGL_WIDTH, 128,
EGL_HEIGHT, 128,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_NONE

even though i try any attrib , i get the same error.

code :

eglDisplay = eglGetDisplay(hDc);
eglInitialize(egldisplay,NULL,NULL); // eglDisplay = 1577130056

EGLint configAttrib[] = {
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE , 6,
EGL_BLUE_SIZE, 5,
EGL_BIND_TO_TEXTURE_RGB, EGL_PBUFFER_BIT,
EGL_NONE
};

eglChooseConfig(eglDisplay,configAttrib,&eglConfig,1,&iConfigs);
// eglConfig = 0
eglSurface = eglCreateWindowSurface(eglDisplay,eglConfig,eglWindow,NULL); //eglSurface = 009929878

eglContext = eglCreateContext(eglDisplay,eglConfig,NULL,NULL);
eglMakeCurrent(eglDisplay,eglSurface,eglcontext);

static const int pBuffer_attrib[]={
EGL_WIDTH, 128,
EGL_HEIGHT, 128,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_NONE
};

EGLSurface pBuffer = eglcreatePBuffer(eglDisplay,eglconfig,pBuffer_attrib); //pBuffer = NULL
int err = eglGetError(); // err = 3009

Tell me If I m still missing something .

That’s not what I wrote. Did you even check whether eglChooseConfig raised an error?

Sorry for that typo. Problem is I’m not able to copy paste due to some restrictions, so I got to type in the entire code every time.
Anyways, wont let it happen again. Forgive me :).

I used the values you specified word for word.

attributes for the eglChooseConfig were:

EGL_RED_SIZE, 5, 
EGL_GREEN_SIZE, 6, 
EGL_BLUE_SIZE, 5, 
EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE, 
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 
EGL_NONE

and for eglCreatePbufferSurface were:

EGL_WIDTH, 128, 
EGL_HEIGHT, 128, 
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, 
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, 
EGL_NONE

Anything else wrong?

Also,

  1. Could you shed some light on EGL_WINDOW_BIT and EGL_PBUFFER_BIT. When should they be used? I am still creating a window surface right… dont I need the window_bit for that?
    Sorry for so many questions as I am a newbie. Am not very clear how sufaces, contexts, pbuffers and textures all work together.

  2. I seem to be getting the same error “EGL_BAD_MATCH” for everything I do. Can I do something to try and get a different error atleast. Just want to make sure its not a problem with the egl implementation. I think I may be using the beta version of the egl drivers.

Seems correct. Did you check none of the EGL functions before eglCreatePbufferSurface raise an error?

  1. Could you shed some light on EGL_WINDOW_BIT and EGL_PBUFFER_BIT. When should they be used? I am still creating a window surface right… dont I need the window_bit for that?
    Sorry for so many questions as I am a newbie. Am not very clear how sufaces, contexts, pbuffers and textures all work together.

An EGL config is more or less a surface format descriptor. But since formats may be limited to certain uses, they also carry information about where they can be used. A config that has EGL_WINDOW_BIT set can be used for window surfaces, while one that has EGL_PBUFFER_BIT set is valid for pbuffers. Of course a config can also support both.

The attribute list you pass to eglChooseConfig describes your minimum requirements. But the config returned can exceed those requirements, depending on the device. For example, you could request a config that can be used for pbuffers, and eglChooseConfig returns a config that can be used for both pbuffers AND window surfaces.

  1. I seem to be getting the same error “EGL_BAD_MATCH” for everything I do. Can I do something to try and get a different error atleast. Just want to make sure its not a problem with the egl implementation. I think I may be using the beta version of the egl drivers.

First you need to make sure you can find a config that can actually be used for a pbuffer.

Did you check none of the EGL functions before eglCreatePbufferSurface raise an error?
yes

A config that has EGL_WINDOW_BIT set can be used for window surfaces, while one that has EGL_PBUFFER_BIT set is valid for pbuffers. Of course a config can also support both.

Can I specify in my arguements to eglChooseConfig that I want both: pbuffer bit and window bit? How do I know if both are set?

First you need to make sure you can find a config that can actually be used for a pbuffer.

You mean this?
EGL_WIDTH, 128,
EGL_HEIGHT, 128,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_NONE

Yes, you can specify both. Just combine them with the bitwise-or operator: EGL_WINDOW_BIT | EGL_PBUFFER_BIT.

eglChooseConfig only returns configs that match or exceed the requirements that you pass in using the attribute list. So if you pass in the requirement
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
and eglChooseConfig actually returns a config (check that iConfigs > 0 after the call!), then that config must be usable for both window and pbuffer surfaces.

[quote:2t7ic5ak]First you need to make sure you can find a config that can actually be used for a pbuffer.

You mean this?[/quote:2t7ic5ak]
No, see above. Use eglChooseConfig to request a config with the single requirement
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
and check whether eglChooseConfig actually returns a config. If not, then your device/driver doesn’t support pbuffers.

Hi xmas ,
I m working on the same code as Akhil.
I tried to check whether pBuffer is supported ot not; by using the following atributes :

EGLint Attrib[]={
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE
};

EGLBoolean res =eglchooseConfig(eglDisplay,Attrib,&eglconfig,1,&iConfig);

The eglConfig value after this is 0 , res is EGL_TRUE, iConfig is 1.
can you please specify what does this actually mean ?

This means that the EGLconfig denoted by the number 0 can be used to create pbuffer surfaces. Now add the other requirements and see if you can still get a config.

Hi ,
When i try using the following Config attributes , it gives EGL_FALSE :
EGLint attrib[]={
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_2D,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE
};

While if i remove EGL_TEXTURE_FORMAT, EGL_TEXTURE_2D from it , it again starts giving EGL_TRUE and 3 as the Config while iConfig is still 1.
When i use this Config for creating the pBuffer its NULL (as always ).Please throw some light !

Again, EGL_TEXTURE_FORMAT is not a valid config attribute. It’s a pbuffer attribute. Besides, EGL_TEXTURE_2D is not a valid value for EGL_TEXTURE_FORMAT. Read the EGL spec, all valid attribute/value combinations are explained there.

Try
EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE,
or
EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,
depending on whether you want an RGB texture or an RGBA texture.

I tried using EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE , but it failed.It failed both for RGB and RGBA.However without this attribute it works ?

Hi,
when i use config attrib list such that config returned is success aftereglChooseConfig ; and then try finding out the RGBA values from eglGetConfigAttrib() , its 8888 for RGBA.