aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLVertexArray.cpp
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2017-05-31 12:51:23 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-31 20:40:20 +0000
commit1d6163577c8a4f1372208e2c9e03b1a69906d385 (patch)
treefdacaa2e860d507bafca16cef0cb6e6e7861a1aa /src/gpu/gl/GrGLVertexArray.cpp
parentfa6d865215b48fac4ee24c120736e500d418f641 (diff)
Add support for instanced draws
Adds an instance buffer to GrMesh and instance attribs to GrPrimitiveProcessor. Implements support in GL and Vulkan. Adds unit tests for instanced rendering with GrMesh. Bug: skia: Change-Id: If1a9920feb9366f346b8c37cf914713c49129b3a Reviewed-on: https://skia-review.googlesource.com/16200 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/gpu/gl/GrGLVertexArray.cpp')
-rw-r--r--src/gpu/gl/GrGLVertexArray.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/gpu/gl/GrGLVertexArray.cpp b/src/gpu/gl/GrGLVertexArray.cpp
index 74e609e9b8..59f2be9831 100644
--- a/src/gpu/gl/GrGLVertexArray.cpp
+++ b/src/gpu/gl/GrGLVertexArray.cpp
@@ -53,8 +53,10 @@ void GrGLAttribArrayState::set(GrGLGpu* gpu,
const GrBuffer* vertexBuffer,
GrVertexAttribType type,
GrGLsizei stride,
- size_t offsetInBytes) {
+ size_t offsetInBytes,
+ int divisor) {
SkASSERT(index >= 0 && index < fAttribArrayStates.count());
+ SkASSERT(0 == divisor || gpu->caps()->instanceAttribSupport());
AttribArrayState* array = &fAttribArrayStates[index];
if (array->fVertexBufferUniqueID != vertexBuffer->uniqueID() ||
array->fType != type ||
@@ -84,10 +86,18 @@ void GrGLAttribArrayState::set(GrGLGpu* gpu,
array->fStride = stride;
array->fOffset = offsetInBytes;
}
+ if (gpu->caps()->instanceAttribSupport() && array->fDivisor != divisor) {
+ SkASSERT(0 == divisor || 1 == divisor); // not necessarily a requirement but what we expect.
+ GR_GL_CALL(gpu->glInterface(), VertexAttribDivisor(index, divisor));
+ array->fDivisor = divisor;
+ }
}
void GrGLAttribArrayState::enableVertexArrays(const GrGLGpu* gpu, int enabledCount) {
SkASSERT(enabledCount <= fAttribArrayStates.count());
+ if (fEnabledCountIsValid && enabledCount == fNumEnabledArrays) {
+ return;
+ }
int firstIdxToEnable = fEnabledCountIsValid ? fNumEnabledArrays : 0;
for (int i = firstIdxToEnable; i < enabledCount; ++i) {