OLD | NEW |
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 "GrGLProgramBuilder.h" | 8 #include "GrGLProgramBuilder.h" |
9 | 9 |
10 #include "GrAutoLocaleSetter.h" | 10 #include "GrAutoLocaleSetter.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 // create a builder. This will be handed off to effects so they can use it
to add | 34 // create a builder. This will be handed off to effects so they can use it
to add |
35 // uniforms, varyings, textures, etc | 35 // uniforms, varyings, textures, etc |
36 GrGLProgramBuilder builder(gpu, args); | 36 GrGLProgramBuilder builder(gpu, args); |
37 | 37 |
38 // TODO: Once all stages can handle taking a float or vec4 and correctly han
dling them we can | 38 // TODO: Once all stages can handle taking a float or vec4 and correctly han
dling them we can |
39 // seed correctly here | 39 // seed correctly here |
40 GrGLSLExpr4 inputColor; | 40 GrGLSLExpr4 inputColor; |
41 GrGLSLExpr4 inputCoverage; | 41 GrGLSLExpr4 inputCoverage; |
42 | 42 |
43 if (!builder.emitAndInstallProcs(&inputColor, | 43 if (!builder.emitAndInstallProcs(&inputColor, &inputCoverage)) { |
44 &inputCoverage, | |
45 gpu->glCaps().maxFragmentTextureUnits())) { | |
46 builder.cleanupFragmentProcessors(); | 44 builder.cleanupFragmentProcessors(); |
47 return nullptr; | 45 return nullptr; |
48 } | 46 } |
49 | 47 |
50 return builder.finalize(); | 48 return builder.finalize(); |
51 } | 49 } |
52 | 50 |
53 ///////////////////////////////////////////////////////////////////////////// | 51 ///////////////////////////////////////////////////////////////////////////// |
54 | 52 |
55 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) | 53 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) |
56 : INHERITED(args) | 54 : INHERITED(args) |
57 , fGpu(gpu) | 55 , fGpu(gpu) |
58 , fSamplerUniforms(4) | |
59 , fVaryingHandler(this) | 56 , fVaryingHandler(this) |
60 , fUniformHandler(this) { | 57 , fUniformHandler(this) { |
61 } | 58 } |
62 | 59 |
63 const GrCaps* GrGLProgramBuilder::caps() const { | 60 const GrCaps* GrGLProgramBuilder::caps() const { |
64 return fGpu->caps(); | 61 return fGpu->caps(); |
65 } | 62 } |
66 | 63 |
67 const GrGLSLCaps* GrGLProgramBuilder::glslCaps() const { | 64 const GrGLSLCaps* GrGLProgramBuilder::glslCaps() const { |
68 return fGpu->ctxInfo().caps()->glslCaps(); | 65 return fGpu->ctxInfo().caps()->glslCaps(); |
69 } | 66 } |
70 | 67 |
71 static GrSLType get_sampler_type(const GrTextureAccess& access) { | |
72 GrGLTexture* glTexture = static_cast<GrGLTexture*>(access.getTexture()); | |
73 if (glTexture->target() == GR_GL_TEXTURE_EXTERNAL) { | |
74 return kSamplerExternal_GrSLType; | |
75 } else if (glTexture->target() == GR_GL_TEXTURE_RECTANGLE) { | |
76 return kSampler2DRect_GrSLType; | |
77 } else { | |
78 SkASSERT(glTexture->target() == GR_GL_TEXTURE_2D); | |
79 return kSampler2D_GrSLType; | |
80 } | |
81 } | |
82 | |
83 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, | |
84 GrGLSLTextureSampler::TextureSamplerArray*
outSamplers) { | |
85 int numTextures = processor.numTextures(); | |
86 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur
es); | |
87 SkString name; | |
88 for (int t = 0; t < numTextures; ++t) { | |
89 name.printf("Sampler%d", t); | |
90 GrSLType samplerType = get_sampler_type(processor.textureAccess(t)); | |
91 localSamplerUniforms[t] = fUniformHandler.addUniform(kFragment_GrShaderF
lag, samplerType, | |
92 kDefault_GrSLPrecis
ion, name.c_str()); | |
93 outSamplers->emplace_back(localSamplerUniforms[t], processor.textureAcce
ss(t)); | |
94 if (kSamplerExternal_GrSLType == samplerType) { | |
95 const char* externalFeatureString = this->glslCaps()->externalTextur
eExtensionString(); | |
96 // We shouldn't ever create a GrGLTexture that requires external sam
pler type | |
97 SkASSERT(externalFeatureString); | |
98 fFS.addFeature(1 << GrGLSLFragmentShaderBuilder::kExternalTexture_GL
SLPrivateFeature, | |
99 externalFeatureString); | |
100 } | |
101 } | |
102 } | |
103 | |
104 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLSLShaderBuilder& shader, | 68 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLSLShaderBuilder& shader, |
105 GrGLuint programId, | 69 GrGLuint programId, |
106 GrGLenum type, | 70 GrGLenum type, |
107 SkTDArray<GrGLuint>* shaderIds)
{ | 71 SkTDArray<GrGLuint>* shaderIds)
{ |
108 GrGLGpu* gpu = this->gpu(); | 72 GrGLGpu* gpu = this->gpu(); |
109 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), | 73 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), |
110 programId, | 74 programId, |
111 type, | 75 type, |
112 shader.fCompilerStrings.begin
(), | 76 shader.fCompilerStrings.begin
(), |
113 shader.fCompilerStringLengths
.begin(), | 77 shader.fCompilerStringLengths
.begin(), |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 fUniformHandles, | 226 fUniformHandles, |
263 programID, | 227 programID, |
264 fUniformHandler.fUniforms, | 228 fUniformHandler.fUniforms, |
265 fVaryingHandler.fPathProcVaryingInfos, | 229 fVaryingHandler.fPathProcVaryingInfos, |
266 fGeometryProcessor, | 230 fGeometryProcessor, |
267 fXferProcessor, | 231 fXferProcessor, |
268 fFragmentProcessors, | 232 fFragmentProcessors, |
269 &fSamplerUniforms); | 233 &fSamplerUniforms); |
270 } | 234 } |
271 | 235 |
OLD | NEW |