-/* $Id: pixel.c,v 1.5 1999/11/11 01:22:27 brianp Exp $ */
-
/*
* Mesa 3-D graphics library
- * Version: 3.3
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
*/
-/*
- * glPixelStore, glPixelTransfer, glPixelMap, glPixelZoom, etc.
+/**
+ * \file pixel.c
+ * Pixel transfer functions (glPixelZoom, glPixelMap, glPixelTransfer)
*/
-
-#ifdef PC_HEADER
-#include "all.h"
-#else
#include "glheader.h"
+#include "bufferobj.h"
+#include "colormac.h"
#include "context.h"
#include "macros.h"
-#include "mem.h"
+#include "mfeatures.h"
#include "pixel.h"
-#include "types.h"
-#endif
+#include "pbo.h"
+#include "mtypes.h"
+#include "main/dispatch.h"
+#if FEATURE_pixel_transfer
+
/**********************************************************************/
/***** glPixelZoom *****/
/**********************************************************************/
-
-
-void
+static void GLAPIENTRY
_mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
{
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelZoom");
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (ctx->Pixel.ZoomX == xfactor &&
+ ctx->Pixel.ZoomY == yfactor)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.ZoomX = xfactor;
ctx->Pixel.ZoomY = yfactor;
}
/**********************************************************************/
-/***** glPixelStore *****/
+/***** glPixelMap *****/
/**********************************************************************/
+/**
+ * Return pointer to a pixelmap by name.
+ */
+static struct gl_pixelmap *
+get_pixelmap(struct gl_context *ctx, GLenum map)
+{
+ switch (map) {
+ case GL_PIXEL_MAP_I_TO_I:
+ return &ctx->PixelMaps.ItoI;
+ case GL_PIXEL_MAP_S_TO_S:
+ return &ctx->PixelMaps.StoS;
+ case GL_PIXEL_MAP_I_TO_R:
+ return &ctx->PixelMaps.ItoR;
+ case GL_PIXEL_MAP_I_TO_G:
+ return &ctx->PixelMaps.ItoG;
+ case GL_PIXEL_MAP_I_TO_B:
+ return &ctx->PixelMaps.ItoB;
+ case GL_PIXEL_MAP_I_TO_A:
+ return &ctx->PixelMaps.ItoA;
+ case GL_PIXEL_MAP_R_TO_R:
+ return &ctx->PixelMaps.RtoR;
+ case GL_PIXEL_MAP_G_TO_G:
+ return &ctx->PixelMaps.GtoG;
+ case GL_PIXEL_MAP_B_TO_B:
+ return &ctx->PixelMaps.BtoB;
+ case GL_PIXEL_MAP_A_TO_A:
+ return &ctx->PixelMaps.AtoA;
+ default:
+ return NULL;
+ }
+}
+
-void
-_mesa_PixelStorei( GLenum pname, GLint param )
+/**
+ * Helper routine used by the other _mesa_PixelMap() functions.
+ */
+static void
+store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize,
+ const GLfloat *values)
{
- /* NOTE: this call can't be compiled into the display list */
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelStore");
+ GLint i;
+ struct gl_pixelmap *pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glPixelMap(map)");
+ return;
+ }
- switch (pname) {
- case GL_PACK_SWAP_BYTES:
- ctx->Pack.SwapBytes = param ? GL_TRUE : GL_FALSE;
- break;
- case GL_PACK_LSB_FIRST:
- ctx->Pack.LsbFirst = param ? GL_TRUE : GL_FALSE;
- break;
- case GL_PACK_ROW_LENGTH:
- if (param<0) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- }
- else {
- ctx->Pack.RowLength = param;
- }
- break;
- case GL_PACK_IMAGE_HEIGHT:
- if (param<0)
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- else
- ctx->Pack.ImageHeight = param;
- break;
- case GL_PACK_SKIP_PIXELS:
- if (param<0) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- }
- else {
- ctx->Pack.SkipPixels = param;
- }
- break;
- case GL_PACK_SKIP_ROWS:
- if (param<0) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- }
- else {
- ctx->Pack.SkipRows = param;
- }
- break;
- case GL_PACK_ALIGNMENT:
- if (param==1 || param==2 || param==4 || param==8) {
- ctx->Pack.Alignment = param;
- }
- else {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- }
- break;
- case GL_UNPACK_SWAP_BYTES:
- ctx->Unpack.SwapBytes = param ? GL_TRUE : GL_FALSE;
- break;
- case GL_UNPACK_LSB_FIRST:
- ctx->Unpack.LsbFirst = param ? GL_TRUE : GL_FALSE;
- break;
- case GL_UNPACK_ROW_LENGTH:
- if (param<0) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- }
- else {
- ctx->Unpack.RowLength = param;
- }
- break;
- case GL_UNPACK_IMAGE_HEIGHT:
- if (param<0)
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- else
- ctx->Unpack.ImageHeight = param;
- break;
- case GL_UNPACK_SKIP_PIXELS:
- if (param<0) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- }
- else {
- ctx->Unpack.SkipPixels = param;
- }
- break;
- case GL_UNPACK_SKIP_ROWS:
- if (param<0) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
- }
- else {
- ctx->Unpack.SkipRows = param;
- }
- break;
- case GL_UNPACK_ALIGNMENT:
- if (param==1 || param==2 || param==4 || param==8) {
- ctx->Unpack.Alignment = param;
- }
- else {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelStore" );
- }
- break;
- default:
- gl_error( ctx, GL_INVALID_ENUM, "glPixelStore" );
+ switch (map) {
+ case GL_PIXEL_MAP_S_TO_S:
+ /* special case */
+ ctx->PixelMaps.StoS.Size = mapsize;
+ for (i = 0; i < mapsize; i++) {
+ ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]);
+ }
+ break;
+ case GL_PIXEL_MAP_I_TO_I:
+ /* special case */
+ ctx->PixelMaps.ItoI.Size = mapsize;
+ for (i = 0; i < mapsize; i++) {
+ ctx->PixelMaps.ItoI.Map[i] = values[i];
+ }
+ break;
+ default:
+ /* general case */
+ pm->Size = mapsize;
+ for (i = 0; i < mapsize; i++) {
+ GLfloat val = CLAMP(values[i], 0.0F, 1.0F);
+ pm->Map[i] = val;
+ pm->Map8[i] = (GLint) (val * 255.0F);
+ }
}
}
-void
-_mesa_PixelStoref( GLenum pname, GLfloat param )
+/**
+ * Convenience wrapper for _mesa_validate_pbo_access() for gl[Get]PixelMap().
+ */
+static GLboolean
+validate_pbo_access(struct gl_context *ctx,
+ struct gl_pixelstore_attrib *pack, GLsizei mapsize,
+ GLenum format, GLenum type, GLsizei clientMemSize,
+ const GLvoid *ptr)
{
- _mesa_PixelStorei( pname, (GLint) param );
+ GLboolean ok;
+
+ /* Note, need to use DefaultPacking and Unpack's buffer object */
+ _mesa_reference_buffer_object(ctx,
+ &ctx->DefaultPacking.BufferObj,
+ pack->BufferObj);
+
+ ok = _mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ format, type, clientMemSize, ptr);
+
+ /* restore */
+ _mesa_reference_buffer_object(ctx,
+ &ctx->DefaultPacking.BufferObj,
+ ctx->Shared->NullBufferObj);
+
+ if (!ok) {
+ if (_mesa_is_bufferobj(pack->BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "gl[Get]PixelMap*v(out of bounds PBO access)");
+ } else {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetnPixelMap*vARB(out of bounds access:"
+ " bufSize (%d) is too small)", clientMemSize);
+ }
+ }
+ return ok;
}
+static void GLAPIENTRY
+_mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
-/**********************************************************************/
-/***** glPixelMap *****/
-/**********************************************************************/
+ /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */
+ if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
+ return;
+ }
+
+ if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
+ /* test that mapsize is a power of two */
+ if (!_mesa_is_pow_two(mapsize)) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
+ return;
+ }
+ }
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize, GL_INTENSITY,
+ GL_FLOAT, INT_MAX, values)) {
+ return;
+ }
-void
-_mesa_PixelMapfv( GLenum map, GLint mapsize, const GLfloat *values )
+ values = (const GLfloat *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapfv(PBO is mapped)");
+ }
+ return;
+ }
+
+ store_pixelmap(ctx, map, mapsize, values);
+
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+}
+
+
+static void GLAPIENTRY
+_mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
{
- GLint i;
+ GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelMapfv");
-
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
- if (mapsize<0 || mapsize>MAX_PIXEL_MAP_TABLE) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
+ if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
return;
}
- if (map>=GL_PIXEL_MAP_S_TO_S && map<=GL_PIXEL_MAP_I_TO_A) {
+ if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
/* test that mapsize is a power of two */
- GLuint p;
- GLboolean ok = GL_FALSE;
- for (p=1; p<=MAX_PIXEL_MAP_TABLE; p=p<<1) {
- if ( (p&mapsize) == p ) {
- ok = GL_TRUE;
- break;
- }
- }
- if (!ok) {
- gl_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
+ if (!_mesa_is_pow_two(mapsize)) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
return;
}
}
- switch (map) {
- case GL_PIXEL_MAP_S_TO_S:
- ctx->Pixel.MapStoSsize = mapsize;
- for (i=0;i<mapsize;i++) {
- ctx->Pixel.MapStoS[i] = (GLint) values[i];
- }
- break;
- case GL_PIXEL_MAP_I_TO_I:
- ctx->Pixel.MapItoIsize = mapsize;
- for (i=0;i<mapsize;i++) {
- ctx->Pixel.MapItoI[i] = (GLint) values[i];
- }
- break;
- case GL_PIXEL_MAP_I_TO_R:
- ctx->Pixel.MapItoRsize = mapsize;
- for (i=0;i<mapsize;i++) {
- GLfloat val = CLAMP( values[i], 0.0, 1.0 );
- ctx->Pixel.MapItoR[i] = val;
- ctx->Pixel.MapItoR8[i] = (GLint) (val * 255.0F);
- }
- break;
- case GL_PIXEL_MAP_I_TO_G:
- ctx->Pixel.MapItoGsize = mapsize;
- for (i=0;i<mapsize;i++) {
- GLfloat val = CLAMP( values[i], 0.0, 1.0 );
- ctx->Pixel.MapItoG[i] = val;
- ctx->Pixel.MapItoG8[i] = (GLint) (val * 255.0F);
- }
- break;
- case GL_PIXEL_MAP_I_TO_B:
- ctx->Pixel.MapItoBsize = mapsize;
- for (i=0;i<mapsize;i++) {
- GLfloat val = CLAMP( values[i], 0.0, 1.0 );
- ctx->Pixel.MapItoB[i] = val;
- ctx->Pixel.MapItoB8[i] = (GLint) (val * 255.0F);
- }
- break;
- case GL_PIXEL_MAP_I_TO_A:
- ctx->Pixel.MapItoAsize = mapsize;
- for (i=0;i<mapsize;i++) {
- GLfloat val = CLAMP( values[i], 0.0, 1.0 );
- ctx->Pixel.MapItoA[i] = val;
- ctx->Pixel.MapItoA8[i] = (GLint) (val * 255.0F);
- }
- break;
- case GL_PIXEL_MAP_R_TO_R:
- ctx->Pixel.MapRtoRsize = mapsize;
- for (i=0;i<mapsize;i++) {
- ctx->Pixel.MapRtoR[i] = CLAMP( values[i], 0.0, 1.0 );
- }
- break;
- case GL_PIXEL_MAP_G_TO_G:
- ctx->Pixel.MapGtoGsize = mapsize;
- for (i=0;i<mapsize;i++) {
- ctx->Pixel.MapGtoG[i] = CLAMP( values[i], 0.0, 1.0 );
- }
- break;
- case GL_PIXEL_MAP_B_TO_B:
- ctx->Pixel.MapBtoBsize = mapsize;
- for (i=0;i<mapsize;i++) {
- ctx->Pixel.MapBtoB[i] = CLAMP( values[i], 0.0, 1.0 );
- }
- break;
- case GL_PIXEL_MAP_A_TO_A:
- ctx->Pixel.MapAtoAsize = mapsize;
- for (i=0;i<mapsize;i++) {
- ctx->Pixel.MapAtoA[i] = CLAMP( values[i], 0.0, 1.0 );
- }
- break;
- default:
- gl_error( ctx, GL_INVALID_ENUM, "glPixelMapfv(map)" );
- }
-}
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize, GL_INTENSITY,
+ GL_UNSIGNED_INT, INT_MAX, values)) {
+ return;
+ }
+ values = (const GLuint *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapuiv(PBO is mapped)");
+ }
+ return;
+ }
-void
-_mesa_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values )
-{
- GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
- GLint i;
- if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) {
- for (i=0;i<mapsize;i++) {
+ /* convert to floats */
+ if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
fvalues[i] = (GLfloat) values[i];
}
}
else {
- for (i=0;i<mapsize;i++) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
fvalues[i] = UINT_TO_FLOAT( values[i] );
}
}
- _mesa_PixelMapfv(map, mapsize, fvalues);
-}
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+ store_pixelmap(ctx, map, mapsize, fvalues);
+}
-void
-_mesa_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values )
+
+static void GLAPIENTRY
+_mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
{
GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
- GLint i;
- if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) {
- for (i=0;i<mapsize;i++) {
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapusv(mapsize)" );
+ return;
+ }
+
+ if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
+ /* test that mapsize is a power of two */
+ if (!_mesa_is_pow_two(mapsize)) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
+ return;
+ }
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+
+ if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize, GL_INTENSITY,
+ GL_UNSIGNED_SHORT, INT_MAX, values)) {
+ return;
+ }
+
+ values = (const GLushort *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapusv(PBO is mapped)");
+ }
+ return;
+ }
+
+ /* convert to floats */
+ if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
fvalues[i] = (GLfloat) values[i];
}
}
else {
- for (i=0;i<mapsize;i++) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
fvalues[i] = USHORT_TO_FLOAT( values[i] );
}
}
- _mesa_PixelMapfv(map, mapsize, fvalues);
-}
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+ store_pixelmap(ctx, map, mapsize, fvalues);
+}
-void
-_mesa_GetPixelMapfv( GLenum map, GLfloat *values )
+
+static void GLAPIENTRY
+_mesa_GetnPixelMapfvARB( GLenum map, GLsizei bufSize, GLfloat *values )
{
GET_CURRENT_CONTEXT(ctx);
- GLint i;
+ GLint mapsize, i;
+ const struct gl_pixelmap *pm;
- ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetPixelMapfv");
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
- switch (map) {
- case GL_PIXEL_MAP_I_TO_I:
- for (i=0;i<ctx->Pixel.MapItoIsize;i++) {
- values[i] = (GLfloat) ctx->Pixel.MapItoI[i];
- }
- break;
- case GL_PIXEL_MAP_S_TO_S:
- for (i=0;i<ctx->Pixel.MapStoSsize;i++) {
- values[i] = (GLfloat) ctx->Pixel.MapStoS[i];
- }
- break;
- case GL_PIXEL_MAP_I_TO_R:
- MEMCPY(values,ctx->Pixel.MapItoR,ctx->Pixel.MapItoRsize*sizeof(GLfloat));
- break;
- case GL_PIXEL_MAP_I_TO_G:
- MEMCPY(values,ctx->Pixel.MapItoG,ctx->Pixel.MapItoGsize*sizeof(GLfloat));
- break;
- case GL_PIXEL_MAP_I_TO_B:
- MEMCPY(values,ctx->Pixel.MapItoB,ctx->Pixel.MapItoBsize*sizeof(GLfloat));
- break;
- case GL_PIXEL_MAP_I_TO_A:
- MEMCPY(values,ctx->Pixel.MapItoA,ctx->Pixel.MapItoAsize*sizeof(GLfloat));
- break;
- case GL_PIXEL_MAP_R_TO_R:
- MEMCPY(values,ctx->Pixel.MapRtoR,ctx->Pixel.MapRtoRsize*sizeof(GLfloat));
- break;
- case GL_PIXEL_MAP_G_TO_G:
- MEMCPY(values,ctx->Pixel.MapGtoG,ctx->Pixel.MapGtoGsize*sizeof(GLfloat));
- break;
- case GL_PIXEL_MAP_B_TO_B:
- MEMCPY(values,ctx->Pixel.MapBtoB,ctx->Pixel.MapBtoBsize*sizeof(GLfloat));
- break;
- case GL_PIXEL_MAP_A_TO_A:
- MEMCPY(values,ctx->Pixel.MapAtoA,ctx->Pixel.MapAtoAsize*sizeof(GLfloat));
- break;
- default:
- gl_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
+ pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapfv(map)");
+ return;
+ }
+
+ mapsize = pm->Size;
+
+ if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
+ GL_FLOAT, bufSize, values)) {
+ return;
}
+
+ values = (GLfloat *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapfv(PBO is mapped)");
+ }
+ return;
+ }
+
+ if (map == GL_PIXEL_MAP_S_TO_S) {
+ /* special case */
+ for (i = 0; i < mapsize; i++) {
+ values[i] = (GLfloat) ctx->PixelMaps.StoS.Map[i];
+ }
+ }
+ else {
+ memcpy(values, pm->Map, mapsize * sizeof(GLfloat));
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
-void
-_mesa_GetPixelMapuiv( GLenum map, GLuint *values )
+static void GLAPIENTRY
+_mesa_GetPixelMapfv( GLenum map, GLfloat *values )
+{
+ _mesa_GetnPixelMapfvARB(map, INT_MAX, values);
+}
+
+static void GLAPIENTRY
+_mesa_GetnPixelMapuivARB( GLenum map, GLsizei bufSize, GLuint *values )
{
GET_CURRENT_CONTEXT(ctx);
- GLint i;
+ GLint mapsize, i;
+ const struct gl_pixelmap *pm;
- ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetPixelMapfv");
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
- switch (map) {
- case GL_PIXEL_MAP_I_TO_I:
- MEMCPY(values, ctx->Pixel.MapItoI, ctx->Pixel.MapItoIsize*sizeof(GLint));
- break;
- case GL_PIXEL_MAP_S_TO_S:
- MEMCPY(values, ctx->Pixel.MapStoS, ctx->Pixel.MapStoSsize*sizeof(GLint));
- break;
- case GL_PIXEL_MAP_I_TO_R:
- for (i=0;i<ctx->Pixel.MapItoRsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoR[i] );
- }
- break;
- case GL_PIXEL_MAP_I_TO_G:
- for (i=0;i<ctx->Pixel.MapItoGsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoG[i] );
- }
- break;
- case GL_PIXEL_MAP_I_TO_B:
- for (i=0;i<ctx->Pixel.MapItoBsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoB[i] );
- }
- break;
- case GL_PIXEL_MAP_I_TO_A:
- for (i=0;i<ctx->Pixel.MapItoAsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoA[i] );
- }
- break;
- case GL_PIXEL_MAP_R_TO_R:
- for (i=0;i<ctx->Pixel.MapRtoRsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapRtoR[i] );
- }
- break;
- case GL_PIXEL_MAP_G_TO_G:
- for (i=0;i<ctx->Pixel.MapGtoGsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapGtoG[i] );
- }
- break;
- case GL_PIXEL_MAP_B_TO_B:
- for (i=0;i<ctx->Pixel.MapBtoBsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapBtoB[i] );
- }
- break;
- case GL_PIXEL_MAP_A_TO_A:
- for (i=0;i<ctx->Pixel.MapAtoAsize;i++) {
- values[i] = FLOAT_TO_UINT( ctx->Pixel.MapAtoA[i] );
- }
- break;
- default:
- gl_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
+ pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapuiv(map)");
+ return;
+ }
+
+ mapsize = pm->Size;
+
+ if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
+ GL_UNSIGNED_INT, bufSize, values)) {
+ return;
+ }
+
+ values = (GLuint *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapuiv(PBO is mapped)");
+ }
+ return;
+ }
+
+ if (map == GL_PIXEL_MAP_S_TO_S) {
+ /* special case */
+ memcpy(values, ctx->PixelMaps.StoS.Map, mapsize * sizeof(GLint));
}
+ else {
+ for (i = 0; i < mapsize; i++) {
+ values[i] = FLOAT_TO_UINT( pm->Map[i] );
+ }
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
-void
-_mesa_GetPixelMapusv( GLenum map, GLushort *values )
+static void GLAPIENTRY
+_mesa_GetPixelMapuiv( GLenum map, GLuint *values )
+{
+ _mesa_GetnPixelMapuivARB(map, INT_MAX, values);
+}
+
+static void GLAPIENTRY
+_mesa_GetnPixelMapusvARB( GLenum map, GLsizei bufSize, GLushort *values )
{
GET_CURRENT_CONTEXT(ctx);
- GLint i;
+ GLint mapsize, i;
+ const struct gl_pixelmap *pm;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapusv(map)");
+ return;
+ }
- ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetPixelMapfv");
+ mapsize = pm->Size;
+
+ if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
+ GL_UNSIGNED_SHORT, bufSize, values)) {
+ return;
+ }
+
+ values = (GLushort *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapusv(PBO is mapped)");
+ }
+ return;
+ }
switch (map) {
- case GL_PIXEL_MAP_I_TO_I:
- for (i=0;i<ctx->Pixel.MapItoIsize;i++) {
- values[i] = (GLushort) ctx->Pixel.MapItoI[i];
- }
- break;
- case GL_PIXEL_MAP_S_TO_S:
- for (i=0;i<ctx->Pixel.MapStoSsize;i++) {
- values[i] = (GLushort) ctx->Pixel.MapStoS[i];
- }
- break;
- case GL_PIXEL_MAP_I_TO_R:
- for (i=0;i<ctx->Pixel.MapItoRsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoR[i] );
- }
- break;
- case GL_PIXEL_MAP_I_TO_G:
- for (i=0;i<ctx->Pixel.MapItoGsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoG[i] );
- }
- break;
- case GL_PIXEL_MAP_I_TO_B:
- for (i=0;i<ctx->Pixel.MapItoBsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoB[i] );
- }
- break;
- case GL_PIXEL_MAP_I_TO_A:
- for (i=0;i<ctx->Pixel.MapItoAsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoA[i] );
- }
- break;
- case GL_PIXEL_MAP_R_TO_R:
- for (i=0;i<ctx->Pixel.MapRtoRsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapRtoR[i] );
- }
- break;
- case GL_PIXEL_MAP_G_TO_G:
- for (i=0;i<ctx->Pixel.MapGtoGsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapGtoG[i] );
- }
- break;
- case GL_PIXEL_MAP_B_TO_B:
- for (i=0;i<ctx->Pixel.MapBtoBsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapBtoB[i] );
- }
- break;
- case GL_PIXEL_MAP_A_TO_A:
- for (i=0;i<ctx->Pixel.MapAtoAsize;i++) {
- values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapAtoA[i] );
- }
- break;
- default:
- gl_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
+ /* special cases */
+ case GL_PIXEL_MAP_I_TO_I:
+ for (i = 0; i < mapsize; i++) {
+ values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0, 65535.);
+ }
+ break;
+ case GL_PIXEL_MAP_S_TO_S:
+ for (i = 0; i < mapsize; i++) {
+ values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0, 65535.);
+ }
+ break;
+ default:
+ for (i = 0; i < mapsize; i++) {
+ CLAMPED_FLOAT_TO_USHORT(values[i], pm->Map[i] );
+ }
}
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
+static void GLAPIENTRY
+_mesa_GetPixelMapusv( GLenum map, GLushort *values )
+{
+ _mesa_GetnPixelMapusvARB(map, INT_MAX, values);
+}
+
/**********************************************************************/
/***** glPixelTransfer *****/
* Implements glPixelTransfer[fi] whether called immediately or from a
* display list.
*/
-void
+static void GLAPIENTRY
_mesa_PixelTransferf( GLenum pname, GLfloat param )
{
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelTransfer");
-
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
switch (pname) {
case GL_MAP_COLOR:
+ if (ctx->Pixel.MapColorFlag == (param ? GL_TRUE : GL_FALSE))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.MapColorFlag = param ? GL_TRUE : GL_FALSE;
break;
case GL_MAP_STENCIL:
+ if (ctx->Pixel.MapStencilFlag == (param ? GL_TRUE : GL_FALSE))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.MapStencilFlag = param ? GL_TRUE : GL_FALSE;
break;
case GL_INDEX_SHIFT:
+ if (ctx->Pixel.IndexShift == (GLint) param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.IndexShift = (GLint) param;
break;
case GL_INDEX_OFFSET:
+ if (ctx->Pixel.IndexOffset == (GLint) param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.IndexOffset = (GLint) param;
break;
case GL_RED_SCALE:
+ if (ctx->Pixel.RedScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.RedScale = param;
break;
case GL_RED_BIAS:
+ if (ctx->Pixel.RedBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.RedBias = param;
break;
case GL_GREEN_SCALE:
+ if (ctx->Pixel.GreenScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.GreenScale = param;
break;
case GL_GREEN_BIAS:
+ if (ctx->Pixel.GreenBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.GreenBias = param;
break;
case GL_BLUE_SCALE:
+ if (ctx->Pixel.BlueScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.BlueScale = param;
break;
case GL_BLUE_BIAS:
+ if (ctx->Pixel.BlueBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.BlueBias = param;
break;
case GL_ALPHA_SCALE:
+ if (ctx->Pixel.AlphaScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.AlphaScale = param;
break;
case GL_ALPHA_BIAS:
+ if (ctx->Pixel.AlphaBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.AlphaBias = param;
break;
case GL_DEPTH_SCALE:
+ if (ctx->Pixel.DepthScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.DepthScale = param;
break;
case GL_DEPTH_BIAS:
+ if (ctx->Pixel.DepthBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
ctx->Pixel.DepthBias = param;
break;
default:
- gl_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" );
+ _mesa_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" );
return;
}
-
- if (ctx->Pixel.RedScale!=1.0F || ctx->Pixel.RedBias!=0.0F ||
- ctx->Pixel.GreenScale!=1.0F || ctx->Pixel.GreenBias!=0.0F ||
- ctx->Pixel.BlueScale!=1.0F || ctx->Pixel.BlueBias!=0.0F ||
- ctx->Pixel.AlphaScale!=1.0F || ctx->Pixel.AlphaBias!=0.0F) {
- ctx->Pixel.ScaleOrBiasRGBA = GL_TRUE;
- }
- else {
- ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
- }
}
-void
+static void GLAPIENTRY
_mesa_PixelTransferi( GLenum pname, GLint param )
{
_mesa_PixelTransferf( pname, (GLfloat) param );
+/**********************************************************************/
+/***** State Management *****/
+/**********************************************************************/
/*
- * Pixel processing functions
- */
-
-
-/*
- * Apply scale and bias factors to an array of RGBA pixels.
- */
-void gl_scale_and_bias_color( const GLcontext *ctx, GLuint n,
- GLfloat red[], GLfloat green[],
- GLfloat blue[], GLfloat alpha[] )
-{
- GLuint i;
- for (i=0;i<n;i++) {
- GLfloat r = red[i] * ctx->Pixel.RedScale + ctx->Pixel.RedBias;
- GLfloat g = green[i] * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias;
- GLfloat b = blue[i] * ctx->Pixel.BlueScale + ctx->Pixel.BlueBias;
- GLfloat a = alpha[i] * ctx->Pixel.AlphaScale + ctx->Pixel.AlphaBias;
- red[i] = CLAMP( r, 0.0F, 1.0F );
- green[i] = CLAMP( g, 0.0F, 1.0F );
- blue[i] = CLAMP( b, 0.0F, 1.0F );
- alpha[i] = CLAMP( a, 0.0F, 1.0F );
- }
-}
-
-
-/*
- * Apply scale and bias factors to an array of RGBA pixels.
- */
-void gl_scale_and_bias_rgba( const GLcontext *ctx, GLuint n, GLubyte rgba[][4] )
-{
- GLfloat rbias = ctx->Pixel.RedBias * 255.0F;
- GLfloat gbias = ctx->Pixel.GreenBias * 255.0F;
- GLfloat bbias = ctx->Pixel.BlueBias * 255.0F;
- GLfloat abias = ctx->Pixel.AlphaBias * 255.0F;
- GLuint i;
- for (i=0;i<n;i++) {
- GLint r = (GLint) (rgba[i][RCOMP] * ctx->Pixel.RedScale + rbias);
- GLint g = (GLint) (rgba[i][GCOMP] * ctx->Pixel.GreenScale + gbias);
- GLint b = (GLint) (rgba[i][BCOMP] * ctx->Pixel.BlueScale + bbias);
- GLint a = (GLint) (rgba[i][ACOMP] * ctx->Pixel.AlphaScale + abias);
- rgba[i][RCOMP] = CLAMP( r, 0, 255 );
- rgba[i][GCOMP] = CLAMP( g, 0, 255 );
- rgba[i][BCOMP] = CLAMP( b, 0, 255 );
- rgba[i][ACOMP] = CLAMP( a, 0, 255 );
- }
-}
-
-
-/*
- * Apply scale and bias factors to an array of RGBA pixels.
+ * Return a bitmask of IMAGE_*_BIT flags which to indicate which
+ * pixel transfer operations are enabled.
*/
-void gl_scale_and_bias_rgba_float( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] )
+static void
+update_image_transfer_state(struct gl_context *ctx)
{
- if (ctx->Pixel.RedScale != 1.0 || ctx->Pixel.RedBias != 0.0) {
- const GLfloat scale = ctx->Pixel.RedScale;
- const GLfloat bias = ctx->Pixel.RedBias;
- GLuint i;
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = rgba[i][RCOMP] * scale + bias;
- }
- }
- if (ctx->Pixel.GreenScale != 1.0 || ctx->Pixel.GreenBias != 0.0) {
- const GLfloat scale = ctx->Pixel.GreenScale;
- const GLfloat bias = ctx->Pixel.GreenBias;
- GLuint i;
- for (i = 0; i < n; i++) {
- rgba[i][GCOMP] = rgba[i][GCOMP] * scale + bias;
- }
- }
- if (ctx->Pixel.BlueScale != 1.0 || ctx->Pixel.BlueBias != 0.0) {
- const GLfloat scale = ctx->Pixel.BlueScale;
- const GLfloat bias = ctx->Pixel.BlueBias;
- GLuint i;
- for (i = 0; i < n; i++) {
- rgba[i][BCOMP] = rgba[i][BCOMP] * scale + bias;
- }
- }
- if (ctx->Pixel.AlphaScale != 1.0 || ctx->Pixel.AlphaBias != 0.0) {
- const GLfloat scale = ctx->Pixel.AlphaScale;
- const GLfloat bias = ctx->Pixel.AlphaBias;
- GLuint i;
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = rgba[i][ACOMP] * scale + bias;
- }
- }
-}
+ GLuint mask = 0;
+ if (ctx->Pixel.RedScale != 1.0F || ctx->Pixel.RedBias != 0.0F ||
+ ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
+ ctx->Pixel.BlueScale != 1.0F || ctx->Pixel.BlueBias != 0.0F ||
+ ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
+ mask |= IMAGE_SCALE_BIAS_BIT;
-/*
- * Apply pixel mapping to an array of RGBA pixels.
- */
-void gl_map_rgba( const GLcontext *ctx, GLuint n, GLubyte rgba[][4] )
-{
- GLfloat rscale = (ctx->Pixel.MapRtoRsize - 1) / 255.0F;
- GLfloat gscale = (ctx->Pixel.MapGtoGsize - 1) / 255.0F;
- GLfloat bscale = (ctx->Pixel.MapBtoBsize - 1) / 255.0F;
- GLfloat ascale = (ctx->Pixel.MapAtoAsize - 1) / 255.0F;
- GLuint i;
- for (i=0;i<n;i++) {
- GLint ir = (GLint) (rgba[i][RCOMP] * rscale);
- GLint ig = (GLint) (rgba[i][GCOMP] * gscale);
- GLint ib = (GLint) (rgba[i][BCOMP] * bscale);
- GLint ia = (GLint) (rgba[i][ACOMP] * ascale);
- rgba[i][RCOMP] = (GLint) (ctx->Pixel.MapRtoR[ir] * 255.0F);
- rgba[i][GCOMP] = (GLint) (ctx->Pixel.MapGtoG[ig] * 255.0F);
- rgba[i][BCOMP] = (GLint) (ctx->Pixel.MapBtoB[ib] * 255.0F);
- rgba[i][ACOMP] = (GLint) (ctx->Pixel.MapAtoA[ia] * 255.0F);
- }
-}
+ if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
+ mask |= IMAGE_SHIFT_OFFSET_BIT;
+ if (ctx->Pixel.MapColorFlag)
+ mask |= IMAGE_MAP_COLOR_BIT;
-/*
- * Apply pixel mapping to an array of floating point RGBA pixels.
- */
-void gl_map_rgba_float( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] )
-{
- const GLfloat rscale = ctx->Pixel.MapRtoRsize - 1;
- const GLfloat gscale = ctx->Pixel.MapGtoGsize - 1;
- const GLfloat bscale = ctx->Pixel.MapBtoBsize - 1;
- const GLfloat ascale = ctx->Pixel.MapAtoAsize - 1;
- const GLfloat *rMap = ctx->Pixel.MapRtoR;
- const GLfloat *gMap = ctx->Pixel.MapGtoG;
- const GLfloat *bMap = ctx->Pixel.MapBtoB;
- const GLfloat *aMap = ctx->Pixel.MapAtoA;
- GLuint i;
- for (i=0;i<n;i++) {
- rgba[i][RCOMP] = rMap[(GLint) (rgba[i][RCOMP] * rscale + 0.5F)];
- rgba[i][GCOMP] = gMap[(GLint) (rgba[i][GCOMP] * gscale + 0.5F)];
- rgba[i][BCOMP] = bMap[(GLint) (rgba[i][BCOMP] * bscale + 0.5F)];
- rgba[i][ACOMP] = aMap[(GLint) (rgba[i][ACOMP] * ascale + 0.5F)];
- }
+ ctx->_ImageTransferState = mask;
}
-/*
- * Apply pixel mapping to an array of RGBA pixels.
+/**
+ * Update mesa pixel transfer derived state.
*/
-void gl_map_color( const GLcontext *ctx, GLuint n,
- GLfloat red[], GLfloat green[],
- GLfloat blue[], GLfloat alpha[] )
+void _mesa_update_pixel( struct gl_context *ctx, GLuint new_state )
{
- GLfloat rscale = ctx->Pixel.MapRtoRsize - 1;
- GLfloat gscale = ctx->Pixel.MapGtoGsize - 1;
- GLfloat bscale = ctx->Pixel.MapBtoBsize - 1;
- GLfloat ascale = ctx->Pixel.MapAtoAsize - 1;
- GLuint i;
- for (i=0;i<n;i++) {
- red[i] = ctx->Pixel.MapRtoR[ (GLint) (red[i] * rscale + 0.5F) ];
- green[i] = ctx->Pixel.MapGtoG[ (GLint) (green[i] * gscale + 0.5F) ];
- blue[i] = ctx->Pixel.MapBtoB[ (GLint) (blue[i] * bscale + 0.5F) ];
- alpha[i] = ctx->Pixel.MapAtoA[ (GLint) (alpha[i] * ascale + 0.5F) ];
- }
+ if (new_state & _NEW_PIXEL)
+ update_image_transfer_state(ctx);
}
-
-/*
- * Apply color index shift and offset to an array of pixels.
- */
-void gl_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] )
+void
+_mesa_init_pixel_dispatch(struct _glapi_table *disp)
{
- GLint shift = ctx->Pixel.IndexShift;
- GLint offset = ctx->Pixel.IndexOffset;
- GLuint i;
- if (shift > 0) {
- for (i=0;i<n;i++) {
- indexes[i] = (indexes[i] << shift) + offset;
- }
- }
- else if (shift < 0) {
- shift = -shift;
- for (i=0;i<n;i++) {
- indexes[i] = (indexes[i] >> shift) + offset;
- }
- }
- else {
- for (i=0;i<n;i++) {
- indexes[i] = indexes[i] + offset;
- }
- }
+ SET_GetPixelMapfv(disp, _mesa_GetPixelMapfv);
+ SET_GetPixelMapuiv(disp, _mesa_GetPixelMapuiv);
+ SET_GetPixelMapusv(disp, _mesa_GetPixelMapusv);
+ SET_PixelMapfv(disp, _mesa_PixelMapfv);
+ SET_PixelMapuiv(disp, _mesa_PixelMapuiv);
+ SET_PixelMapusv(disp, _mesa_PixelMapusv);
+ SET_PixelTransferf(disp, _mesa_PixelTransferf);
+ SET_PixelTransferi(disp, _mesa_PixelTransferi);
+ SET_PixelZoom(disp, _mesa_PixelZoom);
+
+ /* GL_ARB_robustness */
+ SET_GetnPixelMapfvARB(disp, _mesa_GetnPixelMapfvARB);
+ SET_GetnPixelMapuivARB(disp, _mesa_GetnPixelMapuivARB);
+ SET_GetnPixelMapusvARB(disp, _mesa_GetnPixelMapusvARB);
}
-/*
- * Apply color index mapping to color indexes.
- */
-void gl_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] )
-{
- GLuint mask = ctx->Pixel.MapItoIsize - 1;
- GLuint i;
- for (i=0;i<n;i++) {
- index[i] = ctx->Pixel.MapItoI[ index[i] & mask ];
- }
-}
-
+#endif /* FEATURE_pixel_transfer */
-/*
- * Map color indexes to rgba values.
- */
-void gl_map_ci_to_rgba( const GLcontext *ctx, GLuint n, const GLuint index[],
- GLubyte rgba[][4] )
-{
- GLuint rmask = ctx->Pixel.MapItoRsize - 1;
- GLuint gmask = ctx->Pixel.MapItoGsize - 1;
- GLuint bmask = ctx->Pixel.MapItoBsize - 1;
- GLuint amask = ctx->Pixel.MapItoAsize - 1;
- const GLubyte *rMap = ctx->Pixel.MapItoR8;
- const GLubyte *gMap = ctx->Pixel.MapItoG8;
- const GLubyte *bMap = ctx->Pixel.MapItoB8;
- const GLubyte *aMap = ctx->Pixel.MapItoA8;
- GLuint i;
- for (i=0;i<n;i++) {
- rgba[i][RCOMP] = rMap[index[i] & rmask];
- rgba[i][GCOMP] = gMap[index[i] & gmask];
- rgba[i][BCOMP] = bMap[index[i] & bmask];
- rgba[i][ACOMP] = aMap[index[i] & amask];
- }
-}
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
-/*
- * Map color indexes to float rgba values.
- */
-void gl_map_ci_to_rgba_float( const GLcontext *ctx, GLuint n, const GLuint index[],
- GLfloat rgba[][4] )
+static void
+init_pixelmap(struct gl_pixelmap *map)
{
- GLuint rmask = ctx->Pixel.MapItoRsize - 1;
- GLuint gmask = ctx->Pixel.MapItoGsize - 1;
- GLuint bmask = ctx->Pixel.MapItoBsize - 1;
- GLuint amask = ctx->Pixel.MapItoAsize - 1;
- const GLfloat *rMap = ctx->Pixel.MapItoR;
- const GLfloat *gMap = ctx->Pixel.MapItoG;
- const GLfloat *bMap = ctx->Pixel.MapItoB;
- const GLfloat *aMap = ctx->Pixel.MapItoA;
- GLuint i;
- for (i=0;i<n;i++) {
- rgba[i][RCOMP] = rMap[index[i] & rmask];
- rgba[i][GCOMP] = gMap[index[i] & gmask];
- rgba[i][BCOMP] = bMap[index[i] & bmask];
- rgba[i][ACOMP] = aMap[index[i] & amask];
- }
+ map->Size = 1;
+ map->Map[0] = 0.0;
+ map->Map8[0] = 0;
}
-/*
- * Map 8-bit color indexes to rgb values.
+/**
+ * Initialize the context's PIXEL attribute group.
*/
-void gl_map_ci8_to_rgba( const GLcontext *ctx, GLuint n, const GLubyte index[],
- GLubyte rgba[][4] )
-{
- GLuint rmask = ctx->Pixel.MapItoRsize - 1;
- GLuint gmask = ctx->Pixel.MapItoGsize - 1;
- GLuint bmask = ctx->Pixel.MapItoBsize - 1;
- GLuint amask = ctx->Pixel.MapItoAsize - 1;
- const GLubyte *rMap = ctx->Pixel.MapItoR8;
- const GLubyte *gMap = ctx->Pixel.MapItoG8;
- const GLubyte *bMap = ctx->Pixel.MapItoB8;
- const GLubyte *aMap = ctx->Pixel.MapItoA8;
- GLuint i;
- for (i=0;i<n;i++) {
- rgba[i][RCOMP] = rMap[index[i] & rmask];
- rgba[i][GCOMP] = gMap[index[i] & gmask];
- rgba[i][BCOMP] = bMap[index[i] & bmask];
- rgba[i][ACOMP] = aMap[index[i] & amask];
- }
-}
-
-
-void gl_map_ci_to_color( const GLcontext *ctx, GLuint n, const GLuint index[],
- GLfloat r[], GLfloat g[],
- GLfloat b[], GLfloat a[] )
-{
- GLuint rmask = ctx->Pixel.MapItoRsize - 1;
- GLuint gmask = ctx->Pixel.MapItoGsize - 1;
- GLuint bmask = ctx->Pixel.MapItoBsize - 1;
- GLuint amask = ctx->Pixel.MapItoAsize - 1;
- GLuint i;
- for (i=0;i<n;i++) {
- r[i] = ctx->Pixel.MapItoR[index[i] & rmask];
- g[i] = ctx->Pixel.MapItoG[index[i] & gmask];
- b[i] = ctx->Pixel.MapItoB[index[i] & bmask];
- a[i] = ctx->Pixel.MapItoA[index[i] & amask];
- }
-}
-
-
-
-void gl_shift_and_offset_stencil( const GLcontext *ctx, GLuint n,
- GLstencil stencil[] )
+void
+_mesa_init_pixel( struct gl_context *ctx )
{
- GLuint i;
- GLint shift = ctx->Pixel.IndexShift;
- GLint offset = ctx->Pixel.IndexOffset;
- if (shift > 0) {
- for (i=0;i<n;i++) {
- stencil[i] = (stencil[i] << shift) + offset;
- }
- }
- else if (shift < 0) {
- shift = -shift;
- for (i=0;i<n;i++) {
- stencil[i] = (stencil[i] >> shift) + offset;
- }
+ /* Pixel group */
+ ctx->Pixel.RedBias = 0.0;
+ ctx->Pixel.RedScale = 1.0;
+ ctx->Pixel.GreenBias = 0.0;
+ ctx->Pixel.GreenScale = 1.0;
+ ctx->Pixel.BlueBias = 0.0;
+ ctx->Pixel.BlueScale = 1.0;
+ ctx->Pixel.AlphaBias = 0.0;
+ ctx->Pixel.AlphaScale = 1.0;
+ ctx->Pixel.DepthBias = 0.0;
+ ctx->Pixel.DepthScale = 1.0;
+ ctx->Pixel.IndexOffset = 0;
+ ctx->Pixel.IndexShift = 0;
+ ctx->Pixel.ZoomX = 1.0;
+ ctx->Pixel.ZoomY = 1.0;
+ ctx->Pixel.MapColorFlag = GL_FALSE;
+ ctx->Pixel.MapStencilFlag = GL_FALSE;
+ init_pixelmap(&ctx->PixelMaps.StoS);
+ init_pixelmap(&ctx->PixelMaps.ItoI);
+ init_pixelmap(&ctx->PixelMaps.ItoR);
+ init_pixelmap(&ctx->PixelMaps.ItoG);
+ init_pixelmap(&ctx->PixelMaps.ItoB);
+ init_pixelmap(&ctx->PixelMaps.ItoA);
+ init_pixelmap(&ctx->PixelMaps.RtoR);
+ init_pixelmap(&ctx->PixelMaps.GtoG);
+ init_pixelmap(&ctx->PixelMaps.BtoB);
+ init_pixelmap(&ctx->PixelMaps.AtoA);
+
+ if (ctx->Visual.doubleBufferMode) {
+ ctx->Pixel.ReadBuffer = GL_BACK;
}
else {
- for (i=0;i<n;i++) {
- stencil[i] = stencil[i] + offset;
- }
+ ctx->Pixel.ReadBuffer = GL_FRONT;
}
+ /* Miscellaneous */
+ ctx->_ImageTransferState = 0;
}
-
-
-
-void gl_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] )
-{
- GLuint mask = ctx->Pixel.MapStoSsize - 1;
- GLuint i;
- for (i=0;i<n;i++) {
- stencil[i] = ctx->Pixel.MapStoS[ stencil[i] & mask ];
- }
-}
-