| 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 GrGLProcessor_DEFINED | 8 #ifndef GrGLProcessor_DEFINED |
| 9 #define GrGLProcessor_DEFINED | 9 #define GrGLProcessor_DEFINED |
| 10 | 10 |
| 11 #include "GrBackendProcessorFactory.h" | 11 #include "GrBackendProcessorFactory.h" |
| 12 #include "GrGLProgramDataManager.h" | 12 #include "GrGLProgramDataManager.h" |
| 13 #include "GrTextureAccess.h" | 13 #include "GrTextureAccess.h" |
| 14 | 14 |
| 15 /** @file | 15 /** @file |
| 16 This file contains specializations for OpenGL of the shader stages declared
in | 16 This file contains specializations for OpenGL of the shader stages declared
in |
| 17 include/gpu/GrProcessor.h. Objects of type GrGLProcessor are responsible for
emitting the | 17 include/gpu/GrProcessor.h. Objects of type GrGLProcessor are responsible for
emitting the |
| 18 GLSL code that implements a GrProcessor and for uploading uniforms at draw t
ime. If they don't | 18 GLSL code that implements a GrProcessor and for uploading uniforms at draw t
ime. If they don't |
| 19 always emit the same GLSL code, they must have a function: | 19 always emit the same GLSL code, they must have a function: |
| 20 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcess
orKeyBuilder*) | 20 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcess
orKeyBuilder*) |
| 21 that is used to implement a program cache. When two GrProcessors produce the
same key this means | 21 that is used to implement a program cache. When two GrProcessors produce the
same key this means |
| 22 that their GrGLProcessors would emit the same GLSL code. | 22 that their GrGLProcessors would emit the same GLSL code. |
| 23 | 23 |
| 24 The GrGLProcessor subclass must also have a constructor of the form: | 24 The GrGLProcessor subclass must also have a constructor of the form: |
| 25 ProcessorSubclass::ProcessorSubclass(const GrBackendProcessorFactory&, c
onst GrProcessor&) | 25 EffectSubclass::EffectSubclass(const GrBackendProcessorFactory&, const G
rProcessor&) |
| 26 | 26 |
| 27 These objects are created by the factory object returned by the GrProcessor:
:getFactory(). | 27 These objects are created by the factory object returned by the GrProcessor:
:getFactory(). |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 class GrGLProcessor { | 30 class GrGLProcessor { |
| 31 public: | 31 public: |
| 32 GrGLProcessor(const GrBackendProcessorFactory& factory) | 32 GrGLProcessor(const GrBackendProcessorFactory& factory) |
| 33 : fFactory(factory) { | 33 : fFactory(factory) { |
| 34 } | 34 } |
| 35 | 35 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 63 uint32_t fConfigComponentMask; | 63 uint32_t fConfigComponentMask; |
| 64 char fSwizzle[5]; | 64 char fSwizzle[5]; |
| 65 | 65 |
| 66 friend class GrGLShaderBuilder; | 66 friend class GrGLShaderBuilder; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 typedef SkTArray<TextureSampler> TextureSamplerArray; | 69 typedef SkTArray<TextureSampler> TextureSamplerArray; |
| 70 | 70 |
| 71 virtual ~GrGLProcessor() {} | 71 virtual ~GrGLProcessor() {} |
| 72 | 72 |
| 73 /** A GrGLProcessor instance can be reused with any GrProcessor that produce
s the same stage |
| 74 key; this function reads data from a GrProcessor and uploads any uniform
variables required |
| 75 by the shaders created in emitCode(). The GrProcessor parameter is guara
nteed to be of the |
| 76 same type that created this GrGLProcessor and to have an identical effec
t key as the one |
| 77 that created this GrGLProcessor. */ |
| 78 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {} |
| 79 |
| 73 const char* name() const { return fFactory.name(); } | 80 const char* name() const { return fFactory.name(); } |
| 74 | 81 |
| 75 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilde
r*) {} | 82 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilde
r*) {} |
| 76 | 83 |
| 77 protected: | 84 protected: |
| 78 const GrBackendProcessorFactory& fFactory; | 85 const GrBackendProcessorFactory& fFactory; |
| 79 }; | 86 }; |
| 80 | 87 |
| 81 class GrGLFPBuilder; | 88 class GrGLFPBuilder; |
| 82 | 89 |
| 83 class GrGLFragmentProcessor : public GrGLProcessor { | 90 class GrGLFragmentProcessor : public GrGLProcessor { |
| 84 public: | 91 public: |
| 85 GrGLFragmentProcessor(const GrBackendProcessorFactory& factory) | 92 GrGLFragmentProcessor(const GrBackendProcessorFactory& factory) |
| 86 : INHERITED(factory) { | 93 : INHERITED(factory) { |
| 87 } | 94 } |
| 88 | 95 |
| 89 virtual ~GrGLFragmentProcessor() {} | 96 virtual ~GrGLFragmentProcessor() {} |
| 90 | 97 |
| 91 /** Called when the program stage should insert its code into the shaders. T
he code in each | 98 /** Called when the program stage should insert its code into the shaders. T
he code in each |
| 92 shader will be in its own block ({}) and so locally scoped names will no
t collide across | 99 shader will be in its own block ({}) and so locally scoped names will no
t collide across |
| 93 stages. | 100 stages. |
| 94 | 101 |
| 95 @param builder Interface used to emit code in the shaders. | 102 @param builder Interface used to emit code in the shaders. |
| 96 @param processor The processor that generated this program stage. | 103 @param effect The effect that generated this program stage. |
| 97 @param key The key that was computed by GenKey() from the gener
ating GrProcessor. | 104 @param key The key that was computed by GenKey() from the gener
ating GrProcessor. |
| 98 @param outputColor A predefined vec4 in the FS in which the stage shoul
d place its output | 105 @param outputColor A predefined vec4 in the FS in which the stage shoul
d place its output |
| 99 color (or coverage). | 106 color (or coverage). |
| 100 @param inputColor A vec4 that holds the input color to the stage in th
e FS. This may be | 107 @param inputColor A vec4 that holds the input color to the stage in th
e FS. This may be |
| 101 NULL in which case the implied input is solid white
(all ones). | 108 NULL in which case the implied input is solid white
(all ones). |
| 102 TODO: Better system for communicating optimization i
nfo (e.g. input | 109 TODO: Better system for communicating optimization i
nfo (e.g. input |
| 103 color is solid white, trans black, known to be opaqu
e, etc.) that allows | 110 color is solid white, trans black, known to be opaqu
e, etc.) that allows |
| 104 the processor to communicate back similar known info
about its output. | 111 the effect to communicate back similar known info ab
out its output. |
| 105 @param samplers Contains one entry for each GrTextureAccess of the G
rProcessor. These | 112 @param samplers Contains one entry for each GrTextureAccess of the G
rProcessor. These |
| 106 can be passed to the builder to emit texture reads i
n the generated | 113 can be passed to the builder to emit texture reads i
n the generated |
| 107 code. | 114 code. |
| 108 TODO this should take a struct | 115 TODO this should take a struct |
| 109 */ | 116 */ |
| 110 virtual void emitCode(GrGLFPBuilder* builder, | 117 virtual void emitCode(GrGLFPBuilder* builder, |
| 111 const GrFragmentProcessor&, | 118 const GrFragmentProcessor& effect, |
| 112 const char* outputColor, | 119 const char* outputColor, |
| 113 const char* inputColor, | 120 const char* inputColor, |
| 114 const TransformedCoordsArray& coords, | 121 const TransformedCoordsArray& coords, |
| 115 const TextureSamplerArray& samplers) = 0; | 122 const TextureSamplerArray& samplers) = 0; |
| 116 | 123 |
| 117 /** A GrGLFragmentProcessor instance can be reused with any GrFragmentProces
sor that produces | |
| 118 the same stage key; this function reads data from a GrFragmentProcessor
and uploads any | |
| 119 uniform variables required by the shaders created in emitCode(). The GrF
ragmentProcessor | |
| 120 parameter is guaranteed to be of the same type that created this GrGLFra
gmentProcessor and | |
| 121 to have an identical processor key as the one that created this GrGLFrag
mentProcessor. */ | |
| 122 // TODO update this to pass in GrFragmentProcessor | |
| 123 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {} | |
| 124 | |
| 125 private: | 124 private: |
| 126 typedef GrGLProcessor INHERITED; | 125 typedef GrGLProcessor INHERITED; |
| 127 }; | 126 }; |
| 128 | 127 |
| 129 class GrGLXferProcessor : public GrGLFragmentProcessor { | 128 class GrGLXferProcessor : public GrGLFragmentProcessor { |
| 130 public: | 129 public: |
| 131 GrGLXferProcessor(const GrBackendProcessorFactory& factory) | 130 GrGLXferProcessor(const GrBackendProcessorFactory& factory) |
| 132 : INHERITED(factory) { | 131 : INHERITED(factory) { |
| 133 } | 132 } |
| 134 | 133 |
| 135 virtual ~GrGLXferProcessor() {} | 134 virtual ~GrGLXferProcessor() {} |
| 136 | 135 |
| 137 private: | 136 private: |
| 138 typedef GrGLFragmentProcessor INHERITED; | 137 typedef GrGLFragmentProcessor INHERITED; |
| 139 }; | 138 }; |
| 140 | 139 |
| 141 #endif | 140 #endif |
| OLD | NEW |