jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 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" |
egdaniel | cb7ba1e | 2015-10-26 08:38:25 -0700 | [diff] [blame] | 9 | #include "GrGLSLCaps.h" |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 10 | #include "SkString.h" |
| 11 | |
| 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: |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 20 | case k400_GrGLSLGeneration: |
Brian Salomon | d327e8c | 2016-11-15 13:26:08 -0500 | [diff] [blame^] | 21 | case k420_GrGLSLGeneration: |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 22 | case k310es_GrGLSLGeneration: |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 23 | case k320es_GrGLSLGeneration: |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 24 | return true; |
| 25 | } |
| 26 | return false; |
| 27 | } |
| 28 | |
egdaniel | cb7ba1e | 2015-10-26 08:38:25 -0700 | [diff] [blame] | 29 | void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, |
| 30 | const GrGLSLCaps& glslCaps, |
| 31 | SkString* out) { |
| 32 | if (glslCaps.usesPrecisionModifiers()) { |
| 33 | switch (p) { |
| 34 | case kHigh_GrSLPrecision: |
| 35 | out->append("precision highp float;\n"); |
| 36 | break; |
| 37 | case kMedium_GrSLPrecision: |
| 38 | out->append("precision mediump float;\n"); |
| 39 | break; |
| 40 | case kLow_GrSLPrecision: |
| 41 | out->append("precision lowp float;\n"); |
| 42 | break; |
| 43 | default: |
| 44 | SkFAIL("Unknown precision value."); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 49 | void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) { |
| 50 | if (mulFactor.isOnes()) { |
| 51 | *outAppend = SkString(); |
| 52 | } |
| 53 | |
| 54 | if (mulFactor.isZeros()) { |
| 55 | outAppend->appendf("%s = vec4(0);", vec4VarName); |
| 56 | } else { |
| 57 | outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str()); |
| 58 | } |
| 59 | } |