GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id ) { WindowInfo *window; VisualInfo *visual; GLboolean showIt; if (id <= 0) { id = (GLint)crHashtableAllocKeys(render_spu.windowTable, 1); if (id <= 0) { crWarning("failed to allocate window id"); return -1; } } else { if (crHashtableIsKeyUsed(render_spu.windowTable, id)) { crWarning("the specified window key %d is in use", id); return -1; } } if (!dpyName || crStrlen(render_spu.display_string) > 0) dpyName = render_spu.display_string; visual = renderspuFindVisual( dpyName, visBits ); if (!visual) { crWarning( "Render SPU: Couldn't create a window, renderspuFindVisual returned NULL" ); return -1; } /* Allocate WindowInfo */ window = (WindowInfo *) crCalloc(sizeof(WindowInfo)); if (!window) { crWarning( "Render SPU: Couldn't create a window" ); return -1; } crHashtableAdd(render_spu.windowTable, id, window); showIt = 0; /* crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->BltInfo.Base.id); */ /* Have GLX/WGL/AGL create the window */ if (!renderspuWindowInit( window, visual, showIt, id )) { crFree(window); crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" ); return -1; } return window->BltInfo.Base.id; }
static ContextInfo * renderspuCreateContextInternal(const char *dpyName, GLint visBits, GLint idCtx, ContextInfo * sharedContext) { ContextInfo *context; VisualInfo *visual; if (idCtx <= 0) { idCtx = (GLint)crHashtableAllocKeys(render_spu.contextTable, 1); if (idCtx <= 0) { crWarning("failed to allocate context id"); return NULL; } } else { if (crHashtableIsKeyUsed(render_spu.contextTable, idCtx)) { crWarning("the specified ctx key %d is in use", idCtx); return NULL; } } if (!dpyName || crStrlen(render_spu.display_string)>0) dpyName = render_spu.display_string; visual = renderspuFindVisual(dpyName, visBits); if (!visual) return NULL; context = (ContextInfo *) crCalloc(sizeof(ContextInfo)); if (!context) return NULL; context->BltInfo.Base.id = idCtx; context->shared = sharedContext; if (!renderspu_SystemCreateContext(visual, context, sharedContext)) return NULL; crHashtableAdd(render_spu.contextTable, idCtx, context); context->BltInfo.Base.visualBits = visual->visAttribs; /* crDebug("Render SPU: CreateContext(%s, 0x%x) returning %d", dpyName, visBits, context->BltInfo.Base.id); */ if (sharedContext) ASMAtomicIncU32(&sharedContext->cRefs); context->cRefs = 1; return context; }
DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsBufferARB( GLuint buffer ) { CRContext *g = GetCurrentContext(); FLUSH(); if (g->current.inBeginEnd) { crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glIsBufferARB called in begin/end"); return GL_FALSE; } return buffer ? crHashtableIsKeyUsed(g->shared->buffersTable, buffer) : GL_FALSE; }
GLboolean DLM_APIENTRY crDLMIsList(GLuint list) { CRDLMContextState *listState = CURRENT_STATE(); if (listState == NULL) { crWarning ("DLM error: IsLists(%d) called with no current state (%s line %d)\n", (int) list, __FILE__, __LINE__); return 0; } if (list == 0) return GL_FALSE; return crHashtableIsKeyUsed(listState->dlm->displayLists, list); }
GLboolean STATE_APIENTRY crStateIsQueryARB(GLuint id) { CRContext *g = GetCurrentContext(); CROcclusionState *o = &(g->occlusion); FLUSH(); if (g->current.inBeginEnd) { crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glIsQueryARB called in begin/end"); return GL_FALSE; } if (id && crHashtableIsKeyUsed(o->objects, id)) return GL_TRUE; else return GL_FALSE; }
DECLEXPORT(void) STATE_APIENTRY crStateBindRenderbufferEXT(GLenum target, GLuint renderbuffer) { CRContext *g = GetCurrentContext(); CRFramebufferObjectState *fbo = &g->framebufferobject; CRSTATE_CHECKERR(g->current.inBeginEnd, GL_INVALID_OPERATION, "called in begin/end"); CRSTATE_CHECKERR(target!=GL_RENDERBUFFER_EXT, GL_INVALID_ENUM, "invalid target"); if (renderbuffer) { fbo->renderbuffer = (CRRenderbufferObject*) crHashtableSearch(g->shared->rbTable, renderbuffer); if (!fbo->renderbuffer) { CRSTATE_CHECKERR(!crHashtableIsKeyUsed(g->shared->rbTable, renderbuffer), GL_INVALID_OPERATION, "name is not a renderbuffer"); fbo->renderbuffer = crStateRenderbufferAllocate(g, renderbuffer); } CR_STATE_SHAREDOBJ_USAGE_SET(fbo->renderbuffer, g); } else fbo->renderbuffer = NULL; }
void STATE_APIENTRY crStateBindBufferARB (GLenum target, GLuint buffer) { CRContext *g = GetCurrentContext(); CRBufferObjectState *b = &(g->bufferobject); CRStateBits *sb = GetCurrentBits(); CRBufferObjectBits *bb = &(sb->bufferobject); CRBufferObject *oldObj, *newObj; if (g->current.inBeginEnd) { crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBindBufferARB called in begin/end"); return; } FLUSH(); oldObj = crStateGetBoundBufferObject(target, b); if (!oldObj) { crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glBindBufferARB(target)"); return; } if (buffer == 0) { newObj = b->nullBuffer; } else { newObj = (CRBufferObject *) crHashtableSearch(g->shared->buffersTable, buffer); if (!newObj) { CRSTATE_CHECKERR(!crHashtableIsKeyUsed(g->shared->buffersTable, buffer), GL_INVALID_OPERATION, "name is not a buffer object"); newObj = AllocBufferObject(buffer); CRSTATE_CHECKERR(!newObj, GL_OUT_OF_MEMORY, "glBindBuffer"); #ifndef IN_GUEST diff_api.GenBuffersARB(1, &newObj->hwid); if (!newObj->hwid) { crWarning("GenBuffersARB failed!"); crFree(newObj); return; } #endif crHashtableAdd( g->shared->buffersTable, buffer, newObj ); } CR_STATE_SHAREDOBJ_USAGE_SET(newObj, g); } newObj->refCount++; oldObj->refCount--; switch (target) { case GL_ARRAY_BUFFER_ARB: b->arrayBuffer = newObj; DIRTY(bb->dirty, g->neg_bitid); DIRTY(bb->arrayBinding, g->neg_bitid); break; case GL_ELEMENT_ARRAY_BUFFER_ARB: b->elementsBuffer = newObj; DIRTY(bb->dirty, g->neg_bitid); DIRTY(bb->elementsBinding, g->neg_bitid); break; #ifdef CR_ARB_pixel_buffer_object case GL_PIXEL_PACK_BUFFER_ARB: b->packBuffer = newObj; DIRTY(bb->dirty, g->neg_bitid); DIRTY(bb->packBinding, g->neg_bitid); break; case GL_PIXEL_UNPACK_BUFFER_ARB: b->unpackBuffer = newObj; DIRTY(bb->dirty, g->neg_bitid); DIRTY(bb->unpackBinding, g->neg_bitid); break; #endif default: /*can't get here*/ CRASSERT(false); return; } if (oldObj->refCount <= 0) { /*we shouldn't reach this point*/ CRASSERT(false); crHashtableDelete(g->shared->buffersTable, (unsigned long) oldObj->id, crStateFreeBufferObject); } #ifdef IN_GUEST if (target == GL_PIXEL_PACK_BUFFER_ARB) { newObj->bResyncOnRead = GL_TRUE; } #endif }