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" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 const GrTextureAccess& textureAccess = processor.textureAccess(s); | 116 const GrTextureAccess& textureAccess = processor.textureAccess(s); |
117 fGpu->bindTexture(samplers[s].fTextureUnit, | 117 fGpu->bindTexture(samplers[s].fTextureUnit, |
118 textureAccess.getParams(), | 118 textureAccess.getParams(), |
119 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; | 119 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 | 123 |
124 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
125 | 125 |
126 void GrGLProgram::setData(const GrOptDrawState& optState) { | 126 void GrGLProgram::setData(const GrOptDrawState& optState, GrGpu::DrawType drawTy
pe) { |
127 GrColor color = optState.getColor(); | 127 GrColor color = optState.getColor(); |
128 uint8_t coverage = optState.getCoverage(); | 128 uint8_t coverage = optState.getCoverage(); |
129 | 129 |
130 this->setColor(optState, color); | 130 this->setColor(optState, color); |
131 this->setCoverage(optState, coverage); | 131 this->setCoverage(optState, coverage); |
132 this->setMatrixAndRenderTargetHeight(optState); | 132 this->setMatrixAndRenderTargetHeight(drawType, optState); |
133 | 133 |
134 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); | 134 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); |
135 if (dstCopy) { | 135 if (dstCopy) { |
136 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { | 136 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
137 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, | 137 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
138 static_cast<GrGLfloat>(dstCopy->offset().
fX), | 138 static_cast<GrGLfloat>(dstCopy->offset().
fX), |
139 static_cast<GrGLfloat>(dstCopy->offset().
fY)); | 139 static_cast<GrGLfloat>(dstCopy->offset().
fY)); |
140 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, | 140 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
141 1.f / dstCopy->texture()->width(), | 141 1.f / dstCopy->texture()->width(), |
142 1.f / dstCopy->texture()->height()); | 142 1.f / dstCopy->texture()->height()); |
(...skipping 14 matching lines...) Expand all Loading... |
157 // of GLProgram determine how to set coord transforms | 157 // of GLProgram determine how to set coord transforms |
158 if (fGeometryProcessor.get()) { | 158 if (fGeometryProcessor.get()) { |
159 SkASSERT(optState.hasGeometryProcessor()); | 159 SkASSERT(optState.hasGeometryProcessor()); |
160 const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); | 160 const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); |
161 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp); | 161 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp); |
162 this->bindTextures(fGeometryProcessor, gp); | 162 this->bindTextures(fGeometryProcessor, gp); |
163 } | 163 } |
164 this->setFragmentData(optState); | 164 this->setFragmentData(optState); |
165 | 165 |
166 // Some of GrGLProgram subclasses need to update state here | 166 // Some of GrGLProgram subclasses need to update state here |
167 this->didSetData(optState.drawType()); | 167 this->didSetData(drawType); |
168 } | 168 } |
169 | 169 |
170 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { | 170 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { |
171 int numProcessors = fFragmentProcessors->fProcs.count(); | 171 int numProcessors = fFragmentProcessors->fProcs.count(); |
172 for (int e = 0; e < numProcessors; ++e) { | 172 for (int e = 0; e < numProcessors; ++e) { |
173 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); | 173 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); |
174 const GrProcessor& processor = *stage.getProcessor(); | 174 const GrProcessor& processor = *stage.getProcessor(); |
175 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); | 175 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); |
176 this->setTransformData(stage, fFragmentProcessors->fProcs[e]); | 176 this->setTransformData(stage, fFragmentProcessors->fProcs[e]); |
177 this->bindTextures(fFragmentProcessors->fProcs[e], processor); | 177 this->bindTextures(fFragmentProcessors->fProcs[e], processor); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 234 } |
235 break; | 235 break; |
236 case GrProgramDesc::kAllOnes_ColorInput: | 236 case GrProgramDesc::kAllOnes_ColorInput: |
237 // Handled by shader creation | 237 // Handled by shader creation |
238 break; | 238 break; |
239 default: | 239 default: |
240 SkFAIL("Unexpected coverage type."); | 240 SkFAIL("Unexpected coverage type."); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState)
{ | 244 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| 245 const GrOptDrawState& optState)
{ |
245 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 246 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
246 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 247 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
247 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { | 248 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { |
248 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | 249 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
249 SkIntToScalar(optState.getRenderTarget()->hei
ght())); | 250 SkIntToScalar(optState.getRenderTarget()->hei
ght())); |
250 } | 251 } |
251 | 252 |
252 // call subclasses to set the actual view matrix | 253 // call subclasses to set the actual view matrix |
253 this->onSetMatrixAndRenderTargetHeight(optState); | 254 this->onSetMatrixAndRenderTargetHeight(drawType, optState); |
254 } | 255 } |
255 | 256 |
256 void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optStat
e) { | 257 void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| 258 const GrOptDrawState& optStat
e) { |
257 const GrRenderTarget* rt = optState.getRenderTarget(); | 259 const GrRenderTarget* rt = optState.getRenderTarget(); |
258 SkISize size; | 260 SkISize size; |
259 size.set(rt->width(), rt->height()); | 261 size.set(rt->width(), rt->height()); |
260 if (fMatrixState.fRenderTargetOrigin != rt->origin() || | 262 if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
261 fMatrixState.fRenderTargetSize != size || | 263 fMatrixState.fRenderTargetSize != size || |
262 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) { | 264 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) { |
263 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); | 265 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); |
264 | 266 |
265 fMatrixState.fViewMatrix = optState.getViewMatrix(); | 267 fMatrixState.fViewMatrix = optState.getViewMatrix(); |
266 fMatrixState.fRenderTargetSize = size; | 268 fMatrixState.fRenderTargetSize = size; |
(...skipping 13 matching lines...) Expand all Loading... |
280 | 282 |
281 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, | 283 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, |
282 const GrProgramDesc& desc, | 284 const GrProgramDesc& desc, |
283 const BuiltinUniformHandles& builtinUni
forms, | 285 const BuiltinUniformHandles& builtinUni
forms, |
284 GrGLuint programID, | 286 GrGLuint programID, |
285 const UniformInfoArray& uniforms, | 287 const UniformInfoArray& uniforms, |
286 GrGLInstalledFragProcs* fragmentProcess
ors) | 288 GrGLInstalledFragProcs* fragmentProcess
ors) |
287 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentP
rocessors) { | 289 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentP
rocessors) { |
288 } | 290 } |
289 | 291 |
290 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState&
optState) { | 292 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawT
ype, |
291 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType())); | 293 const GrOptDrawState&
optState) { |
| 294 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
292 const GrRenderTarget* rt = optState.getRenderTarget(); | 295 const GrRenderTarget* rt = optState.getRenderTarget(); |
293 SkISize size; | 296 SkISize size; |
294 size.set(rt->width(), rt->height()); | 297 size.set(rt->width(), rt->height()); |
295 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); | 298 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); |
296 } | 299 } |
297 | 300 |
298 ////////////////////////////////////////////////////////////////////////////////
///////// | 301 ////////////////////////////////////////////////////////////////////////////////
///////// |
299 | 302 |
300 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, | 303 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, |
301 const GrProgramDesc& desc, | 304 const GrProgramDesc& desc, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 for (int t = 0; t < numTransforms; ++t) { | 375 for (int t = 0; t < numTransforms; ++t) { |
373 const SkMatrix& transform = get_transform_matrix(proc, t); | 376 const SkMatrix& transform = get_transform_matrix(proc, t); |
374 GrGLPathRendering::PathTexGenComponents components = | 377 GrGLPathRendering::PathTexGenComponents components = |
375 GrGLPathRendering::kST_PathTexGenComponents; | 378 GrGLPathRendering::kST_PathTexGenComponents; |
376 if (proc.isPerspectiveCoordTransform(t)) { | 379 if (proc.isPerspectiveCoordTransform(t)) { |
377 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 380 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
378 } | 381 } |
379 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 382 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
380 } | 383 } |
381 } | 384 } |
OLD | NEW |