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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 312 } |
313 | 313 |
314 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { | 314 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { |
315 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); | 315 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); |
316 } | 316 } |
317 | 317 |
318 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { | 318 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { |
319 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); | 319 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); |
320 } | 320 } |
321 | 321 |
| 322 static GrSLType get_sampler_type(const GrTextureAccess& access) { |
| 323 GrGLTexture* glTexture = static_cast<GrGLTexture*>(access.getTexture()); |
| 324 if (glTexture->target() == GR_GL_TEXTURE_EXTERNAL) { |
| 325 return kSamplerExternal_GrSLType; |
| 326 } else { |
| 327 SkASSERT(glTexture->target() == GR_GL_TEXTURE_2D); |
| 328 return kSampler2D_GrSLType; |
| 329 } |
| 330 } |
| 331 |
322 template <class Proc> | 332 template <class Proc> |
323 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, | 333 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, |
324 GrGLSLTextureSampler::TextureSamplerArray*
outSamplers, | 334 GrGLSLTextureSampler::TextureSamplerArray*
outSamplers, |
325 GrGLInstalledProc<Proc>* ip) { | 335 GrGLInstalledProc<Proc>* ip) { |
326 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();) | 336 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();) |
327 int numTextures = processor.numTextures(); | 337 int numTextures = processor.numTextures(); |
328 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur
es); | 338 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur
es); |
329 SkString name; | 339 SkString name; |
330 for (int t = 0; t < numTextures; ++t) { | 340 for (int t = 0; t < numTextures; ++t) { |
331 name.printf("Sampler%d", t); | 341 name.printf("Sampler%d", t); |
| 342 GrSLType samplerType = get_sampler_type(processor.textureAccess(t)); |
332 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 343 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment
_Visibility, |
333 kSampler2D_GrSLType, kDefault
_GrSLPrecision, | 344 samplerType, kDefault_GrSLPre
cision, |
334 name.c_str()); | 345 name.c_str()); |
335 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler, | 346 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler, |
336 (localSamplerUniforms[t], processor.textureAccess
(t))); | 347 (localSamplerUniforms[t], processor.textureAccess
(t))); |
| 348 if (kSamplerExternal_GrSLType == samplerType) { |
| 349 const char* externalFeatureString = this->glslCaps()->externalTextur
eExtensionString(); |
| 350 // We shouldn't ever create a GrGLTexture that requires external sam
pler type |
| 351 SkASSERT(externalFeatureString); |
| 352 fFS.addFeature(1 << GrGLSLFragmentShaderBuilder::kExternalTexture_GL
SLPrivateFeature, |
| 353 externalFeatureString); |
| 354 } |
337 } | 355 } |
338 } | 356 } |
339 | 357 |
340 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLSLShaderBuilder& shader, | 358 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLSLShaderBuilder& shader, |
341 GrGLuint programId, | 359 GrGLuint programId, |
342 GrGLenum type, | 360 GrGLenum type, |
343 SkTDArray<GrGLuint>* shaderIds)
{ | 361 SkTDArray<GrGLuint>* shaderIds)
{ |
344 GrGLGpu* gpu = this->gpu(); | 362 GrGLGpu* gpu = this->gpu(); |
345 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), | 363 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), |
346 programId, | 364 programId, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 529 } |
512 | 530 |
513 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 531 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
514 | 532 |
515 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 533 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
516 int numProcs = fProcs.count(); | 534 int numProcs = fProcs.count(); |
517 for (int i = 0; i < numProcs; ++i) { | 535 for (int i = 0; i < numProcs; ++i) { |
518 delete fProcs[i]; | 536 delete fProcs[i]; |
519 } | 537 } |
520 } | 538 } |
OLD | NEW |