void CrHlpPutTexImage(CRContext *pCurCtx, PVBOXVR_TEXTURE pTexture, GLenum enmFormat, void *pvData) { CRASSERT(pTexture->hwid); cr_server.head_spu->dispatch_table.BindTexture(pTexture->target, pTexture->hwid); if (!pCurCtx || crStateIsBufferBoundForCtx(pCurCtx, GL_PIXEL_UNPACK_BUFFER_ARB)) { cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); } /*read the texture, note pixels are NULL for PBO case as it's offset in the buffer*/ cr_server.head_spu->dispatch_table.TexSubImage2D(GL_TEXTURE_2D, 0 /* level*/, 0 /*xoffset*/, 0 /*yoffset*/, pTexture->width, pTexture->height, enmFormat, GL_UNSIGNED_BYTE, pvData); /*restore gl state*/ if (pCurCtx) { CRTextureObj *pTObj; CRTextureLevel *pTImg; crStateGetTextureObjectAndImage(pCurCtx, pTexture->target, 0, &pTObj, &pTImg); GLuint uid = pTObj->hwid; CRASSERT(uid); cr_server.head_spu->dispatch_table.BindTexture(pTexture->target, uid); } else { cr_server.head_spu->dispatch_table.BindTexture(pTexture->target, 0); } if (pCurCtx && crStateIsBufferBoundForCtx(pCurCtx, GL_PIXEL_UNPACK_BUFFER_ARB)) cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pCurCtx->bufferobject.unpackBuffer->hwid); }
void* CrHlpGetTexImage(CRContext *pCurCtx, PVBOXVR_TEXTURE pTexture, GLuint idPBO, GLenum enmFormat) { void *pvData = NULL; cr_server.head_spu->dispatch_table.BindTexture(pTexture->target, pTexture->hwid); if (idPBO) { cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, idPBO); } else { if (!pCurCtx || crStateIsBufferBoundForCtx(pCurCtx, GL_PIXEL_PACK_BUFFER_ARB)) { cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); } pvData = crAlloc(4*pTexture->width*pTexture->height); if (!pvData) { crWarning("Out of memory in CrHlpGetTexImage"); return NULL; } } /*read the texture, note pixels are NULL for PBO case as it's offset in the buffer*/ cr_server.head_spu->dispatch_table.GetTexImage(GL_TEXTURE_2D, 0, enmFormat, GL_UNSIGNED_BYTE, pvData); /*restore gl state*/ if (pCurCtx) { CRTextureObj *pTObj; CRTextureLevel *pTImg; crStateGetTextureObjectAndImage(pCurCtx, pTexture->target, 0, &pTObj, &pTImg); GLuint uid = pTObj->hwid; CRASSERT(uid); cr_server.head_spu->dispatch_table.BindTexture(pTexture->target, uid); } else { cr_server.head_spu->dispatch_table.BindTexture(pTexture->target, 0); } if (idPBO) { pvData = cr_server.head_spu->dispatch_table.MapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); if (!pvData) { crWarning("Failed to MapBuffer in CrHlpGetTexImage"); return NULL; } } CRASSERT(pvData); return pvData; }
void CrHlpFreeTexImage(CRContext *pCurCtx, GLuint idPBO, void *pvData) { if (idPBO) { cr_server.head_spu->dispatch_table.UnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); if (pCurCtx) cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pCurCtx->bufferobject.packBuffer->hwid); else cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); } else { crFree(pvData); if (pCurCtx && crStateIsBufferBoundForCtx(pCurCtx, GL_PIXEL_PACK_BUFFER_ARB)) cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pCurCtx->bufferobject.packBuffer->hwid); } }
GLboolean crStateIsBufferBound(GLenum target) { CRContext *g = GetCurrentContext(); return crStateIsBufferBoundForCtx(g, target); }