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" |
11 #include "GrCoordTransform.h" | 11 #include "GrCoordTransform.h" |
12 #include "GrGLProgramBuilder.h" | 12 #include "GrGLProgramBuilder.h" |
13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
14 #include "SkRTConf.h" | 14 #include "SkRTConf.h" |
15 #include "SkTraceEvent.h" | 15 #include "SkTraceEvent.h" |
| 16 #include "gl/GrGLFragmentProcessor.h" |
16 #include "gl/GrGLGeometryProcessor.h" | 17 #include "gl/GrGLGeometryProcessor.h" |
17 #include "gl/GrGLGpu.h" | 18 #include "gl/GrGLGpu.h" |
18 #include "gl/GrGLProgram.h" | 19 #include "gl/GrGLProgram.h" |
19 #include "gl/GrGLSLPrettyPrint.h" | 20 #include "gl/GrGLSLPrettyPrint.h" |
20 #include "gl/GrGLXferProcessor.h" | 21 #include "gl/GrGLXferProcessor.h" |
| 22 #include "gl/builders/GrGLShaderStringBuilder.h" |
21 #include "glsl/GrGLSLCaps.h" | 23 #include "glsl/GrGLSLCaps.h" |
22 #include "glsl/GrGLSLProgramDataManager.h" | 24 #include "glsl/GrGLSLProgramDataManager.h" |
23 #include "glsl/GrGLSLTextureSampler.h" | 25 #include "glsl/GrGLSLTextureSampler.h" |
24 | 26 |
25 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) | 27 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) |
26 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) | 28 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) |
27 | 29 |
28 const int GrGLProgramBuilder::kVarsPerBlock = 8; | 30 const int GrGLProgramBuilder::kVarsPerBlock = 8; |
29 | 31 |
30 GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp
u) { | 32 GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp
u) { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 for (int t = 0; t < numTextures; ++t) { | 375 for (int t = 0; t < numTextures; ++t) { |
374 name.printf("Sampler%d", t); | 376 name.printf("Sampler%d", t); |
375 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 377 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment
_Visibility, |
376 kSampler2D_GrSLType, kDefault
_GrSLPrecision, | 378 kSampler2D_GrSLType, kDefault
_GrSLPrecision, |
377 name.c_str()); | 379 name.c_str()); |
378 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler, | 380 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler, |
379 (localSamplerUniforms[t], processor.textureAccess
(t))); | 381 (localSamplerUniforms[t], processor.textureAccess
(t))); |
380 } | 382 } |
381 } | 383 } |
382 | 384 |
| 385 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLShaderBuilder& shader, |
| 386 GrGLuint programId, |
| 387 GrGLenum type, |
| 388 SkTDArray<GrGLuint>* shaderIds)
{ |
| 389 GrGLGpu* gpu = this->gpu(); |
| 390 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), |
| 391 programId, |
| 392 type, |
| 393 shader.fCompilerStrings.begin
(), |
| 394 shader.fCompilerStringLengths
.begin(), |
| 395 shader.fCompilerStrings.count
(), |
| 396 gpu->stats()); |
| 397 |
| 398 if (!shaderId) { |
| 399 return false; |
| 400 } |
| 401 |
| 402 *shaderIds->append() = shaderId; |
| 403 |
| 404 return true; |
| 405 } |
| 406 |
383 GrGLProgram* GrGLProgramBuilder::finalize() { | 407 GrGLProgram* GrGLProgramBuilder::finalize() { |
384 // verify we can get a program id | 408 // verify we can get a program id |
385 GrGLuint programID; | 409 GrGLuint programID; |
386 GL_CALL_RET(programID, CreateProgram()); | 410 GL_CALL_RET(programID, CreateProgram()); |
387 if (0 == programID) { | 411 if (0 == programID) { |
388 return nullptr; | 412 return nullptr; |
389 } | 413 } |
390 | 414 |
391 // compile shaders and bind attributes / uniforms | 415 // compile shaders and bind attributes / uniforms |
392 SkTDArray<GrGLuint> shadersToDelete; | 416 SkTDArray<GrGLuint> shadersToDelete; |
393 | 417 fVS.finalize(kVertex_Visibility); |
394 if (!fVS.compileAndAttachShaders(programID, &shadersToDelete)) { | 418 if (!this->compileAndAttachShaders(fVS, programID, GR_GL_VERTEX_SHADER, &sha
dersToDelete)) { |
395 this->cleanupProgram(programID, shadersToDelete); | 419 this->cleanupProgram(programID, shadersToDelete); |
396 return nullptr; | 420 return nullptr; |
397 } | 421 } |
398 | 422 |
399 // NVPR actually requires a vertex shader to compile | 423 // NVPR actually requires a vertex shader to compile |
400 bool useNvpr = primitiveProcessor().isPathRendering(); | 424 bool useNvpr = primitiveProcessor().isPathRendering(); |
401 if (!useNvpr) { | 425 if (!useNvpr) { |
402 fVS.bindVertexAttributes(programID); | 426 fVS.bindVertexAttributes(programID); |
403 } | 427 } |
404 | 428 |
405 if (!fFS.compileAndAttachShaders(programID, &shadersToDelete)) { | 429 fFS.finalize(kFragment_Visibility); |
| 430 if (!this->compileAndAttachShaders(fFS, programID, GR_GL_FRAGMENT_SHADER, &s
hadersToDelete)) { |
406 this->cleanupProgram(programID, shadersToDelete); | 431 this->cleanupProgram(programID, shadersToDelete); |
407 return nullptr; | 432 return nullptr; |
408 } | 433 } |
409 | 434 |
410 this->bindProgramResourceLocations(programID); | 435 this->bindProgramResourceLocations(programID); |
411 | 436 |
412 GL_CALL(LinkProgram(programID)); | 437 GL_CALL(LinkProgram(programID)); |
413 | 438 |
414 // Calling GetProgramiv is expensive in Chromium. Assume success in release
builds. | 439 // Calling GetProgramiv is expensive in Chromium. Assume success in release
builds. |
415 bool checkLinked = kChromium_GrGLDriver != fGpu->ctxInfo().driver(); | 440 bool checkLinked = kChromium_GrGLDriver != fGpu->ctxInfo().driver(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 544 } |
520 | 545 |
521 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 546 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
522 | 547 |
523 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 548 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
524 int numProcs = fProcs.count(); | 549 int numProcs = fProcs.count(); |
525 for (int i = 0; i < numProcs; ++i) { | 550 for (int i = 0; i < numProcs; ++i) { |
526 delete fProcs[i]; | 551 delete fProcs[i]; |
527 } | 552 } |
528 } | 553 } |
OLD | NEW |