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

Side by Side Diff: src/gpu/glsl/GrGLSLShaderBuilder.cpp

Issue 1569393002: Revert of Add a class representing texture swizzle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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/glsl/GrGLSLCaps.cpp ('k') | src/gpu/glsl/GrGLSLTextureSampler.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 "GrSwizzle.h"
9 #include "glsl/GrGLSLShaderBuilder.h" 8 #include "glsl/GrGLSLShaderBuilder.h"
10 #include "glsl/GrGLSLCaps.h" 9 #include "glsl/GrGLSLCaps.h"
11 #include "glsl/GrGLSLShaderVar.h" 10 #include "glsl/GrGLSLShaderVar.h"
12 #include "glsl/GrGLSLTextureSampler.h" 11 #include "glsl/GrGLSLTextureSampler.h"
13 #include "glsl/GrGLSLProgramBuilder.h" 12 #include "glsl/GrGLSLProgramBuilder.h"
14 13
14 static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangl edSwizzle) {
15 int i;
16 for (i = 0; '\0' != swizzle[i]; ++i) {
17 switch (swizzle[i]) {
18 case 'r':
19 mangledSwizzle[i] = swizzleMap[0];
20 break;
21 case 'g':
22 mangledSwizzle[i] = swizzleMap[1];
23 break;
24 case 'b':
25 mangledSwizzle[i] = swizzleMap[2];
26 break;
27 case 'a':
28 mangledSwizzle[i] = swizzleMap[3];
29 break;
30 default:
31 SkFAIL("Unsupported swizzle");
32 }
33 }
34 mangledSwizzle[i] ='\0';
35 }
36
37 static void append_texture_lookup(SkString* out,
38 const GrGLSLCaps* glslCaps,
39 const char* samplerName,
40 const char* coordName,
41 GrPixelConfig config,
42 const char* swizzle,
43 GrSLType varyingType = kVec2f_GrSLType) {
44 SkASSERT(coordName);
45
46 out->appendf("%s(%s, %s)",
47 GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation() ),
48 samplerName,
49 coordName);
50
51 char mangledSwizzle[5];
52
53 // This refers to any swizzling we may need to get from some backend interna l format to the
54 // format used in GrPixelConfig. Some backends will automatically do the siz zling for us.
55 if (glslCaps->mustSwizzleInShader()) {
56 const char* swizzleMap = glslCaps->getSwizzleMap(config);
57 // if the map is simply 'rgba' then we don't need to do any manual swizz ling to get us to
58 // a GrPixelConfig format.
59 if (memcmp(swizzleMap, "rgba", 4)) {
60 // Manually 'swizzle' the swizzle using our mapping
61 map_swizzle(swizzleMap, swizzle, mangledSwizzle);
62 swizzle = mangledSwizzle;
63 }
64 }
65
66 // For shader prettiness we omit the swizzle rather than appending ".rgba".
67 if (memcmp(swizzle, "rgba", 4)) {
68 out->appendf(".%s", swizzle);
69 }
70 }
71
15 GrGLSLShaderBuilder::GrGLSLShaderBuilder(GrGLSLProgramBuilder* program) 72 GrGLSLShaderBuilder::GrGLSLShaderBuilder(GrGLSLProgramBuilder* program)
16 : fProgramBuilder(program) 73 : fProgramBuilder(program)
17 , fInputs(GrGLSLProgramBuilder::kVarsPerBlock) 74 , fInputs(GrGLSLProgramBuilder::kVarsPerBlock)
18 , fOutputs(GrGLSLProgramBuilder::kVarsPerBlock) 75 , fOutputs(GrGLSLProgramBuilder::kVarsPerBlock)
19 , fFeaturesAddedMask(0) 76 , fFeaturesAddedMask(0)
20 , fCodeIndex(kCode) 77 , fCodeIndex(kCode)
21 , fFinalized(false) { 78 , fFinalized(false) {
22 // We push back some dummy pointers which will later become our header 79 // We push back some dummy pointers which will later become our header
23 for (int i = 0; i <= kCode; i++) { 80 for (int i = 0; i <= kCode; i++) {
24 fShaderStrings.push_back(); 81 fShaderStrings.push_back();
(...skipping 28 matching lines...) Expand all
53 } 110 }
54 this->functions().append(") {\n"); 111 this->functions().append(") {\n");
55 this->functions().append(body); 112 this->functions().append(body);
56 this->functions().append("}\n\n"); 113 this->functions().append("}\n\n");
57 } 114 }
58 115
59 void GrGLSLShaderBuilder::appendTextureLookup(SkString* out, 116 void GrGLSLShaderBuilder::appendTextureLookup(SkString* out,
60 const GrGLSLTextureSampler& sample r, 117 const GrGLSLTextureSampler& sample r,
61 const char* coordName, 118 const char* coordName,
62 GrSLType varyingType) const { 119 GrSLType varyingType) const {
63 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
64 GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler(); 120 GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler();
65 out->appendf("%s(%s, %s)", 121 append_texture_lookup(out,
66 GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation() ), 122 fProgramBuilder->glslCaps(),
67 uniformHandler->getUniformCStr(sampler.fSamplerUniform), 123 uniformHandler->getUniformCStr(sampler.fSamplerUniform ),
68 coordName); 124 coordName,
69 125 sampler.config(),
70 // This refers to any swizzling we may need to get from some backend interna l format to the 126 sampler.swizzle(),
71 // format used in GrPixelConfig. If this is implemented by the GrGpu object, then swizzle will 127 varyingType);
72 // be rgba. For shader prettiness we omit the swizzle rather than appending ".rgba".
73 const GrSwizzle& configSwizzle = glslCaps->configTextureSwizzle(sampler.conf ig());
74
75 if (configSwizzle != GrSwizzle::RGBA()) {
76 out->appendf(".%s", configSwizzle.c_str());
77 }
78 } 128 }
79 129
80 void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLTextureSampler& sample r, 130 void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLTextureSampler& sample r,
81 const char* coordName, 131 const char* coordName,
82 GrSLType varyingType) { 132 GrSLType varyingType) {
83 this->appendTextureLookup(&this->code(), sampler, coordName, varyingType); 133 this->appendTextureLookup(&this->code(), sampler, coordName, varyingType);
84 } 134 }
85 135
86 void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation, 136 void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
87 const GrGLSLTextureSamp ler& sampler, 137 const GrGLSLTextureSamp ler& sampler,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 this->code().append("}"); 197 this->code().append("}");
148 198
149 for (int i = 0; i <= fCodeIndex; i++) { 199 for (int i = 0; i <= fCodeIndex; i++) {
150 fCompilerStrings[i] = fShaderStrings[i].c_str(); 200 fCompilerStrings[i] = fShaderStrings[i].c_str();
151 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); 201 fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
152 } 202 }
153 203
154 fFinalized = true; 204 fFinalized = true;
155 } 205 }
156 206
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLCaps.cpp ('k') | src/gpu/glsl/GrGLSLTextureSampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698