Beispiel #1
0
static void
make_expected(void)
{
	float *pe = expected;
	int i, j;

	for (j = 0; j < TEXTURE_HEIGHT; j++)
		for (i = 0; i < TEXTURE_WIDTH; i++) {
			if (comptype == SHADOW_T) {
				*pe++ = shadow_compare(norm_value(pixel_value(i, j + 1)));
				*pe++ = shadow_compare(norm_value(pixel_value(i + 1, j + 1)));
				*pe++ = shadow_compare(norm_value(pixel_value(i + 1, j)));
				*pe++ = shadow_compare(norm_value(pixel_value(i, j)));
			}
			else {
				*pe++ = norm_value(pixel_value(i, j + 1));
				*pe++ = norm_value(pixel_value(i + 1, j + 1));
				*pe++ = norm_value(pixel_value(i + 1, j));
				*pe++ = norm_value(pixel_value(i, j));
			}
		}
}
Beispiel #2
0
static void
make_expected(void)
{
	float *pe = expected;
	int i, j;

	for (j = 0; j < texture_height; j++)
		for (i = 0; i < texture_width; i++) {
			if (comptype == SHADOW_T) {
				if (use_offsets) {
					*pe++ = shadow_compare(norm_value(pixel_value(i, j, 0)));
					*pe++ = shadow_compare(norm_value(pixel_value(i, j, 1)));
					*pe++ = shadow_compare(norm_value(pixel_value(i, j, 2)));
					*pe++ = shadow_compare(norm_value(pixel_value(i, j, 3)));
				} else {
					*pe++ = shadow_compare(norm_value(pixel_value(i, j + 1, 0)));
					*pe++ = shadow_compare(norm_value(pixel_value(i + 1, j + 1, 0)));
					*pe++ = shadow_compare(norm_value(pixel_value(i + 1, j, 0)));
					*pe++ = shadow_compare(norm_value(pixel_value(i, j, 0)));
				}
			}
			else {
				if (use_offsets) {
					*pe++ = norm_value(pixel_value(i, j, 0));
					*pe++ = norm_value(pixel_value(i, j, 1));
					*pe++ = norm_value(pixel_value(i, j, 2));
					*pe++ = norm_value(pixel_value(i, j, 3));
				} else {
					*pe++ = norm_value(pixel_value(i, j + 1, 0));
					*pe++ = norm_value(pixel_value(i + 1, j + 1, 0));
					*pe++ = norm_value(pixel_value(i + 1, j, 0));
					*pe++ = norm_value(pixel_value(i, j, 0));
				}
			}
		}
}
Beispiel #3
0
/**
 * Common code for sampling 1D/2D/cube textures.
 * Could probably extend for 3D...
 */
