Example #1
0
/*
 * Allocate the state (dirty) bits data structures.
 * This should be called before we create any contexts.
 * We'll also create the default/NULL context at this time and make
 * it the current context by default.  This means that if someone
 * tries to set GL state before calling MakeCurrent() they'll be
 * modifying the default state object, and not segfaulting on a NULL
 * pointer somewhere.
 */
void crStateInit(void)
{
    unsigned int i;

    /* Purely initialize the context bits */
    if (!__currentBits) {
        __currentBits = (CRStateBits *) crCalloc( sizeof(CRStateBits) );
        crStateClientInitBits( &(__currentBits->client) );
        crStateLightingInitBits( &(__currentBits->lighting) );
    } else
        crWarning("State tracker is being re-initialized..\n");

    for (i=0;i<CR_MAX_CONTEXTS;i++)
        g_availableContexts[i] = 0;

#ifdef CHROMIUM_THREADSAFE
    if (!__isContextTLSInited)
    {
# ifndef RT_OS_WINDOWS
        /* tls destructor is implemented for all platforms except windows*/
        crInitTSDF(&__contextTSD, crStateThreadTlsDtor);
# else
        /* windows should do cleanup via DllMain THREAD_DETACH notification */
        crInitTSD(&__contextTSD);
# endif
        __isContextTLSInited = 1;
    }
#endif

    if (defaultContext) {
        /* Free the default/NULL context.
         * Ensures context bits are reset */
#ifdef CHROMIUM_THREADSAFE
        SetCurrentContext(NULL);
        VBoxTlsRefRelease(defaultContext);
#else
        crStateFreeContext(defaultContext);
        __currentContext = NULL;
#endif
    }

    /* Reset diff_api */
    crMemZero(&diff_api, sizeof(SPUDispatchTable));

    /* Allocate the default/NULL context */
    defaultContext = crStateCreateContextId(0, NULL, CR_RGB_BIT, NULL);
    CRASSERT(g_availableContexts[0] == 0);
    g_availableContexts[0] = 1; /* in use forever */

#ifdef CHROMIUM_THREADSAFE
    SetCurrentContext(defaultContext);
#else
    __currentContext = defaultContext;
#endif
}
Example #2
0
CRContext *
crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID)
{
    if (presetID>0)
    {
        CRASSERT(!g_availableContexts[presetID]);
        g_availableContexts[presetID] = 1;
        return crStateCreateContextId(presetID, limits, visBits, share);
    }
    else return crStateCreateContext(limits, visBits, share);
}
Example #3
0
CRContext *
crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share)
{
    int i;

    /* Must have created the default context via crStateInit() first */
    CRASSERT(defaultContext);

    for (i = 1 ; i < CR_MAX_CONTEXTS ; i++)
    {
        if (!g_availableContexts[i])
        {
            g_availableContexts[i] = 1; /* it's no longer available */
            return crStateCreateContextId( i, limits, visBits, share );
        }
    }
    crError( "Out of available contexts in crStateCreateContexts (max %d)",
                     CR_MAX_CONTEXTS );
    /* never get here */
    return NULL;
}
Example #4
0
/*
 * Allocate the state (dirty) bits data structures.
 * This should be called before we create any contexts.
 * We'll also create the default/NULL context at this time and make
 * it the current context by default.  This means that if someone
 * tries to set GL state before calling MakeCurrent() they'll be
 * modifying the default state object, and not segfaulting on a NULL
 * pointer somewhere.
 */
void crStateInit(void)
{
    unsigned int i;

    /* Purely initialize the context bits */
    if (!__currentBits) {
        __currentBits = (CRStateBits *) crCalloc( sizeof(CRStateBits) );
        crStateClientInitBits( &(__currentBits->client) );
        crStateLightingInitBits( &(__currentBits->lighting) );
    } else
        crWarning("State tracker is being re-initialized..\n");

    for (i=0;i<CR_MAX_CONTEXTS;i++)
        g_availableContexts[i] = 0;

    if (defaultContext) {
        /* Free the default/NULL context.
         * Ensures context bits are reset */
        crStateFreeContext(defaultContext);
#ifdef CHROMIUM_THREADSAFE
        crSetTSD(&__contextTSD, NULL);
#else
        __currentContext = NULL;
#endif
    }

    /* Reset diff_api */
    crMemZero(&diff_api, sizeof(SPUDispatchTable));

    /* Allocate the default/NULL context */
    defaultContext = crStateCreateContextId(0, NULL, CR_RGB_BIT, NULL);
    CRASSERT(g_availableContexts[0] == 0);
    g_availableContexts[0] = 1; /* in use forever */

#ifdef CHROMIUM_THREADSAFE
    crSetTSD(&__contextTSD, defaultContext);
#else
    __currentContext = defaultContext;
#endif
}