| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 /** | 227 /** |
| 228 * Used to communicate draws to GPUs / subclasses | 228 * Used to communicate draw index vertex offsets and counts toto GPUs / subc
lasses |
| 229 */ | 229 */ |
| 230 class DrawInfo { | 230 class DrawInfo { |
| 231 public: | 231 public: |
| 232 DrawInfo() { fDevBounds = NULL; } | 232 DrawInfo() {} |
| 233 DrawInfo(const DrawInfo& di) { (*this) = di; } | 233 DrawInfo(const DrawInfo& di) { (*this) = di; } |
| 234 DrawInfo& operator =(const DrawInfo& di); | 234 DrawInfo& operator =(const DrawInfo& di); |
| 235 | 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 |
| 236 GrPrimitiveType primitiveType() const { return fPrimitiveType; } | 320 GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 237 int startVertex() const { return fStartVertex; } | 321 int startVertex() const { return fStartVertex; } |
| 238 int startIndex() const { return fStartIndex; } | 322 int startIndex() const { return fStartIndex; } |
| 239 int vertexCount() const { return fVertexCount; } | 323 int vertexCount() const { return fVertexCount; } |
| 240 int indexCount() const { return fIndexCount; } | 324 int indexCount() const { return fIndexCount; } |
| 325 |
| 326 /** These return 0 if initInstanced was not used to initialize the DrawI
nfo. */ |
| 241 int verticesPerInstance() const { return fVerticesPerInstance; } | 327 int verticesPerInstance() const { return fVerticesPerInstance; } |
| 242 int indicesPerInstance() const { return fIndicesPerInstance; } | 328 int indicesPerInstance() const { return fIndicesPerInstance; } |
| 243 int instanceCount() const { return fInstanceCount; } | 329 int instanceCount() const { return fInstanceCount; } |
| 244 | 330 |
| 245 void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; } | 331 bool isIndexed() const { return fIndexCount > 0; } |
| 246 void setStartVertex(int startVertex) { fStartVertex = startVertex; } | 332 bool isInstanced() const { return fInstanceCount > 0; } |
| 247 void setStartIndex(int startIndex) { fStartIndex = startIndex; } | |
| 248 void setVertexCount(int vertexCount) { fVertexCount = vertexCount; } | |
| 249 void setIndexCount(int indexCount) { fIndexCount = indexCount; } | |
| 250 void setVerticesPerInstance(int verticesPerI) { fVerticesPerInstance = v
erticesPerI; } | |
| 251 void setIndicesPerInstance(int indicesPerI) { fIndicesPerInstance = indi
cesPerI; } | |
| 252 void setInstanceCount(int instanceCount) { fInstanceCount = instanceCoun
t; } | |
| 253 | 333 |
| 254 bool isIndexed() const { return fIndexCount > 0; } | 334 /** Called after using this draw info to draw the next set of instances. |
| 255 #ifdef SK_DEBUG | 335 The vertex offset is advanced while the index buffer is reused at th
e same |
| 256 bool isInstanced() const; // this version is longer because of asserts | 336 position. instancesRemaining is number of instances that remain, max
Instances is |
| 257 #else | 337 the most number of instances that can be used with the index buffer.
If there |
| 258 bool isInstanced() const { return fInstanceCount > 0; } | 338 are no instances remaining, the DrawInfo is unmodified and false is
returned.*/ |
| 259 #endif | 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 } |
| 260 | 351 |
| 261 // adds or remove instances | |
| 262 void adjustInstanceCount(int instanceOffset); | |
| 263 // shifts the start vertex | |
| 264 void adjustStartVertex(int vertexOffset) { | |
| 265 fStartVertex += vertexOffset; | |
| 266 SkASSERT(fStartVertex >= 0); | |
| 267 } | |
| 268 // shifts the start index | |
| 269 void adjustStartIndex(int indexOffset) { | |
| 270 SkASSERT(this->isIndexed()); | |
| 271 fStartIndex += indexOffset; | |
| 272 SkASSERT(fStartIndex >= 0); | |
| 273 } | |
| 274 void setDevBounds(const SkRect& bounds) { | |
| 275 fDevBoundsStorage = bounds; | |
| 276 fDevBounds = &fDevBoundsStorage; | |
| 277 } | |
| 278 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | 352 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
| 279 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 353 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 280 void setVertexBuffer(const GrVertexBuffer* vb) { | |
| 281 fVertexBuffer.reset(vb); | |
| 282 } | |
| 283 void setIndexBuffer(const GrIndexBuffer* ib) { | |
| 284 fIndexBuffer.reset(ib); | |
| 285 } | |
| 286 const SkRect* getDevBounds() const { return fDevBounds; } | |
| 287 | 354 |
| 288 private: | 355 private: |
| 289 friend class GrDrawTarget; | 356 friend class GrDrawTarget; |
| 290 | 357 |
| 291 GrPrimitiveType fPrimitiveType; | 358 GrPrimitiveType fPrimitiveType; |
| 292 | 359 |
| 293 int fStartVertex; | 360 int fStartVertex; |
| 294 int fStartIndex; | 361 int fStartIndex; |
| 295 int fVertexCount; | 362 int fVertexCount; |
| 296 int fIndexCount; | 363 int fIndexCount; |
| 297 | 364 |
| 298 int fInstanceCount; | 365 int fInstanceCount; |
| 299 int fVerticesPerInstance; | 366 int fVerticesPerInstance; |
| 300 int fIndicesPerInstance; | 367 int fIndicesPerInstance; |
| 301 | 368 |
| 302 SkRect fDevBoundsStorage; | |
| 303 SkRect* fDevBounds; | |
| 304 | |
| 305 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; | 369 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
| 306 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; | 370 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
| 307 }; | 371 }; |
| 308 | 372 |
| 309 bool programUnitTest(int maxStages); | 373 bool programUnitTest(int maxStages); |
| 310 | 374 |
| 311 protected: | 375 protected: |
| 312 friend class GrTargetCommands; // for PipelineInfo | 376 friend class GrTargetCommands; // for PipelineInfo |
| 313 | 377 |
| 314 GrContext* getContext() { return fContext; } | 378 GrContext* getContext() { return fContext; } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 virtual bool setupClip(GrPipelineBuilder*, | 541 virtual bool setupClip(GrPipelineBuilder*, |
| 478 GrPipelineBuilder::AutoRestoreFragmentProcessors*, | 542 GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
| 479 GrPipelineBuilder::AutoRestoreStencil*, | 543 GrPipelineBuilder::AutoRestoreStencil*, |
| 480 GrScissorState* scissorState, | 544 GrScissorState* scissorState, |
| 481 const SkRect* devBounds) override; | 545 const SkRect* devBounds) override; |
| 482 | 546 |
| 483 typedef GrDrawTarget INHERITED; | 547 typedef GrDrawTarget INHERITED; |
| 484 }; | 548 }; |
| 485 | 549 |
| 486 #endif | 550 #endif |
| OLD | NEW |