-
/*
* Mesa 3-D graphics library
- * Version: 4.1
+ * Version: 6.3
*
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
*/
#include "glheader.h"
-#include "imports.h"
+#include "bufferobj.h"
#include "colormac.h"
#include "context.h"
+#include "image.h"
#include "macros.h"
#include "pixel.h"
#include "mtypes.h"
-void
+void GLAPIENTRY
_mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
{
GET_CURRENT_CONTEXT(ctx);
/**********************************************************************/
-void
+void GLAPIENTRY
_mesa_PixelStorei( GLenum pname, GLint param )
{
/* NOTE: this call can't be compiled into the display list */
}
-void
+void GLAPIENTRY
_mesa_PixelStoref( GLenum pname, GLfloat param )
{
_mesa_PixelStorei( pname, (GLint) param );
/**********************************************************************/
-
-void
-_mesa_PixelMapfv( GLenum map, GLint mapsize, const GLfloat *values )
+/**
+ * Helper routine used by the other _mesa_PixelMap() functions.
+ */
+static void
+pixelmap(GLcontext *ctx, GLenum map, GLsizei mapsize, const GLfloat *values)
{
GLint i;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- 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_bitcount((GLuint) mapsize) != 1) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
- return;
- }
- }
-
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
-
switch (map) {
case GL_PIXEL_MAP_S_TO_S:
ctx->Pixel.MapStoSsize = mapsize;
- for (i=0;i<mapsize;i++) {
+ 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++) {
+ 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++) {
+ for (i = 0; i < mapsize; i++) {
GLfloat val = CLAMP( values[i], 0.0F, 1.0F );
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++) {
+ for (i = 0; i < mapsize; i++) {
GLfloat val = CLAMP( values[i], 0.0F, 1.0F );
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++) {
+ for (i = 0; i < mapsize; i++) {
GLfloat val = CLAMP( values[i], 0.0F, 1.0F );
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++) {
+ for (i = 0; i < mapsize; i++) {
GLfloat val = CLAMP( values[i], 0.0F, 1.0F );
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++) {
+ for (i = 0; i < mapsize; i++) {
ctx->Pixel.MapRtoR[i] = CLAMP( values[i], 0.0F, 1.0F );
}
break;
case GL_PIXEL_MAP_G_TO_G:
ctx->Pixel.MapGtoGsize = mapsize;
- for (i=0;i<mapsize;i++) {
+ for (i = 0; i < mapsize; i++) {
ctx->Pixel.MapGtoG[i] = CLAMP( values[i], 0.0F, 1.0F );
}
break;
case GL_PIXEL_MAP_B_TO_B:
ctx->Pixel.MapBtoBsize = mapsize;
- for (i=0;i<mapsize;i++) {
+ for (i = 0; i < mapsize; i++) {
ctx->Pixel.MapBtoB[i] = CLAMP( values[i], 0.0F, 1.0F );
}
break;
case GL_PIXEL_MAP_A_TO_A:
ctx->Pixel.MapAtoAsize = mapsize;
- for (i=0;i<mapsize;i++) {
+ for (i = 0; i < mapsize; i++) {
ctx->Pixel.MapAtoA[i] = CLAMP( values[i], 0.0F, 1.0F );
}
break;
default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glPixelMapfv(map)" );
+ _mesa_error( ctx, GL_INVALID_ENUM, "glPixelMap(map)" );
}
}
+void GLAPIENTRY
+_mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
-void
-_mesa_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values )
+ /* 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_bitcount((GLuint) mapsize) != 1) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
+ return;
+ }
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ /* unpack pixelmap from PBO */
+ GLubyte *buf;
+ /* Note, need to use DefaultPacking and Unpack's buffer object */
+ ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj;
+ if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ GL_INTENSITY, GL_FLOAT, values)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapfv(invalid PBO access)");
+ return;
+ }
+ /* restore */
+ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+ buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ GL_READ_ONLY_ARB,
+ ctx->Unpack.BufferObj);
+ if (!buf) {
+ /* buffer is already mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapfv(PBO is mapped)");
+ return;
+ }
+ values = (const GLfloat *) ADD_POINTERS(buf, values);
+ }
+ else if (!values) {
+ return;
+ }
+
+ pixelmap(ctx, map, mapsize, values);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ ctx->Unpack.BufferObj);
+ }
+}
+
+
+
+void GLAPIENTRY
+_mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
{
- const GLint n = MIN2(mapsize, MAX_PIXEL_MAP_TABLE);
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<n;i++) {
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ 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) {
+ /* test that mapsize is a power of two */
+ if (_mesa_bitcount((GLuint) mapsize) != 1) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
+ return;
+ }
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ /* unpack pixelmap from PBO */
+ GLubyte *buf;
+ /* Note, need to use DefaultPacking and Unpack's buffer object */
+ ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj;
+ if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ GL_INTENSITY, GL_UNSIGNED_INT, values)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapuiv(invalid PBO access)");
+ return;
+ }
+ /* restore */
+ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+ buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ GL_READ_ONLY_ARB,
+ ctx->Unpack.BufferObj);
+ if (!buf) {
+ /* buffer is already mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapuiv(PBO is mapped)");
+ return;
+ }
+ values = (const GLuint *) ADD_POINTERS(buf, values);
+ }
+ else if (!values) {
+ 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<n;i++) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
fvalues[i] = UINT_TO_FLOAT( values[i] );
}
}
- _mesa_PixelMapfv(map, mapsize, fvalues);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ ctx->Unpack.BufferObj);
+ }
+
+ pixelmap(ctx, map, mapsize, fvalues);
}
-void
-_mesa_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values )
+void GLAPIENTRY
+_mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
{
- const GLint n = MIN2(mapsize, MAX_PIXEL_MAP_TABLE);
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<n;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_bitcount((GLuint) mapsize) != 1) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
+ return;
+ }
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ /* unpack pixelmap from PBO */
+ GLubyte *buf;
+ /* Note, need to use DefaultPacking and Unpack's buffer object */
+ ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj;
+ if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ GL_INTENSITY, GL_UNSIGNED_SHORT,
+ values)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapusv(invalid PBO access)");
+ return;
+ }
+ /* restore */
+ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+ buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ GL_READ_ONLY_ARB,
+ ctx->Unpack.BufferObj);
+ if (!buf) {
+ /* buffer is already mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapusv(PBO is mapped)");
+ return;
+ }
+ values = (const GLushort *) ADD_POINTERS(buf, values);
+ }
+ else if (!values) {
+ 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<n;i++) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
fvalues[i] = USHORT_TO_FLOAT( values[i] );
}
}
- _mesa_PixelMapfv(map, mapsize, fvalues);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ ctx->Unpack.BufferObj);
+ }
+
+ pixelmap(ctx, map, mapsize, fvalues);
}
+/**
+ * Return size of the named map.
+ */
+static GLuint
+get_map_size(GLcontext *ctx, GLenum map)
+{
+ switch (map) {
+ case GL_PIXEL_MAP_I_TO_I:
+ return ctx->Pixel.MapItoIsize;
+ case GL_PIXEL_MAP_S_TO_S:
+ return ctx->Pixel.MapStoSsize;
+ case GL_PIXEL_MAP_I_TO_R:
+ return ctx->Pixel.MapItoRsize;
+ case GL_PIXEL_MAP_I_TO_G:
+ return ctx->Pixel.MapItoGsize;
+ case GL_PIXEL_MAP_I_TO_B:
+ return ctx->Pixel.MapItoBsize;
+ case GL_PIXEL_MAP_I_TO_A:
+ return ctx->Pixel.MapItoAsize;
+ case GL_PIXEL_MAP_R_TO_R:
+ return ctx->Pixel.MapRtoRsize;
+ case GL_PIXEL_MAP_G_TO_G:
+ return ctx->Pixel.MapGtoGsize;
+ case GL_PIXEL_MAP_B_TO_B:
+ return ctx->Pixel.MapBtoBsize;
+ case GL_PIXEL_MAP_A_TO_A:
+ return ctx->Pixel.MapAtoAsize;
+ default:
+ return 0;
+ }
+}
-void
+
+void GLAPIENTRY
_mesa_GetPixelMapfv( GLenum map, GLfloat *values )
{
GET_CURRENT_CONTEXT(ctx);
- GLint i;
+ GLuint mapsize, i;
ASSERT_OUTSIDE_BEGIN_END(ctx);
+ mapsize = get_map_size(ctx, map);
+
+ if (ctx->Pack.BufferObj->Name) {
+ /* pack pixelmap into PBO */
+ GLubyte *buf;
+ /* Note, need to use DefaultPacking and Pack's buffer object */
+ ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
+ if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ GL_INTENSITY, GL_FLOAT, values)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapfv(invalid PBO access)");
+ return;
+ }
+ /* restore */
+ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+ 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,
+ "glGetPixelMapfv(PBO is mapped)");
+ return;
+ }
+ values = (GLfloat *) ADD_POINTERS(buf, values);
+ }
+ else if (!values) {
+ return;
+ }
+
switch (map) {
case GL_PIXEL_MAP_I_TO_I:
- for (i=0;i<ctx->Pixel.MapItoIsize;i++) {
+ for (i = 0; i < mapsize; i++) {
values[i] = (GLfloat) ctx->Pixel.MapItoI[i];
}
break;
case GL_PIXEL_MAP_S_TO_S:
- for (i=0;i<ctx->Pixel.MapStoSsize;i++) {
+ for (i = 0; i < mapsize; 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));
+ MEMCPY(values, ctx->Pixel.MapItoR, mapsize * sizeof(GLfloat));
break;
case GL_PIXEL_MAP_I_TO_G:
- MEMCPY(values,ctx->Pixel.MapItoG,ctx->Pixel.MapItoGsize*sizeof(GLfloat));
+ MEMCPY(values, ctx->Pixel.MapItoG, mapsize * sizeof(GLfloat));
break;
case GL_PIXEL_MAP_I_TO_B:
- MEMCPY(values,ctx->Pixel.MapItoB,ctx->Pixel.MapItoBsize*sizeof(GLfloat));
+ MEMCPY(values, ctx->Pixel.MapItoB, mapsize * sizeof(GLfloat));
break;
case GL_PIXEL_MAP_I_TO_A:
- MEMCPY(values,ctx->Pixel.MapItoA,ctx->Pixel.MapItoAsize*sizeof(GLfloat));
+ MEMCPY(values, ctx->Pixel.MapItoA, mapsize * sizeof(GLfloat));
break;
case GL_PIXEL_MAP_R_TO_R:
- MEMCPY(values,ctx->Pixel.MapRtoR,ctx->Pixel.MapRtoRsize*sizeof(GLfloat));
+ MEMCPY(values, ctx->Pixel.MapRtoR, mapsize * sizeof(GLfloat));
break;
case GL_PIXEL_MAP_G_TO_G:
- MEMCPY(values,ctx->Pixel.MapGtoG,ctx->Pixel.MapGtoGsize*sizeof(GLfloat));
+ MEMCPY(values, ctx->Pixel.MapGtoG, mapsize * sizeof(GLfloat));
break;
case GL_PIXEL_MAP_B_TO_B:
- MEMCPY(values,ctx->Pixel.MapBtoB,ctx->Pixel.MapBtoBsize*sizeof(GLfloat));
+ MEMCPY(values, ctx->Pixel.MapBtoB, mapsize * sizeof(GLfloat));
break;
case GL_PIXEL_MAP_A_TO_A:
- MEMCPY(values,ctx->Pixel.MapAtoA,ctx->Pixel.MapAtoAsize*sizeof(GLfloat));
+ MEMCPY(values, ctx->Pixel.MapAtoA, mapsize * sizeof(GLfloat));
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
}
+
+ if (ctx->Pack.BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+ ctx->Pack.BufferObj);
+ }
}
-void
+void GLAPIENTRY
_mesa_GetPixelMapuiv( GLenum map, GLuint *values )
{
GET_CURRENT_CONTEXT(ctx);
- GLint i;
+ GLint mapsize, i;
ASSERT_OUTSIDE_BEGIN_END(ctx);
+ mapsize = get_map_size(ctx, map);
+
+ if (ctx->Pack.BufferObj->Name) {
+ /* pack pixelmap into PBO */
+ GLubyte *buf;
+ /* Note, need to use DefaultPacking and Pack's buffer object */
+ ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
+ if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ GL_INTENSITY, GL_UNSIGNED_INT, values)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapuiv(invalid PBO access)");
+ return;
+ }
+ /* restore */
+ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+ 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,
+ "glGetPixelMapuiv(PBO is mapped)");
+ return;
+ }
+ values = (GLuint *) ADD_POINTERS(buf, values);
+ }
+ else if (!values) {
+ return;
+ }
+
switch (map) {
case GL_PIXEL_MAP_I_TO_I:
- MEMCPY(values, ctx->Pixel.MapItoI, ctx->Pixel.MapItoIsize*sizeof(GLint));
+ MEMCPY(values, ctx->Pixel.MapItoI, mapsize * sizeof(GLint));
break;
case GL_PIXEL_MAP_S_TO_S:
- MEMCPY(values, ctx->Pixel.MapStoS, ctx->Pixel.MapStoSsize*sizeof(GLint));
+ MEMCPY(values, ctx->Pixel.MapStoS, mapsize * sizeof(GLint));
break;
case GL_PIXEL_MAP_I_TO_R:
- for (i=0;i<ctx->Pixel.MapItoRsize;i++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; i++) {
values[i] = FLOAT_TO_UINT( ctx->Pixel.MapAtoA[i] );
}
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
}
+
+ if (ctx->Pack.BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+ ctx->Pack.BufferObj);
+ }
}
-void
+void GLAPIENTRY
_mesa_GetPixelMapusv( GLenum map, GLushort *values )
{
GET_CURRENT_CONTEXT(ctx);
- GLint i;
+ GLint mapsize, i;
ASSERT_OUTSIDE_BEGIN_END(ctx);
+ mapsize = get_map_size(ctx, map);
+
+ if (ctx->Pack.BufferObj->Name) {
+ /* pack pixelmap into PBO */
+ GLubyte *buf;
+ /* Note, need to use DefaultPacking and Pack's buffer object */
+ ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
+ if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ GL_INTENSITY, GL_UNSIGNED_SHORT,
+ values)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapusv(invalid PBO access)");
+ return;
+ }
+ /* restore */
+ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+ 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,
+ "glGetPixelMapusv(PBO is mapped)");
+ return;
+ }
+ values = (GLushort *) ADD_POINTERS(buf, values);
+ }
+ else if (!values) {
+ return;
+ }
+
switch (map) {
case GL_PIXEL_MAP_I_TO_I:
- for (i=0;i<ctx->Pixel.MapItoIsize;i++) {
+ for (i = 0; i < mapsize; i++) {
values[i] = (GLushort) ctx->Pixel.MapItoI[i];
}
break;
case GL_PIXEL_MAP_S_TO_S:
- for (i=0;i<ctx->Pixel.MapStoSsize;i++) {
+ for (i = 0; i < mapsize; i++) {
values[i] = (GLushort) ctx->Pixel.MapStoS[i];
}
break;
case GL_PIXEL_MAP_I_TO_R:
- for (i=0;i<ctx->Pixel.MapItoRsize;i++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; 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++) {
+ for (i = 0; i < mapsize; i++) {
values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapAtoA[i] );
}
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
}
+
+ if (ctx->Pack.BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+ ctx->Pack.BufferObj);
+ }
}
* Implements glPixelTransfer[fi] whether called immediately or from a
* display list.
*/
-void
+void GLAPIENTRY
_mesa_PixelTransferf( GLenum pname, GLfloat param )
{
GET_CURRENT_CONTEXT(ctx);
}
-void
+void GLAPIENTRY
_mesa_PixelTransferi( GLenum pname, GLint param )
{
_mesa_PixelTransferf( pname, (GLfloat) param );
}
+
+
/**********************************************************************/
/***** Pixel processing functions ******/
/**********************************************************************/
-
/*
* Apply scale and bias factors to an array of RGBA pixels.
*/
void
-_mesa_scale_and_bias_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4],
+_mesa_scale_and_bias_rgba(GLuint n, GLfloat rgba[][4],
GLfloat rScale, GLfloat gScale,
GLfloat bScale, GLfloat aScale,
GLfloat rBias, GLfloat gBias,
}
-/*
- * Apply a color table lookup to an array of colors.
+/**
+ * Apply a color table lookup to an array of floating point RGBA colors.
*/
void
-_mesa_lookup_rgba(const struct gl_color_table *table,
- GLuint n, GLfloat rgba[][4])
+_mesa_lookup_rgba_float(const struct gl_color_table *table,
+ GLuint n, GLfloat rgba[][4])
{
if (!table->Table || table->Size == 0)
return;
switch (table->Format) {
case GL_INTENSITY:
/* replace RGBA with I */
- if (!table->FloatTable) {
+ if (table->Type == GL_FLOAT) {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLchan *lut = (const GLchan *) table->Table;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
+ GLfloat c = lut[CLAMP(j, 0, max)];
rgba[i][RCOMP] = rgba[i][GCOMP] =
rgba[i][BCOMP] = rgba[i][ACOMP] = c;
}
else {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLfloat *lut = (const GLfloat *) table->Table;
+ const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = lut[CLAMP(j, 0, max)];
+ GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
rgba[i][RCOMP] = rgba[i][GCOMP] =
rgba[i][BCOMP] = rgba[i][ACOMP] = c;
}
break;
case GL_LUMINANCE:
/* replace RGB with L */
- if (!table->FloatTable) {
+ if (table->Type == GL_FLOAT) {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLchan *lut = (const GLchan *) table->Table;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
+ GLfloat c = lut[CLAMP(j, 0, max)];
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
}
}
else {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLfloat *lut = (const GLfloat *) table->Table;
+ const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][RCOMP] * scale);
- GLfloat c = lut[CLAMP(j, 0, max)];
+ GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
}
}
break;
case GL_ALPHA:
/* replace A with A */
- if (!table->FloatTable) {
+ if (table->Type == GL_FLOAT) {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLchan *lut = (const GLchan *) table->Table;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][ACOMP] * scale);
- rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
+ rgba[i][ACOMP] = lut[CLAMP(j, 0, max)];
}
}
- else {
+ else {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLfloat *lut = (const GLfloat *) table->Table;
+ const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint j = IROUND(rgba[i][ACOMP] * scale);
- rgba[i][ACOMP] = lut[CLAMP(j, 0, max)];
+ rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
}
}
break;
case GL_LUMINANCE_ALPHA:
/* replace RGBA with LLLA */
- if (!table->FloatTable) {
+ if (table->Type == GL_FLOAT) {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLchan *lut = (const GLchan *) table->Table;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jL = IROUND(rgba[i][RCOMP] * scale);
GLfloat luminance, alpha;
jL = CLAMP(jL, 0, max);
jA = CLAMP(jA, 0, max);
- luminance = CHAN_TO_FLOAT(lut[jL * 2 + 0]);
- alpha = CHAN_TO_FLOAT(lut[jA * 2 + 1]);
+ luminance = lut[jL * 2 + 0];
+ alpha = lut[jA * 2 + 1];
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
rgba[i][ACOMP] = alpha;;
}
else {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLfloat *lut = (const GLfloat *) table->Table;
+ const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jL = IROUND(rgba[i][RCOMP] * scale);
GLfloat luminance, alpha;
jL = CLAMP(jL, 0, max);
jA = CLAMP(jA, 0, max);
- luminance = lut[jL * 2 + 0];
- alpha = lut[jA * 2 + 1];
+ luminance = CHAN_TO_FLOAT(lut[jL * 2 + 0]);
+ alpha = CHAN_TO_FLOAT(lut[jA * 2 + 1]);
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
rgba[i][ACOMP] = alpha;;
}
break;
case GL_RGB:
/* replace RGB with RGB */
- if (!table->FloatTable) {
+ if (table->Type == GL_FLOAT) {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLchan *lut = (const GLchan *) table->Table;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jR = IROUND(rgba[i][RCOMP] * scale);
jR = CLAMP(jR, 0, max);
jG = CLAMP(jG, 0, max);
jB = CLAMP(jB, 0, max);
- rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 3 + 0]);
- rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 3 + 1]);
- rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 3 + 2]);
+ rgba[i][RCOMP] = lut[jR * 3 + 0];
+ rgba[i][GCOMP] = lut[jG * 3 + 1];
+ rgba[i][BCOMP] = lut[jB * 3 + 2];
}
}
else {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLfloat *lut = (const GLfloat *) table->Table;
+ const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jR = IROUND(rgba[i][RCOMP] * scale);
jR = CLAMP(jR, 0, max);
jG = CLAMP(jG, 0, max);
jB = CLAMP(jB, 0, max);
- rgba[i][RCOMP] = lut[jR * 3 + 0];
- rgba[i][GCOMP] = lut[jG * 3 + 1];
- rgba[i][BCOMP] = lut[jB * 3 + 2];
+ rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 3 + 0]);
+ rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 3 + 1]);
+ rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 3 + 2]);
}
}
break;
case GL_RGBA:
/* replace RGBA with RGBA */
- if (!table->FloatTable) {
+ if (table->Type == GL_FLOAT) {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLchan *lut = (const GLchan *) table->Table;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jR = IROUND(rgba[i][RCOMP] * scale);
jG = CLAMP(jG, 0, max);
jB = CLAMP(jB, 0, max);
jA = CLAMP(jA, 0, max);
- rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 4 + 0]);
- rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 4 + 1]);
- rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 4 + 2]);
- rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[jA * 4 + 3]);
+ rgba[i][RCOMP] = lut[jR * 4 + 0];
+ rgba[i][GCOMP] = lut[jG * 4 + 1];
+ rgba[i][BCOMP] = lut[jB * 4 + 2];
+ rgba[i][ACOMP] = lut[jA * 4 + 3];
}
}
else {
const GLint max = table->Size - 1;
const GLfloat scale = (GLfloat) max;
- const GLfloat *lut = (const GLfloat *) table->Table;
+ const GLchan *lut = (const GLchan *) table->Table;
GLuint i;
for (i = 0; i < n; i++) {
GLint jR = IROUND(rgba[i][RCOMP] * scale);
jG = CLAMP(jG, 0, max);
jB = CLAMP(jB, 0, max);
jA = CLAMP(jA, 0, max);
- rgba[i][RCOMP] = lut[jR * 4 + 0];
- rgba[i][GCOMP] = lut[jG * 4 + 1];
- rgba[i][BCOMP] = lut[jB * 4 + 2];
- rgba[i][ACOMP] = lut[jA * 4 + 3];
+ rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 4 + 0]);
+ rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 4 + 1]);
+ rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 4 + 2]);
+ rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[jA * 4 + 3]);
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "Bad format in _mesa_lookup_rgba_float");
+ return;
+ }
+}
+
+
+
+/**
+ * Apply a color table lookup to an array of GLchan RGBA colors.
+ */
+void
+_mesa_lookup_rgba_chan(const struct gl_color_table *table,
+ GLuint n, GLchan rgba[][4])
+{
+ if (!table->Table || table->Size == 0)
+ return;
+
+ switch (table->Format) {
+ case GL_INTENSITY:
+ /* replace RGBA with I */
+ if (table->Type == GL_FLOAT) {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLchan c;
+ CLAMPED_FLOAT_TO_CHAN(c, lut[j]);
+ rgba[i][RCOMP] = rgba[i][GCOMP] =
+ rgba[i][BCOMP] = rgba[i][ACOMP] = c;
+ }
+ }
+ else {
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ if (table->Size == 256) {
+ /* common case */
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ const GLchan c = lut[rgba[i][RCOMP]];
+ rgba[i][RCOMP] = rgba[i][GCOMP] =
+ rgba[i][BCOMP] = rgba[i][ACOMP] = c;
+ }
+ }
+ else
+#endif
+ {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ rgba[i][RCOMP] = rgba[i][GCOMP] =
+ rgba[i][BCOMP] = rgba[i][ACOMP] = lut[j];
+ }
+ }
+ }
+ break;
+ case GL_LUMINANCE:
+ /* replace RGB with L */
+ if (table->Type == GL_FLOAT) {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLchan c;
+ CLAMPED_FLOAT_TO_CHAN(c, lut[j]);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
+ }
+ }
+ else {
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ if (table->Size == 256) {
+ /* common case */
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ const GLchan c = lut[rgba[i][RCOMP]];
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
+ }
+ }
+ else
+#endif
+ {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = lut[j];
+ }
+ }
+ }
+ break;
+ case GL_ALPHA:
+ /* replace A with A */
+ if (table->Type == GL_FLOAT) {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = IROUND((GLfloat) rgba[i][ACOMP] * scale);
+ GLchan c;
+ CLAMPED_FLOAT_TO_CHAN(c, lut[j]);
+ rgba[i][ACOMP] = c;
+ }
+ }
+ else {
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ if (table->Size == 256) {
+ /* common case */
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = lut[rgba[i][ACOMP]];
+ }
+ }
+ else
+#endif
+ {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = IROUND((GLfloat) rgba[i][ACOMP] * scale);
+ rgba[i][ACOMP] = lut[j];
+ }
+ }
+ }
+ break;
+ case GL_LUMINANCE_ALPHA:
+ /* replace RGBA with LLLA */
+ if (table->Type == GL_FLOAT) {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jL = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale);
+ GLchan luminance, alpha;
+ CLAMPED_FLOAT_TO_CHAN(luminance, lut[jL * 2 + 0]);
+ CLAMPED_FLOAT_TO_CHAN(alpha, lut[jA * 2 + 1]);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
+ rgba[i][ACOMP] = alpha;;
+ }
+ }
+ else {
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ if (table->Size == 256) {
+ /* common case */
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLchan l = lut[rgba[i][RCOMP] * 2 + 0];
+ GLchan a = lut[rgba[i][ACOMP] * 2 + 1];;
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = l;
+ rgba[i][ACOMP] = a;
+ }
+ }
+ else
+#endif
+ {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jL = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale);
+ GLchan luminance = lut[jL * 2 + 0];
+ GLchan alpha = lut[jA * 2 + 1];
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
+ rgba[i][ACOMP] = alpha;
+ }
+ }
+ }
+ break;
+ case GL_RGB:
+ /* replace RGB with RGB */
+ if (table->Type == GL_FLOAT) {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale);
+ GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], lut[jR * 3 + 0]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], lut[jG * 3 + 1]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], lut[jB * 3 + 2]);
+ }
+ }
+ else {
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ if (table->Size == 256) {
+ /* common case */
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = lut[rgba[i][RCOMP] * 3 + 0];
+ rgba[i][GCOMP] = lut[rgba[i][GCOMP] * 3 + 1];
+ rgba[i][BCOMP] = lut[rgba[i][BCOMP] * 3 + 2];
+ }
+ }
+ else
+#endif
+ {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale);
+ GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale);
+ rgba[i][RCOMP] = lut[jR * 3 + 0];
+ rgba[i][GCOMP] = lut[jG * 3 + 1];
+ rgba[i][BCOMP] = lut[jB * 3 + 2];
+ }
+ }
+ }
+ break;
+ case GL_RGBA:
+ /* replace RGBA with RGBA */
+ if (table->Type == GL_FLOAT) {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale);
+ GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale);
+ GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], lut[jR * 4 + 0]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], lut[jG * 4 + 1]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], lut[jB * 4 + 2]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][ACOMP], lut[jA * 4 + 3]);
+ }
+ }
+ else {
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ if (table->Size == 256) {
+ /* common case */
+ const GLchan *lut = (const GLchan *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = lut[rgba[i][RCOMP] * 4 + 0];
+ rgba[i][GCOMP] = lut[rgba[i][GCOMP] * 4 + 1];
+ rgba[i][BCOMP] = lut[rgba[i][BCOMP] * 4 + 2];
+ rgba[i][ACOMP] = lut[rgba[i][ACOMP] * 4 + 3];
+ }
+ }
+ else
+#endif
+ {
+ const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale);
+ GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale);
+ GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale);
+ GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], lut[jR * 4 + 0]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], lut[jG * 4 + 1]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], lut[jB * 4 + 2]);
+ CLAMPED_FLOAT_TO_CHAN(rgba[i][ACOMP], lut[jA * 4 + 3]);
+ }
}
}
break;
default:
- _mesa_problem(NULL, "Bad format in _mesa_lookup_rgba");
+ _mesa_problem(NULL, "Bad format in _mesa_lookup_rgba_chan");
return;
}
}
/***** Initialization *****/
/**********************************************************************/
-void _mesa_init_pixel( GLcontext * ctx )
+
+/**
+ * Initialize the context's PIXEL attribute group.
+ */
+void
+_mesa_init_pixel( GLcontext *ctx )
{
int i;
ctx->Pack.LsbFirst = GL_FALSE;
ctx->Pack.ClientStorage = GL_FALSE;
ctx->Pack.Invert = GL_FALSE;
+#if FEATURE_EXT_pixel_buffer_object
+ ctx->Pack.BufferObj = ctx->Array.NullBufferObj;
+#endif
ctx->Unpack.Alignment = 4;
ctx->Unpack.RowLength = 0;
ctx->Unpack.ImageHeight = 0;
ctx->Unpack.LsbFirst = GL_FALSE;
ctx->Unpack.ClientStorage = GL_FALSE;
ctx->Unpack.Invert = GL_FALSE;
+#if FEATURE_EXT_pixel_buffer_object
+ ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+#endif
+
+ /*
+ * _mesa_unpack_image() returns image data in this format. When we
+ * execute image commands (glDrawPixels(), glTexImage(), etc) from
+ * within display lists we have to be sure to set the current
+ * unpacking parameters to these values!
+ */
+ ctx->DefaultPacking.Alignment = 1;
+ ctx->DefaultPacking.RowLength = 0;
+ ctx->DefaultPacking.SkipPixels = 0;
+ ctx->DefaultPacking.SkipRows = 0;
+ ctx->DefaultPacking.ImageHeight = 0;
+ ctx->DefaultPacking.SkipImages = 0;
+ ctx->DefaultPacking.SwapBytes = GL_FALSE;
+ ctx->DefaultPacking.LsbFirst = GL_FALSE;
+ ctx->DefaultPacking.ClientStorage = GL_FALSE;
+ ctx->DefaultPacking.Invert = GL_FALSE;
+#if FEATURE_EXT_pixel_buffer_object
+ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
+#endif
if (ctx->Visual.doubleBufferMode) {
ctx->Pixel.ReadBuffer = GL_BACK;
- ctx->Pixel._ReadSrcMask = BACK_LEFT_BIT;
}
else {
ctx->Pixel.ReadBuffer = GL_FRONT;
- ctx->Pixel._ReadSrcMask = FRONT_LEFT_BIT;
}
/* Miscellaneous */