static void
sp_get_samples_2d_common(const struct tgsi_sampler *tgsi_sampler,
                         const float s[QUAD_SIZE],
                         const float t[QUAD_SIZE],
                         const float p[QUAD_SIZE],
                         boolean computeLambda,
                         float lodbias,
                         float rgba[NUM_CHANNELS][QUAD_SIZE],
                         const unsigned faces[4])
{
   const struct sp_shader_sampler *samp = sp_shader_sampler(tgsi_sampler);
   const struct softpipe_context *sp = samp->sp;
   const uint unit = samp->unit;
   const struct pipe_texture *texture = sp->texture[unit];
   const struct pipe_sampler_state *sampler = sp->sampler[unit];
   const uint compare_func = sampler->compare_func;
   unsigned level0, level1, j, imgFilter;
   int width, height;
   float levelBlend;

   choose_mipmap_levels(texture, sampler, s, t, p, computeLambda, lodbias,
                        &level0, &level1, &levelBlend, &imgFilter);

   assert(sampler->normalized_coords);

   width = texture->width[level0];
   height = texture->height[level0];

   assert(width > 0);

   switch (imgFilter) {
   case PIPE_TEX_FILTER_NEAREST:
      {
         int x[4], y[4];
         nearest_texcoord_4(sampler->wrap_s, s, width, x);
         nearest_texcoord_4(sampler->wrap_t, t, height, y);

         for (j = 0; j < QUAD_SIZE; j++) {
            get_texel(tgsi_sampler, faces[j], level0, x[j], y[j], 0, rgba, j);
            if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
               shadow_compare(compare_func, rgba, p, j);
            }

            if (level0 != level1) {
               /* get texels from second mipmap level and blend */
               float rgba2[4][4];
               unsigned c;
               x[j] /= 2;
               y[j] /= 2;
               get_texel(tgsi_sampler, faces[j], level1, x[j], y[j], 0,
                         rgba2, j);
               if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE){
                  shadow_compare(compare_func, rgba2, p, j);
               }

               for (c = 0; c < NUM_CHANNELS; c++) {
                  rgba[c][j] = lerp(levelBlend, rgba[c][j], rgba2[c][j]);
               }
            }
         }
      }
      break;
   case PIPE_TEX_FILTER_LINEAR:
   case PIPE_TEX_FILTER_ANISO:
      {
         int x0[4], y0[4], x1[4], y1[4];
         float xw[4], yw[4]; /* weights */

         linear_texcoord_4(sampler->wrap_s, s, width, x0, x1, xw);
         linear_texcoord_4(sampler->wrap_t, t, height, y0, y1, yw);

         for (j = 0; j < QUAD_SIZE; j++) {
            float tx[4][4]; /* texels */
            int c;
            get_texel(tgsi_sampler, faces[j], level0, x0[j], y0[j], 0, tx, 0);
            get_texel(tgsi_sampler, faces[j], level0, x1[j], y0[j], 0, tx, 1);
            get_texel(tgsi_sampler, faces[j], level0, x0[j], y1[j], 0, tx, 2);
            get_texel(tgsi_sampler, faces[j], level0, x1[j], y1[j], 0, tx, 3);
            if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
               shadow_compare(compare_func, tx, p, 0);
               shadow_compare(compare_func, tx, p, 1);
               shadow_compare(compare_func, tx, p, 2);
               shadow_compare(compare_func, tx, p, 3);
            }

            /* interpolate R, G, B, A */
            for (c = 0; c < 4; c++) {
               rgba[c][j] = lerp_2d(xw[j], yw[j],
                                    tx[c][0], tx[c][1],
                                    tx[c][2], tx[c][3]);
            }

            if (level0 != level1) {
               /* get texels from second mipmap level and blend */
               float rgba2[4][4];
               x0[j] /= 2;
               y0[j] /= 2;
               x1[j] /= 2;
               y1[j] /= 2;
               get_texel(tgsi_sampler, faces[j], level1, x0[j], y0[j], 0, tx, 0);
               get_texel(tgsi_sampler, faces[j], level1, x1[j], y0[j], 0, tx, 1);
               get_texel(tgsi_sampler, faces[j], level1, x0[j], y1[j], 0, tx, 2);
               get_texel(tgsi_sampler, faces[j], level1, x1[j], y1[j], 0, tx, 3);
               if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE){
                  shadow_compare(compare_func, tx, p, 0);
                  shadow_compare(compare_func, tx, p, 1);
                  shadow_compare(compare_func, tx, p, 2);
                  shadow_compare(compare_func, tx, p, 3);
               }

               /* interpolate R, G, B, A */
               for (c = 0; c < 4; c++) {
                  rgba2[c][j] = lerp_2d(xw[j], yw[j],
                                        tx[c][0], tx[c][1], tx[c][2], tx[c][3]);
               }

               for (c = 0; c < NUM_CHANNELS; c++) {
                  rgba[c][j] = lerp(levelBlend, rgba[c][j], rgba2[c][j]);
               }
            }
         }
      }
      break;
   default:
      assert(0);
   }
}