Hi,
I am trying to create a sample application where i am trying to use a EGLImage as texture. The EGLImage is created from a native pixmap using eglCreateImageKHR.
Most of the open source sample codes available over net using eglCreateImageKHR has the last parameter(image attribute list) set to
NULL/EGL_IMAGE_PRESERVED_KHR is set to EGL_FALSE.
My query is what is the use of EGL_IMAGE_PRESERVED_KHR attribute and what is the difference b/w setting this attribute to EGL_FALSE and EGL_TRUE
and in which scenarios should i set this attribute to EGL_TRUE.
Thanks and Regards,
Prabal Kumar Ghosh
Thank you very much for the reply.
In my application the EGLImage is updated for each frame ; so if we set EGL_IMAGE_PRESERVED_KHR attribute
to EGL_TRUE ,then can we reuse the pixel data values of the previous frame in the current frame?
My queries is, in which scenarios should i set EGL_IMAGE_PRESERVED_KHR to true.
Hi pk.ghosh,
The specification states the following:
If it is set to true, then all pixel data values associated with <buffer> are preserved.
<buffer> is the name (or handle) of a resource to be used as the EGLImage source, cast into the type EGLClientBuffer.
What this means is, your input source buffer to create the EGLImage from, by default, will be undefined after the eglCreateImageKHR call.
If you want the original source buffer to be preserved, i.e. its data not undefined... then set it to EGL_TRUE.
I hope that helped.
Michael McGeagh
Hi Michael,
Thanks a lot for your reply.
The things are pretty much clear now.
I have few more queries.
According to your last reply, the pixel data of the source buffer is preserved.
Does this mean that if we create 2 EGLImages from the same source with EGL_IMAGE_PRESERVED_KHR set to EGL_TRUE,
then we will successfully be able create 2 EGLImages.
However if we set EGL_IMAGE_PRESERVED_KHR to EGL_FALSE, then the first EGLImage will be created successfully
but the creation of second EGLImage will be failing.
Code snippet :
const EGLint imageAttributes[] =
{
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
EGL_NONE
};
......
/* Create an 1st EGL image from the texture */
image1 = EGL_CHECK(eglCreateImageKHR(sEGLDisplay, sEGLContext, EGL_GL_TEXTURE_2D_KHR,
(EGLClientBuffer)sourceTexId, imageAttributes));
GL_CHECK(glGenTextures(1, &targetTexId1));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, targetTexId1));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
GL_CHECK(glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image1));
/* Create an 2nd EGL image from the texture */
-------> image2 = EGL_CHECK(eglCreateImageKHR(sEGLDisplay, sEGLContext, EGL_GL_TEXTURE_2D_KHR,
GL_CHECK(glGenTextures(1, &targetTexId2));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, targetTexId2));
GL_CHECK(glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image2));
The above code snippet fails at line marked by"------->" with EGL_BAD_ACCESS even when i have set EGL_IMAGE_PRESERVED_KHR to EGL_TRUE .
Please suggest.
According to the specification:
* If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> has an off-screen buffer bound to it (e.g., by a previous call to eglBindTexImage), the error EGL_BAD_ACCESS is generated. * If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> is bound to an off-screen buffer (e.g., by a previous call to eglCreatePbufferFromClientBuffer), the error EGL_BAD_ACCESS is generated. * If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> is itself an EGLImage sibling, the error EGL_BAD_ACCESS is generated. * If the value specified in <attrib_list> for EGL_IMAGE_PRESERVED_KHR is EGL_TRUE, and an EGLImageKHR handle cannot be created from the specified resource such that the pixel data values in <buffer> are preserved, the error EGL_BAD_ACCESS is generated.
* If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> has an off-screen buffer bound to it (e.g., by a previous call to eglBindTexImage), the error EGL_BAD_ACCESS is generated.
* If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> is bound to an off-screen buffer (e.g., by a previous call to eglCreatePbufferFromClientBuffer), the error EGL_BAD_ACCESS is generated.
* If the resource specified by <dpy>, <ctx>, <target>, <buffer> and <attrib_list> is itself an EGLImage sibling, the error EGL_BAD_ACCESS is generated.
* If the value specified in <attrib_list> for EGL_IMAGE_PRESERVED_KHR is EGL_TRUE, and an EGLImageKHR handle cannot be created from the specified resource such that the pixel data values in <buffer> are preserved, the error EGL_BAD_ACCESS is generated.
Are the possible reasons for you to obtain that error.
The first 2 are unlikely to be the reason, however point 3 looks possible, as does point 4.
The definition of an EGLImage sibling is:
The set of all EGLImage targets (in all client API contexts) which are created from the same EGLImage object, and the EGLImage source resouce which was used to create that EGLImage.
It is also worth pointing out that the previous command:
void EGLImageTargetTexture2DOES(enum target, eglImageOES image); Any existing image arrays associated with any mipmap levels in the texture object are freed (as if TexImage was called for each, with an image of zero size). As a result of this referencing operation, all of the pixel data in the <buffer> used as the EGLImage source resource (i.e., the <buffer> parameter passed to the CreateImageOES command that returned <image>) will become undefined.
void EGLImageTargetTexture2DOES(enum target, eglImageOES image);
Any existing image arrays associated with any mipmap levels in the texture object are freed (as if TexImage was called for each, with an image of zero size). As a result of this referencing operation, all of the pixel data in the <buffer> used as the EGLImage source resource (i.e., the <buffer> parameter passed to the CreateImageOES command that returned <image>) will become undefined.
Which could be an issue.
I hope that helps. Please refer to the Khronos specification for more details.
Kind Regards,