| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrGLSL.h" | 8 #include "GrGLGLSL.h" |
| 9 #include "GrGLShaderVar.h" | 9 #include "GrGLShaderVar.h" |
| 10 #include "SkString.h" | 10 #include "SkString.h" |
| 11 | 11 |
| 12 bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation)
{ | 12 bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation
) { |
| 13 SkASSERT(generation); | 13 SkASSERT(generation); |
| 14 GrGLSLVersion ver = GrGLGetGLSLVersion(gl); | 14 GrGLSLVersion ver = GrGLGetGLSLVersion(gl); |
| 15 if (GR_GLSL_INVALID_VER == ver) { | 15 if (GR_GLSL_INVALID_VER == ver) { |
| 16 return false; | 16 return false; |
| 17 } | 17 } |
| 18 switch (gl->fStandard) { | 18 switch (gl->fStandard) { |
| 19 case kGL_GrGLStandard: | 19 case kGL_GrGLStandard: |
| 20 SkASSERT(ver >= GR_GLSL_VER(1,10)); | 20 SkASSERT(ver >= GR_GLSL_VER(1,10)); |
| 21 if (ver >= GR_GLSL_VER(3,30)) { | 21 if (ver >= GR_GLSL_VER(3,30)) { |
| 22 *generation = k330_GrGLSLGeneration; | 22 *generation = k330_GrGLSLGeneration; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 } else { | 40 } else { |
| 41 *generation = k110_GrGLSLGeneration; | 41 *generation = k110_GrGLSLGeneration; |
| 42 } | 42 } |
| 43 return true; | 43 return true; |
| 44 default: | 44 default: |
| 45 SkFAIL("Unknown GL Standard"); | 45 SkFAIL("Unknown GL Standard"); |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 const char* GrGetGLSLVersionDecl(const GrGLContextInfo& info) { | 50 const char* GrGLGetGLSLVersionDecl(const GrGLContextInfo& info) { |
| 51 switch (info.glslGeneration()) { | 51 switch (info.glslGeneration()) { |
| 52 case k110_GrGLSLGeneration: | 52 case k110_GrGLSLGeneration: |
| 53 if (kGLES_GrGLStandard == info.standard()) { | 53 if (kGLES_GrGLStandard == info.standard()) { |
| 54 // ES2s shader language is based on version 1.20 but is version | 54 // ES2s shader language is based on version 1.20 but is version |
| 55 // 1.00 of the ES language. | 55 // 1.00 of the ES language. |
| 56 return "#version 100\n"; | 56 return "#version 100\n"; |
| 57 } else { | 57 } else { |
| 58 SkASSERT(kGL_GrGLStandard == info.standard()); | 58 SkASSERT(kGL_GrGLStandard == info.standard()); |
| 59 return "#version 110\n"; | 59 return "#version 110\n"; |
| 60 } | 60 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 82 return "#version 330 compatibility\n"; | 82 return "#version 330 compatibility\n"; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 case k310es_GrGLSLGeneration: | 85 case k310es_GrGLSLGeneration: |
| 86 SkASSERT(kGLES_GrGLStandard == info.standard()); | 86 SkASSERT(kGLES_GrGLStandard == info.standard()); |
| 87 return "#version 310 es\n"; | 87 return "#version 310 es\n"; |
| 88 } | 88 } |
| 89 return "<no version>"; | 89 return "<no version>"; |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) { | 92 void GrGLAppendGLSLDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandar
d s, SkString* out) { |
| 93 switch (gen) { | |
| 94 case k110_GrGLSLGeneration: | |
| 95 return false; | |
| 96 case k130_GrGLSLGeneration: | |
| 97 case k140_GrGLSLGeneration: | |
| 98 case k150_GrGLSLGeneration: | |
| 99 case k330_GrGLSLGeneration: | |
| 100 case k310es_GrGLSLGeneration: | |
| 101 return true; | |
| 102 } | |
| 103 return false; | |
| 104 } | |
| 105 | |
| 106 void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard
s, SkString* out) { | |
| 107 // Desktop GLSL has added precision qualifiers but they don't do anything. | 93 // Desktop GLSL has added precision qualifiers but they don't do anything. |
| 108 if (kGLES_GrGLStandard == s) { | 94 if (kGLES_GrGLStandard == s) { |
| 109 switch (p) { | 95 switch (p) { |
| 110 case kHigh_GrSLPrecision: | 96 case kHigh_GrSLPrecision: |
| 111 out->append("precision highp float;\n"); | 97 out->append("precision highp float;\n"); |
| 112 break; | 98 break; |
| 113 case kMedium_GrSLPrecision: | 99 case kMedium_GrSLPrecision: |
| 114 out->append("precision mediump float;\n"); | 100 out->append("precision mediump float;\n"); |
| 115 break; | 101 break; |
| 116 case kLow_GrSLPrecision: | 102 case kLow_GrSLPrecision: |
| 117 out->append("precision lowp float;\n"); | 103 out->append("precision lowp float;\n"); |
| 118 break; | 104 break; |
| 119 default: | 105 default: |
| 120 SkFAIL("Unknown precision value."); | 106 SkFAIL("Unknown precision value."); |
| 121 } | 107 } |
| 122 } | 108 } |
| 123 } | 109 } |
| 124 | |
| 125 void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSL
Expr4& mulFactor) { | |
| 126 if (mulFactor.isOnes()) { | |
| 127 *outAppend = SkString(); | |
| 128 } | |
| 129 | |
| 130 if (mulFactor.isZeros()) { | |
| 131 outAppend->appendf("%s = vec4(0);", vec4VarName); | |
| 132 } else { | |
| 133 outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str()); | |
| 134 } | |
| 135 } | |
| OLD | NEW |