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

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

Issue 1869063005: Add GLSL support for texelFetch (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_renaem
Patch Set: rebase Created 4 years, 8 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/GrGLSLShaderBuilder.h ('k') | no next file » | 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" 8 #include "GrSwizzle.h"
9 #include "glsl/GrGLSLShaderBuilder.h" 9 #include "glsl/GrGLSLShaderBuilder.h"
10 #include "glsl/GrGLSLCaps.h" 10 #include "glsl/GrGLSLCaps.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 coordName, 86 coordName,
87 coordName); 87 coordName);
88 } 88 }
89 } else { 89 } else {
90 out->appendf("%s(%s, %s)", 90 out->appendf("%s(%s, %s)",
91 GrGLSLTexture2DFunctionName(varyingType, samplerType, glslC aps->generation()), 91 GrGLSLTexture2DFunctionName(varyingType, samplerType, glslC aps->generation()),
92 uniformHandler->getUniformCStr(sampler.fSamplerUniform), 92 uniformHandler->getUniformCStr(sampler.fSamplerUniform),
93 coordName); 93 coordName);
94 } 94 }
95 95
96 // This refers to any swizzling we may need to get from some backend interna l format to the 96 this->appendTextureSwizzle(out, sampler.config());
97 // format used in GrPixelConfig. If this is implemented by the GrGpu object, then swizzle will
98 // be rgba. For shader prettiness we omit the swizzle rather than appending ".rgba".
99 const GrSwizzle& configSwizzle = glslCaps->configTextureSwizzle(sampler.conf ig());
100
101 if (configSwizzle != GrSwizzle::RGBA()) {
102 out->appendf(".%s", configSwizzle.c_str());
103 }
104 } 97 }
105 98
106 void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLSampler& sampler, 99 void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLSampler& sampler,
107 const char* coordName, 100 const char* coordName,
108 GrSLType varyingType) { 101 GrSLType varyingType) {
109 this->appendTextureLookup(&this->code(), sampler, coordName, varyingType); 102 this->appendTextureLookup(&this->code(), sampler, coordName, varyingType);
110 } 103 }
111 104
112 void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation, 105 void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
113 const GrGLSLSampler& sa mpler, 106 const GrGLSLSampler& sa mpler,
114 const char* coordName, 107 const char* coordName,
115 GrSLType varyingType) { 108 GrSLType varyingType) {
116 SkString lookup; 109 SkString lookup;
117 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); 110 this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
118 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()); 111 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
119 } 112 }
120 113
114 void GrGLSLShaderBuilder::appendTexelFetch(SkString* out,
115 const GrGLSLSampler& sampler,
116 const char* coordExpr) const {
117 const GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler ();
118 SkASSERT(fProgramBuilder->glslCaps()->texelFetchSupport());
119 SkASSERT(GrSLTypeIsSamplerType(
120 uniformHandler->getUniformVariable(sampler.fSamplerUniform).getType ()));
121
122 out->appendf("texelFetch(%s, %s)",
123 uniformHandler->getUniformCStr(sampler.fSamplerUniform),
124 coordExpr);
125
126 this->appendTextureSwizzle(out, sampler.config());
127 }
128
129 void GrGLSLShaderBuilder::appendTexelFetch(const GrGLSLSampler& sampler, const c har* coordExpr) {
130 this->appendTexelFetch(&this->code(), sampler, coordExpr);
131 }
132
133 void GrGLSLShaderBuilder::appendTextureSwizzle(SkString* out, GrPixelConfig conf ig) const {
134 const GrSwizzle& configSwizzle = fProgramBuilder->glslCaps()->configTextureS wizzle(config);
135
136 if (configSwizzle != GrSwizzle::RGBA()) {
137 out->appendf(".%s", configSwizzle.c_str());
138 }
139 }
140
121 bool GrGLSLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionN ame) { 141 bool GrGLSLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionN ame) {
122 if (featureBit & fFeaturesAddedMask) { 142 if (featureBit & fFeaturesAddedMask) {
123 return false; 143 return false;
124 } 144 }
125 this->extensions().appendf("#extension %s: require\n", extensionName); 145 this->extensions().appendf("#extension %s: require\n", extensionName);
126 fFeaturesAddedMask |= featureBit; 146 fFeaturesAddedMask |= featureBit;
127 return true; 147 return true;
128 } 148 }
129 149
130 void GrGLSLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { 150 void GrGLSLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // append the 'footer' to code 193 // append the 'footer' to code
174 this->code().append("}"); 194 this->code().append("}");
175 195
176 for (int i = 0; i <= fCodeIndex; i++) { 196 for (int i = 0; i <= fCodeIndex; i++) {
177 fCompilerStrings[i] = fShaderStrings[i].c_str(); 197 fCompilerStrings[i] = fShaderStrings[i].c_str();
178 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); 198 fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
179 } 199 }
180 200
181 fFinalized = true; 201 fFinalized = true;
182 } 202 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698