1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrGLSL.h"
9 #include "GrGLSLCaps.h"
10 #include "SkString.h"
11
GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen)12 bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) {
13 switch (gen) {
14 case k110_GrGLSLGeneration:
15 return false;
16 case k130_GrGLSLGeneration:
17 case k140_GrGLSLGeneration:
18 case k150_GrGLSLGeneration:
19 case k330_GrGLSLGeneration:
20 case k400_GrGLSLGeneration:
21 case k310es_GrGLSLGeneration:
22 case k320es_GrGLSLGeneration:
23 return true;
24 }
25 return false;
26 }
27
GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p,const GrGLSLCaps & glslCaps,SkString * out)28 void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p,
29 const GrGLSLCaps& glslCaps,
30 SkString* out) {
31 if (glslCaps.usesPrecisionModifiers()) {
32 switch (p) {
33 case kHigh_GrSLPrecision:
34 out->append("precision highp float;\n");
35 break;
36 case kMedium_GrSLPrecision:
37 out->append("precision mediump float;\n");
38 break;
39 case kLow_GrSLPrecision:
40 out->append("precision lowp float;\n");
41 break;
42 default:
43 SkFAIL("Unknown precision value.");
44 }
45 }
46 }
47
GrGLSLMulVarBy4f(SkString * outAppend,const char * vec4VarName,const GrGLSLExpr4 & mulFactor)48 void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) {
49 if (mulFactor.isOnes()) {
50 *outAppend = SkString();
51 }
52
53 if (mulFactor.isZeros()) {
54 outAppend->appendf("%s = vec4(0);", vec4VarName);
55 } else {
56 outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str());
57 }
58 }
59