OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2013 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef GrGLFragmentProcessor_DEFINED | |
9 #define GrGLFragmentProcessor_DEFINED | |
10 | |
11 #include "glsl/GrGLSLProcessorTypes.h" | |
12 #include "glsl/GrGLSLProgramDataManager.h" | |
13 #include "glsl/GrGLSLTextureSampler.h" | |
14 | |
15 class GrProcessor; | |
16 class GrProcessorKeyBuilder; | |
17 class GrGLSLFPBuilder; | |
18 class GrGLSLCaps; | |
19 | |
20 class GrGLFragmentProcessor { | |
21 public: | |
22 GrGLFragmentProcessor() {} | |
23 | |
24 virtual ~GrGLFragmentProcessor() { | |
25 for (int i = 0; i < fChildProcessors.count(); ++i) { | |
26 delete fChildProcessors[i]; | |
27 } | |
28 } | |
29 | |
30 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | |
31 typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray; | |
32 | |
33 /** Called when the program stage should insert its code into the shaders. T
he code in each | |
34 shader will be in its own block ({}) and so locally scoped names will no
t collide across | |
35 stages. | |
36 | |
37 @param builder Interface used to emit code in the shaders. | |
38 @param processor The processor that generated this program stage. | |
39 @param key The key that was computed by GenKey() from the gener
ating GrProcessor. | |
40 @param outputColor A predefined vec4 in the FS in which the stage shoul
d place its output | |
41 color (or coverage). | |
42 @param inputColor A vec4 that holds the input color to the stage in th
e FS. This may be | |
43 nullptr in which case the implied input is solid whi
te (all ones). | |
44 TODO: Better system for communicating optimization i
nfo (e.g. input | |
45 color is solid white, trans black, known to be opaqu
e, etc.) that allows | |
46 the processor to communicate back similar known info
about its output. | |
47 @param samplers Contains one entry for each GrTextureAccess of the G
rProcessor. These | |
48 can be passed to the builder to emit texture reads i
n the generated | |
49 code. | |
50 */ | |
51 | |
52 struct EmitArgs { | |
53 EmitArgs(GrGLSLFPBuilder* builder, | |
54 const GrFragmentProcessor& fp, | |
55 const char* outputColor, | |
56 const char* inputColor, | |
57 const GrGLSLTransformedCoordsArray& coords, | |
58 const TextureSamplerArray& samplers) | |
59 : fBuilder(builder) | |
60 , fFp(fp) | |
61 , fOutputColor(outputColor) | |
62 , fInputColor(inputColor) | |
63 , fCoords(coords) | |
64 , fSamplers(samplers) {} | |
65 GrGLSLFPBuilder* fBuilder; | |
66 const GrFragmentProcessor& fFp; | |
67 const char* fOutputColor; | |
68 const char* fInputColor; | |
69 const GrGLSLTransformedCoordsArray& fCoords; | |
70 const TextureSamplerArray& fSamplers; | |
71 }; | |
72 | |
73 virtual void emitCode(EmitArgs&) = 0; | |
74 | |
75 void setData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcesso
r& processor); | |
76 | |
77 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuil
der*) {} | |
78 | |
79 int numChildProcessors() const { return fChildProcessors.count(); } | |
80 | |
81 GrGLFragmentProcessor* childProcessor(int index) const { | |
82 return fChildProcessors[index]; | |
83 } | |
84 | |
85 /** Will emit the code of a child proc in its own scope. Pass in the parent'
s EmitArgs and | |
86 * emitChild will automatically extract the coords and samplers of that chi
ld and pass them | |
87 * on to the child's emitCode(). Also, any uniforms or functions emitted by
the child will | |
88 * have their names mangled to prevent redefinitions. The output color name
is also mangled | |
89 * therefore in an in/out param. It will be declared in mangled form by emi
tChild(). It is | |
90 * legal to pass nullptr as inputColor, since all fragment processors are r
equired to work | |
91 * without an input color. | |
92 */ | |
93 void emitChild(int childIndex, const char* inputColor, SkString* outputColor
, | |
94 EmitArgs& parentArgs); | |
95 | |
96 /** Variation that uses the parent's output color variable to hold the child
's output.*/ | |
97 void emitChild(int childIndex, const char* inputColor, EmitArgs& parentArgs)
; | |
98 | |
99 protected: | |
100 /** A GrGLFragmentProcessor instance can be reused with any GrFragmentProces
sor that produces | |
101 the same stage key; this function reads data from a GrFragmentProcessor and
uploads any | |
102 uniform variables required by the shaders created in emitCode(). The GrFragm
entProcessor | |
103 parameter is guaranteed to be of the same type that created this GrGLFragmen
tProcessor and | |
104 to have an identical processor key as the one that created this GrGLFragment
Processor. */ | |
105 // TODO update this to pass in GrFragmentProcessor | |
106 virtual void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&)
{} | |
107 | |
108 private: | |
109 void internalEmitChild(int, const char*, const char*, EmitArgs&); | |
110 | |
111 SkTArray<GrGLFragmentProcessor*, true> fChildProcessors; | |
112 | |
113 friend class GrFragmentProcessor; | |
114 }; | |
115 | |
116 #endif | |
OLD | NEW |