OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 #ifndef GrDrawTarget_DEFINED | 8 #ifndef GrDrawTarget_DEFINED |
9 #define GrDrawTarget_DEFINED | 9 #define GrDrawTarget_DEFINED |
10 | 10 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} | 217 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} |
218 | 218 |
219 private: | 219 private: |
220 GrDrawTarget* fDrawTarget; | 220 GrDrawTarget* fDrawTarget; |
221 uint32_t fDrawID; // this may wrap, but we're doing direct compa
rison | 221 uint32_t fDrawID; // this may wrap, but we're doing direct compa
rison |
222 // so that should be okay | 222 // so that should be okay |
223 }; | 223 }; |
224 | 224 |
225 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } | 225 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } |
226 | 226 |
227 /** | |
228 * Used to communicate draw index vertex offsets and counts toto GPUs / subc
lasses | |
229 */ | |
230 class DrawInfo { | |
231 public: | |
232 DrawInfo() {} | |
233 DrawInfo(const DrawInfo& di) { (*this) = di; } | |
234 DrawInfo& operator =(const DrawInfo& di); | |
235 | |
236 void init(GrPrimitiveType primType, const GrVertexBuffer* vertexBuffer,
int startVertex, | |
237 int vertexCount) { | |
238 SkASSERT(vertexBuffer); | |
239 SkASSERT(vertexCount); | |
240 SkASSERT(startVertex >= 0); | |
241 fPrimitiveType = primType; | |
242 fVertexBuffer.reset(SkRef(vertexBuffer)); | |
243 fIndexBuffer.reset(NULL); | |
244 fStartVertex = startVertex; | |
245 fStartIndex = 0; | |
246 fVertexCount = vertexCount; | |
247 fIndexCount = 0; | |
248 fInstanceCount = 0; | |
249 fVerticesPerInstance = 0; | |
250 fIndicesPerInstance = 0; | |
251 } | |
252 | |
253 void initIndexed(GrPrimitiveType primType, | |
254 const GrVertexBuffer* vertexBuffer, | |
255 const GrIndexBuffer* indexBuffer, | |
256 int startVertex, | |
257 int startIndex, | |
258 int vertexCount, | |
259 int indexCount) { | |
260 SkASSERT(indexBuffer); | |
261 SkASSERT(vertexBuffer); | |
262 SkASSERT(indexCount); | |
263 SkASSERT(vertexCount); | |
264 SkASSERT(startIndex >= 0); | |
265 SkASSERT(startVertex >= 0); | |
266 fPrimitiveType = primType; | |
267 fVertexBuffer.reset(SkRef(vertexBuffer)); | |
268 fIndexBuffer.reset(SkRef(indexBuffer)); | |
269 fStartVertex = startVertex; | |
270 fStartIndex = startIndex; | |
271 fVertexCount = vertexCount; | |
272 fIndexCount = indexCount; | |
273 fInstanceCount = 0; | |
274 fVerticesPerInstance = 0; | |
275 fIndicesPerInstance = 0; | |
276 } | |
277 | |
278 void initInstanced(GrPrimitiveType primType, | |
279 const GrVertexBuffer* vertexBuffer, | |
280 const GrIndexBuffer* indexBuffer, | |
281 int startVertex, | |
282 int verticesPerInstance, | |
283 int indicesPerInstance, | |
284 int instanceCount) { | |
285 SkASSERT(vertexBuffer); | |
286 SkASSERT(indexBuffer); | |
287 SkASSERT(instanceCount); | |
288 SkASSERT(verticesPerInstance); | |
289 SkASSERT(indicesPerInstance); | |
290 SkASSERT(startVertex >= 0); | |
291 fPrimitiveType = primType; | |
292 fVertexBuffer.reset(SkRef(vertexBuffer)); | |
293 fIndexBuffer.reset(SkRef(indexBuffer)); | |
294 fStartVertex = startVertex; | |
295 fStartIndex = 0; | |
296 fVerticesPerInstance = verticesPerInstance; | |
297 fIndicesPerInstance = indicesPerInstance; | |
298 fInstanceCount = instanceCount; | |
299 fVertexCount = instanceCount * fVerticesPerInstance; | |
300 fIndexCount = instanceCount * fIndicesPerInstance; | |
301 } | |
302 | |
303 /** Variation of the above that may be used when the total number of ins
tances may exceed | |
304 the number of instances supported by the index buffer. To be used wi
th | |
305 nextInstances() to draw in max-sized batches.*/ | |
306 void initInstanced(GrPrimitiveType primType, | |
307 const GrVertexBuffer* vertexBuffer, | |
308 const GrIndexBuffer* indexBuffer, | |
309 int startVertex, | |
310 int verticesPerInstance, | |
311 int indicesPerInstance, | |
312 int* instancesRemaining, | |
313 int maxInstancesPerDraw) { | |
314 int instanceCount = SkTMin(*instancesRemaining, maxInstancesPerDraw)
; | |
315 *instancesRemaining -= instanceCount; | |
316 this->initInstanced(primType, vertexBuffer, indexBuffer, startVertex
, | |
317 verticesPerInstance, indicesPerInstance, instanc
eCount); | |
318 } | |
319 | |
320 GrPrimitiveType primitiveType() const { return fPrimitiveType; } | |
321 int startVertex() const { return fStartVertex; } | |
322 int startIndex() const { return fStartIndex; } | |
323 int vertexCount() const { return fVertexCount; } | |
324 int indexCount() const { return fIndexCount; } | |
325 | |
326 /** These return 0 if initInstanced was not used to initialize the DrawI
nfo. */ | |
327 int verticesPerInstance() const { return fVerticesPerInstance; } | |
328 int indicesPerInstance() const { return fIndicesPerInstance; } | |
329 int instanceCount() const { return fInstanceCount; } | |
330 | |
331 bool isIndexed() const { return fIndexCount > 0; } | |
332 bool isInstanced() const { return fInstanceCount > 0; } | |
333 | |
334 /** Called after using this draw info to draw the next set of instances. | |
335 The vertex offset is advanced while the index buffer is reused at th
e same | |
336 position. instancesRemaining is number of instances that remain, max
Instances is | |
337 the most number of instances that can be used with the index buffer.
If there | |
338 are no instances remaining, the DrawInfo is unmodified and false is
returned.*/ | |
339 bool nextInstances(int* instancesRemaining, int maxInstances) { | |
340 SkASSERT(this->isInstanced()); | |
341 if (!*instancesRemaining) { | |
342 return false; | |
343 } | |
344 fStartVertex += fVertexCount; | |
345 fInstanceCount = SkTMin(*instancesRemaining, maxInstances); | |
346 fVertexCount = fInstanceCount * fVerticesPerInstance; | |
347 fIndexCount = fInstanceCount * fIndicesPerInstance; | |
348 *instancesRemaining -= fInstanceCount; | |
349 return true; | |
350 } | |
351 | |
352 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | |
353 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | |
354 | |
355 private: | |
356 friend class GrDrawTarget; | |
357 | |
358 GrPrimitiveType fPrimitiveType; | |
359 | |
360 int fStartVertex; | |
361 int fStartIndex; | |
362 int fVertexCount; | |
363 int fIndexCount; | |
364 | |
365 int fInstanceCount; | |
366 int fVerticesPerInstance; | |
367 int fIndicesPerInstance; | |
368 | |
369 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; | |
370 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; | |
371 }; | |
372 | |
373 bool programUnitTest(int maxStages); | 227 bool programUnitTest(int maxStages); |
374 | 228 |
375 protected: | 229 protected: |
376 friend class GrCommandBuilder; // for PipelineInfo | 230 friend class GrCommandBuilder; // for PipelineInfo |
377 friend class GrTargetCommands; // for PipelineInfo | 231 friend class GrTargetCommands; // for PipelineInfo |
378 | 232 |
379 GrContext* getContext() { return fContext; } | 233 GrContext* getContext() { return fContext; } |
380 const GrContext* getContext() const { return fContext; } | 234 const GrContext* getContext() const { return fContext; } |
381 | 235 |
382 GrGpu* getGpu() { | 236 GrGpu* getGpu() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 virtual bool setupClip(GrPipelineBuilder*, | 396 virtual bool setupClip(GrPipelineBuilder*, |
543 GrPipelineBuilder::AutoRestoreFragmentProcessors*, | 397 GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
544 GrPipelineBuilder::AutoRestoreStencil*, | 398 GrPipelineBuilder::AutoRestoreStencil*, |
545 GrScissorState* scissorState, | 399 GrScissorState* scissorState, |
546 const SkRect* devBounds) override; | 400 const SkRect* devBounds) override; |
547 | 401 |
548 typedef GrDrawTarget INHERITED; | 402 typedef GrDrawTarget INHERITED; |
549 }; | 403 }; |
550 | 404 |
551 #endif | 405 #endif |
OLD | NEW |