Wednesday, May 25, 2011

eglGetConfigs example c c++ objc java

Name

eglGetConfigs - return a list of all EGL frame buffer configurations for a display

C Specification

EGLBoolean eglGetConfigs(EGLDisplay display,
    EGLConfig * configs,
    EGLint config_size,
    EGLint * num_config)

Parameters

display
Specifies the EGL display connection.
configs
Returns a list of configs.
config_size
Specifies the size of the list of configs.
num_config
Returns the number of configs returned.

Description

eglGetConfigs returns a list of all EGL frame buffer configurations that are available for the specified display. The items in the list can be used in any EGL function that requires an EGL frame buffer configuration.
configs does not return values, if it is specified as NULL. This is useful for querying just the number of all frame buffer configurations.
Use eglGetConfigAttrib to retrieve individual attribute values of a frame buffer configuration.

Errors of eglGetConfigs

EGL_FALSE is returned on failure, EGL_TRUE otherwise. configs and num_config are not modified when EGL_FALSE is returned.
EGL_BAD_DISPLAY is generated if display is not an EGL display connection.
EGL_NOT_INITIALIZED is generated if display has not been initialized.
EGL_BAD_PARAMETER is generated if num_config is NULL.

Copyright

Copyright © 2003 Silicon Graphics, Inc.
This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.

See Also

eglCreateContext, eglCreatePbufferSurface, eglCreatePixmapSurface, eglCreateWindowSurface, eglChooseConfig, eglGetConfigAttrib

Example of eglGetConfigs

// OpenGL ES초기화
boolean myglCreate(MYAPPLET* pMe)
{
    IBitmap *   DeviceBitmap = NULL;
    IDIB *      DIB = NULL;

    EGLint params[5] = {EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE};
    EGLint major = 0;
    EGLint minor = 0;
    EGLint numConfigs = 1;

    IShell * shell;
    IDisplay * display;

    shell = pMe->m_a.m_pIShell;
    display = pMe->m_a.m_pIDisplay;

    pMe->m_IGL      = NULL;
    pMe->m_IEGL     = NULL;

    pMe->m_Display  = NULL;
    pMe->m_Config   = NULL;
    pMe->m_Surface  = NULL;
    pMe->m_Context  = NULL;

    if (ISHELL_CreateInstance(shell, AEECLSID_GL, (void **)&pMe->m_IGL) != SUCCESS)
    {
        myglDestroy( pMe );
        return FALSE;
    }

    if (ISHELL_CreateInstance(shell, AEECLSID_EGL, (void **)&pMe->m_IEGL) != SUCCESS)
    {
        myglDestroy( pMe );
        return FALSE;
    }

    IGL_Init(pMe->m_IGL);
    IEGL_Init(pMe->m_IEGL);

    pMe->m_Display = eglGetDisplay(display);

    if (pMe->m_Display == EGL_NO_DISPLAY )
    {
        DBGPRINTF(" *** eglGetDisplay failed");
        myglDestroy( pMe );
        return FALSE;
    }

    if (eglInitialize(pMe->m_Display, &major, &minor) == FALSE)
    {
        DBGPRINTF(" *** eglInitialize failed");
        myglDestroy( pMe );
        return FALSE;
    }

    DBGPRINTF(" *** ES version %d.%d", major, minor);

    if (eglGetConfigs(pMe->m_Display, &pMe->m_Config, 1, &numConfigs) == FALSE)
    {
        DBGPRINTF(" *** eglGetConfigs failed");
        myglDestroy( pMe );
        return FALSE;
    }

    if (IDISPLAY_GetDeviceBitmap(display, &DeviceBitmap) != SUCCESS)
    {
        DBGPRINTF(" *** IDISPLAY_GetDeviceBitmap failed");
        myglDestroy( pMe );
        return FALSE;
    }

    if (IBITMAP_QueryInterface(DeviceBitmap, AEECLSID_DIB, (void**)&DIB) != SUCCESS)
    {
        DBGPRINTF(" *** IBITMAP_QueryInterface failed");
        IBITMAP_Release(DeviceBitmap);
        myglDestroy( pMe );
        return FALSE;
    }

    pMe->m_Surface = eglCreateWindowSurface(pMe->m_Display, pMe->m_Config, DIB, params);

    IDIB_Release(DIB);
    IBITMAP_Release(DeviceBitmap);

    if (pMe->m_Surface == EGL_NO_SURFACE)
    {
        DBGPRINTF(" *** eglCreateWindowSurface failed");
        myglDestroy( pMe );
        return FALSE;
    }

    pMe->m_Context = eglCreateContext(pMe->m_Display, pMe->m_Config, NULL, NULL);

    if (pMe->m_Context == EGL_NO_CONTEXT)
    {
        DBGPRINTF(" *** eglCreateContext failed");
        myglDestroy( pMe );
        return FALSE;
    }

    if (eglMakeCurrent(pMe->m_Display, pMe->m_Surface, pMe->m_Surface, pMe->m_Context) == FALSE)
    {
        DBGPRINTF(" *** eglMakeCurrent failed");
        myglDestroy( pMe );
        return FALSE;
    }

    return TRUE;
}