int
__glXDisp_ReadPixels(__GLXclientState * cl, GLbyte * pc)
{
    GLsizei width, height;
    GLenum format, type;
    GLboolean swapBytes, lsbFirst;
    GLint compsize;
    __GLXcontext *cx;
    ClientPtr client = cl->client;
    int error;
    char *answer, answerBuffer[200];

    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
    if (!cx) {
        return error;
    }

    pc += __GLX_SINGLE_HDR_SIZE;
    width = *(GLsizei *) (pc + 8);
    height = *(GLsizei *) (pc + 12);
    format = *(GLenum *) (pc + 16);
    type = *(GLenum *) (pc + 20);
    swapBytes = *(GLboolean *) (pc + 24);
    lsbFirst = *(GLboolean *) (pc + 25);
    compsize = __glReadPixels_size(format, type, width, height);
    if (compsize < 0)
        compsize = 0;

    CALL_PixelStorei(GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes));
    CALL_PixelStorei(GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst));
    __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
    __glXClearErrorOccured();
    CALL_ReadPixels(GET_DISPATCH(), (*(GLint *) (pc + 0),
                                     *(GLint *) (pc + 4),
                                     *(GLsizei *) (pc + 8),
                                     *(GLsizei *) (pc + 12),
                                     *(GLenum *) (pc + 16),
                                     *(GLenum *) (pc + 20), answer));

    if (__glXErrorOccured()) {
        __GLX_BEGIN_REPLY(0);
        __GLX_SEND_HEADER();
    }
    else {
        __GLX_BEGIN_REPLY(compsize);
        __GLX_SEND_HEADER();
        __GLX_SEND_VOID_ARRAY(compsize);
    }
    cx->hasUnflushedCommands = GL_FALSE;
    return Success;
}
Beispiel #2
0
int
__glXDispSwap_ReadPixels(__GLXclientState * cl, GLbyte * pc)
{
    GLsizei width, height;
    GLenum format, type;
    GLboolean swapBytes, lsbFirst;
    GLint compsize;

    __GLX_DECLARE_SWAP_VARIABLES;
    __GLXcontext *cx;
    ClientPtr client = cl->client;
    int error;
    char *answer, answerBuffer[200];
    xGLXSingleReply reply = { 0, };

    REQUEST_FIXED_SIZE(xGLXSingleReq, 28);

    __GLX_SWAP_INT(&((xGLXSingleReq *) pc)->contextTag);
    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
    if (!cx) {
        return error;
    }

    pc += __GLX_SINGLE_HDR_SIZE;
    __GLX_SWAP_INT(pc + 0);
    __GLX_SWAP_INT(pc + 4);
    __GLX_SWAP_INT(pc + 8);
    __GLX_SWAP_INT(pc + 12);
    __GLX_SWAP_INT(pc + 16);
    __GLX_SWAP_INT(pc + 20);

    width = *(GLsizei *) (pc + 8);
    height = *(GLsizei *) (pc + 12);
    format = *(GLenum *) (pc + 16);
    type = *(GLenum *) (pc + 20);
    swapBytes = *(GLboolean *) (pc + 24);
    lsbFirst = *(GLboolean *) (pc + 25);
    compsize = __glReadPixels_size(format, type, width, height);
    if (compsize < 0)
        return BadLength;

    glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
    glPixelStorei(GL_PACK_LSB_FIRST, lsbFirst);
    __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
    __glXClearErrorOccured();
    glReadPixels(*(GLint *) (pc + 0), *(GLint *) (pc + 4),
                 *(GLsizei *) (pc + 8), *(GLsizei *) (pc + 12),
                 *(GLenum *) (pc + 16), *(GLenum *) (pc + 20), answer);

    if (__glXErrorOccured()) {
        __GLX_BEGIN_REPLY(0);
        __GLX_SWAP_REPLY_HEADER();
        __GLX_SEND_HEADER();
    }
    else {
        __GLX_BEGIN_REPLY(compsize);
        __GLX_SWAP_REPLY_HEADER();
        __GLX_SEND_HEADER();
        __GLX_SEND_VOID_ARRAY(compsize);
    }
    return Success;
}