OpenGL ES 2.0 on SGX540 OpenGL Offscreen PIXMAP Support

285 views Asked by At

On the DM370 ( TI OMAP 3 ) with the Imagination Technologies PowerVR SGX 530 I was able to use the following code to initialize my EglSurface using CMEM and PIXMAP offscreen surfaces:

// Index to bind the attributes to vertex shaders
#define VERTEX_ARRAY 0
#define TEXCOORD_ARRAY 1

// Bit types
#define SGXPERF_RGB565 0
#define SGXPERF_ARGB8888 2

// SurfaceTypes
#define SGXPERF_SURFACE_TYPE_WINDOW 0
#define SGXPERF_SURFACE_TYPE_PIXMAP_16 1
#define SGXPERF_SURFACE_TYPE_PIXMAP_32 2

typedef struct _NATIVE_PIXMAP_STRUCT
{
    long pixelFormat;
    long rotation;
    long width;
    long height;
    long stride;
    long sizeInBytes;
    long pvAddress;
    long lAddress;
} NATIVE_PIXMAP_STRUCT;


// Init EGL with offscreen PIXMAP support
void* GLWidget::commonEglInit(int surfaceType, NATIVE_PIXMAP_STRUCT** pNativePixmapPtr) {

    int windowWidthTi, windowHeightTi;

    EGLint iMajorVersion, iMinorVersion;
    EGLint ai32ContextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
    eglDisplay = eglGetDisplay((int)0);

    if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion))
        return NULL;

    if ( !eglBindAPI(EGL_OPENGL_ES_API) ) {
        return NULL;
    }

    EGLint pi32ConfigAttribs[5];
    pi32ConfigAttribs[0] = EGL_SURFACE_TYPE;
    pi32ConfigAttribs[1] = EGL_WINDOW_BIT | EGL_PIXMAP_BIT;
    pi32ConfigAttribs[2] = EGL_RENDERABLE_TYPE;
    pi32ConfigAttribs[3] = EGL_OPENGL_ES2_BIT;
    pi32ConfigAttribs[4] = EGL_NONE;

    int iConfigs;
    if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1))
    {
        fprintf(stderr,"Error: eglChooseConfig() failed.\n");
        return NULL;
    }

    commonCreateNativePixmap(SGXPERF_ARGB8888,WIDTH, HEIGHT, pNativePixmapPtr);
    eglSurface = eglCreatePixmapSurface(eglDisplay, eglConfig, *pNativePixmapPtr, NULL);

    if (!fprintf(stderr,"eglCreateSurface\n"))
        return NULL;

    eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32ContextAttribs);
    if (!fprintf(stderr,"eglCreateContext\n"))
        return NULL;

    eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
    if (!fprintf(stderr,"eglMakeCurrent\n"))
        return NULL;

    EGLBoolean success = eglSwapInterval(eglDisplay, 1);
    if ( !success ) {
        fprintf(stderr,"eglSwapInterval\n");
        sleep(3600);
        return NULL;
    }

    eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &windowWidthTi);
    eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &windowHeightTi);

    fprintf(stderr,"Window width=%d, Height=%d\n", windowWidthTi, windowHeightTi);

    (void*)(*pNativePixmapPtr)->lAddress;

    return (void*)(*pNativePixmapPtr)->lAddress;
}

On the OMAP 5 / Sitara - AM57xx EVM, with the SGX 540 GPU, I've built and deployed the processor SDK with the OpenGL libraries, cmemk.ko, and pvrsrvctl. I can successfully run the PVR OpenGL demos and they show up on the display. I'm trying to run my application on this new EVM and it always fails with:

Error: eglChooseConfig() failed.
Error creating EGL surface!

If I remove the EGL_PIXMAP_BIT in the pi32ConfigAttribs, then it gets further.

Do the AM57xx OpenGL libraries not support PIXMAP surfaces? If they do, how can I get them to work? Thanks!

1

There are 1 answers

0
ClayMontgomery On BEST ANSWER

You should not be using the EGL_PIXMAP_BIT. It requires the EGL to provide surfaces in a format which is directly compatible with the OS's windowing system for off-screen image transfers. Use FBOs for this instead.

Note that pixmaps are not the same thing as pixel buffers or (pbuffers).

It looks like you are using TI's embedded Linux distribution, so pixmaps would have to be compatible with something like Qt, DirectFB or X11. TI has never provided EGL drivers for OMAP that were that well integrated for specific windowing system's off-screen images. EGL_PIXMAP_BIT may have worked in the past with some specific windowing system, but not necessarily the one you are using. This article explains in more detail the differences between various types of off-screen images for OpenGL ES:

Render to Texture with OpenGL ES