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

Unified Diff: src/gpu/gl/builders/GrGLShaderBuilder.cpp

Issue 929503002: Multi-string shaders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: windows warning Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderStringBuilder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/builders/GrGLShaderBuilder.cpp
diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.cpp b/src/gpu/gl/builders/GrGLShaderBuilder.cpp
index 48872256dab58ad5cb0e25c114d70eb862fcaf3e..c1bc959709f2f20ce46b31595122e9c2d85d428f 100644
--- a/src/gpu/gl/builders/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderBuilder.cpp
@@ -7,7 +7,7 @@
#include "GrGLShaderBuilder.h"
#include "GrGLProgramBuilder.h"
-#include "GrGLProgramBuilder.h"
+#include "GrGLShaderStringBuilder.h"
#include "../GrGLGpu.h"
#include "../GrGLShaderVar.h"
@@ -59,7 +59,17 @@ GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program)
: fProgramBuilder(program)
, fInputs(GrGLProgramBuilder::kVarsPerBlock)
, fOutputs(GrGLProgramBuilder::kVarsPerBlock)
- , fFeaturesAddedMask(0) {
+ , fFeaturesAddedMask(0)
+ , fCodeIndex(kCode)
+ , fFinalized(false) {
+ // We push back some dummy pointers which will later become our header
+ for (int i = 0; i <= kCode; i++) {
+ fShaderStrings.push_back();
+ fCompilerStrings.push_back(NULL);
+ fCompilerStringLengths.push_back(0);
+ }
+
+ this->main() = "void main() {";
}
void GrGLShaderBuilder::declAppend(const GrGLShaderVar& var) {
@@ -74,20 +84,20 @@ void GrGLShaderBuilder::emitFunction(GrSLType returnType,
const GrGLShaderVar* args,
const char* body,
SkString* outName) {
- fFunctions.append(GrGLSLTypeString(returnType));
+ this->functions().append(GrGLSLTypeString(returnType));
fProgramBuilder->nameVariable(outName, '\0', name);
- fFunctions.appendf(" %s", outName->c_str());
- fFunctions.append("(");
+ this->functions().appendf(" %s", outName->c_str());
+ this->functions().append("(");
const GrGLContextInfo& ctxInfo = fProgramBuilder->gpu()->ctxInfo();
for (int i = 0; i < argCnt; ++i) {
- args[i].appendDecl(ctxInfo, &fFunctions);
+ args[i].appendDecl(ctxInfo, &this->functions());
if (i < argCnt - 1) {
- fFunctions.append(", ");
+ this->functions().append(", ");
}
}
- fFunctions.append(") {\n");
- fFunctions.append(body);
- fFunctions.append("}\n\n");
+ this->functions().append(") {\n");
+ this->functions().append(body);
+ this->functions().append("}\n\n");
}
void GrGLShaderBuilder::appendTextureLookup(SkString* out,
@@ -106,7 +116,7 @@ void GrGLShaderBuilder::appendTextureLookup(SkString* out,
void GrGLShaderBuilder::appendTextureLookup(const TextureSampler& sampler,
const char* coordName,
GrSLType varyingType) {
- this->appendTextureLookup(&fCode, sampler, coordName, varyingType);
+ this->appendTextureLookup(&this->code(), sampler, coordName, varyingType);
}
void GrGLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
@@ -137,8 +147,8 @@ const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons
void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionName) {
if (!(featureBit & fFeaturesAddedMask)) {
- fExtensions.appendf("#extension %s: require\n", extensionName);
- fFeaturesAddedMask |= featureBit;
+ this->extensions().appendf("#extension %s: require\n", extensionName);
+ fFeaturesAddedMask |= featureBit;
}
}
@@ -153,7 +163,7 @@ void GrGLShaderBuilder::appendTextureLookup(const char* samplerName,
const char* coordName,
uint32_t configComponentMask,
const char* swizzle) {
- append_texture_lookup(&fCode,
+ append_texture_lookup(&this->code(),
fProgramBuilder->gpu(),
samplerName,
coordName,
@@ -161,3 +171,34 @@ void GrGLShaderBuilder::appendTextureLookup(const char* samplerName,
swizzle,
kVec2f_GrSLType);
}
+
+bool
+GrGLShaderBuilder::finalize(GrGLuint programId, GrGLenum type, SkTDArray<GrGLuint>* shaderIds) {
+ SkASSERT(!fFinalized);
+ // append the 'footer' to code
+ this->code().append("}");
+
+ for (int i = 0; i <= fCodeIndex; i++) {
+ fCompilerStrings[i] = fShaderStrings[i].c_str();
+ fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
+ }
+
+ GrGLGpu* gpu = fProgramBuilder->gpu();
+ GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(),
+ programId,
+ type,
+ fCompilerStrings.begin(),
+ fCompilerStringLengths.begin(),
+ fCompilerStrings.count(),
+ gpu->stats());
+
+ fFinalized = true;
+
+ if (!shaderId) {
+ return false;
+ }
+
+ *shaderIds->append() = shaderId;
+
+ return true;
+}
« no previous file with comments | « src/gpu/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderStringBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698