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 "GrProcessor.h" | 11 #include "GrProcessor.h" |
12 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
13 #include "GrGLGeometryProcessor.h" | 13 #include "GrGLGeometryProcessor.h" |
14 #include "GrGLProcessor.h" | 14 #include "GrGLProcessor.h" |
15 #include "GrGLXferProcessor.h" | 15 #include "GrGLXferProcessor.h" |
16 #include "GrGLGpu.h" | 16 #include "GrGLGpu.h" |
17 #include "GrGLPathRendering.h" | 17 #include "GrGLPathRendering.h" |
18 #include "GrGLShaderVar.h" | 18 #include "GrGLShaderVar.h" |
19 #include "GrGLSL.h" | 19 #include "GrGLSL.h" |
20 #include "GrOptDrawState.h" | 20 #include "GrPipeline.h" |
21 #include "GrXferProcessor.h" | 21 #include "GrXferProcessor.h" |
22 #include "SkXfermode.h" | 22 #include "SkXfermode.h" |
23 | 23 |
24 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 24 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
25 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 25 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
26 | 26 |
27 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 27 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
28 | 28 |
29 GrGLProgram::GrGLProgram(GrGLGpu* gpu, | 29 GrGLProgram::GrGLProgram(GrGLGpu* gpu, |
30 const GrProgramDesc& desc, | 30 const GrProgramDesc& desc, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const GrTextureAccess& textureAccess = processor.textureAccess(s); | 96 const GrTextureAccess& textureAccess = processor.textureAccess(s); |
97 fGpu->bindTexture(samplers[s].fTextureUnit, | 97 fGpu->bindTexture(samplers[s].fTextureUnit, |
98 textureAccess.getParams(), | 98 textureAccess.getParams(), |
99 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; | 99 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 /////////////////////////////////////////////////////////////////////////////// | 104 /////////////////////////////////////////////////////////////////////////////// |
105 | 105 |
106 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrOptDrawS
tate& optState, | 106 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline
& pipeline, |
107 const GrBatchTracker& batchTracker) { | 107 const GrBatchTracker& batchTracker) { |
108 this->setRenderTargetState(primProc, optState); | 108 this->setRenderTargetState(primProc, pipeline); |
109 | 109 |
110 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); | 110 const GrDeviceCoordTexture* dstCopy = pipeline.getDstCopy(); |
111 if (dstCopy) { | 111 if (dstCopy) { |
112 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { | 112 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
113 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, | 113 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
114 static_cast<GrGLfloat>(dstCopy->offset().
fX), | 114 static_cast<GrGLfloat>(dstCopy->offset().
fX), |
115 static_cast<GrGLfloat>(dstCopy->offset().
fY)); | 115 static_cast<GrGLfloat>(dstCopy->offset().
fY)); |
116 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, | 116 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
117 1.f / dstCopy->texture()->width(), | 117 1.f / dstCopy->texture()->width(), |
118 1.f / dstCopy->texture()->height()); | 118 1.f / dstCopy->texture()->height()); |
119 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; | 119 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; |
120 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. | 120 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. |
121 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); | 121 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
122 } else { | 122 } else { |
123 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 123 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
124 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 124 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
125 } | 125 } |
126 } else { | 126 } else { |
127 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); | 127 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); |
128 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 128 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
129 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 129 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
130 } | 130 } |
131 | 131 |
132 // we set the textures, and uniforms for installed processors in a generic w
ay, but subclasses | 132 // we set the textures, and uniforms for installed processors in a generic w
ay, but subclasses |
133 // of GLProgram determine how to set coord transforms | 133 // of GLProgram determine how to set coord transforms |
134 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, batchTra
cker); | 134 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, batchTra
cker); |
135 this->bindTextures(fGeometryProcessor.get(), primProc); | 135 this->bindTextures(fGeometryProcessor.get(), primProc); |
136 | 136 |
137 if (fXferProcessor.get()) { | 137 if (fXferProcessor.get()) { |
138 const GrXferProcessor& xp = *optState.getXferProcessor(); | 138 const GrXferProcessor& xp = *pipeline.getXferProcessor(); |
139 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); | 139 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); |
140 this->bindTextures(fXferProcessor.get(), xp); | 140 this->bindTextures(fXferProcessor.get(), xp); |
141 } | 141 } |
142 this->setFragmentData(primProc, optState); | 142 this->setFragmentData(primProc, pipeline); |
143 | 143 |
144 // Some of GrGLProgram subclasses need to update state here | 144 // Some of GrGLProgram subclasses need to update state here |
145 this->didSetData(); | 145 this->didSetData(); |
146 } | 146 } |
147 | 147 |
148 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, | 148 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, |
149 const GrOptDrawState& optState) { | 149 const GrPipeline& pipeline) { |
150 int numProcessors = fFragmentProcessors->fProcs.count(); | 150 int numProcessors = fFragmentProcessors->fProcs.count(); |
151 for (int e = 0; e < numProcessors; ++e) { | 151 for (int e = 0; e < numProcessors; ++e) { |
152 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); | 152 const GrPendingFragmentStage& stage = pipeline.getFragmentStage(e); |
153 const GrProcessor& processor = *stage.processor(); | 153 const GrProcessor& processor = *stage.processor(); |
154 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); | 154 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); |
155 this->setTransformData(primProc, | 155 this->setTransformData(primProc, |
156 stage, | 156 stage, |
157 e, | 157 e, |
158 fFragmentProcessors->fProcs[e]); | 158 fFragmentProcessors->fProcs[e]); |
159 this->bindTextures(fFragmentProcessors->fProcs[e], processor); | 159 this->bindTextures(fFragmentProcessors->fProcs[e], processor); |
160 } | 160 } |
161 } | 161 } |
162 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, | 162 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, |
163 const GrPendingFragmentStage& processor, | 163 const GrPendingFragmentStage& processor, |
164 int index, | 164 int index, |
165 GrGLInstalledFragProc* ip) { | 165 GrGLInstalledFragProc* ip) { |
166 GrGLGeometryProcessor* gp = | 166 GrGLGeometryProcessor* gp = |
167 static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLPro
c.get()); | 167 static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLPro
c.get()); |
168 gp->setTransformData(primProc, fProgramDataManager, index, | 168 gp->setTransformData(primProc, fProgramDataManager, index, |
169 processor.processor()->coordTransforms()); | 169 processor.processor()->coordTransforms()); |
170 } | 170 } |
171 | 171 |
172 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, | 172 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, |
173 const GrOptDrawState& optState) { | 173 const GrPipeline& pipeline) { |
174 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 174 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
175 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 175 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
176 fRenderTargetState.fRenderTargetSize.fHeight != optState.getRenderTarget
()->height()) { | 176 fRenderTargetState.fRenderTargetSize.fHeight != pipeline.getRenderTarget
()->height()) { |
177 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | 177 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
178 SkIntToScalar(optState.getRenderTarget()->hei
ght())); | 178 SkIntToScalar(pipeline.getRenderTarget()->hei
ght())); |
179 } | 179 } |
180 | 180 |
181 // call subclasses to set the actual view matrix | 181 // call subclasses to set the actual view matrix |
182 this->onSetRenderTargetState(primProc, optState); | 182 this->onSetRenderTargetState(primProc, pipeline); |
183 } | 183 } |
184 | 184 |
185 void GrGLProgram::onSetRenderTargetState(const GrPrimitiveProcessor&, | 185 void GrGLProgram::onSetRenderTargetState(const GrPrimitiveProcessor&, |
186 const GrOptDrawState& optState) { | 186 const GrPipeline& pipeline) { |
187 const GrRenderTarget* rt = optState.getRenderTarget(); | 187 const GrRenderTarget* rt = pipeline.getRenderTarget(); |
188 SkISize size; | 188 SkISize size; |
189 size.set(rt->width(), rt->height()); | 189 size.set(rt->width(), rt->height()); |
190 if (fRenderTargetState.fRenderTargetOrigin != rt->origin() || | 190 if (fRenderTargetState.fRenderTargetOrigin != rt->origin() || |
191 fRenderTargetState.fRenderTargetSize != size) { | 191 fRenderTargetState.fRenderTargetSize != size) { |
192 fRenderTargetState.fRenderTargetSize = size; | 192 fRenderTargetState.fRenderTargetSize = size; |
193 fRenderTargetState.fRenderTargetOrigin = rt->origin(); | 193 fRenderTargetState.fRenderTargetOrigin = rt->origin(); |
194 | 194 |
195 GrGLfloat rtAdjustmentVec[4]; | 195 GrGLfloat rtAdjustmentVec[4]; |
196 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); | 196 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); |
197 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); | 197 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); |
(...skipping 23 matching lines...) Expand all Loading... |
221 const GrPendingFragmentStage& proc, | 221 const GrPendingFragmentStage& proc, |
222 int index, | 222 int index, |
223 GrGLInstalledFragProc* ip) { | 223 GrGLInstalledFragProc* ip) { |
224 GrGLPathProcessor* pathProc = | 224 GrGLPathProcessor* pathProc = |
225 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge
t()); | 225 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge
t()); |
226 pathProc->setTransformData(primProc, index, proc.processor()->coordTransform
s(), | 226 pathProc->setTransformData(primProc, index, proc.processor()->coordTransform
s(), |
227 fGpu->glPathRendering(), fProgramID); | 227 fGpu->glPathRendering(), fProgramID); |
228 } | 228 } |
229 | 229 |
230 void GrGLNvprProgram::onSetRenderTargetState(const GrPrimitiveProcessor& primPro
c, | 230 void GrGLNvprProgram::onSetRenderTargetState(const GrPrimitiveProcessor& primPro
c, |
231 const GrOptDrawState& optState) { | 231 const GrPipeline& pipeline) { |
232 SkASSERT(!primProc.willUseGeoShader() && primProc.numAttribs() == 0); | 232 SkASSERT(!primProc.willUseGeoShader() && primProc.numAttribs() == 0); |
233 const GrRenderTarget* rt = optState.getRenderTarget(); | 233 const GrRenderTarget* rt = pipeline.getRenderTarget(); |
234 SkISize size; | 234 SkISize size; |
235 size.set(rt->width(), rt->height()); | 235 size.set(rt->width(), rt->height()); |
236 fGpu->glPathRendering()->setProjectionMatrix(primProc.viewMatrix(), | 236 fGpu->glPathRendering()->setProjectionMatrix(primProc.viewMatrix(), |
237 size, rt->origin()); | 237 size, rt->origin()); |
238 } | 238 } |
OLD | NEW |