1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLSL.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +/* 1.5 + * Copyright 2011 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "GrGLSL.h" 1.12 +#include "GrGLShaderVar.h" 1.13 +#include "SkString.h" 1.14 + 1.15 +GrGLSLGeneration GrGetGLSLGeneration(const GrGLInterface* gl) { 1.16 + GrGLSLVersion ver = GrGLGetGLSLVersion(gl); 1.17 + switch (gl->fStandard) { 1.18 + case kGL_GrGLStandard: 1.19 + SkASSERT(ver >= GR_GLSL_VER(1,10)); 1.20 + if (ver >= GR_GLSL_VER(1,50)) { 1.21 + return k150_GrGLSLGeneration; 1.22 + } else if (ver >= GR_GLSL_VER(1,40)) { 1.23 + return k140_GrGLSLGeneration; 1.24 + } else if (ver >= GR_GLSL_VER(1,30)) { 1.25 + return k130_GrGLSLGeneration; 1.26 + } else { 1.27 + return k110_GrGLSLGeneration; 1.28 + } 1.29 + case kGLES_GrGLStandard: 1.30 + // version 1.00 of ES GLSL based on ver 1.20 of desktop GLSL 1.31 + SkASSERT(ver >= GR_GL_VER(1,00)); 1.32 + return k110_GrGLSLGeneration; 1.33 + default: 1.34 + GrCrash("Unknown GL Standard"); 1.35 + return k110_GrGLSLGeneration; // suppress warning 1.36 + } 1.37 +} 1.38 + 1.39 +const char* GrGetGLSLVersionDecl(const GrGLContextInfo& info) { 1.40 + switch (info.glslGeneration()) { 1.41 + case k110_GrGLSLGeneration: 1.42 + if (kGLES_GrGLStandard == info.standard()) { 1.43 + // ES2s shader language is based on version 1.20 but is version 1.44 + // 1.00 of the ES language. 1.45 + return "#version 100\n"; 1.46 + } else { 1.47 + SkASSERT(kGL_GrGLStandard == info.standard()); 1.48 + return "#version 110\n"; 1.49 + } 1.50 + case k130_GrGLSLGeneration: 1.51 + SkASSERT(kGL_GrGLStandard == info.standard()); 1.52 + return "#version 130\n"; 1.53 + case k140_GrGLSLGeneration: 1.54 + SkASSERT(kGL_GrGLStandard == info.standard()); 1.55 + return "#version 140\n"; 1.56 + case k150_GrGLSLGeneration: 1.57 + SkASSERT(kGL_GrGLStandard == info.standard()); 1.58 + if (info.caps()->isCoreProfile()) { 1.59 + return "#version 150\n"; 1.60 + } else { 1.61 + return "#version 150 compatibility\n"; 1.62 + } 1.63 + default: 1.64 + GrCrash("Unknown GL version."); 1.65 + return ""; // suppress warning 1.66 + } 1.67 +} 1.68 + 1.69 +namespace { 1.70 + void append_tabs(SkString* outAppend, int tabCnt) { 1.71 + static const char kTabs[] = "\t\t\t\t\t\t\t\t"; 1.72 + while (tabCnt) { 1.73 + int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt); 1.74 + outAppend->append(kTabs, cnt); 1.75 + tabCnt -= cnt; 1.76 + } 1.77 + } 1.78 +} 1.79 + 1.80 +void GrGLSLMulVarBy4f(SkString* outAppend, 1.81 + unsigned tabCnt, 1.82 + const char* vec4VarName, 1.83 + const GrGLSLExpr4& mulFactor) { 1.84 + if (mulFactor.isOnes()) { 1.85 + *outAppend = SkString(); 1.86 + } 1.87 + 1.88 + append_tabs(outAppend, tabCnt); 1.89 + 1.90 + if (mulFactor.isZeros()) { 1.91 + outAppend->appendf("%s = vec4(0);\n", vec4VarName); 1.92 + } else { 1.93 + outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor.c_str()); 1.94 + } 1.95 +}