| 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 "GrGLEffectArray.h" |
| 12 #include "GrGLShaderBuilder.h" | 13 #include "GrGLShaderBuilder.h" |
| 13 #include "GrGLShaderVar.h" | 14 #include "GrGLShaderVar.h" |
| 14 #include "GrGLSL.h" | 15 #include "GrGLSL.h" |
| 15 | 16 |
| 16 class GrGLTexture; | 17 class GrGLTexture; |
| 17 | 18 |
| 18 /** @file | 19 /** @file |
| 19 This file contains specializations for OpenGL of the shader stages declared
in | 20 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 | 21 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 | 22 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: | 23 always emit the same GLSL code, they must have a function: |
| 23 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) | 24 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) |
| 24 that is used to implement a program cache. When two GrEffects produce the sa
me key this means | 25 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. | 26 that their GrGLEffects would emit the same GLSL code. |
| 26 | 27 |
| 27 The GrGLEffect subclass must also have a constructor of the form: | 28 The GrGLEffect subclass must also have a constructor of the form: |
| 28 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDr
awEffect&) | 29 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 The effect held by the GrDrawEffect is guaranteed to be of the type that gen
erated the |
| 30 GrGLEffect subclass instance. | 31 GrGLEffect subclass instance. |
| 31 | 32 |
| 32 These objects are created by the factory object returned by the GrEffect::ge
tFactory(). | 33 These objects are created by the factory object returned by the GrEffect::ge
tFactory(). |
| 33 */ | 34 */ |
| 34 | 35 |
| 35 class GrDrawEffect; | 36 class GrDrawEffect; |
| 36 | 37 |
| 37 class GrGLEffect { | 38 class GrGLEffect { |
| 38 | 39 |
| 39 public: | 40 public: |
| 40 typedef GrBackendEffectFactory::EffectKey EffectKey; | 41 typedef GrBackendEffectFactory::EffectKey EffectKey; |
| 42 typedef GrGLEffectArray::TransformedCoordsArray TransformedCoordsArray; |
| 43 typedef GrGLEffectArray::TextureSamplerArray TextureSamplerArray; |
| 44 typedef GrGLEffectArray ArrayClass; |
| 41 | 45 |
| 42 enum { | 46 enum { |
| 43 kNoEffectKey = GrBackendEffectFactory::kNoEffectKey, | 47 kNoEffectKey = GrBackendEffectFactory::kNoEffectKey, |
| 44 // the number of bits in EffectKey available to GenKey | 48 // the number of bits in EffectKey available to GenKey |
| 45 kEffectKeyBits = GrBackendEffectFactory::kEffectKeyBits, | 49 kEffectKeyBits = GrBackendEffectFactory::kEffectKeyBits, |
| 46 }; | 50 }; |
| 47 | 51 |
| 48 typedef GrGLShaderBuilder::TransformedCoordsArray TransformedCoordsArray; | 52 GrGLEffect(const GrBackendEffectFactory& factory) : fFactory(factory) {} |
| 49 typedef GrGLShaderBuilder::TextureSamplerArray TextureSamplerArray; | |
| 50 | 53 |
| 51 GrGLEffect(const GrBackendEffectFactory&); | 54 virtual ~GrGLEffect() {} |
| 52 | |
| 53 virtual ~GrGLEffect(); | |
| 54 | 55 |
| 55 /** Called when the program stage should insert its code into the shaders. T
he code in each | 56 /** Called when the program stage should insert its code into the shaders. T
he code in each |
| 56 shader will be in its own block ({}) and so locally scoped names will no
t collide across | 57 shader will be in its own block ({}) and so locally scoped names will no
t collide across |
| 57 stages. | 58 stages. |
| 58 | 59 |
| 59 @param builder Interface used to emit code in the shaders. | 60 @param builder Interface used to emit code in the shaders. |
| 60 @param drawEffect A wrapper on the effect that generated this program
stage. | 61 @param drawEffect A wrapper on the effect that generated this program
stage. |
| 61 @param key The key that was computed by GenKey() from the gener
ating GrEffect. | 62 @param key The key that was computed by GenKey() from the gener
ating GrEffect. |
| 62 Only the bits indicated by GrBackendEffectFactory::k
EffectKeyBits are | 63 Only the bits indicated by GrBackendEffectFactory::k
EffectKeyBits are |
| 63 guaranteed to match the value produced by GenKey(); | 64 guaranteed to match the value produced by GenKey(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 const TransformedCoordsArray& coords, | 81 const TransformedCoordsArray& coords, |
| 81 const TextureSamplerArray& samplers) = 0; | 82 const TextureSamplerArray& samplers) = 0; |
| 82 | 83 |
| 83 /** A GrGLEffect instance can be reused with any GrEffect that produces the
same stage | 84 /** A GrGLEffect instance can be reused with any GrEffect that produces the
same stage |
| 84 key; this function reads data from a stage and uploads any uniform varia
bles required | 85 key; this function reads data from a stage and uploads any uniform varia
bles required |
| 85 by the shaders created in emitCode(). The GrEffect installed in the GrEf
fectStage is | 86 by the shaders created in emitCode(). The GrEffect installed in the GrEf
fectStage is |
| 86 guaranteed to be of the same type that created this GrGLEffect and to ha
ve an identical | 87 guaranteed to be of the same type that created this GrGLEffect and to ha
ve an identical |
| 87 EffectKey as the one that created this GrGLEffect. Effects that use loca
l coords have | 88 EffectKey as the one that created this GrGLEffect. Effects that use loca
l coords have |
| 88 to consider whether the GrEffectStage's coord change matrix should be us
ed. When explicit | 89 to consider whether the GrEffectStage's coord change matrix should be us
ed. When explicit |
| 89 local coordinates are used it can be ignored. */ | 90 local coordinates are used it can be ignored. */ |
| 90 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&); | 91 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) {} |
| 91 | 92 |
| 92 const char* name() const { return fFactory.name(); } | 93 const char* name() const { return fFactory.name(); } |
| 93 | 94 |
| 94 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { retur
n 0; } | 95 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { retur
n 0; } |
| 95 | 96 |
| 96 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&); | |
| 97 static EffectKey GenTransformKey(const GrDrawEffect&); | |
| 98 static EffectKey GenAttribKey(const GrDrawEffect& stage); | |
| 99 | |
| 100 protected: | 97 protected: |
| 101 const GrBackendEffectFactory& fFactory; | 98 const GrBackendEffectFactory& fFactory; |
| 102 }; | 99 }; |
| 103 | 100 |
| 104 #endif | 101 #endif |
| OLD | NEW |