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 SkFAIL("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 */
GrGLSLTypeString(GrSLType t)88 static inline const char* GrGLSLTypeString(GrSLType t) {
89 switch (t) {
90 case kVoid_GrSLType:
91 return "void";
92 case kFloat_GrSLType:
93 return "float";
94 case kVec2f_GrSLType:
95 return "vec2";
96 case kVec3f_GrSLType:
97 return "vec3";
98 case kVec4f_GrSLType:
99 return "vec4";
100 case kVec2i_GrSLType:
101 return "ivec2";
102 case kVec3i_GrSLType:
103 return "ivec3";
104 case kVec4i_GrSLType:
105 return "ivec4";
106 case kMat22f_GrSLType:
107 return "mat2";
108 case kMat33f_GrSLType:
109 return "mat3";
110 case kMat44f_GrSLType:
111 return "mat4";
112 case kTexture2DSampler_GrSLType:
113 return "sampler2D";
114 case kITexture2DSampler_GrSLType:
115 return "isampler2D";
116 case kTextureExternalSampler_GrSLType:
117 return "samplerExternalOES";
118 case kTexture2DRectSampler_GrSLType:
119 return "sampler2DRect";
120 case kBufferSampler_GrSLType:
121 return "samplerBuffer";
122 case kBool_GrSLType:
123 return "bool";
124 case kInt_GrSLType:
125 return "int";
126 case kUint_GrSLType:
127 return "uint";
128 case kTexture2D_GrSLType:
129 return "texture2D";
130 case kSampler_GrSLType:
131 return "sampler";
132 case kImageStorage2D_GrSLType:
133 return "image2D";
134 case kIImageStorage2D_GrSLType:
135 return "iimage2D";
136 }
137 SkFAIL("Unknown shader var type.");
138 return ""; // suppress warning
139 }
140
141 #endif
142