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";
|
|
|
|
default:
|
|
|
|
SkFAIL("Unexpected precision type.");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:36:09 +00:00
|
|
|
/**
|
|
|
|
* Converts a GrSLType to a string containing the name of the equivalent GLSL type.
|
|
|
|
*/
|
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
|
|
|
static inline const char* GrGLSLTypeString(GrSLType t) {
|
2013-04-18 19:36:09 +00:00
|
|
|
switch (t) {
|
|
|
|
case kVoid_GrSLType:
|
|
|
|
return "void";
|
|
|
|
case kFloat_GrSLType:
|
|
|
|
return "float";
|
|
|
|
case kVec2f_GrSLType:
|
|
|
|
return "vec2";
|
|
|
|
case kVec3f_GrSLType:
|
|
|
|
return "vec3";
|
|
|
|
case kVec4f_GrSLType:
|
|
|
|
return "vec4";
|
2017-02-08 19:56:27 +00:00
|
|
|
case kVec2i_GrSLType:
|
|
|
|
return "ivec2";
|
|
|
|
case kVec3i_GrSLType:
|
|
|
|
return "ivec3";
|
|
|
|
case kVec4i_GrSLType:
|
|
|
|
return "ivec4";
|
2016-03-07 23:39:09 +00:00
|
|
|
case kMat22f_GrSLType:
|
|
|
|
return "mat2";
|
2013-04-18 19:36:09 +00:00
|
|
|
case kMat33f_GrSLType:
|
|
|
|
return "mat3";
|
|
|
|
case kMat44f_GrSLType:
|
|
|
|
return "mat4";
|
Add Texture2D and Sampler GrSLTypes
These two new types are in support of Vulkan and the ability to send
separate texture and sampler uniforms to the shader. They don't really fit
well in the current system, since the current system ties together to idea
of intended use and how to emit shader code into the same GrSLType enum.
In vulkan, I want the GrGLSLSampler object to be used as a Sampler2D, but
when appending its declaration it will emit a Texture2D and sampler object.
Our query for GrSLTypeIsSamplerType refers more to the combination of texture
and sampler and not just the sampler part. The GrSLTypeIs2DTextureType query
is for is a a SamplerType that uses Texture2Ds. My new types don't really fit
into either these categories as they are just half of the whole.
In some refactoring down the road (possibly connected with SkSL), I suggest we
split apart the concept of how we intend to use a GrGLSLSampler (Sampler2D, SamplerBuffer,
etc.), from how we actually add it to the code (sampler, texture2D, sampler2D, etc.).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2143143002
Review-Url: https://codereview.chromium.org/2143143002
2016-07-13 21:09:30 +00:00
|
|
|
case kTexture2DSampler_GrSLType:
|
2013-04-18 19:36:09 +00:00
|
|
|
return "sampler2D";
|
2016-11-16 17:55:57 +00:00
|
|
|
case kITexture2DSampler_GrSLType:
|
2016-11-11 21:08:03 +00:00
|
|
|
return "isampler2D";
|
Add Texture2D and Sampler GrSLTypes
These two new types are in support of Vulkan and the ability to send
separate texture and sampler uniforms to the shader. They don't really fit
well in the current system, since the current system ties together to idea
of intended use and how to emit shader code into the same GrSLType enum.
In vulkan, I want the GrGLSLSampler object to be used as a Sampler2D, but
when appending its declaration it will emit a Texture2D and sampler object.
Our query for GrSLTypeIsSamplerType refers more to the combination of texture
and sampler and not just the sampler part. The GrSLTypeIs2DTextureType query
is for is a a SamplerType that uses Texture2Ds. My new types don't really fit
into either these categories as they are just half of the whole.
In some refactoring down the road (possibly connected with SkSL), I suggest we
split apart the concept of how we intend to use a GrGLSLSampler (Sampler2D, SamplerBuffer,
etc.), from how we actually add it to the code (sampler, texture2D, sampler2D, etc.).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2143143002
Review-Url: https://codereview.chromium.org/2143143002
2016-07-13 21:09:30 +00:00
|
|
|
case kTextureExternalSampler_GrSLType:
|
2015-11-22 22:51:00 +00:00
|
|
|
return "samplerExternalOES";
|
Add Texture2D and Sampler GrSLTypes
These two new types are in support of Vulkan and the ability to send
separate texture and sampler uniforms to the shader. They don't really fit
well in the current system, since the current system ties together to idea
of intended use and how to emit shader code into the same GrSLType enum.
In vulkan, I want the GrGLSLSampler object to be used as a Sampler2D, but
when appending its declaration it will emit a Texture2D and sampler object.
Our query for GrSLTypeIsSamplerType refers more to the combination of texture
and sampler and not just the sampler part. The GrSLTypeIs2DTextureType query
is for is a a SamplerType that uses Texture2Ds. My new types don't really fit
into either these categories as they are just half of the whole.
In some refactoring down the road (possibly connected with SkSL), I suggest we
split apart the concept of how we intend to use a GrGLSLSampler (Sampler2D, SamplerBuffer,
etc.), from how we actually add it to the code (sampler, texture2D, sampler2D, etc.).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2143143002
Review-Url: https://codereview.chromium.org/2143143002
2016-07-13 21:09:30 +00:00
|
|
|
case kTexture2DRectSampler_GrSLType:
|
2016-01-14 17:24:09 +00:00
|
|
|
return "sampler2DRect";
|
2016-11-16 18:28:16 +00:00
|
|
|
case kBufferSampler_GrSLType:
|
2016-04-11 21:47:28 +00:00
|
|
|
return "samplerBuffer";
|
2016-01-30 17:59:10 +00:00
|
|
|
case kBool_GrSLType:
|
|
|
|
return "bool";
|
|
|
|
case kInt_GrSLType:
|
|
|
|
return "int";
|
2016-02-08 18:11:47 +00:00
|
|
|
case kUint_GrSLType:
|
|
|
|
return "uint";
|
Add Texture2D and Sampler GrSLTypes
These two new types are in support of Vulkan and the ability to send
separate texture and sampler uniforms to the shader. They don't really fit
well in the current system, since the current system ties together to idea
of intended use and how to emit shader code into the same GrSLType enum.
In vulkan, I want the GrGLSLSampler object to be used as a Sampler2D, but
when appending its declaration it will emit a Texture2D and sampler object.
Our query for GrSLTypeIsSamplerType refers more to the combination of texture
and sampler and not just the sampler part. The GrSLTypeIs2DTextureType query
is for is a a SamplerType that uses Texture2Ds. My new types don't really fit
into either these categories as they are just half of the whole.
In some refactoring down the road (possibly connected with SkSL), I suggest we
split apart the concept of how we intend to use a GrGLSLSampler (Sampler2D, SamplerBuffer,
etc.), from how we actually add it to the code (sampler, texture2D, sampler2D, etc.).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2143143002
Review-Url: https://codereview.chromium.org/2143143002
2016-07-13 21:09:30 +00:00
|
|
|
case kTexture2D_GrSLType:
|
|
|
|
return "texture2D";
|
|
|
|
case kSampler_GrSLType:
|
|
|
|
return "sampler";
|
2016-11-29 16:59:17 +00:00
|
|
|
case kImageStorage2D_GrSLType:
|
|
|
|
return "image2D";
|
|
|
|
case kIImageStorage2D_GrSLType:
|
|
|
|
return "iimage2D";
|
2013-04-18 19:36:09 +00:00
|
|
|
}
|
2016-11-11 21:08:03 +00:00
|
|
|
SkFAIL("Unknown shader var type.");
|
|
|
|
return ""; // suppress warning
|
2013-04-18 19:36:09 +00:00
|
|
|
}
|
2012-02-10 15:56:06 +00:00
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** A generic base-class representing a GLSL expression.
|
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
|
|
|
* The instance can be a variable name, expression or vecN(0) or vecN(1). Does simple constant
|
|
|
|
* folding with help of 1 and 0.
|
2013-10-23 05:42:03 +00:00
|
|
|
*
|
|
|
|
* Clients should not use this class, rather the specific instantiations defined
|
|
|
|
* later, for example GrGLSLExpr4.
|
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
|
|
|
*/
|
2013-10-23 05:42:03 +00:00
|
|
|
template <typename Self>
|
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
|
|
|
class GrGLSLExpr {
|
|
|
|
public:
|
2013-10-23 05:42:03 +00:00
|
|
|
bool isOnes() const { return kOnes_ExprType == fType; }
|
|
|
|
bool isZeros() const { return kZeros_ExprType == fType; }
|
|
|
|
|
|
|
|
const char* c_str() const {
|
|
|
|
if (kZeros_ExprType == fType) {
|
|
|
|
return Self::ZerosStr();
|
|
|
|
} else if (kOnes_ExprType == fType) {
|
|
|
|
return Self::OnesStr();
|
|
|
|
}
|
|
|
|
SkASSERT(!fExpr.isEmpty()); // Empty expressions should not be used.
|
|
|
|
return fExpr.c_str();
|
|
|
|
}
|
|
|
|
|
2014-11-08 17:24:25 +00:00
|
|
|
bool isValid() const {
|
|
|
|
return kFullExpr_ExprType != fType || !fExpr.isEmpty();
|
|
|
|
}
|
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
protected:
|
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
|
|
|
/** Constructs an invalid expression.
|
|
|
|
* Useful only as a return value from functions that never actually return
|
|
|
|
* this and instances that will be assigned to later. */
|
|
|
|
GrGLSLExpr()
|
|
|
|
: fType(kFullExpr_ExprType) {
|
|
|
|
// The only constructor that is allowed to build an empty expression.
|
|
|
|
SkASSERT(!this->isValid());
|
|
|
|
}
|
2012-04-18 17:49:20 +00:00
|
|
|
|
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
|
|
|
/** Constructs an expression with all components as value v */
|
|
|
|
explicit GrGLSLExpr(int v) {
|
|
|
|
if (v == 0) {
|
|
|
|
fType = kZeros_ExprType;
|
|
|
|
} else if (v == 1) {
|
|
|
|
fType = kOnes_ExprType;
|
|
|
|
} else {
|
|
|
|
fType = kFullExpr_ExprType;
|
2013-10-23 05:42:03 +00:00
|
|
|
fExpr.appendf(Self::CastIntStr(), v);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Constructs an expression from a string.
|
|
|
|
* Argument expr is a simple expression or a parenthesized expression. */
|
|
|
|
// TODO: make explicit once effects input Exprs.
|
|
|
|
GrGLSLExpr(const char expr[]) {
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == expr) { // TODO: remove this once effects input Exprs.
|
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
|
|
|
fType = kOnes_ExprType;
|
|
|
|
} else {
|
|
|
|
fType = kFullExpr_ExprType;
|
|
|
|
fExpr = expr;
|
|
|
|
}
|
|
|
|
SkASSERT(this->isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Constructs an expression from a string.
|
|
|
|
* Argument expr is a simple expression or a parenthesized expression. */
|
|
|
|
// TODO: make explicit once effects input Exprs.
|
|
|
|
GrGLSLExpr(const SkString& expr) {
|
|
|
|
if (expr.isEmpty()) { // TODO: remove this once effects input Exprs.
|
|
|
|
fType = kOnes_ExprType;
|
|
|
|
} else {
|
|
|
|
fType = kFullExpr_ExprType;
|
|
|
|
fExpr = expr;
|
|
|
|
}
|
|
|
|
SkASSERT(this->isValid());
|
|
|
|
}
|
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** Constructs an expression from a string with one substitution. */
|
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
|
|
|
GrGLSLExpr(const char format[], const char in0[])
|
|
|
|
: fType(kFullExpr_ExprType) {
|
|
|
|
fExpr.appendf(format, in0);
|
|
|
|
}
|
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** Constructs an expression from a string with two substitutions. */
|
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
|
|
|
GrGLSLExpr(const char format[], const char in0[], const char in1[])
|
|
|
|
: fType(kFullExpr_ExprType) {
|
|
|
|
fExpr.appendf(format, in0, in1);
|
|
|
|
}
|
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** Returns expression casted to another type.
|
|
|
|
* Generic implementation that is called for non-trivial cases of casts. */
|
|
|
|
template <typename T>
|
|
|
|
static Self VectorCastImpl(const T& other);
|
|
|
|
|
|
|
|
/** Returns a GLSL multiplication: component-wise or component-by-scalar.
|
|
|
|
* The multiplication will be component-wise or multiply each component by a scalar.
|
|
|
|
*
|
|
|
|
* The returned expression will compute the value of:
|
|
|
|
* vecN(in0.x * in1.x, ...) if dim(T0) == dim(T1) (component-wise)
|
|
|
|
* vecN(in0.x * in1, ...) if dim(T1) == 1 (vector by scalar)
|
|
|
|
* vecN(in0 * in1.x, ...) if dim(T0) == 1 (scalar by vector)
|
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
|
|
|
*/
|
2013-10-23 05:42:03 +00:00
|
|
|
template <typename T0, typename T1>
|
|
|
|
static Self Mul(T0 in0, T1 in1);
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** Returns a GLSL addition: component-wise or add a scalar to each component.
|
|
|
|
* Return value computes:
|
|
|
|
* vecN(in0.x + in1.x, ...) or vecN(in0.x + in1, ...) or vecN(in0 + in1.x, ...).
|
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
|
|
|
*/
|
2013-10-23 05:42:03 +00:00
|
|
|
template <typename T0, typename T1>
|
|
|
|
static Self Add(T0 in0, T1 in1);
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** Returns a GLSL subtraction: component-wise or subtract compoments by a scalar.
|
|
|
|
* Return value computes
|
|
|
|
* vecN(in0.x - in1.x, ...) or vecN(in0.x - in1, ...) or vecN(in0 - in1.x, ...).
|
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
|
|
|
*/
|
2013-10-23 05:42:03 +00:00
|
|
|
template <typename T0, typename T1>
|
|
|
|
static Self Sub(T0 in0, T1 in1);
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** Returns expression that accesses component(s) of the expression.
|
|
|
|
* format should be the form "%s.x" where 'x' is the component(s) to access.
|
|
|
|
* Caller is responsible for making sure the amount of components in the
|
|
|
|
* format string is equal to dim(T).
|
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
|
|
|
*/
|
2013-10-23 05:42:03 +00:00
|
|
|
template <typename T>
|
|
|
|
T extractComponents(const char format[]) const;
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
private:
|
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
|
|
|
enum ExprType {
|
|
|
|
kZeros_ExprType,
|
|
|
|
kOnes_ExprType,
|
|
|
|
kFullExpr_ExprType,
|
|
|
|
};
|
|
|
|
ExprType fType;
|
|
|
|
SkString fExpr;
|
2013-10-23 05:42:03 +00:00
|
|
|
};
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
class GrGLSLExpr1;
|
|
|
|
class GrGLSLExpr4;
|
|
|
|
|
|
|
|
/** Class representing a float GLSL expression. */
|
|
|
|
class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> {
|
|
|
|
public:
|
|
|
|
GrGLSLExpr1()
|
|
|
|
: INHERITED() {
|
|
|
|
}
|
|
|
|
explicit GrGLSLExpr1(int v)
|
|
|
|
: INHERITED(v) {
|
|
|
|
}
|
|
|
|
GrGLSLExpr1(const char* expr)
|
|
|
|
: INHERITED(expr) {
|
|
|
|
}
|
|
|
|
GrGLSLExpr1(const SkString& expr)
|
|
|
|
: INHERITED(expr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static GrGLSLExpr1 VectorCast(const GrGLSLExpr1& expr);
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrGLSLExpr1(const char format[], const char in0[])
|
|
|
|
: INHERITED(format, in0) {
|
|
|
|
}
|
|
|
|
GrGLSLExpr1(const char format[], const char in0[], const char in1[])
|
|
|
|
: INHERITED(format, in0, in1) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* ZerosStr();
|
|
|
|
static const char* OnesStr();
|
|
|
|
static const char* CastStr();
|
|
|
|
static const char* CastIntStr();
|
|
|
|
|
|
|
|
friend GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
|
|
|
|
friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
|
|
|
|
friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
|
|
|
|
|
|
|
|
friend class GrGLSLExpr<GrGLSLExpr1>;
|
|
|
|
friend class GrGLSLExpr<GrGLSLExpr4>;
|
|
|
|
|
|
|
|
typedef GrGLSLExpr<GrGLSLExpr1> INHERITED;
|
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
|
|
|
};
|
2012-04-18 17:49:20 +00:00
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** Class representing a float vector (vec4) GLSL expression. */
|
|
|
|
class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> {
|
|
|
|
public:
|
|
|
|
GrGLSLExpr4()
|
|
|
|
: INHERITED() {
|
|
|
|
}
|
|
|
|
explicit GrGLSLExpr4(int v)
|
|
|
|
: INHERITED(v) {
|
|
|
|
}
|
|
|
|
GrGLSLExpr4(const char* expr)
|
|
|
|
: INHERITED(expr) {
|
|
|
|
}
|
|
|
|
GrGLSLExpr4(const SkString& expr)
|
|
|
|
: INHERITED(expr) {
|
|
|
|
}
|
2012-08-29 12:59:57 +00:00
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
typedef GrGLSLExpr1 AExpr;
|
|
|
|
AExpr a() const;
|
2013-04-18 19:36:09 +00:00
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
/** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, floatv, floatv) */
|
|
|
|
static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr);
|
|
|
|
static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr);
|
2013-04-18 19:36:09 +00:00
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
private:
|
|
|
|
GrGLSLExpr4(const char format[], const char in0[])
|
|
|
|
: INHERITED(format, in0) {
|
|
|
|
}
|
|
|
|
GrGLSLExpr4(const char format[], const char in0[], const char in1[])
|
|
|
|
: INHERITED(format, in0, in1) {
|
|
|
|
}
|
2012-08-29 12:59:57 +00:00
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
static const char* ZerosStr();
|
|
|
|
static const char* OnesStr();
|
|
|
|
static const char* CastStr();
|
|
|
|
static const char* CastIntStr();
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
// The vector-by-scalar and scalar-by-vector binary operations.
|
|
|
|
friend GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
|
|
|
|
friend GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
|
|
|
|
friend GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
|
|
|
|
friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
|
|
|
|
friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
|
|
|
|
friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
// The vector-by-vector, i.e. component-wise, binary operations.
|
|
|
|
friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
|
|
|
|
friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
|
|
|
|
friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
friend class GrGLSLExpr<GrGLSLExpr4>;
|
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
|
|
|
|
2013-10-23 05:42:03 +00:00
|
|
|
typedef GrGLSLExpr<GrGLSLExpr4> INHERITED;
|
|
|
|
};
|
2012-08-29 12:59:57 +00:00
|
|
|
|
|
|
|
/**
|
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
|
|
|
* Does an inplace mul, *=, of vec4VarName by mulFactor.
|
2014-10-09 17:34:58 +00:00
|
|
|
* A semicolon is added after the assignment.
|
2013-04-18 19:36:09 +00:00
|
|
|
*/
|
2014-10-09 17:34:58 +00:00
|
|
|
void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor);
|
2013-04-18 19:36:09 +00:00
|
|
|
|
|
|
|
#include "GrGLSL_impl.h"
|
2012-08-29 12:59:57 +00:00
|
|
|
|
2012-02-10 15:56:06 +00:00
|
|
|
#endif
|