| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } | 351 } |
| 352 | 352 |
| 353 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { | 353 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { |
| 354 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); | 354 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { | 357 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { |
| 358 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); | 358 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); |
| 359 } | 359 } |
| 360 | 360 |
| 361 static GrSLType get_sampler_type(const GrTextureAccess& access) { |
| 362 GrGLTexture* glTexture = static_cast<GrGLTexture*>(access.getTexture()); |
| 363 if (glTexture->target() == GR_GL_TEXTURE_EXTERNAL) { |
| 364 return kSamplerExternal_GrSLType; |
| 365 } else { |
| 366 SkASSERT(glTexture->target() == GR_GL_TEXTURE_2D); |
| 367 return kSampler2D_GrSLType; |
| 368 } |
| 369 } |
| 370 |
| 361 template <class Proc> | 371 template <class Proc> |
| 362 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, | 372 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, |
| 363 GrGLSLTextureSampler::TextureSamplerArray*
outSamplers, | 373 GrGLSLTextureSampler::TextureSamplerArray*
outSamplers, |
| 364 GrGLInstalledProc<Proc>* ip) { | 374 GrGLInstalledProc<Proc>* ip) { |
| 365 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();) | 375 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();) |
| 366 int numTextures = processor.numTextures(); | 376 int numTextures = processor.numTextures(); |
| 367 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur
es); | 377 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur
es); |
| 368 SkString name; | 378 SkString name; |
| 369 for (int t = 0; t < numTextures; ++t) { | 379 for (int t = 0; t < numTextures; ++t) { |
| 370 name.printf("Sampler%d", t); | 380 name.printf("Sampler%d", t); |
| 381 GrSLType samplerType = get_sampler_type(processor.textureAccess(t)); |
| 371 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 382 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment
_Visibility, |
| 372 kSampler2D_GrSLType, kDefault
_GrSLPrecision, | 383 samplerType, kDefault_GrSLPre
cision, |
| 373 name.c_str()); | 384 name.c_str()); |
| 374 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler, | 385 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler, |
| 375 (localSamplerUniforms[t], processor.textureAccess
(t))); | 386 (localSamplerUniforms[t], processor.textureAccess
(t))); |
| 387 if (kSamplerExternal_GrSLType == samplerType) { |
| 388 const char* externalFeatureString = this->glslCaps()->externalTextur
eExtensionString(); |
| 389 // We shouldn't ever create a GrGLTexture that requires external sam
pler type |
| 390 SkASSERT(externalFeatureString); |
| 391 fFS.addFeature(1 << GrGLSLFragmentShaderBuilder::kExternalTexture_GL
SLPrivateFeature, |
| 392 externalFeatureString); |
| 393 } |
| 376 } | 394 } |
| 377 } | 395 } |
| 378 | 396 |
| 379 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLSLShaderBuilder& shader, | 397 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLSLShaderBuilder& shader, |
| 380 GrGLuint programId, | 398 GrGLuint programId, |
| 381 GrGLenum type, | 399 GrGLenum type, |
| 382 SkTDArray<GrGLuint>* shaderIds)
{ | 400 SkTDArray<GrGLuint>* shaderIds)
{ |
| 383 GrGLGpu* gpu = this->gpu(); | 401 GrGLGpu* gpu = this->gpu(); |
| 384 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), | 402 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), |
| 385 programId, | 403 programId, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 } | 569 } |
| 552 | 570 |
| 553 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 571 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 554 | 572 |
| 555 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 573 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
| 556 int numProcs = fProcs.count(); | 574 int numProcs = fProcs.count(); |
| 557 for (int i = 0; i < numProcs; ++i) { | 575 for (int i = 0; i < numProcs; ++i) { |
| 558 delete fProcs[i]; | 576 delete fProcs[i]; |
| 559 } | 577 } |
| 560 } | 578 } |
| OLD | NEW |