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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // This must come after textures are flushed because a texture may need | 243 // This must come after textures are flushed because a texture may need |
244 // to be msaa-resolved (which will modify bound FBO state). | 244 // to be msaa-resolved (which will modify bound FBO state). |
245 this->flushRenderTarget(glRT, NULL); | 245 this->flushRenderTarget(glRT, NULL); |
246 | 246 |
247 return true; | 247 return true; |
248 } | 248 } |
249 | 249 |
250 void GrGpuGL::setupGeometry(const GrOptDrawState& optState, | 250 void GrGpuGL::setupGeometry(const GrOptDrawState& optState, |
251 const GrDrawTarget::DrawInfo& info, | 251 const GrDrawTarget::DrawInfo& info, |
252 size_t* indexOffsetInBytes) { | 252 size_t* indexOffsetInBytes) { |
253 GrGLsizei stride = static_cast<GrGLsizei>(optState.getVertexStride()); | |
254 | |
255 size_t vertexOffsetInBytes = stride * info.startVertex(); | |
256 | |
257 GrGLVertexBuffer* vbuf; | 253 GrGLVertexBuffer* vbuf; |
258 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); | 254 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); |
259 | 255 |
260 SkASSERT(vbuf); | 256 SkASSERT(vbuf); |
261 SkASSERT(!vbuf->isMapped()); | 257 SkASSERT(!vbuf->isMapped()); |
262 vertexOffsetInBytes += vbuf->baseOffset(); | |
263 | 258 |
264 GrGLIndexBuffer* ibuf = NULL; | 259 GrGLIndexBuffer* ibuf = NULL; |
265 if (info.isIndexed()) { | 260 if (info.isIndexed()) { |
266 SkASSERT(indexOffsetInBytes); | 261 SkASSERT(indexOffsetInBytes); |
267 | 262 |
268 *indexOffsetInBytes = 0; | 263 *indexOffsetInBytes = 0; |
269 ibuf = (GrGLIndexBuffer*)info.indexBuffer(); | 264 ibuf = (GrGLIndexBuffer*)info.indexBuffer(); |
270 | 265 |
271 SkASSERT(ibuf); | 266 SkASSERT(ibuf); |
272 SkASSERT(!ibuf->isMapped()); | 267 SkASSERT(!ibuf->isMapped()); |
273 *indexOffsetInBytes += ibuf->baseOffset(); | 268 *indexOffsetInBytes += ibuf->baseOffset(); |
274 } | 269 } |
275 GrGLAttribArrayState* attribState = | 270 GrGLAttribArrayState* attribState = |
276 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); | 271 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); |
277 | 272 |
278 if (fCurrentProgram->hasVertexShader()) { | 273 if (fCurrentProgram->hasVertexShader()) { |
279 int vertexAttribCount = optState.getVertexAttribCount(); | 274 const GrGeometryProcessor* gp = optState.getGeometryProcessor(); |
| 275 |
| 276 GrGLsizei stride = static_cast<GrGLsizei>(gp->getVertexStride()); |
| 277 |
| 278 size_t vertexOffsetInBytes = stride * info.startVertex(); |
| 279 |
| 280 vertexOffsetInBytes += vbuf->baseOffset(); |
| 281 |
| 282 const SkTArray<GrGeometryProcessor::GrAttribute, true>& attribs = gp->ge
tAttribs(); |
| 283 int vaCount = attribs.count(); |
280 uint32_t usedAttribArraysMask = 0; | 284 uint32_t usedAttribArraysMask = 0; |
281 const GrVertexAttrib* vertexAttrib = optState.getVertexAttribs(); | 285 size_t offset = 0; |
282 | 286 |
283 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; | 287 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { |
284 ++vertexAttribIndex, ++vertexAttrib) { | 288 usedAttribArraysMask |= (1 << attribIndex); |
285 usedAttribArraysMask |= (1 << vertexAttribIndex); | 289 GrVertexAttribType attribType = attribs[attribIndex].fType; |
286 GrVertexAttribType attribType = vertexAttrib->fType; | |
287 attribState->set(this, | 290 attribState->set(this, |
288 vertexAttribIndex, | 291 attribIndex, |
289 vbuf, | 292 vbuf, |
290 GrGLAttribTypeToLayout(attribType).fCount, | 293 GrGLAttribTypeToLayout(attribType).fCount, |
291 GrGLAttribTypeToLayout(attribType).fType, | 294 GrGLAttribTypeToLayout(attribType).fType, |
292 GrGLAttribTypeToLayout(attribType).fNormalized, | 295 GrGLAttribTypeToLayout(attribType).fNormalized, |
293 stride, | 296 stride, |
294 reinterpret_cast<GrGLvoid*>( | 297 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o
ffset)); |
295 vertexOffsetInBytes + vertexAttrib->fOffset)); | 298 offset += attribs[attribIndex].fOffset; |
296 } | 299 } |
297 attribState->disableUnusedArrays(this, usedAttribArraysMask); | 300 attribState->disableUnusedArrays(this, usedAttribArraysMask); |
298 } | 301 } |
299 } | 302 } |
300 | 303 |
301 void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState, | 304 void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState, |
302 const GrProgramDesc::DescInfo& descInfo, | 305 const GrProgramDesc::DescInfo& descInfo, |
303 GrGpu::DrawType drawType, | 306 GrGpu::DrawType drawType, |
304 GrProgramDesc* desc) { | 307 GrProgramDesc* desc) { |
305 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)
) { | 308 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)
) { |
306 SkDEBUGFAIL("Failed to generate GL program descriptor"); | 309 SkDEBUGFAIL("Failed to generate GL program descriptor"); |
307 } | 310 } |
308 } | 311 } |
OLD | NEW |