Ejemplo n.º 1
0
/*
 * Solve plane and return clamped GLchan value.
 */
static inline GLchan
solve_plane_chan(GLfloat x, GLfloat y, const GLfloat plane[4])
{
   const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];
#if CHAN_TYPE == GL_FLOAT
   return CLAMP(z, 0.0F, CHAN_MAXF);
#else
   if (z < 0)
      return 0;
   else if (z > CHAN_MAX)
      return CHAN_MAX;
   return (GLchan) IROUND_POS(z);
#endif
}
Ejemplo n.º 2
0
void GLAPIENTRY
_mesa_GetColorTable( GLenum target, GLenum format,
                     GLenum type, GLvoid *data )
{
    GET_CURRENT_CONTEXT(ctx);
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    struct gl_color_table *table = NULL;
    GLchan rgba[MAX_COLOR_TABLE_SIZE][4];
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);

    if (ctx->NewState) {
        _mesa_update_state(ctx);
    }

    switch (target) {
    case GL_TEXTURE_1D:
        table = &texUnit->Current1D->Palette;
        break;
    case GL_TEXTURE_2D:
        table = &texUnit->Current2D->Palette;
        break;
    case GL_TEXTURE_3D:
        table = &texUnit->Current3D->Palette;
        break;
    case GL_TEXTURE_CUBE_MAP_ARB:
        if (!ctx->Extensions.ARB_texture_cube_map) {
            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
            return;
        }
        table = &texUnit->CurrentCubeMap->Palette;
        break;
    case GL_SHARED_TEXTURE_PALETTE_EXT:
        table = &ctx->Texture.Palette;
        break;
    case GL_COLOR_TABLE:
        table = &ctx->ColorTable;
        break;
    case GL_TEXTURE_COLOR_TABLE_SGI:
        if (!ctx->Extensions.SGI_texture_color_table) {
            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
            return;
        }
        table = &(texUnit->ColorTable);
        break;
    case GL_POST_CONVOLUTION_COLOR_TABLE:
        table = &ctx->PostConvolutionColorTable;
        break;
    case GL_POST_COLOR_MATRIX_COLOR_TABLE:
        table = &ctx->PostColorMatrixColorTable;
        break;
    default:
        _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
        return;
    }

    ASSERT(table);

    switch (table->Format) {
    case GL_ALPHA:
        if (table->Type == GL_FLOAT) {
            const GLfloat *tableF = (const GLfloat *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = 0;
                rgba[i][GCOMP] = 0;
                rgba[i][BCOMP] = 0;
                rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
            }
        }
        else {
            const GLchan *tableUB = (const GLchan *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = 0;
                rgba[i][GCOMP] = 0;
                rgba[i][BCOMP] = 0;
                rgba[i][ACOMP] = tableUB[i];
            }
        }
        break;
    case GL_LUMINANCE:
        if (table->Type == GL_FLOAT) {
            const GLfloat *tableF = (const GLfloat *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
                rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
                rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
                rgba[i][ACOMP] = CHAN_MAX;
            }
        }
        else {
            const GLchan *tableUB = (const GLchan *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = tableUB[i];
                rgba[i][GCOMP] = tableUB[i];
                rgba[i][BCOMP] = tableUB[i];
                rgba[i][ACOMP] = CHAN_MAX;
            }
        }
        break;
    case GL_LUMINANCE_ALPHA:
        if (table->Type == GL_FLOAT) {
            const GLfloat *tableF = (const GLfloat *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
                rgba[i][GCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
                rgba[i][BCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
                rgba[i][ACOMP] = IROUND_POS(tableF[i*2+1] * CHAN_MAXF);
            }
        }
        else {
            const GLchan *tableUB = (const GLchan *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = tableUB[i*2+0];
                rgba[i][GCOMP] = tableUB[i*2+0];
                rgba[i][BCOMP] = tableUB[i*2+0];
                rgba[i][ACOMP] = tableUB[i*2+1];
            }
        }
        break;
    case GL_INTENSITY:
        if (table->Type == GL_FLOAT) {
            const GLfloat *tableF = (const GLfloat *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
                rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
                rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
                rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
            }
        }
        else {
            const GLchan *tableUB = (const GLchan *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = tableUB[i];
                rgba[i][GCOMP] = tableUB[i];
                rgba[i][BCOMP] = tableUB[i];
                rgba[i][ACOMP] = tableUB[i];
            }
        }
        break;
    case GL_RGB:
        if (table->Type == GL_FLOAT) {
            const GLfloat *tableF = (const GLfloat *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = IROUND_POS(tableF[i*3+0] * CHAN_MAXF);
                rgba[i][GCOMP] = IROUND_POS(tableF[i*3+1] * CHAN_MAXF);
                rgba[i][BCOMP] = IROUND_POS(tableF[i*3+2] * CHAN_MAXF);
                rgba[i][ACOMP] = CHAN_MAX;
            }
        }
        else {
            const GLchan *tableUB = (const GLchan *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = tableUB[i*3+0];
                rgba[i][GCOMP] = tableUB[i*3+1];
                rgba[i][BCOMP] = tableUB[i*3+2];
                rgba[i][ACOMP] = CHAN_MAX;
            }
        }
        break;
    case GL_RGBA:
        if (table->Type == GL_FLOAT) {
            const GLfloat *tableF = (const GLfloat *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = IROUND_POS(tableF[i*4+0] * CHAN_MAXF);
                rgba[i][GCOMP] = IROUND_POS(tableF[i*4+1] * CHAN_MAXF);
                rgba[i][BCOMP] = IROUND_POS(tableF[i*4+2] * CHAN_MAXF);
                rgba[i][ACOMP] = IROUND_POS(tableF[i*4+3] * CHAN_MAXF);
            }
        }
        else {
            const GLchan *tableUB = (const GLchan *) table->Table;
            GLuint i;
            for (i = 0; i < table->Size; i++) {
                rgba[i][RCOMP] = tableUB[i*4+0];
                rgba[i][GCOMP] = tableUB[i*4+1];
                rgba[i][BCOMP] = tableUB[i*4+2];
                rgba[i][ACOMP] = tableUB[i*4+3];
            }
        }
        break;
    default:
        _mesa_problem(ctx, "bad table format in glGetColorTable");
        return;
    }

    if (ctx->Pack.BufferObj->Name) {
        /* pack color table into PBO */
        GLubyte *buf;
        if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
                                       format, type, data)) {
            _mesa_error(ctx, GL_INVALID_OPERATION,
                        "glGetColorTable(invalid PBO access)");
            return;
        }
        buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
                                                GL_WRITE_ONLY_ARB,
                                                ctx->Pack.BufferObj);
        if (!buf) {
            /* buffer is already mapped - that's an error */
            _mesa_error(ctx, GL_INVALID_OPERATION,
                        "glGetColorTable(PBO is mapped)");
            return;
        }
        data = ADD_POINTERS(buf, data);
    }

    _mesa_pack_rgba_span_chan(ctx, table->Size, (const GLchan (*)[4]) rgba,
                              format, type, data, &ctx->Pack, GL_FALSE);

    if (ctx->Pack.BufferObj->Name) {
        ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
                                ctx->Pack.BufferObj);
    }
}