Hello,
I am trying to read pixel from created EGLImageKHR
object but can not read as glReadPixels
returns.I tested the validity of created egl image by importing it to another render buffer by using glEGLImageTargetRenderbufferStorageOES
function and used glReadPixels
. What I need to do is to read pixel of EGLImageKHR
object without importing it with glEGLImageTargetRenderbufferStorageOES
function since I will send the EGLImageKHR
from one device to another.
Following is the code snippet that I tried which is not working:
glBindFramebuffer(GL_READ_FRAMEBUFFER,mwindow->openglContext()->defaultFramebufferObject());
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,frameBuffer);
glBlitFramebuffer(0, 0, mWinWidth, mWinHeight, 0, 0, mWinWidth, mWinHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
mImage = CreateImageKHR(eglGetCurrentDisplay(),eglGetCurrentContext(), EGL_GL_RENDERBUFFER_KHR,
reinterpret_cast<EGLClientBuffer>(renderBuffer), nullptr);
if (mImage == EGL_NO_IMAGE_KHR)
{
qDebug("failed to make image from target buffer: %s", get_egl_error());
return -1;
}
int bufSize = mWinHeight * mWinWidth*3;
unsigned char * trialBuff = new unsigned char[bufSize];
memcpy(trialBuff,mImage,bufSize);
FILE *out = fopen("dada.txt", "w");
fwrite(trialBuff, bufSize, 1, out);
fflush(out);
fsync(fileno(out));
fclose(out);
delete [] trialBuff;
When I checked the file that I saved the pixels , it has a lot of noise and wrong colors.
Could you please check the issue and help me ?
Regards