• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrGLShaderVar.h"
10 
GrGetGLSLGeneration(GrGLBinding binding,const GrGLInterface * gl)11 GrGLSLGeneration GrGetGLSLGeneration(GrGLBinding binding,
12                                    const GrGLInterface* gl) {
13     GrGLSLVersion ver = GrGLGetGLSLVersion(gl);
14     switch (binding) {
15         case kDesktop_GrGLBinding:
16             GrAssert(ver >= GR_GLSL_VER(1,10));
17             if (ver >= GR_GLSL_VER(1,50)) {
18                 return k150_GrGLSLGeneration;
19             } else if (ver >= GR_GLSL_VER(1,30)) {
20                 return k130_GrGLSLGeneration;
21             } else {
22                 return k110_GrGLSLGeneration;
23             }
24         case kES2_GrGLBinding:
25             // version 1.00 of ES GLSL based on ver 1.20 of desktop GLSL
26             GrAssert(ver >= GR_GL_VER(1,00));
27             return k110_GrGLSLGeneration;
28         default:
29             GrCrash("Unknown GL Binding");
30             return k110_GrGLSLGeneration; // suppress warning
31     }
32 }
33 
GrGetGLSLVersionDecl(GrGLBinding binding,GrGLSLGeneration gen)34 const char* GrGetGLSLVersionDecl(GrGLBinding binding,
35                                    GrGLSLGeneration gen) {
36     switch (gen) {
37         case k110_GrGLSLGeneration:
38             if (kES2_GrGLBinding == binding) {
39                 // ES2s shader language is based on version 1.20 but is version
40                 // 1.00 of the ES language.
41                 return "#version 100\n";
42             } else {
43                 GrAssert(kDesktop_GrGLBinding == binding);
44                 return "#version 110\n";
45             }
46         case k130_GrGLSLGeneration:
47             GrAssert(kDesktop_GrGLBinding == binding);
48             return "#version 130\n";
49         case k150_GrGLSLGeneration:
50             GrAssert(kDesktop_GrGLBinding == binding);
51             return "#version 150\n";
52         default:
53             GrCrash("Unknown GL version.");
54             return ""; // suppress warning
55     }
56 }
57 
GrGetGLSLVarPrecisionDeclType(GrGLBinding binding)58 const char* GrGetGLSLVarPrecisionDeclType(GrGLBinding binding) {
59     if (kES2_GrGLBinding == binding) {
60         return "mediump";
61     } else {
62         return " ";
63     }
64 }
65 
GrGetGLSLShaderPrecisionDecl(GrGLBinding binding)66 const char* GrGetGLSLShaderPrecisionDecl(GrGLBinding binding) {
67     if (kES2_GrGLBinding == binding) {
68         return "precision mediump float;\n";
69     } else {
70         return "";
71     }
72 }
73 
GrGLSLSetupFSColorOuput(GrGLSLGeneration gen,const char * nameIfDeclared,GrGLShaderVar * var)74 bool GrGLSLSetupFSColorOuput(GrGLSLGeneration gen,
75                              const char* nameIfDeclared,
76                              GrGLShaderVar* var) {
77     bool declaredOutput = k110_GrGLSLGeneration != gen;
78     var->set(GrGLShaderVar::kVec4f_Type,
79              GrGLShaderVar::kOut_TypeModifier,
80              declaredOutput ? nameIfDeclared : "gl_FragColor");
81     return declaredOutput;
82 }
83