1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/webgl/webgl_multi_draw.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h"
namespace blink {
WebGLMultiDraw::WebGLMultiDraw(WebGLRenderingContextBase* context)
: WebGLExtension(context) {
context->ExtensionsUtil()->EnsureExtensionEnabled("GL_WEBGL_multi_draw");
context->ExtensionsUtil()->EnsureExtensionEnabled("GL_ANGLE_multi_draw");
// Spec requires ANGLE_instanced_arrays to be implicitly turned on
// here in WebGL 1.0 contexts.
if (!context->IsWebGL2()) {
context->EnableExtensionIfSupported("ANGLE_instanced_arrays");
}
}
WebGLExtensionName WebGLMultiDraw::GetName() const {
return kWebGLMultiDrawName;
}
bool WebGLMultiDraw::Supported(WebGLRenderingContextBase* context) {
return context->ExtensionsUtil()->SupportsExtension("GL_WEBGL_multi_draw") ||
(context->ExtensionsUtil()->SupportsExtension("GL_ANGLE_multi_draw") &&
context->ExtensionsUtil()->SupportsExtension(
"GL_ANGLE_instanced_arrays"));
}
const char* WebGLMultiDraw::ExtensionName() {
return "WEBGL_multi_draw";
}
void WebGLMultiDraw::multiDrawArraysWEBGL(GLenum mode,
base::span<const int32_t> firsts,
GLuint firstsOffset,
base::span<const int32_t> counts,
GLuint countsOffset,
GLsizei drawcount) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost() ||
!ValidateDrawcount(&scoped, "multiDrawArraysWEBGL", drawcount) ||
!ValidateArray(&scoped, "multiDrawArraysWEBGL",
"firstsOffset out of bounds", firsts.size(), firstsOffset,
drawcount) ||
!ValidateArray(&scoped, "multiDrawArraysWEBGL",
"countsOffset out of bounds", counts.size(), countsOffset,
drawcount)) {
return;
}
scoped.Context()->DrawWrapper(
"multiDrawArraysWEBGL", CanvasPerformanceMonitor::DrawType::kDrawArrays,
[&]() {
scoped.Context()->ContextGL()->MultiDrawArraysWEBGL(
mode, &firsts[firstsOffset], &counts[countsOffset], drawcount);
});
}
void WebGLMultiDraw::multiDrawElementsWEBGL(GLenum mode,
base::span<const int32_t> counts,
GLuint countsOffset,
GLenum type,
base::span<const int32_t> offsets,
GLuint offsetsOffset,
GLsizei drawcount) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost() ||
!ValidateDrawcount(&scoped, "multiDrawElementsWEBGL", drawcount) ||
!ValidateArray(&scoped, "multiDrawElementsWEBGL",
"countsOffset out of bounds", counts.size(), countsOffset,
drawcount) ||
!ValidateArray(&scoped, "multiDrawElementsWEBGL",
"offsetsOffset out of bounds", offsets.size(),
offsetsOffset, drawcount)) {
return;
}
scoped.Context()->DrawWrapper(
"multiDrawElementsWEBGL",
CanvasPerformanceMonitor::DrawType::kDrawElements, [&]() {
scoped.Context()->ContextGL()->MultiDrawElementsWEBGL(
mode, &counts[countsOffset], type, &offsets[offsetsOffset],
drawcount);
});
}
void WebGLMultiDraw::multiDrawArraysInstancedWEBGL(
GLenum mode,
base::span<const int32_t> firsts,
GLuint firstsOffset,
base::span<const int32_t> counts,
GLuint countsOffset,
base::span<const int32_t> instanceCounts,
GLuint instanceCountsOffset,
GLsizei drawcount) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost() ||
!ValidateDrawcount(&scoped, "multiDrawArraysInstancedWEBGL", drawcount) ||
!ValidateArray(&scoped, "multiDrawArraysInstancedWEBGL",
"firstsOffset out of bounds", firsts.size(), firstsOffset,
drawcount) ||
!ValidateArray(&scoped, "multiDrawArraysInstancedWEBGL",
"countsOffset out of bounds", counts.size(), countsOffset,
drawcount) ||
!ValidateArray(&scoped, "multiDrawArraysInstancedWEBGL",
"instanceCountsOffset out of bounds",
instanceCounts.size(), instanceCountsOffset, drawcount)) {
return;
}
scoped.Context()->DrawWrapper(
"multiDrawArraysInstancedWEBGL",
CanvasPerformanceMonitor::DrawType::kDrawArrays, [&]() {
scoped.Context()->ContextGL()->MultiDrawArraysInstancedWEBGL(
mode, &firsts[firstsOffset], &counts[countsOffset],
&instanceCounts[instanceCountsOffset], drawcount);
});
}
void WebGLMultiDraw::multiDrawElementsInstancedWEBGL(
GLenum mode,
base::span<const int32_t> counts,
GLuint countsOffset,
GLenum type,
base::span<const int32_t> offsets,
GLuint offsetsOffset,
base::span<const int32_t> instanceCounts,
GLuint instanceCountsOffset,
GLsizei drawcount) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost() ||
!ValidateDrawcount(&scoped, "multiDrawElementsInstancedWEBGL",
drawcount) ||
!ValidateArray(&scoped, "multiDrawElementsInstancedWEBGL",
"countsOffset out of bounds", counts.size(), countsOffset,
drawcount) ||
!ValidateArray(&scoped, "multiDrawElementsInstancedWEBGL",
"offsetsOffset out of bounds", offsets.size(),
offsetsOffset, drawcount) ||
!ValidateArray(&scoped, "multiDrawElementsInstancedWEBGL",
"instanceCountsOffset out of bounds",
instanceCounts.size(), instanceCountsOffset, drawcount)) {
return;
}
scoped.Context()->DrawWrapper(
"multiDrawElementsInstancedWEBGL",
CanvasPerformanceMonitor::DrawType::kDrawElements, [&]() {
scoped.Context()->ContextGL()->MultiDrawElementsInstancedWEBGL(
mode, &counts[countsOffset], type, &offsets[offsetsOffset],
&instanceCounts[instanceCountsOffset], drawcount);
});
}
} // namespace blink
|