diff options
author | marha <marha@users.sourceforge.net> | 2011-11-17 16:37:26 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-11-17 16:37:26 +0100 |
commit | d41bc08d1ae8c4784c09d8977816c0fadab1ba52 (patch) | |
tree | 4dc3081a9af0316eeee02356a44fcc2419e1b15e /mesalib/src/mesa/main | |
parent | 156e37d3879b316329e3e05579414031da2647e2 (diff) | |
download | vcxsrv-d41bc08d1ae8c4784c09d8977816c0fadab1ba52.tar.gz vcxsrv-d41bc08d1ae8c4784c09d8977816c0fadab1ba52.tar.bz2 vcxsrv-d41bc08d1ae8c4784c09d8977816c0fadab1ba52.zip |
xserver mesa git update 17 nov 2011
Diffstat (limited to 'mesalib/src/mesa/main')
-rw-r--r-- | mesalib/src/mesa/main/ffvertex_prog.c | 113 | ||||
-rw-r--r-- | mesalib/src/mesa/main/format_unpack.c | 1530 | ||||
-rw-r--r-- | mesalib/src/mesa/main/image.c | 71 | ||||
-rw-r--r-- | mesalib/src/mesa/main/light.c | 2863 | ||||
-rw-r--r-- | mesalib/src/mesa/main/macros.h | 37 | ||||
-rw-r--r-- | mesalib/src/mesa/main/mtypes.h | 22 | ||||
-rw-r--r-- | mesalib/src/mesa/main/pack.c | 64 | ||||
-rw-r--r-- | mesalib/src/mesa/main/pack.h | 4 | ||||
-rw-r--r-- | mesalib/src/mesa/main/pixeltransfer.c | 4 | ||||
-rw-r--r-- | mesalib/src/mesa/main/pixeltransfer.h | 2 | ||||
-rw-r--r-- | mesalib/src/mesa/main/readpix.c | 496 | ||||
-rw-r--r-- | mesalib/src/mesa/main/readpix.h | 9 | ||||
-rw-r--r-- | mesalib/src/mesa/main/renderbuffer.c | 367 | ||||
-rw-r--r-- | mesalib/src/mesa/main/renderbuffer.h | 9 | ||||
-rw-r--r-- | mesalib/src/mesa/main/uniform_query.cpp | 22 |
15 files changed, 2975 insertions, 2638 deletions
diff --git a/mesalib/src/mesa/main/ffvertex_prog.c b/mesalib/src/mesa/main/ffvertex_prog.c index 846907842..2c937386a 100644 --- a/mesalib/src/mesa/main/ffvertex_prog.c +++ b/mesalib/src/mesa/main/ffvertex_prog.c @@ -949,7 +949,7 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p, { struct ureg attenuation = register_param3(p, STATE_LIGHT, i, STATE_ATTENUATION); - struct ureg att = get_temp(p); + struct ureg att = undef; /* Calculate spot attenuation: */ @@ -959,6 +959,8 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p, struct ureg spot = get_temp(p); struct ureg slt = get_temp(p); + att = get_temp(p); + emit_op2(p, OPCODE_DP3, spot, 0, negate(VPpli), spot_dir_norm); emit_op2(p, OPCODE_SLT, slt, 0, swizzle1(spot_dir_norm,W), spot); emit_op2(p, OPCODE_POW, spot, 0, spot, swizzle1(attenuation, W)); @@ -968,9 +970,13 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p, release_temp(p, slt); } - /* Calculate distance attenuation: + /* Calculate distance attenuation(See formula (2.4) at glspec 2.1 page 62): + * + * Skip the calucation when _dist_ is undefined(light_eyepos3_is_zero) */ - if (p->state->unit[i].light_attenuated) { + if (p->state->unit[i].light_attenuated && !is_undef(dist)) { + if (is_undef(att)) + att = get_temp(p); /* 1/d,d,d,1/d */ emit_op1(p, OPCODE_RCP, dist, WRITEMASK_YZ, dist); /* 1,d,d*d,1/d */ @@ -1113,73 +1119,54 @@ static void build_lighting( struct tnl_program *p ) if (p->state->unit[i].light_enabled) { struct ureg half = undef; struct ureg att = undef, VPpli = undef; + struct ureg dist = undef; count++; + if (p->state->unit[i].light_eyepos3_is_zero) { + VPpli = register_param3(p, STATE_INTERNAL, + STATE_LIGHT_POSITION_NORMALIZED, i); + } else { + struct ureg Ppli = register_param3(p, STATE_INTERNAL, + STATE_LIGHT_POSITION, i); + struct ureg V = get_eye_position(p); + + VPpli = get_temp(p); + dist = get_temp(p); + + /* Calculate VPpli vector + */ + emit_op2(p, OPCODE_SUB, VPpli, 0, Ppli, V); - if (p->state->unit[i].light_eyepos3_is_zero) { - /* Can used precomputed constants in this case. - * Attenuation never applies to infinite lights. - */ - VPpli = register_param3(p, STATE_INTERNAL, - STATE_LIGHT_POSITION_NORMALIZED, i); - - if (!p->state->material_shininess_is_zero) { - if (p->state->light_local_viewer) { - struct ureg eye_hat = get_eye_position_normalized(p); - half = get_temp(p); - emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat); - emit_normalize_vec3(p, half, half); - } - else { - half = register_param3(p, STATE_INTERNAL, - STATE_LIGHT_HALF_VECTOR, i); - } - } - } - else { - struct ureg Ppli = register_param3(p, STATE_INTERNAL, - STATE_LIGHT_POSITION, i); - struct ureg V = get_eye_position(p); - struct ureg dist = get_temp(p); - - VPpli = get_temp(p); - - /* Calculate VPpli vector - */ - emit_op2(p, OPCODE_SUB, VPpli, 0, Ppli, V); - - /* Normalize VPpli. The dist value also used in - * attenuation below. - */ - emit_op2(p, OPCODE_DP3, dist, 0, VPpli, VPpli); - emit_op1(p, OPCODE_RSQ, dist, 0, dist); - emit_op2(p, OPCODE_MUL, VPpli, 0, VPpli, dist); - - /* Calculate attenuation: - */ - if (!p->state->unit[i].light_spotcutoff_is_180 || - p->state->unit[i].light_attenuated) { - att = calculate_light_attenuation(p, i, VPpli, dist); - } - - /* Calculate viewer direction, or use infinite viewer: - */ - if (!p->state->material_shininess_is_zero) { - half = get_temp(p); + /* Normalize VPpli. The dist value also used in + * attenuation below. + */ + emit_op2(p, OPCODE_DP3, dist, 0, VPpli, VPpli); + emit_op1(p, OPCODE_RSQ, dist, 0, dist); + emit_op2(p, OPCODE_MUL, VPpli, 0, VPpli, dist); + } - if (p->state->light_local_viewer) { - struct ureg eye_hat = get_eye_position_normalized(p); - emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat); - } - else { - struct ureg z_dir = swizzle(get_identity_param(p),X,Y,W,Z); - emit_op2(p, OPCODE_ADD, half, 0, VPpli, z_dir); - } + /* Calculate attenuation: + */ + att = calculate_light_attenuation(p, i, VPpli, dist); + release_temp(p, dist); + /* Calculate viewer direction, or use infinite viewer: + */ + if (!p->state->material_shininess_is_zero) { + if (p->state->light_local_viewer) { + struct ureg eye_hat = get_eye_position_normalized(p); + half = get_temp(p); + emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat); + emit_normalize_vec3(p, half, half); + } else if (p->state->unit[i].light_eyepos3_is_zero) { + half = register_param3(p, STATE_INTERNAL, + STATE_LIGHT_HALF_VECTOR, i); + } else { + struct ureg z_dir = swizzle(get_identity_param(p),X,Y,W,Z); + half = get_temp(p); + emit_op2(p, OPCODE_ADD, half, 0, VPpli, z_dir); emit_normalize_vec3(p, half, half); } - - release_temp(p, dist); } /* Calculate dot products: diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c index 525bbcb1c..6e2ce7a05 100644 --- a/mesalib/src/mesa/main/format_unpack.c +++ b/mesalib/src/mesa/main/format_unpack.c @@ -57,1049 +57,1335 @@ nonlinear_to_linear(GLubyte cs8) } -typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[4]); +typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n); static void -unpack_RGBA8888(const void *src, GLfloat dst[4]) +unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) ); - dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); - dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); - dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff ); + } } static void -unpack_RGBA8888_REV(const void *src, GLfloat dst[4]) +unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); - dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); - dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); - dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) ); + } } static void -unpack_ARGB8888(const void *src, GLfloat dst[4]) +unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); - dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); - dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); - dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) ); + } } static void -unpack_ARGB8888_REV(const void *src, GLfloat dst[4]) +unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); - dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); - dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) ); - dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff ); + } } static void -unpack_XRGB8888(const void *src, GLfloat dst[4]) +unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); - dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); - dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); - dst[ACOMP] = 1.0f; + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff ); + dst[i][ACOMP] = 1.0f; + } } static void -unpack_XRGB8888_REV(const void *src, GLfloat dst[4]) +unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff ); - dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff ); - dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) ); - dst[ACOMP] = 1.0f; + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) ); + dst[i][ACOMP] = 1.0f; + } } static void -unpack_RGB888(const void *src, GLfloat dst[4]) +unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n) { const GLubyte *s = (const GLubyte *) src; - dst[RCOMP] = UBYTE_TO_FLOAT( s[2] ); - dst[GCOMP] = UBYTE_TO_FLOAT( s[1] ); - dst[BCOMP] = UBYTE_TO_FLOAT( s[0] ); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] ); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_BGR888(const void *src, GLfloat dst[4]) +unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n) { const GLubyte *s = (const GLubyte *) src; - dst[RCOMP] = UBYTE_TO_FLOAT( s[0] ); - dst[GCOMP] = UBYTE_TO_FLOAT( s[1] ); - dst[BCOMP] = UBYTE_TO_FLOAT( s[2] ); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] ); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_RGB565(const void *src, GLfloat dst[4]) +unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F); - dst[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F); - dst[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F); - dst[ACOMP] = 1.0F; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F); + dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F); + dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_RGB565_REV(const void *src, GLfloat dst[4]) +unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n) { - GLushort s = *((const GLushort *) src); - s = (s >> 8) | (s << 8); /* byte swap */ - dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) ); - dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) ); - dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) ); - dst[ACOMP] = 1.0F; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */ + dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) ); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_ARGB4444(const void *src, GLfloat dst[4]) +unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F); - dst[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F); - dst[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F); - dst[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F); + dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F); + dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F); + dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F); + } } static void -unpack_ARGB4444_REV(const void *src, GLfloat dst[4]) +unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F); - dst[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F); - dst[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F); - dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F); + dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F); + dst[i][BCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F); + dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F); + } } static void -unpack_RGBA5551(const void *src, GLfloat dst[4]) +unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F); - dst[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F); - dst[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F); - dst[ACOMP] = ((s ) & 0x01) * 1.0F; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F); + dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F); + dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F); + dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F; + } } static void -unpack_ARGB1555(const void *src, GLfloat dst[4]) +unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F); - dst[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F); - dst[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F); - dst[ACOMP] = ((s >> 15) & 0x01) * 1.0F; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F); + dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F); + dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F); + dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F; + } } static void -unpack_ARGB1555_REV(const void *src, GLfloat dst[4]) +unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) ); - dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) ); - dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) ); - dst[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 ); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( ((s[i] >> 7) & 0xf8) | ((s[i] >> 12) & 0x7) ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( ((s[i] >> 2) & 0xf8) | ((s[i] >> 7) & 0x7) ); + dst[i][BCOMP] = UBYTE_TO_FLOAT( ((s[i] << 3) & 0xf8) | ((s[i] >> 2) & 0x7) ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( ((s[i] >> 15) & 0x01) * 255 ); + } } static void -unpack_AL44(const void *src, GLfloat dst[4]) +unpack_AL44(const void *src, GLfloat dst[][4], GLuint n) { - const GLubyte s = *((const GLubyte *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = (s & 0xf) * (1.0F / 15.0F); - dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F); + const GLubyte *s = ((const GLubyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F); + dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F); + } } static void -unpack_AL88(const void *src, GLfloat dst[4]) +unpack_AL88(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = UBYTE_TO_FLOAT( s & 0xff ); - dst[ACOMP] = UBYTE_TO_FLOAT( s >> 8 ); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 ); + } } static void -unpack_AL88_REV(const void *src, GLfloat dst[4]) +unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = UBYTE_TO_FLOAT( s >> 8 ); - dst[ACOMP] = UBYTE_TO_FLOAT( s & 0xff ); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); + } } static void -unpack_AL1616(const void *src, GLfloat dst[4]) +unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = USHORT_TO_FLOAT( s & 0xffff ); - dst[ACOMP] = USHORT_TO_FLOAT( s >> 16 ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff ); + dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 ); + } } static void -unpack_AL1616_REV(const void *src, GLfloat dst[4]) +unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = USHORT_TO_FLOAT( s >> 16 ); - dst[ACOMP] = USHORT_TO_FLOAT( s & 0xffff ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 ); + dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff ); + } } static void -unpack_RGB332(const void *src, GLfloat dst[4]) +unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n) { - const GLubyte s = *((const GLubyte *) src); - dst[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F); - dst[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F); - dst[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F); - dst[ACOMP] = 1.0F; + const GLubyte *s = ((const GLubyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F); + dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F); + dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_A8(const void *src, GLfloat dst[4]) +unpack_A8(const void *src, GLfloat dst[][4], GLuint n) { - const GLubyte s = *((const GLubyte *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = 0.0F; - dst[ACOMP] = UBYTE_TO_FLOAT(s); + const GLubyte *s = ((const GLubyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]); + } } static void -unpack_A16(const void *src, GLfloat dst[4]) +unpack_A16(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = 0.0F; - dst[ACOMP] = USHORT_TO_FLOAT(s); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]); + } } static void -unpack_L8(const void *src, GLfloat dst[4]) +unpack_L8(const void *src, GLfloat dst[][4], GLuint n) { - const GLubyte s = *((const GLubyte *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = UBYTE_TO_FLOAT(s); - dst[ACOMP] = 1.0F; + const GLubyte *s = ((const GLubyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_L16(const void *src, GLfloat dst[4]) +unpack_L16(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = USHORT_TO_FLOAT(s); - dst[ACOMP] = 1.0F; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_I8(const void *src, GLfloat dst[4]) +unpack_I8(const void *src, GLfloat dst[][4], GLuint n) { - const GLubyte s = *((const GLubyte *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = - dst[ACOMP] = UBYTE_TO_FLOAT(s); + const GLubyte *s = ((const GLubyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = + dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]); + } } static void -unpack_I16(const void *src, GLfloat dst[4]) +unpack_I16(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = - dst[ACOMP] = USHORT_TO_FLOAT(s); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = + dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]); + } } static void -unpack_YCBCR(const void *src, GLfloat dst[4]) +unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint i = 0; - const GLushort *src0 = (const GLushort *) src; - const GLushort *src1 = src0 + 1; /* odd */ - const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */ - const GLubyte cb = *src0 & 0xff; /* chroma U */ - const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */ - const GLubyte cr = *src1 & 0xff; /* chroma V */ - const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */ - GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128); - GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128); - GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128); - r *= (1.0F / 255.0F); - g *= (1.0F / 255.0F); - b *= (1.0F / 255.0F); - dst[RCOMP] = CLAMP(r, 0.0F, 1.0F); - dst[GCOMP] = CLAMP(g, 0.0F, 1.0F); - dst[BCOMP] = CLAMP(b, 0.0F, 1.0F); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */ + const GLushort *src1 = src0 + 1; /* odd */ + const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */ + const GLubyte cb = *src0 & 0xff; /* chroma U */ + const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */ + const GLubyte cr = *src1 & 0xff; /* chroma V */ + const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */ + GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128); + GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128); + GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128); + r *= (1.0F / 255.0F); + g *= (1.0F / 255.0F); + b *= (1.0F / 255.0F); + dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F); + dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F); + dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_YCBCR_REV(const void *src, GLfloat dst[4]) +unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint i = 0; - const GLushort *src0 = (const GLushort *) src; - const GLushort *src1 = src0 + 1; /* odd */ - const GLubyte y0 = *src0 & 0xff; /* luminance */ - const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */ - const GLubyte y1 = *src1 & 0xff; /* luminance */ - const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */ - const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */ - GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128); - GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128); - GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128); - r *= (1.0F / 255.0F); - g *= (1.0F / 255.0F); - b *= (1.0F / 255.0F); - dst[RCOMP] = CLAMP(r, 0.0F, 1.0F); - dst[GCOMP] = CLAMP(g, 0.0F, 1.0F); - dst[BCOMP] = CLAMP(b, 0.0F, 1.0F); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */ + const GLushort *src1 = src0 + 1; /* odd */ + const GLubyte y0 = *src0 & 0xff; /* luminance */ + const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */ + const GLubyte y1 = *src1 & 0xff; /* luminance */ + const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */ + const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */ + GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128); + GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128); + GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128); + r *= (1.0F / 255.0F); + g *= (1.0F / 255.0F); + b *= (1.0F / 255.0F); + dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F); + dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F); + dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_R8(const void *src, GLfloat dst[4]) +unpack_R8(const void *src, GLfloat dst[][4], GLuint n) { - const GLubyte s = *((const GLubyte *) src); - dst[0] = UBYTE_TO_FLOAT(s); - dst[1] = dst[2] = 0.0F; - dst[3] = 1.0F; + const GLubyte *s = ((const GLubyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = UBYTE_TO_FLOAT(s[i]); + dst[i][1] = + dst[i][2] = 0.0F; + dst[i][3] = 1.0F; + } } static void -unpack_RG88(const void *src, GLfloat dst[4]) +unpack_RG88(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff ); - dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 ); - dst[BCOMP] = 0.0; - dst[ACOMP] = 1.0; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 ); + dst[i][BCOMP] = 0.0; + dst[i][ACOMP] = 1.0; + } } static void -unpack_RG88_REV(const void *src, GLfloat dst[4]) +unpack_RG88_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff ); - dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 ); - dst[BCOMP] = 0.0; - dst[ACOMP] = 1.0; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); + dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 ); + dst[i][BCOMP] = 0.0; + dst[i][ACOMP] = 1.0; + } } static void -unpack_R16(const void *src, GLfloat dst[4]) +unpack_R16(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = USHORT_TO_FLOAT(s); - dst[GCOMP] = 0.0; - dst[BCOMP] = 0.0; - dst[ACOMP] = 1.0; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]); + dst[i][GCOMP] = 0.0; + dst[i][BCOMP] = 0.0; + dst[i][ACOMP] = 1.0; + } } static void -unpack_RG1616(const void *src, GLfloat dst[4]) +unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = USHORT_TO_FLOAT( s & 0xffff ); - dst[GCOMP] = USHORT_TO_FLOAT( s >> 16 ); - dst[BCOMP] = 0.0; - dst[ACOMP] = 1.0; + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff ); + dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 ); + dst[i][BCOMP] = 0.0; + dst[i][ACOMP] = 1.0; + } } static void -unpack_RG1616_REV(const void *src, GLfloat dst[4]) +unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = USHORT_TO_FLOAT( s >> 16 ); - dst[GCOMP] = USHORT_TO_FLOAT( s & 0xffff ); - dst[BCOMP] = 0.0; - dst[ACOMP] = 1.0; + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 ); + dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff ); + dst[i][BCOMP] = 0.0; + dst[i][ACOMP] = 1.0; + } } static void -unpack_ARGB2101010(const void *src, GLfloat dst[4]) +unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F); - dst[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F); - dst[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F); - dst[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F); + dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F); + dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F); + dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F); + } } static void -unpack_Z24_S8(const void *src, GLfloat dst[4]) +unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n) { /* only return Z, not stencil data */ - const GLuint s = *((const GLuint *) src); + const GLuint *s = ((const GLuint *) src); const GLfloat scale = 1.0F / (GLfloat) 0xffffff; - dst[0] = dst[1] = dst[2] = (s >> 8) * scale; - dst[3] = 1.0F; - ASSERT(dst[0] >= 0.0F); - ASSERT(dst[0] <= 1.0F); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = + dst[i][1] = + dst[i][2] = (s[i] >> 8) * scale; + dst[i][3] = 1.0F; + ASSERT(dst[i][0] >= 0.0F); + ASSERT(dst[i][0] <= 1.0F); + } } static void -unpack_S8_Z24(const void *src, GLfloat dst[4]) +unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n) { /* only return Z, not stencil data */ - const GLuint s = *((const GLuint *) src); + const GLuint *s = ((const GLuint *) src); const GLfloat scale = 1.0F / (GLfloat) 0xffffff; - dst[0] = dst[1] = dst[2] = (s & 0x00ffffff) * scale; - dst[3] = 1.0F; - ASSERT(dst[0] >= 0.0F); - ASSERT(dst[0] <= 1.0F); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = + dst[i][1] = + dst[i][2] = (s[i] & 0x00ffffff) * scale; + dst[i][3] = 1.0F; + ASSERT(dst[i][0] >= 0.0F); + ASSERT(dst[i][0] <= 1.0F); + } } static void -unpack_Z16(const void *src, GLfloat dst[4]) +unpack_Z16(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[0] = dst[1] = dst[2] = s * (1.0F / 65535.0F); - dst[3] = 1.0F; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = + dst[i][1] = + dst[i][2] = s[i] * (1.0F / 65535.0F); + dst[i][3] = 1.0F; + } } static void -unpack_X8_Z24(const void *src, GLfloat dst[4]) +unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n) { - unpack_S8_Z24(src, dst); + unpack_S8_Z24(src, dst, n); } static void -unpack_Z24_X8(const void *src, GLfloat dst[4]) +unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n) { - unpack_Z24_S8(src, dst); + unpack_Z24_S8(src, dst, n); } static void -unpack_Z32(const void *src, GLfloat dst[4]) +unpack_Z32(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[0] = dst[1] = dst[2] = s * (1.0F / 0xffffffff); - dst[3] = 1.0F; + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = + dst[i][1] = + dst[i][2] = s[i] * (1.0F / 0xffffffff); + dst[i][3] = 1.0F; + } } static void -unpack_Z32_FLOAT(const void *src, GLfloat dst[4]) +unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n) { - const GLfloat s = *((const GLfloat *) src); - dst[0] = dst[1] = dst[2] = s; - dst[3] = 1.0F; + const GLfloat *s = ((const GLfloat *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = + dst[i][1] = + dst[i][2] = s[i]; + dst[i][3] = 1.0F; + } } static void -unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[4]) +unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n) { - const GLfloat s = *((const GLfloat *) src); - dst[0] = dst[1] = dst[2] = s; - dst[3] = 1.0F; + const GLfloat *s = ((const GLfloat *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = + dst[i][1] = + dst[i][2] = s[i]; + dst[i][3] = 1.0F; + } } static void -unpack_S8(const void *src, GLfloat dst[4]) +unpack_S8(const void *src, GLfloat dst[][4], GLuint n) { /* should never be used */ - dst[0] = dst[1] = dst[2] = 0.0F; - dst[3] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][0] = + dst[i][1] = + dst[i][2] = 0.0F; + dst[i][3] = 1.0F; + } } static void -unpack_SRGB8(const void *src, GLfloat dst[4]) +unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n) { const GLubyte *s = (const GLubyte *) src; - dst[RCOMP] = nonlinear_to_linear(s[2]); - dst[GCOMP] = nonlinear_to_linear(s[1]); - dst[BCOMP] = nonlinear_to_linear(s[0]); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]); + dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]); + dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SRGBA8(const void *src, GLfloat dst[4]) +unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = nonlinear_to_linear( (s >> 24) ); - dst[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); - dst[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */ + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) ); + dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][BCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */ + } } static void -unpack_SARGB8(const void *src, GLfloat dst[4]) +unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); - dst[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - dst[BCOMP] = nonlinear_to_linear( (s ) & 0xff ); - dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */ + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = nonlinear_to_linear( (s[i] ) & 0xff ); + dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */ + } } static void -unpack_SL8(const void *src, GLfloat dst[4]) +unpack_SL8(const void *src, GLfloat dst[][4], GLuint n) { - const GLubyte s = *((const GLubyte *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = nonlinear_to_linear(s); - dst[ACOMP] = 1.0F; + const GLubyte *s = ((const GLubyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = nonlinear_to_linear(s[i]); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SLA8(const void *src, GLfloat dst[4]) +unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n) { const GLubyte *s = (const GLubyte *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = nonlinear_to_linear(s[0]); - dst[ACOMP] = UBYTE_TO_FLOAT(s[1]); /* linear */ + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = nonlinear_to_linear(s[i*2+0]); + dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i*2+1]); /* linear! */ + } } static void -unpack_SRGB_DXT1(const void *src, GLfloat dst[4]) +unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_SRGBA_DXT1(const void *src, GLfloat dst[4]) +unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_SRGBA_DXT3(const void *src, GLfloat dst[4]) +unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_SRGBA_DXT5(const void *src, GLfloat dst[4]) +unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_RGB_FXT1(const void *src, GLfloat dst[4]) +unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_RGBA_FXT1(const void *src, GLfloat dst[4]) +unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_RGB_DXT1(const void *src, GLfloat dst[4]) +unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_RGBA_DXT1(const void *src, GLfloat dst[4]) +unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_RGBA_DXT3(const void *src, GLfloat dst[4]) +unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_RGBA_DXT5(const void *src, GLfloat dst[4]) +unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n) { } static void -unpack_RGBA_FLOAT32(const void *src, GLfloat dst[4]) +unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = s[0]; - dst[GCOMP] = s[1]; - dst[BCOMP] = s[2]; - dst[ACOMP] = s[3]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = s[i*4+0]; + dst[i][GCOMP] = s[i*4+1]; + dst[i][BCOMP] = s[i*4+2]; + dst[i][ACOMP] = s[i*4+3]; + } } static void -unpack_RGBA_FLOAT16(const void *src, GLfloat dst[4]) +unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = _mesa_half_to_float(s[0]); - dst[GCOMP] = _mesa_half_to_float(s[1]); - dst[BCOMP] = _mesa_half_to_float(s[2]); - dst[ACOMP] = _mesa_half_to_float(s[3]); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]); + dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]); + dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]); + dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]); + } } static void -unpack_RGB_FLOAT32(const void *src, GLfloat dst[4]) +unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = s[0]; - dst[GCOMP] = s[1]; - dst[BCOMP] = s[2]; - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = s[i*3+0]; + dst[i][GCOMP] = s[i*3+1]; + dst[i][BCOMP] = s[i*3+2]; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_RGB_FLOAT16(const void *src, GLfloat dst[4]) +unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = _mesa_half_to_float(s[0]); - dst[GCOMP] = _mesa_half_to_float(s[1]); - dst[BCOMP] = _mesa_half_to_float(s[2]); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]); + dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]); + dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[4]) +unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = 0.0F; - dst[ACOMP] = s[0]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = s[i]; + } } static void -unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[4]) +unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = 0.0F; - dst[ACOMP] = _mesa_half_to_float(s[0]); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = _mesa_half_to_float(s[i]); + } } static void -unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[4]) +unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = s[0]; - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = s[i]; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[4]) +unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = _mesa_half_to_float(s[0]); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = _mesa_half_to_float(s[i]); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[4]) +unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = s[0]; - dst[ACOMP] = s[1]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = s[i*2+0]; + dst[i][ACOMP] = s[i*2+1]; + } } static void -unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[4]) +unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = _mesa_half_to_float(s[0]); - dst[ACOMP] = _mesa_half_to_float(s[1]); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]); + dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]); + } } static void -unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[4]) +unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = - dst[ACOMP] = s[0]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = + dst[i][ACOMP] = s[i]; + } } static void -unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[4]) +unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = - dst[ACOMP] = s[0]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = + dst[i][ACOMP] = s[i]; + } } static void -unpack_R_FLOAT32(const void *src, GLfloat dst[4]) +unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = s[0]; - dst[GCOMP] = 0.0F; - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = s[i]; + dst[i][GCOMP] = 0.0F; + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_R_FLOAT16(const void *src, GLfloat dst[4]) +unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = _mesa_half_to_float(s[0]); - dst[GCOMP] = 0.0F; - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = _mesa_half_to_float(s[i]); + dst[i][GCOMP] = 0.0F; + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_RG_FLOAT32(const void *src, GLfloat dst[4]) +unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n) { const GLfloat *s = (const GLfloat *) src; - dst[RCOMP] = s[0]; - dst[GCOMP] = s[1]; - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = s[i*2+0]; + dst[i][GCOMP] = s[i*2+1]; + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_RG_FLOAT16(const void *src, GLfloat dst[4]) +unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) { const GLhalfARB *s = (const GLhalfARB *) src; - dst[RCOMP] = _mesa_half_to_float(s[0]); - dst[GCOMP] = _mesa_half_to_float(s[1]); - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]); + dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]); + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_RGBA_INT8(const void *src, GLfloat dst[4]) +unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n) { const GLbyte *s = (const GLbyte *) src; - dst[RCOMP] = (GLfloat) s[0]; - dst[GCOMP] = (GLfloat) s[1]; - dst[BCOMP] = (GLfloat) s[2]; - dst[ACOMP] = (GLfloat) s[3]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLfloat) s[i*4+0]; + dst[i][GCOMP] = (GLfloat) s[i*4+1]; + dst[i][BCOMP] = (GLfloat) s[i*4+2]; + dst[i][ACOMP] = (GLfloat) s[i*4+3]; + } } static void -unpack_RGBA_INT16(const void *src, GLfloat dst[4]) +unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n) { const GLshort *s = (const GLshort *) src; - dst[RCOMP] = (GLfloat) s[0]; - dst[GCOMP] = (GLfloat) s[1]; - dst[BCOMP] = (GLfloat) s[2]; - dst[ACOMP] = (GLfloat) s[3]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLfloat) s[i*4+0]; + dst[i][GCOMP] = (GLfloat) s[i*4+1]; + dst[i][BCOMP] = (GLfloat) s[i*4+2]; + dst[i][ACOMP] = (GLfloat) s[i*4+3]; + } } static void -unpack_RGBA_INT32(const void *src, GLfloat dst[4]) +unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n) { const GLint *s = (const GLint *) src; - dst[RCOMP] = (GLfloat) s[0]; - dst[GCOMP] = (GLfloat) s[1]; - dst[BCOMP] = (GLfloat) s[2]; - dst[ACOMP] = (GLfloat) s[3]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLfloat) s[i*4+0]; + dst[i][GCOMP] = (GLfloat) s[i*4+1]; + dst[i][BCOMP] = (GLfloat) s[i*4+2]; + dst[i][ACOMP] = (GLfloat) s[i*4+3]; + } } static void -unpack_RGBA_UINT8(const void *src, GLfloat dst[4]) +unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n) { const GLubyte *s = (const GLubyte *) src; - dst[RCOMP] = (GLfloat) s[0]; - dst[GCOMP] = (GLfloat) s[1]; - dst[BCOMP] = (GLfloat) s[2]; - dst[ACOMP] = (GLfloat) s[3]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLfloat) s[i*4+0]; + dst[i][GCOMP] = (GLfloat) s[i*4+1]; + dst[i][BCOMP] = (GLfloat) s[i*4+2]; + dst[i][ACOMP] = (GLfloat) s[i*4+3]; + } } static void -unpack_RGBA_UINT16(const void *src, GLfloat dst[4]) +unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n) { const GLushort *s = (const GLushort *) src; - dst[RCOMP] = (GLfloat) s[0]; - dst[GCOMP] = (GLfloat) s[1]; - dst[BCOMP] = (GLfloat) s[2]; - dst[ACOMP] = (GLfloat) s[3]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLfloat) s[i*4+0]; + dst[i][GCOMP] = (GLfloat) s[i*4+1]; + dst[i][BCOMP] = (GLfloat) s[i*4+2]; + dst[i][ACOMP] = (GLfloat) s[i*4+3]; + } } static void -unpack_RGBA_UINT32(const void *src, GLfloat dst[4]) +unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n) { const GLuint *s = (const GLuint *) src; - dst[RCOMP] = (GLfloat) s[0]; - dst[GCOMP] = (GLfloat) s[1]; - dst[BCOMP] = (GLfloat) s[2]; - dst[ACOMP] = (GLfloat) s[3]; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLfloat) s[i*4+0]; + dst[i][GCOMP] = (GLfloat) s[i*4+1]; + dst[i][BCOMP] = (GLfloat) s[i*4+2]; + dst[i][ACOMP] = (GLfloat) s[i*4+3]; + } } static void -unpack_DUDV8(const void *src, GLfloat dst[4]) +unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n) { const GLbyte *s = (const GLbyte *) src; - dst[RCOMP] = BYTE_TO_FLOAT(s[0]); - dst[GCOMP] = BYTE_TO_FLOAT(s[1]); - dst[BCOMP] = 0; - dst[ACOMP] = 0; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]); + dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]); + dst[i][BCOMP] = 0; + dst[i][ACOMP] = 0; + } } static void -unpack_SIGNED_R8(const void *src, GLfloat dst[4]) +unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n) { - const GLbyte s = *((const GLbyte *) src); - dst[RCOMP] = BYTE_TO_FLOAT_TEX( s ); - dst[GCOMP] = 0.0F; - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + const GLbyte *s = ((const GLbyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] ); + dst[i][GCOMP] = 0.0F; + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[4]) +unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLushort *) src); - dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) ); - dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) ); + dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) ); + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[4]) +unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) ); - dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) ); - dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); - dst[ACOMP] = 1.0f; + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) ); + dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) ); + dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) ); + dst[i][ACOMP] = 1.0f; + } } static void -unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[4]) +unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) ); - dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) ); - dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); - dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) ); + dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) ); + dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) ); + dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) ); + } } static void -unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[4]) +unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) ); - dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); - dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) ); - dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) ); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) ); + dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) ); + dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) ); + dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) ); + } } static void -unpack_SIGNED_R16(const void *src, GLfloat dst[4]) +unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n) { - const GLshort s = *((const GLshort *) src); - dst[RCOMP] = SHORT_TO_FLOAT_TEX( s ); - dst[GCOMP] = 0.0F; - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + const GLshort *s = ((const GLshort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] ); + dst[i][GCOMP] = 0.0F; + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SIGNED_GR1616(const void *src, GLfloat dst[4]) +unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n) { - const GLuint s = *((const GLuint *) src); - dst[RCOMP] = SHORT_TO_FLOAT_TEX( s & 0xffff ); - dst[GCOMP] = SHORT_TO_FLOAT_TEX( s >> 16 ); - dst[BCOMP] = 0.0F; - dst[ACOMP] = 1.0F; + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] & 0xffff ); + dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i] >> 16 ); + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SIGNED_RGB_16(const void *src, GLfloat dst[4]) +unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n) { const GLshort *s = (const GLshort *) src; - dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); - dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] ); - dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] ); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] ); + dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] ); + dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] ); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[4]) +unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n) { const GLshort *s = (const GLshort *) src; - dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); - dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] ); - dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] ); - dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] ); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] ); + dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] ); + dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] ); + dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] ); + } } static void -unpack_RGBA_16(const void *src, GLfloat dst[4]) +unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n) { const GLushort *s = (const GLushort *) src; - dst[RCOMP] = USHORT_TO_FLOAT( s[0] ); - dst[GCOMP] = USHORT_TO_FLOAT( s[1] ); - dst[BCOMP] = USHORT_TO_FLOAT( s[2] ); - dst[ACOMP] = USHORT_TO_FLOAT( s[3] ); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] ); + dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] ); + dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] ); + dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] ); + } } static void -unpack_RED_RGTC1(const void *src, GLfloat dst[4]) +unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[4]) +unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_RG_RGTC2(const void *src, GLfloat dst[4]) +unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[4]) +unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_L_LATC1(const void *src, GLfloat dst[4]) +unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[4]) +unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_LA_LATC2(const void *src, GLfloat dst[4]) +unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[4]) +unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n) { /* XXX to do */ } static void -unpack_SIGNED_A8(const void *src, GLfloat dst[4]) +unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n) { - const GLbyte s = *((const GLbyte *) src); - dst[RCOMP] = 0.0F; - dst[GCOMP] = 0.0F; - dst[BCOMP] = 0.0F; - dst[ACOMP] = BYTE_TO_FLOAT_TEX( s ); + const GLbyte *s = ((const GLbyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = 0.0F; + dst[i][GCOMP] = 0.0F; + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] ); + } } static void -unpack_SIGNED_L8(const void *src, GLfloat dst[4]) +unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n) { - const GLbyte s = *((const GLbyte *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = BYTE_TO_FLOAT_TEX( s ); - dst[ACOMP] = 1.0F; + const GLbyte *s = ((const GLbyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] ); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SIGNED_AL88(const void *src, GLfloat dst[4]) +unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n) { - const GLushort s = *((const GLshort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) ); - dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) ); + const GLshort *s = ((const GLshort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) ); + dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) ); + } } static void -unpack_SIGNED_I8(const void *src, GLfloat dst[4]) +unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n) { - const GLbyte s = *((const GLbyte *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = - dst[ACOMP] = BYTE_TO_FLOAT_TEX( s ); + const GLbyte *s = ((const GLbyte *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = + dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] ); + } } static void -unpack_SIGNED_A16(const void *src, GLfloat dst[4]) +unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n) { - const GLshort s = *((const GLshort *) src); - dst[RCOMP] = 0.0F; - dst[GCOMP] = 0.0F; - dst[BCOMP] = 0.0F; - dst[ACOMP] = SHORT_TO_FLOAT_TEX( s ); + const GLshort *s = ((const GLshort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = 0.0F; + dst[i][GCOMP] = 0.0F; + dst[i][BCOMP] = 0.0F; + dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] ); + } } static void -unpack_SIGNED_L16(const void *src, GLfloat dst[4]) +unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n) { - const GLshort s = *((const GLshort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = SHORT_TO_FLOAT_TEX( s ); - dst[ACOMP] = 1.0F; + const GLshort *s = ((const GLshort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] ); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_SIGNED_AL1616(const void *src, GLfloat dst[4]) +unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n) { const GLshort *s = (const GLshort *) src; - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] ); - dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] ); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] ); + dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] ); + } } static void -unpack_SIGNED_I16(const void *src, GLfloat dst[4]) +unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n) { - const GLshort s = *((const GLshort *) src); - dst[RCOMP] = - dst[GCOMP] = - dst[BCOMP] = - dst[ACOMP] = SHORT_TO_FLOAT_TEX( s ); + const GLshort *s = ((const GLshort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = + dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] ); + } } static void -unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[4]) +unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n) { const GLuint *s = (const GLuint *) src; - rgb9e5_to_float3(*s, dst); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + rgb9e5_to_float3(s[i], dst[i]); + dst[i][ACOMP] = 1.0F; + } } static void -unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[4]) +unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n) { const GLuint *s = (const GLuint *) src; - r11g11b10f_to_float3(*s, dst); - dst[ACOMP] = 1.0F; + GLuint i; + for (i = 0; i < n; i++) { + r11g11b10f_to_float3(s[i], dst[i]); + dst[i][ACOMP] = 1.0F; + } } @@ -1248,14 +1534,7 @@ _mesa_unpack_rgba_row(gl_format format, GLuint n, const void *src, GLfloat dst[][4]) { unpack_rgba_func unpack = get_unpack_rgba_function(format); - GLuint srcStride = _mesa_get_format_bytes(format); - const GLubyte *srcPtr = (GLubyte *) src; - GLuint i; - - for (i = 0; i < n; i++) { - unpack(srcPtr, dst[i]); - srcPtr += srcStride; - } + unpack(src, dst, n); } static void @@ -1401,10 +1680,9 @@ _mesa_unpack_rgba_block(gl_format format, unpack_rgba_func unpack = get_unpack_rgba_function(format); const GLuint srcPixStride = _mesa_get_format_bytes(format); const GLuint dstPixStride = 4 * sizeof(GLfloat); - const GLubyte *srcRow, *srcPix; + const GLubyte *srcRow; GLubyte *dstRow; - GLfloat *dstPix; - GLuint i, j; + GLuint i; /* XXX needs to be fixed for compressed formats */ @@ -1412,14 +1690,7 @@ _mesa_unpack_rgba_block(gl_format format, dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x; for (i = 0; i < height; i++) { - srcPix = srcRow; - dstPix = (GLfloat *) dstRow; - - for (j = 0; j < width; j++) { - unpack(srcPix, dstPix); - srcPix += srcPixStride; - dstPix += dstPixStride; - } + unpack(srcRow, (GLfloat (*)[4]) dstRow, width); dstRow += dstRowStride; srcRow += srcRowStride; @@ -1429,60 +1700,64 @@ _mesa_unpack_rgba_block(gl_format format, -typedef void (*unpack_float_z_func)(const void *src, GLfloat *dst); +typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst); static void -unpack_float_z_Z24_S8(const void *src, GLfloat *dst) +unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst) { /* only return Z, not stencil data */ - const GLuint s = *((const GLuint *) src); + const GLuint *s = ((const GLuint *) src); const GLfloat scale = 1.0F / (GLfloat) 0xffffff; - *dst = (s >> 8) * scale; - ASSERT(*dst >= 0.0F); - ASSERT(*dst <= 1.0F); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = (s[i] >> 8) * scale; + ASSERT(dst[i] >= 0.0F); + ASSERT(dst[i] <= 1.0F); + } } static void -unpack_float_z_S8_Z24(const void *src, GLfloat *dst) +unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst) { /* only return Z, not stencil data */ - const GLuint s = *((const GLuint *) src); + const GLuint *s = ((const GLuint *) src); const GLfloat scale = 1.0F / (GLfloat) 0xffffff; - *dst = (s & 0x00ffffff) * scale; - ASSERT(*dst >= 0.0F); - ASSERT(*dst <= 1.0F); -} - -static void -unpack_float_z_Z16(const void *src, GLfloat *dst) -{ - const GLushort s = *((const GLushort *) src); - *dst = s * (1.0F / 65535.0F); -} - -static void -unpack_float_z_X8_Z24(const void *src, GLfloat *dst) -{ - unpack_float_z_S8_Z24(src, dst); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = (s[i] & 0x00ffffff) * scale; + ASSERT(dst[i] >= 0.0F); + ASSERT(dst[i] <= 1.0F); + } } static void -unpack_float_z_Z24_X8(const void *src, GLfloat *dst) +unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst) { - unpack_float_z_Z24_S8(src, dst); + const GLushort *s = ((const GLushort *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = s[i] * (1.0F / 65535.0F); + } } static void -unpack_float_z_Z32(const void *src, GLfloat *dst) +unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst) { - const GLuint s = *((const GLuint *) src); - *dst = s * (1.0F / 0xffffffff); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = s[i] * (1.0F / 0xffffffff); + } } static void -unpack_float_z_Z32X24S8(const void *src, GLfloat *dst) +unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst) { - *dst = *((const GLfloat *) src); + const GLfloat *s = ((const GLfloat *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = s[i * 2]; + } } @@ -1492,25 +1767,18 @@ _mesa_unpack_float_z_row(gl_format format, GLuint n, const void *src, GLfloat *dst) { unpack_float_z_func unpack; - GLuint srcStride = _mesa_get_format_bytes(format); - const GLubyte *srcPtr = (GLubyte *) src; - GLuint i; switch (format) { case MESA_FORMAT_Z24_S8: - unpack = unpack_float_z_Z24_S8; + case MESA_FORMAT_Z24_X8: + unpack = unpack_float_z_Z24_X8; break; case MESA_FORMAT_S8_Z24: - unpack = unpack_float_z_S8_Z24; - break; - case MESA_FORMAT_Z16: - unpack = unpack_float_z_Z16; - break; case MESA_FORMAT_X8_Z24: unpack = unpack_float_z_X8_Z24; break; - case MESA_FORMAT_Z24_X8: - unpack = unpack_float_z_Z24_X8; + case MESA_FORMAT_Z16: + unpack = unpack_float_z_Z16; break; case MESA_FORMAT_Z32: unpack = unpack_float_z_Z32; @@ -1524,43 +1792,49 @@ _mesa_unpack_float_z_row(gl_format format, GLuint n, return; } - for (i = 0; i < n; i++) { - unpack(srcPtr, &dst[i]); - srcPtr += srcStride; - } + unpack(n, src, dst); } -typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst); +typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n); static void -unpack_uint_z_Z24_X8(const void *src, GLuint *dst) +unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n) { /* only return Z, not stencil data */ - const GLuint s = *((const GLuint *) src); - *dst = (s & 0xffffff00) | (s >> 24); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24); + } } static void -unpack_uint_z_X8_Z24(const void *src, GLuint *dst) +unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n) { /* only return Z, not stencil data */ - const GLuint s = *((const GLuint *) src); - *dst = (s << 8) | ((s >> 16) & 0xff); + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff); + } } static void -unpack_uint_z_Z16(const void *src, GLuint *dst) +unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n) { - const GLushort s = *((const GLushort *)src); - *dst = (s << 16) | s; + const GLushort *s = ((const GLushort *)src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i] = (s[i] << 16) | s[i]; + } } static void -unpack_uint_z_Z32(const void *src, GLuint *dst) +unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n) { - *dst = *((const GLuint *) src); + memcpy(dst, src, n * sizeof(GLuint)); } @@ -1569,9 +1843,7 @@ _mesa_unpack_uint_z_row(gl_format format, GLuint n, const void *src, GLuint *dst) { unpack_uint_z_func unpack; - GLuint srcStride = _mesa_get_format_bytes(format); const GLubyte *srcPtr = (GLubyte *) src; - GLuint i; switch (format) { case MESA_FORMAT_Z24_S8: @@ -1594,12 +1866,10 @@ _mesa_unpack_uint_z_row(gl_format format, GLuint n, return; } - for (i = 0; i < n; i++) { - unpack(srcPtr, &dst[i]); - srcPtr += srcStride; - } + unpack(srcPtr, dst, n); } + static void unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n) { diff --git a/mesalib/src/mesa/main/image.c b/mesalib/src/mesa/main/image.c index 7d95dd6be..914a99923 100644 --- a/mesalib/src/mesa/main/image.c +++ b/mesalib/src/mesa/main/image.c @@ -39,25 +39,6 @@ #include "mtypes.h" -/** - * NOTE: - * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when - * we later convert the float to a packed integer value (such as for - * GL_RGB5_A1) because we'll wind up with a non-zero value. - * - * We redefine the macros here so zero is handled correctly. - */ -#undef BYTE_TO_FLOAT -#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F))) - -#undef SHORT_TO_FLOAT -#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))) - - - -/** Compute ceiling of integer quotient of A divided by B. */ -#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 ) - /** * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise. @@ -195,38 +176,24 @@ _mesa_sizeof_packed_type( GLenum type ) case GL_FLOAT: return sizeof(GLfloat); case GL_UNSIGNED_BYTE_3_3_2: - return sizeof(GLubyte); case GL_UNSIGNED_BYTE_2_3_3_REV: - return sizeof(GLubyte); case MESA_UNSIGNED_BYTE_4_4: return sizeof(GLubyte); case GL_UNSIGNED_SHORT_5_6_5: - return sizeof(GLushort); case GL_UNSIGNED_SHORT_5_6_5_REV: - return sizeof(GLushort); case GL_UNSIGNED_SHORT_4_4_4_4: - return sizeof(GLushort); case GL_UNSIGNED_SHORT_4_4_4_4_REV: - return sizeof(GLushort); case GL_UNSIGNED_SHORT_5_5_5_1: - return sizeof(GLushort); case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT_8_8_MESA: + case GL_UNSIGNED_SHORT_8_8_REV_MESA: return sizeof(GLushort); case GL_UNSIGNED_INT_8_8_8_8: - return sizeof(GLuint); case GL_UNSIGNED_INT_8_8_8_8_REV: - return sizeof(GLuint); case GL_UNSIGNED_INT_10_10_10_2: - return sizeof(GLuint); case GL_UNSIGNED_INT_2_10_10_10_REV: - return sizeof(GLuint); - case GL_UNSIGNED_SHORT_8_8_MESA: - case GL_UNSIGNED_SHORT_8_8_REV_MESA: - return sizeof(GLushort); case GL_UNSIGNED_INT_24_8_EXT: - return sizeof(GLuint); case GL_UNSIGNED_INT_5_9_9_9_REV: - return sizeof(GLuint); case GL_UNSIGNED_INT_10F_11F_11F_REV: return sizeof(GLuint); case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: @@ -263,29 +230,27 @@ _mesa_components_in_format( GLenum format ) case GL_LUMINANCE_INTEGER_EXT: case GL_INTENSITY: return 1; + case GL_LUMINANCE_ALPHA: case GL_LUMINANCE_ALPHA_INTEGER_EXT: case GL_RG: + case GL_YCBCR_MESA: + case GL_DEPTH_STENCIL_EXT: + case GL_DUDV_ATI: + case GL_DU8DV8_ATI: return 2; + case GL_RGB: + case GL_BGR: case GL_RGB_INTEGER_EXT: return 3; + case GL_RGBA: - case GL_RGBA_INTEGER_EXT: - return 4; - case GL_BGR: - return 3; case GL_BGRA: - return 4; case GL_ABGR_EXT: + case GL_RGBA_INTEGER_EXT: return 4; - case GL_YCBCR_MESA: - return 2; - case GL_DEPTH_STENCIL_EXT: - return 2; - case GL_DUDV_ATI: - case GL_DU8DV8_ATI: - return 2; + default: return -1; } @@ -987,36 +952,48 @@ _mesa_is_integer_format(GLenum format) /* specific integer formats */ case GL_RGBA32UI_EXT: case GL_RGB32UI_EXT: + case GL_RG32UI: + case GL_R32UI: case GL_ALPHA32UI_EXT: case GL_INTENSITY32UI_EXT: case GL_LUMINANCE32UI_EXT: case GL_LUMINANCE_ALPHA32UI_EXT: case GL_RGBA16UI_EXT: case GL_RGB16UI_EXT: + case GL_RG16UI: + case GL_R16UI: case GL_ALPHA16UI_EXT: case GL_INTENSITY16UI_EXT: case GL_LUMINANCE16UI_EXT: case GL_LUMINANCE_ALPHA16UI_EXT: case GL_RGBA8UI_EXT: case GL_RGB8UI_EXT: + case GL_RG8UI: + case GL_R8UI: case GL_ALPHA8UI_EXT: case GL_INTENSITY8UI_EXT: case GL_LUMINANCE8UI_EXT: case GL_LUMINANCE_ALPHA8UI_EXT: case GL_RGBA32I_EXT: case GL_RGB32I_EXT: + case GL_RG32I: + case GL_R32I: case GL_ALPHA32I_EXT: case GL_INTENSITY32I_EXT: case GL_LUMINANCE32I_EXT: case GL_LUMINANCE_ALPHA32I_EXT: case GL_RGBA16I_EXT: case GL_RGB16I_EXT: + case GL_RG16I: + case GL_R16I: case GL_ALPHA16I_EXT: case GL_INTENSITY16I_EXT: case GL_LUMINANCE16I_EXT: case GL_LUMINANCE_ALPHA16I_EXT: case GL_RGBA8I_EXT: case GL_RGB8I_EXT: + case GL_RG8I: + case GL_R8I: case GL_ALPHA8I_EXT: case GL_INTENSITY8I_EXT: case GL_LUMINANCE8I_EXT: diff --git a/mesalib/src/mesa/main/light.c b/mesalib/src/mesa/main/light.c index 888e5622e..60daa89a3 100644 --- a/mesalib/src/mesa/main/light.c +++ b/mesalib/src/mesa/main/light.c @@ -1,1430 +1,1433 @@ -/*
- * Mesa 3-D graphics library
- * Version: 7.5
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. 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
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "enums.h"
-#include "light.h"
-#include "macros.h"
-#include "simple_list.h"
-#include "mtypes.h"
-#include "math/m_matrix.h"
-
-
-void GLAPIENTRY
-_mesa_ShadeModel( GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glShadeModel %s\n", _mesa_lookup_enum_by_nr(mode));
-
- if (mode != GL_FLAT && mode != GL_SMOOTH) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glShadeModel");
- return;
- }
-
- if (ctx->Light.ShadeModel == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.ShadeModel = mode;
- if (mode == GL_FLAT)
- ctx->_TriangleCaps |= DD_FLATSHADE;
- else
- ctx->_TriangleCaps &= ~DD_FLATSHADE;
-
- if (ctx->Driver.ShadeModel)
- ctx->Driver.ShadeModel( ctx, mode );
-}
-
-
-/**
- * Set the provoking vertex (the vertex which specifies the prim's
- * color when flat shading) to either the first or last vertex of the
- * triangle or line.
- */
-void GLAPIENTRY
-_mesa_ProvokingVertexEXT(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glProvokingVertexEXT 0x%x\n", mode);
-
- switch (mode) {
- case GL_FIRST_VERTEX_CONVENTION_EXT:
- case GL_LAST_VERTEX_CONVENTION_EXT:
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glProvokingVertexEXT(0x%x)", mode);
- return;
- }
-
- if (ctx->Light.ProvokingVertex == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.ProvokingVertex = mode;
-}
-
-
-/**
- * Helper function called by _mesa_Lightfv and _mesa_PopAttrib to set
- * per-light state.
- * For GL_POSITION and GL_SPOT_DIRECTION the params position/direction
- * will have already been transformed by the modelview matrix!
- * Also, all error checking should have already been done.
- */
-void
-_mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params)
-{
- struct gl_light *light;
-
- ASSERT(lnum < MAX_LIGHTS);
- light = &ctx->Light.Light[lnum];
-
- switch (pname) {
- case GL_AMBIENT:
- if (TEST_EQ_4V(light->Ambient, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( light->Ambient, params );
- break;
- case GL_DIFFUSE:
- if (TEST_EQ_4V(light->Diffuse, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( light->Diffuse, params );
- break;
- case GL_SPECULAR:
- if (TEST_EQ_4V(light->Specular, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( light->Specular, params );
- break;
- case GL_POSITION:
- /* NOTE: position has already been transformed by ModelView! */
- if (TEST_EQ_4V(light->EyePosition, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V(light->EyePosition, params);
- if (light->EyePosition[3] != 0.0F)
- light->_Flags |= LIGHT_POSITIONAL;
- else
- light->_Flags &= ~LIGHT_POSITIONAL;
- break;
- case GL_SPOT_DIRECTION:
- /* NOTE: Direction already transformed by inverse ModelView! */
- if (TEST_EQ_3V(light->SpotDirection, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_3V(light->SpotDirection, params);
- break;
- case GL_SPOT_EXPONENT:
- ASSERT(params[0] >= 0.0);
- ASSERT(params[0] <= ctx->Const.MaxSpotExponent);
- if (light->SpotExponent == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->SpotExponent = params[0];
- _mesa_invalidate_spot_exp_table(light);
- break;
- case GL_SPOT_CUTOFF:
- ASSERT(params[0] == 180.0 || (params[0] >= 0.0 && params[0] <= 90.0));
- if (light->SpotCutoff == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->SpotCutoff = params[0];
- light->_CosCutoffNeg = (GLfloat) (cos(light->SpotCutoff * DEG2RAD));
- if (light->_CosCutoffNeg < 0)
- light->_CosCutoff = 0;
- else
- light->_CosCutoff = light->_CosCutoffNeg;
- if (light->SpotCutoff != 180.0F)
- light->_Flags |= LIGHT_SPOT;
- else
- light->_Flags &= ~LIGHT_SPOT;
- break;
- case GL_CONSTANT_ATTENUATION:
- ASSERT(params[0] >= 0.0);
- if (light->ConstantAttenuation == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->ConstantAttenuation = params[0];
- break;
- case GL_LINEAR_ATTENUATION:
- ASSERT(params[0] >= 0.0);
- if (light->LinearAttenuation == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->LinearAttenuation = params[0];
- break;
- case GL_QUADRATIC_ATTENUATION:
- ASSERT(params[0] >= 0.0);
- if (light->QuadraticAttenuation == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->QuadraticAttenuation = params[0];
- break;
- default:
- _mesa_problem(ctx, "Unexpected pname in _mesa_light()");
- return;
- }
-
- if (ctx->Driver.Lightfv)
- ctx->Driver.Lightfv( ctx, GL_LIGHT0 + lnum, pname, params );
-}
-
-
-void GLAPIENTRY
-_mesa_Lightf( GLenum light, GLenum pname, GLfloat param )
-{
- GLfloat fparam[4];
- fparam[0] = param;
- fparam[1] = fparam[2] = fparam[3] = 0.0F;
- _mesa_Lightfv( light, pname, fparam );
-}
-
-
-void GLAPIENTRY
-_mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i = (GLint) (light - GL_LIGHT0);
- GLfloat temp[4];
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (i < 0 || i >= (GLint) ctx->Const.MaxLights) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glLight(light=0x%x)", light );
- return;
- }
-
- /* do particular error checks, transformations */
- switch (pname) {
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- /* nothing */
- break;
- case GL_POSITION:
- /* transform position by ModelView matrix */
- TRANSFORM_POINT(temp, ctx->ModelviewMatrixStack.Top->m, params);
- params = temp;
- break;
- case GL_SPOT_DIRECTION:
- /* transform direction by inverse modelview */
- if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
- _math_matrix_analyse(ctx->ModelviewMatrixStack.Top);
- }
- TRANSFORM_DIRECTION(temp, params, ctx->ModelviewMatrixStack.Top->m);
- params = temp;
- break;
- case GL_SPOT_EXPONENT:
- if (params[0] < 0.0 || params[0] > ctx->Const.MaxSpotExponent) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_SPOT_CUTOFF:
- if ((params[0] < 0.0 || params[0] > 90.0) && params[0] != 180.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_CONSTANT_ATTENUATION:
- if (params[0] < 0.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_LINEAR_ATTENUATION:
- if (params[0] < 0.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_QUADRATIC_ATTENUATION:
- if (params[0] < 0.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glLight(pname=0x%x)", pname);
- return;
- }
-
- _mesa_light(ctx, i, pname, params);
-}
-
-
-void GLAPIENTRY
-_mesa_Lighti( GLenum light, GLenum pname, GLint param )
-{
- GLint iparam[4];
- iparam[0] = param;
- iparam[1] = iparam[2] = iparam[3] = 0;
- _mesa_Lightiv( light, pname, iparam );
-}
-
-
-void GLAPIENTRY
-_mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
-{
- GLfloat fparam[4];
-
- switch (pname) {
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- fparam[0] = INT_TO_FLOAT( params[0] );
- fparam[1] = INT_TO_FLOAT( params[1] );
- fparam[2] = INT_TO_FLOAT( params[2] );
- fparam[3] = INT_TO_FLOAT( params[3] );
- break;
- case GL_POSITION:
- fparam[0] = (GLfloat) params[0];
- fparam[1] = (GLfloat) params[1];
- fparam[2] = (GLfloat) params[2];
- fparam[3] = (GLfloat) params[3];
- break;
- case GL_SPOT_DIRECTION:
- fparam[0] = (GLfloat) params[0];
- fparam[1] = (GLfloat) params[1];
- fparam[2] = (GLfloat) params[2];
- break;
- case GL_SPOT_EXPONENT:
- case GL_SPOT_CUTOFF:
- case GL_CONSTANT_ATTENUATION:
- case GL_LINEAR_ATTENUATION:
- case GL_QUADRATIC_ATTENUATION:
- fparam[0] = (GLfloat) params[0];
- break;
- default:
- /* error will be caught later in gl_Lightfv */
- ;
- }
-
- _mesa_Lightfv( light, pname, fparam );
-}
-
-
-
-void GLAPIENTRY
-_mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint l = (GLint) (light - GL_LIGHT0);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
- return;
- }
-
- switch (pname) {
- case GL_AMBIENT:
- COPY_4V( params, ctx->Light.Light[l].Ambient );
- break;
- case GL_DIFFUSE:
- COPY_4V( params, ctx->Light.Light[l].Diffuse );
- break;
- case GL_SPECULAR:
- COPY_4V( params, ctx->Light.Light[l].Specular );
- break;
- case GL_POSITION:
- COPY_4V( params, ctx->Light.Light[l].EyePosition );
- break;
- case GL_SPOT_DIRECTION:
- COPY_3V( params, ctx->Light.Light[l].SpotDirection );
- break;
- case GL_SPOT_EXPONENT:
- params[0] = ctx->Light.Light[l].SpotExponent;
- break;
- case GL_SPOT_CUTOFF:
- params[0] = ctx->Light.Light[l].SpotCutoff;
- break;
- case GL_CONSTANT_ATTENUATION:
- params[0] = ctx->Light.Light[l].ConstantAttenuation;
- break;
- case GL_LINEAR_ATTENUATION:
- params[0] = ctx->Light.Light[l].LinearAttenuation;
- break;
- case GL_QUADRATIC_ATTENUATION:
- params[0] = ctx->Light.Light[l].QuadraticAttenuation;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
- break;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint l = (GLint) (light - GL_LIGHT0);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
- return;
- }
-
- switch (pname) {
- case GL_AMBIENT:
- params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]);
- params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]);
- params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]);
- params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]);
- break;
- case GL_DIFFUSE:
- params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]);
- params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]);
- params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]);
- params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]);
- break;
- case GL_SPECULAR:
- params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]);
- params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]);
- params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]);
- params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]);
- break;
- case GL_POSITION:
- params[0] = (GLint) ctx->Light.Light[l].EyePosition[0];
- params[1] = (GLint) ctx->Light.Light[l].EyePosition[1];
- params[2] = (GLint) ctx->Light.Light[l].EyePosition[2];
- params[3] = (GLint) ctx->Light.Light[l].EyePosition[3];
- break;
- case GL_SPOT_DIRECTION:
- params[0] = (GLint) ctx->Light.Light[l].SpotDirection[0];
- params[1] = (GLint) ctx->Light.Light[l].SpotDirection[1];
- params[2] = (GLint) ctx->Light.Light[l].SpotDirection[2];
- break;
- case GL_SPOT_EXPONENT:
- params[0] = (GLint) ctx->Light.Light[l].SpotExponent;
- break;
- case GL_SPOT_CUTOFF:
- params[0] = (GLint) ctx->Light.Light[l].SpotCutoff;
- break;
- case GL_CONSTANT_ATTENUATION:
- params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation;
- break;
- case GL_LINEAR_ATTENUATION:
- params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation;
- break;
- case GL_QUADRATIC_ATTENUATION:
- params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
- break;
- }
-}
-
-
-
-/**********************************************************************/
-/*** Light Model ***/
-/**********************************************************************/
-
-
-void GLAPIENTRY
-_mesa_LightModelfv( GLenum pname, const GLfloat *params )
-{
- GLenum newenum;
- GLboolean newbool;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- switch (pname) {
- case GL_LIGHT_MODEL_AMBIENT:
- if (TEST_EQ_4V( ctx->Light.Model.Ambient, params ))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( ctx->Light.Model.Ambient, params );
- break;
- case GL_LIGHT_MODEL_LOCAL_VIEWER:
- newbool = (params[0]!=0.0);
- if (ctx->Light.Model.LocalViewer == newbool)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Model.LocalViewer = newbool;
- break;
- case GL_LIGHT_MODEL_TWO_SIDE:
- newbool = (params[0]!=0.0);
- if (ctx->Light.Model.TwoSide == newbool)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Model.TwoSide = newbool;
- if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
- ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
- else
- ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
- break;
- case GL_LIGHT_MODEL_COLOR_CONTROL:
- if (params[0] == (GLfloat) GL_SINGLE_COLOR)
- newenum = GL_SINGLE_COLOR;
- else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR)
- newenum = GL_SEPARATE_SPECULAR_COLOR;
- else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(param=0x0%x)",
- (GLint) params[0] );
- return;
- }
- if (ctx->Light.Model.ColorControl == newenum)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Model.ColorControl = newenum;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
- break;
- }
-
- if (ctx->Driver.LightModelfv)
- ctx->Driver.LightModelfv( ctx, pname, params );
-}
-
-
-void GLAPIENTRY
-_mesa_LightModeliv( GLenum pname, const GLint *params )
-{
- GLfloat fparam[4];
-
- switch (pname) {
- case GL_LIGHT_MODEL_AMBIENT:
- fparam[0] = INT_TO_FLOAT( params[0] );
- fparam[1] = INT_TO_FLOAT( params[1] );
- fparam[2] = INT_TO_FLOAT( params[2] );
- fparam[3] = INT_TO_FLOAT( params[3] );
- break;
- case GL_LIGHT_MODEL_LOCAL_VIEWER:
- case GL_LIGHT_MODEL_TWO_SIDE:
- case GL_LIGHT_MODEL_COLOR_CONTROL:
- fparam[0] = (GLfloat) params[0];
- break;
- default:
- /* Error will be caught later in gl_LightModelfv */
- ASSIGN_4V(fparam, 0.0F, 0.0F, 0.0F, 0.0F);
- }
- _mesa_LightModelfv( pname, fparam );
-}
-
-
-void GLAPIENTRY
-_mesa_LightModeli( GLenum pname, GLint param )
-{
- GLint iparam[4];
- iparam[0] = param;
- iparam[1] = iparam[2] = iparam[3] = 0;
- _mesa_LightModeliv( pname, iparam );
-}
-
-
-void GLAPIENTRY
-_mesa_LightModelf( GLenum pname, GLfloat param )
-{
- GLfloat fparam[4];
- fparam[0] = param;
- fparam[1] = fparam[2] = fparam[3] = 0.0F;
- _mesa_LightModelfv( pname, fparam );
-}
-
-
-
-/********** MATERIAL **********/
-
-
-/*
- * Given a face and pname value (ala glColorMaterial), compute a bitmask
- * of the targeted material values.
- */
-GLuint
-_mesa_material_bitmask( struct gl_context *ctx, GLenum face, GLenum pname,
- GLuint legal, const char *where )
-{
- GLuint bitmask = 0;
-
- /* Make a bitmask indicating what material attribute(s) we're updating */
- switch (pname) {
- case GL_EMISSION:
- bitmask |= MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION;
- break;
- case GL_AMBIENT:
- bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
- break;
- case GL_DIFFUSE:
- bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
- break;
- case GL_SPECULAR:
- bitmask |= MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR;
- break;
- case GL_SHININESS:
- bitmask |= MAT_BIT_FRONT_SHININESS | MAT_BIT_BACK_SHININESS;
- break;
- case GL_AMBIENT_AND_DIFFUSE:
- bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
- bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
- break;
- case GL_COLOR_INDEXES:
- bitmask |= MAT_BIT_FRONT_INDEXES | MAT_BIT_BACK_INDEXES;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
- return 0;
- }
-
- if (face==GL_FRONT) {
- bitmask &= FRONT_MATERIAL_BITS;
- }
- else if (face==GL_BACK) {
- bitmask &= BACK_MATERIAL_BITS;
- }
- else if (face != GL_FRONT_AND_BACK) {
- _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
- return 0;
- }
-
- if (bitmask & ~legal) {
- _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
- return 0;
- }
-
- return bitmask;
-}
-
-
-
-/* Perform a straight copy between materials.
- */
-void
-_mesa_copy_materials( struct gl_material *dst,
- const struct gl_material *src,
- GLuint bitmask )
-{
- int i;
-
- for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
- if (bitmask & (1<<i))
- COPY_4FV( dst->Attrib[i], src->Attrib[i] );
-}
-
-
-
-/* Update derived values following a change in ctx->Light.Material
- */
-void
-_mesa_update_material( struct gl_context *ctx, GLuint bitmask )
-{
- struct gl_light *light, *list = &ctx->Light.EnabledList;
- GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
-
- if (MESA_VERBOSE & VERBOSE_MATERIAL)
- _mesa_debug(ctx, "_mesa_update_material, mask 0x%x\n", bitmask);
-
- if (!bitmask)
- return;
-
- /* update material ambience */
- if (bitmask & MAT_BIT_FRONT_AMBIENT) {
- foreach (light, list) {
- SCALE_3V( light->_MatAmbient[0], light->Ambient,
- mat[MAT_ATTRIB_FRONT_AMBIENT]);
- }
- }
-
- if (bitmask & MAT_BIT_BACK_AMBIENT) {
- foreach (light, list) {
- SCALE_3V( light->_MatAmbient[1], light->Ambient,
- mat[MAT_ATTRIB_BACK_AMBIENT]);
- }
- }
-
- /* update BaseColor = emission + scene's ambience * material's ambience */
- if (bitmask & (MAT_BIT_FRONT_EMISSION | MAT_BIT_FRONT_AMBIENT)) {
- COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] );
- ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT],
- ctx->Light.Model.Ambient );
- }
-
- if (bitmask & (MAT_BIT_BACK_EMISSION | MAT_BIT_BACK_AMBIENT)) {
- COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] );
- ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT],
- ctx->Light.Model.Ambient );
- }
-
- /* update material diffuse values */
- if (bitmask & MAT_BIT_FRONT_DIFFUSE) {
- foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
- mat[MAT_ATTRIB_FRONT_DIFFUSE] );
- }
- }
-
- if (bitmask & MAT_BIT_BACK_DIFFUSE) {
- foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
- mat[MAT_ATTRIB_BACK_DIFFUSE] );
- }
- }
-
- /* update material specular values */
- if (bitmask & MAT_BIT_FRONT_SPECULAR) {
- foreach (light, list) {
- SCALE_3V( light->_MatSpecular[0], light->Specular,
- mat[MAT_ATTRIB_FRONT_SPECULAR]);
- }
- }
-
- if (bitmask & MAT_BIT_BACK_SPECULAR) {
- foreach (light, list) {
- SCALE_3V( light->_MatSpecular[1], light->Specular,
- mat[MAT_ATTRIB_BACK_SPECULAR]);
- }
- }
-
- if (bitmask & MAT_BIT_FRONT_SHININESS) {
- _mesa_invalidate_shine_table( ctx, 0 );
- }
-
- if (bitmask & MAT_BIT_BACK_SHININESS) {
- _mesa_invalidate_shine_table( ctx, 1 );
- }
-}
-
-
-/*
- * Update the current materials from the given rgba color
- * according to the bitmask in ColorMaterialBitmask, which is
- * set by glColorMaterial().
- */
-void
-_mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
-{
- GLuint bitmask = ctx->Light.ColorMaterialBitmask;
- struct gl_material *mat = &ctx->Light.Material;
- int i;
-
- for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
- if (bitmask & (1<<i))
- COPY_4FV( mat->Attrib[i], color );
-
- _mesa_update_material( ctx, bitmask );
-}
-
-
-void GLAPIENTRY
-_mesa_ColorMaterial( GLenum face, GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint bitmask;
- GLuint legal = (MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION |
- MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR |
- MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE |
- MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glColorMaterial %s %s\n",
- _mesa_lookup_enum_by_nr(face),
- _mesa_lookup_enum_by_nr(mode));
-
- bitmask = _mesa_material_bitmask(ctx, face, mode, legal, "glColorMaterial");
-
- if (ctx->Light.ColorMaterialBitmask == bitmask &&
- ctx->Light.ColorMaterialFace == face &&
- ctx->Light.ColorMaterialMode == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.ColorMaterialBitmask = bitmask;
- ctx->Light.ColorMaterialFace = face;
- ctx->Light.ColorMaterialMode = mode;
-
- if (ctx->Light.ColorMaterialEnabled) {
- FLUSH_CURRENT( ctx, 0 );
- _mesa_update_color_material(ctx,ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
- }
-
- if (ctx->Driver.ColorMaterial)
- ctx->Driver.ColorMaterial( ctx, face, mode );
-}
-
-
-void GLAPIENTRY
-_mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint f;
- GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
-
- FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
-
- if (face==GL_FRONT) {
- f = 0;
- }
- else if (face==GL_BACK) {
- f = 1;
- }
- else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(face)" );
- return;
- }
-
- switch (pname) {
- case GL_AMBIENT:
- COPY_4FV( params, mat[MAT_ATTRIB_AMBIENT(f)] );
- break;
- case GL_DIFFUSE:
- COPY_4FV( params, mat[MAT_ATTRIB_DIFFUSE(f)] );
- break;
- case GL_SPECULAR:
- COPY_4FV( params, mat[MAT_ATTRIB_SPECULAR(f)] );
- break;
- case GL_EMISSION:
- COPY_4FV( params, mat[MAT_ATTRIB_EMISSION(f)] );
- break;
- case GL_SHININESS:
- *params = mat[MAT_ATTRIB_SHININESS(f)][0];
- break;
- case GL_COLOR_INDEXES:
- params[0] = mat[MAT_ATTRIB_INDEXES(f)][0];
- params[1] = mat[MAT_ATTRIB_INDEXES(f)][1];
- params[2] = mat[MAT_ATTRIB_INDEXES(f)][2];
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint f;
- GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
-
- FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
-
- if (face==GL_FRONT) {
- f = 0;
- }
- else if (face==GL_BACK) {
- f = 1;
- }
- else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialiv(face)" );
- return;
- }
- switch (pname) {
- case GL_AMBIENT:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][3] );
- break;
- case GL_DIFFUSE:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][3] );
- break;
- case GL_SPECULAR:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][3] );
- break;
- case GL_EMISSION:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] );
- break;
- case GL_SHININESS:
- *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] );
- break;
- case GL_COLOR_INDEXES:
- params[0] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][0] );
- params[1] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][1] );
- params[2] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][2] );
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
- }
-}
-
-
-
-/**********************************************************************/
-/***** Lighting computation *****/
-/**********************************************************************/
-
-
-/*
- * Notes:
- * When two-sided lighting is enabled we compute the color (or index)
- * for both the front and back side of the primitive. Then, when the
- * orientation of the facet is later learned, we can determine which
- * color (or index) to use for rendering.
- *
- * KW: We now know orientation in advance and only shade for
- * the side or sides which are actually required.
- *
- * Variables:
- * n = normal vector
- * V = vertex position
- * P = light source position
- * Pe = (0,0,0,1)
- *
- * Precomputed:
- * IF P[3]==0 THEN
- * // light at infinity
- * IF local_viewer THEN
- * _VP_inf_norm = unit vector from V to P // Precompute
- * ELSE
- * // eye at infinity
- * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute
- * ENDIF
- * ENDIF
- *
- * Functions:
- * Normalize( v ) = normalized vector v
- * Magnitude( v ) = length of vector v
- */
-
-
-
-/*
- * Whenever the spotlight exponent for a light changes we must call
- * this function to recompute the exponent lookup table.
- */
-void
-_mesa_invalidate_spot_exp_table( struct gl_light *l )
-{
- l->_SpotExpTable[0][0] = -1;
-}
-
-
-static void
-validate_spot_exp_table( struct gl_light *l )
-{
- GLint i;
- GLdouble exponent = l->SpotExponent;
- GLdouble tmp = 0;
- GLint clamp = 0;
-
- l->_SpotExpTable[0][0] = 0.0;
-
- for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) {
- if (clamp == 0) {
- tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent);
- if (tmp < FLT_MIN * 100.0) {
- tmp = 0.0;
- clamp = 1;
- }
- }
- l->_SpotExpTable[i][0] = (GLfloat) tmp;
- }
- for (i = 0; i < EXP_TABLE_SIZE - 1; i++) {
- l->_SpotExpTable[i][1] = (l->_SpotExpTable[i+1][0] -
- l->_SpotExpTable[i][0]);
- }
- l->_SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0;
-}
-
-
-
-/* Calculate a new shine table. Doing this here saves a branch in
- * lighting, and the cost of doing it early may be partially offset
- * by keeping a MRU cache of shine tables for various shine values.
- */
-void
-_mesa_invalidate_shine_table( struct gl_context *ctx, GLuint side )
-{
- ASSERT(side < 2);
- if (ctx->_ShineTable[side])
- ctx->_ShineTable[side]->refcount--;
- ctx->_ShineTable[side] = NULL;
-}
-
-
-static void
-validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess )
-{
- struct gl_shine_tab *list = ctx->_ShineTabList;
- struct gl_shine_tab *s;
-
- ASSERT(side < 2);
-
- foreach(s, list)
- if ( s->shininess == shininess )
- break;
-
- if (s == list) {
- GLint j;
- GLfloat *m;
-
- foreach(s, list)
- if (s->refcount == 0)
- break;
-
- m = s->tab;
- m[0] = 0.0;
- if (shininess == 0.0) {
- for (j = 1 ; j <= SHINE_TABLE_SIZE ; j++)
- m[j] = 1.0;
- }
- else {
- for (j = 1 ; j < SHINE_TABLE_SIZE ; j++) {
- GLdouble t, x = j / (GLfloat) (SHINE_TABLE_SIZE - 1);
- if (x < 0.005) /* underflow check */
- x = 0.005;
- t = pow(x, shininess);
- if (t > 1e-20)
- m[j] = (GLfloat) t;
- else
- m[j] = 0.0;
- }
- m[SHINE_TABLE_SIZE] = 1.0;
- }
-
- s->shininess = shininess;
- }
-
- if (ctx->_ShineTable[side])
- ctx->_ShineTable[side]->refcount--;
-
- ctx->_ShineTable[side] = s;
- move_to_tail( list, s );
- s->refcount++;
-}
-
-
-void
-_mesa_validate_all_lighting_tables( struct gl_context *ctx )
-{
- GLuint i;
- GLfloat shininess;
-
- shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
- if (!ctx->_ShineTable[0] || ctx->_ShineTable[0]->shininess != shininess)
- validate_shine_table( ctx, 0, shininess );
-
- shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
- if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess)
- validate_shine_table( ctx, 1, shininess );
-
- for (i = 0; i < ctx->Const.MaxLights; i++)
- if (ctx->Light.Light[i]._SpotExpTable[0][0] == -1)
- validate_spot_exp_table( &ctx->Light.Light[i] );
-}
-
-
-/**
- * Examine current lighting parameters to determine if the optimized lighting
- * function can be used.
- * Also, precompute some lighting values such as the products of light
- * source and material ambient, diffuse and specular coefficients.
- */
-void
-_mesa_update_lighting( struct gl_context *ctx )
-{
- struct gl_light *light;
- ctx->Light._NeedEyeCoords = GL_FALSE;
- ctx->Light._Flags = 0;
-
- if (!ctx->Light.Enabled)
- return;
-
- foreach(light, &ctx->Light.EnabledList) {
- ctx->Light._Flags |= light->_Flags;
- }
-
- ctx->Light._NeedVertices =
- ((ctx->Light._Flags & (LIGHT_POSITIONAL|LIGHT_SPOT)) ||
- ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR ||
- ctx->Light.Model.LocalViewer);
-
- ctx->Light._NeedEyeCoords = ((ctx->Light._Flags & LIGHT_POSITIONAL) ||
- ctx->Light.Model.LocalViewer);
-
- /* XXX: This test is overkill & needs to be fixed both for software and
- * hardware t&l drivers. The above should be sufficient & should
- * be tested to verify this.
- */
- if (ctx->Light._NeedVertices)
- ctx->Light._NeedEyeCoords = GL_TRUE;
-
- /* Precompute some shading values. Although we reference
- * Light.Material here, we can get away without flushing
- * FLUSH_UPDATE_CURRENT, as when any outstanding material changes
- * are flushed, they will update the derived state at that time.
- */
- if (ctx->Light.Model.TwoSide)
- _mesa_update_material(ctx,
- MAT_BIT_FRONT_EMISSION |
- MAT_BIT_FRONT_AMBIENT |
- MAT_BIT_FRONT_DIFFUSE |
- MAT_BIT_FRONT_SPECULAR |
- MAT_BIT_BACK_EMISSION |
- MAT_BIT_BACK_AMBIENT |
- MAT_BIT_BACK_DIFFUSE |
- MAT_BIT_BACK_SPECULAR);
- else
- _mesa_update_material(ctx,
- MAT_BIT_FRONT_EMISSION |
- MAT_BIT_FRONT_AMBIENT |
- MAT_BIT_FRONT_DIFFUSE |
- MAT_BIT_FRONT_SPECULAR);
-}
-
-
-/**
- * Update state derived from light position, spot direction.
- * Called upon:
- * _NEW_MODELVIEW
- * _NEW_LIGHT
- * _TNL_NEW_NEED_EYE_COORDS
- *
- * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled.
- * Also update on lighting space changes.
- */
-static void
-compute_light_positions( struct gl_context *ctx )
-{
- struct gl_light *light;
- static const GLfloat eye_z[3] = { 0, 0, 1 };
-
- if (!ctx->Light.Enabled)
- return;
-
- if (ctx->_NeedEyeCoords) {
- COPY_3V( ctx->_EyeZDir, eye_z );
- }
- else {
- TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelviewMatrixStack.Top->m );
- }
-
- foreach (light, &ctx->Light.EnabledList) {
-
- if (ctx->_NeedEyeCoords) {
- /* _Position is in eye coordinate space */
- COPY_4FV( light->_Position, light->EyePosition );
- }
- else {
- /* _Position is in object coordinate space */
- TRANSFORM_POINT( light->_Position, ctx->ModelviewMatrixStack.Top->inv,
- light->EyePosition );
- }
-
- if (!(light->_Flags & LIGHT_POSITIONAL)) {
- /* VP (VP) = Normalize( Position ) */
- COPY_3V( light->_VP_inf_norm, light->_Position );
- NORMALIZE_3FV( light->_VP_inf_norm );
-
- if (!ctx->Light.Model.LocalViewer) {
- /* _h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
- ADD_3V( light->_h_inf_norm, light->_VP_inf_norm, ctx->_EyeZDir);
- NORMALIZE_3FV( light->_h_inf_norm );
- }
- light->_VP_inf_spot_attenuation = 1.0;
- }
- else {
- /* positional light w/ homogeneous coordinate, divide by W */
- GLfloat wInv = (GLfloat)1.0 / light->_Position[3];
- light->_Position[0] *= wInv;
- light->_Position[1] *= wInv;
- light->_Position[2] *= wInv;
- }
-
- if (light->_Flags & LIGHT_SPOT) {
- /* Note: we normalize the spot direction now */
-
- if (ctx->_NeedEyeCoords) {
- COPY_3V( light->_NormSpotDirection, light->SpotDirection );
- NORMALIZE_3FV( light->_NormSpotDirection );
- }
- else {
- GLfloat spotDir[3];
- COPY_3V(spotDir, light->SpotDirection);
- NORMALIZE_3FV(spotDir);
- TRANSFORM_NORMAL( light->_NormSpotDirection,
- spotDir,
- ctx->ModelviewMatrixStack.Top->m);
- }
-
- NORMALIZE_3FV( light->_NormSpotDirection );
-
- if (!(light->_Flags & LIGHT_POSITIONAL)) {
- GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm,
- light->_NormSpotDirection);
-
- if (PV_dot_dir > light->_CosCutoff) {
- double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
- int k = (int) x;
- light->_VP_inf_spot_attenuation =
- (GLfloat) (light->_SpotExpTable[k][0] +
- (x-k)*light->_SpotExpTable[k][1]);
- }
- else {
- light->_VP_inf_spot_attenuation = 0;
- }
- }
- }
- }
-}
-
-
-
-static void
-update_modelview_scale( struct gl_context *ctx )
-{
- ctx->_ModelViewInvScale = 1.0F;
- if (!_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top)) {
- const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv;
- GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
- if (f < 1e-12) f = 1.0;
- if (ctx->_NeedEyeCoords)
- ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f);
- else
- ctx->_ModelViewInvScale = (GLfloat) SQRTF(f);
- }
-}
-
-
-/**
- * Bring up to date any state that relies on _NeedEyeCoords.
- */
-void
-_mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state )
-{
- const GLuint oldneedeyecoords = ctx->_NeedEyeCoords;
-
- (void) new_state;
- ctx->_NeedEyeCoords = GL_FALSE;
-
- if (ctx->_ForceEyeCoords ||
- (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD) ||
- ctx->Point._Attenuated ||
- ctx->Light._NeedEyeCoords)
- ctx->_NeedEyeCoords = GL_TRUE;
-
- if (ctx->Light.Enabled &&
- !_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top))
- ctx->_NeedEyeCoords = GL_TRUE;
-
- /* Check if the truth-value interpretations of the bitfields have
- * changed:
- */
- if (oldneedeyecoords != ctx->_NeedEyeCoords) {
- /* Recalculate all state that depends on _NeedEyeCoords.
- */
- update_modelview_scale(ctx);
- compute_light_positions( ctx );
-
- if (ctx->Driver.LightingSpaceChange)
- ctx->Driver.LightingSpaceChange( ctx );
- }
- else {
- GLuint new_state2 = ctx->NewState;
-
- /* Recalculate that same state only if it has been invalidated
- * by other statechanges.
- */
- if (new_state2 & _NEW_MODELVIEW)
- update_modelview_scale(ctx);
-
- if (new_state2 & (_NEW_LIGHT|_NEW_MODELVIEW))
- compute_light_positions( ctx );
- }
-}
-
-
-/**
- * Drivers may need this if the hardware tnl unit doesn't support the
- * light-in-modelspace optimization. It's also useful for debugging.
- */
-void
-_mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag )
-{
- ctx->_ForceEyeCoords = !flag;
- ctx->NewState |= _NEW_POINT; /* one of the bits from
- * _MESA_NEW_NEED_EYE_COORDS.
- */
-}
-
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-/**
- * Initialize the n-th light data structure.
- *
- * \param l pointer to the gl_light structure to be initialized.
- * \param n number of the light.
- * \note The defaults for light 0 are different than the other lights.
- */
-static void
-init_light( struct gl_light *l, GLuint n )
-{
- make_empty_list( l );
-
- ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
- if (n==0) {
- ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
- ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
- }
- else {
- ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
- ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
- }
- ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
- ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 );
- l->SpotExponent = 0.0;
- _mesa_invalidate_spot_exp_table( l );
- l->SpotCutoff = 180.0;
- l->_CosCutoffNeg = -1.0f;
- l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
- l->ConstantAttenuation = 1.0;
- l->LinearAttenuation = 0.0;
- l->QuadraticAttenuation = 0.0;
- l->Enabled = GL_FALSE;
-}
-
-
-/**
- * Initialize the light model data structure.
- *
- * \param lm pointer to the gl_lightmodel structure to be initialized.
- */
-static void
-init_lightmodel( struct gl_lightmodel *lm )
-{
- ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
- lm->LocalViewer = GL_FALSE;
- lm->TwoSide = GL_FALSE;
- lm->ColorControl = GL_SINGLE_COLOR;
-}
-
-
-/**
- * Initialize the material data structure.
- *
- * \param m pointer to the gl_material structure to be initialized.
- */
-static void
-init_material( struct gl_material *m )
-{
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
-
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
-}
-
-
-/**
- * Initialize all lighting state for the given context.
- */
-void
-_mesa_init_lighting( struct gl_context *ctx )
-{
- GLuint i;
-
- /* Lighting group */
- for (i = 0; i < MAX_LIGHTS; i++) {
- init_light( &ctx->Light.Light[i], i );
- }
- make_empty_list( &ctx->Light.EnabledList );
-
- init_lightmodel( &ctx->Light.Model );
- init_material( &ctx->Light.Material );
- ctx->Light.ShadeModel = GL_SMOOTH;
- ctx->Light.ProvokingVertex = GL_LAST_VERTEX_CONVENTION_EXT;
- ctx->Light.Enabled = GL_FALSE;
- ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
- ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
- ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
- GL_FRONT_AND_BACK,
- GL_AMBIENT_AND_DIFFUSE, ~0,
- NULL );
-
- ctx->Light.ColorMaterialEnabled = GL_FALSE;
- ctx->Light.ClampVertexColor = GL_TRUE;
-
- /* Lighting miscellaneous */
- ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
- make_empty_list( ctx->_ShineTabList );
- /* Allocate 10 (arbitrary) shininess lookup tables */
- for (i = 0 ; i < 10 ; i++) {
- struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
- s->shininess = -1;
- s->refcount = 0;
- insert_at_tail( ctx->_ShineTabList, s );
- }
-
- /* Miscellaneous */
- ctx->Light._NeedEyeCoords = GL_FALSE;
- ctx->_NeedEyeCoords = GL_FALSE;
- ctx->_ForceEyeCoords = GL_FALSE;
- ctx->_ModelViewInvScale = 1.0;
-}
-
-
-/**
- * Deallocate malloc'd lighting state attached to given context.
- */
-void
-_mesa_free_lighting_data( struct gl_context *ctx )
-{
- struct gl_shine_tab *s, *tmps;
-
- /* Free lighting shininess exponentiation table */
- foreach_s( s, tmps, ctx->_ShineTabList ) {
- free( s );
- }
- free( ctx->_ShineTabList );
-}
+/* + * Mesa 3-D graphics library + * Version: 7.5 + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. 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 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include "glheader.h" +#include "imports.h" +#include "context.h" +#include "enums.h" +#include "light.h" +#include "macros.h" +#include "simple_list.h" +#include "mtypes.h" +#include "math/m_matrix.h" + + +void GLAPIENTRY +_mesa_ShadeModel( GLenum mode ) +{ + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (MESA_VERBOSE & VERBOSE_API) + _mesa_debug(ctx, "glShadeModel %s\n", _mesa_lookup_enum_by_nr(mode)); + + if (mode != GL_FLAT && mode != GL_SMOOTH) { + _mesa_error(ctx, GL_INVALID_ENUM, "glShadeModel"); + return; + } + + if (ctx->Light.ShadeModel == mode) + return; + + FLUSH_VERTICES(ctx, _NEW_LIGHT); + ctx->Light.ShadeModel = mode; + if (mode == GL_FLAT) + ctx->_TriangleCaps |= DD_FLATSHADE; + else + ctx->_TriangleCaps &= ~DD_FLATSHADE; + + if (ctx->Driver.ShadeModel) + ctx->Driver.ShadeModel( ctx, mode ); +} + + +/** + * Set the provoking vertex (the vertex which specifies the prim's + * color when flat shading) to either the first or last vertex of the + * triangle or line. + */ +void GLAPIENTRY +_mesa_ProvokingVertexEXT(GLenum mode) +{ + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (MESA_VERBOSE&VERBOSE_API) + _mesa_debug(ctx, "glProvokingVertexEXT 0x%x\n", mode); + + switch (mode) { + case GL_FIRST_VERTEX_CONVENTION_EXT: + case GL_LAST_VERTEX_CONVENTION_EXT: + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glProvokingVertexEXT(0x%x)", mode); + return; + } + + if (ctx->Light.ProvokingVertex == mode) + return; + + FLUSH_VERTICES(ctx, _NEW_LIGHT); + ctx->Light.ProvokingVertex = mode; +} + + +/** + * Helper function called by _mesa_Lightfv and _mesa_PopAttrib to set + * per-light state. + * For GL_POSITION and GL_SPOT_DIRECTION the params position/direction + * will have already been transformed by the modelview matrix! + * Also, all error checking should have already been done. + */ +void +_mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params) +{ + struct gl_light *light; + + ASSERT(lnum < MAX_LIGHTS); + light = &ctx->Light.Light[lnum]; + + switch (pname) { + case GL_AMBIENT: + if (TEST_EQ_4V(light->Ambient, params)) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + COPY_4V( light->Ambient, params ); + break; + case GL_DIFFUSE: + if (TEST_EQ_4V(light->Diffuse, params)) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + COPY_4V( light->Diffuse, params ); + break; + case GL_SPECULAR: + if (TEST_EQ_4V(light->Specular, params)) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + COPY_4V( light->Specular, params ); + break; + case GL_POSITION: + /* NOTE: position has already been transformed by ModelView! */ + if (TEST_EQ_4V(light->EyePosition, params)) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + COPY_4V(light->EyePosition, params); + if (light->EyePosition[3] != 0.0F) + light->_Flags |= LIGHT_POSITIONAL; + else + light->_Flags &= ~LIGHT_POSITIONAL; + break; + case GL_SPOT_DIRECTION: + /* NOTE: Direction already transformed by inverse ModelView! */ + if (TEST_EQ_3V(light->SpotDirection, params)) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + COPY_3V(light->SpotDirection, params); + break; + case GL_SPOT_EXPONENT: + ASSERT(params[0] >= 0.0); + ASSERT(params[0] <= ctx->Const.MaxSpotExponent); + if (light->SpotExponent == params[0]) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + light->SpotExponent = params[0]; + _mesa_invalidate_spot_exp_table(light); + break; + case GL_SPOT_CUTOFF: + ASSERT(params[0] == 180.0 || (params[0] >= 0.0 && params[0] <= 90.0)); + if (light->SpotCutoff == params[0]) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + light->SpotCutoff = params[0]; + light->_CosCutoffNeg = (GLfloat) (cos(light->SpotCutoff * DEG2RAD)); + if (light->_CosCutoffNeg < 0) + light->_CosCutoff = 0; + else + light->_CosCutoff = light->_CosCutoffNeg; + if (light->SpotCutoff != 180.0F) + light->_Flags |= LIGHT_SPOT; + else + light->_Flags &= ~LIGHT_SPOT; + break; + case GL_CONSTANT_ATTENUATION: + ASSERT(params[0] >= 0.0); + if (light->ConstantAttenuation == params[0]) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + light->ConstantAttenuation = params[0]; + break; + case GL_LINEAR_ATTENUATION: + ASSERT(params[0] >= 0.0); + if (light->LinearAttenuation == params[0]) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + light->LinearAttenuation = params[0]; + break; + case GL_QUADRATIC_ATTENUATION: + ASSERT(params[0] >= 0.0); + if (light->QuadraticAttenuation == params[0]) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + light->QuadraticAttenuation = params[0]; + break; + default: + _mesa_problem(ctx, "Unexpected pname in _mesa_light()"); + return; + } + + if (ctx->Driver.Lightfv) + ctx->Driver.Lightfv( ctx, GL_LIGHT0 + lnum, pname, params ); +} + + +void GLAPIENTRY +_mesa_Lightf( GLenum light, GLenum pname, GLfloat param ) +{ + GLfloat fparam[4]; + fparam[0] = param; + fparam[1] = fparam[2] = fparam[3] = 0.0F; + _mesa_Lightfv( light, pname, fparam ); +} + + +void GLAPIENTRY +_mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params ) +{ + GET_CURRENT_CONTEXT(ctx); + GLint i = (GLint) (light - GL_LIGHT0); + GLfloat temp[4]; + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (i < 0 || i >= (GLint) ctx->Const.MaxLights) { + _mesa_error( ctx, GL_INVALID_ENUM, "glLight(light=0x%x)", light ); + return; + } + + /* do particular error checks, transformations */ + switch (pname) { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + /* nothing */ + break; + case GL_POSITION: + /* transform position by ModelView matrix */ + TRANSFORM_POINT(temp, ctx->ModelviewMatrixStack.Top->m, params); + params = temp; + break; + case GL_SPOT_DIRECTION: + /* transform direction by inverse modelview */ + if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) { + _math_matrix_analyse(ctx->ModelviewMatrixStack.Top); + } + TRANSFORM_DIRECTION(temp, params, ctx->ModelviewMatrixStack.Top->m); + params = temp; + break; + case GL_SPOT_EXPONENT: + if (params[0] < 0.0 || params[0] > ctx->Const.MaxSpotExponent) { + _mesa_error(ctx, GL_INVALID_VALUE, "glLight"); + return; + } + break; + case GL_SPOT_CUTOFF: + if ((params[0] < 0.0 || params[0] > 90.0) && params[0] != 180.0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glLight"); + return; + } + break; + case GL_CONSTANT_ATTENUATION: + if (params[0] < 0.0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glLight"); + return; + } + break; + case GL_LINEAR_ATTENUATION: + if (params[0] < 0.0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glLight"); + return; + } + break; + case GL_QUADRATIC_ATTENUATION: + if (params[0] < 0.0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glLight"); + return; + } + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glLight(pname=0x%x)", pname); + return; + } + + _mesa_light(ctx, i, pname, params); +} + + +void GLAPIENTRY +_mesa_Lighti( GLenum light, GLenum pname, GLint param ) +{ + GLint iparam[4]; + iparam[0] = param; + iparam[1] = iparam[2] = iparam[3] = 0; + _mesa_Lightiv( light, pname, iparam ); +} + + +void GLAPIENTRY +_mesa_Lightiv( GLenum light, GLenum pname, const GLint *params ) +{ + GLfloat fparam[4]; + + switch (pname) { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + fparam[0] = INT_TO_FLOAT( params[0] ); + fparam[1] = INT_TO_FLOAT( params[1] ); + fparam[2] = INT_TO_FLOAT( params[2] ); + fparam[3] = INT_TO_FLOAT( params[3] ); + break; + case GL_POSITION: + fparam[0] = (GLfloat) params[0]; + fparam[1] = (GLfloat) params[1]; + fparam[2] = (GLfloat) params[2]; + fparam[3] = (GLfloat) params[3]; + break; + case GL_SPOT_DIRECTION: + fparam[0] = (GLfloat) params[0]; + fparam[1] = (GLfloat) params[1]; + fparam[2] = (GLfloat) params[2]; + break; + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + fparam[0] = (GLfloat) params[0]; + break; + default: + /* error will be caught later in gl_Lightfv */ + ; + } + + _mesa_Lightfv( light, pname, fparam ); +} + + + +void GLAPIENTRY +_mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params ) +{ + GET_CURRENT_CONTEXT(ctx); + GLint l = (GLint) (light - GL_LIGHT0); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (l < 0 || l >= (GLint) ctx->Const.MaxLights) { + _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" ); + return; + } + + switch (pname) { + case GL_AMBIENT: + COPY_4V( params, ctx->Light.Light[l].Ambient ); + break; + case GL_DIFFUSE: + COPY_4V( params, ctx->Light.Light[l].Diffuse ); + break; + case GL_SPECULAR: + COPY_4V( params, ctx->Light.Light[l].Specular ); + break; + case GL_POSITION: + COPY_4V( params, ctx->Light.Light[l].EyePosition ); + break; + case GL_SPOT_DIRECTION: + COPY_3V( params, ctx->Light.Light[l].SpotDirection ); + break; + case GL_SPOT_EXPONENT: + params[0] = ctx->Light.Light[l].SpotExponent; + break; + case GL_SPOT_CUTOFF: + params[0] = ctx->Light.Light[l].SpotCutoff; + break; + case GL_CONSTANT_ATTENUATION: + params[0] = ctx->Light.Light[l].ConstantAttenuation; + break; + case GL_LINEAR_ATTENUATION: + params[0] = ctx->Light.Light[l].LinearAttenuation; + break; + case GL_QUADRATIC_ATTENUATION: + params[0] = ctx->Light.Light[l].QuadraticAttenuation; + break; + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" ); + break; + } +} + + +void GLAPIENTRY +_mesa_GetLightiv( GLenum light, GLenum pname, GLint *params ) +{ + GET_CURRENT_CONTEXT(ctx); + GLint l = (GLint) (light - GL_LIGHT0); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (l < 0 || l >= (GLint) ctx->Const.MaxLights) { + _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" ); + return; + } + + switch (pname) { + case GL_AMBIENT: + params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]); + params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]); + params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]); + params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]); + break; + case GL_DIFFUSE: + params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]); + params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]); + params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]); + params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]); + break; + case GL_SPECULAR: + params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]); + params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]); + params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]); + params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]); + break; + case GL_POSITION: + params[0] = (GLint) ctx->Light.Light[l].EyePosition[0]; + params[1] = (GLint) ctx->Light.Light[l].EyePosition[1]; + params[2] = (GLint) ctx->Light.Light[l].EyePosition[2]; + params[3] = (GLint) ctx->Light.Light[l].EyePosition[3]; + break; + case GL_SPOT_DIRECTION: + params[0] = (GLint) ctx->Light.Light[l].SpotDirection[0]; + params[1] = (GLint) ctx->Light.Light[l].SpotDirection[1]; + params[2] = (GLint) ctx->Light.Light[l].SpotDirection[2]; + break; + case GL_SPOT_EXPONENT: + params[0] = (GLint) ctx->Light.Light[l].SpotExponent; + break; + case GL_SPOT_CUTOFF: + params[0] = (GLint) ctx->Light.Light[l].SpotCutoff; + break; + case GL_CONSTANT_ATTENUATION: + params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation; + break; + case GL_LINEAR_ATTENUATION: + params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation; + break; + case GL_QUADRATIC_ATTENUATION: + params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation; + break; + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" ); + break; + } +} + + + +/**********************************************************************/ +/*** Light Model ***/ +/**********************************************************************/ + + +void GLAPIENTRY +_mesa_LightModelfv( GLenum pname, const GLfloat *params ) +{ + GLenum newenum; + GLboolean newbool; + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + switch (pname) { + case GL_LIGHT_MODEL_AMBIENT: + if (TEST_EQ_4V( ctx->Light.Model.Ambient, params )) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + COPY_4V( ctx->Light.Model.Ambient, params ); + break; + case GL_LIGHT_MODEL_LOCAL_VIEWER: + newbool = (params[0]!=0.0); + if (ctx->Light.Model.LocalViewer == newbool) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + ctx->Light.Model.LocalViewer = newbool; + break; + case GL_LIGHT_MODEL_TWO_SIDE: + newbool = (params[0]!=0.0); + if (ctx->Light.Model.TwoSide == newbool) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + ctx->Light.Model.TwoSide = newbool; + if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) + ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE; + else + ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE; + break; + case GL_LIGHT_MODEL_COLOR_CONTROL: + if (params[0] == (GLfloat) GL_SINGLE_COLOR) + newenum = GL_SINGLE_COLOR; + else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR) + newenum = GL_SEPARATE_SPECULAR_COLOR; + else { + _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(param=0x0%x)", + (GLint) params[0] ); + return; + } + if (ctx->Light.Model.ColorControl == newenum) + return; + FLUSH_VERTICES(ctx, _NEW_LIGHT); + ctx->Light.Model.ColorControl = newenum; + break; + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname ); + break; + } + + if (ctx->Driver.LightModelfv) + ctx->Driver.LightModelfv( ctx, pname, params ); +} + + +void GLAPIENTRY +_mesa_LightModeliv( GLenum pname, const GLint *params ) +{ + GLfloat fparam[4]; + + switch (pname) { + case GL_LIGHT_MODEL_AMBIENT: + fparam[0] = INT_TO_FLOAT( params[0] ); + fparam[1] = INT_TO_FLOAT( params[1] ); + fparam[2] = INT_TO_FLOAT( params[2] ); + fparam[3] = INT_TO_FLOAT( params[3] ); + break; + case GL_LIGHT_MODEL_LOCAL_VIEWER: + case GL_LIGHT_MODEL_TWO_SIDE: + case GL_LIGHT_MODEL_COLOR_CONTROL: + fparam[0] = (GLfloat) params[0]; + break; + default: + /* Error will be caught later in gl_LightModelfv */ + ASSIGN_4V(fparam, 0.0F, 0.0F, 0.0F, 0.0F); + } + _mesa_LightModelfv( pname, fparam ); +} + + +void GLAPIENTRY +_mesa_LightModeli( GLenum pname, GLint param ) +{ + GLint iparam[4]; + iparam[0] = param; + iparam[1] = iparam[2] = iparam[3] = 0; + _mesa_LightModeliv( pname, iparam ); +} + + +void GLAPIENTRY +_mesa_LightModelf( GLenum pname, GLfloat param ) +{ + GLfloat fparam[4]; + fparam[0] = param; + fparam[1] = fparam[2] = fparam[3] = 0.0F; + _mesa_LightModelfv( pname, fparam ); +} + + + +/********** MATERIAL **********/ + + +/* + * Given a face and pname value (ala glColorMaterial), compute a bitmask + * of the targeted material values. + */ +GLuint +_mesa_material_bitmask( struct gl_context *ctx, GLenum face, GLenum pname, + GLuint legal, const char *where ) +{ + GLuint bitmask = 0; + + /* Make a bitmask indicating what material attribute(s) we're updating */ + switch (pname) { + case GL_EMISSION: + bitmask |= MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION; + break; + case GL_AMBIENT: + bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT; + break; + case GL_DIFFUSE: + bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE; + break; + case GL_SPECULAR: + bitmask |= MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR; + break; + case GL_SHININESS: + bitmask |= MAT_BIT_FRONT_SHININESS | MAT_BIT_BACK_SHININESS; + break; + case GL_AMBIENT_AND_DIFFUSE: + bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT; + bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE; + break; + case GL_COLOR_INDEXES: + bitmask |= MAT_BIT_FRONT_INDEXES | MAT_BIT_BACK_INDEXES; + break; + default: + _mesa_error( ctx, GL_INVALID_ENUM, "%s", where ); + return 0; + } + + if (face==GL_FRONT) { + bitmask &= FRONT_MATERIAL_BITS; + } + else if (face==GL_BACK) { + bitmask &= BACK_MATERIAL_BITS; + } + else if (face != GL_FRONT_AND_BACK) { + _mesa_error( ctx, GL_INVALID_ENUM, "%s", where ); + return 0; + } + + if (bitmask & ~legal) { + _mesa_error( ctx, GL_INVALID_ENUM, "%s", where ); + return 0; + } + + return bitmask; +} + + + +/* Perform a straight copy between materials. + */ +void +_mesa_copy_materials( struct gl_material *dst, + const struct gl_material *src, + GLuint bitmask ) +{ + int i; + + for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) + if (bitmask & (1<<i)) + COPY_4FV( dst->Attrib[i], src->Attrib[i] ); +} + + + +/* Update derived values following a change in ctx->Light.Material + */ +void +_mesa_update_material( struct gl_context *ctx, GLuint bitmask ) +{ + struct gl_light *light, *list = &ctx->Light.EnabledList; + GLfloat (*mat)[4] = ctx->Light.Material.Attrib; + + if (MESA_VERBOSE & VERBOSE_MATERIAL) + _mesa_debug(ctx, "_mesa_update_material, mask 0x%x\n", bitmask); + + if (!bitmask) + return; + + /* update material ambience */ + if (bitmask & MAT_BIT_FRONT_AMBIENT) { + foreach (light, list) { + SCALE_3V( light->_MatAmbient[0], light->Ambient, + mat[MAT_ATTRIB_FRONT_AMBIENT]); + } + } + + if (bitmask & MAT_BIT_BACK_AMBIENT) { + foreach (light, list) { + SCALE_3V( light->_MatAmbient[1], light->Ambient, + mat[MAT_ATTRIB_BACK_AMBIENT]); + } + } + + /* update BaseColor = emission + scene's ambience * material's ambience */ + if (bitmask & (MAT_BIT_FRONT_EMISSION | MAT_BIT_FRONT_AMBIENT)) { + COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] ); + ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT], + ctx->Light.Model.Ambient ); + } + + if (bitmask & (MAT_BIT_BACK_EMISSION | MAT_BIT_BACK_AMBIENT)) { + COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] ); + ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT], + ctx->Light.Model.Ambient ); + } + + /* update material diffuse values */ + if (bitmask & MAT_BIT_FRONT_DIFFUSE) { + foreach (light, list) { + SCALE_3V( light->_MatDiffuse[0], light->Diffuse, + mat[MAT_ATTRIB_FRONT_DIFFUSE] ); + } + } + + if (bitmask & MAT_BIT_BACK_DIFFUSE) { + foreach (light, list) { + SCALE_3V( light->_MatDiffuse[1], light->Diffuse, + mat[MAT_ATTRIB_BACK_DIFFUSE] ); + } + } + + /* update material specular values */ + if (bitmask & MAT_BIT_FRONT_SPECULAR) { + foreach (light, list) { + SCALE_3V( light->_MatSpecular[0], light->Specular, + mat[MAT_ATTRIB_FRONT_SPECULAR]); + } + } + + if (bitmask & MAT_BIT_BACK_SPECULAR) { + foreach (light, list) { + SCALE_3V( light->_MatSpecular[1], light->Specular, + mat[MAT_ATTRIB_BACK_SPECULAR]); + } + } + + if (bitmask & MAT_BIT_FRONT_SHININESS) { + _mesa_invalidate_shine_table( ctx, 0 ); + } + + if (bitmask & MAT_BIT_BACK_SHININESS) { + _mesa_invalidate_shine_table( ctx, 1 ); + } +} + + +/* + * Update the current materials from the given rgba color + * according to the bitmask in ColorMaterialBitmask, which is + * set by glColorMaterial(). + */ +void +_mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] ) +{ + GLuint bitmask = ctx->Light.ColorMaterialBitmask; + struct gl_material *mat = &ctx->Light.Material; + int i; + + for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) + if (bitmask & (1<<i)) + COPY_4FV( mat->Attrib[i], color ); + + _mesa_update_material( ctx, bitmask ); +} + + +void GLAPIENTRY +_mesa_ColorMaterial( GLenum face, GLenum mode ) +{ + GET_CURRENT_CONTEXT(ctx); + GLuint bitmask; + GLuint legal = (MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION | + MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR | + MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE | + MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (MESA_VERBOSE&VERBOSE_API) + _mesa_debug(ctx, "glColorMaterial %s %s\n", + _mesa_lookup_enum_by_nr(face), + _mesa_lookup_enum_by_nr(mode)); + + bitmask = _mesa_material_bitmask(ctx, face, mode, legal, "glColorMaterial"); + + if (ctx->Light.ColorMaterialBitmask == bitmask && + ctx->Light.ColorMaterialFace == face && + ctx->Light.ColorMaterialMode == mode) + return; + + FLUSH_VERTICES(ctx, _NEW_LIGHT); + ctx->Light.ColorMaterialBitmask = bitmask; + ctx->Light.ColorMaterialFace = face; + ctx->Light.ColorMaterialMode = mode; + + if (ctx->Light.ColorMaterialEnabled) { + FLUSH_CURRENT( ctx, 0 ); + _mesa_update_color_material(ctx,ctx->Current.Attrib[VERT_ATTRIB_COLOR0]); + } + + if (ctx->Driver.ColorMaterial) + ctx->Driver.ColorMaterial( ctx, face, mode ); +} + + +void GLAPIENTRY +_mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params ) +{ + GET_CURRENT_CONTEXT(ctx); + GLuint f; + GLfloat (*mat)[4] = ctx->Light.Material.Attrib; + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */ + + FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */ + + if (face==GL_FRONT) { + f = 0; + } + else if (face==GL_BACK) { + f = 1; + } + else { + _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(face)" ); + return; + } + + switch (pname) { + case GL_AMBIENT: + COPY_4FV( params, mat[MAT_ATTRIB_AMBIENT(f)] ); + break; + case GL_DIFFUSE: + COPY_4FV( params, mat[MAT_ATTRIB_DIFFUSE(f)] ); + break; + case GL_SPECULAR: + COPY_4FV( params, mat[MAT_ATTRIB_SPECULAR(f)] ); + break; + case GL_EMISSION: + COPY_4FV( params, mat[MAT_ATTRIB_EMISSION(f)] ); + break; + case GL_SHININESS: + *params = mat[MAT_ATTRIB_SHININESS(f)][0]; + break; + case GL_COLOR_INDEXES: + params[0] = mat[MAT_ATTRIB_INDEXES(f)][0]; + params[1] = mat[MAT_ATTRIB_INDEXES(f)][1]; + params[2] = mat[MAT_ATTRIB_INDEXES(f)][2]; + break; + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" ); + } +} + + +void GLAPIENTRY +_mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) +{ + GET_CURRENT_CONTEXT(ctx); + GLuint f; + GLfloat (*mat)[4] = ctx->Light.Material.Attrib; + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */ + + FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */ + + if (face==GL_FRONT) { + f = 0; + } + else if (face==GL_BACK) { + f = 1; + } + else { + _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialiv(face)" ); + return; + } + switch (pname) { + case GL_AMBIENT: + params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][0] ); + params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][1] ); + params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][2] ); + params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][3] ); + break; + case GL_DIFFUSE: + params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][0] ); + params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][1] ); + params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][2] ); + params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][3] ); + break; + case GL_SPECULAR: + params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][0] ); + params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][1] ); + params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][2] ); + params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][3] ); + break; + case GL_EMISSION: + params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][0] ); + params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][1] ); + params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][2] ); + params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] ); + break; + case GL_SHININESS: + *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] ); + break; + case GL_COLOR_INDEXES: + params[0] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][0] ); + params[1] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][1] ); + params[2] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][2] ); + break; + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" ); + } +} + + + +/**********************************************************************/ +/***** Lighting computation *****/ +/**********************************************************************/ + + +/* + * Notes: + * When two-sided lighting is enabled we compute the color (or index) + * for both the front and back side of the primitive. Then, when the + * orientation of the facet is later learned, we can determine which + * color (or index) to use for rendering. + * + * KW: We now know orientation in advance and only shade for + * the side or sides which are actually required. + * + * Variables: + * n = normal vector + * V = vertex position + * P = light source position + * Pe = (0,0,0,1) + * + * Precomputed: + * IF P[3]==0 THEN + * // light at infinity + * IF local_viewer THEN + * _VP_inf_norm = unit vector from V to P // Precompute + * ELSE + * // eye at infinity + * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute + * ENDIF + * ENDIF + * + * Functions: + * Normalize( v ) = normalized vector v + * Magnitude( v ) = length of vector v + */ + + + +/* + * Whenever the spotlight exponent for a light changes we must call + * this function to recompute the exponent lookup table. + */ +void +_mesa_invalidate_spot_exp_table( struct gl_light *l ) +{ + l->_SpotExpTable[0][0] = -1; +} + + +static void +validate_spot_exp_table( struct gl_light *l ) +{ + GLint i; + GLdouble exponent = l->SpotExponent; + GLdouble tmp = 0; + GLint clamp = 0; + + l->_SpotExpTable[0][0] = 0.0; + + for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) { + if (clamp == 0) { + tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent); + if (tmp < FLT_MIN * 100.0) { + tmp = 0.0; + clamp = 1; + } + } + l->_SpotExpTable[i][0] = (GLfloat) tmp; + } + for (i = 0; i < EXP_TABLE_SIZE - 1; i++) { + l->_SpotExpTable[i][1] = (l->_SpotExpTable[i+1][0] - + l->_SpotExpTable[i][0]); + } + l->_SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0; +} + + + +/* Calculate a new shine table. Doing this here saves a branch in + * lighting, and the cost of doing it early may be partially offset + * by keeping a MRU cache of shine tables for various shine values. + */ +void +_mesa_invalidate_shine_table( struct gl_context *ctx, GLuint side ) +{ + ASSERT(side < 2); + if (ctx->_ShineTable[side]) + ctx->_ShineTable[side]->refcount--; + ctx->_ShineTable[side] = NULL; +} + + +static void +validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess ) +{ + struct gl_shine_tab *list = ctx->_ShineTabList; + struct gl_shine_tab *s; + + ASSERT(side < 2); + + foreach(s, list) + if ( s->shininess == shininess ) + break; + + if (s == list) { + GLint j; + GLfloat *m; + + foreach(s, list) + if (s->refcount == 0) + break; + + m = s->tab; + m[0] = 0.0; + if (shininess == 0.0) { + for (j = 1 ; j <= SHINE_TABLE_SIZE ; j++) + m[j] = 1.0; + } + else { + for (j = 1 ; j < SHINE_TABLE_SIZE ; j++) { + GLdouble t, x = j / (GLfloat) (SHINE_TABLE_SIZE - 1); + if (x < 0.005) /* underflow check */ + x = 0.005; + t = pow(x, shininess); + if (t > 1e-20) + m[j] = (GLfloat) t; + else + m[j] = 0.0; + } + m[SHINE_TABLE_SIZE] = 1.0; + } + + s->shininess = shininess; + } + + if (ctx->_ShineTable[side]) + ctx->_ShineTable[side]->refcount--; + + ctx->_ShineTable[side] = s; + move_to_tail( list, s ); + s->refcount++; +} + + +void +_mesa_validate_all_lighting_tables( struct gl_context *ctx ) +{ + GLuint i; + GLfloat shininess; + + shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0]; + if (!ctx->_ShineTable[0] || ctx->_ShineTable[0]->shininess != shininess) + validate_shine_table( ctx, 0, shininess ); + + shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0]; + if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess) + validate_shine_table( ctx, 1, shininess ); + + for (i = 0; i < ctx->Const.MaxLights; i++) + if (ctx->Light.Light[i]._SpotExpTable[0][0] == -1) + validate_spot_exp_table( &ctx->Light.Light[i] ); +} + + +/** + * Examine current lighting parameters to determine if the optimized lighting + * function can be used. + * Also, precompute some lighting values such as the products of light + * source and material ambient, diffuse and specular coefficients. + */ +void +_mesa_update_lighting( struct gl_context *ctx ) +{ + struct gl_light *light; + ctx->Light._NeedEyeCoords = GL_FALSE; + ctx->Light._Flags = 0; + + if (!ctx->Light.Enabled) + return; + + foreach(light, &ctx->Light.EnabledList) { + ctx->Light._Flags |= light->_Flags; + } + + ctx->Light._NeedVertices = + ((ctx->Light._Flags & (LIGHT_POSITIONAL|LIGHT_SPOT)) || + ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR || + ctx->Light.Model.LocalViewer); + + ctx->Light._NeedEyeCoords = ((ctx->Light._Flags & LIGHT_POSITIONAL) || + ctx->Light.Model.LocalViewer); + + /* XXX: This test is overkill & needs to be fixed both for software and + * hardware t&l drivers. The above should be sufficient & should + * be tested to verify this. + */ + if (ctx->Light._NeedVertices) + ctx->Light._NeedEyeCoords = GL_TRUE; + + /* Precompute some shading values. Although we reference + * Light.Material here, we can get away without flushing + * FLUSH_UPDATE_CURRENT, as when any outstanding material changes + * are flushed, they will update the derived state at that time. + */ + if (ctx->Light.Model.TwoSide) + _mesa_update_material(ctx, + MAT_BIT_FRONT_EMISSION | + MAT_BIT_FRONT_AMBIENT | + MAT_BIT_FRONT_DIFFUSE | + MAT_BIT_FRONT_SPECULAR | + MAT_BIT_BACK_EMISSION | + MAT_BIT_BACK_AMBIENT | + MAT_BIT_BACK_DIFFUSE | + MAT_BIT_BACK_SPECULAR); + else + _mesa_update_material(ctx, + MAT_BIT_FRONT_EMISSION | + MAT_BIT_FRONT_AMBIENT | + MAT_BIT_FRONT_DIFFUSE | + MAT_BIT_FRONT_SPECULAR); +} + + +/** + * Update state derived from light position, spot direction. + * Called upon: + * _NEW_MODELVIEW + * _NEW_LIGHT + * _TNL_NEW_NEED_EYE_COORDS + * + * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled. + * Also update on lighting space changes. + */ +static void +compute_light_positions( struct gl_context *ctx ) +{ + struct gl_light *light; + static const GLfloat eye_z[3] = { 0, 0, 1 }; + + if (!ctx->Light.Enabled) + return; + + if (ctx->_NeedEyeCoords) { + COPY_3V( ctx->_EyeZDir, eye_z ); + } + else { + TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelviewMatrixStack.Top->m ); + } + + /* Make sure all the light tables are updated before the computation */ + _mesa_validate_all_lighting_tables(ctx); + + foreach (light, &ctx->Light.EnabledList) { + + if (ctx->_NeedEyeCoords) { + /* _Position is in eye coordinate space */ + COPY_4FV( light->_Position, light->EyePosition ); + } + else { + /* _Position is in object coordinate space */ + TRANSFORM_POINT( light->_Position, ctx->ModelviewMatrixStack.Top->inv, + light->EyePosition ); + } + + if (!(light->_Flags & LIGHT_POSITIONAL)) { + /* VP (VP) = Normalize( Position ) */ + COPY_3V( light->_VP_inf_norm, light->_Position ); + NORMALIZE_3FV( light->_VP_inf_norm ); + + if (!ctx->Light.Model.LocalViewer) { + /* _h_inf_norm = Normalize( V_to_P + <0,0,1> ) */ + ADD_3V( light->_h_inf_norm, light->_VP_inf_norm, ctx->_EyeZDir); + NORMALIZE_3FV( light->_h_inf_norm ); + } + light->_VP_inf_spot_attenuation = 1.0; + } + else { + /* positional light w/ homogeneous coordinate, divide by W */ + GLfloat wInv = (GLfloat)1.0 / light->_Position[3]; + light->_Position[0] *= wInv; + light->_Position[1] *= wInv; + light->_Position[2] *= wInv; + } + + if (light->_Flags & LIGHT_SPOT) { + /* Note: we normalize the spot direction now */ + + if (ctx->_NeedEyeCoords) { + COPY_3V( light->_NormSpotDirection, light->SpotDirection ); + NORMALIZE_3FV( light->_NormSpotDirection ); + } + else { + GLfloat spotDir[3]; + COPY_3V(spotDir, light->SpotDirection); + NORMALIZE_3FV(spotDir); + TRANSFORM_NORMAL( light->_NormSpotDirection, + spotDir, + ctx->ModelviewMatrixStack.Top->m); + } + + NORMALIZE_3FV( light->_NormSpotDirection ); + + if (!(light->_Flags & LIGHT_POSITIONAL)) { + GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm, + light->_NormSpotDirection); + + if (PV_dot_dir > light->_CosCutoff) { + double x = PV_dot_dir * (EXP_TABLE_SIZE-1); + int k = (int) x; + light->_VP_inf_spot_attenuation = + (GLfloat) (light->_SpotExpTable[k][0] + + (x-k)*light->_SpotExpTable[k][1]); + } + else { + light->_VP_inf_spot_attenuation = 0; + } + } + } + } +} + + + +static void +update_modelview_scale( struct gl_context *ctx ) +{ + ctx->_ModelViewInvScale = 1.0F; + if (!_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top)) { + const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv; + GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10]; + if (f < 1e-12) f = 1.0; + if (ctx->_NeedEyeCoords) + ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f); + else + ctx->_ModelViewInvScale = (GLfloat) SQRTF(f); + } +} + + +/** + * Bring up to date any state that relies on _NeedEyeCoords. + */ +void +_mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state ) +{ + const GLuint oldneedeyecoords = ctx->_NeedEyeCoords; + + (void) new_state; + ctx->_NeedEyeCoords = GL_FALSE; + + if (ctx->_ForceEyeCoords || + (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD) || + ctx->Point._Attenuated || + ctx->Light._NeedEyeCoords) + ctx->_NeedEyeCoords = GL_TRUE; + + if (ctx->Light.Enabled && + !_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top)) + ctx->_NeedEyeCoords = GL_TRUE; + + /* Check if the truth-value interpretations of the bitfields have + * changed: + */ + if (oldneedeyecoords != ctx->_NeedEyeCoords) { + /* Recalculate all state that depends on _NeedEyeCoords. + */ + update_modelview_scale(ctx); + compute_light_positions( ctx ); + + if (ctx->Driver.LightingSpaceChange) + ctx->Driver.LightingSpaceChange( ctx ); + } + else { + GLuint new_state2 = ctx->NewState; + + /* Recalculate that same state only if it has been invalidated + * by other statechanges. + */ + if (new_state2 & _NEW_MODELVIEW) + update_modelview_scale(ctx); + + if (new_state2 & (_NEW_LIGHT|_NEW_MODELVIEW)) + compute_light_positions( ctx ); + } +} + + +/** + * Drivers may need this if the hardware tnl unit doesn't support the + * light-in-modelspace optimization. It's also useful for debugging. + */ +void +_mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag ) +{ + ctx->_ForceEyeCoords = !flag; + ctx->NewState |= _NEW_POINT; /* one of the bits from + * _MESA_NEW_NEED_EYE_COORDS. + */ +} + + + +/**********************************************************************/ +/***** Initialization *****/ +/**********************************************************************/ + +/** + * Initialize the n-th light data structure. + * + * \param l pointer to the gl_light structure to be initialized. + * \param n number of the light. + * \note The defaults for light 0 are different than the other lights. + */ +static void +init_light( struct gl_light *l, GLuint n ) +{ + make_empty_list( l ); + + ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 ); + if (n==0) { + ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 ); + ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 ); + } + else { + ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 ); + ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 ); + } + ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 ); + ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 ); + l->SpotExponent = 0.0; + _mesa_invalidate_spot_exp_table( l ); + l->SpotCutoff = 180.0; + l->_CosCutoffNeg = -1.0f; + l->_CosCutoff = 0.0; /* KW: -ve values not admitted */ + l->ConstantAttenuation = 1.0; + l->LinearAttenuation = 0.0; + l->QuadraticAttenuation = 0.0; + l->Enabled = GL_FALSE; +} + + +/** + * Initialize the light model data structure. + * + * \param lm pointer to the gl_lightmodel structure to be initialized. + */ +static void +init_lightmodel( struct gl_lightmodel *lm ) +{ + ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F ); + lm->LocalViewer = GL_FALSE; + lm->TwoSide = GL_FALSE; + lm->ColorControl = GL_SINGLE_COLOR; +} + + +/** + * Initialize the material data structure. + * + * \param m pointer to the gl_material structure to be initialized. + */ +static void +init_material( struct gl_material *m ) +{ + ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F ); + + ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F ); + ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F ); +} + + +/** + * Initialize all lighting state for the given context. + */ +void +_mesa_init_lighting( struct gl_context *ctx ) +{ + GLuint i; + + /* Lighting group */ + for (i = 0; i < MAX_LIGHTS; i++) { + init_light( &ctx->Light.Light[i], i ); + } + make_empty_list( &ctx->Light.EnabledList ); + + init_lightmodel( &ctx->Light.Model ); + init_material( &ctx->Light.Material ); + ctx->Light.ShadeModel = GL_SMOOTH; + ctx->Light.ProvokingVertex = GL_LAST_VERTEX_CONVENTION_EXT; + ctx->Light.Enabled = GL_FALSE; + ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK; + ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE; + ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx, + GL_FRONT_AND_BACK, + GL_AMBIENT_AND_DIFFUSE, ~0, + NULL ); + + ctx->Light.ColorMaterialEnabled = GL_FALSE; + ctx->Light.ClampVertexColor = GL_TRUE; + + /* Lighting miscellaneous */ + ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab ); + make_empty_list( ctx->_ShineTabList ); + /* Allocate 10 (arbitrary) shininess lookup tables */ + for (i = 0 ; i < 10 ; i++) { + struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab ); + s->shininess = -1; + s->refcount = 0; + insert_at_tail( ctx->_ShineTabList, s ); + } + + /* Miscellaneous */ + ctx->Light._NeedEyeCoords = GL_FALSE; + ctx->_NeedEyeCoords = GL_FALSE; + ctx->_ForceEyeCoords = GL_FALSE; + ctx->_ModelViewInvScale = 1.0; +} + + +/** + * Deallocate malloc'd lighting state attached to given context. + */ +void +_mesa_free_lighting_data( struct gl_context *ctx ) +{ + struct gl_shine_tab *s, *tmps; + + /* Free lighting shininess exponentiation table */ + foreach_s( s, tmps, ctx->_ShineTabList ) { + free( s ); + } + free( ctx->_ShineTabList ); +} diff --git a/mesalib/src/mesa/main/macros.h b/mesalib/src/mesa/main/macros.h index 2a849e36a..dbe5b867c 100644 --- a/mesalib/src/mesa/main/macros.h +++ b/mesalib/src/mesa/main/macros.h @@ -54,6 +54,10 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256]; #define FLOAT_TO_BYTE(X) ( (((GLint) (255.0F * (X))) - 1) / 2 ) +/** Convert GLbyte to GLfloat while preserving zero */ +#define BYTE_TO_FLOATZ(B) ((B) == 0 ? 0.0F : BYTE_TO_FLOAT(B)) + + /** Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0], texture/fb data */ #define BYTE_TO_FLOAT_TEX(B) ((B) == -128 ? -1.0F : (B) * (1.0F/127.0F)) @@ -73,6 +77,9 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256]; /** Convert GLfloat in [-1.0,1.0] to GLshort in [-32768,32767] */ #define FLOAT_TO_SHORT(X) ( (((GLint) (65535.0F * (X))) - 1) / 2 ) +/** Convert GLshort to GLfloat while preserving zero */ +#define SHORT_TO_FLOATZ(S) ((S) == 0 ? 0.0F : SHORT_TO_FLOAT(S)) + /** Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0], texture/fb data */ #define SHORT_TO_FLOAT_TEX(S) ((S) == -32768 ? -1.0F : (S) * (1.0F/32767.0F)) @@ -588,19 +595,6 @@ do { \ */ #define LINTERP(T, OUT, IN) ((OUT) + (T) * ((IN) - (OUT))) -/* Can do better with integer math - */ -#define INTERP_UB( t, dstub, outub, inub ) \ -do { \ - GLfloat inf = UBYTE_TO_FLOAT( inub ); \ - GLfloat outf = UBYTE_TO_FLOAT( outub ); \ - GLfloat dstf = LINTERP( t, outf, inf ); \ - UNCLAMPED_FLOAT_TO_UBYTE( dstub, dstf ); \ -} while (0) - -#define INTERP_UI( t, dstui, outui, inui ) \ - dstui = (GLuint) (GLint) LINTERP( (t), (GLfloat) (outui), (GLfloat) (inui) ) - #define INTERP_F( t, dstf, outf, inf ) \ dstf = LINTERP( t, outf, inf ) @@ -619,16 +613,6 @@ do { \ dst[2] = LINTERP( (t), (out)[2], (in)[2] ); \ } while (0) -#define INTERP_SZ( t, vec, to, out, in, sz ) \ -do { \ - switch (sz) { \ - case 4: vec[to][3] = LINTERP( (t), (vec)[out][3], (vec)[in][3] ); \ - case 3: vec[to][2] = LINTERP( (t), (vec)[out][2], (vec)[in][2] ); \ - case 2: vec[to][1] = LINTERP( (t), (vec)[out][1], (vec)[in][1] ); \ - case 1: vec[to][0] = LINTERP( (t), (vec)[out][0], (vec)[in][0] ); \ - } \ -} while(0) - /*@}*/ @@ -656,9 +640,6 @@ do { \ #define DOT4( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + \ (a)[2]*(b)[2] + (a)[3]*(b)[3] ) -/** Dot product of two 4-element vectors */ -#define DOT4V(v,a,b,c,d) (v[0]*(a) + v[1]*(b) + v[2]*(c) + v[3]*(d)) - /** Cross product of two 3-element vectors */ #define CROSS3(n, u, v) \ @@ -688,6 +669,10 @@ do { \ #define LEN_SQUARED_2FV( V ) ((V)[0]*(V)[0]+(V)[1]*(V)[1]) +/** Compute ceiling of integer quotient of A divided by B. */ +#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 ) + + /** casts to silence warnings with some compilers */ #define ENUM_TO_INT(E) ((GLint)(E)) #define ENUM_TO_FLOAT(E) ((GLfloat)(GLint)(E)) diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index deab97d3e..285ec0783 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -49,18 +49,6 @@ extern "C" { /** - * Stencil buffer data type. - */ -#if STENCIL_BITS==8 - typedef GLubyte GLstencil; -#elif STENCIL_BITS==16 - typedef GLushort GLstencil; -#else -# error "illegal number of stencil bits" -#endif - - -/** * \name 64-bit extension of GLbitfield. */ /*@{*/ @@ -2158,6 +2146,16 @@ struct gl_shader unsigned Version; /**< GLSL version used for linking */ + unsigned num_samplers; /**< Number of samplers used by this shader. + * This field is only set post-linking. + */ + /** + * Number of uniform components used by this shader. + * + * This field is only set post-linking. + */ + unsigned num_uniform_components; + struct exec_list *ir; struct glsl_symbol_table *symbols; diff --git a/mesalib/src/mesa/main/pack.c b/mesalib/src/mesa/main/pack.c index 539a06c9a..6f48a2e7c 100644 --- a/mesalib/src/mesa/main/pack.c +++ b/mesalib/src/mesa/main/pack.c @@ -34,6 +34,7 @@ #include "enums.h" #include "image.h" #include "imports.h" +#include "macros.h" #include "mtypes.h" #include "pack.h" #include "pixeltransfer.h" @@ -43,26 +44,6 @@ /** - * NOTE: - * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when - * we later convert the float to a packed integer value (such as for - * GL_RGB5_A1) because we'll wind up with a non-zero value. - * - * We redefine the macros here so zero is handled correctly. - */ -#undef BYTE_TO_FLOAT -#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F))) - -#undef SHORT_TO_FLOAT -#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))) - - - -/** Compute ceiling of integer quotient of A divided by B. */ -#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 ) - - -/** * Flip the 8 bits in each byte of the given array. * * \param p array. @@ -2507,10 +2488,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], PROCESS(aSrc, ACOMP, 1.0F, 255, GLubyte, UBYTE_TO_FLOAT); break; case GL_BYTE: - PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT); - PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT); - PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT); - PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOAT); + PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ); + PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ); + PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ); + PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOATZ); break; case GL_UNSIGNED_SHORT: PROCESS(rSrc, RCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT); @@ -2519,10 +2500,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], PROCESS(aSrc, ACOMP, 1.0F, 0xffff, GLushort, USHORT_TO_FLOAT); break; case GL_SHORT: - PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT); - PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT); - PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT); - PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOAT); + PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ); + PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ); + PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ); + PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOATZ); break; case GL_UNSIGNED_INT: PROCESS(rSrc, RCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT); @@ -4586,10 +4567,10 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n, void _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n, - GLenum dstType, GLvoid *dest, const GLstencil *source, + GLenum dstType, GLvoid *dest, const GLubyte *source, const struct gl_pixelstore_attrib *dstPacking ) { - GLstencil *stencil = (GLstencil *) malloc(n * sizeof(GLstencil)); + GLubyte *stencil = (GLubyte *) malloc(n * sizeof(GLubyte)); if (!stencil) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil packing"); @@ -4599,23 +4580,14 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n, if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag) { /* make a copy of input */ - memcpy(stencil, source, n * sizeof(GLstencil)); + memcpy(stencil, source, n * sizeof(GLubyte)); _mesa_apply_stencil_transfer_ops(ctx, n, stencil); source = stencil; } switch (dstType) { case GL_UNSIGNED_BYTE: - if (sizeof(GLstencil) == 1) { - memcpy( dest, source, n ); - } - else { - GLubyte *dst = (GLubyte *) dest; - GLuint i; - for (i=0;i<n;i++) { - dst[i] = (GLubyte) source[i]; - } - } + memcpy(dest, source, n); break; case GL_BYTE: { @@ -4834,14 +4806,14 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n, */ switch (srcType) { case GL_BYTE: - DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT); + DEPTH_VALUES(GLbyte, BYTE_TO_FLOATZ); needClamp = GL_TRUE; break; case GL_UNSIGNED_BYTE: DEPTH_VALUES(GLubyte, UBYTE_TO_FLOAT); break; case GL_SHORT: - DEPTH_VALUES(GLshort, SHORT_TO_FLOAT); + DEPTH_VALUES(GLshort, SHORT_TO_FLOATZ); needClamp = GL_TRUE; break; case GL_UNSIGNED_SHORT: @@ -5120,11 +5092,11 @@ void _mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n, GLenum dstType, GLuint *dest, const GLfloat *depthVals, - const GLstencil *stencilVals, + const GLubyte *stencilVals, const struct gl_pixelstore_attrib *dstPacking) { GLfloat *depthCopy = (GLfloat *) malloc(n * sizeof(GLfloat)); - GLstencil *stencilCopy = (GLstencil *) malloc(n * sizeof(GLstencil)); + GLubyte *stencilCopy = (GLubyte *) malloc(n * sizeof(GLubyte)); GLuint i; if (!depthCopy || !stencilCopy) { @@ -5143,7 +5115,7 @@ _mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n, if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag) { - memcpy(stencilCopy, stencilVals, n * sizeof(GLstencil)); + memcpy(stencilCopy, stencilVals, n * sizeof(GLubyte)); _mesa_apply_stencil_transfer_ops(ctx, n, stencilCopy); stencilVals = stencilCopy; } diff --git a/mesalib/src/mesa/main/pack.h b/mesalib/src/mesa/main/pack.h index 7a0089c2f..b1853cd59 100644 --- a/mesalib/src/mesa/main/pack.h +++ b/mesalib/src/mesa/main/pack.h @@ -113,7 +113,7 @@ _mesa_unpack_stencil_span(struct gl_context *ctx, GLuint n, extern void _mesa_pack_stencil_span(struct gl_context *ctx, GLuint n, - GLenum dstType, GLvoid *dest, const GLstencil *source, + GLenum dstType, GLvoid *dest, const GLubyte *source, const struct gl_pixelstore_attrib *dstPacking); @@ -133,7 +133,7 @@ extern void _mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n, GLenum dstType, GLuint *dest, const GLfloat *depthVals, - const GLstencil *stencilVals, + const GLubyte *stencilVals, const struct gl_pixelstore_attrib *dstPacking); diff --git a/mesalib/src/mesa/main/pixeltransfer.c b/mesalib/src/mesa/main/pixeltransfer.c index 5e881436a..5c167e0a9 100644 --- a/mesalib/src/mesa/main/pixeltransfer.c +++ b/mesalib/src/mesa/main/pixeltransfer.c @@ -273,7 +273,7 @@ _mesa_apply_ci_transfer_ops(const struct gl_context *ctx, */ void _mesa_apply_stencil_transfer_ops(const struct gl_context *ctx, GLuint n, - GLstencil stencil[]) + GLubyte stencil[]) { if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset != 0) { const GLint offset = ctx->Pixel.IndexOffset; @@ -300,7 +300,7 @@ _mesa_apply_stencil_transfer_ops(const struct gl_context *ctx, GLuint n, GLuint mask = ctx->PixelMaps.StoS.Size - 1; GLuint i; for (i = 0; i < n; i++) { - stencil[i] = (GLstencil)ctx->PixelMaps.StoS.Map[ stencil[i] & mask ]; + stencil[i] = (GLubyte) ctx->PixelMaps.StoS.Map[ stencil[i] & mask ]; } } } diff --git a/mesalib/src/mesa/main/pixeltransfer.h b/mesalib/src/mesa/main/pixeltransfer.h index 8af2e9ee2..a8c14757f 100644 --- a/mesalib/src/mesa/main/pixeltransfer.h +++ b/mesalib/src/mesa/main/pixeltransfer.h @@ -75,7 +75,7 @@ _mesa_apply_ci_transfer_ops(const struct gl_context *ctx, extern void _mesa_apply_stencil_transfer_ops(const struct gl_context *ctx, GLuint n, - GLstencil stencil[]); + GLubyte stencil[]); #endif diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c index 84c5b2228..86b87534d 100644 --- a/mesalib/src/mesa/main/readpix.c +++ b/mesalib/src/mesa/main/readpix.c @@ -30,13 +30,509 @@ #include "readpix.h" #include "framebuffer.h" #include "formats.h" +#include "format_unpack.h" #include "image.h" #include "mtypes.h" +#include "pack.h" #include "pbo.h" #include "state.h" /** + * Tries to implement glReadPixels() of GL_DEPTH_COMPONENT using memcpy of the + * mapping. + */ +static GLboolean +fast_read_depth_pixels( struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type, GLvoid *pixels, + const struct gl_pixelstore_attrib *packing ) +{ + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; + GLubyte *map, *dst; + int stride, dstStride, j; + + if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) + return GL_FALSE; + + if (packing->SwapBytes) + return GL_FALSE; + + if (_mesa_get_format_datatype(rb->Format) != GL_UNSIGNED_INT) + return GL_FALSE; + + if (!((type == GL_UNSIGNED_SHORT && rb->Format == MESA_FORMAT_Z16) || + type == GL_UNSIGNED_INT)) + return GL_FALSE; + + ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, + &map, &stride); + + dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type); + dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, + GL_DEPTH_COMPONENT, type, 0, 0); + + for (j = 0; j < height; j++) { + if (type == GL_UNSIGNED_INT) { + _mesa_unpack_uint_z_row(rb->Format, width, map, (GLuint *)dst); + } else { + ASSERT(type == GL_UNSIGNED_SHORT && rb->Format == MESA_FORMAT_Z16); + memcpy(dst, map, width * 2); + } + + map += stride; + dst += dstStride; + } + ctx->Driver.UnmapRenderbuffer(ctx, rb); + + return GL_TRUE; +} + +/** + * Read pixels for format=GL_DEPTH_COMPONENT. + */ +static void +read_depth_pixels( struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type, GLvoid *pixels, + const struct gl_pixelstore_attrib *packing ) +{ + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; + GLint j; + GLubyte *dst, *map; + int dstStride, stride; + + if (!rb) + return; + + /* clipping should have been done already */ + ASSERT(x >= 0); + ASSERT(y >= 0); + ASSERT(x + width <= (GLint) rb->Width); + ASSERT(y + height <= (GLint) rb->Height); + /* width should never be > MAX_WIDTH since we did clipping earlier */ + ASSERT(width <= MAX_WIDTH); + + if (fast_read_depth_pixels(ctx, x, y, width, height, type, pixels, packing)) + return; + + dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type); + dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, + GL_DEPTH_COMPONENT, type, 0, 0); + + ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, + &map, &stride); + + /* General case (slower) */ + for (j = 0; j < height; j++, y++) { + GLfloat depthValues[MAX_WIDTH]; + _mesa_unpack_float_z_row(rb->Format, width, map, depthValues); + _mesa_pack_depth_span(ctx, width, dst, type, depthValues, packing); + + dst += dstStride; + map += stride; + } + + ctx->Driver.UnmapRenderbuffer(ctx, rb); +} + + +/** + * Read pixels for format=GL_STENCIL_INDEX. + */ +static void +read_stencil_pixels( struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type, GLvoid *pixels, + const struct gl_pixelstore_attrib *packing ) +{ + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; + GLint j; + GLubyte *map; + GLint stride; + + if (!rb) + return; + + /* width should never be > MAX_WIDTH since we did clipping earlier */ + ASSERT(width <= MAX_WIDTH); + + ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, + &map, &stride); + + /* process image row by row */ + for (j = 0; j < height; j++) { + GLvoid *dest; + GLubyte stencil[MAX_WIDTH]; + + _mesa_unpack_ubyte_stencil_row(rb->Format, width, map, stencil); + dest = _mesa_image_address2d(packing, pixels, width, height, + GL_STENCIL_INDEX, type, j, 0); + + _mesa_pack_stencil_span(ctx, width, type, dest, stencil, packing); + + map += stride; + } + + ctx->Driver.UnmapRenderbuffer(ctx, rb); +} + +static GLboolean +fast_read_rgba_pixels_memcpy( struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + GLbitfield transferOps ) +{ + struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; + GLubyte *dst, *map; + int dstStride, stride, j, texelBytes; + + if (!_mesa_format_matches_format_and_type(rb->Format, format, type)) + return GL_FALSE; + + /* check for things we can't handle here */ + if (packing->SwapBytes || + packing->LsbFirst) { + return GL_FALSE; + } + + dstStride = _mesa_image_row_stride(packing, width, format, type); + dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, + format, type, 0, 0); + + ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, + &map, &stride); + + texelBytes = _mesa_get_format_bytes(rb->Format); + for (j = 0; j < height; j++) { + memcpy(dst, map, width * texelBytes); + dst += dstStride; + map += stride; + } + + ctx->Driver.UnmapRenderbuffer(ctx, rb); + + return GL_TRUE; +} + +static GLboolean +slow_read_rgba_pixels( struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + GLbitfield transferOps ) +{ + struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; + const gl_format rbFormat = _mesa_get_srgb_format_linear(rb->Format); + union { + float f[MAX_WIDTH][4]; + unsigned int i[MAX_WIDTH][4]; + } rgba; + GLubyte *dst, *map; + int dstStride, stride, j; + + dstStride = _mesa_image_row_stride(packing, width, format, type); + dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, + format, type, 0, 0); + + ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, + &map, &stride); + + for (j = 0; j < height; j++) { + if (_mesa_is_integer_format(format)) { + _mesa_unpack_int_rgba_row(rbFormat, width, map, rgba.i); + _mesa_pack_rgba_span_int(ctx, width, rgba.i, format, type, dst); + } else { + _mesa_unpack_rgba_row(rbFormat, width, map, rgba.f); + _mesa_pack_rgba_span_float(ctx, width, rgba.f, format, type, dst, + packing, transferOps); + } + dst += dstStride; + map += stride; + } + + ctx->Driver.UnmapRenderbuffer(ctx, rb); + + return GL_TRUE; +} + +/* + * Read R, G, B, A, RGB, L, or LA pixels. + */ +static void +read_rgba_pixels( struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, GLvoid *pixels, + const struct gl_pixelstore_attrib *packing ) +{ + GLbitfield transferOps = ctx->_ImageTransferState; + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct gl_renderbuffer *rb = fb->_ColorReadBuffer; + + if (!rb) + return; + + if ((ctx->Color._ClampReadColor == GL_TRUE || type != GL_FLOAT) && + !_mesa_is_integer_format(format)) { + transferOps |= IMAGE_CLAMP_BIT; + } + + if (!transferOps) { + /* Try the optimized paths first. */ + if (fast_read_rgba_pixels_memcpy(ctx, x, y, width, height, + format, type, pixels, packing, + transferOps)) { + return; + } + } + + slow_read_rgba_pixels(ctx, x, y, width, height, + format, type, pixels, packing, transferOps); +} + +/** + * For a packed depth/stencil buffer being read as depth/stencil, just memcpy the + * data (possibly swapping 8/24 vs 24/8 as we go). + */ +static GLboolean +fast_read_depth_stencil_pixels(struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLubyte *dst, int dstStride) +{ + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; + struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; + GLubyte *map; + int stride, i; + + if (rb != stencilRb) + return GL_FALSE; + + if (rb->Format != MESA_FORMAT_Z24_S8 && + rb->Format != MESA_FORMAT_S8_Z24) + return GL_FALSE; + + ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, + &map, &stride); + + for (i = 0; i < height; i++) { + _mesa_unpack_uint_24_8_depth_stencil_row(rb->Format, width, + map, (GLuint *)dst); + map += stride; + dst += dstStride; + } + + ctx->Driver.UnmapRenderbuffer(ctx, rb); + + return GL_TRUE; +} + + +/** + * For non-float-depth and stencil buffers being read as 24/8 depth/stencil, + * copy the integer data directly instead of converting depth to float and + * re-packing. + */ +static GLboolean +fast_read_depth_stencil_pixels_separate(struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + uint32_t *dst, int dstStride) +{ + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; + struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; + GLubyte *depthMap, *stencilMap; + int depthStride, stencilStride, i, j; + + if (_mesa_get_format_datatype(depthRb->Format) != GL_UNSIGNED_INT) + return GL_FALSE; + + ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height, + GL_MAP_READ_BIT, &depthMap, &depthStride); + ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height, + GL_MAP_READ_BIT, &stencilMap, &stencilStride); + + for (j = 0; j < height; j++) { + GLubyte stencilVals[MAX_WIDTH]; + + _mesa_unpack_uint_z_row(depthRb->Format, width, depthMap, dst); + _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width, + stencilMap, stencilVals); + + for (i = 0; i < width; i++) { + dst[i] = (dst[i] & 0xffffff00) | stencilVals[i]; + } + + depthMap += depthStride; + stencilMap += stencilStride; + dst += dstStride / 4; + } + + ctx->Driver.UnmapRenderbuffer(ctx, depthRb); + ctx->Driver.UnmapRenderbuffer(ctx, stencilRb); + + return GL_TRUE; +} + +static void +slow_read_depth_stencil_pixels_separate(struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type, + const struct gl_pixelstore_attrib *packing, + GLubyte *dst, int dstStride) +{ + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; + struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; + GLubyte *depthMap, *stencilMap; + int depthStride, stencilStride, j; + + /* The depth and stencil buffers might be separate, or a single buffer. + * If one buffer, only map it once. + */ + ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height, + GL_MAP_READ_BIT, &depthMap, &depthStride); + if (stencilRb != depthRb) { + ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height, + GL_MAP_READ_BIT, &stencilMap, + &stencilStride); + } + else { + stencilMap = depthMap; + stencilStride = depthStride; + } + + for (j = 0; j < height; j++) { + GLubyte stencilVals[MAX_WIDTH]; + GLfloat depthVals[MAX_WIDTH]; + + _mesa_unpack_float_z_row(depthRb->Format, width, depthMap, depthVals); + _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width, + stencilMap, stencilVals); + + _mesa_pack_depth_stencil_span(ctx, width, type, (GLuint *)dst, + depthVals, stencilVals, packing); + + depthMap += depthStride; + stencilMap += stencilStride; + dst += dstStride; + } + + ctx->Driver.UnmapRenderbuffer(ctx, depthRb); + if (stencilRb != depthRb) { + ctx->Driver.UnmapRenderbuffer(ctx, stencilRb); + } +} + + +/** + * Read combined depth/stencil values. + * We'll have already done error checking to be sure the expected + * depth and stencil buffers really exist. + */ +static void +read_depth_stencil_pixels(struct gl_context *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type, GLvoid *pixels, + const struct gl_pixelstore_attrib *packing ) +{ + const GLboolean scaleOrBias + = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0; + const GLboolean stencilTransfer = ctx->Pixel.IndexShift + || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag; + GLubyte *dst; + int dstStride; + + dst = (GLubyte *) _mesa_image_address2d(packing, pixels, + width, height, + GL_DEPTH_STENCIL_EXT, + type, 0, 0); + dstStride = _mesa_image_row_stride(packing, width, + GL_DEPTH_STENCIL_EXT, type); + + /* Fast 24/8 reads. */ + if (type == GL_UNSIGNED_INT_24_8 && + !scaleOrBias && !stencilTransfer && !packing->SwapBytes) { + if (fast_read_depth_stencil_pixels(ctx, x, y, width, height, + dst, dstStride)) + return; + + if (fast_read_depth_stencil_pixels_separate(ctx, x, y, width, height, + (uint32_t *)dst, dstStride)) + return; + } + + slow_read_depth_stencil_pixels_separate(ctx, x, y, width, height, + type, packing, + dst, dstStride); +} + + + +/** + * Software fallback routine for ctx->Driver.ReadPixels(). + * By time we get here, all error checking will have been done. + */ +void +_mesa_readpixels(struct gl_context *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid *pixels) +{ + struct gl_pixelstore_attrib clippedPacking = *packing; + + if (ctx->NewState) + _mesa_update_state(ctx); + + /* Do all needed clipping here, so that we can forget about it later */ + if (_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) { + + pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels); + + if (pixels) { + switch (format) { + case GL_STENCIL_INDEX: + read_stencil_pixels(ctx, x, y, width, height, type, pixels, + &clippedPacking); + break; + case GL_DEPTH_COMPONENT: + read_depth_pixels(ctx, x, y, width, height, type, pixels, + &clippedPacking); + break; + case GL_DEPTH_STENCIL_EXT: + read_depth_stencil_pixels(ctx, x, y, width, height, type, pixels, + &clippedPacking); + break; + default: + /* all other formats should be color formats */ + read_rgba_pixels(ctx, x, y, width, height, format, type, pixels, + &clippedPacking); + } + + _mesa_unmap_pbo_dest(ctx, &clippedPacking); + } + } +} + + +/** * Do error checking of the format/type parameters to glReadPixels and * glDrawPixels. * \param drawing if GL_TRUE do checking for DrawPixels, else do checking diff --git a/mesalib/src/mesa/main/readpix.h b/mesalib/src/mesa/main/readpix.h index f6bb3d6e2..6caaf3adc 100644 --- a/mesalib/src/mesa/main/readpix.h +++ b/mesalib/src/mesa/main/readpix.h @@ -30,11 +30,20 @@ #include "glheader.h" struct gl_context; +struct gl_pixelstore_attrib; + extern GLboolean _mesa_error_check_format_type(struct gl_context *ctx, GLenum format, GLenum type, GLboolean drawing); +extern void +_mesa_readpixels(struct gl_context *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid *pixels); + extern void GLAPIENTRY _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels ); diff --git a/mesalib/src/mesa/main/renderbuffer.c b/mesalib/src/mesa/main/renderbuffer.c index 4415dbd4f..c9a16a989 100644 --- a/mesalib/src/mesa/main/renderbuffer.c +++ b/mesalib/src/mesa/main/renderbuffer.c @@ -28,11 +28,6 @@ * Also, routines for reading/writing software-based renderbuffer data as * ubytes, ushorts, uints, etc. * - * The 'alpha8' renderbuffer is interesting. It's used to add a software-based - * alpha channel to RGB renderbuffers. This is done by wrapping the RGB - * renderbuffer with the alpha renderbuffer. We can do this because of the - * OO-nature of renderbuffers. - * * Down the road we'll use this for run-time support of 8, 16 and 32-bit * color channels. For example, Mesa may use 32-bit/float color channels * internally (swrast) and use wrapper renderbuffers to convert 32-bit @@ -1470,18 +1465,6 @@ _mesa_set_renderbuffer_accessors(struct gl_renderbuffer *rb) rb->PutMonoValues = put_mono_values_ushort4; break; -#if 0 - case MESA_FORMAT_A8: - rb->DataType = GL_UNSIGNED_BYTE; - rb->GetValues = get_values_alpha8; - rb->PutRow = put_row_alpha8; - rb->PutRowRGB = NULL; - rb->PutMonoRow = put_mono_row_alpha8; - rb->PutValues = put_values_alpha8; - rb->PutMonoValues = put_mono_values_alpha8; - break; -#endif - case MESA_FORMAT_S8: rb->DataType = GL_UNSIGNED_BYTE; rb->GetValues = get_values_ubyte; @@ -1639,11 +1622,6 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer * /* for accum buffer */ rb->Format = MESA_FORMAT_SIGNED_RGBA_16; break; -#if 0 - case GL_ALPHA8: - rb->Format = MESA_FORMAT_A8; - break; -#endif case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: case GL_STENCIL_INDEX4_EXT: @@ -1754,236 +1732,6 @@ _mesa_unmap_soft_renderbuffer(struct gl_context *ctx, } -/**********************************************************************/ -/**********************************************************************/ -/**********************************************************************/ - - -/** - * Here we utilize the gl_renderbuffer->Wrapper field to put an alpha - * buffer wrapper around an existing RGB renderbuffer (hw or sw). - * - * When PutRow is called (for example), we store the alpha values in - * this buffer, then pass on the PutRow call to the wrapped RGB - * buffer. - */ - - -static GLboolean -alloc_storage_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, - GLenum internalFormat, GLuint width, GLuint height) -{ - ASSERT(arb != arb->Wrapped); - ASSERT(arb->Format == MESA_FORMAT_A8); - - /* first, pass the call to the wrapped RGB buffer */ - if (!arb->Wrapped->AllocStorage(ctx, arb->Wrapped, internalFormat, - width, height)) { - return GL_FALSE; - } - - /* next, resize my alpha buffer */ - if (arb->Data) { - free(arb->Data); - } - - arb->Data = malloc(width * height * sizeof(GLubyte)); - if (arb->Data == NULL) { - arb->Width = 0; - arb->Height = 0; - _mesa_error(ctx, GL_OUT_OF_MEMORY, "software alpha buffer allocation"); - return GL_FALSE; - } - - arb->Width = width; - arb->Height = height; - arb->RowStride = width; - - return GL_TRUE; -} - - -/** - * Delete an alpha_renderbuffer object, as well as the wrapped RGB buffer. - */ -static void -delete_renderbuffer_alpha8(struct gl_renderbuffer *arb) -{ - if (arb->Data) { - free(arb->Data); - } - ASSERT(arb->Wrapped); - ASSERT(arb != arb->Wrapped); - arb->Wrapped->Delete(arb->Wrapped); - arb->Wrapped = NULL; - free(arb); -} - - -static void * -get_pointer_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, - GLint x, GLint y) -{ - return NULL; /* don't allow direct access! */ -} - - -static void -get_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count, - GLint x, GLint y, void *values) -{ - /* NOTE: 'values' is RGBA format! */ - const GLubyte *src = (const GLubyte *) arb->Data + y * arb->RowStride + x; - GLubyte *dst = (GLubyte *) values; - GLuint i; - ASSERT(arb != arb->Wrapped); - ASSERT(arb->DataType == GL_UNSIGNED_BYTE); - /* first, pass the call to the wrapped RGB buffer */ - arb->Wrapped->GetRow(ctx, arb->Wrapped, count, x, y, values); - /* second, fill in alpha values from this buffer! */ - for (i = 0; i < count; i++) { - dst[i * 4 + 3] = src[i]; - } -} - - -static void -get_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count, - const GLint x[], const GLint y[], void *values) -{ - GLubyte *dst = (GLubyte *) values; - GLuint i; - ASSERT(arb != arb->Wrapped); - ASSERT(arb->DataType == GL_UNSIGNED_BYTE); - /* first, pass the call to the wrapped RGB buffer */ - arb->Wrapped->GetValues(ctx, arb->Wrapped, count, x, y, values); - /* second, fill in alpha values from this buffer! */ - for (i = 0; i < count; i++) { - const GLubyte *src = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i]; - dst[i * 4 + 3] = *src; - } -} - - -static void -put_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count, - GLint x, GLint y, const void *values, const GLubyte *mask) -{ - const GLubyte *src = (const GLubyte *) values; - GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x; - GLuint i; - ASSERT(arb != arb->Wrapped); - ASSERT(arb->DataType == GL_UNSIGNED_BYTE); - /* first, pass the call to the wrapped RGB buffer */ - arb->Wrapped->PutRow(ctx, arb->Wrapped, count, x, y, values, mask); - /* second, store alpha in our buffer */ - for (i = 0; i < count; i++) { - if (!mask || mask[i]) { - dst[i] = src[i * 4 + 3]; - } - } -} - - -static void -put_row_rgb_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count, - GLint x, GLint y, const void *values, const GLubyte *mask) -{ - const GLubyte *src = (const GLubyte *) values; - GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x; - GLuint i; - ASSERT(arb != arb->Wrapped); - ASSERT(arb->DataType == GL_UNSIGNED_BYTE); - /* first, pass the call to the wrapped RGB buffer */ - arb->Wrapped->PutRowRGB(ctx, arb->Wrapped, count, x, y, values, mask); - /* second, store alpha in our buffer */ - for (i = 0; i < count; i++) { - if (!mask || mask[i]) { - dst[i] = src[i * 4 + 3]; - } - } -} - - -static void -put_mono_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count, - GLint x, GLint y, const void *value, const GLubyte *mask) -{ - const GLubyte val = ((const GLubyte *) value)[3]; - GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x; - ASSERT(arb != arb->Wrapped); - ASSERT(arb->DataType == GL_UNSIGNED_BYTE); - /* first, pass the call to the wrapped RGB buffer */ - arb->Wrapped->PutMonoRow(ctx, arb->Wrapped, count, x, y, value, mask); - /* second, store alpha in our buffer */ - if (mask) { - GLuint i; - for (i = 0; i < count; i++) { - if (mask[i]) { - dst[i] = val; - } - } - } - else { - memset(dst, val, count); - } -} - - -static void -put_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count, - const GLint x[], const GLint y[], - const void *values, const GLubyte *mask) -{ - const GLubyte *src = (const GLubyte *) values; - GLuint i; - ASSERT(arb != arb->Wrapped); - ASSERT(arb->DataType == GL_UNSIGNED_BYTE); - /* first, pass the call to the wrapped RGB buffer */ - arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, values, mask); - /* second, store alpha in our buffer */ - for (i = 0; i < count; i++) { - if (!mask || mask[i]) { - GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i]; - *dst = src[i * 4 + 3]; - } - } -} - - -static void -put_mono_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, - GLuint count, const GLint x[], const GLint y[], - const void *value, const GLubyte *mask) -{ - const GLubyte val = ((const GLubyte *) value)[3]; - GLuint i; - ASSERT(arb != arb->Wrapped); - ASSERT(arb->DataType == GL_UNSIGNED_BYTE); - /* first, pass the call to the wrapped RGB buffer */ - arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, value, mask); - /* second, store alpha in our buffer */ - for (i = 0; i < count; i++) { - if (!mask || mask[i]) { - GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i]; - *dst = val; - } - } -} - - -static void -copy_buffer_alpha8(struct gl_renderbuffer* dst, struct gl_renderbuffer* src) -{ - ASSERT(dst->Format == MESA_FORMAT_A8); - ASSERT(src->Format == MESA_FORMAT_A8); - ASSERT(dst->Width == src->Width); - ASSERT(dst->Height == src->Height); - ASSERT(dst->RowStride == src->RowStride); - - memcpy(dst->Data, src->Data, dst->RowStride * dst->Height * sizeof(GLubyte)); -} - /**********************************************************************/ /**********************************************************************/ @@ -2148,114 +1896,6 @@ _mesa_add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb, /** - * Add software-based alpha renderbuffers to the given framebuffer. - * This is a helper routine for device drivers when creating a - * window system framebuffer (not a user-created render/framebuffer). - * Once this function is called, you can basically forget about this - * renderbuffer; core Mesa will handle all the buffer management and - * rendering! - */ -GLboolean -_mesa_add_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb, - GLuint alphaBits, - GLboolean frontLeft, GLboolean backLeft, - GLboolean frontRight, GLboolean backRight) -{ - gl_buffer_index b; - - /* for window system framebuffers only! */ - assert(fb->Name == 0); - - if (alphaBits > 8) { - _mesa_problem(ctx, - "Unsupported bit depth in _mesa_add_alpha_renderbuffers"); - return GL_FALSE; - } - - assert(MAX_COLOR_ATTACHMENTS >= 4); - - /* Wrap each of the RGB color buffers with an alpha renderbuffer. - */ - for (b = BUFFER_FRONT_LEFT; b <= BUFFER_BACK_RIGHT; b++) { - struct gl_renderbuffer *arb; - - if (b == BUFFER_FRONT_LEFT && !frontLeft) - continue; - else if (b == BUFFER_BACK_LEFT && !backLeft) - continue; - else if (b == BUFFER_FRONT_RIGHT && !frontRight) - continue; - else if (b == BUFFER_BACK_RIGHT && !backRight) - continue; - - /* the RGB buffer to wrap must already exist!! */ - assert(fb->Attachment[b].Renderbuffer); - - /* only GLubyte supported for now */ - assert(fb->Attachment[b].Renderbuffer->DataType == GL_UNSIGNED_BYTE); - - /* allocate alpha renderbuffer */ - arb = _mesa_new_renderbuffer(ctx, 0); - if (!arb) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating alpha buffer"); - return GL_FALSE; - } - - /* wrap the alpha renderbuffer around the RGB renderbuffer */ - arb->Wrapped = fb->Attachment[b].Renderbuffer; - - /* Set up my alphabuffer fields and plug in my functions. - * The functions will put/get the alpha values from/to RGBA arrays - * and then call the wrapped buffer's functions to handle the RGB - * values. - */ - arb->InternalFormat = arb->Wrapped->InternalFormat; - arb->Format = MESA_FORMAT_A8; - arb->DataType = arb->Wrapped->DataType; - arb->AllocStorage = alloc_storage_alpha8; - arb->Delete = delete_renderbuffer_alpha8; - arb->GetPointer = get_pointer_alpha8; - arb->GetRow = get_row_alpha8; - arb->GetValues = get_values_alpha8; - arb->PutRow = put_row_alpha8; - arb->PutRowRGB = put_row_rgb_alpha8; - arb->PutMonoRow = put_mono_row_alpha8; - arb->PutValues = put_values_alpha8; - arb->PutMonoValues = put_mono_values_alpha8; - - /* clear the pointer to avoid assertion/sanity check failure later */ - fb->Attachment[b].Renderbuffer = NULL; - - /* plug the alpha renderbuffer into the colorbuffer attachment */ - _mesa_add_renderbuffer(fb, b, arb); - } - - return GL_TRUE; -} - - -/** - * For framebuffers that use a software alpha channel wrapper - * created by _mesa_add_alpha_renderbuffer or _mesa_add_soft_renderbuffers, - * copy the back buffer alpha channel into the front buffer alpha channel. - */ -void -_mesa_copy_soft_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb) -{ - if (fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer && - fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer) - copy_buffer_alpha8(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer, - fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); - - - if (fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer && - fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer) - copy_buffer_alpha8(fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer, - fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer); -} - - -/** * Add a software-based depth renderbuffer to the given framebuffer. * This is a helper routine for device drivers when creating a * window system framebuffer (not a user-created render/framebuffer). @@ -2476,13 +2116,6 @@ _mesa_add_soft_renderbuffers(struct gl_framebuffer *fb, fb->Visual.numAuxBuffers); } - if (alpha) { - assert(fb->Visual.alphaBits > 0); - _mesa_add_alpha_renderbuffers(NULL, fb, fb->Visual.alphaBits, - frontLeft, backLeft, - frontRight, backRight); - } - #if 0 if (multisample) { /* maybe someday */ diff --git a/mesalib/src/mesa/main/renderbuffer.h b/mesalib/src/mesa/main/renderbuffer.h index cb0d712eb..3194fc3fe 100644 --- a/mesalib/src/mesa/main/renderbuffer.h +++ b/mesalib/src/mesa/main/renderbuffer.h @@ -73,15 +73,6 @@ _mesa_add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb, GLboolean frontRight, GLboolean backRight); extern GLboolean -_mesa_add_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb, - GLuint alphaBits, - GLboolean frontLeft, GLboolean backLeft, - GLboolean frontRight, GLboolean backRight); - -extern void -_mesa_copy_soft_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb); - -extern GLboolean _mesa_add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb, GLuint depthBits); diff --git a/mesalib/src/mesa/main/uniform_query.cpp b/mesalib/src/mesa/main/uniform_query.cpp index 5371d6a17..33ba53c2e 100644 --- a/mesalib/src/mesa/main/uniform_query.cpp +++ b/mesalib/src/mesa/main/uniform_query.cpp @@ -698,11 +698,27 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg, prog = shProg->_LinkedShaders[i]->Program; + /* If the shader stage doesn't use any samplers, don't bother + * checking if any samplers have changed. + */ + if (prog->SamplersUsed == 0) + continue; + assert(sizeof(prog->SamplerUnits) == sizeof(shProg->SamplerUnits)); - if (memcmp(prog->SamplerUnits, - shProg->SamplerUnits, - sizeof(shProg->SamplerUnits)) != 0) { + /* Determine if any of the samplers used by this shader stage have + * been modified. + */ + bool changed = false; + for (unsigned j = 0; j < Elements(prog->SamplerUnits); j++) { + if ((prog->SamplersUsed & (1U << j)) != 0 + && (prog->SamplerUnits[j] != shProg->SamplerUnits[j])) { + changed = true; + break; + } + } + + if (changed) { if (!flushed) { FLUSH_VERTICES(ctx, _NEW_TEXTURE | _NEW_PROGRAM); flushed = true; |