static void RENDER_APIENTRY renderspuWindowDestroy( GLint win ) { WindowInfo *window; GET_CONTEXT(pOldCtx); CRASSERT(win >= 0); window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, win); if (window) { crDebug("Render SPU: Destroy window (%d)", win); renderspu_SystemDestroyWindow( window ); /* remove window info from hash table, and free it */ crHashtableDelete(render_spu.windowTable, win, crFree); /* check if this window is bound to some ctx. Note: window pointer is already freed here */ crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window); /* restore current context */ { GET_CONTEXT(pNewCtx); if (pNewCtx!=pOldCtx) { renderspuMakeCurrent(pOldCtx&&pOldCtx->currentWindow ? pOldCtx->currentWindow->id:0, 0, pOldCtx ? pOldCtx->id:0); } } } else { crDebug("Render SPU: Attempt to destroy invalid window (%d)", win); } }
void Scene::display() { GET_CONTEXT(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TwWindowSize(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)); GLfloat aspect = static_cast<GLfloat>(glutGet(GLUT_WINDOW_WIDTH))/glutGet(GLUT_WINDOW_HEIGHT); glm::mat4 projection = glm::perspective(45.0f, aspect, 0.1f, 500.0f); glm::mat4 projectionView; for (std::size_t i = 0; i < m_objects.size(); ++i) { if (m_camera) { m_objects[i]->setCameraView(m_camera->view()); m_objects[i]->setCameraPos(m_camera->getPos()); } m_objects[i]->setProjection(projection); m_objects[i]->render(); } TwDraw(); glutSwapBuffers(); }
static void AccumulateScreenBBox(const GLfloat * bbox) { CRrecti winBox; GET_CONTEXT(context); WindowInfo *window = context->currentWindow; GLfloat z1 = bbox[2]; winBox.x1 = (int) bbox[0]; winBox.y1 = (int) bbox[1]; winBox.x2 = (int) bbox[4]; winBox.y2 = (int) bbox[5]; /* adjust depth for alpha composite */ binaryswap_spu.depth = z1; if (window->bboxUnion.x1 == 0 && window->bboxUnion.x2 == 0) { /* this is the first box */ window->bboxUnion = winBox; } else { /* compute union of current screen bbox and this one */ crRectiUnion(&window->bboxUnion, &window->bboxUnion, &winBox); } }
Shader::~Shader(void) { GET_CONTEXT(); unUse(); glDeleteProgram(m_program); }
void libusb_set_debug(libusb_context *ctx, int level) { ctx = GET_CONTEXT(ctx); if (ctx) ctx->debug = level; }
void * PACKSPU_APIENTRY packspu_MapBufferARB( GLenum target, GLenum access ) { GET_CONTEXT(ctx); void *buffer; CRBufferObject *pBufObj; CRASSERT(GL_TRUE == ctx->clientState->bufferobject.retainBufferData); buffer = crStateMapBufferARB(target, access); #ifdef CR_ARB_pixel_buffer_object if (buffer) { pBufObj = crStateGetBoundBufferObject(target, &ctx->clientState->bufferobject); CRASSERT(pBufObj); if (pBufObj->bResyncOnRead && access != GL_WRITE_ONLY_ARB) { /*fetch data from host side*/ packspu_GetHostBufferSubDataARB(target, 0, pBufObj->size, buffer); } } #endif return buffer; }
int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData) { int rc; PCR_BLITTER_CONTEXT pCtxInfo = NULL; PCR_BLITTER_WINDOW pWindowInfo = NULL; GET_CONTEXT(pCtx); if (pCtx) { if (pCtx->currentWindow) { pCtxInfo = &pCtx->BltInfo; pWindowInfo = &pCtx->currentWindow->BltInfo; } } CrBltSetMakeCurrentUserData(pBlitter, i32MakeCurrentUserData); rc = CrBltEnter(pBlitter, pCtxInfo, pWindowInfo); if (!RT_SUCCESS(rc)) { crWarning("CrBltEnter failed, rc %d", rc); return rc; } return VINF_SUCCESS; }
void PACKSPU_APIENTRY packspu_ArrayElement( GLint index ) { /*@todo cash guest/host pointers calculation and use appropriate path here without crStateUseServerArrays call*/ #if 1 GLboolean serverArrays = GL_FALSE; #if CR_ARB_vertex_buffer_object GET_CONTEXT(ctx); /*crDebug("packspu_ArrayElement index:%i", index);*/ if (ctx->clientState->extensions.ARB_vertex_buffer_object) serverArrays = crStateUseServerArrays(); #endif if (serverArrays) { GET_CONTEXT(ctx); CRClientState *clientState = &(ctx->clientState->client); /* LockArraysEXT can not be executed between glBegin/glEnd pair, it also * leads to vertexpointers being adjusted on the host side between glBegin/glEnd calls which * produces unpredictable results. Locking is done before the glBegin call instead. */ CRASSERT(!clientState->array.locked || clientState->array.synced); /* Send the DrawArrays command over the wire */ if (pack_spu.swap) crPackArrayElementSWAP( index ); else crPackArrayElement( index ); } else { /* evaluate locally */ GET_CONTEXT(ctx); CRClientState *clientState = &(ctx->clientState->client); if (pack_spu.swap) crPackExpandArrayElementSWAP( index, clientState ); else crPackExpandArrayElement( index, clientState ); } #else GET_CONTEXT(ctx); CRClientState *clientState = &(ctx->clientState->client); crPackExpandArrayElement(index, clientState); #endif }
static void ResetAccumulatedBBox(void) { GET_CONTEXT(context); WindowInfo *window = context->currentWindow; window->bboxUnion.x1 = 0; window->bboxUnion.x2 = 0; window->bboxUnion.y1 = 0; window->bboxUnion.y2 = 0; }
static void AccumulateFullWindow(void) { GET_CONTEXT(context); WindowInfo *window = context->currentWindow; window->bboxUnion.x1 = 0; window->bboxUnion.y1 = 0; window->bboxUnion.x2 = 100 * 1000; window->bboxUnion.y2 = 100 * 1000; }
void scroll_layer_click_config_provider(ScrollLayer *scroll_layer) { // In case there's anything interesting happening in the original handler I don't know about scroll_layer_ccp(scroll_layer); // Overwrite up/down window_single_repeating_click_subscribe(remap[BUTTON_ID_UP], 100, scroll_layer_scroll_up_click_handler); window_single_repeating_click_subscribe(remap[BUTTON_ID_DOWN], 100, scroll_layer_scroll_down_click_handler); // Update context for the select-click handler // (the handler itself, if any, exists in app code and is thus handled by the earlier *_subscribe patches) window_set_click_context(remap[BUTTON_ID_SELECT], GET_CONTEXT(scroll_layer)); }
// Auto-discover the context - if they use it at all void scroll_layer_set_context__patch(ScrollLayer *scroll_layer, void* context) { if (!scroll_layer_context_offset) { scroll_layer_set_context(scroll_layer, 0x01233210); for (scroll_layer_context_offset = 255; scroll_layer_context_offset >= 0; scroll_layer_context_offset--) { if (GET_CONTEXT(scroll_layer) == 0x01233210) { break; } } } scroll_layer_set_context(scroll_layer, context); }
void renderspuWindowTerm( WindowInfo *window ) { GET_CONTEXT(pOldCtx); /* ensure no concurrent draws can take place */ renderspuVBoxCompositorSet(window, NULL); renderspuVBoxPresentBlitterCleanup(window); renderspu_SystemDestroyWindow( window ); RTCritSectDelete(&window->CompositorLock); /* check if this window is bound to some ctx. Note: window pointer is already freed here */ crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window); /* restore current context */ { GET_CONTEXT(pNewCtx); if (pNewCtx!=pOldCtx) { renderspuMakeCurrent(pOldCtx&&pOldCtx->currentWindow ? pOldCtx->currentWindow->BltInfo.Base.id:CR_RENDER_DEFAULT_WINDOW_ID, 0, pOldCtx ? pOldCtx->BltInfo.Base.id:CR_RENDER_DEFAULT_CONTEXT_ID); } } }
void PACKSPU_APIENTRY packspu_DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ) { GLboolean serverArrays = GL_FALSE; #if CR_ARB_vertex_buffer_object GET_CONTEXT(ctx); /*crDebug("DrawRangeElements count=%d", count);*/ if (ctx->clientState->extensions.ARB_vertex_buffer_object) serverArrays = crStateUseServerArrays(); #endif if (serverArrays) { GET_CONTEXT(ctx); CRClientState *clientState = &(ctx->clientState->client); /*Note the comment in packspu_LockArraysEXT*/ if (clientState->array.locked && !clientState->array.synced) { crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount); clientState->array.synced = GL_TRUE; } /* Send the DrawRangeElements command over the wire */ if (pack_spu.swap) crPackDrawRangeElementsSWAP( mode, start, end, count, type, indices ); else crPackDrawRangeElements( mode, start, end, count, type, indices ); } else { /* evaluate locally */ GET_CONTEXT(ctx); CRClientState *clientState = &(ctx->clientState->client); if (pack_spu.swap) crPackExpandDrawRangeElementsSWAP( mode, start, end, count, type, indices, clientState ); else { crPackExpandDrawRangeElements( mode, start, end, count, type, indices, clientState ); } } }
void Scene::reshape(int width, int height) { GET_CONTEXT(); glViewport(0,0,width,height); for (std::size_t i = 0; i < m_objects.size(); ++i) m_objects[i]->reshape(width, height); TwWindowSize(width, height); glutPostRedisplay(); }
void PACKSPU_APIENTRY packspu_UnlockArraysEXT() { GET_CONTEXT(ctx); CRClientState *clientState = &(ctx->clientState->client); if (clientState->array.locked && clientState->array.synced) { crPackUnlockArraysEXT(); } crStateUnlockArraysEXT(); }
/* * Put the given buffer list into the free buffer pool. We do this when * we've finished rendering a frame and no longer need the buffer list. */ void hiddenlineReclaimPackBuffer( BufList *bl ) { if (bl->can_reclaim) { GET_CONTEXT(context); crBufferPoolPush( context->bufpool, bl->buf, hiddenline_spu.buffer_size ); } else { crPackFree( bl->buf ); } }
void PACKSPU_APIENTRY packspu_EdgeFlagPointer( GLsizei stride, const GLvoid *pointer ) { #if CR_ARB_vertex_buffer_object GET_CONTEXT(ctx); if (ctx->clientState->extensions.ARB_vertex_buffer_object) { if (pack_spu.swap) crPackEdgeFlagPointerSWAP( stride, pointer ); else crPackEdgeFlagPointer( stride, pointer ); } #endif crStateEdgeFlagPointer( stride, pointer ); }
void PACKSPU_APIENTRY packspu_TexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) { #if CR_ARB_vertex_buffer_object GET_CONTEXT(ctx); if (ctx->clientState->extensions.ARB_vertex_buffer_object) { if (pack_spu.swap) crPackTexCoordPointerSWAP( size, type, stride, pointer ); else crPackTexCoordPointer( size, type, stride, pointer ); } #endif crStateTexCoordPointer( size, type, stride, pointer ); }
void PACKSPU_APIENTRY packspu_VertexAttribPointerNV( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) { #if CR_ARB_vertex_buffer_object GET_CONTEXT(ctx); if (ctx->clientState->extensions.ARB_vertex_buffer_object) { if (pack_spu.swap) crPackVertexAttribPointerNVSWAP( index, size, type, stride, pointer ); else crPackVertexAttribPointerNV( index, size, type, stride, pointer ); } #endif crStateVertexAttribPointerNV( index, size, type, stride, pointer ); }
/** * Transform the given object-space bounds to window coordinates and * update the window's bounding box union. */ static void AccumulateObjectBBox(const GLfloat * bbox) { GLfloat proj[16], modl[16], viewport[4]; GLfloat x1, y1, z1, x2, y2, z2; CRrecti winBox; GET_CONTEXT(context); WindowInfo *window = context->currentWindow; x1 = bbox[0]; y1 = bbox[1]; z1 = bbox[2]; x2 = bbox[3]; y2 = bbox[4]; z2 = bbox[5]; /* transform by modelview and projection */ binaryswap_spu.super.GetFloatv(GL_PROJECTION_MATRIX, proj); binaryswap_spu.super.GetFloatv(GL_MODELVIEW_MATRIX, modl); crProjectBBox(modl, proj, &x1, &y1, &z1, &x2, &y2, &z2); /* Sanity check... */ if (x2 < x1 || y2 < y1 || z2 < z1) { crWarning("Damnit!!!!, we screwed up the clipping somehow..."); return; } /* adjust depth for alpha composite */ binaryswap_spu.depth = z1; /* map to window coords */ binaryswap_spu.super.GetFloatv(GL_VIEWPORT, viewport); winBox.x1 = (int) ((x1 + 1.0f) * (viewport[2] * 0.5F) + viewport[0]); winBox.y1 = (int) ((y1 + 1.0f) * (viewport[3] * 0.5F) + viewport[1]); winBox.x2 = (int) ((x2 + 1.0f) * (viewport[2] * 0.5F) + viewport[0]); winBox.y2 = (int) ((y2 + 1.0f) * (viewport[3] * 0.5F) + viewport[1]); if (window->bboxUnion.x1 == 0 && window->bboxUnion.x2 == 0) { /* this is the first box */ window->bboxUnion = winBox; } else { /* compute union of current screen bbox and this one */ crRectiUnion(&window->bboxUnion, &window->bboxUnion, &winBox); } }
/* * Get an empty packing buffer from the buffer pool, or allocate a new one. * Then tell the packer to use it. */ void hiddenlineProvidePackBuffer(void) { void *buf; GET_CONTEXT(context); CRASSERT(context); buf = crBufferPoolPop( context->bufpool, hiddenline_spu.buffer_size ); if (!buf) { buf = crAlloc( hiddenline_spu.buffer_size ); } crPackInitBuffer( &(context->pack_buffer), buf, hiddenline_spu.buffer_size, hiddenline_spu.buffer_size ); crPackSetBuffer( context->packer, &(context->pack_buffer) ); }
static __init void build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr) { /* * Bug workaround for the Nevada. It seems as if under certain * circumstances the move from cp0_context might produce a * bogus result when the mfc0 instruction and its consumer are * in a different cacheline or a load instruction, probably any * memory reference, is between them. */ switch (current_cpu_type()) { case CPU_NEVADA: UASM_i_LW(p, ptr, 0, ptr); GET_CONTEXT(p, tmp); /* get context reg */ break; default: GET_CONTEXT(p, tmp); /* get context reg */ UASM_i_LW(p, ptr, 0, ptr); break; } build_adjust_context(p, tmp); UASM_i_ADDU(p, ptr, ptr, tmp); /* add in offset */ }
/* * This is called by the packer when the packer's buffer is full and * it needs to be emptied. * This function is registered as a callback with crPackFlushFunc(). */ void hiddenlineFlush( void *arg ) { GET_CONTEXT(context); CRPackBuffer *buf; CRASSERT(context); buf = &(context->pack_buffer); /* release previous buffer if any */ crPackReleaseBuffer( context->packer ); hiddenlineRecord( buf->pack, buf->data_start, buf->opcode_start, buf->opcode_start - buf->opcode_current , 1 ); hiddenlineProvidePackBuffer(); (void) arg; }
void PACKSPU_APIENTRY packspu_InterleavedArrays( GLenum format, GLsizei stride, const GLvoid *pointer ) { #if CR_ARB_vertex_buffer_object GET_CONTEXT(ctx); if (ctx->clientState->extensions.ARB_vertex_buffer_object) { if (pack_spu.swap) crPackInterleavedArraysSWAP( format, stride, pointer ); else crPackInterleavedArrays( format, stride, pointer ); } #endif /*crDebug("packspu_InterleavedArrays");*/ crStateInterleavedArrays( format, stride, pointer ); }
bool Shader::loadFromFile(const char* fileName, GLuint type) { GET_CONTEXT(); GLuint program; std::string shaderName; if ((program = glCreateProgram()) == 0){ LOG_ERROR(boost::str(boost::format("Creating shader program fail (%d)\n") % glGetError())); return false; } // если необходимо создать вершинный шейдер if (type & Vertex){ // им¤ вершинного шейдера shaderName = boost::str(boost::format("%s.vs") % fileName); if (!loadShader(shaderName, GL_VERTEX_SHADER, program)){ glDeleteProgram(program); return false; } } // если необходимо создать фрагментный шейдер if (type & Fragment) { shaderName = boost::str(boost::format("%s.fs") % fileName); if (!loadShader(shaderName, GL_FRAGMENT_SHADER, program)){ glDeleteProgram(program); return false; } } if (type & Geometry) { shaderName = boost::str(boost::format("%s.gs") % fileName); if (!loadShader(shaderName, GL_GEOMETRY_SHADER, program)){ glDeleteProgram(program); return false; } } OPENGL_CHECK_FOR_ERRORS(); m_program = program; return true; }
void PACKSPU_APIENTRY packspu_GetBufferSubDataARB( GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data ) { GET_CONTEXT(ctx); #ifdef CR_ARB_pixel_buffer_object CRBufferObject *pBufObj; pBufObj = crStateGetBoundBufferObject(target, &ctx->clientState->bufferobject); if (pBufObj && pBufObj->bResyncOnRead) { packspu_GetHostBufferSubDataARB(target, offset, size, data); return; } #endif crStateGetBufferSubDataARB(target, offset, size, data); }
static void BINARYSWAPSPU_APIENTRY binaryswapspuDrawBuffer(GLenum buffer) { GET_CONTEXT(context); WindowInfo *window; window = context->currentWindow; CRASSERT(window); if (window->superVisBits & CR_PBUFFER_BIT) { /* we only have a front color buffer */ if (buffer != GL_FRONT) { crWarning("Binaryswap SPU: bad glDrawBuffer(0x%x)", buffer); buffer = GL_FRONT; } binaryswap_spu.super.DrawBuffer(buffer); } }
GLboolean PACKSPU_APIENTRY packspu_UnmapBufferARB( GLenum target ) { GET_CONTEXT(ctx); #if CR_ARB_vertex_buffer_object CRBufferObject *bufObj; bufObj = crStateGetBoundBufferObject(target, &ctx->clientState->bufferobject); /* send new buffer contents to server */ crPackBufferDataARB( target, bufObj->size, bufObj->pointer, bufObj->usage ); #endif CRASSERT(GL_TRUE == ctx->clientState->bufferobject.retainBufferData); crStateUnmapBufferARB( target ); return GL_TRUE; }
GLint Shader::shaderProgramStatus(GLuint program, GLenum param) { GET_CONTEXT(); GLint status = 0, length = 0; GLchar buffer[1024]; glGetProgramiv(program, param, &status); if (status != GL_TRUE) { glGetProgramInfoLog(program, 1024, &length, buffer); buffer[length] = '\0'; LOG_ERROR(boost::str(boost::format("Shader: %s\n") % (const char*)buffer)); } OPENGL_CHECK_FOR_ERRORS(); return status; }