glsl: add ir_variable::determine_interpolation_mode() function.
authorPaul Berry <stereotype441@gmail.com>
Fri, 21 Oct 2011 14:55:48 +0000 (07:55 -0700)
committerPaul Berry <stereotype441@gmail.com>
Thu, 27 Oct 2011 22:31:32 +0000 (15:31 -0700)
This function determines how a variable should be interpolated based
both on interpolation qualifiers and the current shade model.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/ir.cpp
src/glsl/ir.h

index 9aad0fcd42fa1107455a7376a770ee665337a0f4..ef7300e6535292946f4d1396905c526bcf5b8464 100644 (file)
@@ -1354,6 +1354,21 @@ ir_variable::interpolation_string() const
 }
 
 
+glsl_interp_qualifier
+ir_variable::determine_interpolation_mode(bool flat_shade)
+{
+   if (this->interpolation != INTERP_QUALIFIER_NONE)
+      return (glsl_interp_qualifier) this->interpolation;
+   int location = this->location;
+   bool is_gl_Color =
+      location == FRAG_ATTRIB_COL0 || location == FRAG_ATTRIB_COL1;
+   if (flat_shade && is_gl_Color)
+      return INTERP_QUALIFIER_FLAT;
+   else
+      return INTERP_QUALIFIER_SMOOTH;
+}
+
+
 ir_function_signature::ir_function_signature(const glsl_type *return_type)
    : return_type(return_type), is_defined(false), _function(NULL)
 {
index 0c0cccbd034cb4e079ac30dd8ef15869444559eb..404d4cffa91436bc58c20032d2a41e5e4ac21f2b 100644 (file)
@@ -291,6 +291,17 @@ public:
     */
    const char *interpolation_string() const;
 
+   /**
+    * Determine how this variable should be interpolated based on its
+    * interpolation qualifier (if present), whether it is gl_Color or
+    * gl_SecondaryColor, and whether flatshading is enabled in the current GL
+    * state.
+    *
+    * The return value will always be either INTERP_QUALIFIER_SMOOTH,
+    * INTERP_QUALIFIER_NOPERSPECTIVE, or INTERP_QUALIFIER_FLAT.
+    */
+   glsl_interp_qualifier determine_interpolation_mode(bool flat_shade);
+
    /**
     * Delcared name of the variable
     */