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 "GrGpuGL.h" | 8 #include "GrGpuGL.h" |
9 | 9 |
10 #include "builders/GrGLProgramBuilder.h" | 10 #include "builders/GrGLProgramBuilder.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 if (SK_MaxU32 == fCurrLRUStamp) { | 190 if (SK_MaxU32 == fCurrLRUStamp) { |
191 // wrap around! just trash our LRU, one time hit. | 191 // wrap around! just trash our LRU, one time hit. |
192 for (int i = 0; i < fCount; ++i) { | 192 for (int i = 0; i < fCount; ++i) { |
193 fEntries[i]->fLRUStamp = 0; | 193 fEntries[i]->fLRUStamp = 0; |
194 } | 194 } |
195 } | 195 } |
196 ++fCurrLRUStamp; | 196 ++fCurrLRUStamp; |
197 return entry->fProgram; | 197 return entry->fProgram; |
198 } | 198 } |
199 | |
200 //////////////////////////////////////////////////////////////////////////////// | |
201 | |
202 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | |
203 | |
204 bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) { | |
205 // GrGpu::setupClipAndFlushState should have already checked this and bailed
if not true. | |
206 SkASSERT(optState.getRenderTarget()); | |
207 | |
208 if (kStencilPath_DrawType == optState.drawType()) { | |
209 const GrRenderTarget* rt = optState.getRenderTarget(); | |
210 SkISize size; | |
211 size.set(rt->width(), rt->height()); | |
212 this->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s
ize, rt->origin()); | |
213 } else { | |
214 this->flushMiscFixedFunctionState(optState); | |
215 | |
216 fCurrentProgram.reset(fProgramCache->getProgram(optState)); | |
217 if (NULL == fCurrentProgram.get()) { | |
218 SkDEBUGFAIL("Failed to create program!"); | |
219 return false; | |
220 } | |
221 | |
222 fCurrentProgram.get()->ref(); | |
223 | |
224 GrGLuint programID = fCurrentProgram->programID(); | |
225 if (fHWProgramID != programID) { | |
226 GL_CALL(UseProgram(programID)); | |
227 fHWProgramID = programID; | |
228 } | |
229 | |
230 this->flushBlend(optState); | |
231 | |
232 fCurrentProgram->setData(optState); | |
233 } | |
234 | |
235 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTa
rget()); | |
236 this->flushStencil(optState.getStencil(), optState.drawType()); | |
237 this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->or
igin()); | |
238 this->flushAAState(optState); | |
239 | |
240 // This must come after textures are flushed because a texture may need | |
241 // to be msaa-resolved (which will modify bound FBO state). | |
242 this->flushRenderTarget(glRT, NULL); | |
243 | |
244 return true; | |
245 } | |
246 | |
247 void GrGpuGL::setupGeometry(const GrOptDrawState& optState, | |
248 const GrDrawTarget::DrawInfo& info, | |
249 size_t* indexOffsetInBytes) { | |
250 GrGLVertexBuffer* vbuf; | |
251 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); | |
252 | |
253 SkASSERT(vbuf); | |
254 SkASSERT(!vbuf->isMapped()); | |
255 | |
256 GrGLIndexBuffer* ibuf = NULL; | |
257 if (info.isIndexed()) { | |
258 SkASSERT(indexOffsetInBytes); | |
259 | |
260 *indexOffsetInBytes = 0; | |
261 ibuf = (GrGLIndexBuffer*)info.indexBuffer(); | |
262 | |
263 SkASSERT(ibuf); | |
264 SkASSERT(!ibuf->isMapped()); | |
265 *indexOffsetInBytes += ibuf->baseOffset(); | |
266 } | |
267 GrGLAttribArrayState* attribState = | |
268 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); | |
269 | |
270 if (fCurrentProgram->hasVertexShader()) { | |
271 const GrGeometryProcessor* gp = optState.getGeometryProcessor(); | |
272 | |
273 GrGLsizei stride = static_cast<GrGLsizei>(gp->getVertexStride()); | |
274 | |
275 size_t vertexOffsetInBytes = stride * info.startVertex(); | |
276 | |
277 vertexOffsetInBytes += vbuf->baseOffset(); | |
278 | |
279 const SkTArray<GrGeometryProcessor::GrAttribute, true>& attribs = gp->ge
tAttribs(); | |
280 int vaCount = attribs.count(); | |
281 uint32_t usedAttribArraysMask = 0; | |
282 size_t offset = 0; | |
283 | |
284 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { | |
285 usedAttribArraysMask |= (1 << attribIndex); | |
286 GrVertexAttribType attribType = attribs[attribIndex].fType; | |
287 attribState->set(this, | |
288 attribIndex, | |
289 vbuf, | |
290 GrGLAttribTypeToLayout(attribType).fCount, | |
291 GrGLAttribTypeToLayout(attribType).fType, | |
292 GrGLAttribTypeToLayout(attribType).fNormalized, | |
293 stride, | |
294 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o
ffset)); | |
295 offset += attribs[attribIndex].fOffset; | |
296 } | |
297 attribState->disableUnusedArrays(this, usedAttribArraysMask); | |
298 } | |
299 } | |
300 | |
301 void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState, | |
302 const GrProgramDesc::DescInfo& descInfo, | |
303 GrGpu::DrawType drawType, | |
304 GrProgramDesc* desc) { | |
305 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)
) { | |
306 SkDEBUGFAIL("Failed to generate GL program descriptor"); | |
307 } | |
308 } | |
OLD | NEW |