summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2012-02-29 20:55:49 -0700
committerBrian Paul <[email protected]>2012-03-08 20:10:36 -0700
commit774c4027651436451b3486f62b9a8903f29a715b (patch)
tree1f757d9d0aafdcb38ce83fb271e07a0a6ef76cf1 /src/mesa
parentbe5f27a84d0d4efb57071d9d7ecda061223d03ef (diff)
mesa: add _mesa_rebase_rgba_float/uint() functions
These will be used by glReadPixels() and glGetTexImage() to fix issues with reading GL_LUMINANCE and other formats. NOTE: This is a candidate for the 8.0 branch. Reviewed-by: José Fonseca <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/pack.c91
-rw-r--r--src/mesa/main/pack.h7
2 files changed, 98 insertions, 0 deletions
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 41485a1bf06..4d4b4a82569 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -5250,3 +5250,94 @@ _mesa_unpack_image( GLuint dimensions,
}
}
+
+
+/**
+ * If we unpack colors from a luminance surface, we'll get pixel colors
+ * such as (l, l, l, a).
+ * When we call _mesa_pack_rgba_span_float(format=GL_LUMINANCE), that
+ * function will compute L=R+G+B before packing. The net effect is we'll
+ * accidentally store luminance values = 3*l.
+ * This function compensates for that by converting (aka rebasing) (l,l,l,a)
+ * to be (l,0,0,a).
+ * It's a similar story for other formats such as LUMINANCE_ALPHA, ALPHA
+ * and INTENSITY.
+ *
+ * Finally, we also need to do this when the actual surface format does
+ * not match the logical surface format. For example, suppose the user
+ * requests a GL_LUMINANCE texture but the driver stores it as RGBA.
+ * Again, we'll get pixel values like (l,l,l,a).
+ */
+void
+_mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], GLenum baseFormat)
+{
+ GLuint i;
+
+ switch (baseFormat) {
+ case GL_ALPHA:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = 0.0F;
+ rgba[i][GCOMP] = 0.0F;
+ rgba[i][BCOMP] = 0.0F;
+ }
+ break;
+ case GL_INTENSITY:
+ /* fall-through */
+ case GL_LUMINANCE:
+ for (i = 0; i < n; i++) {
+ rgba[i][GCOMP] = 0.0F;
+ rgba[i][BCOMP] = 0.0F;
+ rgba[i][ACOMP] = 1.0F;
+ }
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i = 0; i < n; i++) {
+ rgba[i][GCOMP] = 0.0F;
+ rgba[i][BCOMP] = 0.0F;
+ }
+ break;
+ default:
+ /* no-op */
+ ;
+ }
+}
+
+
+/**
+ * As above, but GLuint components.
+ */
+void
+_mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat)
+{
+ GLuint i;
+
+ switch (baseFormat) {
+ case GL_ALPHA:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = 0;
+ rgba[i][GCOMP] = 0;
+ rgba[i][BCOMP] = 0;
+ }
+ break;
+ case GL_INTENSITY:
+ /* fall-through */
+ case GL_LUMINANCE:
+ for (i = 0; i < n; i++) {
+ rgba[i][GCOMP] = 0;
+ rgba[i][BCOMP] = 0;
+ rgba[i][ACOMP] = 1;
+ }
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i = 0; i < n; i++) {
+ rgba[i][GCOMP] = 0;
+ rgba[i][BCOMP] = 0;
+ }
+ break;
+ default:
+ /* no-op */
+ ;
+ }
+}
+
+
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h
index b1853cd5909..cd49c74954a 100644
--- a/src/mesa/main/pack.h
+++ b/src/mesa/main/pack.h
@@ -149,4 +149,11 @@ _mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
GLenum dstFormat, GLenum dstType,
GLvoid *dstAddr);
+
+extern void
+_mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], GLenum baseFormat);
+
+extern void
+_mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat);
+
#endif