Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: src/gpu/gl/builders/GrGLShaderBuilder.h

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 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 GrGLShaderBuilder_DEFINED
9 #define GrGLShaderBuilder_DEFINED
10
11 #include "gl/GrGLProgramDesc.h"
12 #include "gl/GrGLProgramEffects.h"
13 #include "gl/GrGLSL.h"
14 #include "gl/GrGLProgramDataManager.h"
15 #include "GrAllocator.h"
16 #include "GrBackendEffectFactory.h"
17 #include "GrColor.h"
18 #include "GrEffect.h"
19 #include "SkTypes.h"
20
21 #include <stdarg.h>
22
23 class GrGLContextInfo;
24 class GrEffectStage;
25 class GrGLProgramDesc;
26 class GrGLProgramBuilder;
27 class GrGLFullProgramBuilder;
28
29 /**
30 base class for all shaders
bsalomon 2014/08/21 17:18:00 How about "... all shader builders"?
31 */
32 class GrGLShaderBuilder {
33 public:
34 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
35 typedef GrGLProgramEffects::TextureSampler TextureSampler;
36 GrGLShaderBuilder(GrGLProgramBuilder* program);
37
38 void addInput(GrGLShaderVar i) { fInputs.push_back(i); }
39 void addOutput(GrGLShaderVar i) { fOutputs.push_back(i); }
40
41 /*
42 * We put texture lookups in the base class because it is TECHNICALLY possib le to do texture
43 * lookups in any kind of shader. However, For the most part, usage of thes e features should be
bsalomon 2014/08/21 17:18:00 Would it work anywhere else? Maybe we should say "
44 * confined to the fragment shader.
45 */
46 /** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or
47 Vec3f. The latter is interpreted as projective texture coords. The vec l ength and swizzle
48 order of the result depends on the GrTextureAccess associated with the T extureSampler. */
49 void appendTextureLookup(SkString* out,
50 const TextureSampler&,
51 const char* coordName,
52 GrSLType coordType = kVec2f_GrSLType) const;
53
54 /** Version of above that appends the result to the fragment shader code ins tead.*/
55 void appendTextureLookup(const TextureSampler&,
56 const char* coordName,
57 GrSLType coordType = kVec2f_GrSLType);
58
59
60 /** Does the work of appendTextureLookup and modulates the result by modulat ion. The result is
61 always a vec4. modulation and the swizzle specified by TextureSampler mu st both be vec4 or
62 float. If modulation is "" or NULL it this function acts as though appen dTextureLookup were
63 called. */
64 void appendTextureLookupAndModulate(const char* modulation,
65 const TextureSampler&,
66 const char* coordName,
67 GrSLType coordType = kVec2f_GrSLType);
68
69 /** If texture swizzling is available using tex parameters then it is prefer red over mangling
70 the generated shader code. This potentially allows greater reuse of cach ed shaders. */
71 static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCa ps& caps);
72
73 /**
74 * Called by GrGLEffects to add code to one of the shaders.
75 */
76 void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
77 va_list args;
78 va_start(args, format);
79 fCode.appendVAList(format, args);
80 va_end(args);
81 }
82
83 void codeAppend(const char* str) { fCode.append(str); }
84
85 void codePrependf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
86 va_list args;
87 va_start(args, format);
88 fCode.prependVAList(format, args);
89 va_end(args);
90 }
91
92 /** Emits a helper function outside of main() in the fragment shader. */
93 void emitFunction(GrSLType returnType,
94 const char* name,
95 int argCnt,
96 const GrGLShaderVar* args,
97 const char* body,
98 SkString* outName);
99
100 /*
101 * Get parent builder for adding uniforms
102 */
103 GrGLProgramBuilder* getProgramBuilder() { return fProgram; }
104
105 /**
106 * Helper for begining and ending a block in the fragment code.
107 */
108 class ShaderBlock {
109 public:
110 ShaderBlock(GrGLShaderBuilder* builder) : fBuilder(builder) {
111 SkASSERT(NULL != builder);
112 fBuilder->codeAppend("{");
113 }
114
115 ~ShaderBlock() {
116 fBuilder->codeAppend("}");
117 }
118 private:
119 GrGLShaderBuilder* fBuilder;
120 };
121 protected:
122
123 /*
124 * this super low level function is just for use internally to builders
125 */
126 void appendTextureLookup(const char* samplerName,
127 const char* coordName,
128 uint32_t configComponentMask,
129 const char* swizzle);
130
131 /*
132 * A general function which enables an extension in a shader if the feature bit is not present
133 */
134 void addFeature(uint32_t featureBit, const char* extensionName);
135
136 typedef GrTAllocator<GrGLShaderVar> VarArray;
137
138 GrGLProgramBuilder* fProgram;
139
140 SkString fCode;
141 SkString fFunctions;
142 SkString fExtensions;
143
144 VarArray fInputs;
145 VarArray fOutputs;
146 uint32_t fFeaturesAddedMask;
147 };
148
149 class GrGLFullShaderBuilder : public GrGLShaderBuilder {
bsalomon 2014/08/21 17:18:00 Why do we need this subclass?
150 public:
151 GrGLFullShaderBuilder(GrGLFullProgramBuilder* program);
152
153 GrGLFullProgramBuilder* fullProgram() { return fFullProgram; }
154 protected:
155 GrGLFullProgramBuilder* fFullProgram;
156 private:
157 typedef GrGLShaderBuilder INHERITED;
158 };
159 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698