aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorChristoph Bumiller <[email protected]>2013-04-12 13:42:01 +0200
committerChristoph Bumiller <[email protected]>2013-04-18 20:35:40 +0200
commit729abfd0f53c27ba58da95882bef985945933c65 (patch)
tree47623e71727be33fda952923809fb9b8391311ee /src/gallium/auxiliary/util
parent246ff8f887e10a2828fb43104a06ba6f2505b74d (diff)
st/mesa: optionally apply texture swizzle to border color v2
This is the only sane solution for nv50 and nvc0 (really, trust me), but since on other hardware the border colour is tightly coupled with texture state they'd have to undo the swizzle, so I've added a cap. The dependency of update_sampler on the texture updates was introduced to avoid doing the apply_depthmode to the swizzle twice. v2: Moved swizzling helper to u_format.c, extended the CAP to provide more accurate information.
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_format.c34
-rw-r--r--src/gallium/auxiliary/util/u_format.h12
2 files changed, 46 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index 18456371c0a..9bdc2eabf11 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -632,6 +632,40 @@ void util_format_compose_swizzles(const unsigned char swz1[4],
}
}
+void util_format_apply_color_swizzle(union pipe_color_union *dst,
+ const union pipe_color_union *src,
+ const unsigned char swz[4],
+ const boolean is_integer)
+{
+ unsigned c;
+
+ if (is_integer) {
+ for (c = 0; c < 4; ++c) {
+ switch (swz[c]) {
+ case PIPE_SWIZZLE_RED: dst->ui[c] = src->ui[0]; break;
+ case PIPE_SWIZZLE_GREEN: dst->ui[c] = src->ui[1]; break;
+ case PIPE_SWIZZLE_BLUE: dst->ui[c] = src->ui[2]; break;
+ case PIPE_SWIZZLE_ALPHA: dst->ui[c] = src->ui[3]; break;
+ default:
+ dst->ui[c] = (swz[c] == PIPE_SWIZZLE_ONE) ? 1 : 0;
+ break;
+ }
+ }
+ } else {
+ for (c = 0; c < 4; ++c) {
+ switch (swz[c]) {
+ case PIPE_SWIZZLE_RED: dst->f[c] = src->f[0]; break;
+ case PIPE_SWIZZLE_GREEN: dst->f[c] = src->f[1]; break;
+ case PIPE_SWIZZLE_BLUE: dst->f[c] = src->f[2]; break;
+ case PIPE_SWIZZLE_ALPHA: dst->f[c] = src->f[3]; break;
+ default:
+ dst->f[c] = (swz[c] == PIPE_SWIZZLE_ONE) ? 1.0f : 0.0f;
+ break;
+ }
+ }
+ }
+}
+
void util_format_swizzle_4f(float *dst, const float *src,
const unsigned char swz[4])
{
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index ed942fb1658..e4b9c365c97 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -33,6 +33,9 @@
#include "pipe/p_format.h"
#include "util/u_debug.h"
+union pipe_color_union;
+
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -1117,6 +1120,15 @@ void util_format_compose_swizzles(const unsigned char swz1[4],
const unsigned char swz2[4],
unsigned char dst[4]);
+/* Apply the swizzle provided in \param swz (which is one of PIPE_SWIZZLE_x)
+ * to \param src and store the result in \param dst.
+ * \param is_integer determines the value written for PIPE_SWIZZLE_ONE.
+ */
+void util_format_apply_color_swizzle(union pipe_color_union *dst,
+ const union pipe_color_union *src,
+ const unsigned char swz[4],
+ const boolean is_integer);
+
void util_format_swizzle_4f(float *dst, const float *src,
const unsigned char swz[4]);