Esempio n. 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
}
Esempio n. 2
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
}