void crStateDestroyContext( CRContext *ctx ) { CRContext *current = GetCurrentContext(); if (current == ctx) { /* destroying the current context - have to be careful here */ CRASSERT(defaultContext); /* Check to see if the differencer exists first, we may not have one, aka the packspu */ if (diff_api.AlphaFunc) crStateSwitchContext(current, defaultContext); #ifdef CHROMIUM_THREADSAFE SetCurrentContext(defaultContext); #else __currentContext = defaultContext; #endif /* ensure matrix state is also current */ crStateMatrixMode(defaultContext->transform.matrixMode); } g_availableContexts[ctx->id] = 0; #ifdef CHROMIUM_THREADSAFE VBoxTlsRefRelease(ctx); #else crStateFreeContext(ctx); #endif }
static void freeContextCallback(void *data) { ContextInfo *contextInfo = (ContextInfo *) data; crFree(contextInfo->server); crStateFreeContext(contextInfo->State); crFree(contextInfo); }
/* * 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 }
/* * 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 }
static DECLCALLBACK(void) crStateContextDtor(void *pvCtx) { crStateFreeContext((CRContext*)pvCtx); }