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

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

Issue 611653002: Cleanup of shader building system (Closed) Base URL: https://skia.googlesource.com/skia.git@solo_gp
Patch Set: Created 6 years, 2 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
« no previous file with comments | « src/gpu/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 #include "GrGLShaderBuilder.h" 8 #include "GrGLShaderBuilder.h"
9 #include "GrGLFullProgramBuilder.h" 9 #include "GrGLProgramBuilder.h"
10 #include "GrGLProgramBuilder.h" 10 #include "GrGLProgramBuilder.h"
11 #include "../GrGpuGL.h" 11 #include "../GrGpuGL.h"
12 #include "../GrGLShaderVar.h" 12 #include "../GrGLShaderVar.h"
13 13
14 namespace { 14 namespace {
15 inline const char* sample_function_name(GrSLType type, GrGLSLGeneration glslGen) { 15 inline const char* sample_function_name(GrSLType type, GrGLSLGeneration glslGen) {
16 if (kVec2f_GrSLType == type) { 16 if (kVec2f_GrSLType == type) {
17 return glslGen >= k130_GrGLSLGeneration ? "texture" : "texture2D"; 17 return glslGen >= k130_GrGLSLGeneration ? "texture" : "texture2D";
18 } else { 18 } else {
19 SkASSERT(kVec3f_GrSLType == type); 19 SkASSERT(kVec3f_GrSLType == type);
(...skipping 26 matching lines...) Expand all
46 mangledSwizzle[i] = alphaChar; 46 mangledSwizzle[i] = alphaChar;
47 } 47 }
48 mangledSwizzle[i] ='\0'; 48 mangledSwizzle[i] ='\0';
49 swizzle = mangledSwizzle; 49 swizzle = mangledSwizzle;
50 } 50 }
51 // For shader prettiness we omit the swizzle rather than appending ".rgba". 51 // For shader prettiness we omit the swizzle rather than appending ".rgba".
52 if (memcmp(swizzle, "rgba", 4)) { 52 if (memcmp(swizzle, "rgba", 4)) {
53 out->appendf(".%s", swizzle); 53 out->appendf(".%s", swizzle);
54 } 54 }
55 } 55 }
56 static const int kVarsPerBlock = 8;
57 } 56 }
58 57
59 GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program) 58 GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program)
60 : fProgramBuilder(program) 59 : fProgramBuilder(program)
61 , fInputs(kVarsPerBlock) 60 , fInputs(GrGLProgramBuilder::kVarsPerBlock)
62 , fOutputs(kVarsPerBlock) 61 , fOutputs(GrGLProgramBuilder::kVarsPerBlock)
63 , fFeaturesAddedMask(0) { 62 , fFeaturesAddedMask(0) {
64 } 63 }
65 64
66 void GrGLShaderBuilder::declAppend(const GrGLShaderVar& var) { 65 void GrGLShaderBuilder::declAppend(const GrGLShaderVar& var) {
67 SkString tempDecl; 66 SkString tempDecl;
68 var.appendDecl(fProgramBuilder->ctxInfo(), &tempDecl); 67 var.appendDecl(fProgramBuilder->ctxInfo(), &tempDecl);
69 this->codeAppendf("%s;", tempDecl.c_str()); 68 this->codeAppendf("%s;", tempDecl.c_str());
70 } 69 }
71 70
72 void GrGLShaderBuilder::emitFunction(GrSLType returnType, 71 void GrGLShaderBuilder::emitFunction(GrSLType returnType,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 135 }
137 } 136 }
138 137
139 void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionNam e) { 138 void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionNam e) {
140 if (!(featureBit & fFeaturesAddedMask)) { 139 if (!(featureBit & fFeaturesAddedMask)) {
141 fExtensions.appendf("#extension %s: require\n", extensionName); 140 fExtensions.appendf("#extension %s: require\n", extensionName);
142 fFeaturesAddedMask |= featureBit; 141 fFeaturesAddedMask |= featureBit;
143 } 142 }
144 } 143 }
145 144
145 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
146 for (int i = 0; i < vars.count(); ++i) {
147 vars[i].appendDecl(fProgramBuilder->ctxInfo(), out);
148 out->append(";\n");
149 }
150 }
151
146 void GrGLShaderBuilder::appendTextureLookup(const char* samplerName, 152 void GrGLShaderBuilder::appendTextureLookup(const char* samplerName,
147 const char* coordName, 153 const char* coordName,
148 uint32_t configComponentMask, 154 uint32_t configComponentMask,
149 const char* swizzle) { 155 const char* swizzle) {
150 append_texture_lookup(&fCode, 156 append_texture_lookup(&fCode,
151 fProgramBuilder->gpu(), 157 fProgramBuilder->gpu(),
152 samplerName, 158 samplerName,
153 coordName, 159 coordName,
154 configComponentMask, 160 configComponentMask,
155 swizzle, 161 swizzle,
156 kVec2f_GrSLType); 162 kVec2f_GrSLType);
157 } 163 }
158
159 //////////////////////////////////////////////////////////////////////////////// ///////////////////
160 GrGLFullShaderBuilder::GrGLFullShaderBuilder(GrGLFullProgramBuilder* program)
161 : INHERITED(program)
162 , fFullProgramBuilder(program) {}
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698