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 "gl/GrGLGeometryProcessor.h" | 10 #include "gl/GrGLGeometryProcessor.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // uniforms, varyings, textures, etc | 60 // uniforms, varyings, textures, etc |
61 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(args, gpu)); | 61 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(args, gpu)); |
62 | 62 |
63 GrGLProgramBuilder* pb = builder.get(); | 63 GrGLProgramBuilder* pb = builder.get(); |
64 | 64 |
65 // TODO: Once all stages can handle taking a float or vec4 and correctly han
dling them we can | 65 // TODO: Once all stages can handle taking a float or vec4 and correctly han
dling them we can |
66 // seed correctly here | 66 // seed correctly here |
67 GrGLSLExpr4 inputColor; | 67 GrGLSLExpr4 inputColor; |
68 GrGLSLExpr4 inputCoverage; | 68 GrGLSLExpr4 inputCoverage; |
69 | 69 |
70 pb->emitAndInstallProcs(&inputColor, &inputCoverage); | 70 if (!pb->emitAndInstallProcs(&inputColor, &inputCoverage)) { |
| 71 return NULL; |
| 72 } |
71 | 73 |
72 return pb->finalize(); | 74 return pb->finalize(); |
73 } | 75 } |
74 | 76 |
75 GrGLProgramBuilder* GrGLProgramBuilder::CreateProgramBuilder(const DrawArgs& arg
s, | 77 GrGLProgramBuilder* GrGLProgramBuilder::CreateProgramBuilder(const DrawArgs& arg
s, |
76 GrGLGpu* gpu) { | 78 GrGLGpu* gpu) { |
77 if (args.fPrimitiveProcessor->isPathRendering()) { | 79 if (args.fPrimitiveProcessor->isPathRendering()) { |
78 SkASSERT(gpu->glCaps().shaderCaps()->pathRenderingSupport() && | 80 SkASSERT(gpu->glCaps().shaderCaps()->pathRenderingSupport() && |
79 !args.fPrimitiveProcessor->willUseGeoShader() && | 81 !args.fPrimitiveProcessor->willUseGeoShader() && |
80 args.fPrimitiveProcessor->numAttribs() == 0); | 82 args.fPrimitiveProcessor->numAttribs() == 0); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); | 184 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); |
183 out->append(";\n"); | 185 out->append(";\n"); |
184 } | 186 } |
185 } | 187 } |
186 } | 188 } |
187 | 189 |
188 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { | 190 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { |
189 return fGpu->ctxInfo(); | 191 return fGpu->ctxInfo(); |
190 } | 192 } |
191 | 193 |
192 void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr
4* inputCoverage) { | 194 bool GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr
4* inputCoverage) { |
193 // First we loop over all of the installed processors and collect coord tran
sforms. These will | 195 // First we loop over all of the installed processors and collect coord tran
sforms. These will |
194 // be sent to the GrGLPrimitiveProcessor in its emitCode function | 196 // be sent to the GrGLPrimitiveProcessor in its emitCode function |
| 197 const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); |
| 198 int totalTextures = primProc.numTextures(); |
| 199 const int maxTextureUnits = fGpu->glCaps().maxFragmentTextureUnits(); |
195 SkSTArray<8, GrGLProcessor::TransformedCoordsArray> outCoords; | 200 SkSTArray<8, GrGLProcessor::TransformedCoordsArray> outCoords; |
196 for (int i = 0; i < this->pipeline().numFragmentStages(); i++) { | 201 for (int i = 0; i < this->pipeline().numFragmentStages(); i++) { |
197 const GrFragmentProcessor* processor = this->pipeline().getFragmentStage
(i).processor(); | 202 const GrFragmentProcessor* processor = this->pipeline().getFragmentStage
(i).processor(); |
198 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTransfor
ms.push_back(); | 203 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTransfor
ms.push_back(); |
199 for (int t = 0; t < processor->numTransforms(); t++) { | 204 for (int t = 0; t < processor->numTransforms(); t++) { |
200 procCoords.push_back(&processor->coordTransform(t)); | 205 procCoords.push_back(&processor->coordTransform(t)); |
201 } | 206 } |
| 207 |
| 208 totalTextures += processor->numTextures(); |
| 209 if (totalTextures >= maxTextureUnits) { |
| 210 GrContextDebugf(fGpu->getContext(), "Program would use too many text
ure units\n"); |
| 211 return false; |
| 212 } |
202 } | 213 } |
203 | 214 |
204 const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); | |
205 this->emitAndInstallProc(primProc, inputColor, inputCoverage); | 215 this->emitAndInstallProc(primProc, inputColor, inputCoverage); |
206 | 216 |
207 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); | 217 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); |
208 int numProcs = this->pipeline().numFragmentStages(); | 218 int numProcs = this->pipeline().numFragmentStages(); |
209 this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentStages(),
inputColor); | 219 this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentStages(),
inputColor); |
210 this->emitAndInstallFragProcs(this->pipeline().numColorFragmentStages(), num
Procs, | 220 this->emitAndInstallFragProcs(this->pipeline().numColorFragmentStages(), num
Procs, |
211 inputCoverage); | 221 inputCoverage); |
212 this->emitAndInstallXferProc(*this->pipeline().getXferProcessor(), *inputCol
or, *inputCoverage); | 222 this->emitAndInstallXferProc(*this->pipeline().getXferProcessor(), *inputCol
or, *inputCoverage); |
| 223 return true; |
213 } | 224 } |
214 | 225 |
215 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, | 226 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, |
216 int numProcs, | 227 int numProcs, |
217 GrGLSLExpr4* inOut) { | 228 GrGLSLExpr4* inOut) { |
218 for (int e = procOffset; e < numProcs; ++e) { | 229 for (int e = procOffset; e < numProcs; ++e) { |
219 GrGLSLExpr4 output; | 230 GrGLSLExpr4 output; |
220 const GrPendingFragmentStage& stage = this->pipeline().getFragmentStage(
e); | 231 const GrPendingFragmentStage& stage = this->pipeline().getFragmentStage(
e); |
221 this->emitAndInstallProc(stage, e, *inOut, &output); | 232 this->emitAndInstallProc(stage, e, *inOut, &output); |
222 *inOut = output; | 233 *inOut = output; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 503 } |
493 | 504 |
494 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 505 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
495 | 506 |
496 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 507 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
497 int numProcs = fProcs.count(); | 508 int numProcs = fProcs.count(); |
498 for (int e = 0; e < numProcs; ++e) { | 509 for (int e = 0; e < numProcs; ++e) { |
499 SkDELETE(fProcs[e]); | 510 SkDELETE(fProcs[e]); |
500 } | 511 } |
501 } | 512 } |
OLD | NEW |