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 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
10 #include "gl/GrGLSLPrettyPrint.h" | 10 #include "gl/GrGLSLPrettyPrint.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) | 21 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) |
22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) | 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) |
23 | 23 |
24 // ES2 FS only guarantees mediump and lowp support | 24 // ES2 FS only guarantees mediump and lowp support |
25 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar:
:kMedium_Precision; | 25 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar:
:kMedium_Precision; |
26 | 26 |
27 ////////////////////////////////////////////////////////////////////////////// | 27 ////////////////////////////////////////////////////////////////////////////// |
28 | 28 |
29 const int GrGLProgramBuilder::kVarsPerBlock = 8; | 29 const int GrGLProgramBuilder::kVarsPerBlock = 8; |
30 | 30 |
31 GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, | 31 GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, G
rGpuGL* gpu) { |
32 GrGpu::DrawType drawType, | |
33 GrGpuGL* gpu) { | |
34 // create a builder. This will be handed off to effects so they can use it
to add | 32 // create a builder. This will be handed off to effects so they can use it
to add |
35 // uniforms, varyings, textures, etc | 33 // uniforms, varyings, textures, etc |
36 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(optState, | 34 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(optState, |
37 drawType, | |
38 optState.hasG
eometryProcessor(), | 35 optState.hasG
eometryProcessor(), |
39 gpu)); | 36 gpu)); |
40 | 37 |
41 GrGLProgramBuilder* pb = builder.get(); | 38 GrGLProgramBuilder* pb = builder.get(); |
42 const GrGLProgramDescBuilder::GLKeyHeader& header = GrGLProgramDescBuilder::
GetHeader(pb->desc()); | 39 const GrGLProgramDescBuilder::GLKeyHeader& header = GrGLProgramDescBuilder::
GetHeader(pb->desc()); |
43 | 40 |
44 // emit code to read the dst copy texture, if necessary | 41 // emit code to read the dst copy texture, if necessary |
45 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != header.fDstReadKey | 42 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != header.fDstReadKey |
46 && !gpu->glCaps().fbFetchSupport()) { | 43 && !gpu->glCaps().fbFetchSupport()) { |
47 pb->fFS.emitCodeToReadDstTexture(); | 44 pb->fFS.emitCodeToReadDstTexture(); |
(...skipping 18 matching lines...) Expand all Loading... |
66 pb->fFS.enableSecondaryOutput(inputColor, inputCoverageVec4); | 63 pb->fFS.enableSecondaryOutput(inputColor, inputCoverageVec4); |
67 } | 64 } |
68 | 65 |
69 pb->fFS.combineColorAndCoverage(inputColor, inputCoverageVec4); | 66 pb->fFS.combineColorAndCoverage(inputColor, inputCoverageVec4); |
70 | 67 |
71 return pb->finalize(); | 68 return pb->finalize(); |
72 } | 69 } |
73 | 70 |
74 GrGLProgramBuilder* | 71 GrGLProgramBuilder* |
75 GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawState& optState, | 72 GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawState& optState, |
76 GrGpu::DrawType drawType, | |
77 bool hasGeometryProcessor, | 73 bool hasGeometryProcessor, |
78 GrGpuGL* gpu) { | 74 GrGpuGL* gpu) { |
79 const GrProgramDesc& desc = optState.programDesc(); | 75 const GrProgramDesc& desc = optState.programDesc(); |
80 if (GrGLProgramDescBuilder::GetHeader(desc).fUseNvpr) { | 76 if (GrGLProgramDescBuilder::GetHeader(desc).fUseNvpr) { |
81 SkASSERT(gpu->glCaps().pathRenderingSupport()); | 77 SkASSERT(gpu->glCaps().pathRenderingSupport()); |
82 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fColorInp
ut); | 78 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fColorInp
ut); |
83 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fCoverage
Input); | 79 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fCoverage
Input); |
84 SkASSERT(!hasGeometryProcessor); | 80 SkASSERT(!hasGeometryProcessor); |
85 if (gpu->glPathRendering()->texturingMode() == | 81 if (gpu->glPathRendering()->texturingMode() == |
86 GrGLPathRendering::FixedFunction_TexturingMode) { | 82 GrGLPathRendering::FixedFunction_TexturingMode) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } else if (GrProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) { | 223 } else if (GrProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) { |
228 *inputCoverage = GrGLSLExpr1(1); | 224 *inputCoverage = GrGLSLExpr1(1); |
229 } | 225 } |
230 } | 226 } |
231 | 227 |
232 void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr
4* inputCoverage) { | 228 void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr
4* inputCoverage) { |
233 if (fOptState.hasGeometryProcessor()) { | 229 if (fOptState.hasGeometryProcessor()) { |
234 fVS.setupUniformViewMatrix(); | 230 fVS.setupUniformViewMatrix(); |
235 | 231 |
236 const GrProgramDesc::KeyHeader& header = this->header(); | 232 const GrProgramDesc::KeyHeader& header = this->header(); |
237 if (header.fEmitsPointSize) { | 233 fVS.codeAppend("gl_PointSize = 1.0;"); |
238 fVS.codeAppend("gl_PointSize = 1.0;"); | |
239 } | |
240 | 234 |
241 // Setup position | 235 // Setup position |
242 // TODO it'd be possible to remove these from the vertexshader builder a
nd have them | 236 // TODO it'd be possible to remove these from the vertexshader builder a
nd have them |
243 // be outputs from the emit call. We don't do this because emitargs is
constant. It would | 237 // be outputs from the emit call. We don't do this because emitargs is
constant. It would |
244 // be easy to change this though | 238 // be easy to change this though |
245 fVS.codeAppendf("vec3 %s;", fVS.glPosition()); | 239 fVS.codeAppendf("vec3 %s;", fVS.glPosition()); |
246 fVS.codeAppendf("vec2 %s;", fVS.positionCoords()); | 240 fVS.codeAppendf("vec2 %s;", fVS.positionCoords()); |
247 fVS.codeAppendf("vec2 %s;", fVS.localCoords()); | 241 fVS.codeAppendf("vec2 %s;", fVS.localCoords()); |
248 | 242 |
249 const GrGeometryProcessor& gp = *fOptState.getGeometryProcessor(); | 243 const GrGeometryProcessor& gp = *fOptState.getGeometryProcessor(); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 } | 548 } |
555 | 549 |
556 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 550 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
557 | 551 |
558 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 552 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
559 int numProcs = fProcs.count(); | 553 int numProcs = fProcs.count(); |
560 for (int e = 0; e < numProcs; ++e) { | 554 for (int e = 0; e < numProcs; ++e) { |
561 SkDELETE(fProcs[e]); | 555 SkDELETE(fProcs[e]); |
562 } | 556 } |
563 } | 557 } |
OLD | NEW |