aboutsummaryrefslogtreecommitdiff
path: root/mesalib
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-11-17 16:46:41 +0100
committermarha <marha@users.sourceforge.net>2011-11-17 16:46:41 +0100
commit97fb1dadc6c52adeba0ac0684129520288ab794f (patch)
tree6a3b54bec00abec5b571087dd001a33d62bf488c /mesalib
parentb99cdb7509cad0b99761d19fe99637177913412b (diff)
parentd41bc08d1ae8c4784c09d8977816c0fadab1ba52 (diff)
downloadvcxsrv-97fb1dadc6c52adeba0ac0684129520288ab794f.tar.gz
vcxsrv-97fb1dadc6c52adeba0ac0684129520288ab794f.tar.bz2
vcxsrv-97fb1dadc6c52adeba0ac0684129520288ab794f.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/src/mesa/swrast/s_readpix.c
Diffstat (limited to 'mesalib')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_draw.c214
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_prim.h2
-rw-r--r--mesalib/src/glsl/ast_function.cpp414
-rw-r--r--mesalib/src/glsl/glsl_parser.yy2
-rw-r--r--mesalib/src/glsl/ir.h7
-rw-r--r--mesalib/src/glsl/ir_function.cpp11
-rw-r--r--mesalib/src/glsl/link_uniforms.cpp46
-rw-r--r--mesalib/src/glsl/linker.cpp44
-rw-r--r--mesalib/src/mesa/SConscript1
-rw-r--r--mesalib/src/mesa/drivers/common/driverfuncs.c3
-rw-r--r--mesalib/src/mesa/drivers/common/meta.c43
-rw-r--r--mesalib/src/mesa/main/ffvertex_prog.c113
-rw-r--r--mesalib/src/mesa/main/format_unpack.c1530
-rw-r--r--mesalib/src/mesa/main/image.c71
-rw-r--r--mesalib/src/mesa/main/light.c2863
-rw-r--r--mesalib/src/mesa/main/macros.h37
-rw-r--r--mesalib/src/mesa/main/mtypes.h22
-rw-r--r--mesalib/src/mesa/main/pack.c64
-rw-r--r--mesalib/src/mesa/main/pack.h4
-rw-r--r--mesalib/src/mesa/main/pixeltransfer.c4
-rw-r--r--mesalib/src/mesa/main/pixeltransfer.h2
-rw-r--r--mesalib/src/mesa/main/readpix.c496
-rw-r--r--mesalib/src/mesa/main/readpix.h9
-rw-r--r--mesalib/src/mesa/main/renderbuffer.c367
-rw-r--r--mesalib/src/mesa/main/renderbuffer.h9
-rw-r--r--mesalib/src/mesa/main/uniform_query.cpp22
-rw-r--r--mesalib/src/mesa/program/ir_to_mesa.cpp59
-rw-r--r--mesalib/src/mesa/sources.mak1
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_drawpixels.c21
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_fbo.c32
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_readpixels.c633
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_readpixels.h92
-rw-r--r--mesalib/src/mesa/state_tracker/st_draw.c6
-rw-r--r--mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp53
-rw-r--r--mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c1
-rw-r--r--mesalib/src/mesa/swrast/s_copypix.c1440
-rw-r--r--mesalib/src/mesa/swrast/s_depth.c3
-rw-r--r--mesalib/src/mesa/swrast/s_drawpix.c10
-rw-r--r--mesalib/src/mesa/swrast/s_readpix.c522
-rw-r--r--mesalib/src/mesa/swrast/s_stencil.c184
-rw-r--r--mesalib/src/mesa/swrast/s_stencil.h106
-rw-r--r--mesalib/src/mesa/swrast/s_texrender.c13
-rw-r--r--mesalib/src/mesa/swrast/s_zoom.c4
-rw-r--r--mesalib/src/mesa/swrast/s_zoom.h112
-rw-r--r--mesalib/src/mesa/swrast/swrast.h7
45 files changed, 4484 insertions, 5215 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_draw.c b/mesalib/src/gallium/auxiliary/util/u_draw.c
index 4f2565edb..d16575b73 100644
--- a/mesalib/src/gallium/auxiliary/util/u_draw.c
+++ b/mesalib/src/gallium/auxiliary/util/u_draw.c
@@ -1,99 +1,115 @@
-/**************************************************************************
- *
- * Copyright 2011 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 "util/u_debug.h"
-#include "util/u_math.h"
-#include "util/u_format.h"
-#include "util/u_draw.h"
-
-
-/**
- * Returns the largest legal index value for the current set of bound vertex
- * buffers. Regardless of any other consideration, all vertex lookups need to
- * be clamped to 0..max_index to prevent an out-of-bound access.
- */
-unsigned
-util_draw_max_index(
- const struct pipe_vertex_buffer *vertex_buffers,
- unsigned nr_vertex_buffers,
- const struct pipe_vertex_element *vertex_elements,
- unsigned nr_vertex_elements,
- const struct pipe_draw_info *info)
-{
- unsigned max_index;
- unsigned i;
-
- max_index = ~0;
- for (i = 0; i < nr_vertex_elements; i++) {
- const struct pipe_vertex_element *element =
- &vertex_elements[i];
- const struct pipe_vertex_buffer *buffer =
- &vertex_buffers[element->vertex_buffer_index];
- unsigned buffer_size;
- const struct util_format_description *format_desc;
- unsigned format_size;
-
- assert(buffer->buffer->height0 == 1);
- assert(buffer->buffer->depth0 == 1);
- buffer_size = buffer->buffer->width0;
-
- format_desc = util_format_description(element->src_format);
- assert(format_desc->block.width == 1);
- assert(format_desc->block.height == 1);
- assert(format_desc->block.bits % 8 == 0);
- format_size = format_desc->block.bits/8;
-
- assert(buffer_size - buffer->buffer_offset <= buffer_size);
- buffer_size -= buffer->buffer_offset;
-
- assert(buffer_size - element->src_offset <= buffer_size);
- buffer_size -= element->src_offset;
-
- assert(buffer_size - format_size <= buffer_size);
- buffer_size -= format_size;
-
- if (buffer->stride != 0) {
- unsigned buffer_max_index;
-
- buffer_max_index = buffer_size / buffer->stride;
-
- if (element->instance_divisor == 0) {
- /* Per-vertex data */
- max_index = MIN2(max_index, buffer_max_index);
- }
- else {
- /* Per-instance data. Simply make sure the state tracker didn't
- * request more instances than those that fit in the buffer */
- assert((info->start_instance + info->instance_count)/element->instance_divisor
- <= (buffer_max_index + 1));
- }
- }
- }
-
- return max_index;
-}
+/**************************************************************************
+ *
+ * Copyright 2011 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 "util/u_debug.h"
+#include "util/u_math.h"
+#include "util/u_format.h"
+#include "util/u_draw.h"
+
+
+/**
+ * Returns the largest legal index value plus one for the current set
+ * of bound vertex buffers. Regardless of any other consideration,
+ * all vertex lookups need to be clamped to 0..max_index-1 to prevent
+ * an out-of-bound access.
+ *
+ * Note that if zero is returned it means that one or more buffers is
+ * too small to contain any valid vertex data.
+ */
+unsigned
+util_draw_max_index(
+ const struct pipe_vertex_buffer *vertex_buffers,
+ unsigned nr_vertex_buffers,
+ const struct pipe_vertex_element *vertex_elements,
+ unsigned nr_vertex_elements,
+ const struct pipe_draw_info *info)
+{
+ unsigned max_index;
+ unsigned i;
+
+ max_index = ~0U - 1;
+ for (i = 0; i < nr_vertex_elements; i++) {
+ const struct pipe_vertex_element *element =
+ &vertex_elements[i];
+ const struct pipe_vertex_buffer *buffer =
+ &vertex_buffers[element->vertex_buffer_index];
+ unsigned buffer_size;
+ const struct util_format_description *format_desc;
+ unsigned format_size;
+
+ assert(buffer->buffer->height0 == 1);
+ assert(buffer->buffer->depth0 == 1);
+ buffer_size = buffer->buffer->width0;
+
+ format_desc = util_format_description(element->src_format);
+ assert(format_desc->block.width == 1);
+ assert(format_desc->block.height == 1);
+ assert(format_desc->block.bits % 8 == 0);
+ format_size = format_desc->block.bits/8;
+
+ if (buffer->buffer_offset >= buffer_size) {
+ /* buffer is too small */
+ return 0;
+ }
+
+ buffer_size -= buffer->buffer_offset;
+
+ if (element->src_offset >= buffer_size) {
+ /* buffer is too small */
+ return 0;
+ }
+
+ buffer_size -= element->src_offset;
+
+ if (format_size > buffer_size) {
+ /* buffer is too small */
+ return 0;
+ }
+
+ buffer_size -= format_size;
+
+ if (buffer->stride != 0) {
+ unsigned buffer_max_index;
+
+ buffer_max_index = buffer_size / buffer->stride;
+
+ if (element->instance_divisor == 0) {
+ /* Per-vertex data */
+ max_index = MIN2(max_index, buffer_max_index);
+ }
+ else {
+ /* Per-instance data. Simply make sure the state tracker didn't
+ * request more instances than those that fit in the buffer */
+ assert((info->start_instance + info->instance_count)/element->instance_divisor
+ <= (buffer_max_index + 1));
+ }
+ }
+ }
+
+ return max_index + 1;
+}
diff --git a/mesalib/src/gallium/auxiliary/util/u_prim.h b/mesalib/src/gallium/auxiliary/util/u_prim.h
index ca7c67d7c..070df643d 100644
--- a/mesalib/src/gallium/auxiliary/util/u_prim.h
+++ b/mesalib/src/gallium/auxiliary/util/u_prim.h
@@ -78,7 +78,7 @@ static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr )
static INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr )
{
boolean ok = TRUE;
- const static int values[][2] = {
+ const static unsigned values[][2] = {
{ 1, 0 }, /* PIPE_PRIM_POINTS */
{ 2, 2 }, /* PIPE_PRIM_LINES */
{ 2, 0 }, /* PIPE_PRIM_LINE_LOOP */
diff --git a/mesalib/src/glsl/ast_function.cpp b/mesalib/src/glsl/ast_function.cpp
index fc0d7497d..126b610d1 100644
--- a/mesalib/src/glsl/ast_function.cpp
+++ b/mesalib/src/glsl/ast_function.cpp
@@ -93,214 +93,256 @@ prototype_string(const glsl_type *return_type, const char *name,
return str;
}
-
static ir_rvalue *
-match_function_by_name(exec_list *instructions, const char *name,
- YYLTYPE *loc, exec_list *actual_parameters,
- struct _mesa_glsl_parse_state *state)
+generate_call(exec_list *instructions, ir_function_signature *sig,
+ YYLTYPE *loc, exec_list *actual_parameters,
+ struct _mesa_glsl_parse_state *state)
{
void *ctx = state;
- ir_function *f = state->symbols->get_function(name);
- ir_function_signature *sig;
-
- sig = f ? f->matching_signature(actual_parameters) : NULL;
+ exec_list post_call_conversions;
- /* FINISHME: This doesn't handle the case where shader X contains a
- * FINISHME: matching signature but shader X + N contains an _exact_
- * FINISHME: matching signature.
+ /* Verify that 'out' and 'inout' actual parameters are lvalues. This
+ * isn't done in ir_function::matching_signature because that function
+ * cannot generate the necessary diagnostics.
+ *
+ * Also, validate that 'const_in' formal parameters (an extension of our
+ * IR) correspond to ir_constant actual parameters.
+ *
+ * Also, perform implicit conversion of arguments. Note: to implicitly
+ * convert out parameters, we need to place them in a temporary
+ * variable, and do the conversion after the call takes place. Since we
+ * haven't emitted the call yet, we'll place the post-call conversions
+ * in a temporary exec_list, and emit them later.
*/
- if (sig == NULL
- && (f == NULL || state->es_shader || !f->has_user_signature())
- && state->symbols->get_type(name) == NULL
- && (state->language_version == 110
- || state->symbols->get_variable(name) == NULL)) {
- /* The current shader doesn't contain a matching function or signature.
- * Before giving up, look for the prototype in the built-in functions.
- */
- _mesa_glsl_initialize_functions(state);
- for (unsigned i = 0; i < state->num_builtins_to_link; i++) {
- ir_function *builtin;
- builtin = state->builtins_to_link[i]->symbols->get_function(name);
- sig = builtin ? builtin->matching_signature(actual_parameters) : NULL;
- if (sig != NULL) {
- if (f == NULL) {
- f = new(ctx) ir_function(name);
- state->symbols->add_global_function(f);
- emit_function(state, f);
- }
+ exec_list_iterator actual_iter = actual_parameters->iterator();
+ exec_list_iterator formal_iter = sig->parameters.iterator();
+
+ while (actual_iter.has_next()) {
+ ir_rvalue *actual = (ir_rvalue *) actual_iter.get();
+ ir_variable *formal = (ir_variable *) formal_iter.get();
- f->add_signature(sig->clone_prototype(f, NULL));
+ assert(actual != NULL);
+ assert(formal != NULL);
+
+ if (formal->mode == ir_var_const_in && !actual->as_constant()) {
+ _mesa_glsl_error(loc, state,
+ "parameter `%s' must be a constant expression",
+ formal->name);
+ return ir_call::get_error_instruction(ctx);
+ }
+
+ if ((formal->mode == ir_var_out)
+ || (formal->mode == ir_var_inout)) {
+ const char *mode = NULL;
+ switch (formal->mode) {
+ case ir_var_out: mode = "out"; break;
+ case ir_var_inout: mode = "inout"; break;
+ default: assert(false); break;
+ }
+ /* FIXME: 'loc' is incorrect (as of 2011-01-21). It is always
+ * FIXME: 0:0(0).
+ */
+ if (actual->variable_referenced()
+ && actual->variable_referenced()->read_only) {
+ _mesa_glsl_error(loc, state,
+ "function parameter '%s %s' references the "
+ "read-only variable '%s'",
+ mode, formal->name,
+ actual->variable_referenced()->name);
+
+ } else if (!actual->is_lvalue()) {
+ _mesa_glsl_error(loc, state,
+ "function parameter '%s %s' is not an lvalue",
+ mode, formal->name);
+ }
+ }
+
+ if (formal->type->is_numeric() || formal->type->is_boolean()) {
+ switch (formal->mode) {
+ case ir_var_const_in:
+ case ir_var_in: {
+ ir_rvalue *converted
+ = convert_component(actual, formal->type);
+ actual->replace_with(converted);
+ break;
+ }
+ case ir_var_out:
+ if (actual->type != formal->type) {
+ /* To convert an out parameter, we need to create a
+ * temporary variable to hold the value before conversion,
+ * and then perform the conversion after the function call
+ * returns.
+ *
+ * This has the effect of transforming code like this:
+ *
+ * void f(out int x);
+ * float value;
+ * f(value);
+ *
+ * Into IR that's equivalent to this:
+ *
+ * void f(out int x);
+ * float value;
+ * int out_parameter_conversion;
+ * f(out_parameter_conversion);
+ * value = float(out_parameter_conversion);
+ */
+ ir_variable *tmp =
+ new(ctx) ir_variable(formal->type,
+ "out_parameter_conversion",
+ ir_var_temporary);
+ instructions->push_tail(tmp);
+ ir_dereference_variable *deref_tmp_1
+ = new(ctx) ir_dereference_variable(tmp);
+ ir_dereference_variable *deref_tmp_2
+ = new(ctx) ir_dereference_variable(tmp);
+ ir_rvalue *converted_tmp
+ = convert_component(deref_tmp_1, actual->type);
+ ir_assignment *assignment
+ = new(ctx) ir_assignment(actual, converted_tmp);
+ post_call_conversions.push_tail(assignment);
+ actual->replace_with(deref_tmp_2);
+ }
+ break;
+ case ir_var_inout:
+ /* Inout parameters should never require conversion, since that
+ * would require an implicit conversion to exist both to and
+ * from the formal parameter type, and there are no
+ * bidirectional implicit conversions.
+ */
+ assert (actual->type == formal->type);
+ break;
+ default:
+ assert (!"Illegal formal parameter mode");
break;
}
}
- }
- exec_list post_call_conversions;
+ actual_iter.next();
+ formal_iter.next();
+ }
- if (sig != NULL) {
- /* Verify that 'out' and 'inout' actual parameters are lvalues. This
- * isn't done in ir_function::matching_signature because that function
- * cannot generate the necessary diagnostics.
- *
- * Also, validate that 'const_in' formal parameters (an extension of our
- * IR) correspond to ir_constant actual parameters.
+ /* Always insert the call in the instruction stream, and return a deref
+ * of its return val if it returns a value, since we don't know if
+ * the rvalue is going to be assigned to anything or not.
+ *
+ * Also insert any out parameter conversions after the call.
+ */
+ ir_call *call = new(ctx) ir_call(sig, actual_parameters);
+ ir_dereference_variable *deref;
+ if (!sig->return_type->is_void()) {
+ /* If the function call is a constant expression, don't
+ * generate the instructions to call it; just generate an
+ * ir_constant representing the constant value.
*
- * Also, perform implicit conversion of arguments. Note: to implicitly
- * convert out parameters, we need to place them in a temporary
- * variable, and do the conversion after the call takes place. Since we
- * haven't emitted the call yet, we'll place the post-call conversions
- * in a temporary exec_list, and emit them later.
+ * Function calls can only be constant expressions starting
+ * in GLSL 1.20.
*/
- exec_list_iterator actual_iter = actual_parameters->iterator();
- exec_list_iterator formal_iter = sig->parameters.iterator();
+ if (state->language_version >= 120) {
+ ir_constant *const_val = call->constant_expression_value();
+ if (const_val) {
+ return const_val;
+ }
+ }
- while (actual_iter.has_next()) {
- ir_rvalue *actual = (ir_rvalue *) actual_iter.get();
- ir_variable *formal = (ir_variable *) formal_iter.get();
+ ir_variable *var;
- assert(actual != NULL);
- assert(formal != NULL);
+ var = new(ctx) ir_variable(sig->return_type,
+ ralloc_asprintf(ctx, "%s_retval",
+ sig->function_name()),
+ ir_var_temporary);
+ instructions->push_tail(var);
- if (formal->mode == ir_var_const_in && !actual->as_constant()) {
- _mesa_glsl_error(loc, state,
- "parameter `%s' must be a constant expression",
- formal->name);
- return ir_call::get_error_instruction(ctx);
- }
+ deref = new(ctx) ir_dereference_variable(var);
+ ir_assignment *assign = new(ctx) ir_assignment(deref, call, NULL);
+ instructions->push_tail(assign);
- if ((formal->mode == ir_var_out)
- || (formal->mode == ir_var_inout)) {
- const char *mode = NULL;
- switch (formal->mode) {
- case ir_var_out: mode = "out"; break;
- case ir_var_inout: mode = "inout"; break;
- default: assert(false); break;
- }
- /* FIXME: 'loc' is incorrect (as of 2011-01-21). It is always
- * FIXME: 0:0(0).
- */
- if (actual->variable_referenced()
- && actual->variable_referenced()->read_only) {
- _mesa_glsl_error(loc, state,
- "function parameter '%s %s' references the "
- "read-only variable '%s'",
- mode, formal->name,
- actual->variable_referenced()->name);
-
- } else if (!actual->is_lvalue()) {
- _mesa_glsl_error(loc, state,
- "function parameter '%s %s' is not an lvalue",
- mode, formal->name);
- }
- }
+ deref = new(ctx) ir_dereference_variable(var);
+ } else {
+ instructions->push_tail(call);
+ deref = NULL;
+ }
+ instructions->append_list(&post_call_conversions);
+ return deref;
+}
- if (formal->type->is_numeric() || formal->type->is_boolean()) {
- switch (formal->mode) {
- case ir_var_const_in:
- case ir_var_in: {
- ir_rvalue *converted
- = convert_component(actual, formal->type);
- actual->replace_with(converted);
- break;
- }
- case ir_var_out:
- if (actual->type != formal->type) {
- /* To convert an out parameter, we need to create a
- * temporary variable to hold the value before conversion,
- * and then perform the conversion after the function call
- * returns.
- *
- * This has the effect of transforming code like this:
- *
- * void f(out int x);
- * float value;
- * f(value);
- *
- * Into IR that's equivalent to this:
- *
- * void f(out int x);
- * float value;
- * int out_parameter_conversion;
- * f(out_parameter_conversion);
- * value = float(out_parameter_conversion);
- */
- ir_variable *tmp =
- new(ctx) ir_variable(formal->type,
- "out_parameter_conversion",
- ir_var_temporary);
- instructions->push_tail(tmp);
- ir_dereference_variable *deref_tmp_1
- = new(ctx) ir_dereference_variable(tmp);
- ir_dereference_variable *deref_tmp_2
- = new(ctx) ir_dereference_variable(tmp);
- ir_rvalue *converted_tmp
- = convert_component(deref_tmp_1, actual->type);
- ir_assignment *assignment
- = new(ctx) ir_assignment(actual, converted_tmp);
- post_call_conversions.push_tail(assignment);
- actual->replace_with(deref_tmp_2);
- }
- break;
- case ir_var_inout:
- /* Inout parameters should never require conversion, since that
- * would require an implicit conversion to exist both to and
- * from the formal parameter type, and there are no
- * bidirectional implicit conversions.
- */
- assert (actual->type == formal->type);
- break;
- default:
- assert (!"Illegal formal parameter mode");
- break;
- }
- }
+static ir_rvalue *
+match_function_by_name(exec_list *instructions, const char *name,
+ YYLTYPE *loc, exec_list *actual_parameters,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+ ir_function *f = state->symbols->get_function(name);
+ ir_function_signature *local_sig = NULL;
+ ir_function_signature *sig = NULL;
+
+ /* Is the function hidden by a record type constructor? */
+ if (state->symbols->get_type(name))
+ goto done; /* no match */
+
+ /* Is the function hidden by a variable (impossible in 1.10)? */
+ if (state->language_version != 110 && state->symbols->get_variable(name))
+ goto done; /* no match */
+
+ if (f != NULL) {
+ /* Look for a match in the local shader. If exact, we're done. */
+ bool is_exact = false;
+ sig = local_sig = f->matching_signature(actual_parameters, &is_exact);
+ if (is_exact)
+ goto done;
+
+ if (!state->es_shader && f->has_user_signature()) {
+ /* In desktop GL, the presence of a user-defined signature hides any
+ * built-in signatures, so we must ignore them. In contrast, in ES2
+ * user-defined signatures add new overloads, so we must proceed.
+ */
+ goto done;
+ }
+ }
- actual_iter.next();
- formal_iter.next();
+ /* Local shader has no exact candidates; check the built-ins. */
+ _mesa_glsl_initialize_functions(state);
+ for (unsigned i = 0; i < state->num_builtins_to_link; i++) {
+ ir_function *builtin =
+ state->builtins_to_link[i]->symbols->get_function(name);
+ if (builtin == NULL)
+ continue;
+
+ bool is_exact = false;
+ ir_function_signature *builtin_sig =
+ builtin->matching_signature(actual_parameters, &is_exact);
+
+ if (builtin_sig == NULL)
+ continue;
+
+ /* If the built-in signature is exact, we can stop. */
+ if (is_exact) {
+ sig = builtin_sig;
+ goto done;
}
- /* Always insert the call in the instruction stream, and return a deref
- * of its return val if it returns a value, since we don't know if
- * the rvalue is going to be assigned to anything or not.
- *
- * Also insert any out parameter conversions after the call.
- */
- ir_call *call = new(ctx) ir_call(sig, actual_parameters);
- ir_dereference_variable *deref;
- if (!sig->return_type->is_void()) {
- /* If the function call is a constant expression, don't
- * generate the instructions to call it; just generate an
- * ir_constant representing the constant value.
- *
- * Function calls can only be constant expressions starting
- * in GLSL 1.20.
- */
- if (state->language_version >= 120) {
- ir_constant *const_val = call->constant_expression_value();
- if (const_val) {
- return const_val;
- }
- }
-
- ir_variable *var;
-
- var = new(ctx) ir_variable(sig->return_type,
- ralloc_asprintf(ctx, "%s_retval",
- sig->function_name()),
- ir_var_temporary);
- instructions->push_tail(var);
-
- deref = new(ctx) ir_dereference_variable(var);
- ir_assignment *assign = new(ctx) ir_assignment(deref, call, NULL);
- instructions->push_tail(assign);
-
- deref = new(ctx) ir_dereference_variable(var);
- } else {
- instructions->push_tail(call);
- deref = NULL;
+ if (sig == NULL) {
+ /* We found an inexact match, which is better than nothing. However,
+ * we should keep searching for an exact match.
+ */
+ sig = builtin_sig;
+ }
+ }
+
+done:
+ if (sig != NULL) {
+ /* If the match is from a linked built-in shader, import the prototype. */
+ if (sig != local_sig) {
+ if (f == NULL) {
+ f = new(ctx) ir_function(name);
+ state->symbols->add_global_function(f);
+ emit_function(state, f);
+ }
+ f->add_signature(sig->clone_prototype(f, NULL));
}
- instructions->append_list(&post_call_conversions);
- return deref;
+
+ /* Finally, generate a call instruction. */
+ return generate_call(instructions, sig, loc, actual_parameters, state);
} else {
char *str = prototype_string(NULL, name, actual_parameters);
diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy
index f3e873800..836390453 100644
--- a/mesalib/src/glsl/glsl_parser.yy
+++ b/mesalib/src/glsl/glsl_parser.yy
@@ -1706,7 +1706,7 @@ case_statement:
ast_case_statement *stmts = new(state) ast_case_statement($1);
stmts->stmts.push_tail(& $2->link);
- $$ = stmts
+ $$ = stmts;
}
| case_statement statement
{
diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h
index 5878c051b..1faae3c72 100644
--- a/mesalib/src/glsl/ir.h
+++ b/mesalib/src/glsl/ir.h
@@ -566,6 +566,13 @@ public:
/**
* Find a signature that matches a set of actual parameters, taking implicit
+ * conversions into account. Also flags whether the match was exact.
+ */
+ ir_function_signature *matching_signature(const exec_list *actual_param,
+ bool *match_is_exact);
+
+ /**
+ * Find a signature that matches a set of actual parameters, taking implicit
* conversions into account.
*/
ir_function_signature *matching_signature(const exec_list *actual_param);
diff --git a/mesalib/src/glsl/ir_function.cpp b/mesalib/src/glsl/ir_function.cpp
index 51d32b46f..b34a50081 100644
--- a/mesalib/src/glsl/ir_function.cpp
+++ b/mesalib/src/glsl/ir_function.cpp
@@ -118,6 +118,14 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
ir_function_signature *
ir_function::matching_signature(const exec_list *actual_parameters)
{
+ bool is_exact;
+ return matching_signature(actual_parameters, &is_exact);
+}
+
+ir_function_signature *
+ir_function::matching_signature(const exec_list *actual_parameters,
+ bool *is_exact)
+{
ir_function_signature *match = NULL;
bool multiple_inexact_matches = false;
@@ -137,6 +145,7 @@ ir_function::matching_signature(const exec_list *actual_parameters)
switch (parameter_lists_match(& sig->parameters, actual_parameters)) {
case PARAMETER_LIST_EXACT_MATCH:
+ *is_exact = true;
return sig;
case PARAMETER_LIST_INEXACT_MATCH:
if (match == NULL)
@@ -159,6 +168,8 @@ ir_function::matching_signature(const exec_list *actual_parameters)
* FINISHME: a "no matching signature" error; it should report that the
* FINISHME: call is ambiguous. But reporting errors from here is hard.
*/
+ *is_exact = false;
+
if (multiple_inexact_matches)
return NULL;
diff --git a/mesalib/src/glsl/link_uniforms.cpp b/mesalib/src/glsl/link_uniforms.cpp
index 1f860440c..ef8e436a5 100644
--- a/mesalib/src/glsl/link_uniforms.cpp
+++ b/mesalib/src/glsl/link_uniforms.cpp
@@ -113,11 +113,18 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
class count_uniform_size : public uniform_field_visitor {
public:
count_uniform_size(struct string_to_uint_map *map)
- : num_active_uniforms(0), num_values(0), map(map)
+ : num_active_uniforms(0), num_values(0), num_shader_samplers(0),
+ num_shader_uniforms(0), map(map)
{
/* empty */
}
+ void start_shader()
+ {
+ this->num_shader_samplers = 0;
+ this->num_shader_uniforms = 0;
+ }
+
/**
* Total number of active uniforms counted
*/
@@ -128,12 +135,39 @@ public:
*/
unsigned num_values;
+ /**
+ * Number of samplers used
+ */
+ unsigned num_shader_samplers;
+
+ /**
+ * Number of uniforms used in the current shader
+ */
+ unsigned num_shader_uniforms;
+
private:
virtual void visit_field(const glsl_type *type, const char *name)
{
assert(!type->is_record());
assert(!(type->is_array() && type->fields.array->is_record()));
+ /* Count the number of samplers regardless of whether the uniform is
+ * already in the hash table. The hash table prevents adding the same
+ * uniform for multiple shader targets, but in this case we want to
+ * count it for each shader target.
+ */
+ const unsigned values = values_for_type(type);
+ if (type->contains_sampler()) {
+ this->num_shader_samplers +=
+ type->is_array() ? type->array_size() : 1;
+ } else {
+ /* Accumulate the total number of uniform slots used by this shader.
+ * Note that samplers do not count against this limit because they
+ * don't use any storage on current hardware.
+ */
+ this->num_shader_uniforms += values;
+ }
+
/* If the uniform is already in the map, there's nothing more to do.
*/
unsigned id;
@@ -147,7 +181,7 @@ private:
* uniforms.
*/
this->num_active_uniforms++;
- this->num_values += values_for_type(type);
+ this->num_values += values;
}
struct string_to_uint_map *map;
@@ -267,6 +301,10 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
if (prog->_LinkedShaders[i] == NULL)
continue;
+ /* Reset various per-shader target counts.
+ */
+ uniform_size.start_shader();
+
foreach_list(node, prog->_LinkedShaders[i]->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
@@ -280,6 +318,10 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
uniform_size.process(var);
}
+
+ prog->_LinkedShaders[i]->num_samplers = uniform_size.num_shader_samplers;
+ prog->_LinkedShaders[i]->num_uniform_components =
+ uniform_size.num_shader_uniforms * 4;
}
const unsigned num_user_uniforms = uniform_size.num_active_uniforms;
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp
index 351680d43..0ec773d6c 100644
--- a/mesalib/src/glsl/linker.cpp
+++ b/mesalib/src/glsl/linker.cpp
@@ -1875,6 +1875,47 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
return true;
}
+/**
+ * Validate the resources used by a program versus the implementation limits
+ */
+static bool
+check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
+{
+ static const char *const shader_names[MESA_SHADER_TYPES] = {
+ "vertex", "fragment", "geometry"
+ };
+
+ const unsigned max_samplers[MESA_SHADER_TYPES] = {
+ ctx->Const.MaxVertexTextureImageUnits,
+ ctx->Const.MaxTextureImageUnits,
+ ctx->Const.MaxGeometryTextureImageUnits
+ };
+
+ const unsigned max_uniform_components[MESA_SHADER_TYPES] = {
+ ctx->Const.VertexProgram.MaxUniformComponents,
+ ctx->Const.FragmentProgram.MaxUniformComponents,
+ 0 /* FINISHME: Geometry shaders. */
+ };
+
+ for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
+ struct gl_shader *sh = prog->_LinkedShaders[i];
+
+ if (sh == NULL)
+ continue;
+
+ if (sh->num_samplers > max_samplers[i]) {
+ linker_error(prog, "Too many %s shader texture samplers",
+ shader_names[i]);
+ }
+
+ if (sh->num_uniform_components > max_uniform_components[i]) {
+ linker_error(prog, "Too many %s shader uniform components",
+ shader_names[i]);
+ }
+ }
+
+ return prog->LinkStatus;
+}
void
link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
@@ -2137,6 +2178,9 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
update_array_sizes(prog);
link_assign_uniform_locations(prog);
+ if (!check_resources(ctx, prog))
+ goto done;
+
/* OpenGL ES requires that a vertex shader and a fragment shader both be
* present in a linked program. By checking for use of shading language
* version 1.00, we also catch the GL_ARB_ES2_compatibility case.
diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript
index 3e42bfd8b..807608636 100644
--- a/mesalib/src/mesa/SConscript
+++ b/mesalib/src/mesa/SConscript
@@ -169,7 +169,6 @@ swrast_sources = [
'swrast/s_logic.c',
'swrast/s_masking.c',
'swrast/s_points.c',
- 'swrast/s_readpix.c',
'swrast/s_span.c',
'swrast/s_stencil.c',
'swrast/s_texcombine.c',
diff --git a/mesalib/src/mesa/drivers/common/driverfuncs.c b/mesalib/src/mesa/drivers/common/driverfuncs.c
index 27ea559b3..5e25d7fda 100644
--- a/mesalib/src/mesa/drivers/common/driverfuncs.c
+++ b/mesalib/src/mesa/drivers/common/driverfuncs.c
@@ -30,6 +30,7 @@
#include "main/framebuffer.h"
#include "main/mipmap.h"
#include "main/queryobj.h"
+#include "main/readpix.h"
#include "main/renderbuffer.h"
#include "main/shaderobj.h"
#include "main/texcompress.h"
@@ -82,7 +83,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
driver->Accum = _swrast_Accum;
driver->RasterPos = _tnl_RasterPos;
driver->DrawPixels = _swrast_DrawPixels;
- driver->ReadPixels = _swrast_ReadPixels;
+ driver->ReadPixels = _mesa_readpixels;
driver->CopyPixels = _swrast_CopyPixels;
driver->Bitmap = _swrast_Bitmap;
diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c
index 8d589e4c3..259041f67 100644
--- a/mesalib/src/mesa/drivers/common/meta.c
+++ b/mesalib/src/mesa/drivers/common/meta.c
@@ -879,40 +879,25 @@ _mesa_meta_end(struct gl_context *ctx)
/* restore texture objects for unit[0] only */
for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- _mesa_reference_texobj(&ctx->Texture.Unit[0].CurrentTex[tgt],
- save->CurrentTexture[tgt]);
+ if (ctx->Texture.Unit[0].CurrentTex[tgt] != save->CurrentTexture[tgt]) {
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ _mesa_reference_texobj(&ctx->Texture.Unit[0].CurrentTex[tgt],
+ save->CurrentTexture[tgt]);
+ }
_mesa_reference_texobj(&save->CurrentTexture[tgt], NULL);
}
- /* Re-enable textures, texgen */
+ /* Restore fixed function texture enables, texgen */
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- if (save->TexEnabled[u]) {
- _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
-
- if (save->TexEnabled[u] & TEXTURE_1D_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_2D_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_3D_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_CUBE_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_RECT_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_TRUE);
- }
-
- if (save->TexGenEnabled[u]) {
- _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
+ if (ctx->Texture.Unit[u].Enabled != save->TexEnabled[u]) {
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ ctx->Texture.Unit[u].Enabled = save->TexEnabled[u];
+ }
- if (save->TexGenEnabled[u] & S_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_TRUE);
- if (save->TexGenEnabled[u] & T_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_TRUE);
- if (save->TexGenEnabled[u] & R_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_TRUE);
- if (save->TexGenEnabled[u] & Q_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
- }
+ if (ctx->Texture.Unit[u].TexGenEnabled != save->TexGenEnabled[u]) {
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ ctx->Texture.Unit[u].TexGenEnabled = save->TexGenEnabled[u];
+ }
}
/* restore current unit state */
diff --git a/mesalib/src/mesa/main/ffvertex_prog.c b/mesalib/src/mesa/main/ffvertex_prog.c
index 846907842..2c937386a 100644
--- a/mesalib/src/mesa/main/ffvertex_prog.c
+++ b/mesalib/src/mesa/main/ffvertex_prog.c
@@ -949,7 +949,7 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p,
{
struct ureg attenuation = register_param3(p, STATE_LIGHT, i,
STATE_ATTENUATION);
- struct ureg att = get_temp(p);
+ struct ureg att = undef;
/* Calculate spot attenuation:
*/
@@ -959,6 +959,8 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p,
struct ureg spot = get_temp(p);
struct ureg slt = get_temp(p);
+ att = get_temp(p);
+
emit_op2(p, OPCODE_DP3, spot, 0, negate(VPpli), spot_dir_norm);
emit_op2(p, OPCODE_SLT, slt, 0, swizzle1(spot_dir_norm,W), spot);
emit_op2(p, OPCODE_POW, spot, 0, spot, swizzle1(attenuation, W));
@@ -968,9 +970,13 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p,
release_temp(p, slt);
}
- /* Calculate distance attenuation:
+ /* Calculate distance attenuation(See formula (2.4) at glspec 2.1 page 62):
+ *
+ * Skip the calucation when _dist_ is undefined(light_eyepos3_is_zero)
*/
- if (p->state->unit[i].light_attenuated) {
+ if (p->state->unit[i].light_attenuated && !is_undef(dist)) {
+ if (is_undef(att))
+ att = get_temp(p);
/* 1/d,d,d,1/d */
emit_op1(p, OPCODE_RCP, dist, WRITEMASK_YZ, dist);
/* 1,d,d*d,1/d */
@@ -1113,73 +1119,54 @@ static void build_lighting( struct tnl_program *p )
if (p->state->unit[i].light_enabled) {
struct ureg half = undef;
struct ureg att = undef, VPpli = undef;
+ struct ureg dist = undef;
count++;
+ if (p->state->unit[i].light_eyepos3_is_zero) {
+ VPpli = register_param3(p, STATE_INTERNAL,
+ STATE_LIGHT_POSITION_NORMALIZED, i);
+ } else {
+ struct ureg Ppli = register_param3(p, STATE_INTERNAL,
+ STATE_LIGHT_POSITION, i);
+ struct ureg V = get_eye_position(p);
+
+ VPpli = get_temp(p);
+ dist = get_temp(p);
+
+ /* Calculate VPpli vector
+ */
+ emit_op2(p, OPCODE_SUB, VPpli, 0, Ppli, V);
- if (p->state->unit[i].light_eyepos3_is_zero) {
- /* Can used precomputed constants in this case.
- * Attenuation never applies to infinite lights.
- */
- VPpli = register_param3(p, STATE_INTERNAL,
- STATE_LIGHT_POSITION_NORMALIZED, i);
-
- if (!p->state->material_shininess_is_zero) {
- if (p->state->light_local_viewer) {
- struct ureg eye_hat = get_eye_position_normalized(p);
- half = get_temp(p);
- emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat);
- emit_normalize_vec3(p, half, half);
- }
- else {
- half = register_param3(p, STATE_INTERNAL,
- STATE_LIGHT_HALF_VECTOR, i);
- }
- }
- }
- else {
- struct ureg Ppli = register_param3(p, STATE_INTERNAL,
- STATE_LIGHT_POSITION, i);
- struct ureg V = get_eye_position(p);
- struct ureg dist = get_temp(p);
-
- VPpli = get_temp(p);
-
- /* Calculate VPpli vector
- */
- emit_op2(p, OPCODE_SUB, VPpli, 0, Ppli, V);
-
- /* Normalize VPpli. The dist value also used in
- * attenuation below.
- */
- emit_op2(p, OPCODE_DP3, dist, 0, VPpli, VPpli);
- emit_op1(p, OPCODE_RSQ, dist, 0, dist);
- emit_op2(p, OPCODE_MUL, VPpli, 0, VPpli, dist);
-
- /* Calculate attenuation:
- */
- if (!p->state->unit[i].light_spotcutoff_is_180 ||
- p->state->unit[i].light_attenuated) {
- att = calculate_light_attenuation(p, i, VPpli, dist);
- }
-
- /* Calculate viewer direction, or use infinite viewer:
- */
- if (!p->state->material_shininess_is_zero) {
- half = get_temp(p);
+ /* Normalize VPpli. The dist value also used in
+ * attenuation below.
+ */
+ emit_op2(p, OPCODE_DP3, dist, 0, VPpli, VPpli);
+ emit_op1(p, OPCODE_RSQ, dist, 0, dist);
+ emit_op2(p, OPCODE_MUL, VPpli, 0, VPpli, dist);
+ }
- if (p->state->light_local_viewer) {
- struct ureg eye_hat = get_eye_position_normalized(p);
- emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat);
- }
- else {
- struct ureg z_dir = swizzle(get_identity_param(p),X,Y,W,Z);
- emit_op2(p, OPCODE_ADD, half, 0, VPpli, z_dir);
- }
+ /* Calculate attenuation:
+ */
+ att = calculate_light_attenuation(p, i, VPpli, dist);
+ release_temp(p, dist);
+ /* Calculate viewer direction, or use infinite viewer:
+ */
+ if (!p->state->material_shininess_is_zero) {
+ if (p->state->light_local_viewer) {
+ struct ureg eye_hat = get_eye_position_normalized(p);
+ half = get_temp(p);
+ emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat);
+ emit_normalize_vec3(p, half, half);
+ } else if (p->state->unit[i].light_eyepos3_is_zero) {
+ half = register_param3(p, STATE_INTERNAL,
+ STATE_LIGHT_HALF_VECTOR, i);
+ } else {
+ struct ureg z_dir = swizzle(get_identity_param(p),X,Y,W,Z);
+ half = get_temp(p);
+ emit_op2(p, OPCODE_ADD, half, 0, VPpli, z_dir);
emit_normalize_vec3(p, half, half);
}
-
- release_temp(p, dist);
}
/* Calculate dot products:
diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c
index 525bbcb1c..6e2ce7a05 100644
--- a/mesalib/src/mesa/main/format_unpack.c
+++ b/mesalib/src/mesa/main/format_unpack.c
@@ -57,1049 +57,1335 @@ nonlinear_to_linear(GLubyte cs8)
}
-typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[4]);
+typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
static void
-unpack_RGBA8888(const void *src, GLfloat dst[4])
+unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
{
- 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 );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
+ }
}
static void
-unpack_RGBA8888_REV(const void *src, GLfloat dst[4])
+unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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) );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
+ }
}
static void
-unpack_ARGB8888(const void *src, GLfloat dst[4])
+unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
{
- 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) );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
+ }
}
static void
-unpack_ARGB8888_REV(const void *src, GLfloat dst[4])
+unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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 );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
+ }
}
static void
-unpack_XRGB8888(const void *src, GLfloat dst[4])
+unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
+ dst[i][ACOMP] = 1.0f;
+ }
}
static void
-unpack_XRGB8888_REV(const void *src, GLfloat dst[4])
+unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
+ dst[i][ACOMP] = 1.0f;
+ }
}
static void
-unpack_RGB888(const void *src, GLfloat dst[4])
+unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_BGR888(const void *src, GLfloat dst[4])
+unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_RGB565(const void *src, GLfloat dst[4])
+unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
+ dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
+ dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_RGB565_REV(const void *src, GLfloat dst[4])
+unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) );
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_ARGB4444(const void *src, GLfloat dst[4])
+unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
{
- 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);
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
+ dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
+ dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
+ dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
+ }
}
static void
-unpack_ARGB4444_REV(const void *src, GLfloat dst[4])
+unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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);
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
+ dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
+ dst[i][BCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
+ dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
+ }
}
static void
-unpack_RGBA5551(const void *src, GLfloat dst[4])
+unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
+ dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F);
+ dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F);
+ dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F;
+ }
}
static void
-unpack_ARGB1555(const void *src, GLfloat dst[4])
+unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
+ dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
+ dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
+ dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
+ }
}
static void
-unpack_ARGB1555_REV(const void *src, GLfloat dst[4])
+unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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 );
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( ((s[i] >> 7) & 0xf8) | ((s[i] >> 12) & 0x7) );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( ((s[i] >> 2) & 0xf8) | ((s[i] >> 7) & 0x7) );
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( ((s[i] << 3) & 0xf8) | ((s[i] >> 2) & 0x7) );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( ((s[i] >> 15) & 0x01) * 255 );
+ }
}
static void
-unpack_AL44(const void *src, GLfloat dst[4])
+unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
{
- 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);
+ const GLubyte *s = ((const GLubyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
+ dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
+ }
}
static void
-unpack_AL88(const void *src, GLfloat dst[4])
+unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLushort s = *((const GLushort *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
- dst[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
+ }
}
static void
-unpack_AL88_REV(const void *src, GLfloat dst[4])
+unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLushort s = *((const GLushort *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
- dst[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
+ }
}
static void
-unpack_AL1616(const void *src, GLfloat dst[4])
+unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLuint s = *((const GLuint *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
- dst[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
+ dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
+ }
}
static void
-unpack_AL1616_REV(const void *src, GLfloat dst[4])
+unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLuint s = *((const GLuint *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
- dst[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
+ dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
+ }
}
static void
-unpack_RGB332(const void *src, GLfloat dst[4])
+unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLubyte *s = ((const GLubyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
+ dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
+ dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_A8(const void *src, GLfloat dst[4])
+unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLubyte s = *((const GLubyte *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = 0.0F;
- dst[ACOMP] = UBYTE_TO_FLOAT(s);
+ const GLubyte *s = ((const GLubyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
+ }
}
static void
-unpack_A16(const void *src, GLfloat dst[4])
+unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLushort s = *((const GLushort *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = 0.0F;
- dst[ACOMP] = USHORT_TO_FLOAT(s);
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
+ }
}
static void
-unpack_L8(const void *src, GLfloat dst[4])
+unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLubyte s = *((const GLubyte *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = UBYTE_TO_FLOAT(s);
- dst[ACOMP] = 1.0F;
+ const GLubyte *s = ((const GLubyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_L16(const void *src, GLfloat dst[4])
+unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLushort s = *((const GLushort *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = USHORT_TO_FLOAT(s);
- dst[ACOMP] = 1.0F;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_I8(const void *src, GLfloat dst[4])
+unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLubyte s = *((const GLubyte *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] =
- dst[ACOMP] = UBYTE_TO_FLOAT(s);
+ const GLubyte *s = ((const GLubyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] =
+ dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
+ }
}
static void
-unpack_I16(const void *src, GLfloat dst[4])
+unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLushort s = *((const GLushort *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] =
- dst[ACOMP] = USHORT_TO_FLOAT(s);
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] =
+ dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
+ }
}
static void
-unpack_YCBCR(const void *src, GLfloat dst[4])
+unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
+ 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[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_YCBCR_REV(const void *src, GLfloat dst[4])
+unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
+ 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[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_R8(const void *src, GLfloat dst[4])
+unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLubyte s = *((const GLubyte *) src);
- dst[0] = UBYTE_TO_FLOAT(s);
- dst[1] = dst[2] = 0.0F;
- dst[3] = 1.0F;
+ const GLubyte *s = ((const GLubyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] = UBYTE_TO_FLOAT(s[i]);
+ dst[i][1] =
+ dst[i][2] = 0.0F;
+ dst[i][3] = 1.0F;
+ }
}
static void
-unpack_RG88(const void *src, GLfloat dst[4])
+unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
+ dst[i][BCOMP] = 0.0;
+ dst[i][ACOMP] = 1.0;
+ }
}
static void
-unpack_RG88_REV(const void *src, GLfloat dst[4])
+unpack_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
+ dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
+ dst[i][BCOMP] = 0.0;
+ dst[i][ACOMP] = 1.0;
+ }
}
static void
-unpack_R16(const void *src, GLfloat dst[4])
+unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLushort s = *((const GLushort *) src);
- dst[RCOMP] = USHORT_TO_FLOAT(s);
- dst[GCOMP] = 0.0;
- dst[BCOMP] = 0.0;
- dst[ACOMP] = 1.0;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
+ dst[i][GCOMP] = 0.0;
+ dst[i][BCOMP] = 0.0;
+ dst[i][ACOMP] = 1.0;
+ }
}
static void
-unpack_RG1616(const void *src, GLfloat dst[4])
+unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
+ dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
+ dst[i][BCOMP] = 0.0;
+ dst[i][ACOMP] = 1.0;
+ }
}
static void
-unpack_RG1616_REV(const void *src, GLfloat dst[4])
+unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
+ dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
+ dst[i][BCOMP] = 0.0;
+ dst[i][ACOMP] = 1.0;
+ }
}
static void
-unpack_ARGB2101010(const void *src, GLfloat dst[4])
+unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
{
- 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);
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
+ dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
+ dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
+ dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
+ }
}
static void
-unpack_Z24_S8(const void *src, GLfloat dst[4])
+unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
{
/* only return Z, not stencil data */
- const GLuint s = *((const GLuint *) src);
+ 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);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] =
+ dst[i][1] =
+ dst[i][2] = (s[i] >> 8) * scale;
+ dst[i][3] = 1.0F;
+ ASSERT(dst[i][0] >= 0.0F);
+ ASSERT(dst[i][0] <= 1.0F);
+ }
}
static void
-unpack_S8_Z24(const void *src, GLfloat dst[4])
+unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
{
/* only return Z, not stencil data */
- const GLuint s = *((const GLuint *) src);
+ 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);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] =
+ dst[i][1] =
+ dst[i][2] = (s[i] & 0x00ffffff) * scale;
+ dst[i][3] = 1.0F;
+ ASSERT(dst[i][0] >= 0.0F);
+ ASSERT(dst[i][0] <= 1.0F);
+ }
}
static void
-unpack_Z16(const void *src, GLfloat dst[4])
+unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLushort s = *((const GLushort *) src);
- dst[0] = dst[1] = dst[2] = s * (1.0F / 65535.0F);
- dst[3] = 1.0F;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] =
+ dst[i][1] =
+ dst[i][2] = s[i] * (1.0F / 65535.0F);
+ dst[i][3] = 1.0F;
+ }
}
static void
-unpack_X8_Z24(const void *src, GLfloat dst[4])
+unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
{
- unpack_S8_Z24(src, dst);
+ unpack_S8_Z24(src, dst, n);
}
static void
-unpack_Z24_X8(const void *src, GLfloat dst[4])
+unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
{
- unpack_Z24_S8(src, dst);
+ unpack_Z24_S8(src, dst, n);
}
static void
-unpack_Z32(const void *src, GLfloat dst[4])
+unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLuint s = *((const GLuint *) src);
- dst[0] = dst[1] = dst[2] = s * (1.0F / 0xffffffff);
- dst[3] = 1.0F;
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] =
+ dst[i][1] =
+ dst[i][2] = s[i] * (1.0F / 0xffffffff);
+ dst[i][3] = 1.0F;
+ }
}
static void
-unpack_Z32_FLOAT(const void *src, GLfloat dst[4])
+unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLfloat s = *((const GLfloat *) src);
- dst[0] = dst[1] = dst[2] = s;
- dst[3] = 1.0F;
+ const GLfloat *s = ((const GLfloat *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] =
+ dst[i][1] =
+ dst[i][2] = s[i];
+ dst[i][3] = 1.0F;
+ }
}
static void
-unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[4])
+unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLfloat s = *((const GLfloat *) src);
- dst[0] = dst[1] = dst[2] = s;
- dst[3] = 1.0F;
+ const GLfloat *s = ((const GLfloat *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] =
+ dst[i][1] =
+ dst[i][2] = s[i];
+ dst[i][3] = 1.0F;
+ }
}
static void
-unpack_S8(const void *src, GLfloat dst[4])
+unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
{
/* should never be used */
- dst[0] = dst[1] = dst[2] = 0.0F;
- dst[3] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][0] =
+ dst[i][1] =
+ dst[i][2] = 0.0F;
+ dst[i][3] = 1.0F;
+ }
}
static void
-unpack_SRGB8(const void *src, GLfloat dst[4])
+unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]);
+ dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]);
+ dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SRGBA8(const void *src, GLfloat dst[4])
+unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
{
- 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! */
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) );
+ dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
+ dst[i][BCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
+ }
}
static void
-unpack_SARGB8(const void *src, GLfloat dst[4])
+unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
{
- 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! */
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
+ dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = nonlinear_to_linear( (s[i] ) & 0xff );
+ dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
+ }
}
static void
-unpack_SL8(const void *src, GLfloat dst[4])
+unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLubyte s = *((const GLubyte *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = nonlinear_to_linear(s);
- dst[ACOMP] = 1.0F;
+ const GLubyte *s = ((const GLubyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = nonlinear_to_linear(s[i]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SLA8(const void *src, GLfloat dst[4])
+unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
{
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 */
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = nonlinear_to_linear(s[i*2+0]);
+ dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i*2+1]); /* linear! */
+ }
}
static void
-unpack_SRGB_DXT1(const void *src, GLfloat dst[4])
+unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_SRGBA_DXT1(const void *src, GLfloat dst[4])
+unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_SRGBA_DXT3(const void *src, GLfloat dst[4])
+unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_SRGBA_DXT5(const void *src, GLfloat dst[4])
+unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_RGB_FXT1(const void *src, GLfloat dst[4])
+unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_RGBA_FXT1(const void *src, GLfloat dst[4])
+unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_RGB_DXT1(const void *src, GLfloat dst[4])
+unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_RGBA_DXT1(const void *src, GLfloat dst[4])
+unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_RGBA_DXT3(const void *src, GLfloat dst[4])
+unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_RGBA_DXT5(const void *src, GLfloat dst[4])
+unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
{
}
static void
-unpack_RGBA_FLOAT32(const void *src, GLfloat dst[4])
+unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] = s[0];
- dst[GCOMP] = s[1];
- dst[BCOMP] = s[2];
- dst[ACOMP] = s[3];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = s[i*4+0];
+ dst[i][GCOMP] = s[i*4+1];
+ dst[i][BCOMP] = s[i*4+2];
+ dst[i][ACOMP] = s[i*4+3];
+ }
}
static void
-unpack_RGBA_FLOAT16(const void *src, GLfloat dst[4])
+unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
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]);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
+ dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
+ dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
+ dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
+ }
}
static void
-unpack_RGB_FLOAT32(const void *src, GLfloat dst[4])
+unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] = s[0];
- dst[GCOMP] = s[1];
- dst[BCOMP] = s[2];
- dst[ACOMP] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = s[i*3+0];
+ dst[i][GCOMP] = s[i*3+1];
+ dst[i][BCOMP] = s[i*3+2];
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_RGB_FLOAT16(const void *src, GLfloat dst[4])
+unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
+ dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
+ dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[4])
+unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = 0.0F;
- dst[ACOMP] = s[0];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = s[i];
+ }
}
static void
-unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[4])
+unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
const GLhalfARB *s = (const GLhalfARB *) src;
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = 0.0F;
- dst[ACOMP] = _mesa_half_to_float(s[0]);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = _mesa_half_to_float(s[i]);
+ }
}
static void
-unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[4])
+unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = s[0];
- dst[ACOMP] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = s[i];
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[4])
+unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
const GLhalfARB *s = (const GLhalfARB *) src;
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = _mesa_half_to_float(s[0]);
- dst[ACOMP] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = _mesa_half_to_float(s[i]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[4])
+unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = s[0];
- dst[ACOMP] = s[1];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = s[i*2+0];
+ dst[i][ACOMP] = s[i*2+1];
+ }
}
static void
-unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[4])
+unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
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]);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
+ dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
+ }
}
static void
-unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[4])
+unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] =
- dst[ACOMP] = s[0];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] =
+ dst[i][ACOMP] = s[i];
+ }
}
static void
-unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[4])
+unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
const GLhalfARB *s = (const GLhalfARB *) src;
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] =
- dst[ACOMP] = s[0];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] =
+ dst[i][ACOMP] = s[i];
+ }
}
static void
-unpack_R_FLOAT32(const void *src, GLfloat dst[4])
+unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] = s[0];
- dst[GCOMP] = 0.0F;
- dst[BCOMP] = 0.0F;
- dst[ACOMP] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = s[i];
+ dst[i][GCOMP] = 0.0F;
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_R_FLOAT16(const void *src, GLfloat dst[4])
+unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = _mesa_half_to_float(s[i]);
+ dst[i][GCOMP] = 0.0F;
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_RG_FLOAT32(const void *src, GLfloat dst[4])
+unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
const GLfloat *s = (const GLfloat *) src;
- dst[RCOMP] = s[0];
- dst[GCOMP] = s[1];
- dst[BCOMP] = 0.0F;
- dst[ACOMP] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = s[i*2+0];
+ dst[i][GCOMP] = s[i*2+1];
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_RG_FLOAT16(const void *src, GLfloat dst[4])
+unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
+ dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_RGBA_INT8(const void *src, GLfloat dst[4])
+unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
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];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = (GLfloat) s[i*4+0];
+ dst[i][GCOMP] = (GLfloat) s[i*4+1];
+ dst[i][BCOMP] = (GLfloat) s[i*4+2];
+ dst[i][ACOMP] = (GLfloat) s[i*4+3];
+ }
}
static void
-unpack_RGBA_INT16(const void *src, GLfloat dst[4])
+unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
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];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = (GLfloat) s[i*4+0];
+ dst[i][GCOMP] = (GLfloat) s[i*4+1];
+ dst[i][BCOMP] = (GLfloat) s[i*4+2];
+ dst[i][ACOMP] = (GLfloat) s[i*4+3];
+ }
}
static void
-unpack_RGBA_INT32(const void *src, GLfloat dst[4])
+unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
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];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = (GLfloat) s[i*4+0];
+ dst[i][GCOMP] = (GLfloat) s[i*4+1];
+ dst[i][BCOMP] = (GLfloat) s[i*4+2];
+ dst[i][ACOMP] = (GLfloat) s[i*4+3];
+ }
}
static void
-unpack_RGBA_UINT8(const void *src, GLfloat dst[4])
+unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
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];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = (GLfloat) s[i*4+0];
+ dst[i][GCOMP] = (GLfloat) s[i*4+1];
+ dst[i][BCOMP] = (GLfloat) s[i*4+2];
+ dst[i][ACOMP] = (GLfloat) s[i*4+3];
+ }
}
static void
-unpack_RGBA_UINT16(const void *src, GLfloat dst[4])
+unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
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];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = (GLfloat) s[i*4+0];
+ dst[i][GCOMP] = (GLfloat) s[i*4+1];
+ dst[i][BCOMP] = (GLfloat) s[i*4+2];
+ dst[i][ACOMP] = (GLfloat) s[i*4+3];
+ }
}
static void
-unpack_RGBA_UINT32(const void *src, GLfloat dst[4])
+unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
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];
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = (GLfloat) s[i*4+0];
+ dst[i][GCOMP] = (GLfloat) s[i*4+1];
+ dst[i][BCOMP] = (GLfloat) s[i*4+2];
+ dst[i][ACOMP] = (GLfloat) s[i*4+3];
+ }
}
static void
-unpack_DUDV8(const void *src, GLfloat dst[4])
+unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
+ dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
+ dst[i][BCOMP] = 0;
+ dst[i][ACOMP] = 0;
+ }
}
static void
-unpack_SIGNED_R8(const void *src, GLfloat dst[4])
+unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLbyte *s = ((const GLbyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
+ dst[i][GCOMP] = 0.0F;
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[4])
+unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
+ dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[4])
+unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
+ dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
+ dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
+ dst[i][ACOMP] = 1.0f;
+ }
}
static void
-unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[4])
+unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
{
- 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 ) );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
+ dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
+ dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
+ dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
+ }
}
static void
-unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[4])
+unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
{
- 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) );
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
+ dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
+ dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
+ dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
+ }
}
static void
-unpack_SIGNED_R16(const void *src, GLfloat dst[4])
+unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
{
- 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;
+ const GLshort *s = ((const GLshort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
+ dst[i][GCOMP] = 0.0F;
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SIGNED_GR1616(const void *src, GLfloat dst[4])
+unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLuint s = *((const GLuint *) src);
- dst[RCOMP] = SHORT_TO_FLOAT_TEX( s & 0xffff );
- dst[GCOMP] = SHORT_TO_FLOAT_TEX( s >> 16 );
- dst[BCOMP] = 0.0F;
- dst[ACOMP] = 1.0F;
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] & 0xffff );
+ dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i] >> 16 );
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SIGNED_RGB_16(const void *src, GLfloat dst[4])
+unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
{
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;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
+ dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
+ dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[4])
+unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
{
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] );
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
+ dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
+ dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
+ dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
+ }
}
static void
-unpack_RGBA_16(const void *src, GLfloat dst[4])
+unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
{
const GLushort *s = (const GLushort *) 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] );
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
+ dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
+ dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
+ dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
+ }
}
static void
-unpack_RED_RGTC1(const void *src, GLfloat dst[4])
+unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[4])
+unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_RG_RGTC2(const void *src, GLfloat dst[4])
+unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[4])
+unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_L_LATC1(const void *src, GLfloat dst[4])
+unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[4])
+unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_LA_LATC2(const void *src, GLfloat dst[4])
+unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[4])
+unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void
-unpack_SIGNED_A8(const void *src, GLfloat dst[4])
+unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
{
- 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 );
+ const GLbyte *s = ((const GLbyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = 0.0F;
+ dst[i][GCOMP] = 0.0F;
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
+ }
}
static void
-unpack_SIGNED_L8(const void *src, GLfloat dst[4])
+unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLbyte s = *((const GLbyte *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = BYTE_TO_FLOAT_TEX( s );
- dst[ACOMP] = 1.0F;
+ const GLbyte *s = ((const GLbyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SIGNED_AL88(const void *src, GLfloat dst[4])
+unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
{
- 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) );
+ const GLshort *s = ((const GLshort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
+ dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
+ }
}
static void
-unpack_SIGNED_I8(const void *src, GLfloat dst[4])
+unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLbyte s = *((const GLbyte *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] =
- dst[ACOMP] = BYTE_TO_FLOAT_TEX( s );
+ const GLbyte *s = ((const GLbyte *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] =
+ dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
+ }
}
static void
-unpack_SIGNED_A16(const void *src, GLfloat dst[4])
+unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
{
- 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 );
+ const GLshort *s = ((const GLshort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = 0.0F;
+ dst[i][GCOMP] = 0.0F;
+ dst[i][BCOMP] = 0.0F;
+ dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
+ }
}
static void
-unpack_SIGNED_L16(const void *src, GLfloat dst[4])
+unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLshort s = *((const GLshort *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] = SHORT_TO_FLOAT_TEX( s );
- dst[ACOMP] = 1.0F;
+ const GLshort *s = ((const GLshort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_SIGNED_AL1616(const void *src, GLfloat dst[4])
+unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
{
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] );
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
+ dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
+ }
}
static void
-unpack_SIGNED_I16(const void *src, GLfloat dst[4])
+unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
{
- const GLshort s = *((const GLshort *) src);
- dst[RCOMP] =
- dst[GCOMP] =
- dst[BCOMP] =
- dst[ACOMP] = SHORT_TO_FLOAT_TEX( s );
+ const GLshort *s = ((const GLshort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] =
+ dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
+ }
}
static void
-unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[4])
+unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
{
const GLuint *s = (const GLuint *) src;
- rgb9e5_to_float3(*s, dst);
- dst[ACOMP] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ rgb9e5_to_float3(s[i], dst[i]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
static void
-unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[4])
+unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
{
const GLuint *s = (const GLuint *) src;
- r11g11b10f_to_float3(*s, dst);
- dst[ACOMP] = 1.0F;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ r11g11b10f_to_float3(s[i], dst[i]);
+ dst[i][ACOMP] = 1.0F;
+ }
}
@@ -1248,14 +1534,7 @@ _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(src, dst, n);
}
static void
@@ -1401,10 +1680,9 @@ _mesa_unpack_rgba_block(gl_format format,
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;
+ const GLubyte *srcRow;
GLubyte *dstRow;
- GLfloat *dstPix;
- GLuint i, j;
+ GLuint i;
/* XXX needs to be fixed for compressed formats */
@@ -1412,14 +1690,7 @@ _mesa_unpack_rgba_block(gl_format format,
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;
- }
+ unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
dstRow += dstRowStride;
srcRow += srcRowStride;
@@ -1429,60 +1700,64 @@ _mesa_unpack_rgba_block(gl_format format,
-typedef void (*unpack_float_z_func)(const void *src, GLfloat *dst);
+typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
static void
-unpack_float_z_Z24_S8(const void *src, GLfloat *dst)
+unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
{
/* only return Z, not stencil data */
- const GLuint s = *((const GLuint *) src);
+ 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);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (s[i] >> 8) * scale;
+ ASSERT(dst[i] >= 0.0F);
+ ASSERT(dst[i] <= 1.0F);
+ }
}
static void
-unpack_float_z_S8_Z24(const void *src, GLfloat *dst)
+unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
{
/* only return Z, not stencil data */
- const GLuint s = *((const GLuint *) src);
+ 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);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (s[i] & 0x00ffffff) * scale;
+ ASSERT(dst[i] >= 0.0F);
+ ASSERT(dst[i] <= 1.0F);
+ }
}
static void
-unpack_float_z_Z24_X8(const void *src, GLfloat *dst)
+unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
{
- unpack_float_z_Z24_S8(src, dst);
+ const GLushort *s = ((const GLushort *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = s[i] * (1.0F / 65535.0F);
+ }
}
static void
-unpack_float_z_Z32(const void *src, GLfloat *dst)
+unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
{
- const GLuint s = *((const GLuint *) src);
- *dst = s * (1.0F / 0xffffffff);
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = s[i] * (1.0F / 0xffffffff);
+ }
}
static void
-unpack_float_z_Z32X24S8(const void *src, GLfloat *dst)
+unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
{
- *dst = *((const GLfloat *) src);
+ const GLfloat *s = ((const GLfloat *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = s[i * 2];
+ }
}
@@ -1492,25 +1767,18 @@ _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;
+ case MESA_FORMAT_Z24_X8:
+ unpack = unpack_float_z_Z24_X8;
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;
+ case MESA_FORMAT_Z16:
+ unpack = unpack_float_z_Z16;
break;
case MESA_FORMAT_Z32:
unpack = unpack_float_z_Z32;
@@ -1524,43 +1792,49 @@ _mesa_unpack_float_z_row(gl_format format, GLuint n,
return;
}
- for (i = 0; i < n; i++) {
- unpack(srcPtr, &dst[i]);
- srcPtr += srcStride;
- }
+ unpack(n, src, dst);
}
-typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst);
+typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
static void
-unpack_uint_z_Z24_X8(const void *src, GLuint *dst)
+unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
{
/* only return Z, not stencil data */
- const GLuint s = *((const GLuint *) src);
- *dst = (s & 0xffffff00) | (s >> 24);
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
+ }
}
static void
-unpack_uint_z_X8_Z24(const void *src, GLuint *dst)
+unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
{
/* only return Z, not stencil data */
- const GLuint s = *((const GLuint *) src);
- *dst = (s << 8) | ((s >> 16) & 0xff);
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
+ }
}
static void
-unpack_uint_z_Z16(const void *src, GLuint *dst)
+unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
{
- const GLushort s = *((const GLushort *)src);
- *dst = (s << 16) | s;
+ const GLushort *s = ((const GLushort *)src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (s[i] << 16) | s[i];
+ }
}
static void
-unpack_uint_z_Z32(const void *src, GLuint *dst)
+unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
{
- *dst = *((const GLuint *) src);
+ memcpy(dst, src, n * sizeof(GLuint));
}
@@ -1569,9 +1843,7 @@ _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:
@@ -1594,12 +1866,10 @@ _mesa_unpack_uint_z_row(gl_format format, GLuint n,
return;
}
- for (i = 0; i < n; i++) {
- unpack(srcPtr, &dst[i]);
- srcPtr += srcStride;
- }
+ unpack(srcPtr, dst, n);
}
+
static void
unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
{
diff --git a/mesalib/src/mesa/main/image.c b/mesalib/src/mesa/main/image.c
index 7d95dd6be..914a99923 100644
--- a/mesalib/src/mesa/main/image.c
+++ b/mesalib/src/mesa/main/image.c
@@ -39,25 +39,6 @@
#include "mtypes.h"
-/**
- * NOTE:
- * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
- * we later convert the float to a packed integer value (such as for
- * GL_RGB5_A1) because we'll wind up with a non-zero value.
- *
- * We redefine the macros here so zero is handled correctly.
- */
-#undef BYTE_TO_FLOAT
-#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
-
-#undef SHORT_TO_FLOAT
-#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
-
-
-
-/** Compute ceiling of integer quotient of A divided by B. */
-#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
-
/**
* \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
@@ -195,38 +176,24 @@ _mesa_sizeof_packed_type( GLenum type )
case GL_FLOAT:
return sizeof(GLfloat);
case GL_UNSIGNED_BYTE_3_3_2:
- return sizeof(GLubyte);
case GL_UNSIGNED_BYTE_2_3_3_REV:
- return sizeof(GLubyte);
case MESA_UNSIGNED_BYTE_4_4:
return sizeof(GLubyte);
case GL_UNSIGNED_SHORT_5_6_5:
- return sizeof(GLushort);
case GL_UNSIGNED_SHORT_5_6_5_REV:
- return sizeof(GLushort);
case GL_UNSIGNED_SHORT_4_4_4_4:
- return sizeof(GLushort);
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- return sizeof(GLushort);
case GL_UNSIGNED_SHORT_5_5_5_1:
- return sizeof(GLushort);
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ case GL_UNSIGNED_SHORT_8_8_MESA:
+ case GL_UNSIGNED_SHORT_8_8_REV_MESA:
return sizeof(GLushort);
case GL_UNSIGNED_INT_8_8_8_8:
- return sizeof(GLuint);
case GL_UNSIGNED_INT_8_8_8_8_REV:
- return sizeof(GLuint);
case GL_UNSIGNED_INT_10_10_10_2:
- return sizeof(GLuint);
case GL_UNSIGNED_INT_2_10_10_10_REV:
- return sizeof(GLuint);
- case GL_UNSIGNED_SHORT_8_8_MESA:
- case GL_UNSIGNED_SHORT_8_8_REV_MESA:
- return sizeof(GLushort);
case GL_UNSIGNED_INT_24_8_EXT:
- return sizeof(GLuint);
case GL_UNSIGNED_INT_5_9_9_9_REV:
- return sizeof(GLuint);
case GL_UNSIGNED_INT_10F_11F_11F_REV:
return sizeof(GLuint);
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
@@ -263,29 +230,27 @@ _mesa_components_in_format( GLenum format )
case GL_LUMINANCE_INTEGER_EXT:
case GL_INTENSITY:
return 1;
+
case GL_LUMINANCE_ALPHA:
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
case GL_RG:
+ case GL_YCBCR_MESA:
+ case GL_DEPTH_STENCIL_EXT:
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
return 2;
+
case GL_RGB:
+ case GL_BGR:
case GL_RGB_INTEGER_EXT:
return 3;
+
case GL_RGBA:
- case GL_RGBA_INTEGER_EXT:
- return 4;
- case GL_BGR:
- return 3;
case GL_BGRA:
- return 4;
case GL_ABGR_EXT:
+ case GL_RGBA_INTEGER_EXT:
return 4;
- case GL_YCBCR_MESA:
- return 2;
- case GL_DEPTH_STENCIL_EXT:
- return 2;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- return 2;
+
default:
return -1;
}
@@ -987,36 +952,48 @@ _mesa_is_integer_format(GLenum format)
/* specific integer formats */
case GL_RGBA32UI_EXT:
case GL_RGB32UI_EXT:
+ case GL_RG32UI:
+ case GL_R32UI:
case GL_ALPHA32UI_EXT:
case GL_INTENSITY32UI_EXT:
case GL_LUMINANCE32UI_EXT:
case GL_LUMINANCE_ALPHA32UI_EXT:
case GL_RGBA16UI_EXT:
case GL_RGB16UI_EXT:
+ case GL_RG16UI:
+ case GL_R16UI:
case GL_ALPHA16UI_EXT:
case GL_INTENSITY16UI_EXT:
case GL_LUMINANCE16UI_EXT:
case GL_LUMINANCE_ALPHA16UI_EXT:
case GL_RGBA8UI_EXT:
case GL_RGB8UI_EXT:
+ case GL_RG8UI:
+ case GL_R8UI:
case GL_ALPHA8UI_EXT:
case GL_INTENSITY8UI_EXT:
case GL_LUMINANCE8UI_EXT:
case GL_LUMINANCE_ALPHA8UI_EXT:
case GL_RGBA32I_EXT:
case GL_RGB32I_EXT:
+ case GL_RG32I:
+ case GL_R32I:
case GL_ALPHA32I_EXT:
case GL_INTENSITY32I_EXT:
case GL_LUMINANCE32I_EXT:
case GL_LUMINANCE_ALPHA32I_EXT:
case GL_RGBA16I_EXT:
case GL_RGB16I_EXT:
+ case GL_RG16I:
+ case GL_R16I:
case GL_ALPHA16I_EXT:
case GL_INTENSITY16I_EXT:
case GL_LUMINANCE16I_EXT:
case GL_LUMINANCE_ALPHA16I_EXT:
case GL_RGBA8I_EXT:
case GL_RGB8I_EXT:
+ case GL_RG8I:
+ case GL_R8I:
case GL_ALPHA8I_EXT:
case GL_INTENSITY8I_EXT:
case GL_LUMINANCE8I_EXT:
diff --git a/mesalib/src/mesa/main/light.c b/mesalib/src/mesa/main/light.c
index 888e5622e..60daa89a3 100644
--- a/mesalib/src/mesa/main/light.c
+++ b/mesalib/src/mesa/main/light.c
@@ -1,1430 +1,1433 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.5
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * 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
- * BRIAN PAUL 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 "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "enums.h"
-#include "light.h"
-#include "macros.h"
-#include "simple_list.h"
-#include "mtypes.h"
-#include "math/m_matrix.h"
-
-
-void GLAPIENTRY
-_mesa_ShadeModel( GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glShadeModel %s\n", _mesa_lookup_enum_by_nr(mode));
-
- if (mode != GL_FLAT && mode != GL_SMOOTH) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glShadeModel");
- return;
- }
-
- if (ctx->Light.ShadeModel == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.ShadeModel = mode;
- if (mode == GL_FLAT)
- ctx->_TriangleCaps |= DD_FLATSHADE;
- else
- ctx->_TriangleCaps &= ~DD_FLATSHADE;
-
- if (ctx->Driver.ShadeModel)
- ctx->Driver.ShadeModel( ctx, mode );
-}
-
-
-/**
- * Set the provoking vertex (the vertex which specifies the prim's
- * color when flat shading) to either the first or last vertex of the
- * triangle or line.
- */
-void GLAPIENTRY
-_mesa_ProvokingVertexEXT(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glProvokingVertexEXT 0x%x\n", mode);
-
- switch (mode) {
- case GL_FIRST_VERTEX_CONVENTION_EXT:
- case GL_LAST_VERTEX_CONVENTION_EXT:
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glProvokingVertexEXT(0x%x)", mode);
- return;
- }
-
- if (ctx->Light.ProvokingVertex == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.ProvokingVertex = mode;
-}
-
-
-/**
- * Helper function called by _mesa_Lightfv and _mesa_PopAttrib to set
- * per-light state.
- * For GL_POSITION and GL_SPOT_DIRECTION the params position/direction
- * will have already been transformed by the modelview matrix!
- * Also, all error checking should have already been done.
- */
-void
-_mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params)
-{
- struct gl_light *light;
-
- ASSERT(lnum < MAX_LIGHTS);
- light = &ctx->Light.Light[lnum];
-
- switch (pname) {
- case GL_AMBIENT:
- if (TEST_EQ_4V(light->Ambient, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( light->Ambient, params );
- break;
- case GL_DIFFUSE:
- if (TEST_EQ_4V(light->Diffuse, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( light->Diffuse, params );
- break;
- case GL_SPECULAR:
- if (TEST_EQ_4V(light->Specular, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( light->Specular, params );
- break;
- case GL_POSITION:
- /* NOTE: position has already been transformed by ModelView! */
- if (TEST_EQ_4V(light->EyePosition, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V(light->EyePosition, params);
- if (light->EyePosition[3] != 0.0F)
- light->_Flags |= LIGHT_POSITIONAL;
- else
- light->_Flags &= ~LIGHT_POSITIONAL;
- break;
- case GL_SPOT_DIRECTION:
- /* NOTE: Direction already transformed by inverse ModelView! */
- if (TEST_EQ_3V(light->SpotDirection, params))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_3V(light->SpotDirection, params);
- break;
- case GL_SPOT_EXPONENT:
- ASSERT(params[0] >= 0.0);
- ASSERT(params[0] <= ctx->Const.MaxSpotExponent);
- if (light->SpotExponent == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->SpotExponent = params[0];
- _mesa_invalidate_spot_exp_table(light);
- break;
- case GL_SPOT_CUTOFF:
- ASSERT(params[0] == 180.0 || (params[0] >= 0.0 && params[0] <= 90.0));
- if (light->SpotCutoff == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->SpotCutoff = params[0];
- light->_CosCutoffNeg = (GLfloat) (cos(light->SpotCutoff * DEG2RAD));
- if (light->_CosCutoffNeg < 0)
- light->_CosCutoff = 0;
- else
- light->_CosCutoff = light->_CosCutoffNeg;
- if (light->SpotCutoff != 180.0F)
- light->_Flags |= LIGHT_SPOT;
- else
- light->_Flags &= ~LIGHT_SPOT;
- break;
- case GL_CONSTANT_ATTENUATION:
- ASSERT(params[0] >= 0.0);
- if (light->ConstantAttenuation == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->ConstantAttenuation = params[0];
- break;
- case GL_LINEAR_ATTENUATION:
- ASSERT(params[0] >= 0.0);
- if (light->LinearAttenuation == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->LinearAttenuation = params[0];
- break;
- case GL_QUADRATIC_ATTENUATION:
- ASSERT(params[0] >= 0.0);
- if (light->QuadraticAttenuation == params[0])
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- light->QuadraticAttenuation = params[0];
- break;
- default:
- _mesa_problem(ctx, "Unexpected pname in _mesa_light()");
- return;
- }
-
- if (ctx->Driver.Lightfv)
- ctx->Driver.Lightfv( ctx, GL_LIGHT0 + lnum, pname, params );
-}
-
-
-void GLAPIENTRY
-_mesa_Lightf( GLenum light, GLenum pname, GLfloat param )
-{
- GLfloat fparam[4];
- fparam[0] = param;
- fparam[1] = fparam[2] = fparam[3] = 0.0F;
- _mesa_Lightfv( light, pname, fparam );
-}
-
-
-void GLAPIENTRY
-_mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i = (GLint) (light - GL_LIGHT0);
- GLfloat temp[4];
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (i < 0 || i >= (GLint) ctx->Const.MaxLights) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glLight(light=0x%x)", light );
- return;
- }
-
- /* do particular error checks, transformations */
- switch (pname) {
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- /* nothing */
- break;
- case GL_POSITION:
- /* transform position by ModelView matrix */
- TRANSFORM_POINT(temp, ctx->ModelviewMatrixStack.Top->m, params);
- params = temp;
- break;
- case GL_SPOT_DIRECTION:
- /* transform direction by inverse modelview */
- if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
- _math_matrix_analyse(ctx->ModelviewMatrixStack.Top);
- }
- TRANSFORM_DIRECTION(temp, params, ctx->ModelviewMatrixStack.Top->m);
- params = temp;
- break;
- case GL_SPOT_EXPONENT:
- if (params[0] < 0.0 || params[0] > ctx->Const.MaxSpotExponent) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_SPOT_CUTOFF:
- if ((params[0] < 0.0 || params[0] > 90.0) && params[0] != 180.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_CONSTANT_ATTENUATION:
- if (params[0] < 0.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_LINEAR_ATTENUATION:
- if (params[0] < 0.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- case GL_QUADRATIC_ATTENUATION:
- if (params[0] < 0.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
- return;
- }
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glLight(pname=0x%x)", pname);
- return;
- }
-
- _mesa_light(ctx, i, pname, params);
-}
-
-
-void GLAPIENTRY
-_mesa_Lighti( GLenum light, GLenum pname, GLint param )
-{
- GLint iparam[4];
- iparam[0] = param;
- iparam[1] = iparam[2] = iparam[3] = 0;
- _mesa_Lightiv( light, pname, iparam );
-}
-
-
-void GLAPIENTRY
-_mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
-{
- GLfloat fparam[4];
-
- switch (pname) {
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- fparam[0] = INT_TO_FLOAT( params[0] );
- fparam[1] = INT_TO_FLOAT( params[1] );
- fparam[2] = INT_TO_FLOAT( params[2] );
- fparam[3] = INT_TO_FLOAT( params[3] );
- break;
- case GL_POSITION:
- fparam[0] = (GLfloat) params[0];
- fparam[1] = (GLfloat) params[1];
- fparam[2] = (GLfloat) params[2];
- fparam[3] = (GLfloat) params[3];
- break;
- case GL_SPOT_DIRECTION:
- fparam[0] = (GLfloat) params[0];
- fparam[1] = (GLfloat) params[1];
- fparam[2] = (GLfloat) params[2];
- break;
- case GL_SPOT_EXPONENT:
- case GL_SPOT_CUTOFF:
- case GL_CONSTANT_ATTENUATION:
- case GL_LINEAR_ATTENUATION:
- case GL_QUADRATIC_ATTENUATION:
- fparam[0] = (GLfloat) params[0];
- break;
- default:
- /* error will be caught later in gl_Lightfv */
- ;
- }
-
- _mesa_Lightfv( light, pname, fparam );
-}
-
-
-
-void GLAPIENTRY
-_mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint l = (GLint) (light - GL_LIGHT0);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
- return;
- }
-
- switch (pname) {
- case GL_AMBIENT:
- COPY_4V( params, ctx->Light.Light[l].Ambient );
- break;
- case GL_DIFFUSE:
- COPY_4V( params, ctx->Light.Light[l].Diffuse );
- break;
- case GL_SPECULAR:
- COPY_4V( params, ctx->Light.Light[l].Specular );
- break;
- case GL_POSITION:
- COPY_4V( params, ctx->Light.Light[l].EyePosition );
- break;
- case GL_SPOT_DIRECTION:
- COPY_3V( params, ctx->Light.Light[l].SpotDirection );
- break;
- case GL_SPOT_EXPONENT:
- params[0] = ctx->Light.Light[l].SpotExponent;
- break;
- case GL_SPOT_CUTOFF:
- params[0] = ctx->Light.Light[l].SpotCutoff;
- break;
- case GL_CONSTANT_ATTENUATION:
- params[0] = ctx->Light.Light[l].ConstantAttenuation;
- break;
- case GL_LINEAR_ATTENUATION:
- params[0] = ctx->Light.Light[l].LinearAttenuation;
- break;
- case GL_QUADRATIC_ATTENUATION:
- params[0] = ctx->Light.Light[l].QuadraticAttenuation;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
- break;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint l = (GLint) (light - GL_LIGHT0);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
- return;
- }
-
- switch (pname) {
- case GL_AMBIENT:
- params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]);
- params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]);
- params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]);
- params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]);
- break;
- case GL_DIFFUSE:
- params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]);
- params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]);
- params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]);
- params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]);
- break;
- case GL_SPECULAR:
- params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]);
- params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]);
- params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]);
- params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]);
- break;
- case GL_POSITION:
- params[0] = (GLint) ctx->Light.Light[l].EyePosition[0];
- params[1] = (GLint) ctx->Light.Light[l].EyePosition[1];
- params[2] = (GLint) ctx->Light.Light[l].EyePosition[2];
- params[3] = (GLint) ctx->Light.Light[l].EyePosition[3];
- break;
- case GL_SPOT_DIRECTION:
- params[0] = (GLint) ctx->Light.Light[l].SpotDirection[0];
- params[1] = (GLint) ctx->Light.Light[l].SpotDirection[1];
- params[2] = (GLint) ctx->Light.Light[l].SpotDirection[2];
- break;
- case GL_SPOT_EXPONENT:
- params[0] = (GLint) ctx->Light.Light[l].SpotExponent;
- break;
- case GL_SPOT_CUTOFF:
- params[0] = (GLint) ctx->Light.Light[l].SpotCutoff;
- break;
- case GL_CONSTANT_ATTENUATION:
- params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation;
- break;
- case GL_LINEAR_ATTENUATION:
- params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation;
- break;
- case GL_QUADRATIC_ATTENUATION:
- params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
- break;
- }
-}
-
-
-
-/**********************************************************************/
-/*** Light Model ***/
-/**********************************************************************/
-
-
-void GLAPIENTRY
-_mesa_LightModelfv( GLenum pname, const GLfloat *params )
-{
- GLenum newenum;
- GLboolean newbool;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- switch (pname) {
- case GL_LIGHT_MODEL_AMBIENT:
- if (TEST_EQ_4V( ctx->Light.Model.Ambient, params ))
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- COPY_4V( ctx->Light.Model.Ambient, params );
- break;
- case GL_LIGHT_MODEL_LOCAL_VIEWER:
- newbool = (params[0]!=0.0);
- if (ctx->Light.Model.LocalViewer == newbool)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Model.LocalViewer = newbool;
- break;
- case GL_LIGHT_MODEL_TWO_SIDE:
- newbool = (params[0]!=0.0);
- if (ctx->Light.Model.TwoSide == newbool)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Model.TwoSide = newbool;
- if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
- ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
- else
- ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
- break;
- case GL_LIGHT_MODEL_COLOR_CONTROL:
- if (params[0] == (GLfloat) GL_SINGLE_COLOR)
- newenum = GL_SINGLE_COLOR;
- else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR)
- newenum = GL_SEPARATE_SPECULAR_COLOR;
- else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(param=0x0%x)",
- (GLint) params[0] );
- return;
- }
- if (ctx->Light.Model.ColorControl == newenum)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Model.ColorControl = newenum;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
- break;
- }
-
- if (ctx->Driver.LightModelfv)
- ctx->Driver.LightModelfv( ctx, pname, params );
-}
-
-
-void GLAPIENTRY
-_mesa_LightModeliv( GLenum pname, const GLint *params )
-{
- GLfloat fparam[4];
-
- switch (pname) {
- case GL_LIGHT_MODEL_AMBIENT:
- fparam[0] = INT_TO_FLOAT( params[0] );
- fparam[1] = INT_TO_FLOAT( params[1] );
- fparam[2] = INT_TO_FLOAT( params[2] );
- fparam[3] = INT_TO_FLOAT( params[3] );
- break;
- case GL_LIGHT_MODEL_LOCAL_VIEWER:
- case GL_LIGHT_MODEL_TWO_SIDE:
- case GL_LIGHT_MODEL_COLOR_CONTROL:
- fparam[0] = (GLfloat) params[0];
- break;
- default:
- /* Error will be caught later in gl_LightModelfv */
- ASSIGN_4V(fparam, 0.0F, 0.0F, 0.0F, 0.0F);
- }
- _mesa_LightModelfv( pname, fparam );
-}
-
-
-void GLAPIENTRY
-_mesa_LightModeli( GLenum pname, GLint param )
-{
- GLint iparam[4];
- iparam[0] = param;
- iparam[1] = iparam[2] = iparam[3] = 0;
- _mesa_LightModeliv( pname, iparam );
-}
-
-
-void GLAPIENTRY
-_mesa_LightModelf( GLenum pname, GLfloat param )
-{
- GLfloat fparam[4];
- fparam[0] = param;
- fparam[1] = fparam[2] = fparam[3] = 0.0F;
- _mesa_LightModelfv( pname, fparam );
-}
-
-
-
-/********** MATERIAL **********/
-
-
-/*
- * Given a face and pname value (ala glColorMaterial), compute a bitmask
- * of the targeted material values.
- */
-GLuint
-_mesa_material_bitmask( struct gl_context *ctx, GLenum face, GLenum pname,
- GLuint legal, const char *where )
-{
- GLuint bitmask = 0;
-
- /* Make a bitmask indicating what material attribute(s) we're updating */
- switch (pname) {
- case GL_EMISSION:
- bitmask |= MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION;
- break;
- case GL_AMBIENT:
- bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
- break;
- case GL_DIFFUSE:
- bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
- break;
- case GL_SPECULAR:
- bitmask |= MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR;
- break;
- case GL_SHININESS:
- bitmask |= MAT_BIT_FRONT_SHININESS | MAT_BIT_BACK_SHININESS;
- break;
- case GL_AMBIENT_AND_DIFFUSE:
- bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
- bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
- break;
- case GL_COLOR_INDEXES:
- bitmask |= MAT_BIT_FRONT_INDEXES | MAT_BIT_BACK_INDEXES;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
- return 0;
- }
-
- if (face==GL_FRONT) {
- bitmask &= FRONT_MATERIAL_BITS;
- }
- else if (face==GL_BACK) {
- bitmask &= BACK_MATERIAL_BITS;
- }
- else if (face != GL_FRONT_AND_BACK) {
- _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
- return 0;
- }
-
- if (bitmask & ~legal) {
- _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
- return 0;
- }
-
- return bitmask;
-}
-
-
-
-/* Perform a straight copy between materials.
- */
-void
-_mesa_copy_materials( struct gl_material *dst,
- const struct gl_material *src,
- GLuint bitmask )
-{
- int i;
-
- for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
- if (bitmask & (1<<i))
- COPY_4FV( dst->Attrib[i], src->Attrib[i] );
-}
-
-
-
-/* Update derived values following a change in ctx->Light.Material
- */
-void
-_mesa_update_material( struct gl_context *ctx, GLuint bitmask )
-{
- struct gl_light *light, *list = &ctx->Light.EnabledList;
- GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
-
- if (MESA_VERBOSE & VERBOSE_MATERIAL)
- _mesa_debug(ctx, "_mesa_update_material, mask 0x%x\n", bitmask);
-
- if (!bitmask)
- return;
-
- /* update material ambience */
- if (bitmask & MAT_BIT_FRONT_AMBIENT) {
- foreach (light, list) {
- SCALE_3V( light->_MatAmbient[0], light->Ambient,
- mat[MAT_ATTRIB_FRONT_AMBIENT]);
- }
- }
-
- if (bitmask & MAT_BIT_BACK_AMBIENT) {
- foreach (light, list) {
- SCALE_3V( light->_MatAmbient[1], light->Ambient,
- mat[MAT_ATTRIB_BACK_AMBIENT]);
- }
- }
-
- /* update BaseColor = emission + scene's ambience * material's ambience */
- if (bitmask & (MAT_BIT_FRONT_EMISSION | MAT_BIT_FRONT_AMBIENT)) {
- COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] );
- ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT],
- ctx->Light.Model.Ambient );
- }
-
- if (bitmask & (MAT_BIT_BACK_EMISSION | MAT_BIT_BACK_AMBIENT)) {
- COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] );
- ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT],
- ctx->Light.Model.Ambient );
- }
-
- /* update material diffuse values */
- if (bitmask & MAT_BIT_FRONT_DIFFUSE) {
- foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
- mat[MAT_ATTRIB_FRONT_DIFFUSE] );
- }
- }
-
- if (bitmask & MAT_BIT_BACK_DIFFUSE) {
- foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
- mat[MAT_ATTRIB_BACK_DIFFUSE] );
- }
- }
-
- /* update material specular values */
- if (bitmask & MAT_BIT_FRONT_SPECULAR) {
- foreach (light, list) {
- SCALE_3V( light->_MatSpecular[0], light->Specular,
- mat[MAT_ATTRIB_FRONT_SPECULAR]);
- }
- }
-
- if (bitmask & MAT_BIT_BACK_SPECULAR) {
- foreach (light, list) {
- SCALE_3V( light->_MatSpecular[1], light->Specular,
- mat[MAT_ATTRIB_BACK_SPECULAR]);
- }
- }
-
- if (bitmask & MAT_BIT_FRONT_SHININESS) {
- _mesa_invalidate_shine_table( ctx, 0 );
- }
-
- if (bitmask & MAT_BIT_BACK_SHININESS) {
- _mesa_invalidate_shine_table( ctx, 1 );
- }
-}
-
-
-/*
- * Update the current materials from the given rgba color
- * according to the bitmask in ColorMaterialBitmask, which is
- * set by glColorMaterial().
- */
-void
-_mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
-{
- GLuint bitmask = ctx->Light.ColorMaterialBitmask;
- struct gl_material *mat = &ctx->Light.Material;
- int i;
-
- for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
- if (bitmask & (1<<i))
- COPY_4FV( mat->Attrib[i], color );
-
- _mesa_update_material( ctx, bitmask );
-}
-
-
-void GLAPIENTRY
-_mesa_ColorMaterial( GLenum face, GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint bitmask;
- GLuint legal = (MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION |
- MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR |
- MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE |
- MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glColorMaterial %s %s\n",
- _mesa_lookup_enum_by_nr(face),
- _mesa_lookup_enum_by_nr(mode));
-
- bitmask = _mesa_material_bitmask(ctx, face, mode, legal, "glColorMaterial");
-
- if (ctx->Light.ColorMaterialBitmask == bitmask &&
- ctx->Light.ColorMaterialFace == face &&
- ctx->Light.ColorMaterialMode == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.ColorMaterialBitmask = bitmask;
- ctx->Light.ColorMaterialFace = face;
- ctx->Light.ColorMaterialMode = mode;
-
- if (ctx->Light.ColorMaterialEnabled) {
- FLUSH_CURRENT( ctx, 0 );
- _mesa_update_color_material(ctx,ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
- }
-
- if (ctx->Driver.ColorMaterial)
- ctx->Driver.ColorMaterial( ctx, face, mode );
-}
-
-
-void GLAPIENTRY
-_mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint f;
- GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
-
- FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
-
- if (face==GL_FRONT) {
- f = 0;
- }
- else if (face==GL_BACK) {
- f = 1;
- }
- else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(face)" );
- return;
- }
-
- switch (pname) {
- case GL_AMBIENT:
- COPY_4FV( params, mat[MAT_ATTRIB_AMBIENT(f)] );
- break;
- case GL_DIFFUSE:
- COPY_4FV( params, mat[MAT_ATTRIB_DIFFUSE(f)] );
- break;
- case GL_SPECULAR:
- COPY_4FV( params, mat[MAT_ATTRIB_SPECULAR(f)] );
- break;
- case GL_EMISSION:
- COPY_4FV( params, mat[MAT_ATTRIB_EMISSION(f)] );
- break;
- case GL_SHININESS:
- *params = mat[MAT_ATTRIB_SHININESS(f)][0];
- break;
- case GL_COLOR_INDEXES:
- params[0] = mat[MAT_ATTRIB_INDEXES(f)][0];
- params[1] = mat[MAT_ATTRIB_INDEXES(f)][1];
- params[2] = mat[MAT_ATTRIB_INDEXES(f)][2];
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint f;
- GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
-
- FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
-
- if (face==GL_FRONT) {
- f = 0;
- }
- else if (face==GL_BACK) {
- f = 1;
- }
- else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialiv(face)" );
- return;
- }
- switch (pname) {
- case GL_AMBIENT:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][3] );
- break;
- case GL_DIFFUSE:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][3] );
- break;
- case GL_SPECULAR:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][3] );
- break;
- case GL_EMISSION:
- params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][0] );
- params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][1] );
- params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][2] );
- params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] );
- break;
- case GL_SHININESS:
- *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] );
- break;
- case GL_COLOR_INDEXES:
- params[0] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][0] );
- params[1] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][1] );
- params[2] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][2] );
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
- }
-}
-
-
-
-/**********************************************************************/
-/***** Lighting computation *****/
-/**********************************************************************/
-
-
-/*
- * Notes:
- * When two-sided lighting is enabled we compute the color (or index)
- * for both the front and back side of the primitive. Then, when the
- * orientation of the facet is later learned, we can determine which
- * color (or index) to use for rendering.
- *
- * KW: We now know orientation in advance and only shade for
- * the side or sides which are actually required.
- *
- * Variables:
- * n = normal vector
- * V = vertex position
- * P = light source position
- * Pe = (0,0,0,1)
- *
- * Precomputed:
- * IF P[3]==0 THEN
- * // light at infinity
- * IF local_viewer THEN
- * _VP_inf_norm = unit vector from V to P // Precompute
- * ELSE
- * // eye at infinity
- * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute
- * ENDIF
- * ENDIF
- *
- * Functions:
- * Normalize( v ) = normalized vector v
- * Magnitude( v ) = length of vector v
- */
-
-
-
-/*
- * Whenever the spotlight exponent for a light changes we must call
- * this function to recompute the exponent lookup table.
- */
-void
-_mesa_invalidate_spot_exp_table( struct gl_light *l )
-{
- l->_SpotExpTable[0][0] = -1;
-}
-
-
-static void
-validate_spot_exp_table( struct gl_light *l )
-{
- GLint i;
- GLdouble exponent = l->SpotExponent;
- GLdouble tmp = 0;
- GLint clamp = 0;
-
- l->_SpotExpTable[0][0] = 0.0;
-
- for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) {
- if (clamp == 0) {
- tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent);
- if (tmp < FLT_MIN * 100.0) {
- tmp = 0.0;
- clamp = 1;
- }
- }
- l->_SpotExpTable[i][0] = (GLfloat) tmp;
- }
- for (i = 0; i < EXP_TABLE_SIZE - 1; i++) {
- l->_SpotExpTable[i][1] = (l->_SpotExpTable[i+1][0] -
- l->_SpotExpTable[i][0]);
- }
- l->_SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0;
-}
-
-
-
-/* Calculate a new shine table. Doing this here saves a branch in
- * lighting, and the cost of doing it early may be partially offset
- * by keeping a MRU cache of shine tables for various shine values.
- */
-void
-_mesa_invalidate_shine_table( struct gl_context *ctx, GLuint side )
-{
- ASSERT(side < 2);
- if (ctx->_ShineTable[side])
- ctx->_ShineTable[side]->refcount--;
- ctx->_ShineTable[side] = NULL;
-}
-
-
-static void
-validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess )
-{
- struct gl_shine_tab *list = ctx->_ShineTabList;
- struct gl_shine_tab *s;
-
- ASSERT(side < 2);
-
- foreach(s, list)
- if ( s->shininess == shininess )
- break;
-
- if (s == list) {
- GLint j;
- GLfloat *m;
-
- foreach(s, list)
- if (s->refcount == 0)
- break;
-
- m = s->tab;
- m[0] = 0.0;
- if (shininess == 0.0) {
- for (j = 1 ; j <= SHINE_TABLE_SIZE ; j++)
- m[j] = 1.0;
- }
- else {
- for (j = 1 ; j < SHINE_TABLE_SIZE ; j++) {
- GLdouble t, x = j / (GLfloat) (SHINE_TABLE_SIZE - 1);
- if (x < 0.005) /* underflow check */
- x = 0.005;
- t = pow(x, shininess);
- if (t > 1e-20)
- m[j] = (GLfloat) t;
- else
- m[j] = 0.0;
- }
- m[SHINE_TABLE_SIZE] = 1.0;
- }
-
- s->shininess = shininess;
- }
-
- if (ctx->_ShineTable[side])
- ctx->_ShineTable[side]->refcount--;
-
- ctx->_ShineTable[side] = s;
- move_to_tail( list, s );
- s->refcount++;
-}
-
-
-void
-_mesa_validate_all_lighting_tables( struct gl_context *ctx )
-{
- GLuint i;
- GLfloat shininess;
-
- shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
- if (!ctx->_ShineTable[0] || ctx->_ShineTable[0]->shininess != shininess)
- validate_shine_table( ctx, 0, shininess );
-
- shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
- if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess)
- validate_shine_table( ctx, 1, shininess );
-
- for (i = 0; i < ctx->Const.MaxLights; i++)
- if (ctx->Light.Light[i]._SpotExpTable[0][0] == -1)
- validate_spot_exp_table( &ctx->Light.Light[i] );
-}
-
-
-/**
- * Examine current lighting parameters to determine if the optimized lighting
- * function can be used.
- * Also, precompute some lighting values such as the products of light
- * source and material ambient, diffuse and specular coefficients.
- */
-void
-_mesa_update_lighting( struct gl_context *ctx )
-{
- struct gl_light *light;
- ctx->Light._NeedEyeCoords = GL_FALSE;
- ctx->Light._Flags = 0;
-
- if (!ctx->Light.Enabled)
- return;
-
- foreach(light, &ctx->Light.EnabledList) {
- ctx->Light._Flags |= light->_Flags;
- }
-
- ctx->Light._NeedVertices =
- ((ctx->Light._Flags & (LIGHT_POSITIONAL|LIGHT_SPOT)) ||
- ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR ||
- ctx->Light.Model.LocalViewer);
-
- ctx->Light._NeedEyeCoords = ((ctx->Light._Flags & LIGHT_POSITIONAL) ||
- ctx->Light.Model.LocalViewer);
-
- /* XXX: This test is overkill & needs to be fixed both for software and
- * hardware t&l drivers. The above should be sufficient & should
- * be tested to verify this.
- */
- if (ctx->Light._NeedVertices)
- ctx->Light._NeedEyeCoords = GL_TRUE;
-
- /* Precompute some shading values. Although we reference
- * Light.Material here, we can get away without flushing
- * FLUSH_UPDATE_CURRENT, as when any outstanding material changes
- * are flushed, they will update the derived state at that time.
- */
- if (ctx->Light.Model.TwoSide)
- _mesa_update_material(ctx,
- MAT_BIT_FRONT_EMISSION |
- MAT_BIT_FRONT_AMBIENT |
- MAT_BIT_FRONT_DIFFUSE |
- MAT_BIT_FRONT_SPECULAR |
- MAT_BIT_BACK_EMISSION |
- MAT_BIT_BACK_AMBIENT |
- MAT_BIT_BACK_DIFFUSE |
- MAT_BIT_BACK_SPECULAR);
- else
- _mesa_update_material(ctx,
- MAT_BIT_FRONT_EMISSION |
- MAT_BIT_FRONT_AMBIENT |
- MAT_BIT_FRONT_DIFFUSE |
- MAT_BIT_FRONT_SPECULAR);
-}
-
-
-/**
- * Update state derived from light position, spot direction.
- * Called upon:
- * _NEW_MODELVIEW
- * _NEW_LIGHT
- * _TNL_NEW_NEED_EYE_COORDS
- *
- * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled.
- * Also update on lighting space changes.
- */
-static void
-compute_light_positions( struct gl_context *ctx )
-{
- struct gl_light *light;
- static const GLfloat eye_z[3] = { 0, 0, 1 };
-
- if (!ctx->Light.Enabled)
- return;
-
- if (ctx->_NeedEyeCoords) {
- COPY_3V( ctx->_EyeZDir, eye_z );
- }
- else {
- TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelviewMatrixStack.Top->m );
- }
-
- foreach (light, &ctx->Light.EnabledList) {
-
- if (ctx->_NeedEyeCoords) {
- /* _Position is in eye coordinate space */
- COPY_4FV( light->_Position, light->EyePosition );
- }
- else {
- /* _Position is in object coordinate space */
- TRANSFORM_POINT( light->_Position, ctx->ModelviewMatrixStack.Top->inv,
- light->EyePosition );
- }
-
- if (!(light->_Flags & LIGHT_POSITIONAL)) {
- /* VP (VP) = Normalize( Position ) */
- COPY_3V( light->_VP_inf_norm, light->_Position );
- NORMALIZE_3FV( light->_VP_inf_norm );
-
- if (!ctx->Light.Model.LocalViewer) {
- /* _h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
- ADD_3V( light->_h_inf_norm, light->_VP_inf_norm, ctx->_EyeZDir);
- NORMALIZE_3FV( light->_h_inf_norm );
- }
- light->_VP_inf_spot_attenuation = 1.0;
- }
- else {
- /* positional light w/ homogeneous coordinate, divide by W */
- GLfloat wInv = (GLfloat)1.0 / light->_Position[3];
- light->_Position[0] *= wInv;
- light->_Position[1] *= wInv;
- light->_Position[2] *= wInv;
- }
-
- if (light->_Flags & LIGHT_SPOT) {
- /* Note: we normalize the spot direction now */
-
- if (ctx->_NeedEyeCoords) {
- COPY_3V( light->_NormSpotDirection, light->SpotDirection );
- NORMALIZE_3FV( light->_NormSpotDirection );
- }
- else {
- GLfloat spotDir[3];
- COPY_3V(spotDir, light->SpotDirection);
- NORMALIZE_3FV(spotDir);
- TRANSFORM_NORMAL( light->_NormSpotDirection,
- spotDir,
- ctx->ModelviewMatrixStack.Top->m);
- }
-
- NORMALIZE_3FV( light->_NormSpotDirection );
-
- if (!(light->_Flags & LIGHT_POSITIONAL)) {
- GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm,
- light->_NormSpotDirection);
-
- if (PV_dot_dir > light->_CosCutoff) {
- double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
- int k = (int) x;
- light->_VP_inf_spot_attenuation =
- (GLfloat) (light->_SpotExpTable[k][0] +
- (x-k)*light->_SpotExpTable[k][1]);
- }
- else {
- light->_VP_inf_spot_attenuation = 0;
- }
- }
- }
- }
-}
-
-
-
-static void
-update_modelview_scale( struct gl_context *ctx )
-{
- ctx->_ModelViewInvScale = 1.0F;
- if (!_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top)) {
- const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv;
- GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
- if (f < 1e-12) f = 1.0;
- if (ctx->_NeedEyeCoords)
- ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f);
- else
- ctx->_ModelViewInvScale = (GLfloat) SQRTF(f);
- }
-}
-
-
-/**
- * Bring up to date any state that relies on _NeedEyeCoords.
- */
-void
-_mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state )
-{
- const GLuint oldneedeyecoords = ctx->_NeedEyeCoords;
-
- (void) new_state;
- ctx->_NeedEyeCoords = GL_FALSE;
-
- if (ctx->_ForceEyeCoords ||
- (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD) ||
- ctx->Point._Attenuated ||
- ctx->Light._NeedEyeCoords)
- ctx->_NeedEyeCoords = GL_TRUE;
-
- if (ctx->Light.Enabled &&
- !_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top))
- ctx->_NeedEyeCoords = GL_TRUE;
-
- /* Check if the truth-value interpretations of the bitfields have
- * changed:
- */
- if (oldneedeyecoords != ctx->_NeedEyeCoords) {
- /* Recalculate all state that depends on _NeedEyeCoords.
- */
- update_modelview_scale(ctx);
- compute_light_positions( ctx );
-
- if (ctx->Driver.LightingSpaceChange)
- ctx->Driver.LightingSpaceChange( ctx );
- }
- else {
- GLuint new_state2 = ctx->NewState;
-
- /* Recalculate that same state only if it has been invalidated
- * by other statechanges.
- */
- if (new_state2 & _NEW_MODELVIEW)
- update_modelview_scale(ctx);
-
- if (new_state2 & (_NEW_LIGHT|_NEW_MODELVIEW))
- compute_light_positions( ctx );
- }
-}
-
-
-/**
- * Drivers may need this if the hardware tnl unit doesn't support the
- * light-in-modelspace optimization. It's also useful for debugging.
- */
-void
-_mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag )
-{
- ctx->_ForceEyeCoords = !flag;
- ctx->NewState |= _NEW_POINT; /* one of the bits from
- * _MESA_NEW_NEED_EYE_COORDS.
- */
-}
-
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-/**
- * Initialize the n-th light data structure.
- *
- * \param l pointer to the gl_light structure to be initialized.
- * \param n number of the light.
- * \note The defaults for light 0 are different than the other lights.
- */
-static void
-init_light( struct gl_light *l, GLuint n )
-{
- make_empty_list( l );
-
- ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
- if (n==0) {
- ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
- ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
- }
- else {
- ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
- ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
- }
- ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
- ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 );
- l->SpotExponent = 0.0;
- _mesa_invalidate_spot_exp_table( l );
- l->SpotCutoff = 180.0;
- l->_CosCutoffNeg = -1.0f;
- l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
- l->ConstantAttenuation = 1.0;
- l->LinearAttenuation = 0.0;
- l->QuadraticAttenuation = 0.0;
- l->Enabled = GL_FALSE;
-}
-
-
-/**
- * Initialize the light model data structure.
- *
- * \param lm pointer to the gl_lightmodel structure to be initialized.
- */
-static void
-init_lightmodel( struct gl_lightmodel *lm )
-{
- ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
- lm->LocalViewer = GL_FALSE;
- lm->TwoSide = GL_FALSE;
- lm->ColorControl = GL_SINGLE_COLOR;
-}
-
-
-/**
- * Initialize the material data structure.
- *
- * \param m pointer to the gl_material structure to be initialized.
- */
-static void
-init_material( struct gl_material *m )
-{
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
-
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
- ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
-}
-
-
-/**
- * Initialize all lighting state for the given context.
- */
-void
-_mesa_init_lighting( struct gl_context *ctx )
-{
- GLuint i;
-
- /* Lighting group */
- for (i = 0; i < MAX_LIGHTS; i++) {
- init_light( &ctx->Light.Light[i], i );
- }
- make_empty_list( &ctx->Light.EnabledList );
-
- init_lightmodel( &ctx->Light.Model );
- init_material( &ctx->Light.Material );
- ctx->Light.ShadeModel = GL_SMOOTH;
- ctx->Light.ProvokingVertex = GL_LAST_VERTEX_CONVENTION_EXT;
- ctx->Light.Enabled = GL_FALSE;
- ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
- ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
- ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
- GL_FRONT_AND_BACK,
- GL_AMBIENT_AND_DIFFUSE, ~0,
- NULL );
-
- ctx->Light.ColorMaterialEnabled = GL_FALSE;
- ctx->Light.ClampVertexColor = GL_TRUE;
-
- /* Lighting miscellaneous */
- ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
- make_empty_list( ctx->_ShineTabList );
- /* Allocate 10 (arbitrary) shininess lookup tables */
- for (i = 0 ; i < 10 ; i++) {
- struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
- s->shininess = -1;
- s->refcount = 0;
- insert_at_tail( ctx->_ShineTabList, s );
- }
-
- /* Miscellaneous */
- ctx->Light._NeedEyeCoords = GL_FALSE;
- ctx->_NeedEyeCoords = GL_FALSE;
- ctx->_ForceEyeCoords = GL_FALSE;
- ctx->_ModelViewInvScale = 1.0;
-}
-
-
-/**
- * Deallocate malloc'd lighting state attached to given context.
- */
-void
-_mesa_free_lighting_data( struct gl_context *ctx )
-{
- struct gl_shine_tab *s, *tmps;
-
- /* Free lighting shininess exponentiation table */
- foreach_s( s, tmps, ctx->_ShineTabList ) {
- free( s );
- }
- free( ctx->_ShineTabList );
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.5
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * 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
+ * BRIAN PAUL 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 "glheader.h"
+#include "imports.h"
+#include "context.h"
+#include "enums.h"
+#include "light.h"
+#include "macros.h"
+#include "simple_list.h"
+#include "mtypes.h"
+#include "math/m_matrix.h"
+
+
+void GLAPIENTRY
+_mesa_ShadeModel( GLenum mode )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glShadeModel %s\n", _mesa_lookup_enum_by_nr(mode));
+
+ if (mode != GL_FLAT && mode != GL_SMOOTH) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glShadeModel");
+ return;
+ }
+
+ if (ctx->Light.ShadeModel == mode)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.ShadeModel = mode;
+ if (mode == GL_FLAT)
+ ctx->_TriangleCaps |= DD_FLATSHADE;
+ else
+ ctx->_TriangleCaps &= ~DD_FLATSHADE;
+
+ if (ctx->Driver.ShadeModel)
+ ctx->Driver.ShadeModel( ctx, mode );
+}
+
+
+/**
+ * Set the provoking vertex (the vertex which specifies the prim's
+ * color when flat shading) to either the first or last vertex of the
+ * triangle or line.
+ */
+void GLAPIENTRY
+_mesa_ProvokingVertexEXT(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glProvokingVertexEXT 0x%x\n", mode);
+
+ switch (mode) {
+ case GL_FIRST_VERTEX_CONVENTION_EXT:
+ case GL_LAST_VERTEX_CONVENTION_EXT:
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProvokingVertexEXT(0x%x)", mode);
+ return;
+ }
+
+ if (ctx->Light.ProvokingVertex == mode)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.ProvokingVertex = mode;
+}
+
+
+/**
+ * Helper function called by _mesa_Lightfv and _mesa_PopAttrib to set
+ * per-light state.
+ * For GL_POSITION and GL_SPOT_DIRECTION the params position/direction
+ * will have already been transformed by the modelview matrix!
+ * Also, all error checking should have already been done.
+ */
+void
+_mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params)
+{
+ struct gl_light *light;
+
+ ASSERT(lnum < MAX_LIGHTS);
+ light = &ctx->Light.Light[lnum];
+
+ switch (pname) {
+ case GL_AMBIENT:
+ if (TEST_EQ_4V(light->Ambient, params))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ COPY_4V( light->Ambient, params );
+ break;
+ case GL_DIFFUSE:
+ if (TEST_EQ_4V(light->Diffuse, params))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ COPY_4V( light->Diffuse, params );
+ break;
+ case GL_SPECULAR:
+ if (TEST_EQ_4V(light->Specular, params))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ COPY_4V( light->Specular, params );
+ break;
+ case GL_POSITION:
+ /* NOTE: position has already been transformed by ModelView! */
+ if (TEST_EQ_4V(light->EyePosition, params))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ COPY_4V(light->EyePosition, params);
+ if (light->EyePosition[3] != 0.0F)
+ light->_Flags |= LIGHT_POSITIONAL;
+ else
+ light->_Flags &= ~LIGHT_POSITIONAL;
+ break;
+ case GL_SPOT_DIRECTION:
+ /* NOTE: Direction already transformed by inverse ModelView! */
+ if (TEST_EQ_3V(light->SpotDirection, params))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ COPY_3V(light->SpotDirection, params);
+ break;
+ case GL_SPOT_EXPONENT:
+ ASSERT(params[0] >= 0.0);
+ ASSERT(params[0] <= ctx->Const.MaxSpotExponent);
+ if (light->SpotExponent == params[0])
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ light->SpotExponent = params[0];
+ _mesa_invalidate_spot_exp_table(light);
+ break;
+ case GL_SPOT_CUTOFF:
+ ASSERT(params[0] == 180.0 || (params[0] >= 0.0 && params[0] <= 90.0));
+ if (light->SpotCutoff == params[0])
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ light->SpotCutoff = params[0];
+ light->_CosCutoffNeg = (GLfloat) (cos(light->SpotCutoff * DEG2RAD));
+ if (light->_CosCutoffNeg < 0)
+ light->_CosCutoff = 0;
+ else
+ light->_CosCutoff = light->_CosCutoffNeg;
+ if (light->SpotCutoff != 180.0F)
+ light->_Flags |= LIGHT_SPOT;
+ else
+ light->_Flags &= ~LIGHT_SPOT;
+ break;
+ case GL_CONSTANT_ATTENUATION:
+ ASSERT(params[0] >= 0.0);
+ if (light->ConstantAttenuation == params[0])
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ light->ConstantAttenuation = params[0];
+ break;
+ case GL_LINEAR_ATTENUATION:
+ ASSERT(params[0] >= 0.0);
+ if (light->LinearAttenuation == params[0])
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ light->LinearAttenuation = params[0];
+ break;
+ case GL_QUADRATIC_ATTENUATION:
+ ASSERT(params[0] >= 0.0);
+ if (light->QuadraticAttenuation == params[0])
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ light->QuadraticAttenuation = params[0];
+ break;
+ default:
+ _mesa_problem(ctx, "Unexpected pname in _mesa_light()");
+ return;
+ }
+
+ if (ctx->Driver.Lightfv)
+ ctx->Driver.Lightfv( ctx, GL_LIGHT0 + lnum, pname, params );
+}
+
+
+void GLAPIENTRY
+_mesa_Lightf( GLenum light, GLenum pname, GLfloat param )
+{
+ GLfloat fparam[4];
+ fparam[0] = param;
+ fparam[1] = fparam[2] = fparam[3] = 0.0F;
+ _mesa_Lightfv( light, pname, fparam );
+}
+
+
+void GLAPIENTRY
+_mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i = (GLint) (light - GL_LIGHT0);
+ GLfloat temp[4];
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (i < 0 || i >= (GLint) ctx->Const.MaxLights) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glLight(light=0x%x)", light );
+ return;
+ }
+
+ /* do particular error checks, transformations */
+ switch (pname) {
+ case GL_AMBIENT:
+ case GL_DIFFUSE:
+ case GL_SPECULAR:
+ /* nothing */
+ break;
+ case GL_POSITION:
+ /* transform position by ModelView matrix */
+ TRANSFORM_POINT(temp, ctx->ModelviewMatrixStack.Top->m, params);
+ params = temp;
+ break;
+ case GL_SPOT_DIRECTION:
+ /* transform direction by inverse modelview */
+ if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
+ _math_matrix_analyse(ctx->ModelviewMatrixStack.Top);
+ }
+ TRANSFORM_DIRECTION(temp, params, ctx->ModelviewMatrixStack.Top->m);
+ params = temp;
+ break;
+ case GL_SPOT_EXPONENT:
+ if (params[0] < 0.0 || params[0] > ctx->Const.MaxSpotExponent) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
+ return;
+ }
+ break;
+ case GL_SPOT_CUTOFF:
+ if ((params[0] < 0.0 || params[0] > 90.0) && params[0] != 180.0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
+ return;
+ }
+ break;
+ case GL_CONSTANT_ATTENUATION:
+ if (params[0] < 0.0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
+ return;
+ }
+ break;
+ case GL_LINEAR_ATTENUATION:
+ if (params[0] < 0.0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
+ return;
+ }
+ break;
+ case GL_QUADRATIC_ATTENUATION:
+ if (params[0] < 0.0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
+ return;
+ }
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glLight(pname=0x%x)", pname);
+ return;
+ }
+
+ _mesa_light(ctx, i, pname, params);
+}
+
+
+void GLAPIENTRY
+_mesa_Lighti( GLenum light, GLenum pname, GLint param )
+{
+ GLint iparam[4];
+ iparam[0] = param;
+ iparam[1] = iparam[2] = iparam[3] = 0;
+ _mesa_Lightiv( light, pname, iparam );
+}
+
+
+void GLAPIENTRY
+_mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
+{
+ GLfloat fparam[4];
+
+ switch (pname) {
+ case GL_AMBIENT:
+ case GL_DIFFUSE:
+ case GL_SPECULAR:
+ fparam[0] = INT_TO_FLOAT( params[0] );
+ fparam[1] = INT_TO_FLOAT( params[1] );
+ fparam[2] = INT_TO_FLOAT( params[2] );
+ fparam[3] = INT_TO_FLOAT( params[3] );
+ break;
+ case GL_POSITION:
+ fparam[0] = (GLfloat) params[0];
+ fparam[1] = (GLfloat) params[1];
+ fparam[2] = (GLfloat) params[2];
+ fparam[3] = (GLfloat) params[3];
+ break;
+ case GL_SPOT_DIRECTION:
+ fparam[0] = (GLfloat) params[0];
+ fparam[1] = (GLfloat) params[1];
+ fparam[2] = (GLfloat) params[2];
+ break;
+ case GL_SPOT_EXPONENT:
+ case GL_SPOT_CUTOFF:
+ case GL_CONSTANT_ATTENUATION:
+ case GL_LINEAR_ATTENUATION:
+ case GL_QUADRATIC_ATTENUATION:
+ fparam[0] = (GLfloat) params[0];
+ break;
+ default:
+ /* error will be caught later in gl_Lightfv */
+ ;
+ }
+
+ _mesa_Lightfv( light, pname, fparam );
+}
+
+
+
+void GLAPIENTRY
+_mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint l = (GLint) (light - GL_LIGHT0);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
+ return;
+ }
+
+ switch (pname) {
+ case GL_AMBIENT:
+ COPY_4V( params, ctx->Light.Light[l].Ambient );
+ break;
+ case GL_DIFFUSE:
+ COPY_4V( params, ctx->Light.Light[l].Diffuse );
+ break;
+ case GL_SPECULAR:
+ COPY_4V( params, ctx->Light.Light[l].Specular );
+ break;
+ case GL_POSITION:
+ COPY_4V( params, ctx->Light.Light[l].EyePosition );
+ break;
+ case GL_SPOT_DIRECTION:
+ COPY_3V( params, ctx->Light.Light[l].SpotDirection );
+ break;
+ case GL_SPOT_EXPONENT:
+ params[0] = ctx->Light.Light[l].SpotExponent;
+ break;
+ case GL_SPOT_CUTOFF:
+ params[0] = ctx->Light.Light[l].SpotCutoff;
+ break;
+ case GL_CONSTANT_ATTENUATION:
+ params[0] = ctx->Light.Light[l].ConstantAttenuation;
+ break;
+ case GL_LINEAR_ATTENUATION:
+ params[0] = ctx->Light.Light[l].LinearAttenuation;
+ break;
+ case GL_QUADRATIC_ATTENUATION:
+ params[0] = ctx->Light.Light[l].QuadraticAttenuation;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
+ break;
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint l = (GLint) (light - GL_LIGHT0);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
+ return;
+ }
+
+ switch (pname) {
+ case GL_AMBIENT:
+ params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]);
+ params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]);
+ params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]);
+ params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]);
+ break;
+ case GL_DIFFUSE:
+ params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]);
+ params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]);
+ params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]);
+ params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]);
+ break;
+ case GL_SPECULAR:
+ params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]);
+ params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]);
+ params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]);
+ params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]);
+ break;
+ case GL_POSITION:
+ params[0] = (GLint) ctx->Light.Light[l].EyePosition[0];
+ params[1] = (GLint) ctx->Light.Light[l].EyePosition[1];
+ params[2] = (GLint) ctx->Light.Light[l].EyePosition[2];
+ params[3] = (GLint) ctx->Light.Light[l].EyePosition[3];
+ break;
+ case GL_SPOT_DIRECTION:
+ params[0] = (GLint) ctx->Light.Light[l].SpotDirection[0];
+ params[1] = (GLint) ctx->Light.Light[l].SpotDirection[1];
+ params[2] = (GLint) ctx->Light.Light[l].SpotDirection[2];
+ break;
+ case GL_SPOT_EXPONENT:
+ params[0] = (GLint) ctx->Light.Light[l].SpotExponent;
+ break;
+ case GL_SPOT_CUTOFF:
+ params[0] = (GLint) ctx->Light.Light[l].SpotCutoff;
+ break;
+ case GL_CONSTANT_ATTENUATION:
+ params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation;
+ break;
+ case GL_LINEAR_ATTENUATION:
+ params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation;
+ break;
+ case GL_QUADRATIC_ATTENUATION:
+ params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
+ break;
+ }
+}
+
+
+
+/**********************************************************************/
+/*** Light Model ***/
+/**********************************************************************/
+
+
+void GLAPIENTRY
+_mesa_LightModelfv( GLenum pname, const GLfloat *params )
+{
+ GLenum newenum;
+ GLboolean newbool;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ switch (pname) {
+ case GL_LIGHT_MODEL_AMBIENT:
+ if (TEST_EQ_4V( ctx->Light.Model.Ambient, params ))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ COPY_4V( ctx->Light.Model.Ambient, params );
+ break;
+ case GL_LIGHT_MODEL_LOCAL_VIEWER:
+ newbool = (params[0]!=0.0);
+ if (ctx->Light.Model.LocalViewer == newbool)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.Model.LocalViewer = newbool;
+ break;
+ case GL_LIGHT_MODEL_TWO_SIDE:
+ newbool = (params[0]!=0.0);
+ if (ctx->Light.Model.TwoSide == newbool)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.Model.TwoSide = newbool;
+ if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
+ ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
+ else
+ ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
+ break;
+ case GL_LIGHT_MODEL_COLOR_CONTROL:
+ if (params[0] == (GLfloat) GL_SINGLE_COLOR)
+ newenum = GL_SINGLE_COLOR;
+ else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR)
+ newenum = GL_SEPARATE_SPECULAR_COLOR;
+ else {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(param=0x0%x)",
+ (GLint) params[0] );
+ return;
+ }
+ if (ctx->Light.Model.ColorControl == newenum)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.Model.ColorControl = newenum;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
+ break;
+ }
+
+ if (ctx->Driver.LightModelfv)
+ ctx->Driver.LightModelfv( ctx, pname, params );
+}
+
+
+void GLAPIENTRY
+_mesa_LightModeliv( GLenum pname, const GLint *params )
+{
+ GLfloat fparam[4];
+
+ switch (pname) {
+ case GL_LIGHT_MODEL_AMBIENT:
+ fparam[0] = INT_TO_FLOAT( params[0] );
+ fparam[1] = INT_TO_FLOAT( params[1] );
+ fparam[2] = INT_TO_FLOAT( params[2] );
+ fparam[3] = INT_TO_FLOAT( params[3] );
+ break;
+ case GL_LIGHT_MODEL_LOCAL_VIEWER:
+ case GL_LIGHT_MODEL_TWO_SIDE:
+ case GL_LIGHT_MODEL_COLOR_CONTROL:
+ fparam[0] = (GLfloat) params[0];
+ break;
+ default:
+ /* Error will be caught later in gl_LightModelfv */
+ ASSIGN_4V(fparam, 0.0F, 0.0F, 0.0F, 0.0F);
+ }
+ _mesa_LightModelfv( pname, fparam );
+}
+
+
+void GLAPIENTRY
+_mesa_LightModeli( GLenum pname, GLint param )
+{
+ GLint iparam[4];
+ iparam[0] = param;
+ iparam[1] = iparam[2] = iparam[3] = 0;
+ _mesa_LightModeliv( pname, iparam );
+}
+
+
+void GLAPIENTRY
+_mesa_LightModelf( GLenum pname, GLfloat param )
+{
+ GLfloat fparam[4];
+ fparam[0] = param;
+ fparam[1] = fparam[2] = fparam[3] = 0.0F;
+ _mesa_LightModelfv( pname, fparam );
+}
+
+
+
+/********** MATERIAL **********/
+
+
+/*
+ * Given a face and pname value (ala glColorMaterial), compute a bitmask
+ * of the targeted material values.
+ */
+GLuint
+_mesa_material_bitmask( struct gl_context *ctx, GLenum face, GLenum pname,
+ GLuint legal, const char *where )
+{
+ GLuint bitmask = 0;
+
+ /* Make a bitmask indicating what material attribute(s) we're updating */
+ switch (pname) {
+ case GL_EMISSION:
+ bitmask |= MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION;
+ break;
+ case GL_AMBIENT:
+ bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
+ break;
+ case GL_DIFFUSE:
+ bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
+ break;
+ case GL_SPECULAR:
+ bitmask |= MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR;
+ break;
+ case GL_SHININESS:
+ bitmask |= MAT_BIT_FRONT_SHININESS | MAT_BIT_BACK_SHININESS;
+ break;
+ case GL_AMBIENT_AND_DIFFUSE:
+ bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
+ bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
+ break;
+ case GL_COLOR_INDEXES:
+ bitmask |= MAT_BIT_FRONT_INDEXES | MAT_BIT_BACK_INDEXES;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
+ return 0;
+ }
+
+ if (face==GL_FRONT) {
+ bitmask &= FRONT_MATERIAL_BITS;
+ }
+ else if (face==GL_BACK) {
+ bitmask &= BACK_MATERIAL_BITS;
+ }
+ else if (face != GL_FRONT_AND_BACK) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
+ return 0;
+ }
+
+ if (bitmask & ~legal) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "%s", where );
+ return 0;
+ }
+
+ return bitmask;
+}
+
+
+
+/* Perform a straight copy between materials.
+ */
+void
+_mesa_copy_materials( struct gl_material *dst,
+ const struct gl_material *src,
+ GLuint bitmask )
+{
+ int i;
+
+ for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
+ if (bitmask & (1<<i))
+ COPY_4FV( dst->Attrib[i], src->Attrib[i] );
+}
+
+
+
+/* Update derived values following a change in ctx->Light.Material
+ */
+void
+_mesa_update_material( struct gl_context *ctx, GLuint bitmask )
+{
+ struct gl_light *light, *list = &ctx->Light.EnabledList;
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
+
+ if (MESA_VERBOSE & VERBOSE_MATERIAL)
+ _mesa_debug(ctx, "_mesa_update_material, mask 0x%x\n", bitmask);
+
+ if (!bitmask)
+ return;
+
+ /* update material ambience */
+ if (bitmask & MAT_BIT_FRONT_AMBIENT) {
+ foreach (light, list) {
+ SCALE_3V( light->_MatAmbient[0], light->Ambient,
+ mat[MAT_ATTRIB_FRONT_AMBIENT]);
+ }
+ }
+
+ if (bitmask & MAT_BIT_BACK_AMBIENT) {
+ foreach (light, list) {
+ SCALE_3V( light->_MatAmbient[1], light->Ambient,
+ mat[MAT_ATTRIB_BACK_AMBIENT]);
+ }
+ }
+
+ /* update BaseColor = emission + scene's ambience * material's ambience */
+ if (bitmask & (MAT_BIT_FRONT_EMISSION | MAT_BIT_FRONT_AMBIENT)) {
+ COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] );
+ ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT],
+ ctx->Light.Model.Ambient );
+ }
+
+ if (bitmask & (MAT_BIT_BACK_EMISSION | MAT_BIT_BACK_AMBIENT)) {
+ COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] );
+ ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT],
+ ctx->Light.Model.Ambient );
+ }
+
+ /* update material diffuse values */
+ if (bitmask & MAT_BIT_FRONT_DIFFUSE) {
+ foreach (light, list) {
+ SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
+ mat[MAT_ATTRIB_FRONT_DIFFUSE] );
+ }
+ }
+
+ if (bitmask & MAT_BIT_BACK_DIFFUSE) {
+ foreach (light, list) {
+ SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
+ mat[MAT_ATTRIB_BACK_DIFFUSE] );
+ }
+ }
+
+ /* update material specular values */
+ if (bitmask & MAT_BIT_FRONT_SPECULAR) {
+ foreach (light, list) {
+ SCALE_3V( light->_MatSpecular[0], light->Specular,
+ mat[MAT_ATTRIB_FRONT_SPECULAR]);
+ }
+ }
+
+ if (bitmask & MAT_BIT_BACK_SPECULAR) {
+ foreach (light, list) {
+ SCALE_3V( light->_MatSpecular[1], light->Specular,
+ mat[MAT_ATTRIB_BACK_SPECULAR]);
+ }
+ }
+
+ if (bitmask & MAT_BIT_FRONT_SHININESS) {
+ _mesa_invalidate_shine_table( ctx, 0 );
+ }
+
+ if (bitmask & MAT_BIT_BACK_SHININESS) {
+ _mesa_invalidate_shine_table( ctx, 1 );
+ }
+}
+
+
+/*
+ * Update the current materials from the given rgba color
+ * according to the bitmask in ColorMaterialBitmask, which is
+ * set by glColorMaterial().
+ */
+void
+_mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
+{
+ GLuint bitmask = ctx->Light.ColorMaterialBitmask;
+ struct gl_material *mat = &ctx->Light.Material;
+ int i;
+
+ for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
+ if (bitmask & (1<<i))
+ COPY_4FV( mat->Attrib[i], color );
+
+ _mesa_update_material( ctx, bitmask );
+}
+
+
+void GLAPIENTRY
+_mesa_ColorMaterial( GLenum face, GLenum mode )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint bitmask;
+ GLuint legal = (MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION |
+ MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR |
+ MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE |
+ MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glColorMaterial %s %s\n",
+ _mesa_lookup_enum_by_nr(face),
+ _mesa_lookup_enum_by_nr(mode));
+
+ bitmask = _mesa_material_bitmask(ctx, face, mode, legal, "glColorMaterial");
+
+ if (ctx->Light.ColorMaterialBitmask == bitmask &&
+ ctx->Light.ColorMaterialFace == face &&
+ ctx->Light.ColorMaterialMode == mode)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.ColorMaterialBitmask = bitmask;
+ ctx->Light.ColorMaterialFace = face;
+ ctx->Light.ColorMaterialMode = mode;
+
+ if (ctx->Light.ColorMaterialEnabled) {
+ FLUSH_CURRENT( ctx, 0 );
+ _mesa_update_color_material(ctx,ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
+ }
+
+ if (ctx->Driver.ColorMaterial)
+ ctx->Driver.ColorMaterial( ctx, face, mode );
+}
+
+
+void GLAPIENTRY
+_mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint f;
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
+
+ FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
+
+ if (face==GL_FRONT) {
+ f = 0;
+ }
+ else if (face==GL_BACK) {
+ f = 1;
+ }
+ else {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(face)" );
+ return;
+ }
+
+ switch (pname) {
+ case GL_AMBIENT:
+ COPY_4FV( params, mat[MAT_ATTRIB_AMBIENT(f)] );
+ break;
+ case GL_DIFFUSE:
+ COPY_4FV( params, mat[MAT_ATTRIB_DIFFUSE(f)] );
+ break;
+ case GL_SPECULAR:
+ COPY_4FV( params, mat[MAT_ATTRIB_SPECULAR(f)] );
+ break;
+ case GL_EMISSION:
+ COPY_4FV( params, mat[MAT_ATTRIB_EMISSION(f)] );
+ break;
+ case GL_SHININESS:
+ *params = mat[MAT_ATTRIB_SHININESS(f)][0];
+ break;
+ case GL_COLOR_INDEXES:
+ params[0] = mat[MAT_ATTRIB_INDEXES(f)][0];
+ params[1] = mat[MAT_ATTRIB_INDEXES(f)][1];
+ params[2] = mat[MAT_ATTRIB_INDEXES(f)][2];
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint f;
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
+
+ FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
+
+ if (face==GL_FRONT) {
+ f = 0;
+ }
+ else if (face==GL_BACK) {
+ f = 1;
+ }
+ else {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialiv(face)" );
+ return;
+ }
+ switch (pname) {
+ case GL_AMBIENT:
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][3] );
+ break;
+ case GL_DIFFUSE:
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][3] );
+ break;
+ case GL_SPECULAR:
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][3] );
+ break;
+ case GL_EMISSION:
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] );
+ break;
+ case GL_SHININESS:
+ *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] );
+ break;
+ case GL_COLOR_INDEXES:
+ params[0] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][0] );
+ params[1] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][1] );
+ params[2] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][2] );
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
+ }
+}
+
+
+
+/**********************************************************************/
+/***** Lighting computation *****/
+/**********************************************************************/
+
+
+/*
+ * Notes:
+ * When two-sided lighting is enabled we compute the color (or index)
+ * for both the front and back side of the primitive. Then, when the
+ * orientation of the facet is later learned, we can determine which
+ * color (or index) to use for rendering.
+ *
+ * KW: We now know orientation in advance and only shade for
+ * the side or sides which are actually required.
+ *
+ * Variables:
+ * n = normal vector
+ * V = vertex position
+ * P = light source position
+ * Pe = (0,0,0,1)
+ *
+ * Precomputed:
+ * IF P[3]==0 THEN
+ * // light at infinity
+ * IF local_viewer THEN
+ * _VP_inf_norm = unit vector from V to P // Precompute
+ * ELSE
+ * // eye at infinity
+ * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute
+ * ENDIF
+ * ENDIF
+ *
+ * Functions:
+ * Normalize( v ) = normalized vector v
+ * Magnitude( v ) = length of vector v
+ */
+
+
+
+/*
+ * Whenever the spotlight exponent for a light changes we must call
+ * this function to recompute the exponent lookup table.
+ */
+void
+_mesa_invalidate_spot_exp_table( struct gl_light *l )
+{
+ l->_SpotExpTable[0][0] = -1;
+}
+
+
+static void
+validate_spot_exp_table( struct gl_light *l )
+{
+ GLint i;
+ GLdouble exponent = l->SpotExponent;
+ GLdouble tmp = 0;
+ GLint clamp = 0;
+
+ l->_SpotExpTable[0][0] = 0.0;
+
+ for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) {
+ if (clamp == 0) {
+ tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent);
+ if (tmp < FLT_MIN * 100.0) {
+ tmp = 0.0;
+ clamp = 1;
+ }
+ }
+ l->_SpotExpTable[i][0] = (GLfloat) tmp;
+ }
+ for (i = 0; i < EXP_TABLE_SIZE - 1; i++) {
+ l->_SpotExpTable[i][1] = (l->_SpotExpTable[i+1][0] -
+ l->_SpotExpTable[i][0]);
+ }
+ l->_SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0;
+}
+
+
+
+/* Calculate a new shine table. Doing this here saves a branch in
+ * lighting, and the cost of doing it early may be partially offset
+ * by keeping a MRU cache of shine tables for various shine values.
+ */
+void
+_mesa_invalidate_shine_table( struct gl_context *ctx, GLuint side )
+{
+ ASSERT(side < 2);
+ if (ctx->_ShineTable[side])
+ ctx->_ShineTable[side]->refcount--;
+ ctx->_ShineTable[side] = NULL;
+}
+
+
+static void
+validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess )
+{
+ struct gl_shine_tab *list = ctx->_ShineTabList;
+ struct gl_shine_tab *s;
+
+ ASSERT(side < 2);
+
+ foreach(s, list)
+ if ( s->shininess == shininess )
+ break;
+
+ if (s == list) {
+ GLint j;
+ GLfloat *m;
+
+ foreach(s, list)
+ if (s->refcount == 0)
+ break;
+
+ m = s->tab;
+ m[0] = 0.0;
+ if (shininess == 0.0) {
+ for (j = 1 ; j <= SHINE_TABLE_SIZE ; j++)
+ m[j] = 1.0;
+ }
+ else {
+ for (j = 1 ; j < SHINE_TABLE_SIZE ; j++) {
+ GLdouble t, x = j / (GLfloat) (SHINE_TABLE_SIZE - 1);
+ if (x < 0.005) /* underflow check */
+ x = 0.005;
+ t = pow(x, shininess);
+ if (t > 1e-20)
+ m[j] = (GLfloat) t;
+ else
+ m[j] = 0.0;
+ }
+ m[SHINE_TABLE_SIZE] = 1.0;
+ }
+
+ s->shininess = shininess;
+ }
+
+ if (ctx->_ShineTable[side])
+ ctx->_ShineTable[side]->refcount--;
+
+ ctx->_ShineTable[side] = s;
+ move_to_tail( list, s );
+ s->refcount++;
+}
+
+
+void
+_mesa_validate_all_lighting_tables( struct gl_context *ctx )
+{
+ GLuint i;
+ GLfloat shininess;
+
+ shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
+ if (!ctx->_ShineTable[0] || ctx->_ShineTable[0]->shininess != shininess)
+ validate_shine_table( ctx, 0, shininess );
+
+ shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
+ if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess)
+ validate_shine_table( ctx, 1, shininess );
+
+ for (i = 0; i < ctx->Const.MaxLights; i++)
+ if (ctx->Light.Light[i]._SpotExpTable[0][0] == -1)
+ validate_spot_exp_table( &ctx->Light.Light[i] );
+}
+
+
+/**
+ * Examine current lighting parameters to determine if the optimized lighting
+ * function can be used.
+ * Also, precompute some lighting values such as the products of light
+ * source and material ambient, diffuse and specular coefficients.
+ */
+void
+_mesa_update_lighting( struct gl_context *ctx )
+{
+ struct gl_light *light;
+ ctx->Light._NeedEyeCoords = GL_FALSE;
+ ctx->Light._Flags = 0;
+
+ if (!ctx->Light.Enabled)
+ return;
+
+ foreach(light, &ctx->Light.EnabledList) {
+ ctx->Light._Flags |= light->_Flags;
+ }
+
+ ctx->Light._NeedVertices =
+ ((ctx->Light._Flags & (LIGHT_POSITIONAL|LIGHT_SPOT)) ||
+ ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR ||
+ ctx->Light.Model.LocalViewer);
+
+ ctx->Light._NeedEyeCoords = ((ctx->Light._Flags & LIGHT_POSITIONAL) ||
+ ctx->Light.Model.LocalViewer);
+
+ /* XXX: This test is overkill & needs to be fixed both for software and
+ * hardware t&l drivers. The above should be sufficient & should
+ * be tested to verify this.
+ */
+ if (ctx->Light._NeedVertices)
+ ctx->Light._NeedEyeCoords = GL_TRUE;
+
+ /* Precompute some shading values. Although we reference
+ * Light.Material here, we can get away without flushing
+ * FLUSH_UPDATE_CURRENT, as when any outstanding material changes
+ * are flushed, they will update the derived state at that time.
+ */
+ if (ctx->Light.Model.TwoSide)
+ _mesa_update_material(ctx,
+ MAT_BIT_FRONT_EMISSION |
+ MAT_BIT_FRONT_AMBIENT |
+ MAT_BIT_FRONT_DIFFUSE |
+ MAT_BIT_FRONT_SPECULAR |
+ MAT_BIT_BACK_EMISSION |
+ MAT_BIT_BACK_AMBIENT |
+ MAT_BIT_BACK_DIFFUSE |
+ MAT_BIT_BACK_SPECULAR);
+ else
+ _mesa_update_material(ctx,
+ MAT_BIT_FRONT_EMISSION |
+ MAT_BIT_FRONT_AMBIENT |
+ MAT_BIT_FRONT_DIFFUSE |
+ MAT_BIT_FRONT_SPECULAR);
+}
+
+
+/**
+ * Update state derived from light position, spot direction.
+ * Called upon:
+ * _NEW_MODELVIEW
+ * _NEW_LIGHT
+ * _TNL_NEW_NEED_EYE_COORDS
+ *
+ * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled.
+ * Also update on lighting space changes.
+ */
+static void
+compute_light_positions( struct gl_context *ctx )
+{
+ struct gl_light *light;
+ static const GLfloat eye_z[3] = { 0, 0, 1 };
+
+ if (!ctx->Light.Enabled)
+ return;
+
+ if (ctx->_NeedEyeCoords) {
+ COPY_3V( ctx->_EyeZDir, eye_z );
+ }
+ else {
+ TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelviewMatrixStack.Top->m );
+ }
+
+ /* Make sure all the light tables are updated before the computation */
+ _mesa_validate_all_lighting_tables(ctx);
+
+ foreach (light, &ctx->Light.EnabledList) {
+
+ if (ctx->_NeedEyeCoords) {
+ /* _Position is in eye coordinate space */
+ COPY_4FV( light->_Position, light->EyePosition );
+ }
+ else {
+ /* _Position is in object coordinate space */
+ TRANSFORM_POINT( light->_Position, ctx->ModelviewMatrixStack.Top->inv,
+ light->EyePosition );
+ }
+
+ if (!(light->_Flags & LIGHT_POSITIONAL)) {
+ /* VP (VP) = Normalize( Position ) */
+ COPY_3V( light->_VP_inf_norm, light->_Position );
+ NORMALIZE_3FV( light->_VP_inf_norm );
+
+ if (!ctx->Light.Model.LocalViewer) {
+ /* _h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
+ ADD_3V( light->_h_inf_norm, light->_VP_inf_norm, ctx->_EyeZDir);
+ NORMALIZE_3FV( light->_h_inf_norm );
+ }
+ light->_VP_inf_spot_attenuation = 1.0;
+ }
+ else {
+ /* positional light w/ homogeneous coordinate, divide by W */
+ GLfloat wInv = (GLfloat)1.0 / light->_Position[3];
+ light->_Position[0] *= wInv;
+ light->_Position[1] *= wInv;
+ light->_Position[2] *= wInv;
+ }
+
+ if (light->_Flags & LIGHT_SPOT) {
+ /* Note: we normalize the spot direction now */
+
+ if (ctx->_NeedEyeCoords) {
+ COPY_3V( light->_NormSpotDirection, light->SpotDirection );
+ NORMALIZE_3FV( light->_NormSpotDirection );
+ }
+ else {
+ GLfloat spotDir[3];
+ COPY_3V(spotDir, light->SpotDirection);
+ NORMALIZE_3FV(spotDir);
+ TRANSFORM_NORMAL( light->_NormSpotDirection,
+ spotDir,
+ ctx->ModelviewMatrixStack.Top->m);
+ }
+
+ NORMALIZE_3FV( light->_NormSpotDirection );
+
+ if (!(light->_Flags & LIGHT_POSITIONAL)) {
+ GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm,
+ light->_NormSpotDirection);
+
+ if (PV_dot_dir > light->_CosCutoff) {
+ double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
+ int k = (int) x;
+ light->_VP_inf_spot_attenuation =
+ (GLfloat) (light->_SpotExpTable[k][0] +
+ (x-k)*light->_SpotExpTable[k][1]);
+ }
+ else {
+ light->_VP_inf_spot_attenuation = 0;
+ }
+ }
+ }
+ }
+}
+
+
+
+static void
+update_modelview_scale( struct gl_context *ctx )
+{
+ ctx->_ModelViewInvScale = 1.0F;
+ if (!_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top)) {
+ const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv;
+ GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
+ if (f < 1e-12) f = 1.0;
+ if (ctx->_NeedEyeCoords)
+ ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f);
+ else
+ ctx->_ModelViewInvScale = (GLfloat) SQRTF(f);
+ }
+}
+
+
+/**
+ * Bring up to date any state that relies on _NeedEyeCoords.
+ */
+void
+_mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state )
+{
+ const GLuint oldneedeyecoords = ctx->_NeedEyeCoords;
+
+ (void) new_state;
+ ctx->_NeedEyeCoords = GL_FALSE;
+
+ if (ctx->_ForceEyeCoords ||
+ (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD) ||
+ ctx->Point._Attenuated ||
+ ctx->Light._NeedEyeCoords)
+ ctx->_NeedEyeCoords = GL_TRUE;
+
+ if (ctx->Light.Enabled &&
+ !_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top))
+ ctx->_NeedEyeCoords = GL_TRUE;
+
+ /* Check if the truth-value interpretations of the bitfields have
+ * changed:
+ */
+ if (oldneedeyecoords != ctx->_NeedEyeCoords) {
+ /* Recalculate all state that depends on _NeedEyeCoords.
+ */
+ update_modelview_scale(ctx);
+ compute_light_positions( ctx );
+
+ if (ctx->Driver.LightingSpaceChange)
+ ctx->Driver.LightingSpaceChange( ctx );
+ }
+ else {
+ GLuint new_state2 = ctx->NewState;
+
+ /* Recalculate that same state only if it has been invalidated
+ * by other statechanges.
+ */
+ if (new_state2 & _NEW_MODELVIEW)
+ update_modelview_scale(ctx);
+
+ if (new_state2 & (_NEW_LIGHT|_NEW_MODELVIEW))
+ compute_light_positions( ctx );
+ }
+}
+
+
+/**
+ * Drivers may need this if the hardware tnl unit doesn't support the
+ * light-in-modelspace optimization. It's also useful for debugging.
+ */
+void
+_mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag )
+{
+ ctx->_ForceEyeCoords = !flag;
+ ctx->NewState |= _NEW_POINT; /* one of the bits from
+ * _MESA_NEW_NEED_EYE_COORDS.
+ */
+}
+
+
+
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
+
+/**
+ * Initialize the n-th light data structure.
+ *
+ * \param l pointer to the gl_light structure to be initialized.
+ * \param n number of the light.
+ * \note The defaults for light 0 are different than the other lights.
+ */
+static void
+init_light( struct gl_light *l, GLuint n )
+{
+ make_empty_list( l );
+
+ ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
+ if (n==0) {
+ ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
+ ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
+ }
+ else {
+ ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
+ ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
+ }
+ ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
+ ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 );
+ l->SpotExponent = 0.0;
+ _mesa_invalidate_spot_exp_table( l );
+ l->SpotCutoff = 180.0;
+ l->_CosCutoffNeg = -1.0f;
+ l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
+ l->ConstantAttenuation = 1.0;
+ l->LinearAttenuation = 0.0;
+ l->QuadraticAttenuation = 0.0;
+ l->Enabled = GL_FALSE;
+}
+
+
+/**
+ * Initialize the light model data structure.
+ *
+ * \param lm pointer to the gl_lightmodel structure to be initialized.
+ */
+static void
+init_lightmodel( struct gl_lightmodel *lm )
+{
+ ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
+ lm->LocalViewer = GL_FALSE;
+ lm->TwoSide = GL_FALSE;
+ lm->ColorControl = GL_SINGLE_COLOR;
+}
+
+
+/**
+ * Initialize the material data structure.
+ *
+ * \param m pointer to the gl_material structure to be initialized.
+ */
+static void
+init_material( struct gl_material *m )
+{
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
+
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
+}
+
+
+/**
+ * Initialize all lighting state for the given context.
+ */
+void
+_mesa_init_lighting( struct gl_context *ctx )
+{
+ GLuint i;
+
+ /* Lighting group */
+ for (i = 0; i < MAX_LIGHTS; i++) {
+ init_light( &ctx->Light.Light[i], i );
+ }
+ make_empty_list( &ctx->Light.EnabledList );
+
+ init_lightmodel( &ctx->Light.Model );
+ init_material( &ctx->Light.Material );
+ ctx->Light.ShadeModel = GL_SMOOTH;
+ ctx->Light.ProvokingVertex = GL_LAST_VERTEX_CONVENTION_EXT;
+ ctx->Light.Enabled = GL_FALSE;
+ ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
+ ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
+ ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
+ GL_FRONT_AND_BACK,
+ GL_AMBIENT_AND_DIFFUSE, ~0,
+ NULL );
+
+ ctx->Light.ColorMaterialEnabled = GL_FALSE;
+ ctx->Light.ClampVertexColor = GL_TRUE;
+
+ /* Lighting miscellaneous */
+ ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
+ make_empty_list( ctx->_ShineTabList );
+ /* Allocate 10 (arbitrary) shininess lookup tables */
+ for (i = 0 ; i < 10 ; i++) {
+ struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
+ s->shininess = -1;
+ s->refcount = 0;
+ insert_at_tail( ctx->_ShineTabList, s );
+ }
+
+ /* Miscellaneous */
+ ctx->Light._NeedEyeCoords = GL_FALSE;
+ ctx->_NeedEyeCoords = GL_FALSE;
+ ctx->_ForceEyeCoords = GL_FALSE;
+ ctx->_ModelViewInvScale = 1.0;
+}
+
+
+/**
+ * Deallocate malloc'd lighting state attached to given context.
+ */
+void
+_mesa_free_lighting_data( struct gl_context *ctx )
+{
+ struct gl_shine_tab *s, *tmps;
+
+ /* Free lighting shininess exponentiation table */
+ foreach_s( s, tmps, ctx->_ShineTabList ) {
+ free( s );
+ }
+ free( ctx->_ShineTabList );
+}
diff --git a/mesalib/src/mesa/main/macros.h b/mesalib/src/mesa/main/macros.h
index 2a849e36a..dbe5b867c 100644
--- a/mesalib/src/mesa/main/macros.h
+++ b/mesalib/src/mesa/main/macros.h
@@ -54,6 +54,10 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
#define FLOAT_TO_BYTE(X) ( (((GLint) (255.0F * (X))) - 1) / 2 )
+/** Convert GLbyte to GLfloat while preserving zero */
+#define BYTE_TO_FLOATZ(B) ((B) == 0 ? 0.0F : BYTE_TO_FLOAT(B))
+
+
/** Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0], texture/fb data */
#define BYTE_TO_FLOAT_TEX(B) ((B) == -128 ? -1.0F : (B) * (1.0F/127.0F))
@@ -73,6 +77,9 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
/** Convert GLfloat in [-1.0,1.0] to GLshort in [-32768,32767] */
#define FLOAT_TO_SHORT(X) ( (((GLint) (65535.0F * (X))) - 1) / 2 )
+/** Convert GLshort to GLfloat while preserving zero */
+#define SHORT_TO_FLOATZ(S) ((S) == 0 ? 0.0F : SHORT_TO_FLOAT(S))
+
/** Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0], texture/fb data */
#define SHORT_TO_FLOAT_TEX(S) ((S) == -32768 ? -1.0F : (S) * (1.0F/32767.0F))
@@ -588,19 +595,6 @@ do { \
*/
#define LINTERP(T, OUT, IN) ((OUT) + (T) * ((IN) - (OUT)))
-/* Can do better with integer math
- */
-#define INTERP_UB( t, dstub, outub, inub ) \
-do { \
- GLfloat inf = UBYTE_TO_FLOAT( inub ); \
- GLfloat outf = UBYTE_TO_FLOAT( outub ); \
- GLfloat dstf = LINTERP( t, outf, inf ); \
- UNCLAMPED_FLOAT_TO_UBYTE( dstub, dstf ); \
-} while (0)
-
-#define INTERP_UI( t, dstui, outui, inui ) \
- dstui = (GLuint) (GLint) LINTERP( (t), (GLfloat) (outui), (GLfloat) (inui) )
-
#define INTERP_F( t, dstf, outf, inf ) \
dstf = LINTERP( t, outf, inf )
@@ -619,16 +613,6 @@ do { \
dst[2] = LINTERP( (t), (out)[2], (in)[2] ); \
} while (0)
-#define INTERP_SZ( t, vec, to, out, in, sz ) \
-do { \
- switch (sz) { \
- case 4: vec[to][3] = LINTERP( (t), (vec)[out][3], (vec)[in][3] ); \
- case 3: vec[to][2] = LINTERP( (t), (vec)[out][2], (vec)[in][2] ); \
- case 2: vec[to][1] = LINTERP( (t), (vec)[out][1], (vec)[in][1] ); \
- case 1: vec[to][0] = LINTERP( (t), (vec)[out][0], (vec)[in][0] ); \
- } \
-} while(0)
-
/*@}*/
@@ -656,9 +640,6 @@ do { \
#define DOT4( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + \
(a)[2]*(b)[2] + (a)[3]*(b)[3] )
-/** Dot product of two 4-element vectors */
-#define DOT4V(v,a,b,c,d) (v[0]*(a) + v[1]*(b) + v[2]*(c) + v[3]*(d))
-
/** Cross product of two 3-element vectors */
#define CROSS3(n, u, v) \
@@ -688,6 +669,10 @@ do { \
#define LEN_SQUARED_2FV( V ) ((V)[0]*(V)[0]+(V)[1]*(V)[1])
+/** Compute ceiling of integer quotient of A divided by B. */
+#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
+
+
/** casts to silence warnings with some compilers */
#define ENUM_TO_INT(E) ((GLint)(E))
#define ENUM_TO_FLOAT(E) ((GLfloat)(GLint)(E))
diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h
index deab97d3e..285ec0783 100644
--- a/mesalib/src/mesa/main/mtypes.h
+++ b/mesalib/src/mesa/main/mtypes.h
@@ -49,18 +49,6 @@ extern "C" {
/**
- * Stencil buffer data type.
- */
-#if STENCIL_BITS==8
- typedef GLubyte GLstencil;
-#elif STENCIL_BITS==16
- typedef GLushort GLstencil;
-#else
-# error "illegal number of stencil bits"
-#endif
-
-
-/**
* \name 64-bit extension of GLbitfield.
*/
/*@{*/
@@ -2158,6 +2146,16 @@ struct gl_shader
unsigned Version; /**< GLSL version used for linking */
+ unsigned num_samplers; /**< Number of samplers used by this shader.
+ * This field is only set post-linking.
+ */
+ /**
+ * Number of uniform components used by this shader.
+ *
+ * This field is only set post-linking.
+ */
+ unsigned num_uniform_components;
+
struct exec_list *ir;
struct glsl_symbol_table *symbols;
diff --git a/mesalib/src/mesa/main/pack.c b/mesalib/src/mesa/main/pack.c
index 539a06c9a..6f48a2e7c 100644
--- a/mesalib/src/mesa/main/pack.c
+++ b/mesalib/src/mesa/main/pack.c
@@ -34,6 +34,7 @@
#include "enums.h"
#include "image.h"
#include "imports.h"
+#include "macros.h"
#include "mtypes.h"
#include "pack.h"
#include "pixeltransfer.h"
@@ -43,26 +44,6 @@
/**
- * NOTE:
- * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
- * we later convert the float to a packed integer value (such as for
- * GL_RGB5_A1) because we'll wind up with a non-zero value.
- *
- * We redefine the macros here so zero is handled correctly.
- */
-#undef BYTE_TO_FLOAT
-#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
-
-#undef SHORT_TO_FLOAT
-#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
-
-
-
-/** Compute ceiling of integer quotient of A divided by B. */
-#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
-
-
-/**
* Flip the 8 bits in each byte of the given array.
*
* \param p array.
@@ -2507,10 +2488,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
PROCESS(aSrc, ACOMP, 1.0F, 255, GLubyte, UBYTE_TO_FLOAT);
break;
case GL_BYTE:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOAT);
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
+ PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOATZ);
break;
case GL_UNSIGNED_SHORT:
PROCESS(rSrc, RCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
@@ -2519,10 +2500,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
PROCESS(aSrc, ACOMP, 1.0F, 0xffff, GLushort, USHORT_TO_FLOAT);
break;
case GL_SHORT:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOAT);
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
+ PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOATZ);
break;
case GL_UNSIGNED_INT:
PROCESS(rSrc, RCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
@@ -4586,10 +4567,10 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
void
_mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest, const GLstencil *source,
+ GLenum dstType, GLvoid *dest, const GLubyte *source,
const struct gl_pixelstore_attrib *dstPacking )
{
- GLstencil *stencil = (GLstencil *) malloc(n * sizeof(GLstencil));
+ GLubyte *stencil = (GLubyte *) malloc(n * sizeof(GLubyte));
if (!stencil) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil packing");
@@ -4599,23 +4580,14 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset ||
ctx->Pixel.MapStencilFlag) {
/* make a copy of input */
- memcpy(stencil, source, n * sizeof(GLstencil));
+ memcpy(stencil, source, n * sizeof(GLubyte));
_mesa_apply_stencil_transfer_ops(ctx, n, stencil);
source = stencil;
}
switch (dstType) {
case GL_UNSIGNED_BYTE:
- if (sizeof(GLstencil) == 1) {
- memcpy( dest, source, n );
- }
- else {
- GLubyte *dst = (GLubyte *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLubyte) source[i];
- }
- }
+ memcpy(dest, source, n);
break;
case GL_BYTE:
{
@@ -4834,14 +4806,14 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
*/
switch (srcType) {
case GL_BYTE:
- DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT);
+ DEPTH_VALUES(GLbyte, BYTE_TO_FLOATZ);
needClamp = GL_TRUE;
break;
case GL_UNSIGNED_BYTE:
DEPTH_VALUES(GLubyte, UBYTE_TO_FLOAT);
break;
case GL_SHORT:
- DEPTH_VALUES(GLshort, SHORT_TO_FLOAT);
+ DEPTH_VALUES(GLshort, SHORT_TO_FLOATZ);
needClamp = GL_TRUE;
break;
case GL_UNSIGNED_SHORT:
@@ -5120,11 +5092,11 @@ void
_mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
GLenum dstType, GLuint *dest,
const GLfloat *depthVals,
- const GLstencil *stencilVals,
+ const GLubyte *stencilVals,
const struct gl_pixelstore_attrib *dstPacking)
{
GLfloat *depthCopy = (GLfloat *) malloc(n * sizeof(GLfloat));
- GLstencil *stencilCopy = (GLstencil *) malloc(n * sizeof(GLstencil));
+ GLubyte *stencilCopy = (GLubyte *) malloc(n * sizeof(GLubyte));
GLuint i;
if (!depthCopy || !stencilCopy) {
@@ -5143,7 +5115,7 @@ _mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
if (ctx->Pixel.IndexShift ||
ctx->Pixel.IndexOffset ||
ctx->Pixel.MapStencilFlag) {
- memcpy(stencilCopy, stencilVals, n * sizeof(GLstencil));
+ memcpy(stencilCopy, stencilVals, n * sizeof(GLubyte));
_mesa_apply_stencil_transfer_ops(ctx, n, stencilCopy);
stencilVals = stencilCopy;
}
diff --git a/mesalib/src/mesa/main/pack.h b/mesalib/src/mesa/main/pack.h
index 7a0089c2f..b1853cd59 100644
--- a/mesalib/src/mesa/main/pack.h
+++ b/mesalib/src/mesa/main/pack.h
@@ -113,7 +113,7 @@ _mesa_unpack_stencil_span(struct gl_context *ctx, GLuint n,
extern void
_mesa_pack_stencil_span(struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest, const GLstencil *source,
+ GLenum dstType, GLvoid *dest, const GLubyte *source,
const struct gl_pixelstore_attrib *dstPacking);
@@ -133,7 +133,7 @@ extern void
_mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
GLenum dstType, GLuint *dest,
const GLfloat *depthVals,
- const GLstencil *stencilVals,
+ const GLubyte *stencilVals,
const struct gl_pixelstore_attrib *dstPacking);
diff --git a/mesalib/src/mesa/main/pixeltransfer.c b/mesalib/src/mesa/main/pixeltransfer.c
index 5e881436a..5c167e0a9 100644
--- a/mesalib/src/mesa/main/pixeltransfer.c
+++ b/mesalib/src/mesa/main/pixeltransfer.c
@@ -273,7 +273,7 @@ _mesa_apply_ci_transfer_ops(const struct gl_context *ctx,
*/
void
_mesa_apply_stencil_transfer_ops(const struct gl_context *ctx, GLuint n,
- GLstencil stencil[])
+ GLubyte stencil[])
{
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset != 0) {
const GLint offset = ctx->Pixel.IndexOffset;
@@ -300,7 +300,7 @@ _mesa_apply_stencil_transfer_ops(const struct gl_context *ctx, GLuint n,
GLuint mask = ctx->PixelMaps.StoS.Size - 1;
GLuint i;
for (i = 0; i < n; i++) {
- stencil[i] = (GLstencil)ctx->PixelMaps.StoS.Map[ stencil[i] & mask ];
+ stencil[i] = (GLubyte) ctx->PixelMaps.StoS.Map[ stencil[i] & mask ];
}
}
}
diff --git a/mesalib/src/mesa/main/pixeltransfer.h b/mesalib/src/mesa/main/pixeltransfer.h
index 8af2e9ee2..a8c14757f 100644
--- a/mesalib/src/mesa/main/pixeltransfer.h
+++ b/mesalib/src/mesa/main/pixeltransfer.h
@@ -75,7 +75,7 @@ _mesa_apply_ci_transfer_ops(const struct gl_context *ctx,
extern void
_mesa_apply_stencil_transfer_ops(const struct gl_context *ctx, GLuint n,
- GLstencil stencil[]);
+ GLubyte stencil[]);
#endif
diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c
index 84c5b2228..86b87534d 100644
--- a/mesalib/src/mesa/main/readpix.c
+++ b/mesalib/src/mesa/main/readpix.c
@@ -30,13 +30,509 @@
#include "readpix.h"
#include "framebuffer.h"
#include "formats.h"
+#include "format_unpack.h"
#include "image.h"
#include "mtypes.h"
+#include "pack.h"
#include "pbo.h"
#include "state.h"
/**
+ * Tries to implement glReadPixels() of GL_DEPTH_COMPONENT using memcpy of the
+ * mapping.
+ */
+static GLboolean
+fast_read_depth_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ GLubyte *map, *dst;
+ int stride, dstStride, j;
+
+ if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0)
+ return GL_FALSE;
+
+ if (packing->SwapBytes)
+ return GL_FALSE;
+
+ if (_mesa_get_format_datatype(rb->Format) != GL_UNSIGNED_INT)
+ return GL_FALSE;
+
+ if (!((type == GL_UNSIGNED_SHORT && rb->Format == MESA_FORMAT_Z16) ||
+ type == GL_UNSIGNED_INT))
+ return GL_FALSE;
+
+ ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
+ &map, &stride);
+
+ dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type);
+ dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, 0, 0);
+
+ for (j = 0; j < height; j++) {
+ if (type == GL_UNSIGNED_INT) {
+ _mesa_unpack_uint_z_row(rb->Format, width, map, (GLuint *)dst);
+ } else {
+ ASSERT(type == GL_UNSIGNED_SHORT && rb->Format == MESA_FORMAT_Z16);
+ memcpy(dst, map, width * 2);
+ }
+
+ map += stride;
+ dst += dstStride;
+ }
+ ctx->Driver.UnmapRenderbuffer(ctx, rb);
+
+ return GL_TRUE;
+}
+
+/**
+ * Read pixels for format=GL_DEPTH_COMPONENT.
+ */
+static void
+read_depth_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ GLint j;
+ GLubyte *dst, *map;
+ int dstStride, stride;
+
+ if (!rb)
+ return;
+
+ /* clipping should have been done already */
+ ASSERT(x >= 0);
+ ASSERT(y >= 0);
+ ASSERT(x + width <= (GLint) rb->Width);
+ ASSERT(y + height <= (GLint) rb->Height);
+ /* width should never be > MAX_WIDTH since we did clipping earlier */
+ ASSERT(width <= MAX_WIDTH);
+
+ if (fast_read_depth_pixels(ctx, x, y, width, height, type, pixels, packing))
+ return;
+
+ dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type);
+ dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, 0, 0);
+
+ ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
+ &map, &stride);
+
+ /* General case (slower) */
+ for (j = 0; j < height; j++, y++) {
+ GLfloat depthValues[MAX_WIDTH];
+ _mesa_unpack_float_z_row(rb->Format, width, map, depthValues);
+ _mesa_pack_depth_span(ctx, width, dst, type, depthValues, packing);
+
+ dst += dstStride;
+ map += stride;
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, rb);
+}
+
+
+/**
+ * Read pixels for format=GL_STENCIL_INDEX.
+ */
+static void
+read_stencil_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+ GLint j;
+ GLubyte *map;
+ GLint stride;
+
+ if (!rb)
+ return;
+
+ /* width should never be > MAX_WIDTH since we did clipping earlier */
+ ASSERT(width <= MAX_WIDTH);
+
+ ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
+ &map, &stride);
+
+ /* process image row by row */
+ for (j = 0; j < height; j++) {
+ GLvoid *dest;
+ GLubyte stencil[MAX_WIDTH];
+
+ _mesa_unpack_ubyte_stencil_row(rb->Format, width, map, stencil);
+ dest = _mesa_image_address2d(packing, pixels, width, height,
+ GL_STENCIL_INDEX, type, j, 0);
+
+ _mesa_pack_stencil_span(ctx, width, type, dest, stencil, packing);
+
+ map += stride;
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, rb);
+}
+
+static GLboolean
+fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ GLbitfield transferOps )
+{
+ struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
+ GLubyte *dst, *map;
+ int dstStride, stride, j, texelBytes;
+
+ if (!_mesa_format_matches_format_and_type(rb->Format, format, type))
+ return GL_FALSE;
+
+ /* check for things we can't handle here */
+ if (packing->SwapBytes ||
+ packing->LsbFirst) {
+ return GL_FALSE;
+ }
+
+ dstStride = _mesa_image_row_stride(packing, width, format, type);
+ dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
+ format, type, 0, 0);
+
+ ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
+ &map, &stride);
+
+ texelBytes = _mesa_get_format_bytes(rb->Format);
+ for (j = 0; j < height; j++) {
+ memcpy(dst, map, width * texelBytes);
+ dst += dstStride;
+ map += stride;
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, rb);
+
+ return GL_TRUE;
+}
+
+static GLboolean
+slow_read_rgba_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ GLbitfield transferOps )
+{
+ struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
+ const gl_format rbFormat = _mesa_get_srgb_format_linear(rb->Format);
+ union {
+ float f[MAX_WIDTH][4];
+ unsigned int i[MAX_WIDTH][4];
+ } rgba;
+ GLubyte *dst, *map;
+ int dstStride, stride, j;
+
+ dstStride = _mesa_image_row_stride(packing, width, format, type);
+ dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
+ format, type, 0, 0);
+
+ ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
+ &map, &stride);
+
+ for (j = 0; j < height; j++) {
+ if (_mesa_is_integer_format(format)) {
+ _mesa_unpack_int_rgba_row(rbFormat, width, map, rgba.i);
+ _mesa_pack_rgba_span_int(ctx, width, rgba.i, format, type, dst);
+ } else {
+ _mesa_unpack_rgba_row(rbFormat, width, map, rgba.f);
+ _mesa_pack_rgba_span_float(ctx, width, rgba.f, format, type, dst,
+ packing, transferOps);
+ }
+ dst += dstStride;
+ map += stride;
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, rb);
+
+ return GL_TRUE;
+}
+
+/*
+ * Read R, G, B, A, RGB, L, or LA pixels.
+ */
+static void
+read_rgba_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ GLbitfield transferOps = ctx->_ImageTransferState;
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->_ColorReadBuffer;
+
+ if (!rb)
+ return;
+
+ if ((ctx->Color._ClampReadColor == GL_TRUE || type != GL_FLOAT) &&
+ !_mesa_is_integer_format(format)) {
+ transferOps |= IMAGE_CLAMP_BIT;
+ }
+
+ if (!transferOps) {
+ /* Try the optimized paths first. */
+ if (fast_read_rgba_pixels_memcpy(ctx, x, y, width, height,
+ format, type, pixels, packing,
+ transferOps)) {
+ return;
+ }
+ }
+
+ slow_read_rgba_pixels(ctx, x, y, width, height,
+ format, type, pixels, packing, transferOps);
+}
+
+/**
+ * For a packed depth/stencil buffer being read as depth/stencil, just memcpy the
+ * data (possibly swapping 8/24 vs 24/8 as we go).
+ */
+static GLboolean
+fast_read_depth_stencil_pixels(struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLubyte *dst, int dstStride)
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+ GLubyte *map;
+ int stride, i;
+
+ if (rb != stencilRb)
+ return GL_FALSE;
+
+ if (rb->Format != MESA_FORMAT_Z24_S8 &&
+ rb->Format != MESA_FORMAT_S8_Z24)
+ return GL_FALSE;
+
+ ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
+ &map, &stride);
+
+ for (i = 0; i < height; i++) {
+ _mesa_unpack_uint_24_8_depth_stencil_row(rb->Format, width,
+ map, (GLuint *)dst);
+ map += stride;
+ dst += dstStride;
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, rb);
+
+ return GL_TRUE;
+}
+
+
+/**
+ * For non-float-depth and stencil buffers being read as 24/8 depth/stencil,
+ * copy the integer data directly instead of converting depth to float and
+ * re-packing.
+ */
+static GLboolean
+fast_read_depth_stencil_pixels_separate(struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ uint32_t *dst, int dstStride)
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+ GLubyte *depthMap, *stencilMap;
+ int depthStride, stencilStride, i, j;
+
+ if (_mesa_get_format_datatype(depthRb->Format) != GL_UNSIGNED_INT)
+ return GL_FALSE;
+
+ ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height,
+ GL_MAP_READ_BIT, &depthMap, &depthStride);
+ ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height,
+ GL_MAP_READ_BIT, &stencilMap, &stencilStride);
+
+ for (j = 0; j < height; j++) {
+ GLubyte stencilVals[MAX_WIDTH];
+
+ _mesa_unpack_uint_z_row(depthRb->Format, width, depthMap, dst);
+ _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width,
+ stencilMap, stencilVals);
+
+ for (i = 0; i < width; i++) {
+ dst[i] = (dst[i] & 0xffffff00) | stencilVals[i];
+ }
+
+ depthMap += depthStride;
+ stencilMap += stencilStride;
+ dst += dstStride / 4;
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
+ ctx->Driver.UnmapRenderbuffer(ctx, stencilRb);
+
+ return GL_TRUE;
+}
+
+static void
+slow_read_depth_stencil_pixels_separate(struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type,
+ const struct gl_pixelstore_attrib *packing,
+ GLubyte *dst, int dstStride)
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+ GLubyte *depthMap, *stencilMap;
+ int depthStride, stencilStride, j;
+
+ /* The depth and stencil buffers might be separate, or a single buffer.
+ * If one buffer, only map it once.
+ */
+ ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height,
+ GL_MAP_READ_BIT, &depthMap, &depthStride);
+ if (stencilRb != depthRb) {
+ ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height,
+ GL_MAP_READ_BIT, &stencilMap,
+ &stencilStride);
+ }
+ else {
+ stencilMap = depthMap;
+ stencilStride = depthStride;
+ }
+
+ for (j = 0; j < height; j++) {
+ GLubyte stencilVals[MAX_WIDTH];
+ GLfloat depthVals[MAX_WIDTH];
+
+ _mesa_unpack_float_z_row(depthRb->Format, width, depthMap, depthVals);
+ _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width,
+ stencilMap, stencilVals);
+
+ _mesa_pack_depth_stencil_span(ctx, width, type, (GLuint *)dst,
+ depthVals, stencilVals, packing);
+
+ depthMap += depthStride;
+ stencilMap += stencilStride;
+ dst += dstStride;
+ }
+
+ ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
+ if (stencilRb != depthRb) {
+ ctx->Driver.UnmapRenderbuffer(ctx, stencilRb);
+ }
+}
+
+
+/**
+ * Read combined depth/stencil values.
+ * We'll have already done error checking to be sure the expected
+ * depth and stencil buffers really exist.
+ */
+static void
+read_depth_stencil_pixels(struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ const GLboolean scaleOrBias
+ = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
+ const GLboolean stencilTransfer = ctx->Pixel.IndexShift
+ || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
+ GLubyte *dst;
+ int dstStride;
+
+ dst = (GLubyte *) _mesa_image_address2d(packing, pixels,
+ width, height,
+ GL_DEPTH_STENCIL_EXT,
+ type, 0, 0);
+ dstStride = _mesa_image_row_stride(packing, width,
+ GL_DEPTH_STENCIL_EXT, type);
+
+ /* Fast 24/8 reads. */
+ if (type == GL_UNSIGNED_INT_24_8 &&
+ !scaleOrBias && !stencilTransfer && !packing->SwapBytes) {
+ if (fast_read_depth_stencil_pixels(ctx, x, y, width, height,
+ dst, dstStride))
+ return;
+
+ if (fast_read_depth_stencil_pixels_separate(ctx, x, y, width, height,
+ (uint32_t *)dst, dstStride))
+ return;
+ }
+
+ slow_read_depth_stencil_pixels_separate(ctx, x, y, width, height,
+ type, packing,
+ dst, dstStride);
+}
+
+
+
+/**
+ * Software fallback routine for ctx->Driver.ReadPixels().
+ * By time we get here, all error checking will have been done.
+ */
+void
+_mesa_readpixels(struct gl_context *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *packing,
+ GLvoid *pixels)
+{
+ struct gl_pixelstore_attrib clippedPacking = *packing;
+
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ /* Do all needed clipping here, so that we can forget about it later */
+ if (_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
+
+ pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
+
+ if (pixels) {
+ switch (format) {
+ case GL_STENCIL_INDEX:
+ read_stencil_pixels(ctx, x, y, width, height, type, pixels,
+ &clippedPacking);
+ break;
+ case GL_DEPTH_COMPONENT:
+ read_depth_pixels(ctx, x, y, width, height, type, pixels,
+ &clippedPacking);
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ read_depth_stencil_pixels(ctx, x, y, width, height, type, pixels,
+ &clippedPacking);
+ break;
+ default:
+ /* all other formats should be color formats */
+ read_rgba_pixels(ctx, x, y, width, height, format, type, pixels,
+ &clippedPacking);
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &clippedPacking);
+ }
+ }
+}
+
+
+/**
* Do error checking of the format/type parameters to glReadPixels and
* glDrawPixels.
* \param drawing if GL_TRUE do checking for DrawPixels, else do checking
diff --git a/mesalib/src/mesa/main/readpix.h b/mesalib/src/mesa/main/readpix.h
index f6bb3d6e2..6caaf3adc 100644
--- a/mesalib/src/mesa/main/readpix.h
+++ b/mesalib/src/mesa/main/readpix.h
@@ -30,11 +30,20 @@
#include "glheader.h"
struct gl_context;
+struct gl_pixelstore_attrib;
+
extern GLboolean
_mesa_error_check_format_type(struct gl_context *ctx, GLenum format, GLenum type,
GLboolean drawing);
+extern void
+_mesa_readpixels(struct gl_context *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *packing,
+ GLvoid *pixels);
+
extern void GLAPIENTRY
_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid *pixels );
diff --git a/mesalib/src/mesa/main/renderbuffer.c b/mesalib/src/mesa/main/renderbuffer.c
index 4415dbd4f..c9a16a989 100644
--- a/mesalib/src/mesa/main/renderbuffer.c
+++ b/mesalib/src/mesa/main/renderbuffer.c
@@ -28,11 +28,6 @@
* Also, routines for reading/writing software-based renderbuffer data as
* ubytes, ushorts, uints, etc.
*
- * The 'alpha8' renderbuffer is interesting. It's used to add a software-based
- * alpha channel to RGB renderbuffers. This is done by wrapping the RGB
- * renderbuffer with the alpha renderbuffer. We can do this because of the
- * OO-nature of renderbuffers.
- *
* Down the road we'll use this for run-time support of 8, 16 and 32-bit
* color channels. For example, Mesa may use 32-bit/float color channels
* internally (swrast) and use wrapper renderbuffers to convert 32-bit
@@ -1470,18 +1465,6 @@ _mesa_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
rb->PutMonoValues = put_mono_values_ushort4;
break;
-#if 0
- case MESA_FORMAT_A8:
- rb->DataType = GL_UNSIGNED_BYTE;
- rb->GetValues = get_values_alpha8;
- rb->PutRow = put_row_alpha8;
- rb->PutRowRGB = NULL;
- rb->PutMonoRow = put_mono_row_alpha8;
- rb->PutValues = put_values_alpha8;
- rb->PutMonoValues = put_mono_values_alpha8;
- break;
-#endif
-
case MESA_FORMAT_S8:
rb->DataType = GL_UNSIGNED_BYTE;
rb->GetValues = get_values_ubyte;
@@ -1639,11 +1622,6 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
/* for accum buffer */
rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
break;
-#if 0
- case GL_ALPHA8:
- rb->Format = MESA_FORMAT_A8;
- break;
-#endif
case GL_STENCIL_INDEX:
case GL_STENCIL_INDEX1_EXT:
case GL_STENCIL_INDEX4_EXT:
@@ -1754,236 +1732,6 @@ _mesa_unmap_soft_renderbuffer(struct gl_context *ctx,
}
-/**********************************************************************/
-/**********************************************************************/
-/**********************************************************************/
-
-
-/**
- * Here we utilize the gl_renderbuffer->Wrapper field to put an alpha
- * buffer wrapper around an existing RGB renderbuffer (hw or sw).
- *
- * When PutRow is called (for example), we store the alpha values in
- * this buffer, then pass on the PutRow call to the wrapped RGB
- * buffer.
- */
-
-
-static GLboolean
-alloc_storage_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb,
- GLenum internalFormat, GLuint width, GLuint height)
-{
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->Format == MESA_FORMAT_A8);
-
- /* first, pass the call to the wrapped RGB buffer */
- if (!arb->Wrapped->AllocStorage(ctx, arb->Wrapped, internalFormat,
- width, height)) {
- return GL_FALSE;
- }
-
- /* next, resize my alpha buffer */
- if (arb->Data) {
- free(arb->Data);
- }
-
- arb->Data = malloc(width * height * sizeof(GLubyte));
- if (arb->Data == NULL) {
- arb->Width = 0;
- arb->Height = 0;
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "software alpha buffer allocation");
- return GL_FALSE;
- }
-
- arb->Width = width;
- arb->Height = height;
- arb->RowStride = width;
-
- return GL_TRUE;
-}
-
-
-/**
- * Delete an alpha_renderbuffer object, as well as the wrapped RGB buffer.
- */
-static void
-delete_renderbuffer_alpha8(struct gl_renderbuffer *arb)
-{
- if (arb->Data) {
- free(arb->Data);
- }
- ASSERT(arb->Wrapped);
- ASSERT(arb != arb->Wrapped);
- arb->Wrapped->Delete(arb->Wrapped);
- arb->Wrapped = NULL;
- free(arb);
-}
-
-
-static void *
-get_pointer_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb,
- GLint x, GLint y)
-{
- return NULL; /* don't allow direct access! */
-}
-
-
-static void
-get_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count,
- GLint x, GLint y, void *values)
-{
- /* NOTE: 'values' is RGBA format! */
- const GLubyte *src = (const GLubyte *) arb->Data + y * arb->RowStride + x;
- GLubyte *dst = (GLubyte *) values;
- GLuint i;
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
- /* first, pass the call to the wrapped RGB buffer */
- arb->Wrapped->GetRow(ctx, arb->Wrapped, count, x, y, values);
- /* second, fill in alpha values from this buffer! */
- for (i = 0; i < count; i++) {
- dst[i * 4 + 3] = src[i];
- }
-}
-
-
-static void
-get_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count,
- const GLint x[], const GLint y[], void *values)
-{
- GLubyte *dst = (GLubyte *) values;
- GLuint i;
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
- /* first, pass the call to the wrapped RGB buffer */
- arb->Wrapped->GetValues(ctx, arb->Wrapped, count, x, y, values);
- /* second, fill in alpha values from this buffer! */
- for (i = 0; i < count; i++) {
- const GLubyte *src = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
- dst[i * 4 + 3] = *src;
- }
-}
-
-
-static void
-put_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
- GLuint i;
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
- /* first, pass the call to the wrapped RGB buffer */
- arb->Wrapped->PutRow(ctx, arb->Wrapped, count, x, y, values, mask);
- /* second, store alpha in our buffer */
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i] = src[i * 4 + 3];
- }
- }
-}
-
-
-static void
-put_row_rgb_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask)
-{
- const GLubyte *src = (const GLubyte *) values;
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
- GLuint i;
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
- /* first, pass the call to the wrapped RGB buffer */
- arb->Wrapped->PutRowRGB(ctx, arb->Wrapped, count, x, y, values, mask);
- /* second, store alpha in our buffer */
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst[i] = src[i * 4 + 3];
- }
- }
-}
-
-
-static void
-put_mono_row_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask)
-{
- const GLubyte val = ((const GLubyte *) value)[3];
- GLubyte *dst = (GLubyte *) arb->Data + y * arb->RowStride + x;
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
- /* first, pass the call to the wrapped RGB buffer */
- arb->Wrapped->PutMonoRow(ctx, arb->Wrapped, count, x, y, value, mask);
- /* second, store alpha in our buffer */
- if (mask) {
- GLuint i;
- for (i = 0; i < count; i++) {
- if (mask[i]) {
- dst[i] = val;
- }
- }
- }
- else {
- memset(dst, val, count);
- }
-}
-
-
-static void
-put_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb, GLuint count,
- const GLint x[], const GLint y[],
- const void *values, const GLubyte *mask)
-{
- const GLubyte *src = (const GLubyte *) values;
- GLuint i;
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
- /* first, pass the call to the wrapped RGB buffer */
- arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, values, mask);
- /* second, store alpha in our buffer */
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
- *dst = src[i * 4 + 3];
- }
- }
-}
-
-
-static void
-put_mono_values_alpha8(struct gl_context *ctx, struct gl_renderbuffer *arb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask)
-{
- const GLubyte val = ((const GLubyte *) value)[3];
- GLuint i;
- ASSERT(arb != arb->Wrapped);
- ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
- /* first, pass the call to the wrapped RGB buffer */
- arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, value, mask);
- /* second, store alpha in our buffer */
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->RowStride + x[i];
- *dst = val;
- }
- }
-}
-
-
-static void
-copy_buffer_alpha8(struct gl_renderbuffer* dst, struct gl_renderbuffer* src)
-{
- ASSERT(dst->Format == MESA_FORMAT_A8);
- ASSERT(src->Format == MESA_FORMAT_A8);
- ASSERT(dst->Width == src->Width);
- ASSERT(dst->Height == src->Height);
- ASSERT(dst->RowStride == src->RowStride);
-
- memcpy(dst->Data, src->Data, dst->RowStride * dst->Height * sizeof(GLubyte));
-}
-
/**********************************************************************/
/**********************************************************************/
@@ -2148,114 +1896,6 @@ _mesa_add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
/**
- * Add software-based alpha renderbuffers to the given framebuffer.
- * This is a helper routine for device drivers when creating a
- * window system framebuffer (not a user-created render/framebuffer).
- * Once this function is called, you can basically forget about this
- * renderbuffer; core Mesa will handle all the buffer management and
- * rendering!
- */
-GLboolean
-_mesa_add_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint alphaBits,
- GLboolean frontLeft, GLboolean backLeft,
- GLboolean frontRight, GLboolean backRight)
-{
- gl_buffer_index b;
-
- /* for window system framebuffers only! */
- assert(fb->Name == 0);
-
- if (alphaBits > 8) {
- _mesa_problem(ctx,
- "Unsupported bit depth in _mesa_add_alpha_renderbuffers");
- return GL_FALSE;
- }
-
- assert(MAX_COLOR_ATTACHMENTS >= 4);
-
- /* Wrap each of the RGB color buffers with an alpha renderbuffer.
- */
- for (b = BUFFER_FRONT_LEFT; b <= BUFFER_BACK_RIGHT; b++) {
- struct gl_renderbuffer *arb;
-
- if (b == BUFFER_FRONT_LEFT && !frontLeft)
- continue;
- else if (b == BUFFER_BACK_LEFT && !backLeft)
- continue;
- else if (b == BUFFER_FRONT_RIGHT && !frontRight)
- continue;
- else if (b == BUFFER_BACK_RIGHT && !backRight)
- continue;
-
- /* the RGB buffer to wrap must already exist!! */
- assert(fb->Attachment[b].Renderbuffer);
-
- /* only GLubyte supported for now */
- assert(fb->Attachment[b].Renderbuffer->DataType == GL_UNSIGNED_BYTE);
-
- /* allocate alpha renderbuffer */
- arb = _mesa_new_renderbuffer(ctx, 0);
- if (!arb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating alpha buffer");
- return GL_FALSE;
- }
-
- /* wrap the alpha renderbuffer around the RGB renderbuffer */
- arb->Wrapped = fb->Attachment[b].Renderbuffer;
-
- /* Set up my alphabuffer fields and plug in my functions.
- * The functions will put/get the alpha values from/to RGBA arrays
- * and then call the wrapped buffer's functions to handle the RGB
- * values.
- */
- arb->InternalFormat = arb->Wrapped->InternalFormat;
- arb->Format = MESA_FORMAT_A8;
- arb->DataType = arb->Wrapped->DataType;
- arb->AllocStorage = alloc_storage_alpha8;
- arb->Delete = delete_renderbuffer_alpha8;
- arb->GetPointer = get_pointer_alpha8;
- arb->GetRow = get_row_alpha8;
- arb->GetValues = get_values_alpha8;
- arb->PutRow = put_row_alpha8;
- arb->PutRowRGB = put_row_rgb_alpha8;
- arb->PutMonoRow = put_mono_row_alpha8;
- arb->PutValues = put_values_alpha8;
- arb->PutMonoValues = put_mono_values_alpha8;
-
- /* clear the pointer to avoid assertion/sanity check failure later */
- fb->Attachment[b].Renderbuffer = NULL;
-
- /* plug the alpha renderbuffer into the colorbuffer attachment */
- _mesa_add_renderbuffer(fb, b, arb);
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * For framebuffers that use a software alpha channel wrapper
- * created by _mesa_add_alpha_renderbuffer or _mesa_add_soft_renderbuffers,
- * copy the back buffer alpha channel into the front buffer alpha channel.
- */
-void
-_mesa_copy_soft_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- if (fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer &&
- fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer)
- copy_buffer_alpha8(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer,
- fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
-
-
- if (fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer &&
- fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer)
- copy_buffer_alpha8(fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer,
- fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer);
-}
-
-
-/**
* Add a software-based depth renderbuffer to the given framebuffer.
* This is a helper routine for device drivers when creating a
* window system framebuffer (not a user-created render/framebuffer).
@@ -2476,13 +2116,6 @@ _mesa_add_soft_renderbuffers(struct gl_framebuffer *fb,
fb->Visual.numAuxBuffers);
}
- if (alpha) {
- assert(fb->Visual.alphaBits > 0);
- _mesa_add_alpha_renderbuffers(NULL, fb, fb->Visual.alphaBits,
- frontLeft, backLeft,
- frontRight, backRight);
- }
-
#if 0
if (multisample) {
/* maybe someday */
diff --git a/mesalib/src/mesa/main/renderbuffer.h b/mesalib/src/mesa/main/renderbuffer.h
index cb0d712eb..3194fc3fe 100644
--- a/mesalib/src/mesa/main/renderbuffer.h
+++ b/mesalib/src/mesa/main/renderbuffer.h
@@ -73,15 +73,6 @@ _mesa_add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
GLboolean frontRight, GLboolean backRight);
extern GLboolean
-_mesa_add_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint alphaBits,
- GLboolean frontLeft, GLboolean backLeft,
- GLboolean frontRight, GLboolean backRight);
-
-extern void
-_mesa_copy_soft_alpha_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb);
-
-extern GLboolean
_mesa_add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
GLuint depthBits);
diff --git a/mesalib/src/mesa/main/uniform_query.cpp b/mesalib/src/mesa/main/uniform_query.cpp
index 5371d6a17..33ba53c2e 100644
--- a/mesalib/src/mesa/main/uniform_query.cpp
+++ b/mesalib/src/mesa/main/uniform_query.cpp
@@ -698,11 +698,27 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
prog = shProg->_LinkedShaders[i]->Program;
+ /* If the shader stage doesn't use any samplers, don't bother
+ * checking if any samplers have changed.
+ */
+ if (prog->SamplersUsed == 0)
+ continue;
+
assert(sizeof(prog->SamplerUnits) == sizeof(shProg->SamplerUnits));
- if (memcmp(prog->SamplerUnits,
- shProg->SamplerUnits,
- sizeof(shProg->SamplerUnits)) != 0) {
+ /* Determine if any of the samplers used by this shader stage have
+ * been modified.
+ */
+ bool changed = false;
+ for (unsigned j = 0; j < Elements(prog->SamplerUnits); j++) {
+ if ((prog->SamplersUsed & (1U << j)) != 0
+ && (prog->SamplerUnits[j] != shProg->SamplerUnits[j])) {
+ changed = true;
+ break;
+ }
+ }
+
+ if (changed) {
if (!flushed) {
FLUSH_VERTICES(ctx, _NEW_TEXTURE | _NEW_PROGRAM);
flushed = true;
diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp
index 1b8b48e53..5cee83778 100644
--- a/mesalib/src/mesa/program/ir_to_mesa.cpp
+++ b/mesalib/src/mesa/program/ir_to_mesa.cpp
@@ -2541,58 +2541,6 @@ count_resources(struct gl_program *prog)
_mesa_update_shader_textures_used(prog);
}
-
-/**
- * Check if the given vertex/fragment/shader program is within the
- * resource limits of the context (number of texture units, etc).
- * If any of those checks fail, record a linker error.
- *
- * XXX more checks are needed...
- */
-static bool
-check_resources(const struct gl_context *ctx,
- struct gl_shader_program *shader_program,
- struct gl_program *prog)
-{
- switch (prog->Target) {
- case GL_VERTEX_PROGRAM_ARB:
- if (_mesa_bitcount(prog->SamplersUsed) >
- ctx->Const.MaxVertexTextureImageUnits) {
- linker_error(shader_program,
- "Too many vertex shader texture samplers");
- }
- if (prog->Parameters->NumParameters > MAX_UNIFORMS) {
- linker_error(shader_program, "Too many vertex shader constants");
- }
- break;
- case MESA_GEOMETRY_PROGRAM:
- if (_mesa_bitcount(prog->SamplersUsed) >
- ctx->Const.MaxGeometryTextureImageUnits) {
- linker_error(shader_program,
- "Too many geometry shader texture samplers");
- }
- if (prog->Parameters->NumParameters >
- MAX_GEOMETRY_UNIFORM_COMPONENTS / 4) {
- linker_error(shader_program, "Too many geometry shader constants");
- }
- break;
- case GL_FRAGMENT_PROGRAM_ARB:
- if (_mesa_bitcount(prog->SamplersUsed) >
- ctx->Const.MaxTextureImageUnits) {
- linker_error(shader_program,
- "Too many fragment shader texture samplers");
- }
- if (prog->Parameters->NumParameters > MAX_UNIFORMS) {
- linker_error(shader_program, "Too many fragment shader constants");
- }
- break;
- default:
- _mesa_problem(ctx, "unexpected program type in check_resources()");
- }
-
- return shader_program->LinkStatus;
-}
-
class add_uniform_to_shader : public uniform_field_visitor {
public:
add_uniform_to_shader(struct gl_shader_program *shader_program,
@@ -3274,9 +3222,6 @@ get_mesa_program(struct gl_context *ctx,
do_set_program_inouts(shader->ir, prog, shader->Type == GL_FRAGMENT_SHADER);
count_resources(prog);
- if (!check_resources(ctx, shader_program, prog))
- goto fail_exit;
-
_mesa_reference_program(ctx, &shader->Program, prog);
if ((ctx->Shader.Flags & GLSL_NO_OPT) == 0) {
@@ -3513,7 +3458,9 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
}
}
- set_uniform_initializers(ctx, prog);
+ if (prog->LinkStatus) {
+ set_uniform_initializers(ctx, prog);
+ }
if (ctx->Shader.Flags & GLSL_DUMP) {
if (!prog->LinkStatus) {
diff --git a/mesalib/src/mesa/sources.mak b/mesalib/src/mesa/sources.mak
index 102562ace..e72a1ce1e 100644
--- a/mesalib/src/mesa/sources.mak
+++ b/mesalib/src/mesa/sources.mak
@@ -141,7 +141,6 @@ SWRAST_SOURCES = \
swrast/s_logic.c \
swrast/s_masking.c \
swrast/s_points.c \
- swrast/s_readpix.c \
swrast/s_span.c \
swrast/s_stencil.c \
swrast/s_texcombine.c \
diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
index 5714d343d..95805fd3c 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -38,6 +38,7 @@
#include "main/mtypes.h"
#include "main/pack.h"
#include "main/pbo.h"
+#include "main/readpix.h"
#include "main/texformat.h"
#include "main/teximage.h"
#include "main/texstore.h"
@@ -1189,9 +1190,9 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
rbDraw = st_renderbuffer(rbDraw->Base.Wrapped);
/* this will do stencil pixel transfer ops */
- st_read_stencil_pixels(ctx, srcx, srcy, width, height,
- GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
- &ctx->DefaultPacking, buffer);
+ _mesa_readpixels(ctx, srcx, srcy, width, height,
+ GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
+ &ctx->DefaultPacking, buffer);
if (0) {
/* debug code: dump stencil values */
@@ -1296,6 +1297,20 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
}
+/**
+ * Return renderbuffer to use for reading color pixels for glCopyPixels
+ */
+static struct st_renderbuffer *
+st_get_color_read_renderbuffer(struct gl_context *ctx)
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct st_renderbuffer *strb =
+ st_renderbuffer(fb->_ColorReadBuffer);
+
+ return strb;
+}
+
+
/** Do the src/dest regions overlap? */
static GLboolean
regions_overlap(GLint srcX, GLint srcY, GLint dstX, GLint dstY,
diff --git a/mesalib/src/mesa/state_tracker/st_cb_fbo.c b/mesalib/src/mesa/state_tracker/st_cb_fbo.c
index e04cb4406..a351d1197 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_fbo.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_fbo.c
@@ -355,8 +355,12 @@ st_render_texture(struct gl_context *ctx,
/* get pointer to texture image we're rendeing to */
texImage = _mesa_get_attachment_teximage(att);
- /* create new renderbuffer which wraps the texture image */
- rb = st_new_renderbuffer(ctx, 0);
+ /* create new renderbuffer which wraps the texture image.
+ * Use the texture's name as the renderbuffer's name so that we have
+ * something that's non-zero (to determine vertical orientation) and
+ * possibly helpful for debugging.
+ */
+ rb = st_new_renderbuffer(ctx, att->Texture->Name);
if (!rb) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");
return;
@@ -644,7 +648,9 @@ st_MapRenderbuffer(struct gl_context *ctx,
struct st_context *st = st_context(ctx);
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_context *pipe = st->pipe;
+ const GLboolean invert = rb->Name == 0;
unsigned usage;
+ GLuint y2;
usage = 0x0;
if (mode & GL_MAP_READ_BIT)
@@ -652,14 +658,30 @@ st_MapRenderbuffer(struct gl_context *ctx,
if (mode & GL_MAP_WRITE_BIT)
usage |= PIPE_TRANSFER_WRITE;
+ /* Note: y=0=bottom of buffer while y2=0=top of buffer.
+ * 'invert' will be true for window-system buffers and false for
+ * user-allocated renderbuffers and textures.
+ */
+ if (invert)
+ y2 = strb->Base.Height - y - h;
+ else
+ y2 = y;
+
strb->transfer = pipe_get_transfer(pipe,
strb->texture,
strb->rtt_level,
strb->rtt_face + strb->rtt_slice,
- usage, x, y, w, h);
+ usage, x, y2, w, h);
if (strb->transfer) {
- *mapOut = pipe_transfer_map(pipe, strb->transfer);
- *rowStrideOut = strb->transfer->stride;
+ GLubyte *map = pipe_transfer_map(pipe, strb->transfer);
+ if (invert) {
+ *rowStrideOut = -strb->transfer->stride;
+ map += (h - 1) * strb->transfer->stride;
+ }
+ else {
+ *rowStrideOut = strb->transfer->stride;
+ }
+ *mapOut = map;
}
else {
*mapOut = NULL;
diff --git a/mesalib/src/mesa/state_tracker/st_cb_readpixels.c b/mesalib/src/mesa/state_tracker/st_cb_readpixels.c
index bd73f3bf0..6b824b161 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_readpixels.c
@@ -26,649 +26,32 @@
**************************************************************************/
-/**
- * glReadPixels interface to pipe
- *
- * \author Brian Paul
- */
-
-
#include "main/imports.h"
-#include "main/bufferobj.h"
-#include "main/context.h"
-#include "main/image.h"
-#include "main/pack.h"
-#include "main/pbo.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_format.h"
-#include "util/u_inlines.h"
-#include "util/u_tile.h"
+#include "main/readpix.h"
-#include "st_debug.h"
-#include "st_context.h"
#include "st_atom.h"
+#include "st_context.h"
#include "st_cb_bitmap.h"
#include "st_cb_readpixels.h"
-#include "st_cb_fbo.h"
-
-/**
- * Special case for reading stencil buffer.
- * For color/depth we use get_tile(). For stencil, map the stencil buffer.
- */
-void
-st_read_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *packing,
- GLvoid *pixels)
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
- struct pipe_transfer *pt;
- ubyte *stmap;
- GLint j;
-
- if (strb->Base.Wrapped) {
- strb = st_renderbuffer(strb->Base.Wrapped);
- }
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- y = ctx->DrawBuffer->Height - y - height;
- }
-
- /* Create a read transfer from the renderbuffer's texture */
-
- pt = pipe_get_transfer(pipe, strb->texture,
- strb->rtt_level,
- strb->rtt_face + strb->rtt_slice,
- PIPE_TRANSFER_READ,
- x, y, width, height);
-
- /* map the stencil buffer */
- stmap = pipe_transfer_map(pipe, pt);
-
- /* width should never be > MAX_WIDTH since we did clipping earlier */
- ASSERT(width <= MAX_WIDTH);
-
- /* process image row by row */
- for (j = 0; j < height; j++) {
- GLvoid *dest;
- GLstencil sValues[MAX_WIDTH];
- GLfloat zValues[MAX_WIDTH];
- GLint srcY;
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- srcY = height - j - 1;
- }
- else {
- srcY = j;
- }
-
- /* get stencil (and Z) values */
- switch (pt->resource->format) {
- case PIPE_FORMAT_S8_UINT:
- {
- const ubyte *src = stmap + srcY * pt->stride;
- memcpy(sValues, src, width);
- }
- break;
- case PIPE_FORMAT_Z24_UNORM_S8_UINT:
- if (format == GL_DEPTH_STENCIL) {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- const GLfloat scale = 1.0f / (0xffffff);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] >> 24;
- zValues[k] = (src[k] & 0xffffff) * scale;
- }
- }
- else {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] >> 24;
- }
- }
- break;
- case PIPE_FORMAT_S8_UINT_Z24_UNORM:
- if (format == GL_DEPTH_STENCIL) {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- const GLfloat scale = 1.0f / (0xffffff);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] & 0xff;
- zValues[k] = (src[k] >> 8) * scale;
- }
- }
- else {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] & 0xff;
- }
- }
- break;
- case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
- if (format == GL_DEPTH_STENCIL) {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- const GLfloat *srcf = (const GLfloat*)src;
- GLint k;
- for (k = 0; k < width; k++) {
- zValues[k] = srcf[k*2];
- sValues[k] = src[k*2+1] & 0xff;
- }
- }
- else {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k*2+1] & 0xff;
- }
- }
- break;
- default:
- assert(0);
- }
-
- /* store */
- dest = _mesa_image_address2d(packing, pixels, width, height,
- format, type, j, 0);
- if (format == GL_DEPTH_STENCIL) {
- _mesa_pack_depth_stencil_span(ctx, width, type, dest,
- zValues, sValues, packing);
- }
- else {
- _mesa_pack_stencil_span(ctx, width, type, dest, sValues, packing);
- }
- }
-
- /* unmap the stencil buffer */
- pipe_transfer_unmap(pipe, pt);
- pipe->transfer_destroy(pipe, pt);
-}
-
-
-/**
- * Return renderbuffer to use for reading color pixels for glRead/CopyPixel
- * commands.
- */
-struct st_renderbuffer *
-st_get_color_read_renderbuffer(struct gl_context *ctx)
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct st_renderbuffer *strb =
- st_renderbuffer(fb->_ColorReadBuffer);
-
- return strb;
-}
-
-
-/**
- * Try to do glReadPixels in a fast manner for common cases.
- * \return GL_TRUE for success, GL_FALSE for failure
- */
-static GLboolean
-st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *pack,
- GLvoid *dest)
-{
- GLubyte alphaORoperand;
- enum combination {
- A8R8G8B8_UNORM_TO_RGBA_UBYTE,
- A8R8G8B8_UNORM_TO_RGB_UBYTE,
- A8R8G8B8_UNORM_TO_BGRA_UINT,
- A8R8G8B8_UNORM_TO_RGBA_UINT
- } combo;
-
- if (ctx->_ImageTransferState)
- return GL_FALSE;
-
- if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM) {
- alphaORoperand = 0;
- }
- else if (strb->format == PIPE_FORMAT_B8G8R8X8_UNORM ) {
- alphaORoperand = 0xff;
- }
- else {
- return GL_FALSE;
- }
-
- if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
- combo = A8R8G8B8_UNORM_TO_RGBA_UBYTE;
- }
- else if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
- combo = A8R8G8B8_UNORM_TO_RGB_UBYTE;
- }
- else if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) {
- combo = A8R8G8B8_UNORM_TO_BGRA_UINT;
- }
- else if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8) {
- combo = A8R8G8B8_UNORM_TO_RGBA_UINT;
- }
- else {
- return GL_FALSE;
- }
-
- /*printf("st_fast_readpixels combo %d\n", (GLint) combo);*/
-
- {
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct pipe_transfer *trans;
- const GLubyte *map;
- GLubyte *dst;
- GLint row, col, dy, dstStride;
-
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- /* convert GL Y to Gallium Y */
- y = strb->texture->height0 - y - height;
- }
-
- trans = pipe_get_transfer(pipe, strb->texture,
- strb->rtt_level,
- strb->rtt_face + strb->rtt_slice,
- PIPE_TRANSFER_READ,
- x, y, width, height);
- if (!trans) {
- return GL_FALSE;
- }
-
- map = pipe_transfer_map(pipe, trans);
- if (!map) {
- pipe->transfer_destroy(pipe, trans);
- return GL_FALSE;
- }
-
- /* We always write to the user/dest buffer from low addr to high addr
- * but the read order depends on renderbuffer orientation
- */
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- /* read source rows from bottom to top */
- y = height - 1;
- dy = -1;
- }
- else {
- /* read source rows from top to bottom */
- y = 0;
- dy = 1;
- }
-
- dst = _mesa_image_address2d(pack, dest, width, height,
- format, type, 0, 0);
- dstStride = _mesa_image_row_stride(pack, width, format, type);
-
- switch (combo) {
- case A8R8G8B8_UNORM_TO_RGBA_UBYTE:
- for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * trans->stride;
- for (col = 0; col < width; col++) {
- GLuint pixel = ((GLuint *) src)[col];
- dst[col*4+0] = (pixel >> 16) & 0xff;
- dst[col*4+1] = (pixel >> 8) & 0xff;
- dst[col*4+2] = (pixel >> 0) & 0xff;
- dst[col*4+3] = ((pixel >> 24) & 0xff) | alphaORoperand;
- }
- dst += dstStride;
- y += dy;
- }
- break;
- case A8R8G8B8_UNORM_TO_RGB_UBYTE:
- for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * trans->stride;
- for (col = 0; col < width; col++) {
- GLuint pixel = ((GLuint *) src)[col];
- dst[col*3+0] = (pixel >> 16) & 0xff;
- dst[col*3+1] = (pixel >> 8) & 0xff;
- dst[col*3+2] = (pixel >> 0) & 0xff;
- }
- dst += dstStride;
- y += dy;
- }
- break;
- case A8R8G8B8_UNORM_TO_BGRA_UINT:
- for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * trans->stride;
- memcpy(dst, src, 4 * width);
- if (alphaORoperand) {
- assert(alphaORoperand == 0xff);
- for (col = 0; col < width; col++) {
- dst[col*4+3] = 0xff;
- }
- }
- dst += dstStride;
- y += dy;
- }
- break;
- case A8R8G8B8_UNORM_TO_RGBA_UINT:
- for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * trans->stride;
- for (col = 0; col < width; col++) {
- GLuint pixel = ((GLuint *) src)[col];
- dst[col*4+0] = ((pixel >> 24) & 0xff) | alphaORoperand;
- dst[col*4+1] = (pixel >> 0) & 0xff;
- dst[col*4+2] = (pixel >> 8) & 0xff;
- dst[col*4+3] = (pixel >> 16) & 0xff;
- }
- dst += dstStride;
- y += dy;
- }
- break;
- default:
- ; /* nothing */
- }
-
- pipe_transfer_unmap(pipe, trans);
- pipe->transfer_destroy(pipe, trans);
- }
-
- return GL_TRUE;
-}
/**
- * Do glReadPixels by getting rows from the framebuffer transfer with
- * get_tile(). Convert to requested format/type with Mesa image routines.
- * Image transfer ops are done in software too.
+ * The only special thing we need to do for the state tracker's
+ * glReadPixels is to validate state (to be sure we have up-to-date
+ * framebuffer surfaces) and flush the bitmap cache prior to reading.
*/
static void
-st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
+st_readpixels(struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *pack,
GLvoid *dest)
{
struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- GLfloat (*temp)[4];
- GLbitfield transferOps = ctx->_ImageTransferState;
- GLsizei i, j;
- GLint yStep, dfStride;
- GLfloat *df;
- GLuint *dui;
- GLint *di;
- struct st_renderbuffer *strb;
- struct gl_pixelstore_attrib clippedPacking = *pack;
- struct pipe_transfer *trans;
- enum pipe_format pformat;
-
- assert(ctx->ReadBuffer->Width > 0);
st_validate_state(st);
-
- /* Do all needed clipping here, so that we can forget about it later */
- if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
- /* The ReadPixels transfer is totally outside the window bounds */
- return;
- }
-
st_flush_bitmap_cache(st);
-
- dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest);
- if (!dest)
- return;
-
- if (format == GL_STENCIL_INDEX ||
- format == GL_DEPTH_STENCIL) {
- st_read_stencil_pixels(ctx, x, y, width, height,
- format, type, pack, dest);
- return;
- }
- else if (format == GL_DEPTH_COMPONENT) {
- strb = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
- if (strb->Base.Wrapped) {
- strb = st_renderbuffer(strb->Base.Wrapped);
- }
- }
- else {
- /* Read color buffer */
- strb = st_get_color_read_renderbuffer(ctx);
- }
-
- if (!strb)
- return;
-
- /* try a fast-path readpixels before anything else */
- if (st_fast_readpixels(ctx, strb, x, y, width, height,
- format, type, pack, dest)) {
- /* success! */
- _mesa_unmap_pbo_dest(ctx, &clippedPacking);
- return;
- }
-
- /* allocate temp pixel row buffer */
- temp = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
- if (!temp) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
- return;
- }
-
- if(ctx->Color._ClampReadColor)
- transferOps |= IMAGE_CLAMP_BIT;
-
- if (format == GL_RGBA && type == GL_FLOAT && !transferOps) {
- /* write tile(row) directly into user's buffer */
- df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width,
- height, format, type, 0, 0);
- dfStride = width * 4;
- }
- else {
- /* write tile(row) into temp row buffer */
- df = (GLfloat *)temp;
- dfStride = 0;
- }
-
- dui = (GLuint *)df;
- di = (GLint *)df;
-
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- /* convert GL Y to Gallium Y */
- y = strb->Base.Height - y - height;
- }
-
- /* Create a read transfer from the renderbuffer's texture */
- trans = pipe_get_transfer(pipe, strb->texture,
- strb->rtt_level, /* level */
- strb->rtt_face + strb->rtt_slice, /* layer */
- PIPE_TRANSFER_READ,
- x, y, width, height);
-
- /* determine bottom-to-top vs. top-to-bottom order */
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- y = height - 1;
- yStep = -1;
- }
- else {
- y = 0;
- yStep = 1;
- }
-
- /* possibly convert sRGB format to linear RGB format */
- pformat = util_format_linear(trans->resource->format);
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- /*
- * Copy pixels from pipe_transfer to user memory
- */
- {
- /* dest of first pixel in client memory */
- GLubyte *dst = _mesa_image_address2d(&clippedPacking, dest, width,
- height, format, type, 0, 0);
- /* dest row stride */
- const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
- format, type);
-
- if (pformat == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
- pformat == PIPE_FORMAT_Z24X8_UNORM) {
- if (format == GL_DEPTH_COMPONENT) {
- for (i = 0; i < height; i++) {
- GLuint ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / ((1 << 24) - 1);
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff));
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else {
- /* XXX: unreachable code -- should be before st_read_stencil_pixels */
- assert(format == GL_DEPTH_STENCIL_EXT);
- for (i = 0; i < height; i++) {
- GLuint *zshort = (GLuint *)dst;
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
- y += yStep;
- /* Reverse into 24/8 */
- for (j = 0; j < width; j++) {
- zshort[j] = (zshort[j] << 8) | (zshort[j] >> 24);
- }
- dst += dstStride;
- }
- }
- }
- else if (pformat == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
- pformat == PIPE_FORMAT_X8Z24_UNORM) {
- if (format == GL_DEPTH_COMPONENT) {
- for (i = 0; i < height; i++) {
- GLuint ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / ((1 << 24) - 1);
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff));
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else {
- /* XXX: unreachable code -- should be before st_read_stencil_pixels */
- assert(format == GL_DEPTH_STENCIL_EXT);
- for (i = 0; i < height; i++) {
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
- y += yStep;
- dst += dstStride;
- }
- }
- }
- else if (pformat == PIPE_FORMAT_Z16_UNORM) {
- for (i = 0; i < height; i++) {
- GLushort ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / 0xffff;
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * ztemp[j]);
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else if (pformat == PIPE_FORMAT_Z32_UNORM) {
- for (i = 0; i < height; i++) {
- GLuint ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / 0xffffffff;
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * ztemp[j]);
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else if (pformat == PIPE_FORMAT_Z32_FLOAT) {
- for (i = 0; i < height; i++) {
- GLfloat zfloat[MAX_WIDTH];
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, zfloat, 0);
- y += yStep;
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else if (pformat == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
- assert(format == GL_DEPTH_COMPONENT);
- for (i = 0; i < height; i++) {
- GLfloat zfloat[MAX_WIDTH]; /* Z32 */
- GLfloat zfloat2[MAX_WIDTH*2]; /* Z32X32 */
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, zfloat2, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = zfloat2[j*2];
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else if (util_format_is_pure_sint(pformat)) {
- for (i = 0; i < height; i++) {
- if (type == GL_UNSIGNED_INT)
- pipe_get_tile_ui_format(pipe, trans, 0, y, width, 1,
- pformat, dui);
- else
- pipe_get_tile_i_format(pipe, trans, 0, y, width, 1,
- pformat, di);
- y += yStep;
- if (!dfStride) {
- _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4])temp,
- format, type, dst);
- dst += dstStride;
- }
- }
- } else if (util_format_is_pure_uint(pformat)) {
- for (i = 0; i < height; i++) {
- if (type == GL_UNSIGNED_INT)
- pipe_get_tile_ui_format(pipe, trans, 0, y, width, 1,
- pformat, dui);
- else
- pipe_get_tile_i_format(pipe, trans, 0, y, width, 1,
- pformat, di);
- y += yStep;
- df += dfStride;
- if (!dfStride) {
- _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4])temp,
- format, type, dst);
- dst += dstStride;
- }
- }
- } else {
- /* RGBA format */
- /* Do a row at a time to flip image data vertically */
- for (i = 0; i < height; i++) {
- pipe_get_tile_rgba_format(pipe, trans, 0, y, width, 1,
- pformat, df);
- y += yStep;
- df += dfStride;
- if (!dfStride) {
- _mesa_pack_rgba_span_float(ctx, width, temp, format, type, dst,
- &clippedPacking, transferOps);
- dst += dstStride;
- }
- }
- }
- }
-
- free(temp);
-
- pipe->transfer_destroy(pipe, trans);
-
- _mesa_unmap_pbo_dest(ctx, &clippedPacking);
+ _mesa_readpixels(ctx, x, y, width, height, format, type, pack, dest);
}
diff --git a/mesalib/src/mesa/state_tracker/st_cb_readpixels.h b/mesalib/src/mesa/state_tracker/st_cb_readpixels.h
index fba1a6540..fdc854782 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_readpixels.h
+++ b/mesalib/src/mesa/state_tracker/st_cb_readpixels.h
@@ -1,52 +1,40 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 ST_CB_READPIXELS_H
-#define ST_CB_READPIXELS_H
-
-#include "main/glheader.h"
-
-struct dd_function_table;
-struct gl_context;
-struct gl_pixelstore_attrib;
-
-extern struct st_renderbuffer *
-st_get_color_read_renderbuffer(struct gl_context *ctx);
-
-extern void
-st_read_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *packing,
- GLvoid *pixels);
-
-extern void
-st_init_readpixels_functions(struct dd_function_table *functions);
-
-
-#endif /* ST_CB_READPIXELS_H */
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 ST_CB_READPIXELS_H
+#define ST_CB_READPIXELS_H
+
+#include "main/glheader.h"
+
+struct dd_function_table;
+
+extern void
+st_init_readpixels_functions(struct dd_function_table *functions);
+
+
+#endif /* ST_CB_READPIXELS_H */
diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c
index f2fbf4836..cb518e1af 100644
--- a/mesalib/src/mesa/state_tracker/st_draw.c
+++ b/mesalib/src/mesa/state_tracker/st_draw.c
@@ -436,8 +436,8 @@ setup_interleaved_attribs(struct gl_context *ctx,
/* all interleaved arrays in a VBO */
struct st_buffer_object *stobj = st_buffer_object(bufobj);
- if (!stobj) {
- /* probably out of memory */
+ if (!stobj || !stobj->buffer) {
+ /* probably out of memory (or zero-sized buffer) */
return GL_FALSE;
}
@@ -505,7 +505,7 @@ setup_non_interleaved_attribs(struct gl_context *ctx,
struct st_buffer_object *stobj = st_buffer_object(bufobj);
if (!stobj || !stobj->buffer) {
- /* probably ran out of memory */
+ /* probably out of memory (or zero-sized buffer) */
return GL_FALSE;
}
diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index b133164c3..0bf6766f7 100644
--- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2873,55 +2873,6 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog)
_mesa_update_shader_textures_used(prog);
}
-
-/**
- * Check if the given vertex/fragment/shader program is within the
- * resource limits of the context (number of texture units, etc).
- * If any of those checks fail, record a linker error.
- *
- * XXX more checks are needed...
- */
-static void
-check_resources(const struct gl_context *ctx,
- struct gl_shader_program *shader_program,
- glsl_to_tgsi_visitor *prog,
- struct gl_program *proginfo)
-{
- switch (proginfo->Target) {
- case GL_VERTEX_PROGRAM_ARB:
- if (_mesa_bitcount(prog->samplers_used) >
- ctx->Const.MaxVertexTextureImageUnits) {
- fail_link(shader_program, "Too many vertex shader texture samplers");
- }
- if (proginfo->Parameters->NumParameters > MAX_UNIFORMS) {
- fail_link(shader_program, "Too many vertex shader constants");
- }
- break;
- case MESA_GEOMETRY_PROGRAM:
- if (_mesa_bitcount(prog->samplers_used) >
- ctx->Const.MaxGeometryTextureImageUnits) {
- fail_link(shader_program, "Too many geometry shader texture samplers");
- }
- if (proginfo->Parameters->NumParameters >
- MAX_GEOMETRY_UNIFORM_COMPONENTS / 4) {
- fail_link(shader_program, "Too many geometry shader constants");
- }
- break;
- case GL_FRAGMENT_PROGRAM_ARB:
- if (_mesa_bitcount(prog->samplers_used) >
- ctx->Const.MaxTextureImageUnits) {
- fail_link(shader_program, "Too many fragment shader texture samplers");
- }
- if (proginfo->Parameters->NumParameters > MAX_UNIFORMS) {
- fail_link(shader_program, "Too many fragment shader constants");
- }
- break;
- default:
- _mesa_problem(ctx, "unexpected program type in check_resources()");
- }
-}
-
-
static void
set_uniform_initializer(struct gl_context *ctx, void *mem_ctx,
struct gl_shader_program *shader_program,
@@ -4015,6 +3966,7 @@ struct st_translate {
/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */
static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
TGSI_SEMANTIC_FACE,
+ TGSI_SEMANTIC_VERTEXID,
TGSI_SEMANTIC_INSTANCEID
};
@@ -4991,6 +4943,7 @@ get_mesa_program(struct gl_context *ctx,
_mesa_print_ir(shader->ir, NULL);
printf("\n");
printf("\n");
+ fflush(stdout);
}
prog->Instructions = NULL;
@@ -4999,8 +4952,6 @@ get_mesa_program(struct gl_context *ctx,
do_set_program_inouts(shader->ir, prog, shader->Type == GL_FRAGMENT_SHADER);
count_resources(v, prog);
- check_resources(ctx, shader_program, v, prog);
-
_mesa_reference_program(ctx, &shader->Program, prog);
/* This has to be done last. Any operation the can cause
diff --git a/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c b/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c
index 27ebb1ad7..ac615343a 100644
--- a/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -108,6 +108,7 @@ struct st_translate {
/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */
static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
TGSI_SEMANTIC_FACE,
+ TGSI_SEMANTIC_VERTEXID,
TGSI_SEMANTIC_INSTANCEID
};
diff --git a/mesalib/src/mesa/swrast/s_copypix.c b/mesalib/src/mesa/swrast/s_copypix.c
index e249e4ad5..3ba31f22c 100644
--- a/mesalib/src/mesa/swrast/s_copypix.c
+++ b/mesalib/src/mesa/swrast/s_copypix.c
@@ -1,720 +1,720 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * 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
- * BRIAN PAUL 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 "main/glheader.h"
-#include "main/context.h"
-#include "main/colormac.h"
-#include "main/condrender.h"
-#include "main/macros.h"
-#include "main/pixeltransfer.h"
-#include "main/imports.h"
-
-#include "s_context.h"
-#include "s_depth.h"
-#include "s_span.h"
-#include "s_stencil.h"
-#include "s_zoom.h"
-
-
-
-/**
- * Determine if there's overlap in an image copy.
- * This test also compensates for the fact that copies are done from
- * bottom to top and overlaps can sometimes be handled correctly
- * without making a temporary image copy.
- * \return GL_TRUE if the regions overlap, GL_FALSE otherwise.
- */
-static GLboolean
-regions_overlap(GLint srcx, GLint srcy,
- GLint dstx, GLint dsty,
- GLint width, GLint height,
- GLfloat zoomX, GLfloat zoomY)
-{
- if (zoomX == 1.0 && zoomY == 1.0) {
- /* no zoom */
- if (srcx >= dstx + width || (srcx + width <= dstx)) {
- return GL_FALSE;
- }
- else if (srcy < dsty) { /* this is OK */
- return GL_FALSE;
- }
- else if (srcy > dsty + height) {
- return GL_FALSE;
- }
- else {
- return GL_TRUE;
- }
- }
- else {
- /* add one pixel of slop when zooming, just to be safe */
- if (srcx > (dstx + ((zoomX > 0.0F) ? (width * zoomX + 1.0F) : 0.0F))) {
- /* src is completely right of dest */
- return GL_FALSE;
- }
- else if (srcx + width + 1.0F < dstx + ((zoomX > 0.0F) ? 0.0F : (width * zoomX))) {
- /* src is completely left of dest */
- return GL_FALSE;
- }
- else if ((srcy < dsty) && (srcy + height < dsty + (height * zoomY))) {
- /* src is completely below dest */
- return GL_FALSE;
- }
- else if ((srcy > dsty) && (srcy + height > dsty + (height * zoomY))) {
- /* src is completely above dest */
- return GL_FALSE;
- }
- else {
- return GL_TRUE;
- }
- }
-}
-
-
-/**
- * RGBA copypixels
- */
-static void
-copy_rgba_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
- GLint width, GLint height, GLint destx, GLint desty)
-{
- GLfloat *tmpImage, *p;
- GLint sy, dy, stepy, row;
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
- GLint overlapping;
- GLuint transferOps = ctx->_ImageTransferState;
- SWspan span;
-
- if (!ctx->ReadBuffer->_ColorReadBuffer) {
- /* no readbuffer - OK */
- return;
- }
-
- if (ctx->DrawBuffer == ctx->ReadBuffer) {
- overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
- ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
- }
- else {
- overlapping = GL_FALSE;
- }
-
- /* Determine if copy should be done bottom-to-top or top-to-bottom */
- if (!overlapping && srcy < desty) {
- /* top-down max-to-min */
- sy = srcy + height - 1;
- dy = desty + height - 1;
- stepy = -1;
- }
- else {
- /* bottom-up min-to-max */
- sy = srcy;
- dy = desty;
- stepy = 1;
- }
-
- INIT_SPAN(span, GL_BITMAP);
- _swrast_span_default_attribs(ctx, &span);
- span.arrayMask = SPAN_RGBA;
- span.arrayAttribs = FRAG_BIT_COL0; /* we'll fill in COL0 attrib values */
-
- if (overlapping) {
- tmpImage = (GLfloat *) malloc(width * height * sizeof(GLfloat) * 4);
- if (!tmpImage) {
- _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
- return;
- }
- /* read the source image as RGBA/float */
- p = tmpImage;
- for (row = 0; row < height; row++) {
- _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
- width, srcx, sy + row, GL_FLOAT, p );
- p += width * 4;
- }
- p = tmpImage;
- }
- else {
- tmpImage = NULL; /* silence compiler warnings */
- p = NULL;
- }
-
- ASSERT(width < MAX_WIDTH);
-
- for (row = 0; row < height; row++, sy += stepy, dy += stepy) {
- GLvoid *rgba = span.array->attribs[FRAG_ATTRIB_COL0];
-
- /* Get row/span of source pixels */
- if (overlapping) {
- /* get from buffered image */
- memcpy(rgba, p, width * sizeof(GLfloat) * 4);
- p += width * 4;
- }
- else {
- /* get from framebuffer */
- _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
- width, srcx, sy, GL_FLOAT, rgba );
- }
-
- if (transferOps) {
- _mesa_apply_rgba_transfer_ops(ctx, transferOps, width,
- (GLfloat (*)[4]) rgba);
- }
-
- /* Write color span */
- span.x = destx;
- span.y = dy;
- span.end = width;
- span.array->ChanType = GL_FLOAT;
- if (zoom) {
- _swrast_write_zoomed_rgba_span(ctx, destx, desty, &span, rgba);
- }
- else {
- _swrast_write_rgba_span(ctx, &span);
- }
- }
-
- span.array->ChanType = CHAN_TYPE; /* restore */
-
- if (overlapping)
- free(tmpImage);
-}
-
-
-/**
- * Convert floating point Z values to integer Z values with pixel transfer's
- * Z scale and bias.
- */
-static void
-scale_and_bias_z(struct gl_context *ctx, GLuint width,
- const GLfloat depth[], GLuint z[])
-{
- const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
- GLuint i;
-
- if (depthMax <= 0xffffff &&
- ctx->Pixel.DepthScale == 1.0 &&
- ctx->Pixel.DepthBias == 0.0) {
- /* no scale or bias and no clamping and no worry of overflow */
- const GLfloat depthMaxF = ctx->DrawBuffer->_DepthMaxF;
- for (i = 0; i < width; i++) {
- z[i] = (GLuint) (depth[i] * depthMaxF);
- }
- }
- else {
- /* need to be careful with overflow */
- const GLdouble depthMaxF = ctx->DrawBuffer->_DepthMaxF;
- for (i = 0; i < width; i++) {
- GLdouble d = depth[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias;
- d = CLAMP(d, 0.0, 1.0) * depthMaxF;
- if (d >= depthMaxF)
- z[i] = depthMax;
- else
- z[i] = (GLuint) d;
- }
- }
-}
-
-
-
-/*
- * TODO: Optimize!!!!
- */
-static void
-copy_depth_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
- GLint width, GLint height,
- GLint destx, GLint desty )
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *readRb = fb->_DepthBuffer;
- GLfloat *p, *tmpImage;
- GLint sy, dy, stepy;
- GLint j;
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
- GLint overlapping;
- SWspan span;
-
- if (!readRb) {
- /* no readbuffer - OK */
- return;
- }
-
- INIT_SPAN(span, GL_BITMAP);
- _swrast_span_default_attribs(ctx, &span);
- span.arrayMask = SPAN_Z;
-
- if (ctx->DrawBuffer == ctx->ReadBuffer) {
- overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
- ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
- }
- else {
- overlapping = GL_FALSE;
- }
-
- /* Determine if copy should be bottom-to-top or top-to-bottom */
- if (!overlapping && srcy < desty) {
- /* top-down max-to-min */
- sy = srcy + height - 1;
- dy = desty + height - 1;
- stepy = -1;
- }
- else {
- /* bottom-up min-to-max */
- sy = srcy;
- dy = desty;
- stepy = 1;
- }
-
- if (overlapping) {
- GLint ssy = sy;
- tmpImage = (GLfloat *) malloc(width * height * sizeof(GLfloat));
- if (!tmpImage) {
- _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
- return;
- }
- p = tmpImage;
- for (j = 0; j < height; j++, ssy += stepy) {
- _swrast_read_depth_span_float(ctx, readRb, width, srcx, ssy, p);
- p += width;
- }
- p = tmpImage;
- }
- else {
- tmpImage = NULL; /* silence compiler warning */
- p = NULL;
- }
-
- for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
- GLfloat depth[MAX_WIDTH];
- /* get depth values */
- if (overlapping) {
- memcpy(depth, p, width * sizeof(GLfloat));
- p += width;
- }
- else {
- _swrast_read_depth_span_float(ctx, readRb, width, srcx, sy, depth);
- }
-
- /* apply scale and bias */
- scale_and_bias_z(ctx, width, depth, span.array->z);
-
- /* write depth values */
- span.x = destx;
- span.y = dy;
- span.end = width;
- if (zoom)
- _swrast_write_zoomed_depth_span(ctx, destx, desty, &span);
- else
- _swrast_write_rgba_span(ctx, &span);
- }
-
- if (overlapping)
- free(tmpImage);
-}
-
-
-
-static void
-copy_stencil_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
- GLint width, GLint height,
- GLint destx, GLint desty )
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->_StencilBuffer;
- GLint sy, dy, stepy;
- GLint j;
- GLstencil *p, *tmpImage;
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
- GLint overlapping;
-
- if (!rb) {
- /* no readbuffer - OK */
- return;
- }
-
- if (ctx->DrawBuffer == ctx->ReadBuffer) {
- overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
- ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
- }
- else {
- overlapping = GL_FALSE;
- }
-
- /* Determine if copy should be bottom-to-top or top-to-bottom */
- if (!overlapping && srcy < desty) {
- /* top-down max-to-min */
- sy = srcy + height - 1;
- dy = desty + height - 1;
- stepy = -1;
- }
- else {
- /* bottom-up min-to-max */
- sy = srcy;
- dy = desty;
- stepy = 1;
- }
-
- if (overlapping) {
- GLint ssy = sy;
- tmpImage = (GLstencil *) malloc(width * height * sizeof(GLstencil));
- if (!tmpImage) {
- _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
- return;
- }
- p = tmpImage;
- for (j = 0; j < height; j++, ssy += stepy) {
- _swrast_read_stencil_span( ctx, rb, width, srcx, ssy, p );
- p += width;
- }
- p = tmpImage;
- }
- else {
- tmpImage = NULL; /* silence compiler warning */
- p = NULL;
- }
-
- for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
- GLstencil stencil[MAX_WIDTH];
-
- /* Get stencil values */
- if (overlapping) {
- memcpy(stencil, p, width * sizeof(GLstencil));
- p += width;
- }
- else {
- _swrast_read_stencil_span( ctx, rb, width, srcx, sy, stencil );
- }
-
- _mesa_apply_stencil_transfer_ops(ctx, width, stencil);
-
- /* Write stencil values */
- if (zoom) {
- _swrast_write_zoomed_stencil_span(ctx, destx, desty, width,
- destx, dy, stencil);
- }
- else {
- _swrast_write_stencil_span( ctx, width, destx, dy, stencil );
- }
- }
-
- if (overlapping)
- free(tmpImage);
-}
-
-
-/**
- * This isn't terribly efficient. If a driver really has combined
- * depth/stencil buffers the driver should implement an optimized
- * CopyPixels function.
- */
-static void
-copy_depth_stencil_pixels(struct gl_context *ctx,
- const GLint srcX, const GLint srcY,
- const GLint width, const GLint height,
- const GLint destX, const GLint destY)
-{
- struct gl_renderbuffer *stencilReadRb, *depthReadRb, *depthDrawRb;
- GLint sy, dy, stepy;
- GLint j;
- GLstencil *tempStencilImage = NULL, *stencilPtr = NULL;
- GLfloat *tempDepthImage = NULL, *depthPtr = NULL;
- const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF;
- const GLuint stencilMask = ctx->Stencil.WriteMask[0];
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
- const GLboolean scaleOrBias
- = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
- GLint overlapping;
-
- depthDrawRb = ctx->DrawBuffer->_DepthBuffer;
- depthReadRb = ctx->ReadBuffer->_DepthBuffer;
- stencilReadRb = ctx->ReadBuffer->_StencilBuffer;
-
- ASSERT(depthDrawRb);
- ASSERT(depthReadRb);
- ASSERT(stencilReadRb);
-
- if (ctx->DrawBuffer == ctx->ReadBuffer) {
- overlapping = regions_overlap(srcX, srcY, destX, destY, width, height,
- ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
- }
- else {
- overlapping = GL_FALSE;
- }
-
- /* Determine if copy should be bottom-to-top or top-to-bottom */
- if (!overlapping && srcY < destY) {
- /* top-down max-to-min */
- sy = srcY + height - 1;
- dy = destY + height - 1;
- stepy = -1;
- }
- else {
- /* bottom-up min-to-max */
- sy = srcY;
- dy = destY;
- stepy = 1;
- }
-
- if (overlapping) {
- GLint ssy = sy;
-
- if (stencilMask != 0x0) {
- tempStencilImage
- = (GLstencil *) malloc(width * height * sizeof(GLstencil));
- if (!tempStencilImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
- return;
- }
-
- /* get copy of stencil pixels */
- stencilPtr = tempStencilImage;
- for (j = 0; j < height; j++, ssy += stepy) {
- _swrast_read_stencil_span(ctx, stencilReadRb,
- width, srcX, ssy, stencilPtr);
- stencilPtr += width;
- }
- stencilPtr = tempStencilImage;
- }
-
- if (ctx->Depth.Mask) {
- tempDepthImage
- = (GLfloat *) malloc(width * height * sizeof(GLfloat));
- if (!tempDepthImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
- free(tempStencilImage);
- return;
- }
-
- /* get copy of depth pixels */
- depthPtr = tempDepthImage;
- for (j = 0; j < height; j++, ssy += stepy) {
- _swrast_read_depth_span_float(ctx, depthReadRb,
- width, srcX, ssy, depthPtr);
- depthPtr += width;
- }
- depthPtr = tempDepthImage;
- }
- }
-
- for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
- if (stencilMask != 0x0) {
- GLstencil stencil[MAX_WIDTH];
-
- /* Get stencil values */
- if (overlapping) {
- memcpy(stencil, stencilPtr, width * sizeof(GLstencil));
- stencilPtr += width;
- }
- else {
- _swrast_read_stencil_span(ctx, stencilReadRb,
- width, srcX, sy, stencil);
- }
-
- _mesa_apply_stencil_transfer_ops(ctx, width, stencil);
-
- /* Write values */
- if (zoom) {
- _swrast_write_zoomed_stencil_span(ctx, destX, destY, width,
- destX, dy, stencil);
- }
- else {
- _swrast_write_stencil_span( ctx, width, destX, dy, stencil );
- }
- }
-
- if (ctx->Depth.Mask) {
- GLfloat depth[MAX_WIDTH];
- GLuint zVals32[MAX_WIDTH];
- GLushort zVals16[MAX_WIDTH];
- GLvoid *zVals;
- GLuint zBytes;
-
- /* get depth values */
- if (overlapping) {
- memcpy(depth, depthPtr, width * sizeof(GLfloat));
- depthPtr += width;
- }
- else {
- _swrast_read_depth_span_float(ctx, depthReadRb,
- width, srcX, sy, depth);
- }
-
- /* scale & bias */
- if (scaleOrBias) {
- _mesa_scale_and_bias_depth(ctx, width, depth);
- }
- /* convert to integer Z values */
- if (depthDrawRb->DataType == GL_UNSIGNED_SHORT) {
- GLint k;
- for (k = 0; k < width; k++)
- zVals16[k] = (GLushort) (depth[k] * depthScale);
- zVals = zVals16;
- zBytes = 2;
- }
- else {
- GLint k;
- for (k = 0; k < width; k++)
- zVals32[k] = (GLuint) (depth[k] * depthScale);
- zVals = zVals32;
- zBytes = 4;
- }
-
- /* Write values */
- if (zoom) {
- _swrast_write_zoomed_z_span(ctx, destX, destY, width,
- destX, dy, zVals);
- }
- else {
- _swrast_put_row(ctx, depthDrawRb, width, destX, dy, zVals, zBytes);
- }
- }
- }
-
- if (tempStencilImage)
- free(tempStencilImage);
-
- if (tempDepthImage)
- free(tempDepthImage);
-}
-
-
-
-/**
- * Try to do a fast copy pixels.
- */
-static GLboolean
-fast_copy_pixels(struct gl_context *ctx,
- GLint srcX, GLint srcY, GLsizei width, GLsizei height,
- GLint dstX, GLint dstY, GLenum type)
-{
- struct gl_framebuffer *srcFb = ctx->ReadBuffer;
- struct gl_framebuffer *dstFb = ctx->DrawBuffer;
- struct gl_renderbuffer *srcRb, *dstRb;
- GLint row, yStep;
-
- if (SWRAST_CONTEXT(ctx)->_RasterMask != 0x0 ||
- ctx->Pixel.ZoomX != 1.0F ||
- ctx->Pixel.ZoomY != 1.0F ||
- ctx->_ImageTransferState) {
- /* can't handle these */
- return GL_FALSE;
- }
-
- if (type == GL_COLOR) {
- if (dstFb->_NumColorDrawBuffers != 1)
- return GL_FALSE;
- srcRb = srcFb->_ColorReadBuffer;
- dstRb = dstFb->_ColorDrawBuffers[0];
- }
- else if (type == GL_STENCIL) {
- srcRb = srcFb->_StencilBuffer;
- dstRb = dstFb->_StencilBuffer;
- }
- else if (type == GL_DEPTH) {
- srcRb = srcFb->_DepthBuffer;
- dstRb = dstFb->_DepthBuffer;
- }
- else {
- ASSERT(type == GL_DEPTH_STENCIL_EXT);
- /* XXX correct? */
- srcRb = srcFb->Attachment[BUFFER_DEPTH].Renderbuffer;
- dstRb = dstFb->Attachment[BUFFER_DEPTH].Renderbuffer;
- }
-
- /* src and dst renderbuffers must be same format and type */
- if (!srcRb || !dstRb ||
- srcRb->DataType != dstRb->DataType ||
- srcRb->_BaseFormat != dstRb->_BaseFormat) {
- return GL_FALSE;
- }
-
- /* clipping not supported */
- if (srcX < 0 || srcX + width > (GLint) srcFb->Width ||
- srcY < 0 || srcY + height > (GLint) srcFb->Height ||
- dstX < dstFb->_Xmin || dstX + width > dstFb->_Xmax ||
- dstY < dstFb->_Ymin || dstY + height > dstFb->_Ymax) {
- return GL_FALSE;
- }
-
- /* overlapping src/dst doesn't matter, just determine Y direction */
- if (srcY < dstY) {
- /* top-down max-to-min */
- srcY = srcY + height - 1;
- dstY = dstY + height - 1;
- yStep = -1;
- }
- else {
- /* bottom-up min-to-max */
- yStep = 1;
- }
-
- for (row = 0; row < height; row++) {
- GLuint temp[MAX_WIDTH][4];
- srcRb->GetRow(ctx, srcRb, width, srcX, srcY, temp);
- dstRb->PutRow(ctx, dstRb, width, dstX, dstY, temp, NULL);
- srcY += yStep;
- dstY += yStep;
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Do software-based glCopyPixels.
- * By time we get here, all parameters will have been error-checked.
- */
-void
-_swrast_CopyPixels( struct gl_context *ctx,
- GLint srcx, GLint srcy, GLsizei width, GLsizei height,
- GLint destx, GLint desty, GLenum type )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- swrast_render_start(ctx);
-
- if (!_mesa_check_conditional_render(ctx))
- return; /* don't copy */
-
- if (swrast->NewState)
- _swrast_validate_derived( ctx );
-
- if (!fast_copy_pixels(ctx, srcx, srcy, width, height, destx, desty, type)) {
- switch (type) {
- case GL_COLOR:
- copy_rgba_pixels( ctx, srcx, srcy, width, height, destx, desty );
- break;
- case GL_DEPTH:
- copy_depth_pixels( ctx, srcx, srcy, width, height, destx, desty );
- break;
- case GL_STENCIL:
- copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty );
- break;
- case GL_DEPTH_STENCIL_EXT:
- copy_depth_stencil_pixels(ctx, srcx, srcy, width, height, destx, desty);
- break;
- default:
- _mesa_problem(ctx, "unexpected type in _swrast_CopyPixels");
- }
- }
-
- swrast_render_finish(ctx);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * 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
+ * BRIAN PAUL 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 "main/glheader.h"
+#include "main/context.h"
+#include "main/colormac.h"
+#include "main/condrender.h"
+#include "main/macros.h"
+#include "main/pixeltransfer.h"
+#include "main/imports.h"
+
+#include "s_context.h"
+#include "s_depth.h"
+#include "s_span.h"
+#include "s_stencil.h"
+#include "s_zoom.h"
+
+
+
+/**
+ * Determine if there's overlap in an image copy.
+ * This test also compensates for the fact that copies are done from
+ * bottom to top and overlaps can sometimes be handled correctly
+ * without making a temporary image copy.
+ * \return GL_TRUE if the regions overlap, GL_FALSE otherwise.
+ */
+static GLboolean
+regions_overlap(GLint srcx, GLint srcy,
+ GLint dstx, GLint dsty,
+ GLint width, GLint height,
+ GLfloat zoomX, GLfloat zoomY)
+{
+ if (zoomX == 1.0 && zoomY == 1.0) {
+ /* no zoom */
+ if (srcx >= dstx + width || (srcx + width <= dstx)) {
+ return GL_FALSE;
+ }
+ else if (srcy < dsty) { /* this is OK */
+ return GL_FALSE;
+ }
+ else if (srcy > dsty + height) {
+ return GL_FALSE;
+ }
+ else {
+ return GL_TRUE;
+ }
+ }
+ else {
+ /* add one pixel of slop when zooming, just to be safe */
+ if (srcx > (dstx + ((zoomX > 0.0F) ? (width * zoomX + 1.0F) : 0.0F))) {
+ /* src is completely right of dest */
+ return GL_FALSE;
+ }
+ else if (srcx + width + 1.0F < dstx + ((zoomX > 0.0F) ? 0.0F : (width * zoomX))) {
+ /* src is completely left of dest */
+ return GL_FALSE;
+ }
+ else if ((srcy < dsty) && (srcy + height < dsty + (height * zoomY))) {
+ /* src is completely below dest */
+ return GL_FALSE;
+ }
+ else if ((srcy > dsty) && (srcy + height > dsty + (height * zoomY))) {
+ /* src is completely above dest */
+ return GL_FALSE;
+ }
+ else {
+ return GL_TRUE;
+ }
+ }
+}
+
+
+/**
+ * RGBA copypixels
+ */
+static void
+copy_rgba_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
+ GLint width, GLint height, GLint destx, GLint desty)
+{
+ GLfloat *tmpImage, *p;
+ GLint sy, dy, stepy, row;
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
+ GLint overlapping;
+ GLuint transferOps = ctx->_ImageTransferState;
+ SWspan span;
+
+ if (!ctx->ReadBuffer->_ColorReadBuffer) {
+ /* no readbuffer - OK */
+ return;
+ }
+
+ if (ctx->DrawBuffer == ctx->ReadBuffer) {
+ overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
+ ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+ }
+ else {
+ overlapping = GL_FALSE;
+ }
+
+ /* Determine if copy should be done bottom-to-top or top-to-bottom */
+ if (!overlapping && srcy < desty) {
+ /* top-down max-to-min */
+ sy = srcy + height - 1;
+ dy = desty + height - 1;
+ stepy = -1;
+ }
+ else {
+ /* bottom-up min-to-max */
+ sy = srcy;
+ dy = desty;
+ stepy = 1;
+ }
+
+ INIT_SPAN(span, GL_BITMAP);
+ _swrast_span_default_attribs(ctx, &span);
+ span.arrayMask = SPAN_RGBA;
+ span.arrayAttribs = FRAG_BIT_COL0; /* we'll fill in COL0 attrib values */
+
+ if (overlapping) {
+ tmpImage = (GLfloat *) malloc(width * height * sizeof(GLfloat) * 4);
+ if (!tmpImage) {
+ _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+ return;
+ }
+ /* read the source image as RGBA/float */
+ p = tmpImage;
+ for (row = 0; row < height; row++) {
+ _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
+ width, srcx, sy + row, GL_FLOAT, p );
+ p += width * 4;
+ }
+ p = tmpImage;
+ }
+ else {
+ tmpImage = NULL; /* silence compiler warnings */
+ p = NULL;
+ }
+
+ ASSERT(width < MAX_WIDTH);
+
+ for (row = 0; row < height; row++, sy += stepy, dy += stepy) {
+ GLvoid *rgba = span.array->attribs[FRAG_ATTRIB_COL0];
+
+ /* Get row/span of source pixels */
+ if (overlapping) {
+ /* get from buffered image */
+ memcpy(rgba, p, width * sizeof(GLfloat) * 4);
+ p += width * 4;
+ }
+ else {
+ /* get from framebuffer */
+ _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
+ width, srcx, sy, GL_FLOAT, rgba );
+ }
+
+ if (transferOps) {
+ _mesa_apply_rgba_transfer_ops(ctx, transferOps, width,
+ (GLfloat (*)[4]) rgba);
+ }
+
+ /* Write color span */
+ span.x = destx;
+ span.y = dy;
+ span.end = width;
+ span.array->ChanType = GL_FLOAT;
+ if (zoom) {
+ _swrast_write_zoomed_rgba_span(ctx, destx, desty, &span, rgba);
+ }
+ else {
+ _swrast_write_rgba_span(ctx, &span);
+ }
+ }
+
+ span.array->ChanType = CHAN_TYPE; /* restore */
+
+ if (overlapping)
+ free(tmpImage);
+}
+
+
+/**
+ * Convert floating point Z values to integer Z values with pixel transfer's
+ * Z scale and bias.
+ */
+static void
+scale_and_bias_z(struct gl_context *ctx, GLuint width,
+ const GLfloat depth[], GLuint z[])
+{
+ const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
+ GLuint i;
+
+ if (depthMax <= 0xffffff &&
+ ctx->Pixel.DepthScale == 1.0 &&
+ ctx->Pixel.DepthBias == 0.0) {
+ /* no scale or bias and no clamping and no worry of overflow */
+ const GLfloat depthMaxF = ctx->DrawBuffer->_DepthMaxF;
+ for (i = 0; i < width; i++) {
+ z[i] = (GLuint) (depth[i] * depthMaxF);
+ }
+ }
+ else {
+ /* need to be careful with overflow */
+ const GLdouble depthMaxF = ctx->DrawBuffer->_DepthMaxF;
+ for (i = 0; i < width; i++) {
+ GLdouble d = depth[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias;
+ d = CLAMP(d, 0.0, 1.0) * depthMaxF;
+ if (d >= depthMaxF)
+ z[i] = depthMax;
+ else
+ z[i] = (GLuint) d;
+ }
+ }
+}
+
+
+
+/*
+ * TODO: Optimize!!!!
+ */
+static void
+copy_depth_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
+ GLint width, GLint height,
+ GLint destx, GLint desty )
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *readRb = fb->_DepthBuffer;
+ GLfloat *p, *tmpImage;
+ GLint sy, dy, stepy;
+ GLint j;
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
+ GLint overlapping;
+ SWspan span;
+
+ if (!readRb) {
+ /* no readbuffer - OK */
+ return;
+ }
+
+ INIT_SPAN(span, GL_BITMAP);
+ _swrast_span_default_attribs(ctx, &span);
+ span.arrayMask = SPAN_Z;
+
+ if (ctx->DrawBuffer == ctx->ReadBuffer) {
+ overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
+ ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+ }
+ else {
+ overlapping = GL_FALSE;
+ }
+
+ /* Determine if copy should be bottom-to-top or top-to-bottom */
+ if (!overlapping && srcy < desty) {
+ /* top-down max-to-min */
+ sy = srcy + height - 1;
+ dy = desty + height - 1;
+ stepy = -1;
+ }
+ else {
+ /* bottom-up min-to-max */
+ sy = srcy;
+ dy = desty;
+ stepy = 1;
+ }
+
+ if (overlapping) {
+ GLint ssy = sy;
+ tmpImage = (GLfloat *) malloc(width * height * sizeof(GLfloat));
+ if (!tmpImage) {
+ _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+ return;
+ }
+ p = tmpImage;
+ for (j = 0; j < height; j++, ssy += stepy) {
+ _swrast_read_depth_span_float(ctx, readRb, width, srcx, ssy, p);
+ p += width;
+ }
+ p = tmpImage;
+ }
+ else {
+ tmpImage = NULL; /* silence compiler warning */
+ p = NULL;
+ }
+
+ for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
+ GLfloat depth[MAX_WIDTH];
+ /* get depth values */
+ if (overlapping) {
+ memcpy(depth, p, width * sizeof(GLfloat));
+ p += width;
+ }
+ else {
+ _swrast_read_depth_span_float(ctx, readRb, width, srcx, sy, depth);
+ }
+
+ /* apply scale and bias */
+ scale_and_bias_z(ctx, width, depth, span.array->z);
+
+ /* write depth values */
+ span.x = destx;
+ span.y = dy;
+ span.end = width;
+ if (zoom)
+ _swrast_write_zoomed_depth_span(ctx, destx, desty, &span);
+ else
+ _swrast_write_rgba_span(ctx, &span);
+ }
+
+ if (overlapping)
+ free(tmpImage);
+}
+
+
+
+static void
+copy_stencil_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
+ GLint width, GLint height,
+ GLint destx, GLint desty )
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->_StencilBuffer;
+ GLint sy, dy, stepy;
+ GLint j;
+ GLubyte *p, *tmpImage;
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
+ GLint overlapping;
+
+ if (!rb) {
+ /* no readbuffer - OK */
+ return;
+ }
+
+ if (ctx->DrawBuffer == ctx->ReadBuffer) {
+ overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
+ ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+ }
+ else {
+ overlapping = GL_FALSE;
+ }
+
+ /* Determine if copy should be bottom-to-top or top-to-bottom */
+ if (!overlapping && srcy < desty) {
+ /* top-down max-to-min */
+ sy = srcy + height - 1;
+ dy = desty + height - 1;
+ stepy = -1;
+ }
+ else {
+ /* bottom-up min-to-max */
+ sy = srcy;
+ dy = desty;
+ stepy = 1;
+ }
+
+ if (overlapping) {
+ GLint ssy = sy;
+ tmpImage = (GLubyte *) malloc(width * height * sizeof(GLubyte));
+ if (!tmpImage) {
+ _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+ return;
+ }
+ p = tmpImage;
+ for (j = 0; j < height; j++, ssy += stepy) {
+ _swrast_read_stencil_span( ctx, rb, width, srcx, ssy, p );
+ p += width;
+ }
+ p = tmpImage;
+ }
+ else {
+ tmpImage = NULL; /* silence compiler warning */
+ p = NULL;
+ }
+
+ for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
+ GLubyte stencil[MAX_WIDTH];
+
+ /* Get stencil values */
+ if (overlapping) {
+ memcpy(stencil, p, width * sizeof(GLubyte));
+ p += width;
+ }
+ else {
+ _swrast_read_stencil_span( ctx, rb, width, srcx, sy, stencil );
+ }
+
+ _mesa_apply_stencil_transfer_ops(ctx, width, stencil);
+
+ /* Write stencil values */
+ if (zoom) {
+ _swrast_write_zoomed_stencil_span(ctx, destx, desty, width,
+ destx, dy, stencil);
+ }
+ else {
+ _swrast_write_stencil_span( ctx, width, destx, dy, stencil );
+ }
+ }
+
+ if (overlapping)
+ free(tmpImage);
+}
+
+
+/**
+ * This isn't terribly efficient. If a driver really has combined
+ * depth/stencil buffers the driver should implement an optimized
+ * CopyPixels function.
+ */
+static void
+copy_depth_stencil_pixels(struct gl_context *ctx,
+ const GLint srcX, const GLint srcY,
+ const GLint width, const GLint height,
+ const GLint destX, const GLint destY)
+{
+ struct gl_renderbuffer *stencilReadRb, *depthReadRb, *depthDrawRb;
+ GLint sy, dy, stepy;
+ GLint j;
+ GLubyte *tempStencilImage = NULL, *stencilPtr = NULL;
+ GLfloat *tempDepthImage = NULL, *depthPtr = NULL;
+ const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF;
+ const GLuint stencilMask = ctx->Stencil.WriteMask[0];
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
+ const GLboolean scaleOrBias
+ = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
+ GLint overlapping;
+
+ depthDrawRb = ctx->DrawBuffer->_DepthBuffer;
+ depthReadRb = ctx->ReadBuffer->_DepthBuffer;
+ stencilReadRb = ctx->ReadBuffer->_StencilBuffer;
+
+ ASSERT(depthDrawRb);
+ ASSERT(depthReadRb);
+ ASSERT(stencilReadRb);
+
+ if (ctx->DrawBuffer == ctx->ReadBuffer) {
+ overlapping = regions_overlap(srcX, srcY, destX, destY, width, height,
+ ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+ }
+ else {
+ overlapping = GL_FALSE;
+ }
+
+ /* Determine if copy should be bottom-to-top or top-to-bottom */
+ if (!overlapping && srcY < destY) {
+ /* top-down max-to-min */
+ sy = srcY + height - 1;
+ dy = destY + height - 1;
+ stepy = -1;
+ }
+ else {
+ /* bottom-up min-to-max */
+ sy = srcY;
+ dy = destY;
+ stepy = 1;
+ }
+
+ if (overlapping) {
+ GLint ssy = sy;
+
+ if (stencilMask != 0x0) {
+ tempStencilImage
+ = (GLubyte *) malloc(width * height * sizeof(GLubyte));
+ if (!tempStencilImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+ return;
+ }
+
+ /* get copy of stencil pixels */
+ stencilPtr = tempStencilImage;
+ for (j = 0; j < height; j++, ssy += stepy) {
+ _swrast_read_stencil_span(ctx, stencilReadRb,
+ width, srcX, ssy, stencilPtr);
+ stencilPtr += width;
+ }
+ stencilPtr = tempStencilImage;
+ }
+
+ if (ctx->Depth.Mask) {
+ tempDepthImage
+ = (GLfloat *) malloc(width * height * sizeof(GLfloat));
+ if (!tempDepthImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+ free(tempStencilImage);
+ return;
+ }
+
+ /* get copy of depth pixels */
+ depthPtr = tempDepthImage;
+ for (j = 0; j < height; j++, ssy += stepy) {
+ _swrast_read_depth_span_float(ctx, depthReadRb,
+ width, srcX, ssy, depthPtr);
+ depthPtr += width;
+ }
+ depthPtr = tempDepthImage;
+ }
+ }
+
+ for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
+ if (stencilMask != 0x0) {
+ GLubyte stencil[MAX_WIDTH];
+
+ /* Get stencil values */
+ if (overlapping) {
+ memcpy(stencil, stencilPtr, width * sizeof(GLubyte));
+ stencilPtr += width;
+ }
+ else {
+ _swrast_read_stencil_span(ctx, stencilReadRb,
+ width, srcX, sy, stencil);
+ }
+
+ _mesa_apply_stencil_transfer_ops(ctx, width, stencil);
+
+ /* Write values */
+ if (zoom) {
+ _swrast_write_zoomed_stencil_span(ctx, destX, destY, width,
+ destX, dy, stencil);
+ }
+ else {
+ _swrast_write_stencil_span( ctx, width, destX, dy, stencil );
+ }
+ }
+
+ if (ctx->Depth.Mask) {
+ GLfloat depth[MAX_WIDTH];
+ GLuint zVals32[MAX_WIDTH];
+ GLushort zVals16[MAX_WIDTH];
+ GLvoid *zVals;
+ GLuint zBytes;
+
+ /* get depth values */
+ if (overlapping) {
+ memcpy(depth, depthPtr, width * sizeof(GLfloat));
+ depthPtr += width;
+ }
+ else {
+ _swrast_read_depth_span_float(ctx, depthReadRb,
+ width, srcX, sy, depth);
+ }
+
+ /* scale & bias */
+ if (scaleOrBias) {
+ _mesa_scale_and_bias_depth(ctx, width, depth);
+ }
+ /* convert to integer Z values */
+ if (depthDrawRb->DataType == GL_UNSIGNED_SHORT) {
+ GLint k;
+ for (k = 0; k < width; k++)
+ zVals16[k] = (GLushort) (depth[k] * depthScale);
+ zVals = zVals16;
+ zBytes = 2;
+ }
+ else {
+ GLint k;
+ for (k = 0; k < width; k++)
+ zVals32[k] = (GLuint) (depth[k] * depthScale);
+ zVals = zVals32;
+ zBytes = 4;
+ }
+
+ /* Write values */
+ if (zoom) {
+ _swrast_write_zoomed_z_span(ctx, destX, destY, width,
+ destX, dy, zVals);
+ }
+ else {
+ _swrast_put_row(ctx, depthDrawRb, width, destX, dy, zVals, zBytes);
+ }
+ }
+ }
+
+ if (tempStencilImage)
+ free(tempStencilImage);
+
+ if (tempDepthImage)
+ free(tempDepthImage);
+}
+
+
+
+/**
+ * Try to do a fast copy pixels.
+ */
+static GLboolean
+fast_copy_pixels(struct gl_context *ctx,
+ GLint srcX, GLint srcY, GLsizei width, GLsizei height,
+ GLint dstX, GLint dstY, GLenum type)
+{
+ struct gl_framebuffer *srcFb = ctx->ReadBuffer;
+ struct gl_framebuffer *dstFb = ctx->DrawBuffer;
+ struct gl_renderbuffer *srcRb, *dstRb;
+ GLint row, yStep;
+
+ if (SWRAST_CONTEXT(ctx)->_RasterMask != 0x0 ||
+ ctx->Pixel.ZoomX != 1.0F ||
+ ctx->Pixel.ZoomY != 1.0F ||
+ ctx->_ImageTransferState) {
+ /* can't handle these */
+ return GL_FALSE;
+ }
+
+ if (type == GL_COLOR) {
+ if (dstFb->_NumColorDrawBuffers != 1)
+ return GL_FALSE;
+ srcRb = srcFb->_ColorReadBuffer;
+ dstRb = dstFb->_ColorDrawBuffers[0];
+ }
+ else if (type == GL_STENCIL) {
+ srcRb = srcFb->_StencilBuffer;
+ dstRb = dstFb->_StencilBuffer;
+ }
+ else if (type == GL_DEPTH) {
+ srcRb = srcFb->_DepthBuffer;
+ dstRb = dstFb->_DepthBuffer;
+ }
+ else {
+ ASSERT(type == GL_DEPTH_STENCIL_EXT);
+ /* XXX correct? */
+ srcRb = srcFb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ dstRb = dstFb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ }
+
+ /* src and dst renderbuffers must be same format and type */
+ if (!srcRb || !dstRb ||
+ srcRb->DataType != dstRb->DataType ||
+ srcRb->_BaseFormat != dstRb->_BaseFormat) {
+ return GL_FALSE;
+ }
+
+ /* clipping not supported */
+ if (srcX < 0 || srcX + width > (GLint) srcFb->Width ||
+ srcY < 0 || srcY + height > (GLint) srcFb->Height ||
+ dstX < dstFb->_Xmin || dstX + width > dstFb->_Xmax ||
+ dstY < dstFb->_Ymin || dstY + height > dstFb->_Ymax) {
+ return GL_FALSE;
+ }
+
+ /* overlapping src/dst doesn't matter, just determine Y direction */
+ if (srcY < dstY) {
+ /* top-down max-to-min */
+ srcY = srcY + height - 1;
+ dstY = dstY + height - 1;
+ yStep = -1;
+ }
+ else {
+ /* bottom-up min-to-max */
+ yStep = 1;
+ }
+
+ for (row = 0; row < height; row++) {
+ GLuint temp[MAX_WIDTH][4];
+ srcRb->GetRow(ctx, srcRb, width, srcX, srcY, temp);
+ dstRb->PutRow(ctx, dstRb, width, dstX, dstY, temp, NULL);
+ srcY += yStep;
+ dstY += yStep;
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Do software-based glCopyPixels.
+ * By time we get here, all parameters will have been error-checked.
+ */
+void
+_swrast_CopyPixels( struct gl_context *ctx,
+ GLint srcx, GLint srcy, GLsizei width, GLsizei height,
+ GLint destx, GLint desty, GLenum type )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ swrast_render_start(ctx);
+
+ if (!_mesa_check_conditional_render(ctx))
+ return; /* don't copy */
+
+ if (swrast->NewState)
+ _swrast_validate_derived( ctx );
+
+ if (!fast_copy_pixels(ctx, srcx, srcy, width, height, destx, desty, type)) {
+ switch (type) {
+ case GL_COLOR:
+ copy_rgba_pixels( ctx, srcx, srcy, width, height, destx, desty );
+ break;
+ case GL_DEPTH:
+ copy_depth_pixels( ctx, srcx, srcy, width, height, destx, desty );
+ break;
+ case GL_STENCIL:
+ copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty );
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ copy_depth_stencil_pixels(ctx, srcx, srcy, width, height, destx, desty);
+ break;
+ default:
+ _mesa_problem(ctx, "unexpected type in _swrast_CopyPixels");
+ }
+ }
+
+ swrast_render_finish(ctx);
+}
diff --git a/mesalib/src/mesa/swrast/s_depth.c b/mesalib/src/mesa/swrast/s_depth.c
index 6ffa0a310..8d3ad105b 100644
--- a/mesalib/src/mesa/swrast/s_depth.c
+++ b/mesalib/src/mesa/swrast/s_depth.c
@@ -1248,8 +1248,7 @@ _swrast_depth_bounds_test( struct gl_context *ctx, SWspan *span )
* Read a span of depth values from the given depth renderbuffer, returning
* the values as GLfloats.
* This function does clipping to prevent reading outside the depth buffer's
- * bounds. Though the clipping is redundant when we're called from
- * _swrast_ReadPixels.
+ * bounds.
*/
void
_swrast_read_depth_span_float( struct gl_context *ctx, struct gl_renderbuffer *rb,
diff --git a/mesalib/src/mesa/swrast/s_drawpix.c b/mesalib/src/mesa/swrast/s_drawpix.c
index 20bf4d626..b6c433753 100644
--- a/mesalib/src/mesa/swrast/s_drawpix.c
+++ b/mesalib/src/mesa/swrast/s_drawpix.c
@@ -320,6 +320,7 @@ draw_stencil_pixels( struct gl_context *ctx, GLint x, GLint y,
const GLvoid *pixels )
{
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
+ const GLenum destType = GL_UNSIGNED_BYTE;
GLint skipPixels;
/* if width > MAX_WIDTH, have to process image in chunks */
@@ -330,9 +331,7 @@ draw_stencil_pixels( struct gl_context *ctx, GLint x, GLint y,
GLint row;
for (row = 0; row < height; row++) {
const GLint spanY = y + row;
- GLstencil values[MAX_WIDTH];
- GLenum destType = (sizeof(GLstencil) == sizeof(GLubyte))
- ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
+ GLubyte values[MAX_WIDTH];
const GLvoid *source = _mesa_image_address2d(unpack, pixels,
width, height,
GL_STENCIL_INDEX, type,
@@ -570,8 +569,7 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
= ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
const GLuint stencilMask = ctx->Stencil.WriteMask[0];
- const GLuint stencilType = (STENCIL_BITS == 8) ?
- GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
+ const GLenum stencilType = GL_UNSIGNED_BYTE;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
struct gl_renderbuffer *depthRb, *stencilRb;
struct gl_pixelstore_attrib clippedUnpack = *unpack;
@@ -672,7 +670,7 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
}
if (stencilMask != 0x0) {
- GLstencil stencilValues[MAX_WIDTH];
+ GLubyte stencilValues[MAX_WIDTH];
/* get stencil values, with shift/offset/mapping */
_mesa_unpack_stencil_span(ctx, width, stencilType, stencilValues,
type, depthStencilSrc, &clippedUnpack,
diff --git a/mesalib/src/mesa/swrast/s_readpix.c b/mesalib/src/mesa/swrast/s_readpix.c
deleted file mode 100644
index 500686798..000000000
--- a/mesalib/src/mesa/swrast/s_readpix.c
+++ /dev/null
@@ -1,522 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.0.3
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * 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
- * BRIAN PAUL 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 "main/glheader.h"
-#include "main/colormac.h"
-#include "main/feedback.h"
-#include "main/formats.h"
-#include "main/format_unpack.h"
-#include "main/image.h"
-#include "main/imports.h"
-#include "main/macros.h"
-#include "main/pack.h"
-#include "main/pbo.h"
-#include "main/state.h"
-
-#include "s_context.h"
-#include "s_depth.h"
-#include "s_span.h"
-#include "s_stencil.h"
-
-/**
- * Tries to implement glReadPixels() of GL_DEPTH_COMPONENT using memcpy of the
- * mapping.
- */
-static GLboolean
-fast_read_depth_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
- GLubyte *map, *dst;
- int stride, dstStride, j;
-
- if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0)
- return GL_FALSE;
-
- if (packing->SwapBytes)
- return GL_FALSE;
-
- if (_mesa_get_format_datatype(rb->Format) != GL_UNSIGNED_INT)
- return GL_FALSE;
-
- if (!((type == GL_UNSIGNED_SHORT && rb->Format == MESA_FORMAT_Z16) ||
- type == GL_UNSIGNED_INT))
- return GL_FALSE;
-
- ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
- &map, &stride);
-
- dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type);
- dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
- GL_DEPTH_COMPONENT, type, 0, 0);
-
- for (j = 0; j < height; j++) {
- if (type == GL_UNSIGNED_INT) {
- _mesa_unpack_uint_z_row(rb->Format, width, map, (GLuint *)dst);
- } else {
- ASSERT(type == GL_UNSIGNED_SHORT && rb->Format == MESA_FORMAT_Z16);
- memcpy(dst, map, width * 2);
- }
-
- map += stride;
- dst += dstStride;
- }
- ctx->Driver.UnmapRenderbuffer(ctx, rb);
-
- return GL_TRUE;
-}
-
-/**
- * Read pixels for format=GL_DEPTH_COMPONENT.
- */
-static void
-read_depth_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
- GLint j;
- GLubyte *dst, *map;
- int dstStride, stride;
-
- if (!rb)
- return;
-
- /* clipping should have been done already */
- ASSERT(x >= 0);
- ASSERT(y >= 0);
- ASSERT(x + width <= (GLint) rb->Width);
- ASSERT(y + height <= (GLint) rb->Height);
- /* width should never be > MAX_WIDTH since we did clipping earlier */
- ASSERT(width <= MAX_WIDTH);
-
- if (fast_read_depth_pixels(ctx, x, y, width, height, type, pixels, packing))
- return;
-
- dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type);
- dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
- GL_DEPTH_COMPONENT, type, 0, 0);
-
- ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
- &map, &stride);
-
- /* General case (slower) */
- for (j = 0; j < height; j++, y++) {
- GLfloat depthValues[MAX_WIDTH];
- _mesa_unpack_float_z_row(rb->Format, width, map, depthValues);
- _mesa_pack_depth_span(ctx, width, dst, type, depthValues, packing);
-
- dst += dstStride;
- map += stride;
- }
-
- ctx->Driver.UnmapRenderbuffer(ctx, rb);
-}
-
-
-/**
- * Read pixels for format=GL_STENCIL_INDEX.
- */
-static void
-read_stencil_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
- GLint j;
- GLubyte *map;
- GLint stride;
-
- if (!rb)
- return;
-
- /* width should never be > MAX_WIDTH since we did clipping earlier */
- ASSERT(width <= MAX_WIDTH);
-
- ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
- &map, &stride);
-
- /* process image row by row */
- for (j = 0; j < height; j++) {
- GLvoid *dest;
- GLstencil stencil[MAX_WIDTH];
-
- _mesa_unpack_ubyte_stencil_row(rb->Format, width, map, stencil);
- dest = _mesa_image_address2d(packing, pixels, width, height,
- GL_STENCIL_INDEX, type, j, 0);
-
- _mesa_pack_stencil_span(ctx, width, type, dest, stencil, packing);
-
- map += stride;
- }
-
- ctx->Driver.UnmapRenderbuffer(ctx, rb);
-}
-
-static GLboolean
-fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- GLbitfield transferOps )
-{
- struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
- GLubyte *dst, *map;
- int dstStride, stride, j, texelBytes;
-
- if (!_mesa_format_matches_format_and_type(rb->Format, format, type))
- return GL_FALSE;
-
- /* check for things we can't handle here */
- if (packing->SwapBytes ||
- packing->LsbFirst) {
- return GL_FALSE;
- }
-
- dstStride = _mesa_image_row_stride(packing, width, format, type);
- dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
- format, type, 0, 0);
-
- ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
- &map, &stride);
-
- texelBytes = _mesa_get_format_bytes(rb->Format);
- for (j = 0; j < height; j++) {
- memcpy(dst, map, width * texelBytes);
- dst += dstStride;
- map += stride;
- }
-
- ctx->Driver.UnmapRenderbuffer(ctx, rb);
-
- return GL_TRUE;
-}
-
-static GLboolean
-slow_read_rgba_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- GLbitfield transferOps )
-{
- struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
- const gl_format rbFormat = _mesa_get_srgb_format_linear(rb->Format);
- union {
- float f[MAX_WIDTH][4];
- unsigned int i[MAX_WIDTH][4];
- } rgba;
- GLubyte *dst, *map;
- int dstStride, stride, j;
-
- dstStride = _mesa_image_row_stride(packing, width, format, type);
- dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
- format, type, 0, 0);
-
- ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
- &map, &stride);
-
- for (j = 0; j < height; j++) {
- if (_mesa_is_integer_format(format)) {
- _mesa_unpack_int_rgba_row(rbFormat, width, map, rgba.i);
- _mesa_pack_rgba_span_int(ctx, width, rgba.i, format, type, dst);
- } else {
- _mesa_unpack_rgba_row(rbFormat, width, map, rgba.f);
- _mesa_pack_rgba_span_float(ctx, width, rgba.f, format, type, dst,
- packing, transferOps);
- }
- dst += dstStride;
- map += stride;
- }
-
- ctx->Driver.UnmapRenderbuffer(ctx, rb);
-
- return GL_TRUE;
-}
-
-/*
- * Read R, G, B, A, RGB, L, or LA pixels.
- */
-static void
-read_rgba_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- GLbitfield transferOps = ctx->_ImageTransferState;
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->_ColorReadBuffer;
-
- if (!rb)
- return;
-
- if ((ctx->Color._ClampReadColor == GL_TRUE || type != GL_FLOAT) &&
- !_mesa_is_integer_format(format)) {
- transferOps |= IMAGE_CLAMP_BIT;
- }
-
- if (!transferOps) {
- /* Try the optimized paths first. */
- if (fast_read_rgba_pixels_memcpy(ctx, x, y, width, height,
- format, type, pixels, packing,
- transferOps)) {
- return;
- }
- }
-
- slow_read_rgba_pixels(ctx, x, y, width, height,
- format, type, pixels, packing, transferOps);
-}
-
-/**
- * For a packed depth/stencil buffer being read as depth/stencil, just memcpy the
- * data (possibly swapping 8/24 vs 24/8 as we go).
- */
-static GLboolean
-fast_read_depth_stencil_pixels(struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLubyte *dst, int dstStride)
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
- struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
- GLubyte *map;
- int stride, i;
-
- if (rb != stencilRb)
- return GL_FALSE;
-
- if (rb->Format != MESA_FORMAT_Z24_S8 &&
- rb->Format != MESA_FORMAT_S8_Z24)
- return GL_FALSE;
-
- ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
- &map, &stride);
-
- for (i = 0; i < height; i++) {
- _mesa_unpack_uint_24_8_depth_stencil_row(rb->Format, width,
- map, (GLuint *)dst);
- map += stride;
- dst = (char*)dst + dstStride;
- }
-
- ctx->Driver.UnmapRenderbuffer(ctx, rb);
-
- return GL_TRUE;
-}
-
-
-/**
- * For non-float-depth and stencil buffers being read as 24/8 depth/stencil,
- * copy the integer data directly instead of converting depth to float and
- * re-packing.
- */
-static GLboolean
-fast_read_depth_stencil_pixels_separate(struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- uint32_t *dst, int dstStride)
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
- struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
- GLubyte *depthMap, *stencilMap;
- int depthStride, stencilStride, i, j;
-
- if (_mesa_get_format_datatype(depthRb->Format) != GL_UNSIGNED_INT)
- return GL_FALSE;
-
- ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height,
- GL_MAP_READ_BIT, &depthMap, &depthStride);
- ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height,
- GL_MAP_READ_BIT, &stencilMap, &stencilStride);
-
- for (j = 0; j < height; j++) {
- GLstencil stencilVals[MAX_WIDTH];
-
- _mesa_unpack_uint_z_row(depthRb->Format, width, depthMap, dst);
- _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width,
- stencilMap, stencilVals);
-
- for (i = 0; i < width; i++) {
- dst[i] = (dst[i] & 0xffffff00) | stencilVals[i];
- }
-
- depthMap += depthStride;
- stencilMap += stencilStride;
- dst += dstStride / 4;
- }
-
- ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
- ctx->Driver.UnmapRenderbuffer(ctx, stencilRb);
-
- return GL_TRUE;
-}
-
-static void
-slow_read_depth_stencil_pixels_separate(struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type,
- const struct gl_pixelstore_attrib *packing,
- GLubyte *dst, int dstStride)
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
- struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
- GLubyte *depthMap, *stencilMap;
- int depthStride, stencilStride, j;
-
- ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height,
- GL_MAP_READ_BIT, &depthMap, &depthStride);
- ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height,
- GL_MAP_READ_BIT, &stencilMap, &stencilStride);
-
- for (j = 0; j < height; j++) {
- GLstencil stencilVals[MAX_WIDTH];
- GLfloat depthVals[MAX_WIDTH];
-
- _mesa_unpack_float_z_row(depthRb->Format, width, depthMap, depthVals);
- _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width,
- stencilMap, stencilVals);
-
- _mesa_pack_depth_stencil_span(ctx, width, type, (GLuint *)dst,
- depthVals, stencilVals, packing);
-
- depthMap += depthStride;
- stencilMap += stencilStride;
- dst += dstStride;
- }
-
- ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
- ctx->Driver.UnmapRenderbuffer(ctx, stencilRb);
-}
-
-
-/**
- * Read combined depth/stencil values.
- * We'll have already done error checking to be sure the expected
- * depth and stencil buffers really exist.
- */
-static void
-read_depth_stencil_pixels(struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- const GLboolean scaleOrBias
- = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
- const GLboolean stencilTransfer = ctx->Pixel.IndexShift
- || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
- GLubyte *dst;
- int dstStride;
-
- dst = (GLubyte *) _mesa_image_address2d(packing, pixels,
- width, height,
- GL_DEPTH_STENCIL_EXT,
- type, 0, 0);
- dstStride = _mesa_image_row_stride(packing, width,
- GL_DEPTH_STENCIL_EXT, type);
-
- /* Fast 24/8 reads. */
- if (type == GL_UNSIGNED_INT_24_8 &&
- !scaleOrBias && !stencilTransfer && !packing->SwapBytes) {
- if (fast_read_depth_stencil_pixels(ctx, x, y, width, height,
- dst, dstStride))
- return;
-
- if (fast_read_depth_stencil_pixels_separate(ctx, x, y, width, height,
- (uint32_t *)dst, dstStride))
- return;
- }
-
- slow_read_depth_stencil_pixels_separate(ctx, x, y, width, height,
- type, packing,
- dst, dstStride);
-}
-
-
-
-/**
- * Software fallback routine for ctx->Driver.ReadPixels().
- * By time we get here, all error checking will have been done.
- */
-void
-_swrast_ReadPixels( struct gl_context *ctx,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *packing,
- GLvoid *pixels )
-{
- struct gl_pixelstore_attrib clippedPacking = *packing;
-
- if (ctx->NewState)
- _mesa_update_state(ctx);
-
- /* Do all needed clipping here, so that we can forget about it later */
- if (_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
-
- pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
-
- if (pixels) {
- switch (format) {
- case GL_STENCIL_INDEX:
- read_stencil_pixels(ctx, x, y, width, height, type, pixels,
- &clippedPacking);
- break;
- case GL_DEPTH_COMPONENT:
- read_depth_pixels(ctx, x, y, width, height, type, pixels,
- &clippedPacking);
- break;
- case GL_DEPTH_STENCIL_EXT:
- read_depth_stencil_pixels(ctx, x, y, width, height, type, pixels,
- &clippedPacking);
- break;
- default:
- /* all other formats should be color formats */
- read_rgba_pixels(ctx, x, y, width, height, format, type, pixels,
- &clippedPacking);
- }
-
- _mesa_unmap_pbo_dest(ctx, &clippedPacking);
- }
- }
-}
diff --git a/mesalib/src/mesa/swrast/s_stencil.c b/mesalib/src/mesa/swrast/s_stencil.c
index e713e2393..101ee5056 100644
--- a/mesalib/src/mesa/swrast/s_stencil.c
+++ b/mesalib/src/mesa/swrast/s_stencil.c
@@ -62,12 +62,12 @@ ENDIF
*/
static void
apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
- GLuint n, GLstencil stencil[], const GLubyte mask[] )
+ GLuint n, GLubyte stencil[], const GLubyte mask[] )
{
- const GLstencil ref = ctx->Stencil.Ref[face];
- const GLstencil wrtmask = ctx->Stencil.WriteMask[face];
- const GLstencil invmask = (GLstencil) (~wrtmask);
- const GLstencil stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
+ const GLubyte ref = ctx->Stencil.Ref[face];
+ const GLubyte wrtmask = ctx->Stencil.WriteMask[face];
+ const GLubyte invmask = (GLubyte) (~wrtmask);
+ const GLubyte stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
GLuint i;
switch (oper) {
@@ -85,7 +85,7 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- stencil[i] = (GLstencil) (stencil[i] & invmask);
+ stencil[i] = (GLubyte) (stencil[i] & invmask);
}
}
}
@@ -101,8 +101,8 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil s = stencil[i];
- stencil[i] = (GLstencil) ((invmask & s ) | (wrtmask & ref));
+ GLubyte s = stencil[i];
+ stencil[i] = (GLubyte) ((invmask & s ) | (wrtmask & ref));
}
}
}
@@ -111,9 +111,9 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil s = stencil[i];
+ GLubyte s = stencil[i];
if (s < stencilMax) {
- stencil[i] = (GLstencil) (s+1);
+ stencil[i] = (GLubyte) (s+1);
}
}
}
@@ -122,9 +122,9 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
for (i=0;i<n;i++) {
if (mask[i]) {
/* VERIFY logic of adding 1 to a write-masked value */
- GLstencil s = stencil[i];
+ GLubyte s = stencil[i];
if (s < stencilMax) {
- stencil[i] = (GLstencil) ((invmask & s) | (wrtmask & (s+1)));
+ stencil[i] = (GLubyte) ((invmask & s) | (wrtmask & (s+1)));
}
}
}
@@ -134,9 +134,9 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil s = stencil[i];
+ GLubyte s = stencil[i];
if (s>0) {
- stencil[i] = (GLstencil) (s-1);
+ stencil[i] = (GLubyte) (s-1);
}
}
}
@@ -145,9 +145,9 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
for (i=0;i<n;i++) {
if (mask[i]) {
/* VERIFY logic of subtracting 1 to a write-masked value */
- GLstencil s = stencil[i];
+ GLubyte s = stencil[i];
if (s>0) {
- stencil[i] = (GLstencil) ((invmask & s) | (wrtmask & (s-1)));
+ stencil[i] = (GLubyte) ((invmask & s) | (wrtmask & (s-1)));
}
}
}
@@ -164,8 +164,8 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil s = stencil[i];
- stencil[i] = (GLstencil) ((invmask & s) | (wrtmask & (s+1)));
+ GLubyte s = stencil[i];
+ stencil[i] = (GLubyte) ((invmask & s) | (wrtmask & (s+1)));
}
}
}
@@ -181,8 +181,8 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil s = stencil[i];
- stencil[i] = (GLstencil) ((invmask & s) | (wrtmask & (s-1)));
+ GLubyte s = stencil[i];
+ stencil[i] = (GLubyte) ((invmask & s) | (wrtmask & (s-1)));
}
}
}
@@ -191,16 +191,16 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil s = stencil[i];
- stencil[i] = (GLstencil) ~s;
+ GLubyte s = stencil[i];
+ stencil[i] = (GLubyte) ~s;
}
}
}
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil s = stencil[i];
- stencil[i] = (GLstencil) ((invmask & s) | (wrtmask & ~s));
+ GLubyte s = stencil[i];
+ stencil[i] = (GLubyte) ((invmask & s) | (wrtmask & ~s));
}
}
}
@@ -225,15 +225,15 @@ apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
* Return: GL_FALSE = all pixels failed, GL_TRUE = zero or more pixels passed.
*/
static GLboolean
-do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stencil[],
+do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLubyte stencil[],
GLubyte mask[] )
{
GLubyte fail[MAX_WIDTH];
GLboolean allfail = GL_FALSE;
GLuint i;
const GLuint valueMask = ctx->Stencil.ValueMask[face];
- const GLstencil r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
- GLstencil s;
+ const GLubyte r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
+ GLubyte s;
ASSERT(n <= MAX_WIDTH);
@@ -263,7 +263,7 @@ do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stenci
case GL_LESS:
for (i=0;i<n;i++) {
if (mask[i]) {
- s = (GLstencil) (stencil[i] & valueMask);
+ s = (GLubyte) (stencil[i] & valueMask);
if (r < s) {
/* passed */
fail[i] = 0;
@@ -281,7 +281,7 @@ do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stenci
case GL_LEQUAL:
for (i=0;i<n;i++) {
if (mask[i]) {
- s = (GLstencil) (stencil[i] & valueMask);
+ s = (GLubyte) (stencil[i] & valueMask);
if (r <= s) {
/* pass */
fail[i] = 0;
@@ -299,7 +299,7 @@ do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stenci
case GL_GREATER:
for (i=0;i<n;i++) {
if (mask[i]) {
- s = (GLstencil) (stencil[i] & valueMask);
+ s = (GLubyte) (stencil[i] & valueMask);
if (r > s) {
/* passed */
fail[i] = 0;
@@ -317,7 +317,7 @@ do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stenci
case GL_GEQUAL:
for (i=0;i<n;i++) {
if (mask[i]) {
- s = (GLstencil) (stencil[i] & valueMask);
+ s = (GLubyte) (stencil[i] & valueMask);
if (r >= s) {
/* passed */
fail[i] = 0;
@@ -335,7 +335,7 @@ do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stenci
case GL_EQUAL:
for (i=0;i<n;i++) {
if (mask[i]) {
- s = (GLstencil) (stencil[i] & valueMask);
+ s = (GLubyte) (stencil[i] & valueMask);
if (r == s) {
/* passed */
fail[i] = 0;
@@ -353,7 +353,7 @@ do_stencil_test( struct gl_context *ctx, GLuint face, GLuint n, GLstencil stenci
case GL_NOTEQUAL:
for (i=0;i<n;i++) {
if (mask[i]) {
- s = (GLstencil) (stencil[i] & valueMask);
+ s = (GLubyte) (stencil[i] & valueMask);
if (r != s) {
/* passed */
fail[i] = 0;
@@ -422,8 +422,8 @@ stencil_and_ztest_span(struct gl_context *ctx, SWspan *span, GLuint face)
{
struct gl_framebuffer *fb = ctx->DrawBuffer;
struct gl_renderbuffer *rb = fb->_StencilBuffer;
- GLstencil stencilRow[MAX_WIDTH];
- GLstencil *stencil;
+ GLubyte stencilRow[MAX_WIDTH];
+ GLubyte *stencil;
const GLuint n = span->end;
const GLint x = span->x;
const GLint y = span->y;
@@ -438,7 +438,7 @@ stencil_and_ztest_span(struct gl_context *ctx, SWspan *span, GLuint face)
}
#endif
- stencil = (GLstencil *) rb->GetPointer(ctx, rb, x, y);
+ stencil = (GLubyte *) rb->GetPointer(ctx, rb, x, y);
if (!stencil) {
rb->GetRow(ctx, rb, n, x, y, stencilRow);
stencil = stencilRow;
@@ -531,16 +531,15 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
{
struct gl_framebuffer *fb = ctx->DrawBuffer;
struct gl_renderbuffer *rb = fb->_StencilBuffer;
- const GLstencil stencilMax = (1 << fb->Visual.stencilBits) - 1;
- const GLstencil ref = ctx->Stencil.Ref[face];
- const GLstencil wrtmask = ctx->Stencil.WriteMask[face];
- const GLstencil invmask = (GLstencil) (~wrtmask);
+ const GLubyte stencilMax = (1 << fb->Visual.stencilBits) - 1;
+ const GLubyte ref = ctx->Stencil.Ref[face];
+ const GLubyte wrtmask = ctx->Stencil.WriteMask[face];
+ const GLubyte invmask = (GLubyte) (~wrtmask);
GLuint i;
- GLstencil *stencilStart = (GLubyte *) rb->Data;
+ GLubyte *stencilStart = (GLubyte *) rb->Data;
const GLuint stride = rb->Width;
ASSERT(rb->GetPointer(ctx, rb, 0, 0));
- ASSERT(sizeof(GLstencil) == 1);
switch (oper) {
case GL_KEEP:
@@ -550,7 +549,7 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
*sptr = 0;
}
}
@@ -558,8 +557,8 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) (invmask & *sptr);
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) (invmask & *sptr);
}
}
}
@@ -568,7 +567,7 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
*sptr = ref;
}
}
@@ -576,8 +575,8 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) ((invmask & *sptr ) | (wrtmask & ref));
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) ((invmask & *sptr ) | (wrtmask & ref));
}
}
}
@@ -586,9 +585,9 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
if (*sptr < stencilMax) {
- *sptr = (GLstencil) (*sptr + 1);
+ *sptr = (GLubyte) (*sptr + 1);
}
}
}
@@ -596,9 +595,9 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
if (*sptr < stencilMax) {
- *sptr = (GLstencil) ((invmask & *sptr) | (wrtmask & (*sptr+1)));
+ *sptr = (GLubyte) ((invmask & *sptr) | (wrtmask & (*sptr+1)));
}
}
}
@@ -608,9 +607,9 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
if (*sptr>0) {
- *sptr = (GLstencil) (*sptr - 1);
+ *sptr = (GLubyte) (*sptr - 1);
}
}
}
@@ -618,9 +617,9 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
if (*sptr>0) {
- *sptr = (GLstencil) ((invmask & *sptr) | (wrtmask & (*sptr-1)));
+ *sptr = (GLubyte) ((invmask & *sptr) | (wrtmask & (*sptr-1)));
}
}
}
@@ -630,16 +629,16 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) (*sptr + 1);
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) (*sptr + 1);
}
}
}
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) ((invmask & *sptr) | (wrtmask & (*sptr+1)));
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) ((invmask & *sptr) | (wrtmask & (*sptr+1)));
}
}
}
@@ -648,16 +647,16 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) (*sptr - 1);
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) (*sptr - 1);
}
}
}
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) ((invmask & *sptr) | (wrtmask & (*sptr-1)));
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) ((invmask & *sptr) | (wrtmask & (*sptr-1)));
}
}
}
@@ -666,16 +665,16 @@ apply_stencil_op_to_pixels( struct gl_context *ctx,
if (invmask==0) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) (~*sptr);
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) (~*sptr);
}
}
}
else {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLstencil *sptr = STENCIL_ADDRESS( x[i], y[i] );
- *sptr = (GLstencil) ((invmask & *sptr) | (wrtmask & ~*sptr));
+ GLubyte *sptr = STENCIL_ADDRESS( x[i], y[i] );
+ *sptr = (GLubyte) ((invmask & *sptr) | (wrtmask & ~*sptr));
}
}
}
@@ -705,15 +704,14 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
const struct gl_framebuffer *fb = ctx->DrawBuffer;
struct gl_renderbuffer *rb = fb->_StencilBuffer;
GLubyte fail[MAX_WIDTH];
- GLstencil r, s;
+ GLubyte r, s;
GLuint i;
GLboolean allfail = GL_FALSE;
const GLuint valueMask = ctx->Stencil.ValueMask[face];
- const GLstencil *stencilStart = (GLstencil *) rb->Data;
+ const GLubyte *stencilStart = (GLubyte *) rb->Data;
const GLuint stride = rb->Width;
ASSERT(rb->GetPointer(ctx, rb, 0, 0));
- ASSERT(sizeof(GLstencil) == 1);
/*
* Perform stencil test. The results of this operation are stored
@@ -740,11 +738,11 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
allfail = GL_TRUE;
break;
case GL_LESS:
- r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
+ r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
for (i=0;i<n;i++) {
if (mask[i]) {
- const GLstencil *sptr = STENCIL_ADDRESS(x[i],y[i]);
- s = (GLstencil) (*sptr & valueMask);
+ const GLubyte *sptr = STENCIL_ADDRESS(x[i],y[i]);
+ s = (GLubyte) (*sptr & valueMask);
if (r < s) {
/* passed */
fail[i] = 0;
@@ -760,11 +758,11 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
}
break;
case GL_LEQUAL:
- r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
+ r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
for (i=0;i<n;i++) {
if (mask[i]) {
- const GLstencil *sptr = STENCIL_ADDRESS(x[i],y[i]);
- s = (GLstencil) (*sptr & valueMask);
+ const GLubyte *sptr = STENCIL_ADDRESS(x[i],y[i]);
+ s = (GLubyte) (*sptr & valueMask);
if (r <= s) {
/* pass */
fail[i] = 0;
@@ -780,11 +778,11 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
}
break;
case GL_GREATER:
- r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
+ r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
for (i=0;i<n;i++) {
if (mask[i]) {
- const GLstencil *sptr = STENCIL_ADDRESS(x[i],y[i]);
- s = (GLstencil) (*sptr & valueMask);
+ const GLubyte *sptr = STENCIL_ADDRESS(x[i],y[i]);
+ s = (GLubyte) (*sptr & valueMask);
if (r > s) {
/* passed */
fail[i] = 0;
@@ -800,11 +798,11 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
}
break;
case GL_GEQUAL:
- r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
+ r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
for (i=0;i<n;i++) {
if (mask[i]) {
- const GLstencil *sptr = STENCIL_ADDRESS(x[i],y[i]);
- s = (GLstencil) (*sptr & valueMask);
+ const GLubyte *sptr = STENCIL_ADDRESS(x[i],y[i]);
+ s = (GLubyte) (*sptr & valueMask);
if (r >= s) {
/* passed */
fail[i] = 0;
@@ -820,11 +818,11 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
}
break;
case GL_EQUAL:
- r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
+ r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
for (i=0;i<n;i++) {
if (mask[i]) {
- const GLstencil *sptr = STENCIL_ADDRESS(x[i],y[i]);
- s = (GLstencil) (*sptr & valueMask);
+ const GLubyte *sptr = STENCIL_ADDRESS(x[i],y[i]);
+ s = (GLubyte) (*sptr & valueMask);
if (r == s) {
/* passed */
fail[i] = 0;
@@ -840,11 +838,11 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, GLuint n,
}
break;
case GL_NOTEQUAL:
- r = (GLstencil) (ctx->Stencil.Ref[face] & valueMask);
+ r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
for (i=0;i<n;i++) {
if (mask[i]) {
- const GLstencil *sptr = STENCIL_ADDRESS(x[i],y[i]);
- s = (GLstencil) (*sptr & valueMask);
+ const GLubyte *sptr = STENCIL_ADDRESS(x[i],y[i]);
+ s = (GLubyte) (*sptr & valueMask);
if (r != s) {
/* passed */
fail[i] = 0;
@@ -914,7 +912,7 @@ stencil_and_ztest_pixels( struct gl_context *ctx, SWspan *span, GLuint face )
if (!rb->GetPointer(ctx, rb, 0, 0)) {
/* No direct access */
- GLstencil stencil[MAX_WIDTH];
+ GLubyte stencil[MAX_WIDTH];
ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
_swrast_get_values(ctx, rb, n, x, y, stencil, sizeof(GLubyte));
@@ -1044,7 +1042,7 @@ clip_span(GLuint bufferWidth, GLuint bufferHeight,
*/
void
_swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint n, GLint x, GLint y, GLstencil stencil[])
+ GLint n, GLint x, GLint y, GLubyte stencil[])
{
if (y < 0 || y >= (GLint) rb->Height ||
x + n <= 0 || x >= (GLint) rb->Width) {
@@ -1081,7 +1079,7 @@ _swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
*/
void
_swrast_write_stencil_span(struct gl_context *ctx, GLint n, GLint x, GLint y,
- const GLstencil stencil[] )
+ const GLubyte stencil[] )
{
struct gl_framebuffer *fb = ctx->DrawBuffer;
struct gl_renderbuffer *rb = fb->_StencilBuffer;
@@ -1109,7 +1107,7 @@ _swrast_write_stencil_span(struct gl_context *ctx, GLint n, GLint x, GLint y,
if ((stencilMask & stencilMax) != stencilMax) {
/* need to apply writemask */
- GLstencil destVals[MAX_WIDTH], newVals[MAX_WIDTH];
+ GLubyte destVals[MAX_WIDTH], newVals[MAX_WIDTH];
GLint i;
rb->GetRow(ctx, rb, n, x, y, destVals);
for (i = 0; i < n; i++) {
diff --git a/mesalib/src/mesa/swrast/s_stencil.h b/mesalib/src/mesa/swrast/s_stencil.h
index 0bcfb799f..37f3c8da1 100644
--- a/mesalib/src/mesa/swrast/s_stencil.h
+++ b/mesalib/src/mesa/swrast/s_stencil.h
@@ -1,53 +1,53 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.3
- *
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
- *
- * 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
- * BRIAN PAUL 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 S_STENCIL_H
-#define S_STENCIL_H
-
-
-#include "main/mtypes.h"
-#include "s_span.h"
-
-
-
-extern GLboolean
-_swrast_stencil_and_ztest_span(struct gl_context *ctx, SWspan *span);
-
-
-extern void
-_swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint n, GLint x, GLint y, GLstencil stencil[]);
-
-
-extern void
-_swrast_write_stencil_span( struct gl_context *ctx, GLint n, GLint x, GLint y,
- const GLstencil stencil[] );
-
-
-extern void
-_swrast_clear_stencil_buffer( struct gl_context *ctx, struct gl_renderbuffer *rb );
-
-
-#endif
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.3
+ *
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ *
+ * 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
+ * BRIAN PAUL 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 S_STENCIL_H
+#define S_STENCIL_H
+
+
+#include "main/mtypes.h"
+#include "s_span.h"
+
+
+
+extern GLboolean
+_swrast_stencil_and_ztest_span(struct gl_context *ctx, SWspan *span);
+
+
+extern void
+_swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLint n, GLint x, GLint y, GLubyte stencil[]);
+
+
+extern void
+_swrast_write_stencil_span( struct gl_context *ctx, GLint n, GLint x, GLint y,
+ const GLubyte stencil[] );
+
+
+extern void
+_swrast_clear_stencil_buffer( struct gl_context *ctx, struct gl_renderbuffer *rb );
+
+
+#endif
diff --git a/mesalib/src/mesa/swrast/s_texrender.c b/mesalib/src/mesa/swrast/s_texrender.c
index 83e7a6a03..3734ce6d5 100644
--- a/mesalib/src/mesa/swrast/s_texrender.c
+++ b/mesalib/src/mesa/swrast/s_texrender.c
@@ -567,6 +567,19 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
trb->Base.InternalFormat = trb->TexImage->Base.InternalFormat;
trb->Base.Format = trb->TexImage->Base.TexFormat;
+ /* Set the gl_renderbuffer::Data field so that mapping the buffer
+ * in renderbuffer.c succeeds.
+ */
+ if (att->Texture->Target == GL_TEXTURE_3D ||
+ att->Texture->Target == GL_TEXTURE_2D_ARRAY_EXT) {
+ trb->Base.Data = trb->TexImage->Buffer +
+ trb->TexImage->ImageOffsets[trb->Zoffset] *
+ _mesa_get_format_bytes(trb->TexImage->Base.TexFormat);
+ }
+ else {
+ trb->Base.Data = trb->TexImage->Buffer;
+ }
+
/* XXX may need more special cases here */
switch (trb->TexImage->Base.TexFormat) {
case MESA_FORMAT_Z24_S8:
diff --git a/mesalib/src/mesa/swrast/s_zoom.c b/mesalib/src/mesa/swrast/s_zoom.c
index 3fb784847..16bb997f3 100644
--- a/mesalib/src/mesa/swrast/s_zoom.c
+++ b/mesalib/src/mesa/swrast/s_zoom.c
@@ -351,9 +351,9 @@ _swrast_write_zoomed_depth_span(struct gl_context *ctx, GLint imgX, GLint imgY,
void
_swrast_write_zoomed_stencil_span(struct gl_context *ctx, GLint imgX, GLint imgY,
GLint width, GLint spanX, GLint spanY,
- const GLstencil stencil[])
+ const GLubyte stencil[])
{
- GLstencil zoomedVals[MAX_WIDTH];
+ GLubyte zoomedVals[MAX_WIDTH];
GLint x0, x1, y0, y1, y;
GLint i, zoomedWidth;
diff --git a/mesalib/src/mesa/swrast/s_zoom.h b/mesalib/src/mesa/swrast/s_zoom.h
index b8d17b5a4..0b82bb824 100644
--- a/mesalib/src/mesa/swrast/s_zoom.h
+++ b/mesalib/src/mesa/swrast/s_zoom.h
@@ -1,56 +1,56 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.5
- *
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
- *
- * 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
- * BRIAN PAUL 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 S_ZOOM_H
-#define S_ZOOM_H
-
-#include "main/mtypes.h"
-#include "s_span.h"
-
-
-extern void
-_swrast_write_zoomed_rgba_span(struct gl_context *ctx, GLint imgX, GLint imgY,
- const SWspan *span, const GLvoid *rgba);
-
-extern void
-_swrast_write_zoomed_rgb_span(struct gl_context *ctx, GLint imgX, GLint imgY,
- const SWspan *span, const GLvoid *rgb);
-
-extern void
-_swrast_write_zoomed_depth_span(struct gl_context *ctx, GLint imgX, GLint imgY,
- const SWspan *span);
-
-
-extern void
-_swrast_write_zoomed_stencil_span(struct gl_context *ctx, GLint imgX, GLint imgY,
- GLint width, GLint spanX, GLint spanY,
- const GLstencil stencil[]);
-
-extern void
-_swrast_write_zoomed_z_span(struct gl_context *ctx, GLint imgX, GLint imgY,
- GLint width, GLint spanX, GLint spanY,
- const GLvoid *z);
-
-
-#endif
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ *
+ * 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
+ * BRIAN PAUL 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 S_ZOOM_H
+#define S_ZOOM_H
+
+#include "main/mtypes.h"
+#include "s_span.h"
+
+
+extern void
+_swrast_write_zoomed_rgba_span(struct gl_context *ctx, GLint imgX, GLint imgY,
+ const SWspan *span, const GLvoid *rgba);
+
+extern void
+_swrast_write_zoomed_rgb_span(struct gl_context *ctx, GLint imgX, GLint imgY,
+ const SWspan *span, const GLvoid *rgb);
+
+extern void
+_swrast_write_zoomed_depth_span(struct gl_context *ctx, GLint imgX, GLint imgY,
+ const SWspan *span);
+
+
+extern void
+_swrast_write_zoomed_stencil_span(struct gl_context *ctx, GLint imgX, GLint imgY,
+ GLint width, GLint spanX, GLint spanY,
+ const GLubyte stencil[]);
+
+extern void
+_swrast_write_zoomed_z_span(struct gl_context *ctx, GLint imgX, GLint imgY,
+ GLint width, GLint spanX, GLint spanY,
+ const GLvoid *z);
+
+
+#endif
diff --git a/mesalib/src/mesa/swrast/swrast.h b/mesalib/src/mesa/swrast/swrast.h
index 08d565ba0..17b66c664 100644
--- a/mesalib/src/mesa/swrast/swrast.h
+++ b/mesalib/src/mesa/swrast/swrast.h
@@ -119,13 +119,6 @@ _swrast_DrawPixels( struct gl_context *ctx,
const GLvoid *pixels );
extern void
-_swrast_ReadPixels( struct gl_context *ctx,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- GLvoid *pixels );
-
-extern void
_swrast_BlitFramebuffer(struct gl_context *ctx,
GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,