Hello,
I want to compose a larger GL_ALPHA only texture from many other smaller GL_ALPHA only textures at run time.
I tried to do this through a PBuffer but have hit a stumbling block. I can’t share a texture with a context with an alpha only surface with a context with an rgb565 surface.
The following code breaks with an EGL_BAD_MATCH error at eglCreateContext if I set the share context. However, it works fine if I don’t try to share the contexts. But then the original context can’t access the newly created texture because it resides in a different context.
int width = 256;
int height = 256;
EGLDisplay current_display = eglGetCurrentDisplay();
if(current_display == EGL_NO_DISPLAY)
{
printf("NO DISPLAY
");
return;
}
EGLContext current_context = eglGetCurrentContext();
if (current_context == EGL_NO_CONTEXT)
{
printf("NO CONTEXT
");
return;
}
EGLSurface current_surface = eglGetCurrentSurface(EGL_DRAW);
if (current_surface == EGL_NO_SURFACE)
{
printf("NO SURFACE
");
return;
}
EGLint num_config;
EGLint conflist[] = {
EGL_ALPHA_SIZE, 8,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE
};
EGLConfig config;
if (!eglChooseConfig(current_display, conflist, &config, 1, &num_config) || num_config != 1) {
printf("Failed to find get configuration %x
", eglGetError());
return;
}
EGLint pbuf_attribs[] = {
EGL_WIDTH, width,
EGL_HEIGHT, height,
EGL_NONE
};
EGLSurface surface = eglCreatePbufferSurface( current_display, config, pbuf_attribs );
if( surface == EGL_NO_SURFACE ) {
printf("Failed to create sureface %x
", eglGetError());
}
EGLContext context = eglCreateContext( current_display, config, current_context, NULL );
if( context == EGL_NO_CONTEXT ) {
printf("Context creation error: %x
", eglGetError());
return;
}
if (!eglMakeCurrent(current_display, surface, surface, context))
{
printf("Unable to make the pbuffer context current: %x
", eglGetError());
return;
}
// DO SOME RENDERING HERE
GLuint texture;
glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 0, 0, width, height, 0);
if (!eglMakeCurrent(current_display, current_surface, current_surface, current_context))
{
printf("Unable to make the main context current");
return;
}
eglDestroyContext(current_display, context);
eglDestroySurface(current_display, surface);
Does anybody know any way I can share the textures between contexts or maybe suggest another way to do this. My platform specs are as follows:
EGL Vendor: Imagination Technologies
EGL Version: 1.2 build 1
GLES Vendor: Imagination Technologies
GLES Renderer: PowerVR MBXLite with VGPLite
GLES Version: OpenGL ES-CM 1.1
Thank you,
Ian