OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrGLEffect_DEFINED | 8 #ifndef GrGLEffect_DEFINED |
9 #define GrGLEffect_DEFINED | 9 #define GrGLEffect_DEFINED |
10 | 10 |
11 #include "GrBackendEffectFactory.h" | 11 #include "GrBackendEffectFactory.h" |
12 #include "GrGLProgramEffects.h" | 12 #include "GrGLProgramEffects.h" |
13 #include "GrGLShaderVar.h" | 13 #include "GrGLShaderVar.h" |
14 #include "GrGLSL.h" | 14 #include "GrGLSL.h" |
15 | 15 |
16 class GrGLShaderBuilder; | 16 class GrGLShaderBuilder; |
17 | 17 |
18 /** @file | 18 /** @file |
19 This file contains specializations for OpenGL of the shader stages declared
in | 19 This file contains specializations for OpenGL of the shader stages declared
in |
20 include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitt
ing the | 20 include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitt
ing the |
21 GLSL code that implements a GrEffect and for uploading uniforms at draw time
. If they don't | 21 GLSL code that implements a GrEffect and for uploading uniforms at draw time
. If they don't |
22 always emit the same GLSL code, they must have a function: | 22 always emit the same GLSL code, they must have a function: |
23 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyB
uilder*) | 23 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect
KeyBuilder*) |
24 that is used to implement a program cache. When two GrEffects produce the sa
me key this means | 24 that is used to implement a program cache. When two GrEffects produce the sa
me key this means |
25 that their GrGLEffects would emit the same GLSL code. | 25 that their GrGLEffects would emit the same GLSL code. |
26 | 26 |
27 The GrGLEffect subclass must also have a constructor of the form: | 27 The GrGLEffect subclass must also have a constructor of the form: |
28 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrEf
fect&) | 28 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDr
awEffect&) |
| 29 The effect held by the GrDrawEffect is guaranteed to be of the type that gen
erated the |
| 30 GrGLEffect subclass instance. |
29 | 31 |
30 These objects are created by the factory object returned by the GrEffect::ge
tFactory(). | 32 These objects are created by the factory object returned by the GrEffect::ge
tFactory(). |
31 */ | 33 */ |
32 | 34 |
| 35 class GrDrawEffect; |
33 class GrGLTexture; | 36 class GrGLTexture; |
34 class GrGLGeometryProcessor; | 37 class GrGLGeometryProcessor; |
35 | 38 |
36 class GrGLEffect { | 39 class GrGLEffect { |
37 | 40 |
38 public: | 41 public: |
39 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; | 42 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; |
40 typedef GrGLProgramEffects::TextureSampler TextureSampler; | 43 typedef GrGLProgramEffects::TextureSampler TextureSampler; |
41 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; | 44 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; |
42 | 45 |
43 GrGLEffect(const GrBackendEffectFactory& factory) | 46 GrGLEffect(const GrBackendEffectFactory& factory) |
44 : fFactory(factory) | 47 : fFactory(factory) |
45 , fIsVertexEffect(false) { | 48 , fIsVertexEffect(false) { |
46 } | 49 } |
47 | 50 |
48 virtual ~GrGLEffect() {} | 51 virtual ~GrGLEffect() {} |
49 | 52 |
50 /** Called when the program stage should insert its code into the shaders. T
he code in each | 53 /** Called when the program stage should insert its code into the shaders. T
he code in each |
51 shader will be in its own block ({}) and so locally scoped names will no
t collide across | 54 shader will be in its own block ({}) and so locally scoped names will no
t collide across |
52 stages. | 55 stages. |
53 | 56 |
54 @param builder Interface used to emit code in the shaders. | 57 @param builder Interface used to emit code in the shaders. |
55 @param effect The effect that generated this program stage. | 58 @param drawEffect A wrapper on the effect that generated this program
stage. |
56 @param key The key that was computed by GenKey() from the gener
ating GrEffect. | 59 @param key The key that was computed by GenKey() from the gener
ating GrEffect. |
57 @param outputColor A predefined vec4 in the FS in which the stage shoul
d place its output | 60 @param outputColor A predefined vec4 in the FS in which the stage shoul
d place its output |
58 color (or coverage). | 61 color (or coverage). |
59 @param inputColor A vec4 that holds the input color to the stage in th
e FS. This may be | 62 @param inputColor A vec4 that holds the input color to the stage in th
e FS. This may be |
60 NULL in which case the implied input is solid white
(all ones). | 63 NULL in which case the implied input is solid white
(all ones). |
61 TODO: Better system for communicating optimization i
nfo (e.g. input | 64 TODO: Better system for communicating optimization i
nfo (e.g. input |
62 color is solid white, trans black, known to be opaqu
e, etc.) that allows | 65 color is solid white, trans black, known to be opaqu
e, etc.) that allows |
63 the effect to communicate back similar known info ab
out its output. | 66 the effect to communicate back similar known info ab
out its output. |
64 @param samplers One entry for each GrTextureAccess of the GrEffect t
hat generated the | 67 @param samplers One entry for each GrTextureAccess of the GrEffect t
hat generated the |
65 GrGLEffect. These can be passed to the builder to em
it texture | 68 GrGLEffect. These can be passed to the builder to em
it texture |
66 reads in the generated code. | 69 reads in the generated code. |
67 */ | 70 */ |
68 virtual void emitCode(GrGLProgramBuilder* builder, | 71 virtual void emitCode(GrGLProgramBuilder* builder, |
69 const GrEffect& effect, | 72 const GrDrawEffect& drawEffect, |
70 const GrEffectKey& key, | 73 const GrEffectKey& key, |
71 const char* outputColor, | 74 const char* outputColor, |
72 const char* inputColor, | 75 const char* inputColor, |
73 const TransformedCoordsArray& coords, | 76 const TransformedCoordsArray& coords, |
74 const TextureSamplerArray& samplers) = 0; | 77 const TextureSamplerArray& samplers) = 0; |
75 | 78 |
76 /** A GrGLEffect instance can be reused with any GrEffect that produces the
same stage | 79 /** A GrGLEffect instance can be reused with any GrEffect that produces the
same stage |
77 key; this function reads data from a GrEffect and uploads any uniform va
riables required | 80 key; this function reads data from a GrEffect and uploads any uniform va
riables required |
78 by the shaders created in emitCode(). The GrEffect is | 81 by the shaders created in emitCode(). The GrEffect installed in the GrDr
awEffect is |
79 guaranteed to be of the same type that created this GrGLEffect and to ha
ve an identical | 82 guaranteed to be of the same type that created this GrGLEffect and to ha
ve an identical |
80 effect key as the one that created this GrGLEffect. Effects that use loc
al coords have | 83 effect key as the one that created this GrGLEffect. Effects that use loc
al coords have |
81 to consider whether the GrEffectStage's coord change matrix should be us
ed. When explicit | 84 to consider whether the GrEffectStage's coord change matrix should be us
ed. When explicit |
82 local coordinates are used it can be ignored. */ | 85 local coordinates are used it can be ignored. */ |
83 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) {} | 86 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) {} |
84 | 87 |
85 const char* name() const { return fFactory.name(); } | 88 const char* name() const { return fFactory.name(); } |
86 | 89 |
87 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder*) {} | 90 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*
) {} |
88 | 91 |
89 /** Used by the system when generating shader code, to see if this effect ca
n be downcasted to | 92 /** Used by the system when generating shader code, to see if this effect ca
n be downcasted to |
90 the internal GrGLGeometryProcessor type */ | 93 the internal GrGLGeometryProcessor type */ |
91 bool isVertexEffect() const { return fIsVertexEffect; } | 94 bool isVertexEffect() const { return fIsVertexEffect; } |
92 | 95 |
93 protected: | 96 protected: |
94 const GrBackendEffectFactory& fFactory; | 97 const GrBackendEffectFactory& fFactory; |
95 | 98 |
96 private: | 99 private: |
97 friend class GrGLGeometryProcessor; // to set fIsVertexEffect | 100 friend class GrGLGeometryProcessor; // to set fIsVertexEffect |
98 | 101 |
99 bool fIsVertexEffect; | 102 bool fIsVertexEffect; |
100 }; | 103 }; |
101 | 104 |
102 #endif | 105 #endif |
OLD | NEW |