EGLImage on Android NDK


#1

Hi all.

I’m trying to use EGLImage on Android NDK.
I wrote a simple test code. but it doesn’t work.
Somebody teach me what’s wrong with my code???

They have EGL_KHR_gl_texture_2D_image and GL_OES_EGL_image extention.

Result on GalaxyS(SGX)
D/libEGL ( 8580): loaded /system/lib/egl/libEGL_POWERVR_SGX540_120.so
D/libEGL ( 8580): loaded /system/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
D/libEGL ( 8580): loaded /system/lib/egl/libGLESv2_POWERVR_SGX540_120.so
D/EGLT( 8580): EGLImageTest: glGenTextures: Good 100271!!
D/EGLT( 8580): EGLImageTest: eglCreateImageKHR: Good!!
D/EGLT( 8580): EGLImageTest: EGLImageTargetRenderbufferStorageOES: Bad!! 0502
D/EGLT( 8580): EGLImageTest: EGLImageTargetTexture2DOES: Good!!

Result on LT-NA75W(Tegra2)
D/libEGL (11388): loaded /system/lib/egl/libGLES_android.so
D/libEGL (11388): loaded /system/lib/egl/libEGL_tegra.so
D/libEGL (11388): loaded /system/lib/egl/libGLESv1_CM_tegra.so
D/libEGL (10590): loaded /system/lib/egl/libGLESv2_tegra.so
D/EGLT(10590): EGLImageTest: glGenTextures: Good 1!!
D/EGLT(10590): EGLImageTest: eglCreateImageKHR: Bad!!
D/EGLT(10590): EGLImageTest eglCreateImageKHR: EGL_BAD_PARAMETER
D/EGLT(10590): EGLImageTest: EGLImageTargetRenderbufferStorageOES: Bad!! 0501
D/EGLT(10590): EGLImageTest: EGLImageTargetTexture2DOES: Bad!! 0502


	{
		EGLImageKHR eimg;
		GLuint texid,fbo;
		GLint error;
		EGLint attr[] = { EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_NONE};
		
		glGenTextures(1,&texid);
		if( texid != 0 )
		{
			printf("EGLImageTest: glGenTextures: Good %d!!",texid); 
		}else{
			printf("EGLImageTest: glGenTextures: Bad %d!!",texid); 
		}
		
		glBindTexture(GL_TEXTURE_2D,texid);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 256,256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );
		glBindTexture(GL_TEXTURE_2D,0);
		glFinish();
		eimg = eglCreateImageKHR(g_eglDisplay, g_eglMainContext, EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)texid, attr);
		if( eimg != NULL )
		{
			printf("EGLImageTest: eglCreateImageKHR: Good!!"); 
		}else{
			printf("EGLImageTest: eglCreateImageKHR: Bad!!");
			EGLint egl_error = eglGetError();
			switch(egl_error)
			{
			case EGL_NOT_INITIALIZED:
				printf("EGLImageTest eglCreateImageKHR: EGL_NOT_INITIALIZED
");
				break;
			case EGL_BAD_ACCESS:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_ACCESS");
				break;
			case EGL_BAD_ALLOC:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_ALLOC
");
				break;
			case EGL_BAD_CONFIG:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_CONFIG
");
				break;
			case EGL_BAD_CONTEXT:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_CONTEXT
");
				break;
			case EGL_BAD_CURRENT_SURFACE:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_CURRENT_SURFACE
");
				break;
			case EGL_BAD_DISPLAY:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_DISPLAY
");
				break;
			case EGL_BAD_MATCH:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_MATCH ");
				break;
			case EGL_BAD_NATIVE_PIXMAP:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_NATIVE_PIXMAP
");
				break;
			case EGL_BAD_NATIVE_WINDOW:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_NATIVE_WINDOW
");
				break;
			case EGL_BAD_PARAMETER:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_PARAMETER
");
				break;
			case EGL_BAD_SURFACE:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_SURFACE
");
				break;
			case EGL_CONTEXT_LOST:
				printf("EGLImageTest eglCreateImageKHR: EGL_CONTEXT_LOST
");
				break;
			default :
				printf("EGLImageTest eglCreateImageKHR: Unknown %04X
",egl_error);
				break;
			}
		}
		
		error = glGetError();
		
		// Target for FBO
		glGenFramebuffersOES(1,&fbo);
		glBindFramebufferOES(GL_FRAMEBUFFER_OES,fbo);
		glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER_OES, eimg);
		error = glGetError();
		if( error != GL_NO_ERROR )
		{
			printf("EGLImageTest: EGLImageTargetRenderbufferStorageOES: Bad!! %04X",error);
		}else{
			printf("EGLImageTest: EGLImageTargetRenderbufferStorageOES: Good!!");
		}
		glBindFramebufferOES(GL_FRAMEBUFFER_OES,0);
		
		// Target for Texture
		glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,eimg);
		error = glGetError();
		if( error != GL_NO_ERROR )
		{
			printf("EGLImageTest: EGLImageTargetTexture2DOES: Bad!! %04X",error);
		}else{
			printf("EGLImageTest: EGLImageTargetTexture2DOES: Good!!");
		}
		
	}


#2

Go to: http://www.khronos.org/registry/egl/ext … e_base.txt and look at Table bbb. You’re using an unsupported attrib.


#3

I have used the EGL Image extensions a lot and I should warn you that this area is like walking through a mine field because these extensions are implemented differently on every embedded system, including Android and you need a lot more information than just the Khronos documents to use them. It’s dangerous to tread where no man has walked before!

I can offer this advice:

  1. Use OpenGL ES 2.0, instead of 1.1. FBOs are more likely to work with 2.0, especially on Android.

  2. EGLImageTargetRenderbufferStorageOES() is obsolete and maybe unimplemented.

  3. The EGL image extensions are not as necessary on Android now that the new TextureView class has been added with Android 4.0. Use TextureView to transfer texture images between OpenGL ES and the Canvas API.

  4. Using OpenGL ES with the Android NDK is not for beginners. Here are some articles that will help:

http://software.intel.com/en-us/articles/using-opengl-es-to-accelerate-apps-with-legacy-2d-guis
http://software.intel.com/en-us/articles/porting-opengl-games-to-android-on-intel-atom-processors-part-1

Regards, Clay