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 #ifndef GrGLSL_DEFINED
9 #define GrGLSL_DEFINED
10
11 #include "GrTypesPriv.h"
12 #include "SkString.h"
13
14 class GrShaderCaps;
15
16 // Limited set of GLSL versions we build shaders for. Caller should round
17 // down the GLSL version to one of these enums.
18 enum GrGLSLGeneration {
19 /**
20 * Desktop GLSL 1.10 and ES2 shading language (based on desktop GLSL 1.20)
21 */
22 k110_GrGLSLGeneration,
23 /**
24 * Desktop GLSL 1.30
25 */
26 k130_GrGLSLGeneration,
27 /**
28 * Desktop GLSL 1.40
29 */
30 k140_GrGLSLGeneration,
31 /**
32 * Desktop GLSL 1.50
33 */
34 k150_GrGLSLGeneration,
35 /**
36 * Desktop GLSL 3.30, and ES GLSL 3.00
37 */
38 k330_GrGLSLGeneration,
39 /**
40 * Desktop GLSL 4.00
41 */
42 k400_GrGLSLGeneration,
43 /**
44 * Desktop GLSL 4.20
45 */
46 k420_GrGLSLGeneration,
47 /**
48 * ES GLSL 3.10 only TODO Make GLSLCap objects to make this more granular
49 */
50 k310es_GrGLSLGeneration,
51 /**
52 * ES GLSL 3.20
53 */
54 k320es_GrGLSLGeneration,
55 };
56
57 bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration);
58
59 /**
60 * Adds a line of GLSL code to declare the default precision for float types.
61 */
62 void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision,
63 const GrShaderCaps&,
64 SkString* out);
65
66 /**
67 * Converts a GrSLPrecision to its corresponding GLSL precision qualifier.
68 */
GrGLSLPrecisionString(GrSLPrecision p)69 static inline const char* GrGLSLPrecisionString(GrSLPrecision p) {
70 switch (p) {
71 case kLow_GrSLPrecision:
72 return "lowp";
73 case kMedium_GrSLPrecision:
74 return "mediump";
75 case kHigh_GrSLPrecision:
76 return "highp";
77 case kDefault_GrSLPrecision:
78 return "";
79 default:
80 SK_ABORT("Unexpected precision type.");
81 return "";
82 }
83 }
84
85 /**
86 * Converts a GrSLType to a string containing the name of the equivalent GLSL type.
87 */
88 const char* GrGLSLTypeString(const GrShaderCaps* shaderCaps, GrSLType t);
89
90 #endif
91