blob: e933ee87c9c7e62287586be6e5683672109cc060 [file] [log] [blame]
tomhudson@google.com086e5352011-12-08 14:44:10 +00001/*
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"
bsalomon@google.come55fd0f2012-02-10 15:56:06 +00009#include "GrGLShaderVar.h"
tomhudson@google.com086e5352011-12-08 14:44:10 +000010
bsalomon@google.come55fd0f2012-02-10 15:56:06 +000011GrGLSLGeneration GrGetGLSLGeneration(GrGLBinding binding,
tomhudson@google.com086e5352011-12-08 14:44:10 +000012 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)) {
bsalomon@google.come55fd0f2012-02-10 15:56:06 +000018 return k150_GrGLSLGeneration;
tomhudson@google.com086e5352011-12-08 14:44:10 +000019 } else if (ver >= GR_GLSL_VER(1,30)) {
bsalomon@google.come55fd0f2012-02-10 15:56:06 +000020 return k130_GrGLSLGeneration;
tomhudson@google.com086e5352011-12-08 14:44:10 +000021 } else {
bsalomon@google.come55fd0f2012-02-10 15:56:06 +000022 return k110_GrGLSLGeneration;
tomhudson@google.com086e5352011-12-08 14:44:10 +000023 }
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));
bsalomon@google.come55fd0f2012-02-10 15:56:06 +000027 return k110_GrGLSLGeneration;
tomhudson@google.com086e5352011-12-08 14:44:10 +000028 default:
29 GrCrash("Unknown GL Binding");
bsalomon@google.come55fd0f2012-02-10 15:56:06 +000030 return k110_GrGLSLGeneration; // suppress warning
tomhudson@google.com086e5352011-12-08 14:44:10 +000031 }
32}
33
bsalomon@google.come55fd0f2012-02-10 15:56:06 +000034const 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
58const char* GrGetGLSLVarPrecisionDeclType(GrGLBinding binding) {
59 if (kES2_GrGLBinding == binding) {
60 return "mediump";
61 } else {
62 return " ";
63 }
64}
65
66const char* GrGetGLSLShaderPrecisionDecl(GrGLBinding binding) {
67 if (kES2_GrGLBinding == binding) {
68 return "precision mediump float;\n";
69 } else {
70 return "";
71 }
72}
73
74bool 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}