OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
9 | 9 |
10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
11 #include "GrEffect.h" | 11 #include "GrEffect.h" |
12 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
13 #include "GrDrawEffect.h" | 13 #include "GrDrawEffect.h" |
14 #include "GrGLEffect.h" | 14 #include "GrGLEffect.h" |
15 #include "GrGpuGL.h" | 15 #include "GrGpuGL.h" |
16 #include "GrGLPathRendering.h" | 16 #include "GrGLPathRendering.h" |
17 #include "GrGLShaderVar.h" | 17 #include "GrGLShaderVar.h" |
18 #include "GrGLSL.h" | 18 #include "GrGLSL.h" |
19 #include "SkXfermode.h" | 19 #include "SkXfermode.h" |
20 | 20 |
21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
23 | 23 |
24 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, | 24 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, |
25 const GrGLProgramDesc& desc, | 25 const GrGLProgramDesc& desc, |
| 26 const GrEffectStage* geometryProcessor, |
26 const GrEffectStage* colorStages[], | 27 const GrEffectStage* colorStages[], |
27 const GrEffectStage* coverageStages[]) { | 28 const GrEffectStage* coverageStages[]) { |
28 SkAutoTDelete<GrGLProgramBuilder> builder; | 29 SkAutoTDelete<GrGLProgramBuilder> builder; |
29 if (!desc.getHeader().fRequiresVertexShader && | 30 if (!desc.getHeader().fRequiresVertexShader && |
30 gpu->glCaps().pathRenderingSupport() && | 31 gpu->glCaps().pathRenderingSupport() && |
31 gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunct
ion_TexturingMode) { | 32 gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunct
ion_TexturingMode) { |
| 33 SkASSERT(NULL == geometryProcessor); |
32 builder.reset(SkNEW_ARGS(GrGLFragmentOnlyProgramBuilder, (gpu, desc))); | 34 builder.reset(SkNEW_ARGS(GrGLFragmentOnlyProgramBuilder, (gpu, desc))); |
33 } else { | 35 } else { |
34 builder.reset(SkNEW_ARGS(GrGLFullProgramBuilder, (gpu, desc))); | 36 builder.reset(SkNEW_ARGS(GrGLFullProgramBuilder, (gpu, desc))); |
35 } | 37 } |
36 if (builder->genProgram(colorStages, coverageStages)) { | 38 if (builder->genProgram(geometryProcessor, colorStages, coverageStages)) { |
37 SkASSERT(0 != builder->getProgramID()); | 39 SkASSERT(0 != builder->getProgramID()); |
38 return SkNEW_ARGS(GrGLProgram, (gpu, desc, *builder)); | 40 return SkNEW_ARGS(GrGLProgram, (gpu, desc, *builder)); |
39 } | 41 } |
40 return NULL; | 42 return NULL; |
41 } | 43 } |
42 | 44 |
43 GrGLProgram::GrGLProgram(GrGpuGL* gpu, | 45 GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
44 const GrGLProgramDesc& desc, | 46 const GrGLProgramDesc& desc, |
45 const GrGLProgramBuilder& builder) | 47 const GrGLProgramBuilder& builder) |
46 : fColor(GrColor_ILLEGAL) | 48 : fColor(GrColor_ILLEGAL) |
47 , fCoverage(GrColor_ILLEGAL) | 49 , fCoverage(GrColor_ILLEGAL) |
48 , fDstCopyTexUnit(-1) | 50 , fDstCopyTexUnit(-1) |
49 , fBuiltinUniformHandles(builder.getBuiltinUniformHandles()) | 51 , fBuiltinUniformHandles(builder.getBuiltinUniformHandles()) |
| 52 , fGeometryProcessor(SkSafeRef(builder.getGeometryProcessor())) |
50 , fColorEffects(SkRef(builder.getColorEffects())) | 53 , fColorEffects(SkRef(builder.getColorEffects())) |
51 , fCoverageEffects(SkRef(builder.getCoverageEffects())) | 54 , fCoverageEffects(SkRef(builder.getCoverageEffects())) |
52 , fProgramID(builder.getProgramID()) | 55 , fProgramID(builder.getProgramID()) |
53 , fHasVertexShader(builder.hasVertexShader()) | 56 , fHasVertexShader(builder.hasVertexShader()) |
54 , fTexCoordSetCnt(builder.getTexCoordSetCount()) | 57 , fTexCoordSetCnt(builder.getTexCoordSetCount()) |
55 , fDesc(desc) | 58 , fDesc(desc) |
56 , fGpu(gpu) | 59 , fGpu(gpu) |
57 , fProgramDataManager(gpu, this, builder) { | 60 , fProgramDataManager(gpu, this, builder) { |
58 this->initSamplerUniforms(); | 61 this->initSamplerUniforms(); |
59 } | 62 } |
(...skipping 30 matching lines...) Expand all Loading... |
90 } | 93 } |
91 } | 94 } |
92 | 95 |
93 void GrGLProgram::initSamplerUniforms() { | 96 void GrGLProgram::initSamplerUniforms() { |
94 GL_CALL(UseProgram(fProgramID)); | 97 GL_CALL(UseProgram(fProgramID)); |
95 GrGLint texUnitIdx = 0; | 98 GrGLint texUnitIdx = 0; |
96 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { | 99 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { |
97 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni
, texUnitIdx); | 100 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni
, texUnitIdx); |
98 fDstCopyTexUnit = texUnitIdx++; | 101 fDstCopyTexUnit = texUnitIdx++; |
99 } | 102 } |
| 103 if (NULL != fGeometryProcessor.get()) { |
| 104 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); |
| 105 } |
100 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 106 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
101 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 107 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
102 } | 108 } |
103 | 109 |
104 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
105 | 111 |
106 void GrGLProgram::setData(GrGpu::DrawType drawType, | 112 void GrGLProgram::setData(GrGpu::DrawType drawType, |
107 GrDrawState::BlendOptFlags blendOpts, | 113 GrDrawState::BlendOptFlags blendOpts, |
| 114 const GrEffectStage* geometryProcessor, |
108 const GrEffectStage* colorStages[], | 115 const GrEffectStage* colorStages[], |
109 const GrEffectStage* coverageStages[], | 116 const GrEffectStage* coverageStages[], |
110 const GrDeviceCoordTexture* dstCopy, | 117 const GrDeviceCoordTexture* dstCopy, |
111 SharedGLState* sharedState) { | 118 SharedGLState* sharedState) { |
112 const GrDrawState& drawState = fGpu->getDrawState(); | 119 const GrDrawState& drawState = fGpu->getDrawState(); |
113 | 120 |
114 GrColor color; | 121 GrColor color; |
115 GrColor coverage; | 122 GrColor coverage; |
116 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { | 123 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { |
117 color = 0; | 124 color = 0; |
(...skipping 24 matching lines...) Expand all Loading... |
142 } else { | 149 } else { |
143 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 150 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
144 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 151 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
145 } | 152 } |
146 } else { | 153 } else { |
147 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); | 154 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); |
148 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 155 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
149 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 156 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
150 } | 157 } |
151 | 158 |
| 159 if (NULL != fGeometryProcessor.get()) { |
| 160 SkASSERT(NULL != geometryProcessor); |
| 161 fGeometryProcessor->setData(fGpu, drawType,fProgramDataManager, geometry
Processor); |
| 162 } |
152 fColorEffects->setData(fGpu, drawType,fProgramDataManager, colorStages); | 163 fColorEffects->setData(fGpu, drawType,fProgramDataManager, colorStages); |
153 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages
); | 164 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages
); |
154 | 165 |
155 // PathTexGen state applies to the the fixed function vertex shader. For | 166 // PathTexGen state applies to the the fixed function vertex shader. For |
156 // custom shaders, it's ignored, so we don't need to change the texgen | 167 // custom shaders, it's ignored, so we don't need to change the texgen |
157 // settings in that case. | 168 // settings in that case. |
158 if (!fHasVertexShader) { | 169 if (!fHasVertexShader) { |
159 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 170 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
160 } | 171 } |
161 } | 172 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 274 |
264 GrGLfloat viewMatrix[3 * 3]; | 275 GrGLfloat viewMatrix[3 * 3]; |
265 fMatrixState.getGLMatrix<3>(viewMatrix); | 276 fMatrixState.getGLMatrix<3>(viewMatrix); |
266 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); | 277 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); |
267 | 278 |
268 GrGLfloat rtAdjustmentVec[4]; | 279 GrGLfloat rtAdjustmentVec[4]; |
269 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 280 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
270 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); | 281 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); |
271 } | 282 } |
272 } | 283 } |
OLD | NEW |