2011-12-08 14:44:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrGLSL_DEFINED
|
|
|
|
#define GrGLSL_DEFINED
|
|
|
|
|
2013-03-12 12:26:08 +00:00
|
|
|
#include "GrTypesPriv.h"
|
Express (GLSL expression, possibly known value) pairs as a class
Express (GLSL expression, possibly known value) pairs as a class
instead of two variables Introduces GrGLSLExpr<N> to encapsulate
the expression and possibly constant-folded value of the expression.
This simplifies passing of the expressions to functions.
Changes the shaders with following patterns:
{ // Stage 0: Linear Gradient
vec4 colorTemp = mix(uGradientStartColor_Stage0, uGradientEndColor_Stage0, clamp(vMatrixCoord_Stage0.x, 0.0, 1
colorTemp.rgb *= colorTemp.a;
- output_Stage0 = vec4((vColor) * (colorTemp));
+ output_Stage0 = (vColor * colorTemp);
+ }
Previously the vector cast was always added if constant folding was
effective, regardless of the term dimensions. Now the vector upcast is
not inserted in places where it is not needed, ie. when the binary
operator term is of the target dimension.
Also, some parentheses can be omitted. It is assumed that
GrGLSLExpr<N>("string") constructors construct a simple expression or
parenthesized expression.
Otherwise the shader code remains identical.
R=jvanverth@google.com, bsalomon@google.com, robertphillips@google.com
Author: kkinnunen@nvidia.com
Review URL: https://codereview.chromium.org/25048002
git-svn-id: http://skia.googlecode.com/svn/trunk@11690 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-10 06:30:18 +00:00
|
|
|
#include "SkString.h"
|
2011-12-08 14:44:10 +00:00
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
class GrShaderCaps;
|
2015-10-26 15:38:25 +00:00
|
|
|
|
2011-12-08 14:44:10 +00:00
|
|
|
// Limited set of GLSL versions we build shaders for. Caller should round
|
|
|
|
// down the GLSL version to one of these enums.
|
|
|
|
enum GrGLSLGeneration {
|
|
|
|
/**
|
2012-10-23 14:31:30 +00:00
|
|
|
* Desktop GLSL 1.10 and ES2 shading language (based on desktop GLSL 1.20)
|
2011-12-08 14:44:10 +00:00
|
|
|
*/
|
2012-02-10 15:56:06 +00:00
|
|
|
k110_GrGLSLGeneration,
|
2011-12-08 14:44:10 +00:00
|
|
|
/**
|
|
|
|
* Desktop GLSL 1.30
|
|
|
|
*/
|
2012-02-10 15:56:06 +00:00
|
|
|
k130_GrGLSLGeneration,
|
2011-12-08 14:44:10 +00:00
|
|
|
/**
|
2012-10-23 14:31:30 +00:00
|
|
|
* Desktop GLSL 1.40
|
|
|
|
*/
|
|
|
|
k140_GrGLSLGeneration,
|
|
|
|
/**
|
|
|
|
* Desktop GLSL 1.50
|
2011-12-08 14:44:10 +00:00
|
|
|
*/
|
2012-02-10 15:56:06 +00:00
|
|
|
k150_GrGLSLGeneration,
|
2014-10-17 13:07:08 +00:00
|
|
|
/**
|
|
|
|
* Desktop GLSL 3.30, and ES GLSL 3.00
|
|
|
|
*/
|
|
|
|
k330_GrGLSLGeneration,
|
2016-02-22 15:55:44 +00:00
|
|
|
/**
|
|
|
|
* Desktop GLSL 4.00
|
|
|
|
*/
|
|
|
|
k400_GrGLSLGeneration,
|
2016-11-15 18:26:08 +00:00
|
|
|
/**
|
|
|
|
* Desktop GLSL 4.20
|
|
|
|
*/
|
|
|
|
k420_GrGLSLGeneration,
|
2014-10-17 13:07:08 +00:00
|
|
|
/**
|
|
|
|
* ES GLSL 3.10 only TODO Make GLSLCap objects to make this more granular
|
|
|
|
*/
|
|
|
|
k310es_GrGLSLGeneration,
|
2016-02-22 15:55:44 +00:00
|
|
|
/**
|
|
|
|
* ES GLSL 3.20
|
|
|
|
*/
|
|
|
|
k320es_GrGLSLGeneration,
|
2011-12-08 14:44:10 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 15:49:34 +00:00
|
|
|
bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration);
|
|
|
|
|
2015-10-26 15:38:25 +00:00
|
|
|
/**
|
|
|
|
* Adds a line of GLSL code to declare the default precision for float types.
|
|
|
|
*/
|
|
|
|
void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision,
|
2016-11-29 18:43:05 +00:00
|
|
|
const GrShaderCaps&,
|
2015-10-26 15:38:25 +00:00
|
|
|
SkString* out);
|
|
|
|
|
2016-04-11 18:30:50 +00:00
|
|
|
/**
|
|
|
|
* Converts a GrSLPrecision to its corresponding GLSL precision qualifier.
|
|
|
|
*/
|
|
|
|
static inline const char* GrGLSLPrecisionString(GrSLPrecision p) {
|
|
|
|
switch (p) {
|
|
|
|
case kLow_GrSLPrecision:
|
|
|
|
return "lowp";
|
|
|
|
case kMedium_GrSLPrecision:
|
|
|
|
return "mediump";
|
|
|
|
case kHigh_GrSLPrecision:
|
|
|
|
return "highp";
|
2017-04-05 13:26:15 +00:00
|
|
|
case kDefault_GrSLPrecision:
|
|
|
|
return "";
|
2016-04-11 18:30:50 +00:00
|
|
|
default:
|
2017-08-16 14:53:04 +00:00
|
|
|
SK_ABORT("Unexpected precision type.");
|
2016-04-11 18:30:50 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:36:09 +00:00
|
|
|
/**
|
|
|
|
* Converts a GrSLType to a string containing the name of the equivalent GLSL type.
|
|
|
|
*/
|
2017-08-25 12:45:21 +00:00
|
|
|
const char* GrGLSLTypeString(const GrShaderCaps* shaderCaps, GrSLType t);
|
2012-02-10 15:56:06 +00:00
|
|
|
|
|
|
|
#endif
|