| 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" | |
| 12 #include "GrGLProgramDataManager.h" | 11 #include "GrGLProgramDataManager.h" |
| 12 #include "GrProcessor.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 ProcessorSubclass::ProcessorSubclass(const GrBackendProcessorFactory&, c
onst GrProcessor&) |
| 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 // TODO delete this and make TextureSampler its own thing |
| 30 class GrGLProcessor { | 30 class GrGLProcessor { |
| 31 public: | 31 public: |
| 32 GrGLProcessor(const GrBackendProcessorFactory& factory) | |
| 33 : fFactory(factory) { | |
| 34 } | |
| 35 | |
| 36 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 32 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 37 | 33 |
| 38 /** | 34 /** |
| 39 * Passed to GrGLProcessors so they can add transformed coordinates to their
shader code. | 35 * Passed to GrGLProcessors so they can add transformed coordinates to their
shader code. |
| 40 */ | 36 */ |
| 41 typedef GrShaderVar TransformedCoords; | 37 typedef GrShaderVar TransformedCoords; |
| 42 typedef SkTArray<GrShaderVar> TransformedCoordsArray; | 38 typedef SkTArray<GrShaderVar> TransformedCoordsArray; |
| 43 | 39 |
| 44 /** | 40 /** |
| 45 * Passed to GrGLProcessors so they can add texture reads to their shader co
de. | 41 * Passed to GrGLProcessors so they can add texture reads to their shader co
de. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 60 | 56 |
| 61 private: | 57 private: |
| 62 UniformHandle fSamplerUniform; | 58 UniformHandle fSamplerUniform; |
| 63 uint32_t fConfigComponentMask; | 59 uint32_t fConfigComponentMask; |
| 64 char fSwizzle[5]; | 60 char fSwizzle[5]; |
| 65 | 61 |
| 66 friend class GrGLShaderBuilder; | 62 friend class GrGLShaderBuilder; |
| 67 }; | 63 }; |
| 68 | 64 |
| 69 typedef SkTArray<TextureSampler> TextureSamplerArray; | 65 typedef SkTArray<TextureSampler> TextureSamplerArray; |
| 70 | |
| 71 virtual ~GrGLProcessor() {} | |
| 72 | |
| 73 const char* name() const { return fFactory.name(); } | |
| 74 | |
| 75 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilde
r*) {} | |
| 76 | |
| 77 protected: | |
| 78 const GrBackendProcessorFactory& fFactory; | |
| 79 }; | 66 }; |
| 80 | 67 |
| 81 class GrGLFPBuilder; | 68 class GrGLFPBuilder; |
| 82 | 69 |
| 83 class GrGLFragmentProcessor : public GrGLProcessor { | 70 class GrGLFragmentProcessor { |
| 84 public: | 71 public: |
| 85 GrGLFragmentProcessor(const GrBackendProcessorFactory& factory) | 72 GrGLFragmentProcessor() {} |
| 86 : INHERITED(factory) { | |
| 87 } | |
| 88 | 73 |
| 89 virtual ~GrGLFragmentProcessor() {} | 74 virtual ~GrGLFragmentProcessor() {} |
| 90 | 75 |
| 76 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 77 typedef GrGLProcessor::TransformedCoordsArray TransformedCoordsArray; |
| 78 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
| 79 |
| 91 /** Called when the program stage should insert its code into the shaders. T
he code in each | 80 /** 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 | 81 shader will be in its own block ({}) and so locally scoped names will no
t collide across |
| 93 stages. | 82 stages. |
| 94 | 83 |
| 95 @param builder Interface used to emit code in the shaders. | 84 @param builder Interface used to emit code in the shaders. |
| 96 @param processor The processor that generated this program stage. | 85 @param processor The processor that generated this program stage. |
| 97 @param key The key that was computed by GenKey() from the gener
ating GrProcessor. | 86 @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 | 87 @param outputColor A predefined vec4 in the FS in which the stage shoul
d place its output |
| 99 color (or coverage). | 88 color (or coverage). |
| 100 @param inputColor A vec4 that holds the input color to the stage in th
e FS. This may be | 89 @param inputColor A vec4 that holds the input color to the stage in th
e FS. This may be |
| (...skipping 14 matching lines...) Expand all Loading... |
| 115 const TextureSamplerArray& samplers) = 0; | 104 const TextureSamplerArray& samplers) = 0; |
| 116 | 105 |
| 117 /** A GrGLFragmentProcessor instance can be reused with any GrFragmentProces
sor that produces | 106 /** 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 | 107 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 | 108 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 | 109 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. */ | 110 to have an identical processor key as the one that created this GrGLFrag
mentProcessor. */ |
| 122 // TODO update this to pass in GrFragmentProcessor | 111 // TODO update this to pass in GrFragmentProcessor |
| 123 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {} | 112 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {} |
| 124 | 113 |
| 114 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilde
r*) {} |
| 115 |
| 125 private: | 116 private: |
| 126 typedef GrGLProcessor INHERITED; | 117 typedef GrGLProcessor INHERITED; |
| 127 }; | 118 }; |
| 128 | 119 |
| 129 class GrGLXferProcessor : public GrGLFragmentProcessor { | 120 class GrGLXferProcessor : public GrGLFragmentProcessor { |
| 130 public: | 121 public: |
| 131 GrGLXferProcessor(const GrBackendProcessorFactory& factory) | 122 GrGLXferProcessor() {} |
| 132 : INHERITED(factory) { | |
| 133 } | |
| 134 | 123 |
| 135 virtual ~GrGLXferProcessor() {} | 124 virtual ~GrGLXferProcessor() {} |
| 136 | 125 |
| 137 private: | 126 private: |
| 138 typedef GrGLFragmentProcessor INHERITED; | 127 typedef GrGLFragmentProcessor INHERITED; |
| 139 }; | 128 }; |
| 140 | 129 |
| 141 #endif | 130 #endif |
| OLD | NEW |