- /* convert four pass/fail values to an intensity in [0,1] */
- val = 0.25F * (k0 + k1 + k2 + k3);
-
- /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
- for (j = 0; j < 4; j++) {
- rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
- rgba[3][j] = 1.0F;
- }
-}
-
-
-/**
- * Use 3D texcoords to choose a cube face, then sample the 2D cube faces.
- * Put face info into the sampler faces[] array.
- */
-static void
-sample_cube(struct tgsi_sampler *tgsi_sampler,
- const float s[QUAD_SIZE],
- const float t[QUAD_SIZE],
- const float p[QUAD_SIZE],
- const float c0[QUAD_SIZE],
- enum tgsi_sampler_control control,
- float rgba[NUM_CHANNELS][QUAD_SIZE])
-{
- struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
- unsigned j;
- float ssss[4], tttt[4];
-
- /*
- major axis
- direction target sc tc ma
- ---------- ------------------------------- --- --- ---
- +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx
- -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx
- +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry
- -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry
- +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz
- -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz
- */
-
- /* Choose the cube face and compute new s/t coords for the 2D face.
- *
- * Use the same cube face for all four pixels in the quad.
- *
- * This isn't ideal, but if we want to use a different cube face
- * per pixel in the quad, we'd have to also compute the per-face
- * LOD here too. That's because the four post-face-selection
- * texcoords are no longer related to each other (they're
- * per-face!) so we can't use subtraction to compute the partial
- * deriviates to compute the LOD. Doing so (near cube edges
- * anyway) gives us pretty much random values.
- */
- {
- /* use the average of the four pixel's texcoords to choose the face */
- const float rx = 0.25F * (s[0] + s[1] + s[2] + s[3]);
- const float ry = 0.25F * (t[0] + t[1] + t[2] + t[3]);
- const float rz = 0.25F * (p[0] + p[1] + p[2] + p[3]);
- const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz);
-
- if (arx >= ary && arx >= arz) {
- float sign = (rx >= 0.0F) ? 1.0F : -1.0F;
- uint face = (rx >= 0.0F) ? PIPE_TEX_FACE_POS_X : PIPE_TEX_FACE_NEG_X;
- for (j = 0; j < QUAD_SIZE; j++) {
- const float ima = -0.5F / fabsf(s[j]);
- ssss[j] = sign * p[j] * ima + 0.5F;
- tttt[j] = t[j] * ima + 0.5F;
- samp->faces[j] = face;
- }
- }
- else if (ary >= arx && ary >= arz) {
- float sign = (ry >= 0.0F) ? 1.0F : -1.0F;
- uint face = (ry >= 0.0F) ? PIPE_TEX_FACE_POS_Y : PIPE_TEX_FACE_NEG_Y;
- for (j = 0; j < QUAD_SIZE; j++) {
- const float ima = -0.5F / fabsf(t[j]);
- ssss[j] = -s[j] * ima + 0.5F;
- tttt[j] = sign * -p[j] * ima + 0.5F;
- samp->faces[j] = face;
- }
- }
- else {
- float sign = (rz >= 0.0F) ? 1.0F : -1.0F;
- uint face = (rz >= 0.0F) ? PIPE_TEX_FACE_POS_Z : PIPE_TEX_FACE_NEG_Z;
- for (j = 0; j < QUAD_SIZE; j++) {
- const float ima = -0.5F / fabsf(p[j]);
- ssss[j] = sign * -s[j] * ima + 0.5F;
- tttt[j] = t[j] * ima + 0.5F;
- samp->faces[j] = face;
- }
- }
- }
-
- /* In our little pipeline, the compare stage is next. If compare
- * is not active, this will point somewhere deeper into the
- * pipeline, eg. to mip_filter or even img_filter.
- */
- samp->compare(tgsi_sampler, ssss, tttt, NULL, c0, control, rgba);
-}
-
-
-static void
-sample_swizzle(struct tgsi_sampler *tgsi_sampler,
- const float s[QUAD_SIZE],
- const float t[QUAD_SIZE],
- const float p[QUAD_SIZE],
- const float c0[QUAD_SIZE],
- enum tgsi_sampler_control control,
- float rgba[NUM_CHANNELS][QUAD_SIZE])
-{
- struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
- float rgba_temp[NUM_CHANNELS][QUAD_SIZE];
- const unsigned swizzle_r = samp->key.bits.swizzle_r;
- const unsigned swizzle_g = samp->key.bits.swizzle_g;
- const unsigned swizzle_b = samp->key.bits.swizzle_b;
- const unsigned swizzle_a = samp->key.bits.swizzle_a;
- unsigned j;
-
- samp->sample_target(tgsi_sampler, s, t, p, c0, control, rgba_temp);
-
- switch (swizzle_r) {
- case PIPE_SWIZZLE_ZERO:
- for (j = 0; j < 4; j++)
- rgba[0][j] = 0.0f;
- break;
- case PIPE_SWIZZLE_ONE:
- for (j = 0; j < 4; j++)
- rgba[0][j] = 1.0f;
- break;
- default:
- assert(swizzle_r < 4);
- for (j = 0; j < 4; j++)
- rgba[0][j] = rgba_temp[swizzle_r][j];
- }
-
- switch (swizzle_g) {
- case PIPE_SWIZZLE_ZERO:
- for (j = 0; j < 4; j++)
- rgba[1][j] = 0.0f;
- break;
- case PIPE_SWIZZLE_ONE:
- for (j = 0; j < 4; j++)
- rgba[1][j] = 1.0f;
- break;
- default:
- assert(swizzle_g < 4);
- for (j = 0; j < 4; j++)
- rgba[1][j] = rgba_temp[swizzle_g][j];
- }
-
- switch (swizzle_b) {
- case PIPE_SWIZZLE_ZERO:
- for (j = 0; j < 4; j++)
- rgba[2][j] = 0.0f;
- break;
- case PIPE_SWIZZLE_ONE:
- for (j = 0; j < 4; j++)
- rgba[2][j] = 1.0f;
- break;
- default:
- assert(swizzle_b < 4);
- for (j = 0; j < 4; j++)
- rgba[2][j] = rgba_temp[swizzle_b][j];
- }
-
- switch (swizzle_a) {
- case PIPE_SWIZZLE_ZERO:
- for (j = 0; j < 4; j++)
- rgba[3][j] = 0.0f;
- break;
- case PIPE_SWIZZLE_ONE:
- for (j = 0; j < 4; j++)
- rgba[3][j] = 1.0f;
- break;
- default:
- assert(swizzle_a < 4);
- for (j = 0; j < 4; j++)
- rgba[3][j] = rgba_temp[swizzle_a][j];