aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-09-09 16:49:03 +0200
committermarha <marha@users.sourceforge.net>2011-09-09 16:49:03 +0200
commit05cf7dd22994a1dbfd3580b00690c01c392a5797 (patch)
treeec1c29b5f8a67c54b13b44f1eb7aa700f91fef9e
parent0947b921a3223c14322f10d83e71618d1724b734 (diff)
parentf9cf11136d65f20aab4fb6d5fc3ec3c59185a0b4 (diff)
downloadvcxsrv-05cf7dd22994a1dbfd3580b00690c01c392a5797.tar.gz
vcxsrv-05cf7dd22994a1dbfd3580b00690c01c392a5797.tar.bz2
vcxsrv-05cf7dd22994a1dbfd3580b00690c01c392a5797.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/include/GL/internal/dri_interface.h mesalib/scons/gallium.py mesalib/src/glsl/ast_to_hir.cpp mesalib/src/glsl/glsl_parser_extras.cpp mesalib/src/glsl/ir_variable.cpp mesalib/src/glsl/linker.cpp mesalib/src/mesa/SConscript mesalib/src/mesa/drivers/common/driverfuncs.c mesalib/src/mesa/main/compiler.h mesalib/src/mesa/main/formats.c mesalib/src/mesa/main/formats.h mesalib/src/mesa/main/texcompress.c mesalib/src/mesa/main/texgetimage.c mesalib/src/mesa/sources.mak
-rw-r--r--mesalib/include/GL/internal/dri_interface.h1
-rw-r--r--mesalib/scons/gallium.py2
-rw-r--r--mesalib/src/glsl/ast_to_hir.cpp92
-rw-r--r--mesalib/src/glsl/glsl_parser_extras.cpp2
-rw-r--r--mesalib/src/glsl/ir_set_program_inouts.cpp330
-rw-r--r--mesalib/src/glsl/ir_variable.cpp43
-rw-r--r--mesalib/src/glsl/linker.cpp19
-rw-r--r--mesalib/src/mapi/mapi/u_compiler.h25
-rw-r--r--mesalib/src/mesa/SConscript1
-rw-r--r--mesalib/src/mesa/drivers/common/driverfuncs.c2
-rw-r--r--mesalib/src/mesa/drivers/common/meta.c492
-rw-r--r--mesalib/src/mesa/drivers/common/meta.h7
-rw-r--r--mesalib/src/mesa/main/compiler.h31
-rw-r--r--mesalib/src/mesa/main/format_unpack.c1494
-rw-r--r--mesalib/src/mesa/main/format_unpack.h49
-rw-r--r--mesalib/src/mesa/main/formats.c64
-rw-r--r--mesalib/src/mesa/main/formats.h7
-rw-r--r--mesalib/src/mesa/main/mipmap.c85
-rw-r--r--mesalib/src/mesa/main/texcompress.c89
-rw-r--r--mesalib/src/mesa/main/texcompress.h5
-rw-r--r--mesalib/src/mesa/main/texgetimage.c177
-rw-r--r--mesalib/src/mesa/sources.mak1
22 files changed, 2602 insertions, 416 deletions
diff --git a/mesalib/include/GL/internal/dri_interface.h b/mesalib/include/GL/internal/dri_interface.h
index 09b2f2c8a..54b9b0de8 100644
--- a/mesalib/include/GL/internal/dri_interface.h
+++ b/mesalib/include/GL/internal/dri_interface.h
@@ -819,6 +819,7 @@ struct __DRIdri2ExtensionRec {
#define __DRI_IMAGE_FORMAT_RGB565 0x1001
#define __DRI_IMAGE_FORMAT_XRGB8888 0x1002
#define __DRI_IMAGE_FORMAT_ARGB8888 0x1003
+#define __DRI_IMAGE_FORMAT_ABGR8888 0x1004
#define __DRI_IMAGE_USE_SHARE 0x0001
#define __DRI_IMAGE_USE_SCANOUT 0x0002
diff --git a/mesalib/scons/gallium.py b/mesalib/scons/gallium.py
index 99481a410..28e505460 100644
--- a/mesalib/scons/gallium.py
+++ b/mesalib/scons/gallium.py
@@ -363,7 +363,7 @@ def generate(env):
ccflags += ['-O3']
# Work around aliasing bugs - developers should comment this out
ccflags += ['-fno-strict-aliasing']
- ccflags += ['-g3']
+ ccflags += ['-g']
if env['build'] in ('checked', 'profile'):
# See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
ccflags += [
diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp
index c85bb0dc7..5ddda824d 100644
--- a/mesalib/src/glsl/ast_to_hir.cpp
+++ b/mesalib/src/glsl/ast_to_hir.cpp
@@ -679,16 +679,20 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
lhs->variable_referenced()->name);
error_emitted = true;
+ } else if (state->language_version <= 110 && lhs->type->is_array()) {
+ /* From page 32 (page 38 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "Other binary or unary expressions, non-dereferenced
+ * arrays, function names, swizzles with repeated fields,
+ * and constants cannot be l-values."
+ */
+ _mesa_glsl_error(&lhs_loc, state, "whole array assignment is not "
+ "allowed in GLSL 1.10 or GLSL ES 1.00.");
+ error_emitted = true;
} else if (!lhs->is_lvalue()) {
_mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment");
error_emitted = true;
}
-
- if (state->es_shader && lhs->type->is_array()) {
- _mesa_glsl_error(&lhs_loc, state, "whole array assignment is not "
- "allowed in GLSL ES 1.00.");
- error_emitted = true;
- }
}
ir_rvalue *new_rhs =
@@ -723,6 +727,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
rhs->type->array_size());
d->type = var->type;
}
+ mark_whole_array_access(rhs);
mark_whole_array_access(lhs);
}
@@ -893,6 +898,44 @@ get_scalar_boolean_operand(exec_list *instructions,
return new(ctx) ir_constant(true);
}
+/**
+ * If name refers to a builtin array whose maximum allowed size is less than
+ * size, report an error and return true. Otherwise return false.
+ */
+static bool
+check_builtin_array_max_size(const char *name, unsigned size,
+ YYLTYPE loc, struct _mesa_glsl_parse_state *state)
+{
+ if ((strcmp("gl_TexCoord", name) == 0)
+ && (size > state->Const.MaxTextureCoords)) {
+ /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
+ *
+ * "The size [of gl_TexCoord] can be at most
+ * gl_MaxTextureCoords."
+ */
+ _mesa_glsl_error(&loc, state, "`gl_TexCoord' array size cannot "
+ "be larger than gl_MaxTextureCoords (%u)\n",
+ state->Const.MaxTextureCoords);
+ return true;
+ } else if (strcmp("gl_ClipDistance", name) == 0
+ && size > state->Const.MaxClipPlanes) {
+ /* From section 7.1 (Vertex Shader Special Variables) of the
+ * GLSL 1.30 spec:
+ *
+ * "The gl_ClipDistance array is predeclared as unsized and
+ * must be sized by the shader either redeclaring it with a
+ * size or indexing it only with integral constant
+ * expressions. ... The size can be at most
+ * gl_MaxClipDistances."
+ */
+ _mesa_glsl_error(&loc, state, "`gl_ClipDistance' array size cannot "
+ "be larger than gl_MaxClipDistances (%u)\n",
+ state->Const.MaxClipPlanes);
+ return true;
+ }
+ return false;
+}
+
ir_rvalue *
ast_expression::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
@@ -1550,8 +1593,15 @@ ast_expression::hir(exec_list *instructions,
* FINISHME: array access limits be added to ir_dereference?
*/
ir_variable *const v = array->whole_variable_referenced();
- if ((v != NULL) && (unsigned(idx) > v->max_array_access))
+ if ((v != NULL) && (unsigned(idx) > v->max_array_access)) {
v->max_array_access = idx;
+
+ /* Check whether this access will, as a side effect, implicitly
+ * cause the size of a built-in array to be too large.
+ */
+ if (check_builtin_array_max_size(v->name, idx+1, loc, state))
+ error_emitted = true;
+ }
}
} else if (array->type->array_size() == 0) {
_mesa_glsl_error(&loc, state, "unsized array index must be constant");
@@ -2071,6 +2121,21 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
else
var->depth_layout = ir_depth_layout_none;
+ /* From page 46 (page 52 of the PDF) of the GLSL ES specification:
+ *
+ * "Array variables are l-values and may be passed to parameters
+ * declared as out or inout. However, they may not be used as
+ * the target of an assignment."
+ *
+ * From page 32 (page 38 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "Other binary or unary expressions, non-dereferenced arrays,
+ * function names, swizzles with repeated fields, and constants
+ * cannot be l-values."
+ *
+ * So we only mark 1.10 as non-lvalues, and check for array
+ * assignment in 100 specifically in do_assignment.
+ */
if (var->type->is_array() && state->language_version != 110) {
var->array_lvalue = true;
}
@@ -2121,18 +2186,9 @@ get_variable_being_redeclared(ir_variable *var, ast_declaration *decl,
* FINISHME: required or not.
*/
- /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
- *
- * "The size [of gl_TexCoord] can be at most
- * gl_MaxTextureCoords."
- */
const unsigned size = unsigned(var->type->array_size());
- if ((strcmp("gl_TexCoord", var->name) == 0)
- && (size > state->Const.MaxTextureCoords)) {
- _mesa_glsl_error(& loc, state, "`gl_TexCoord' array size cannot "
- "be larger than gl_MaxTextureCoords (%u)\n",
- state->Const.MaxTextureCoords);
- } else if ((size > 0) && (size <= earlier->max_array_access)) {
+ check_builtin_array_max_size(var->name, size, loc, state);
+ if ((size > 0) && (size <= earlier->max_array_access)) {
_mesa_glsl_error(& loc, state, "array size must be > %u due to "
"previous access",
earlier->max_array_access);
diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp
index 7204c9274..5d66fe9d5 100644
--- a/mesalib/src/glsl/glsl_parser_extras.cpp
+++ b/mesalib/src/glsl/glsl_parser_extras.cpp
@@ -891,8 +891,8 @@ do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iteration
if (linked) {
progress = do_function_inlining(ir) || progress;
progress = do_dead_functions(ir) || progress;
+ progress = do_structure_splitting(ir) || progress;
}
- progress = do_structure_splitting(ir) || progress;
progress = do_if_simplification(ir) || progress;
progress = do_discard_simplification(ir) || progress;
progress = do_copy_propagation(ir) || progress;
diff --git a/mesalib/src/glsl/ir_set_program_inouts.cpp b/mesalib/src/glsl/ir_set_program_inouts.cpp
index c5533c8cd..3b10b9097 100644
--- a/mesalib/src/glsl/ir_set_program_inouts.cpp
+++ b/mesalib/src/glsl/ir_set_program_inouts.cpp
@@ -1,166 +1,164 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file ir_set_program_inouts.cpp
- *
- * Sets the InputsRead and OutputsWritten of Mesa programs.
- *
- * Mesa programs (gl_program, not gl_shader_program) have a set of
- * flags indicating which varyings are read and written. Computing
- * which are actually read from some sort of backend code can be
- * tricky when variable array indexing involved. So this pass
- * provides support for setting InputsRead and OutputsWritten right
- * from the GLSL IR.
- */
-
-extern "C" {
-#include "main/core.h" /* for struct gl_program */
-#include "program/hash_table.h"
-}
-#include "ir.h"
-#include "ir_visitor.h"
-#include "glsl_types.h"
-
-class ir_set_program_inouts_visitor : public ir_hierarchical_visitor {
-public:
- ir_set_program_inouts_visitor(struct gl_program *prog)
- {
- this->prog = prog;
- this->ht = hash_table_ctor(0,
- hash_table_pointer_hash,
- hash_table_pointer_compare);
- }
- ~ir_set_program_inouts_visitor()
- {
- hash_table_dtor(this->ht);
- }
-
- virtual ir_visitor_status visit_enter(ir_dereference_array *);
- virtual ir_visitor_status visit_enter(ir_function_signature *);
- virtual ir_visitor_status visit(ir_dereference_variable *);
- virtual ir_visitor_status visit(ir_variable *);
-
- struct gl_program *prog;
- struct hash_table *ht;
-};
-
-static void
-mark(struct gl_program *prog, ir_variable *var, int offset, int len)
-{
- /* As of GLSL 1.20, varyings can only be floats, floating-point
- * vectors or matrices, or arrays of them. For Mesa programs using
- * InputsRead/OutputsWritten, everything but matrices uses one
- * slot, while matrices use a slot per column. Presumably
- * something doing a more clever packing would use something other
- * than InputsRead/OutputsWritten.
- */
-
- for (int i = 0; i < len; i++) {
- if (var->mode == ir_var_in)
- prog->InputsRead |= BITFIELD64_BIT(var->location + offset + i);
- else if (var->mode == ir_var_system_value)
- prog->SystemValuesRead |= (1 << (var->location + offset + i));
- else
- prog->OutputsWritten |= BITFIELD64_BIT(var->location + offset + i);
- }
-}
-
-/* Default handler: Mark all the locations in the variable as used. */
-ir_visitor_status
-ir_set_program_inouts_visitor::visit(ir_dereference_variable *ir)
-{
- if (hash_table_find(this->ht, ir->var) == NULL)
- return visit_continue;
-
- if (ir->type->is_array()) {
- for (unsigned int i = 0; i < ir->type->length; i++) {
- mark(this->prog, ir->var, i,
- ir->type->length * ir->type->fields.array->matrix_columns);
- }
- } else {
- mark(this->prog, ir->var, 0, ir->type->matrix_columns);
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_set_program_inouts_visitor::visit_enter(ir_dereference_array *ir)
-{
- ir_dereference_variable *deref_var;
- ir_constant *index = ir->array_index->as_constant();
- deref_var = ir->array->as_dereference_variable();
- ir_variable *var = NULL;
-
- /* Check that we're dereferencing a shader in or out */
- if (deref_var)
- var = (ir_variable *)hash_table_find(this->ht, deref_var->var);
-
- if (index && var) {
- int width = 1;
-
- if (deref_var->type->is_array() &&
- deref_var->type->fields.array->is_matrix()) {
- width = deref_var->type->fields.array->matrix_columns;
- }
-
- mark(this->prog, var, index->value.i[0] * width, width);
- return visit_continue_with_parent;
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_set_program_inouts_visitor::visit(ir_variable *ir)
-{
- if (ir->mode == ir_var_in ||
- ir->mode == ir_var_out ||
- ir->mode == ir_var_system_value) {
- hash_table_insert(this->ht, ir, ir);
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_set_program_inouts_visitor::visit_enter(ir_function_signature *ir)
-{
- /* We don't want to descend into the function parameters and
- * consider them as shader inputs or outputs.
- */
- visit_list_elements(this, &ir->body);
- return visit_continue_with_parent;
-}
-
-void
-do_set_program_inouts(exec_list *instructions, struct gl_program *prog)
-{
- ir_set_program_inouts_visitor v(prog);
-
- prog->InputsRead = 0;
- prog->OutputsWritten = 0;
- prog->SystemValuesRead = 0;
- visit_list_elements(&v, instructions);
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file ir_set_program_inouts.cpp
+ *
+ * Sets the InputsRead and OutputsWritten of Mesa programs.
+ *
+ * Mesa programs (gl_program, not gl_shader_program) have a set of
+ * flags indicating which varyings are read and written. Computing
+ * which are actually read from some sort of backend code can be
+ * tricky when variable array indexing involved. So this pass
+ * provides support for setting InputsRead and OutputsWritten right
+ * from the GLSL IR.
+ */
+
+extern "C" {
+#include "main/core.h" /* for struct gl_program */
+#include "program/hash_table.h"
+}
+#include "ir.h"
+#include "ir_visitor.h"
+#include "glsl_types.h"
+
+class ir_set_program_inouts_visitor : public ir_hierarchical_visitor {
+public:
+ ir_set_program_inouts_visitor(struct gl_program *prog)
+ {
+ this->prog = prog;
+ this->ht = hash_table_ctor(0,
+ hash_table_pointer_hash,
+ hash_table_pointer_compare);
+ }
+ ~ir_set_program_inouts_visitor()
+ {
+ hash_table_dtor(this->ht);
+ }
+
+ virtual ir_visitor_status visit_enter(ir_dereference_array *);
+ virtual ir_visitor_status visit_enter(ir_function_signature *);
+ virtual ir_visitor_status visit(ir_dereference_variable *);
+ virtual ir_visitor_status visit(ir_variable *);
+
+ struct gl_program *prog;
+ struct hash_table *ht;
+};
+
+static void
+mark(struct gl_program *prog, ir_variable *var, int offset, int len)
+{
+ /* As of GLSL 1.20, varyings can only be floats, floating-point
+ * vectors or matrices, or arrays of them. For Mesa programs using
+ * InputsRead/OutputsWritten, everything but matrices uses one
+ * slot, while matrices use a slot per column. Presumably
+ * something doing a more clever packing would use something other
+ * than InputsRead/OutputsWritten.
+ */
+
+ for (int i = 0; i < len; i++) {
+ if (var->mode == ir_var_in)
+ prog->InputsRead |= BITFIELD64_BIT(var->location + offset + i);
+ else if (var->mode == ir_var_system_value)
+ prog->SystemValuesRead |= (1 << (var->location + offset + i));
+ else
+ prog->OutputsWritten |= BITFIELD64_BIT(var->location + offset + i);
+ }
+}
+
+/* Default handler: Mark all the locations in the variable as used. */
+ir_visitor_status
+ir_set_program_inouts_visitor::visit(ir_dereference_variable *ir)
+{
+ if (hash_table_find(this->ht, ir->var) == NULL)
+ return visit_continue;
+
+ if (ir->type->is_array()) {
+ mark(this->prog, ir->var, 0,
+ ir->type->length * ir->type->fields.array->matrix_columns);
+ } else {
+ mark(this->prog, ir->var, 0, ir->type->matrix_columns);
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_set_program_inouts_visitor::visit_enter(ir_dereference_array *ir)
+{
+ ir_dereference_variable *deref_var;
+ ir_constant *index = ir->array_index->as_constant();
+ deref_var = ir->array->as_dereference_variable();
+ ir_variable *var = NULL;
+
+ /* Check that we're dereferencing a shader in or out */
+ if (deref_var)
+ var = (ir_variable *)hash_table_find(this->ht, deref_var->var);
+
+ if (index && var) {
+ int width = 1;
+
+ if (deref_var->type->is_array() &&
+ deref_var->type->fields.array->is_matrix()) {
+ width = deref_var->type->fields.array->matrix_columns;
+ }
+
+ mark(this->prog, var, index->value.i[0] * width, width);
+ return visit_continue_with_parent;
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_set_program_inouts_visitor::visit(ir_variable *ir)
+{
+ if (ir->mode == ir_var_in ||
+ ir->mode == ir_var_out ||
+ ir->mode == ir_var_system_value) {
+ hash_table_insert(this->ht, ir, ir);
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_set_program_inouts_visitor::visit_enter(ir_function_signature *ir)
+{
+ /* We don't want to descend into the function parameters and
+ * consider them as shader inputs or outputs.
+ */
+ visit_list_elements(this, &ir->body);
+ return visit_continue_with_parent;
+}
+
+void
+do_set_program_inouts(exec_list *instructions, struct gl_program *prog)
+{
+ ir_set_program_inouts_visitor v(prog);
+
+ prog->InputsRead = 0;
+ prog->OutputsWritten = 0;
+ prog->SystemValuesRead = 0;
+ visit_list_elements(&v, instructions);
+}
diff --git a/mesalib/src/glsl/ir_variable.cpp b/mesalib/src/glsl/ir_variable.cpp
index 8495043fe..76f79da92 100644
--- a/mesalib/src/glsl/ir_variable.cpp
+++ b/mesalib/src/glsl/ir_variable.cpp
@@ -585,6 +585,17 @@ generate_120_vs_variables(exec_list *instructions,
static void
+generate_130_uniforms(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ glsl_symbol_table *const symtab = state->symbols;
+
+ add_builtin_constant(instructions, symtab, "gl_MaxClipDistances",
+ state->Const.MaxClipPlanes);
+}
+
+
+static void
generate_130_vs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
@@ -595,9 +606,20 @@ generate_130_vs_variables(exec_list *instructions,
& builtin_130_vs_variables[i]);
}
+ generate_130_uniforms(instructions, state);
+
+ /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special
+ * Variables):
+ *
+ * The gl_ClipDistance array is predeclared as unsized and must
+ * be sized by the shader either redeclaring it with a size or
+ * indexing it only with integral constant expressions.
+ *
+ * We represent this in Mesa by initially declaring the array as
+ * size 0.
+ */
const glsl_type *const clip_distance_array_type =
- glsl_type::get_array_instance(glsl_type::float_type,
- state->Const.MaxClipPlanes);
+ glsl_type::get_array_instance(glsl_type::float_type, 0);
/* FINISHME: gl_ClipDistance needs a real location assigned. */
add_variable(instructions, state->symbols,
@@ -802,9 +824,22 @@ generate_130_fs_variables(exec_list *instructions,
{
generate_120_fs_variables(instructions, state);
+ generate_130_uniforms(instructions, state);
+
+ /* From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special
+ * Variables):
+ *
+ * The built-in input variable gl_ClipDistance array contains linearly
+ * interpolated values for the vertex values written by the vertex shader
+ * to the gl_ClipDistance vertex output variable. This array must be
+ * sized in the fragment shader either implicitly or explicitly to be the
+ * same size as it was sized in the vertex shader.
+ *
+ * In other words, the array must be pre-declared as implicitly sized. We
+ * represent this in Mesa by initially declaring the array as size 0.
+ */
const glsl_type *const clip_distance_array_type =
- glsl_type::get_array_instance(glsl_type::float_type,
- state->Const.MaxClipPlanes);
+ glsl_type::get_array_instance(glsl_type::float_type, 0);
/* FINISHME: gl_ClipDistance needs a real location assigned. */
add_variable(instructions, state->symbols,
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp
index 3538dc5fe..ad50fe18d 100644
--- a/mesalib/src/glsl/linker.cpp
+++ b/mesalib/src/glsl/linker.cpp
@@ -262,6 +262,25 @@ validate_vertex_shader_executable(struct gl_shader_program *prog,
return false;
}
+ if (prog->Version >= 130) {
+ /* From section 7.1 (Vertex Shader Special Variables) of the
+ * GLSL 1.30 spec:
+ *
+ * "It is an error for a shader to statically write both
+ * gl_ClipVertex and gl_ClipDistance."
+ */
+ find_assignment_visitor clip_vertex("gl_ClipVertex");
+ find_assignment_visitor clip_distance("gl_ClipDistance");
+
+ clip_vertex.run(shader->ir);
+ clip_distance.run(shader->ir);
+ if (clip_vertex.variable_found() && clip_distance.variable_found()) {
+ linker_error(prog, "vertex shader writes to both `gl_ClipVertex' "
+ "and `gl_ClipDistance'\n");
+ return false;
+ }
+ }
+
return true;
}
diff --git a/mesalib/src/mapi/mapi/u_compiler.h b/mesalib/src/mapi/mapi/u_compiler.h
index f1752d16f..2b019ed15 100644
--- a/mesalib/src/mapi/mapi/u_compiler.h
+++ b/mesalib/src/mapi/mapi/u_compiler.h
@@ -2,27 +2,30 @@
#define _U_COMPILER_H_
/* Function inlining */
-#ifndef INLINE
+#ifndef inline
# ifdef __cplusplus
-# define INLINE inline
+ /* C++ supports inline keyword */
# elif defined(__GNUC__)
-# define INLINE __inline__
+# define inline __inline__
# elif defined(_MSC_VER)
-# define INLINE __inline
+# define inline __inline
# elif defined(__ICL)
-# define INLINE __inline
+# define inline __inline
# elif defined(__INTEL_COMPILER)
-# define INLINE inline
+ /* Intel compiler supports inline keyword */
# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
-# define INLINE __inline
+# define inline __inline
# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
-# define INLINE inline
-# elif (__STDC_VERSION__ >= 199901L) /* C99 */
-# define INLINE inline
+ /* C99 supports inline keyword */
+# elif (__STDC_VERSION__ >= 199901L)
+ /* C99 supports inline keyword */
# else
-# define INLINE
+# define inline
# endif
#endif
+#ifndef INLINE
+# define INLINE inline
+#endif
/* Function visibility */
#ifndef PUBLIC
diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript
index 089d2356e..70c4a2203 100644
--- a/mesalib/src/mesa/SConscript
+++ b/mesalib/src/mesa/SConscript
@@ -72,6 +72,7 @@ main_sources = [
'main/ffvertex_prog.c',
'main/fog.c',
'main/formats.c',
+ 'main/format_unpack.c',
'main/framebuffer.c',
'main/get.c',
'main/getstring.c',
diff --git a/mesalib/src/mesa/drivers/common/driverfuncs.c b/mesalib/src/mesa/drivers/common/driverfuncs.c
index 14990b9c9..63df03f5d 100644
--- a/mesalib/src/mesa/drivers/common/driverfuncs.c
+++ b/mesalib/src/mesa/drivers/common/driverfuncs.c
@@ -94,7 +94,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
driver->TexSubImage1D = _mesa_store_texsubimage1d;
driver->TexSubImage2D = _mesa_store_texsubimage2d;
driver->TexSubImage3D = _mesa_store_texsubimage3d;
- driver->GetTexImage = _mesa_get_teximage;
+ driver->GetTexImage = _mesa_meta_GetTexImage;
driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D;
driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D;
driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D;
diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c
index ad04d369f..2ebcd35bd 100644
--- a/mesalib/src/mesa/drivers/common/meta.c
+++ b/mesalib/src/mesa/drivers/common/meta.c
@@ -59,6 +59,7 @@
#include "main/stencil.h"
#include "main/texobj.h"
#include "main/texenv.h"
+#include "main/texgetimage.h"
#include "main/teximage.h"
#include "main/texparam.h"
#include "main/texstate.h"
@@ -259,6 +260,18 @@ struct gen_mipmap_state
GLuint FBO;
};
+
+/**
+ * State for texture decompression
+ */
+struct decompress_state
+{
+ GLuint ArrayObj;
+ GLuint VBO, FBO, RBO;
+ GLint Width, Height;
+};
+
+
#define MAX_META_OPS_DEPTH 2
/**
* All per-context meta state.
@@ -278,6 +291,7 @@ struct gl_meta_state
struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */
struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */
struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */
+ struct decompress_state Decompress; /**< For texture decompression */
};
@@ -2477,6 +2491,160 @@ _mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target,
/**
+ * Compute the texture coordinates for the four vertices of a quad for
+ * drawing a 2D texture image or slice of a cube/3D texture.
+ * \param faceTarget GL_TEXTURE_1D/2D/3D or cube face name
+ * \param slice slice of a 1D/2D array texture or 3D texture
+ * \param width width of the texture image
+ * \param height height of the texture image
+ * \param coords0/1/2/3 returns the computed texcoords
+ */
+static void
+setup_texture_coords(GLenum faceTarget,
+ GLint slice,
+ GLint width,
+ GLint height,
+ GLfloat coords0[3],
+ GLfloat coords1[3],
+ GLfloat coords2[3],
+ GLfloat coords3[3])
+{
+ static const GLfloat st[4][2] = {
+ {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
+ };
+ GLuint i;
+ GLfloat r;
+
+ switch (faceTarget) {
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_3D:
+ case GL_TEXTURE_2D_ARRAY:
+ if (faceTarget == GL_TEXTURE_3D)
+ r = 1.0F / slice;
+ else if (faceTarget == GL_TEXTURE_2D_ARRAY)
+ r = slice;
+ else
+ r = 0.0F;
+ coords0[0] = 0.0F; /* s */
+ coords0[1] = 0.0F; /* t */
+ coords0[2] = r; /* r */
+ coords1[0] = 1.0F;
+ coords1[1] = 0.0F;
+ coords1[2] = r;
+ coords2[0] = 1.0F;
+ coords2[1] = 1.0F;
+ coords2[2] = r;
+ coords3[0] = 0.0F;
+ coords3[1] = 1.0F;
+ coords3[2] = r;
+ break;
+ case GL_TEXTURE_RECTANGLE_ARB:
+ coords0[0] = 0.0F; /* s */
+ coords0[1] = 0.0F; /* t */
+ coords0[2] = 0.0F; /* r */
+ coords1[0] = width;
+ coords1[1] = 0.0F;
+ coords1[2] = 0.0F;
+ coords2[0] = width;
+ coords2[1] = height;
+ coords2[2] = 0.0F;
+ coords3[0] = 0.0F;
+ coords3[1] = height;
+ coords3[2] = 0.0F;
+ break;
+ case GL_TEXTURE_1D_ARRAY:
+ coords0[0] = 0.0F; /* s */
+ coords0[1] = slice; /* t */
+ coords0[2] = 0.0F; /* r */
+ coords1[0] = 1.0f;
+ coords1[1] = slice;
+ coords1[2] = 0.0F;
+ coords2[0] = 1.0F;
+ coords2[1] = slice;
+ coords2[2] = 0.0F;
+ coords3[0] = 0.0F;
+ coords3[1] = slice;
+ coords3[2] = 0.0F;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ /* loop over quad verts */
+ for (i = 0; i < 4; i++) {
+ /* Compute sc = +/-scale and tc = +/-scale.
+ * Not +/-1 to avoid cube face selection ambiguity near the edges,
+ * though that can still sometimes happen with this scale factor...
+ */
+ const GLfloat scale = 0.9999f;
+ const GLfloat sc = (2.0f * st[i][0] - 1.0f) * scale;
+ const GLfloat tc = (2.0f * st[i][1] - 1.0f) * scale;
+ GLfloat *coord;
+
+ switch (i) {
+ case 0:
+ coord = coords0;
+ break;
+ case 1:
+ coord = coords1;
+ break;
+ case 2:
+ coord = coords2;
+ break;
+ case 3:
+ coord = coords3;
+ break;
+ default:
+ assert(0);
+ }
+
+ switch (faceTarget) {
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ coord[0] = 1.0f;
+ coord[1] = -tc;
+ coord[2] = -sc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ coord[0] = -1.0f;
+ coord[1] = -tc;
+ coord[2] = sc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ coord[0] = sc;
+ coord[1] = 1.0f;
+ coord[2] = tc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ coord[0] = sc;
+ coord[1] = -1.0f;
+ coord[2] = -tc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ coord[0] = sc;
+ coord[1] = -tc;
+ coord[2] = 1.0f;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ coord[0] = -sc;
+ coord[1] = -tc;
+ coord[2] = -1.0f;
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+ default:
+ assert(0 && "unexpected target in meta setup_texture_coords()");
+ }
+}
+
+
+/**
* Called via ctx->Driver.GenerateMipmap()
* Note: We don't yet support 3D textures, 1D/2D array textures or texture
* borders.
@@ -2487,7 +2655,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
{
struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap;
struct vertex {
- GLfloat x, y, s, t, r;
+ GLfloat x, y, tex[3];
};
struct vertex verts[4];
const GLuint baseLevel = texObj->BaseLevel;
@@ -2503,7 +2671,8 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
const GLuint original_active_unit = ctx->Texture.CurrentUnit;
GLenum faceTarget;
GLuint dstLevel;
- GLuint border = 0;
+ const GLuint border = 0;
+ const GLint slice = 0;
if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) {
_mesa_generate_mipmap(ctx, target, texObj);
@@ -2539,7 +2708,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
/* setup vertex arrays */
_mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
- _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
+ _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(tex));
_mesa_EnableClientState(GL_VERTEX_ARRAY);
_mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
}
@@ -2562,98 +2731,27 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
_mesa_set_enable(ctx, target, GL_TRUE);
- /* setup texcoords once (XXX what about border?) */
- switch (faceTarget) {
- case GL_TEXTURE_1D:
- case GL_TEXTURE_2D:
- verts[0].s = 0.0F;
- verts[0].t = 0.0F;
- verts[0].r = 0.0F;
- verts[1].s = 1.0F;
- verts[1].t = 0.0F;
- verts[1].r = 0.0F;
- verts[2].s = 1.0F;
- verts[2].t = 1.0F;
- verts[2].r = 0.0F;
- verts[3].s = 0.0F;
- verts[3].t = 1.0F;
- verts[3].r = 0.0F;
- break;
- case GL_TEXTURE_3D:
- abort();
- break;
- default:
- /* cube face */
- {
- static const GLfloat st[4][2] = {
- {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
- };
- GLuint i;
-
- /* loop over quad verts */
- for (i = 0; i < 4; i++) {
- /* Compute sc = +/-scale and tc = +/-scale.
- * Not +/-1 to avoid cube face selection ambiguity near the edges,
- * though that can still sometimes happen with this scale factor...
- */
- const GLfloat scale = 0.9999f;
- const GLfloat sc = (2.0f * st[i][0] - 1.0f) * scale;
- const GLfloat tc = (2.0f * st[i][1] - 1.0f) * scale;
-
- switch (faceTarget) {
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- verts[i].s = 1.0f;
- verts[i].t = -tc;
- verts[i].r = -sc;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- verts[i].s = -1.0f;
- verts[i].t = -tc;
- verts[i].r = sc;
- break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- verts[i].s = sc;
- verts[i].t = 1.0f;
- verts[i].r = tc;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- verts[i].s = sc;
- verts[i].t = -1.0f;
- verts[i].r = -tc;
- break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- verts[i].s = sc;
- verts[i].t = -tc;
- verts[i].r = 1.0f;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- verts[i].s = -sc;
- verts[i].t = -tc;
- verts[i].r = -1.0f;
- break;
- default:
- assert(0);
- }
- }
- }
- }
-
- _mesa_set_enable(ctx, target, GL_TRUE);
+ /* setup texcoords (XXX what about border?) */
+ setup_texture_coords(faceTarget,
+ 0.0, 0.0, /* width, height never used here */
+ slice,
+ verts[0].tex,
+ verts[1].tex,
+ verts[2].tex,
+ verts[3].tex);
/* setup vertex positions */
- {
- verts[0].x = 0.0F;
- verts[0].y = 0.0F;
- verts[1].x = 1.0F;
- verts[1].y = 0.0F;
- verts[2].x = 1.0F;
- verts[2].y = 1.0F;
- verts[3].x = 0.0F;
- verts[3].y = 1.0F;
+ verts[0].x = 0.0F;
+ verts[0].y = 0.0F;
+ verts[1].x = 1.0F;
+ verts[1].y = 0.0F;
+ verts[2].x = 1.0F;
+ verts[2].y = 1.0F;
+ verts[3].x = 0.0F;
+ verts[3].y = 1.0F;
- /* upload new vertex data */
- _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
- }
+ /* upload new vertex data */
+ _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
/* setup projection matrix */
_mesa_MatrixMode(GL_PROJECTION);
@@ -2939,3 +3037,213 @@ _mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
copy_tex_sub_image(ctx, 3, target, level, xoffset, yoffset, zoffset,
x, y, width, height);
}
+
+
+/**
+ * Decompress a texture image by drawing a quad with the compressed
+ * texture and reading the pixels out of the color buffer.
+ * \param slice which slice of a 3D texture or layer of a 1D/2D texture
+ * \param destFormat format, ala glReadPixels
+ * \param destType type, ala glReadPixels
+ * \param dest destination buffer
+ * \param destRowLength dest image rowLength (ala GL_PACK_ROW_LENGTH)
+ */
+static void
+decompress_texture_image(struct gl_context *ctx,
+ struct gl_texture_image *texImage,
+ GLuint slice,
+ GLenum destFormat, GLenum destType,
+ GLvoid *dest, GLint destRowLength)
+{
+ struct decompress_state *decompress = &ctx->Meta->Decompress;
+ struct gl_texture_object *texObj = texImage->TexObject;
+ const GLint width = texImage->Width;
+ const GLint height = texImage->Height;
+ const GLenum target = texObj->Target;
+ GLenum faceTarget;
+ struct vertex {
+ GLfloat x, y, tex[3];
+ };
+ struct vertex verts[4];
+ GLuint fboDrawSave, fboReadSave;
+
+ if (slice > 0) {
+ assert(target == GL_TEXTURE_3D ||
+ target == GL_TEXTURE_2D_ARRAY);
+ }
+
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + texImage->Face;
+ }
+ else {
+ faceTarget = target;
+ }
+
+ /* save fbo bindings (not saved by _mesa_meta_begin()) */
+ fboDrawSave = ctx->DrawBuffer->Name;
+ fboReadSave = ctx->ReadBuffer->Name;
+
+ _mesa_meta_begin(ctx, MESA_META_ALL);
+
+ /* Create/bind FBO/renderbuffer */
+ if (decompress->FBO == 0) {
+ _mesa_GenFramebuffersEXT(1, &decompress->FBO);
+ _mesa_GenRenderbuffersEXT(1, &decompress->RBO);
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, decompress->FBO);
+ _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, decompress->RBO);
+ _mesa_FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ GL_RENDERBUFFER_EXT,
+ decompress->RBO);
+ }
+ else {
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, decompress->FBO);
+ }
+
+ /* alloc dest surface */
+ if (width != decompress->Width || height != decompress->Height) {
+ _mesa_RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA,
+ width, height);
+ decompress->Width = width;
+ decompress->Height = height;
+ }
+
+ /* setup VBO data */
+ if (decompress->ArrayObj == 0) {
+ /* create vertex array object */
+ _mesa_GenVertexArrays(1, &decompress->ArrayObj);
+ _mesa_BindVertexArray(decompress->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &decompress->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, decompress->VBO);
+ _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
+ NULL, GL_DYNAMIC_DRAW_ARB);
+
+ /* setup vertex arrays */
+ _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(tex));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ else {
+ _mesa_BindVertexArray(decompress->ArrayObj);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, decompress->VBO);
+ }
+
+ setup_texture_coords(faceTarget, slice, width, height,
+ verts[0].tex,
+ verts[1].tex,
+ verts[2].tex,
+ verts[3].tex);
+
+ /* setup vertex positions */
+ verts[0].x = 0.0F;
+ verts[0].y = 0.0F;
+ verts[1].x = width;
+ verts[1].y = 0.0F;
+ verts[2].x = width;
+ verts[2].y = height;
+ verts[3].x = 0.0F;
+ verts[3].y = height;
+
+ /* upload new vertex data */
+ _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
+
+ /* setup texture state */
+ _mesa_BindTexture(target, texObj->Name);
+ _mesa_Enable(target);
+
+ {
+ /* save texture object state */
+ const GLenum minFilterSave = texObj->Sampler.MinFilter;
+ const GLenum magFilterSave = texObj->Sampler.MagFilter;
+ const GLint baseLevelSave = texObj->BaseLevel;
+ const GLint maxLevelSave = texObj->MaxLevel;
+ const GLenum wrapSSave = texObj->Sampler.WrapS;
+ const GLenum wrapTSave = texObj->Sampler.WrapT;
+ const GLenum srgbSave = texObj->Sampler.sRGBDecode;
+
+ /* restrict sampling to the texture level of interest */
+ _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, texImage->Level);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, texImage->Level);
+ /* nearest filtering */
+ _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ /* No sRGB decode or encode.*/
+ if (ctx->Extensions.EXT_texture_sRGB_decode) {
+ _mesa_TexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT,
+ GL_SKIP_DECODE_EXT);
+ }
+ if (ctx->Extensions.EXT_framebuffer_sRGB) {
+ _mesa_Disable(GL_FRAMEBUFFER_SRGB_EXT);
+ }
+
+ /* render quad w/ texture into renderbuffer */
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ /* Restore texture object state, the texture binding will
+ * be restored by _mesa_meta_end().
+ */
+ _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave);
+ if (target != GL_TEXTURE_RECTANGLE_ARB) {
+ _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
+ }
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave);
+ if (ctx->Extensions.EXT_texture_sRGB_decode) {
+ _mesa_TexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT, srgbSave);
+ }
+ }
+
+ /* read pixels from renderbuffer */
+ ctx->Pack.RowLength = destRowLength;
+ _mesa_ReadPixels(0, 0, width, height, destFormat, destType, dest);
+
+ _mesa_meta_end(ctx);
+
+ /* restore fbo bindings */
+ if (fboDrawSave == fboReadSave) {
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboDrawSave);
+ }
+ else {
+ _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fboDrawSave);
+ _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fboReadSave);
+ }
+}
+
+
+/**
+ * This is just a wrapper around _mesa_get_tex_image() and
+ * decompress_texture_image(). Meta functions should not be directly called
+ * from core Mesa.
+ */
+void
+_mesa_meta_GetTexImage(struct gl_context *ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* We can only use the decompress-with-blit method here if the texels are
+ * unsigned, normalized values. We could handle signed and unnormalized
+ * with floating point renderbuffers...
+ */
+ if (_mesa_is_format_compressed(texImage->TexFormat) &&
+ _mesa_get_format_datatype(texImage->TexFormat)
+ == GL_UNSIGNED_NORMALIZED) {
+ const GLuint slice = 0; /* only 2D compressed textures for now */
+ /* Need to unlock the texture here to prevent deadlock... */
+ _mesa_unlock_texture(ctx, texObj);
+ decompress_texture_image(ctx, texImage, slice, format, type, pixels,
+ ctx->Pack.RowLength);
+ /* ... and relock it */
+ _mesa_lock_texture(ctx, texObj);
+ }
+ else {
+ _mesa_get_teximage(ctx, target, level, format, type, pixels,
+ texObj, texImage);
+ }
+}
diff --git a/mesalib/src/mesa/drivers/common/meta.h b/mesalib/src/mesa/drivers/common/meta.h
index 9a92613c4..9d634ae56 100644
--- a/mesalib/src/mesa/drivers/common/meta.h
+++ b/mesalib/src/mesa/drivers/common/meta.h
@@ -121,4 +121,11 @@ _mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
GLint x, GLint y,
GLsizei width, GLsizei height);
+extern void
+_mesa_meta_GetTexImage(struct gl_context *ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
#endif /* META_H */
diff --git a/mesalib/src/mesa/main/compiler.h b/mesalib/src/mesa/main/compiler.h
index 942ac6b0a..d2caaaa79 100644
--- a/mesalib/src/mesa/main/compiler.h
+++ b/mesalib/src/mesa/main/compiler.h
@@ -114,29 +114,30 @@ extern "C" {
/**
* Function inlining
*/
-#ifndef INLINE
-# if defined(__GNUC__)
-# define INLINE __inline__
-# elif defined(__MSC__)
-# define INLINE __inline
+#ifndef inline
+# ifdef __cplusplus
+ /* C++ supports inline keyword */
+# elif defined(__GNUC__)
+# define inline __inline__
# elif defined(_MSC_VER)
-# define INLINE __inline
+# define inline __inline
# elif defined(__ICL)
-# define INLINE __inline
+# define inline __inline
# elif defined(__INTEL_COMPILER)
-# define INLINE inline
+ /* Intel compiler supports inline keyword */
# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
-# define INLINE __inline
+# define inline __inline
# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
-# define INLINE inline
-# define __inline inline
-# define __inline__ inline
-# elif (__STDC_VERSION__ >= 199901L) /* C99 */
-# define INLINE inline
+ /* C99 supports inline keyword */
+# elif (__STDC_VERSION__ >= 199901L)
+ /* C99 supports inline keyword */
# else
-# define INLINE
+# define inline
# endif
#endif
+#ifndef INLINE
+# define INLINE inline
+#endif
/**
diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c
new file mode 100644
index 000000000..c5146f72d
--- /dev/null
+++ b/mesalib/src/mesa/main/format_unpack.c
@@ -0,0 +1,1494 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (c) 2011 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "colormac.h"
+#include "format_unpack.h"
+#include "macros.h"
+#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
+#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
+
+
+/**
+ * Convert an 8-bit sRGB value from non-linear space to a
+ * linear RGB value in [0, 1].
+ * Implemented with a 256-entry lookup table.
+ */
+static INLINE GLfloat
+nonlinear_to_linear(GLubyte cs8)
+{
+ static GLfloat table[256];
+ static GLboolean tableReady = GL_FALSE;
+ if (!tableReady) {
+ /* compute lookup table now */
+ GLuint i;
+ for (i = 0; i < 256; i++) {
+ const GLfloat cs = UBYTE_TO_FLOAT(i);
+ if (cs <= 0.04045) {
+ table[i] = cs / 12.92f;
+ }
+ else {
+ table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
+ }
+ }
+ tableReady = GL_TRUE;
+ }
+ return table[cs8];
+}
+
+
+typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[4]);
+
+
+static void
+unpack_RGBA8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+}
+
+static void
+unpack_RGBA8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+}
+
+static void
+unpack_ARGB8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+}
+
+static void
+unpack_ARGB8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+}
+
+static void
+unpack_XRGB8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ dst[ACOMP] = 1.0f;
+}
+
+static void
+unpack_XRGB8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ dst[ACOMP] = 1.0f;
+}
+
+static void
+unpack_RGB888(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = UBYTE_TO_FLOAT( s[2] );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s[1] );
+ dst[BCOMP] = UBYTE_TO_FLOAT( s[0] );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_BGR888(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = UBYTE_TO_FLOAT( s[0] );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s[1] );
+ dst[BCOMP] = UBYTE_TO_FLOAT( s[2] );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RGB565(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+ dst[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
+ dst[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RGB565_REV(const void *src, GLfloat dst[4])
+{
+ GLushort s = *((const GLushort *) src);
+ s = (s >> 8) | (s << 8); /* byte swap */
+ dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
+ dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
+ dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_ARGB4444(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
+ dst[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+ dst[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
+ dst[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
+}
+
+static void
+unpack_ARGB4444_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
+ dst[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
+ dst[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
+ dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+}
+
+static void
+unpack_RGBA5551(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+ dst[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
+ dst[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
+ dst[ACOMP] = ((s ) & 0x01) * 1.0F;
+}
+
+static void
+unpack_ARGB1555(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
+ dst[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
+ dst[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
+ dst[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
+}
+
+static void
+unpack_ARGB1555_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
+ dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
+ dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
+ dst[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
+}
+
+static void
+unpack_AL44(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
+ dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+}
+
+static void
+unpack_AL88(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
+}
+
+static void
+unpack_AL88_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ dst[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
+}
+
+static void
+unpack_AL1616(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ dst[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
+}
+
+static void
+unpack_AL1616_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ dst[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
+}
+
+static void
+unpack_RGB332(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
+ dst[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
+ dst[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+
+static void
+unpack_A8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = UBYTE_TO_FLOAT(s);
+}
+
+static void
+unpack_A16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = USHORT_TO_FLOAT(s);
+}
+
+static void
+unpack_L8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = UBYTE_TO_FLOAT(s);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_L16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = USHORT_TO_FLOAT(s);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_I8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = UBYTE_TO_FLOAT(s);
+}
+
+static void
+unpack_I16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = USHORT_TO_FLOAT(s);
+}
+
+static void
+unpack_YCBCR(const void *src, GLfloat dst[4])
+{
+ const GLuint i = 0;
+ const GLushort *src0 = (const GLushort *) src;
+ const GLushort *src1 = src0 + 1; /* odd */
+ const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
+ const GLubyte cb = *src0 & 0xff; /* chroma U */
+ const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
+ const GLubyte cr = *src1 & 0xff; /* chroma V */
+ const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+ GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+ GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+ r *= (1.0F / 255.0F);
+ g *= (1.0F / 255.0F);
+ b *= (1.0F / 255.0F);
+ dst[RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ dst[GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ dst[BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_YCBCR_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint i = 0;
+ const GLushort *src0 = (const GLushort *) src;
+ const GLushort *src1 = src0 + 1; /* odd */
+ const GLubyte y0 = *src0 & 0xff; /* luminance */
+ const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
+ const GLubyte y1 = *src1 & 0xff; /* luminance */
+ const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
+ const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+ GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+ GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+ r *= (1.0F / 255.0F);
+ g *= (1.0F / 255.0F);
+ b *= (1.0F / 255.0F);
+ dst[RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ dst[GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ dst[BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_R8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[0] = UBYTE_TO_FLOAT(s);
+ dst[1] = dst[2] = 0.0F;
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_RG88(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_RG88_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_R16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = USHORT_TO_FLOAT(s);
+ dst[GCOMP] = 0.0;
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_RG1616(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ dst[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_RG1616_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ dst[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_ARGB2101010(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
+ dst[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
+ dst[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
+ dst[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
+}
+
+
+static void
+unpack_Z24_S8(const void *src, GLfloat dst[4])
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ dst[0] = dst[1] = dst[2] = (s >> 8) * scale;
+ dst[3] = 1.0F;
+ ASSERT(dst[0] >= 0.0F);
+ ASSERT(dst[0] <= 1.0F);
+}
+
+static void
+unpack_S8_Z24(const void *src, GLfloat dst[4])
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ dst[0] = dst[1] = dst[2] = (s & 0x00ffffff) * scale;
+ dst[3] = 1.0F;
+ ASSERT(dst[0] >= 0.0F);
+ ASSERT(dst[0] <= 1.0F);
+}
+
+static void
+unpack_Z16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[0] = dst[1] = dst[2] = s * (1.0F / 65535.0F);
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_X8_Z24(const void *src, GLfloat dst[4])
+{
+ unpack_S8_Z24(src, dst);
+}
+
+static void
+unpack_Z24_X8(const void *src, GLfloat dst[4])
+{
+ unpack_Z24_S8(src, dst);
+}
+
+static void
+unpack_Z32(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[0] = dst[1] = dst[2] = s * (1.0F / 0xffffffff);
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_Z32_FLOAT(const void *src, GLfloat dst[4])
+{
+ const GLfloat s = *((const GLfloat *) src);
+ dst[0] = dst[1] = dst[2] = s;
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[4])
+{
+ const GLfloat s = *((const GLfloat *) src);
+ dst[0] = dst[1] = dst[2] = s;
+ dst[3] = 1.0F;
+}
+
+
+static void
+unpack_S8(const void *src, GLfloat dst[4])
+{
+ /* should never be used */
+ dst[0] = dst[1] = dst[2] = 0.0F;
+ dst[3] = 1.0F;
+}
+
+
+static void
+unpack_SRGB8(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = nonlinear_to_linear(s[2]);
+ dst[GCOMP] = nonlinear_to_linear(s[1]);
+ dst[BCOMP] = nonlinear_to_linear(s[0]);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SRGBA8(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = nonlinear_to_linear( (s >> 24) );
+ dst[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
+ dst[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
+}
+
+static void
+unpack_SARGB8(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
+ dst[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
+ dst[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
+}
+
+static void
+unpack_SL8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = nonlinear_to_linear(s);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SLA8(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = nonlinear_to_linear(s[0]);
+ dst[ACOMP] = UBYTE_TO_FLOAT(s[1]); /* linear */
+}
+
+static void
+unpack_SRGB_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_SRGBA_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_SRGBA_DXT3(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_SRGBA_DXT5(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGB_FXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_FXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGB_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_DXT3(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_DXT5(const void *src, GLfloat dst[4])
+{
+}
+
+
+static void
+unpack_RGBA_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = s[1];
+ dst[BCOMP] = s[2];
+ dst[ACOMP] = s[3];
+}
+
+static void
+unpack_RGBA_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = _mesa_half_to_float(s[1]);
+ dst[BCOMP] = _mesa_half_to_float(s[2]);
+ dst[ACOMP] = _mesa_half_to_float(s[3]);
+}
+
+static void
+unpack_RGB_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = s[1];
+ dst[BCOMP] = s[2];
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RGB_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = _mesa_half_to_float(s[1]);
+ dst[BCOMP] = _mesa_half_to_float(s[2]);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = s[0];
+}
+
+static void
+unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = _mesa_half_to_float(s[0]);
+}
+
+static void
+unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = s[0];
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = _mesa_half_to_float(s[0]);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = s[0];
+ dst[ACOMP] = s[1];
+}
+
+static void
+unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = _mesa_half_to_float(s[0]);
+ dst[ACOMP] = _mesa_half_to_float(s[1]);
+}
+
+static void
+unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = s[0];
+}
+
+static void
+unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = s[0];
+}
+
+static void
+unpack_R_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_R_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RG_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = s[1];
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RG_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = _mesa_half_to_float(s[1]);
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+
+static void
+unpack_RGBA_INT8(const void *src, GLfloat dst[4])
+{
+ const GLbyte *s = (const GLbyte *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_INT16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_INT32(const void *src, GLfloat dst[4])
+{
+ const GLint *s = (const GLint *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_UINT8(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_UINT16(const void *src, GLfloat dst[4])
+{
+ const GLushort *s = (const GLushort *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_UINT32(const void *src, GLfloat dst[4])
+{
+ const GLuint *s = (const GLuint *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_DUDV8(const void *src, GLfloat dst[4])
+{
+ const GLbyte *s = (const GLbyte *) src;
+ dst[RCOMP] = BYTE_TO_FLOAT(s[0]);
+ dst[GCOMP] = BYTE_TO_FLOAT(s[1]);
+ dst[BCOMP] = 0;
+ dst[ACOMP] = 0;
+}
+
+static void
+unpack_SIGNED_R8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( s );
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[ACOMP] = 1.0f;
+}
+
+static void
+unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
+}
+
+static void
+unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+}
+
+static void
+unpack_SIGNED_R16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] = SHORT_TO_FLOAT_TEX( s );
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_GR1616(const void *src, GLfloat dst[4])
+{
+ /* XXX TODO */
+}
+
+static void
+unpack_SIGNED_RGB_16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
+}
+
+static void
+unpack_RGBA_16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = USHORT_TO_FLOAT( s[0] );
+ dst[GCOMP] = USHORT_TO_FLOAT( s[1] );
+ dst[BCOMP] = USHORT_TO_FLOAT( s[2] );
+ dst[ACOMP] = USHORT_TO_FLOAT( s[3] );
+}
+
+static void
+unpack_RED_RGTC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_RG_RGTC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_L_LATC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_LA_LATC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_A8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] = 0.0F;
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_SIGNED_L8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( s );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_AL88(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLshort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+}
+
+static void
+unpack_SIGNED_I8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_SIGNED_A16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] = 0.0F;
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_SIGNED_L16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_AL1616(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+}
+
+static void
+unpack_SIGNED_I16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[4])
+{
+ const GLuint *s = (const GLuint *) src;
+ rgb9e5_to_float3(*s, dst);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[4])
+{
+ const GLuint *s = (const GLuint *) src;
+ r11g11b10f_to_float3(*s, dst);
+ dst[ACOMP] = 1.0F;
+}
+
+
+/**
+ * Return the unpacker function for the given format.
+ */
+static unpack_rgba_func
+get_unpack_rgba_function(gl_format format)
+{
+ static unpack_rgba_func table[MESA_FORMAT_COUNT];
+ static GLboolean initialized = GL_FALSE;
+
+ if (!initialized) {
+ table[MESA_FORMAT_NONE] = NULL;
+
+ table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
+ table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
+ table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
+ table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
+ table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
+ table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
+ table[MESA_FORMAT_RGB888] = unpack_RGB888;
+ table[MESA_FORMAT_BGR888] = unpack_BGR888;
+ table[MESA_FORMAT_RGB565] = unpack_RGB565;
+ table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
+ table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
+ table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
+ table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
+ table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
+ table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
+ table[MESA_FORMAT_AL44] = unpack_AL44;
+ table[MESA_FORMAT_AL88] = unpack_AL88;
+ table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
+ table[MESA_FORMAT_AL1616] = unpack_AL1616;
+ table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
+ table[MESA_FORMAT_RGB332] = unpack_RGB332;
+ table[MESA_FORMAT_A8] = unpack_A8;
+ table[MESA_FORMAT_A16] = unpack_A16;
+ table[MESA_FORMAT_L8] = unpack_L8;
+ table[MESA_FORMAT_L16] = unpack_L16;
+ table[MESA_FORMAT_I8] = unpack_I8;
+ table[MESA_FORMAT_I16] = unpack_I16;
+ table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
+ table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
+ table[MESA_FORMAT_R8] = unpack_R8;
+ table[MESA_FORMAT_RG88] = unpack_RG88;
+ table[MESA_FORMAT_RG88_REV] = unpack_RG88_REV;
+ table[MESA_FORMAT_R16] = unpack_R16;
+ table[MESA_FORMAT_RG1616] = unpack_RG1616;
+ table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
+ table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
+ table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
+ table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
+ table[MESA_FORMAT_Z16] = unpack_Z16;
+ table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
+ table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
+ table[MESA_FORMAT_Z32] = unpack_Z32;
+ table[MESA_FORMAT_S8] = unpack_S8;
+ table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
+ table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
+ table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
+ table[MESA_FORMAT_SL8] = unpack_SL8;
+ table[MESA_FORMAT_SLA8] = unpack_SLA8;
+ table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
+ table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
+ table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
+ table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
+
+ table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
+ table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
+ table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
+ table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
+ table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
+ table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
+
+ table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
+ table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
+ table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
+ table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
+ table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
+ table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
+ table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
+ table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
+ table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
+ table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
+ table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
+ table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
+
+ table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
+ table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
+ table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
+ table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
+ table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
+ table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
+
+ table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
+ table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
+ table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
+ table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
+ table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
+ table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
+ table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
+ table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
+ table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
+ table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
+ table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
+
+ table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
+ table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
+ table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
+ table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
+
+ table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
+ table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
+ table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
+ table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
+
+ table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
+ table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
+ table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
+ table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
+ table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
+ table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
+ table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
+ table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
+
+ table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
+ table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
+
+ table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
+ table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
+
+ initialized = GL_TRUE;
+ }
+
+ return table[format];
+}
+
+
+void
+_mesa_unpack_rgba_row(gl_format format, GLuint n,
+ const void *src, GLfloat dst[][4])
+{
+ unpack_rgba_func unpack = get_unpack_rgba_function(format);
+ GLuint srcStride = _mesa_get_format_bytes(format);
+ const GLubyte *srcPtr = (GLubyte *) src;
+ GLuint i;
+
+ for (i = 0; i < n; i++) {
+ unpack(srcPtr, dst[i]);
+ srcPtr += srcStride;
+ }
+}
+
+
+
+/**
+ * Unpack a 2D rect of pixels returning float RGBA colors.
+ * \param format the source image format
+ * \param src start address of the source image
+ * \param srcRowStride source image row stride in bytes
+ * \param dst start address of the dest image
+ * \param dstRowStride dest image row stride in bytes
+ * \param x source image start X pos
+ * \param y source image start Y pos
+ * \param width width of rect region to convert
+ * \param height height of rect region to convert
+ */
+void
+_mesa_unpack_rgba_block(gl_format format,
+ const void *src, GLint srcRowStride,
+ GLfloat dst[][4], GLint dstRowStride,
+ GLuint x, GLuint y, GLuint width, GLuint height)
+{
+ unpack_rgba_func unpack = get_unpack_rgba_function(format);
+ const GLuint srcPixStride = _mesa_get_format_bytes(format);
+ const GLuint dstPixStride = 4 * sizeof(GLfloat);
+ const GLubyte *srcRow, *srcPix;
+ GLubyte *dstRow;
+ GLfloat *dstPix;
+ GLuint i, j;
+
+ /* XXX needs to be fixed for compressed formats */
+
+ srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
+ dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
+
+ for (i = 0; i < height; i++) {
+ srcPix = srcRow;
+ dstPix = (GLfloat *) dstRow;
+
+ for (j = 0; j < width; j++) {
+ unpack(srcPix, dstPix);
+ srcPix += srcPixStride;
+ dstPix += dstPixStride;
+ }
+
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+}
+
+
+
+
+typedef void (*unpack_float_z_func)(const void *src, GLfloat *dst);
+
+static void
+unpack_float_z_Z24_S8(const void *src, GLfloat *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ *dst = (s >> 8) * scale;
+ ASSERT(*dst >= 0.0F);
+ ASSERT(*dst <= 1.0F);
+}
+
+static void
+unpack_float_z_S8_Z24(const void *src, GLfloat *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ *dst = (s & 0x00ffffff) * scale;
+ ASSERT(*dst >= 0.0F);
+ ASSERT(*dst <= 1.0F);
+}
+
+static void
+unpack_float_z_Z16(const void *src, GLfloat *dst)
+{
+ const GLushort s = *((const GLushort *) src);
+ *dst = s * (1.0F / 65535.0F);
+}
+
+static void
+unpack_float_z_X8_Z24(const void *src, GLfloat *dst)
+{
+ unpack_float_z_S8_Z24(src, dst);
+}
+
+static void
+unpack_float_z_Z24_X8(const void *src, GLfloat *dst)
+{
+ unpack_float_z_Z24_S8(src, dst);
+}
+
+static void
+unpack_float_z_Z32(const void *src, GLfloat *dst)
+{
+ const GLuint s = *((const GLuint *) src);
+ *dst = s * (1.0F / 0xffffffff);
+}
+
+static void
+unpack_float_z_Z32X24S8(const void *src, GLfloat *dst)
+{
+ *dst = *((const GLfloat *) src);
+}
+
+
+
+void
+_mesa_unpack_float_z_row(gl_format format, GLuint n,
+ const void *src, GLfloat *dst)
+{
+ unpack_float_z_func unpack;
+ GLuint srcStride = _mesa_get_format_bytes(format);
+ const GLubyte *srcPtr = (GLubyte *) src;
+ GLuint i;
+
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ unpack = unpack_float_z_Z24_S8;
+ break;
+ case MESA_FORMAT_S8_Z24:
+ unpack = unpack_float_z_S8_Z24;
+ break;
+ case MESA_FORMAT_Z16:
+ unpack = unpack_float_z_Z16;
+ break;
+ case MESA_FORMAT_X8_Z24:
+ unpack = unpack_float_z_X8_Z24;
+ break;
+ case MESA_FORMAT_Z24_X8:
+ unpack = unpack_float_z_Z24_X8;
+ break;
+ case MESA_FORMAT_Z32:
+ unpack = unpack_float_z_Z32;
+ break;
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ unpack = unpack_float_z_Z32X24S8;
+ break;
+ default:
+ _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
+ _mesa_get_format_name(format));
+ return;
+ }
+
+ for (i = 0; i < n; i++) {
+ unpack(srcPtr, &dst[i]);
+ srcPtr += srcStride;
+ }
+}
+
+
+
+typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst);
+
+static void
+unpack_uint_z_Z24_S8(const void *src, GLuint *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ *dst = (s >> 8);
+}
+
+static void
+unpack_uint_z_S8_Z24(const void *src, GLuint *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ *dst = s & 0x00ffffff;
+}
+
+static void
+unpack_uint_z_Z16(const void *src, GLuint *dst)
+{
+ *dst = *((const GLushort *) src);
+}
+
+static void
+unpack_uint_z_X8_Z24(const void *src, GLuint *dst)
+{
+ unpack_uint_z_S8_Z24(src, dst);
+}
+
+static void
+unpack_uint_z_Z24_X8(const void *src, GLuint *dst)
+{
+ unpack_uint_z_Z24_S8(src, dst);
+}
+
+static void
+unpack_uint_z_Z32(const void *src, GLuint *dst)
+{
+ *dst = *((const GLuint *) src);
+}
+
+
+void
+_mesa_unpack_uint_z_row(gl_format format, GLuint n,
+ const void *src, GLuint *dst)
+{
+ unpack_uint_z_func unpack;
+ GLuint srcStride = _mesa_get_format_bytes(format);
+ const GLubyte *srcPtr = (GLubyte *) src;
+ GLuint i;
+
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ unpack = unpack_uint_z_Z24_S8;
+ break;
+ case MESA_FORMAT_S8_Z24:
+ unpack = unpack_uint_z_S8_Z24;
+ break;
+ case MESA_FORMAT_Z16:
+ unpack = unpack_uint_z_Z16;
+ break;
+ case MESA_FORMAT_X8_Z24:
+ unpack = unpack_uint_z_X8_Z24;
+ break;
+ case MESA_FORMAT_Z24_X8:
+ unpack = unpack_uint_z_Z24_X8;
+ break;
+ case MESA_FORMAT_Z32:
+ unpack = unpack_uint_z_Z32;
+ break;
+ default:
+ _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
+ _mesa_get_format_name(format));
+ return;
+ }
+
+ for (i = 0; i < n; i++) {
+ unpack(srcPtr, &dst[i]);
+ srcPtr += srcStride;
+ }
+}
+
+
diff --git a/mesalib/src/mesa/main/format_unpack.h b/mesalib/src/mesa/main/format_unpack.h
new file mode 100644
index 000000000..c37727d91
--- /dev/null
+++ b/mesalib/src/mesa/main/format_unpack.h
@@ -0,0 +1,49 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (c) 2011 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef FORMAT_UNPACK_H
+#define FORMAT_UNPACK_H
+
+extern void
+_mesa_unpack_rgba_row(gl_format format, GLuint n,
+ const void *src, GLfloat dst[][4]);
+
+
+extern void
+_mesa_unpack_rgba_block(gl_format format,
+ const void *src, GLint srcRowStride,
+ GLfloat dst[][4], GLint dstRowStride,
+ GLuint x, GLuint y, GLuint width, GLuint height);
+
+
+extern void
+_mesa_unpack_float_z_row(gl_format format, GLuint n,
+ const void *src, GLfloat *dst);
+
+
+void
+_mesa_unpack_uint_z_row(gl_format format, GLuint n,
+ const void *src, GLuint *dst);
+
+
+#endif /* FORMAT_UNPACK_H */
diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c
index fd16d98c5..47f876b76 100644
--- a/mesalib/src/mesa/main/formats.c
+++ b/mesalib/src/mesa/main/formats.c
@@ -1343,6 +1343,70 @@ _mesa_get_srgb_format_linear(gl_format format)
/**
+ * If the given format is a compressed format, return a corresponding
+ * uncompressed format.
+ */
+gl_format
+_mesa_get_uncompressed_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_RGB_FXT1:
+ return MESA_FORMAT_RGB888;
+ case MESA_FORMAT_RGBA_FXT1:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RGB_DXT1:
+ case MESA_FORMAT_SRGB_DXT1:
+ return MESA_FORMAT_RGB888;
+ case MESA_FORMAT_RGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT3:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RGBA_DXT5:
+ case MESA_FORMAT_SRGBA_DXT5:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RED_RGTC1:
+ return MESA_FORMAT_R8;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ return MESA_FORMAT_SIGNED_R8;
+ case MESA_FORMAT_RG_RGTC2:
+ return MESA_FORMAT_RG88;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ return MESA_FORMAT_SIGNED_RG88_REV;
+ case MESA_FORMAT_L_LATC1:
+ return MESA_FORMAT_L8;
+ case MESA_FORMAT_SIGNED_L_LATC1:
+ return MESA_FORMAT_SIGNED_L8;
+ case MESA_FORMAT_LA_LATC2:
+ return MESA_FORMAT_AL88;
+ case MESA_FORMAT_SIGNED_LA_LATC2:
+ return MESA_FORMAT_SIGNED_AL88;
+ default:
+#ifdef DEBUG
+ assert(!_mesa_is_format_compressed(format));
+#endif
+ return format;
+ }
+}
+
+
+GLuint
+_mesa_format_num_components(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return ((info->RedBits > 0) +
+ (info->GreenBits > 0) +
+ (info->BlueBits > 0) +
+ (info->AlphaBits > 0) +
+ (info->LuminanceBits > 0) +
+ (info->IntensityBits > 0) +
+ (info->DepthBits > 0) +
+ (info->StencilBits > 0));
+}
+
+
+/**
* Return number of bytes needed to store an image of the given size
* in the given format.
*/
diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h
index 26bcbe084..b6b1b687f 100644
--- a/mesalib/src/mesa/main/formats.h
+++ b/mesalib/src/mesa/main/formats.h
@@ -266,4 +266,11 @@ _mesa_test_formats(void);
extern gl_format
_mesa_get_srgb_format_linear(gl_format format);
+extern gl_format
+_mesa_get_uncompressed_format(gl_format format);
+
+extern GLuint
+_mesa_format_num_components(gl_format format);
+
+
#endif /* FORMATS_H */
diff --git a/mesalib/src/mesa/main/mipmap.c b/mesalib/src/mesa/main/mipmap.c
index cf9d522f2..869243d1c 100644
--- a/mesalib/src/mesa/main/mipmap.c
+++ b/mesalib/src/mesa/main/mipmap.c
@@ -1985,50 +1985,45 @@ generate_mipmap_uncompressed(struct gl_context *ctx, GLenum target,
static void
generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
struct gl_texture_object *texObj,
- const struct gl_texture_image *srcImage,
+ struct gl_texture_image *srcImage,
GLuint maxLevel)
{
GLint level;
gl_format temp_format;
- GLenum datatype;
- GLuint comps;
- GLuint row;
GLint components;
GLuint temp_src_stride, temp_dst_stride; /* in bytes */
GLchan *temp_src = NULL, *temp_dst = NULL;
+ GLenum temp_datatype;
+ GLenum temp_base_format;
- /* Choose the format we will do _mesa_generate_mipmap_level() in,
- * and uncompress the firstImage into a temporary of that format.
- */
+ /* only two types of compressed textures at this time */
assert(texObj->Target == GL_TEXTURE_2D ||
texObj->Target == GL_TEXTURE_CUBE_MAP_ARB);
- if (srcImage->_BaseFormat == GL_RGB) {
- temp_format = MESA_FORMAT_RGB888;
- components = 3;
- } else if (srcImage->_BaseFormat == GL_RED) {
- temp_format = MESA_FORMAT_R8;
- components = 1;
- } else if (srcImage->_BaseFormat == GL_RG) {
- temp_format = MESA_FORMAT_RG88;
- components = 2;
- } else if (srcImage->_BaseFormat == GL_RGBA) {
- temp_format = MESA_FORMAT_RGBA8888;
- components = 4;
- } else if (srcImage->_BaseFormat == GL_LUMINANCE) {
- temp_format = MESA_FORMAT_L8;
- components = 1;
- } else if (srcImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
- temp_format = MESA_FORMAT_AL88;
- components = 2;
- } else {
- _mesa_problem(ctx, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
- return;
+ /*
+ * Choose a format for the temporary, uncompressed base image.
+ * Then, get number of components, choose temporary image datatype,
+ * and get base format.
+ */
+ temp_format = _mesa_get_uncompressed_format(srcImage->TexFormat);
+
+ components = _mesa_format_num_components(temp_format);
+
+ /* Revisit this if we get compressed formats with >8 bits per component */
+ if (_mesa_get_format_datatype(srcImage->TexFormat)
+ == GL_SIGNED_NORMALIZED) {
+ temp_datatype = GL_BYTE;
+ }
+ else {
+ temp_datatype = GL_UNSIGNED_BYTE;
}
- /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
- temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width);
+ temp_base_format = _mesa_get_format_base_format(temp_format);
+
+
+ /* allocate storage for the temporary, uncompressed image */
/* 20 extra bytes, just be safe when calling last FetchTexel */
+ temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width);
temp_src = (GLubyte *) malloc(temp_src_stride * srcImage->Height + 20);
if (!temp_src) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
@@ -2036,16 +2031,20 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
}
/* decompress base image to the temporary */
- for (row = 0; row < srcImage->Height; row++) {
- GLuint col;
- GLchan *dst = (GLchan *) temp_src + temp_src_stride * row;
- for (col = 0; col < srcImage->Width; col++) {
- srcImage->FetchTexelc(srcImage, col, row, 0, dst);
- dst += components;
- }
+ {
+ /* save pixel packing mode */
+ struct gl_pixelstore_attrib save = ctx->Pack;
+ /* use default/tight packing parameters */
+ ctx->Pack = ctx->DefaultPacking;
+
+ /* Get the uncompressed image */
+ ctx->Driver.GetTexImage(ctx, target, texObj->BaseLevel,
+ temp_base_format, temp_datatype,
+ temp_src, texObj, srcImage);
+ /* restore packing mode */
+ ctx->Pack = save;
}
- _mesa_format_to_type_and_comps(temp_format, &datatype, &comps);
for (level = texObj->BaseLevel; level < maxLevel; level++) {
/* generate image[level+1] from image[level] */
@@ -2086,7 +2085,10 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
return;
}
- _mesa_generate_mipmap_level(target, datatype, comps, border,
+ /* Free old image data */
+ ctx->Driver.FreeTextureImageBuffer(ctx, dstImage);
+
+ _mesa_generate_mipmap_level(target, temp_datatype, components, border,
srcWidth, srcHeight, srcDepth,
temp_src, temp_src_stride / components,
dstWidth, dstHeight, dstDepth,
@@ -2100,8 +2102,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
ctx->Driver.TexImage2D(ctx, target, level + 1,
srcImage->InternalFormat,
dstWidth, dstHeight, border,
- _mesa_get_format_base_format(temp_format),
- GL_UNSIGNED_BYTE,
+ temp_base_format, temp_datatype,
temp_dst, &ctx->DefaultPacking, texObj, dstImage);
/* swap src and dest pointers */
@@ -2130,7 +2131,7 @@ void
_mesa_generate_mipmap(struct gl_context *ctx, GLenum target,
struct gl_texture_object *texObj)
{
- const struct gl_texture_image *srcImage;
+ struct gl_texture_image *srcImage;
GLint maxLevel;
ASSERT(texObj);
diff --git a/mesalib/src/mesa/main/texcompress.c b/mesalib/src/mesa/main/texcompress.c
index 532f79fd5..b821dd0c0 100644
--- a/mesalib/src/mesa/main/texcompress.c
+++ b/mesalib/src/mesa/main/texcompress.c
@@ -37,6 +37,9 @@
#include "mfeatures.h"
#include "mtypes.h"
#include "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_rgtc.h"
+#include "texcompress_s3tc.h"
/**
@@ -259,7 +262,6 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
n += 4;
}
}
- return n;
#if FEATURE_ES1 || FEATURE_ES2
if (formats) {
@@ -278,6 +280,8 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
n += 10;
}
#endif
+
+ return n;
}
@@ -437,3 +441,86 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
return (GLubyte *) image + offset;
}
+
+
+/**
+ * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
+ */
+void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+ const GLubyte *src, GLint srcRowStride,
+ GLfloat *dest)
+{
+ void (*fetch)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+ struct gl_texture_image texImage; /* dummy teximage */
+ GLuint i, j;
+
+ /* setup dummy texture image info */
+ memset(&texImage, 0, sizeof(texImage));
+ texImage.Data = (void *) src;
+ texImage.RowStride = srcRowStride;
+
+ switch (format) {
+ /* DXT formats */
+ case MESA_FORMAT_RGB_DXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgb_dxt1;
+ break;
+ case MESA_FORMAT_RGBA_DXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt1;
+ break;
+ case MESA_FORMAT_RGBA_DXT3:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt3;
+ break;
+ case MESA_FORMAT_RGBA_DXT5:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt5;
+ break;
+
+ /* FXT1 formats */
+ case MESA_FORMAT_RGB_FXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgb_fxt1;
+ break;
+ case MESA_FORMAT_RGBA_FXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgba_fxt1;
+ break;
+
+ /* Red/RG formats */
+ case MESA_FORMAT_RED_RGTC1:
+ fetch = _mesa_fetch_texel_2d_f_red_rgtc1;
+ break;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ fetch = _mesa_fetch_texel_2d_f_signed_red_rgtc1;
+ break;
+ case MESA_FORMAT_RG_RGTC2:
+ fetch = _mesa_fetch_texel_2d_f_rg_rgtc2;
+ break;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ fetch = _mesa_fetch_texel_2d_f_signed_rg_rgtc2;
+ break;
+
+ /* L/LA formats */
+ case MESA_FORMAT_L_LATC1:
+ fetch = _mesa_fetch_texel_2d_f_l_latc1;
+ break;
+ case MESA_FORMAT_SIGNED_L_LATC1:
+ fetch = _mesa_fetch_texel_2d_f_signed_l_latc1;
+ break;
+ case MESA_FORMAT_LA_LATC2:
+ fetch = _mesa_fetch_texel_2d_f_la_latc2;
+ break;
+ case MESA_FORMAT_SIGNED_LA_LATC2:
+ fetch = _mesa_fetch_texel_2d_f_signed_la_latc2;
+ break;
+
+ default:
+ _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
+ return;
+ }
+
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
+ fetch(&texImage, i, j, 0, dest);
+ dest += 4;
+ }
+ }
+}
diff --git a/mesalib/src/mesa/main/texcompress.h b/mesalib/src/mesa/main/texcompress.h
index 375cf90c8..2c357068c 100644
--- a/mesalib/src/mesa/main/texcompress.h
+++ b/mesalib/src/mesa/main/texcompress.h
@@ -50,6 +50,11 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
gl_format mesaFormat,
GLsizei width, const GLubyte *image);
+extern void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+ const GLubyte *src, GLint srcRowStride,
+ GLfloat *dest);
+
#else /* _HAVE_FULL_GL */
/* no-op macros */
diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c
index 46e38d7bc..7e1fc3695 100644
--- a/mesalib/src/mesa/main/texgetimage.c
+++ b/mesalib/src/mesa/main/texgetimage.c
@@ -34,13 +34,14 @@
#include "enums.h"
#include "context.h"
#include "formats.h"
+#include "format_unpack.h"
#include "image.h"
#include "mfeatures.h"
#include "mtypes.h"
#include "pack.h"
#include "pbo.h"
+#include "texcompress.h"
#include "texgetimage.h"
-#include "texfetch.h"
#include "teximage.h"
@@ -75,8 +76,9 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions,
const GLint width = texImage->Width;
const GLint height = texImage->Height;
const GLint depth = texImage->Depth;
- GLint img, row, col;
+ GLint img, row;
GLfloat *depthRow = (GLfloat *) malloc(width * sizeof(GLfloat));
+ const GLint texelSize = _mesa_get_format_bytes(texImage->TexFormat);
if (!depthRow) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
@@ -88,11 +90,12 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions,
void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
width, height, format, type,
img, row, 0);
- assert(dest);
+ const GLubyte *src = (GLubyte *) texImage->Data +
+ (texImage->ImageOffsets[img] +
+ texImage->RowStride * row) * texelSize;
+
+ _mesa_unpack_float_z_row(texImage->TexFormat, width, src, depthRow);
- for (col = 0; col < width; col++) {
- texImage->FetchTexelf(texImage, col, row, img, depthRow + col);
- }
_mesa_pack_depth_span(ctx, width, dest, type, depthRow, &ctx->Pack);
}
}
@@ -173,95 +176,141 @@ get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions,
/**
- * glGetTexImage for (s)RGBA, Luminance, etc. pixels.
- * This is the slow way since we use texture sampling.
+ * glGetTexImage for color formats (RGBA, RGB, alpha, LA, etc).
+ * Compressed textures are handled here as well.
*/
static void
get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
GLenum format, GLenum type, GLvoid *pixels,
struct gl_texture_image *texImage)
{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- const GLenum dataType = _mesa_get_format_datatype(texImage->TexFormat);
+ /* don't want to apply sRGB -> RGB conversion here so override the format */
+ const gl_format texFormat = _mesa_get_srgb_format_linear(texImage->TexFormat);
+ const GLuint width = texImage->Width;
+ const GLuint height = texImage->Height;
+ const GLuint depth = texImage->Depth;
+ const GLenum dataType = _mesa_get_format_datatype(texFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(texFormat);
/* Normally, no pixel transfer ops are performed during glGetTexImage.
* The only possible exception is component clamping to [0,1].
*/
GLbitfield transferOps = 0x0;
- GLint img, row;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
- const GLboolean is_sampler_srgb_decode =
- _mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB &&
- texImage->TexObject->Sampler.sRGBDecode == GL_DECODE_EXT;
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
- return;
- }
- /* Clamping does not apply to GetTexImage (final conversion)?
- * Looks like we need clamp though when going from format
- * containing negative values to unsigned format.
+ /* In general, clamping does not apply to glGetTexImage, except when
+ * the returned type of the image can't hold negative values.
*/
- if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) {
- transferOps |= IMAGE_CLAMP_BIT;
- }
- else if (!type_with_negative_values(type) &&
- (dataType == GL_FLOAT ||
- dataType == GL_SIGNED_NORMALIZED)) {
- transferOps |= IMAGE_CLAMP_BIT;
+ if (!type_with_negative_values(type)) {
+ /* the returned image type can't have negative values */
+ if (dataType == GL_FLOAT ||
+ dataType == GL_SIGNED_NORMALIZED ||
+ format == GL_LUMINANCE ||
+ format == GL_LUMINANCE_ALPHA) {
+ transferOps |= IMAGE_CLAMP_BIT;
+ }
}
- /* glGetTexImage always returns sRGB data for sRGB textures. Make sure the
- * fetch functions return sRGB data without linearizing it.
- */
- if (is_sampler_srgb_decode) {
- texImage->TexObject->Sampler.sRGBDecode = GL_SKIP_DECODE_EXT;
- _mesa_set_fetch_functions(texImage, dimensions);
- }
+ if (_mesa_is_format_compressed(texFormat)) {
+ /* Decompress into temp buffer, then pack into user buffer */
+ GLfloat *tempImage, *srcRow;
+ GLuint row;
- for (img = 0; img < depth; img++) {
+ tempImage = (GLfloat *) malloc(texImage->Width * texImage->Height *
+ texImage->Depth * 4 * sizeof(GLfloat));
+ if (!tempImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
+ return;
+ }
+
+ _mesa_decompress_image(texFormat, texImage->Width, texImage->Height,
+ texImage->Data, texImage->RowStride, tempImage);
+
+ if (baseFormat == GL_LUMINANCE ||
+ baseFormat == GL_LUMINANCE_ALPHA) {
+ /* Set green and blue to zero since the pack function here will
+ * compute L=R+G+B.
+ */
+ GLuint i;
+ for (i = 0; i < width * height; i++) {
+ tempImage[i * 4 + GCOMP] = tempImage[i * 4 + BCOMP] = 0.0f;
+ }
+ }
+
+ srcRow = tempImage;
for (row = 0; row < height; row++) {
void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
width, height, format, type,
- img, row, 0);
- GLint col;
+ 0, row, 0);
+
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow,
+ format, type, dest, &ctx->Pack, transferOps);
+ srcRow += width * 4;
+ }
+
+ free(tempImage);
+ }
+ else {
+ /* No decompression needed */
+ const GLint texelSize = _mesa_get_format_bytes(texFormat);
+ GLuint img, row;
+ GLfloat (*rgba)[4];
+
+ rgba = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
+ return;
+ }
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+ const GLubyte *src = (const GLubyte *) texImage->Data +
+ (texImage->ImageOffsets[img] +
+ texImage->RowStride * row) * texelSize;
+
+ _mesa_unpack_rgba_row(texFormat, width, src, rgba);
- for (col = 0; col < width; col++) {
- texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
if (texImage->_BaseFormat == GL_ALPHA) {
- rgba[col][RCOMP] = 0.0F;
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][RCOMP] = 0.0F;
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ }
}
else if (texImage->_BaseFormat == GL_LUMINANCE) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- rgba[col][ACOMP] = 1.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ rgba[col][ACOMP] = 1.0F;
+ }
}
else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ }
}
else if (texImage->_BaseFormat == GL_INTENSITY) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- rgba[col][ACOMP] = 1.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ rgba[col][ACOMP] = 1.0F;
+ }
}
+
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
+ format, type, dest,
+ &ctx->Pack, transferOps);
}
- _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
- format, type, dest,
- &ctx->Pack, transferOps);
}
- }
- if (is_sampler_srgb_decode) {
- texImage->TexObject->Sampler.sRGBDecode = GL_DECODE_EXT;
- _mesa_set_fetch_functions(texImage, dimensions);
+ free(rgba);
}
-
- free(rgba);
}
diff --git a/mesalib/src/mesa/sources.mak b/mesalib/src/mesa/sources.mak
index 0ff16d662..e7022b255 100644
--- a/mesalib/src/mesa/sources.mak
+++ b/mesalib/src/mesa/sources.mak
@@ -43,6 +43,7 @@ MAIN_SOURCES = \
main/ffvertex_prog.c \
main/fog.c \
main/formats.c \
+ main/format_unpack.c \
main/framebuffer.c \
main/get.c \
main/getstring.c \