OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLSL_DEFINED | 8 #ifndef GrGLSL_DEFINED |
9 #define GrGLSL_DEFINED | 9 #define GrGLSL_DEFINED |
10 | 10 |
11 #include "GrTypesPriv.h" | 11 #include "GrTypesPriv.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 | 13 #include "GrGLSLCaps.h" |
14 class GrGLSLCaps; | |
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 * ES GLSL 3.10 only TODO Make GLSLCap objects to make this more granular | |
41 */ | |
42 k310es_GrGLSLGeneration, | |
43 }; | |
44 | 14 |
45 bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration); | 15 bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration); |
46 | 16 |
47 /** | 17 /** |
48 * Gets the name of the function that should be used to sample a 2D texture. Coo
rd type is used | 18 * Gets the name of the function that should be used to sample a 2D texture. Coo
rd type is used |
49 * to indicate whether the texture is sampled using projective textured (kVec3f)
or not (kVec2f). | 19 * to indicate whether the texture is sampled using projective textured (kVec3f)
or not (kVec2f). |
50 */ | 20 */ |
51 inline const char* GrGLSLTexture2DFunctionName(GrSLType coordType, GrSLType samp
lerType, | 21 inline const char* GrGLSLTexture2DFunctionName(GrSLType coordType, GrSLType samp
lerType, |
52 GrGLSLGeneration glslGen) { | 22 const GrGLSLCaps& glslCaps) { |
53 SkASSERT(GrSLTypeIsSamplerType(samplerType)); | 23 SkASSERT(GrSLTypeIsSamplerType(samplerType)); |
54 SkASSERT(kVec2f_GrSLType == coordType || kVec3f_GrSLType == coordType); | 24 SkASSERT(kVec2f_GrSLType == coordType || kVec3f_GrSLType == coordType); |
55 // GL_TEXTURE_RECTANGLE_ARB is written against OpenGL 2.0/GLSL 1.10. At that
time there were | 25 // GL_TEXTURE_RECTANGLE_ARB is written against OpenGL 2.0/GLSL 1.10. At that
time there were |
56 // separate texture*() functions. In OpenGL 3.0/GLSL 1.30 the different text
ure*() functions | 26 // separate texture*() functions. In OpenGL 3.0/GLSL 1.30 the different text
ure*() functions |
57 // were deprecated in favor or the unified texture() function. RECTANGLE tex
tures became | 27 // were deprecated in favor or the unified texture() function. RECTANGLE tex
tures became |
58 // standard in OpenGL 3.2/GLSL 1.50 and use texture(). It isn't completely c
lear what function | 28 // standard in OpenGL 3.2/GLSL 1.50 and use texture(). It isn't completely c
lear what function |
59 // should be used for RECTANGLE textures in GLSL versions >= 1.30 && < 1.50.
We're going with | 29 // should be used for RECTANGLE textures in GLSL versions >= 1.30 && < 1.50.
We're going with |
60 // using texture(). | 30 // using texture(). |
61 if (glslGen >= k130_GrGLSLGeneration) { | 31 if (samplerType == kSampler2DRect_GrSLType && |
62 return (kVec2f_GrSLType == coordType) ? "texture" : "textureProj"; | 32 !glslCaps.rectangleTextureUseUnifiedTextureFunctionName()) { |
| 33 if (kVec2f_GrSLType == coordType) { |
| 34 return "texture2DRect"; |
| 35 } |
| 36 return "texture2DRectProj"; |
| 37 } |
| 38 if (glslCaps.generation() >= k130_GrGLSLGeneration) { |
| 39 if (kVec2f_GrSLType == coordType) { |
| 40 return "texture"; |
| 41 } |
| 42 return "textureProj"; |
63 } | 43 } |
64 if (kVec2f_GrSLType == coordType) { | 44 if (kVec2f_GrSLType == coordType) { |
65 return (samplerType == kSampler2DRect_GrSLType) ? "texture2DRect" : "tex
ture2D"; | 45 return "texture2D"; |
66 } else { | |
67 return (samplerType == kSampler2DRect_GrSLType) ? "texture2DRectProj" :
"texture2DProj"; | |
68 } | 46 } |
| 47 return "texture2DProj"; |
69 } | 48 } |
70 | 49 |
71 /** | 50 /** |
72 * Adds a line of GLSL code to declare the default precision for float types. | 51 * Adds a line of GLSL code to declare the default precision for float types. |
73 */ | 52 */ |
74 void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision, | 53 void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision, |
75 const GrGLSLCaps& glslCaps, | 54 const GrGLSLCaps& glslCaps, |
76 SkString* out); | 55 SkString* out); |
77 | 56 |
78 /** | 57 /** |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 326 |
348 /** | 327 /** |
349 * Does an inplace mul, *=, of vec4VarName by mulFactor. | 328 * Does an inplace mul, *=, of vec4VarName by mulFactor. |
350 * A semicolon is added after the assignment. | 329 * A semicolon is added after the assignment. |
351 */ | 330 */ |
352 void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSL
Expr4& mulFactor); | 331 void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSL
Expr4& mulFactor); |
353 | 332 |
354 #include "GrGLSL_impl.h" | 333 #include "GrGLSL_impl.h" |
355 | 334 |
356 #endif | 335 #endif |
OLD | NEW |