Chromium Code Reviews| 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 "GrGLShaderBuilder.h" | 12 #include "GrGLShaderBuilder.h" |
| 13 #include "GrGLShaderVar.h" | 13 #include "GrGLShaderVar.h" |
| 14 #include "GrGLSL.h" | 14 #include "GrGLSL.h" |
| 15 | 15 |
| 16 class GrGLTexture; | 16 class GrGLTexture; |
| 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 . They also | 21 GLSL code that implements a GrEffect and for uploading uniforms at draw time . If they don't |
| 22 must have a function: | 22 always emit the same GLSL code, they must have a function: |
| 23 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) | 23 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 | 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 GrDr awEffect&) | 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 | 29 The effect held by the GrDrawEffect is guaranteed to be of the type that gen erated the |
| 30 GrGLEffect subclass instance. | 30 GrGLEffect subclass instance. |
| 31 | 31 |
| 32 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(). |
| 33 */ | 33 */ |
| 34 | 34 |
| 35 class GrDrawEffect; | 35 class GrDrawEffect; |
| 36 | 36 |
| 37 class GrGLEffect { | 37 class GrGLEffect { |
| 38 | 38 |
| 39 public: | 39 public: |
| 40 typedef GrBackendEffectFactory::EffectKey EffectKey; | 40 typedef GrBackendEffectFactory::EffectKey EffectKey; |
| 41 | 41 |
| 42 enum { | 42 enum { |
| 43 kNoEffectKey = GrBackendEffectFactory::kNoEffectKey, | 43 kNoEffectKey = GrBackendEffectFactory::kNoEffectKey, |
| 44 // the number of bits in EffectKey available to GenKey | 44 // the number of bits in EffectKey available to GenKey |
| 45 kEffectKeyBits = GrBackendEffectFactory::kEffectKeyBits, | 45 kEffectKeyBits = GrBackendEffectFactory::kEffectKeyBits, |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 typedef GrGLShaderBuilder::TransformedCoordsArray TransformedCoordsArray; | |
| 48 typedef GrGLShaderBuilder::TextureSamplerArray TextureSamplerArray; | 49 typedef GrGLShaderBuilder::TextureSamplerArray TextureSamplerArray; |
| 49 | 50 |
| 50 GrGLEffect(const GrBackendEffectFactory&); | 51 GrGLEffect(const GrBackendEffectFactory&); |
| 51 | 52 |
| 52 virtual ~GrGLEffect(); | 53 virtual ~GrGLEffect(); |
| 53 | 54 |
| 54 /** Called when the program stage should insert its code into the shaders. T he code in each | 55 /** Called when the program stage should insert its code into the shaders. T he code in each |
| 55 shader will be in its own block ({}) and so locally scoped names will no t collide across | 56 shader will be in its own block ({}) and so locally scoped names will no t collide across |
| 56 stages. | 57 stages. |
| 57 | 58 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 69 the effect to communicate back similar known info ab out its output. | 70 the effect to communicate back similar known info ab out its output. |
| 70 @param samplers One entry for each GrTextureAccess of the GrEffect t hat generated the | 71 @param samplers One entry for each GrTextureAccess of the GrEffect t hat generated the |
| 71 GrGLEffect. These can be passed to the builder to em it texture | 72 GrGLEffect. These can be passed to the builder to em it texture |
| 72 reads in the generated code. | 73 reads in the generated code. |
| 73 */ | 74 */ |
| 74 virtual void emitCode(GrGLShaderBuilder* builder, | 75 virtual void emitCode(GrGLShaderBuilder* builder, |
| 75 const GrDrawEffect& drawEffect, | 76 const GrDrawEffect& drawEffect, |
| 76 EffectKey key, | 77 EffectKey key, |
| 77 const char* outputColor, | 78 const char* outputColor, |
| 78 const char* inputColor, | 79 const char* inputColor, |
| 80 const TransformedCoordsArray& coords, | |
| 79 const TextureSamplerArray& samplers) = 0; | 81 const TextureSamplerArray& samplers) = 0; |
| 80 | 82 |
| 81 /** A GrGLEffect instance can be reused with any GrEffect that produces the same stage | 83 /** A GrGLEffect instance can be reused with any GrEffect that produces the same stage |
| 82 key; this function reads data from a stage and uploads any uniform varia bles required | 84 key; this function reads data from a stage and uploads any uniform varia bles required |
| 83 by the shaders created in emitCode(). The GrEffect installed in the GrEf fectStage is | 85 by the shaders created in emitCode(). The GrEffect installed in the GrEf fectStage is |
| 84 guaranteed to be of the same type that created this GrGLEffect and to ha ve an identical | 86 guaranteed to be of the same type that created this GrGLEffect and to ha ve an identical |
| 85 EffectKey as the one that created this GrGLEffect. Effects that use loca l coords have | 87 EffectKey as the one that created this GrGLEffect. Effects that use loca l coords have |
| 86 to consider whether the GrEffectStage's coord change matrix should be us ed. When explicit | 88 to consider whether the GrEffectStage's coord change matrix should be us ed. When explicit |
| 87 local coordinates are used it can be ignored. */ | 89 local coordinates are used it can be ignored. */ |
| 88 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&); | 90 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&); |
| 89 | 91 |
| 90 const char* name() const { return fFactory.name(); } | 92 const char* name() const { return fFactory.name(); } |
| 91 | 93 |
| 94 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { retur n 0; } | |
|
bsalomon
2013/09/27 20:04:25
does this get called?
Chris Dalton
2013/09/27 23:33:45
Yeah. A lot of effects don't need to make their ow
bsalomon
2013/09/30 13:24:41
Oh wow. I don't think I ever seen this pattern of
| |
| 95 | |
| 92 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&); | 96 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&); |
| 97 static EffectKey GenTransformKey(const GrDrawEffect&); | |
| 93 static EffectKey GenAttribKey(const GrDrawEffect& stage); | 98 static EffectKey GenAttribKey(const GrDrawEffect& stage); |
| 94 | 99 |
| 95 protected: | 100 protected: |
| 96 const GrBackendEffectFactory& fFactory; | 101 const GrBackendEffectFactory& fFactory; |
| 97 }; | 102 }; |
| 98 | 103 |
| 99 #endif | 104 #endif |
| OLD | NEW |