- switch (baseFormat) {
- case GL_RED:
- colorOut[0] = colorIn[0];
- colorOut[1] = 0.0F;
- colorOut[2] = 0.0F;
- colorOut[3] = 1.0F;
- break;
- case GL_RG:
- colorOut[0] = colorIn[0];
- colorOut[1] = colorIn[1];
- colorOut[2] = 0.0F;
- colorOut[3] = 1.0F;
- break;
- case GL_RGB:
- colorOut[0] = colorIn[0];
- colorOut[1] = colorIn[1];
- colorOut[2] = colorIn[2];
- colorOut[3] = 1.0F;
- break;
- case GL_ALPHA:
- colorOut[0] = colorOut[1] = colorOut[2] = 0.0;
- colorOut[3] = colorIn[3];
- break;
- case GL_LUMINANCE:
- colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
- colorOut[3] = 1.0;
- break;
- case GL_LUMINANCE_ALPHA:
- colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
- colorOut[3] = colorIn[3];
- break;
- case GL_INTENSITY:
- colorOut[0] = colorOut[1] = colorOut[2] = colorOut[3] = colorIn[0];
- break;
- default:
- COPY_4V(colorOut, colorIn);
+ memset(sampler, 0, sizeof(*sampler));
+ sampler->wrap_s = gl_wrap_xlate(msamp->WrapS);
+ sampler->wrap_t = gl_wrap_xlate(msamp->WrapT);
+ sampler->wrap_r = gl_wrap_xlate(msamp->WrapR);
+
+ if (texobj->_IsIntegerFormat && st->ctx->Const.ForceIntegerTexNearest) {
+ sampler->min_img_filter = gl_filter_to_img_filter(GL_NEAREST);
+ sampler->mag_img_filter = gl_filter_to_img_filter(GL_NEAREST);
+ } else {
+ sampler->min_img_filter = gl_filter_to_img_filter(msamp->MinFilter);
+ sampler->mag_img_filter = gl_filter_to_img_filter(msamp->MagFilter);
+ }
+ sampler->min_mip_filter = gl_filter_to_mip_filter(msamp->MinFilter);
+
+ if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB)
+ sampler->normalized_coords = 1;
+
+ sampler->lod_bias = msamp->LodBias + tex_unit_lod_bias;
+ /* Reduce the number of states by allowing only the values that AMD GCN
+ * can represent. Apps use lod_bias for smooth transitions to bigger mipmap
+ * levels.
+ */
+ sampler->lod_bias = CLAMP(sampler->lod_bias, -16, 16);
+ sampler->lod_bias = floorf(sampler->lod_bias * 256) / 256;
+
+ sampler->min_lod = MAX2(msamp->MinLod, 0.0f);
+ sampler->max_lod = msamp->MaxLod;
+ if (sampler->max_lod < sampler->min_lod) {
+ /* The GL spec doesn't seem to specify what to do in this case.
+ * Swap the values.
+ */
+ float tmp = sampler->max_lod;
+ sampler->max_lod = sampler->min_lod;
+ sampler->min_lod = tmp;
+ assert(sampler->min_lod <= sampler->max_lod);
+ }
+
+ /* Check that only wrap modes using the border color have the first bit
+ * set.
+ */
+ STATIC_ASSERT(PIPE_TEX_WRAP_CLAMP & 0x1);
+ STATIC_ASSERT(PIPE_TEX_WRAP_CLAMP_TO_BORDER & 0x1);
+ STATIC_ASSERT(PIPE_TEX_WRAP_MIRROR_CLAMP & 0x1);
+ STATIC_ASSERT(PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER & 0x1);
+ STATIC_ASSERT(((PIPE_TEX_WRAP_REPEAT |
+ PIPE_TEX_WRAP_CLAMP_TO_EDGE |
+ PIPE_TEX_WRAP_MIRROR_REPEAT |
+ PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE) & 0x1) == 0);
+
+ /* For non-black borders... */
+ if (/* This is true if wrap modes are using the border color: */
+ (sampler->wrap_s | sampler->wrap_t | sampler->wrap_r) & 0x1 &&
+ (msamp->BorderColor.ui[0] ||
+ msamp->BorderColor.ui[1] ||
+ msamp->BorderColor.ui[2] ||
+ msamp->BorderColor.ui[3])) {
+ const GLboolean is_integer = texobj->_IsIntegerFormat;
+ GLenum texBaseFormat = _mesa_base_tex_image(texobj)->_BaseFormat;
+
+ if (texobj->StencilSampling)
+ texBaseFormat = GL_STENCIL_INDEX;
+
+ if (st->apply_texture_swizzle_to_border_color) {
+ const struct st_texture_object *stobj = st_texture_object_const(texobj);
+ /* XXX: clean that up to not use the sampler view at all */
+ const struct st_sampler_view *sv = st_texture_get_current_sampler_view(st, stobj);
+
+ if (sv) {
+ struct pipe_sampler_view *view = sv->view;
+ union pipe_color_union tmp;
+ const unsigned char swz[4] =
+ {
+ view->swizzle_r,
+ view->swizzle_g,
+ view->swizzle_b,
+ view->swizzle_a,
+ };
+
+ st_translate_color(&msamp->BorderColor, &tmp,
+ texBaseFormat, is_integer);
+
+ util_format_apply_color_swizzle(&sampler->border_color,
+ &tmp, swz, is_integer);
+ } else {
+ st_translate_color(&msamp->BorderColor,
+ &sampler->border_color,
+ texBaseFormat, is_integer);
+ }
+ } else {
+ st_translate_color(&msamp->BorderColor,
+ &sampler->border_color,
+ texBaseFormat, is_integer);
+ }