| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/html/canvas/WebGL2RenderingContextBase.h" |
| 7 |
| 8 #include "bindings/core/v8/WebGLAny.h" |
| 9 #include "core/html/HTMLCanvasElement.h" |
| 10 #include "core/html/HTMLImageElement.h" |
| 11 #include "core/html/HTMLVideoElement.h" |
| 12 #include "core/html/ImageData.h" |
| 13 #include "core/html/canvas/WebGLActiveInfo.h" |
| 14 #include "core/html/canvas/WebGLBuffer.h" |
| 15 #include "core/html/canvas/WebGLFenceSync.h" |
| 16 #include "core/html/canvas/WebGLFramebuffer.h" |
| 17 #include "core/html/canvas/WebGLProgram.h" |
| 18 #include "core/html/canvas/WebGLQuery.h" |
| 19 #include "core/html/canvas/WebGLSampler.h" |
| 20 #include "core/html/canvas/WebGLSync.h" |
| 21 #include "core/html/canvas/WebGLTexture.h" |
| 22 #include "core/html/canvas/WebGLTransformFeedback.h" |
| 23 #include "core/html/canvas/WebGLUniformLocation.h" |
| 24 #include "core/html/canvas/WebGLVertexArrayObjectOES.h" |
| 25 |
| 26 #include "platform/NotImplemented.h" |
| 27 |
| 28 namespace blink { |
| 29 |
| 30 namespace { |
| 31 |
| 32 const GLuint WEBGL_TIMEOUT_IGNORED = 0xFFFFFFFF; |
| 33 |
| 34 Platform3DObject objectOrZero(const WebGLObject* object) |
| 35 { |
| 36 return object ? object->object() : 0; |
| 37 } |
| 38 |
| 39 } |
| 40 |
| 41 WebGL2RenderingContextBase::WebGL2RenderingContextBase(HTMLCanvasElement* passed
Canvas, PassOwnPtr<blink::WebGraphicsContext3D> context, const WebGLContextAttri
butes& requestedAttributes) |
| 42 : WebGLRenderingContextBase(passedCanvas, context, requestedAttributes) |
| 43 { |
| 44 |
| 45 } |
| 46 |
| 47 WebGL2RenderingContextBase::~WebGL2RenderingContextBase() |
| 48 { |
| 49 |
| 50 } |
| 51 |
| 52 void WebGL2RenderingContextBase::copyBufferSubData(GLenum readTarget, GLenum wri
teTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) |
| 53 { |
| 54 if (isContextLost()) |
| 55 return; |
| 56 |
| 57 webContext()->copyBufferSubData(readTarget, writeTarget, readOffset, writeOf
fset, size); |
| 58 } |
| 59 |
| 60 void WebGL2RenderingContextBase::blitFramebuffer(GLint srcX0, GLint srcY0, GLint
srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfi
eld mask, GLenum filter) |
| 61 { |
| 62 if (isContextLost()) |
| 63 return; |
| 64 |
| 65 webContext()->blitFramebufferCHROMIUM(srcX0, srcY0, srcX1, srcY1, dstX0, dst
Y0, dstX1, dstY1, mask, filter); |
| 66 } |
| 67 |
| 68 void WebGL2RenderingContextBase::framebufferTextureLayer(GLenum target, GLenum a
ttachment, const WebGLTexture* texture, GLint level, GLint layer) |
| 69 { |
| 70 if (isContextLost()) |
| 71 return; |
| 72 |
| 73 if (texture && !texture->validate(contextGroup(), this)) { |
| 74 synthesizeGLError(GL_INVALID_VALUE, "framebufferTextureLayer", "no textu
re or texture not from this context"); |
| 75 return; |
| 76 } |
| 77 |
| 78 webContext()->framebufferTextureLayer(target, attachment, objectOrZero(textu
re), level, layer); |
| 79 } |
| 80 |
| 81 ScriptValue WebGL2RenderingContextBase::getInternalformatParameter(ScriptState*
scriptState, GLenum target, GLenum internalformat, GLenum pname) |
| 82 { |
| 83 if (isContextLost()) |
| 84 return ScriptValue::createNull(scriptState); |
| 85 |
| 86 notImplemented(); |
| 87 return ScriptValue::createNull(scriptState); |
| 88 } |
| 89 |
| 90 void WebGL2RenderingContextBase::invalidateFramebuffer(GLenum target, Vector<GLe
num>& attachments) |
| 91 { |
| 92 if (isContextLost()) |
| 93 return; |
| 94 |
| 95 webContext()->invalidateFramebuffer(target, attachments.size(), attachments.
data()); |
| 96 } |
| 97 |
| 98 void WebGL2RenderingContextBase::invalidateSubFramebuffer(GLenum target, Vector<
GLenum>& attachments, GLint x, GLint y, GLsizei width, GLsizei height) |
| 99 { |
| 100 if (isContextLost()) |
| 101 return; |
| 102 |
| 103 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen
ts.data(), x, y, width, height); |
| 104 } |
| 105 |
| 106 void WebGL2RenderingContextBase::readBuffer(GLenum mode) |
| 107 { |
| 108 if (isContextLost()) |
| 109 return; |
| 110 |
| 111 webContext()->readBuffer(mode); |
| 112 } |
| 113 |
| 114 void WebGL2RenderingContextBase::renderbufferStorageMultisample(GLenum target, G
Lsizei samples, GLenum internalformat, GLsizei width, GLsizei height) |
| 115 { |
| 116 if (isContextLost()) |
| 117 return; |
| 118 |
| 119 webContext()->renderbufferStorageMultisampleEXT(target, samples, internalfor
mat, width, height); |
| 120 } |
| 121 |
| 122 /* Texture objects */ |
| 123 void WebGL2RenderingContextBase::texStorage2D(GLenum target, GLsizei levels, GLe
num internalformat, GLsizei width, GLsizei height) |
| 124 { |
| 125 if (isContextLost()) |
| 126 return; |
| 127 |
| 128 webContext()->texStorage2DEXT(target, levels, internalformat, width, height)
; |
| 129 } |
| 130 |
| 131 void WebGL2RenderingContextBase::texStorage3D(GLenum target, GLsizei levels, GLe
num internalformat, GLsizei width, GLsizei height, GLsizei depth) |
| 132 { |
| 133 if (isContextLost()) |
| 134 return; |
| 135 |
| 136 webContext()->texStorage3D(target, levels, internalformat, width, height, de
pth); |
| 137 } |
| 138 |
| 139 void WebGL2RenderingContextBase::texImage3D(GLenum target, GLint level, GLint in
ternalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum
format, GLenum type, DOMArrayBufferView* pixels) |
| 140 { |
| 141 if (isContextLost()) |
| 142 return; |
| 143 |
| 144 notImplemented(); |
| 145 } |
| 146 |
| 147 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei d
epth, GLenum format, GLenum type, DOMArrayBufferView* pixels) |
| 148 { |
| 149 if (isContextLost() || !pixels) |
| 150 return; |
| 151 |
| 152 // TODO: Ensure pixels is large enough to contain the desired texture dimens
ions. |
| 153 |
| 154 void* data = pixels->baseAddress(); |
| 155 Vector<uint8_t> tempData; |
| 156 bool changeUnpackAlignment = false; |
| 157 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { |
| 158 if (!WebGLImageConversion::extractTextureData(width, height, format, typ
e, |
| 159 m_unpackAlignment, |
| 160 m_unpackFlipY, m_unpackPremultiplyAlpha, |
| 161 data, |
| 162 tempData)) |
| 163 return; |
| 164 data = tempData.data(); |
| 165 changeUnpackAlignment = true; |
| 166 } |
| 167 if (changeUnpackAlignment) |
| 168 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 169 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, width,
height, depth, format, type, data); |
| 170 if (changeUnpackAlignment) |
| 171 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 172 } |
| 173 |
| 174 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, ImageData* p
ixels) |
| 175 { |
| 176 if (isContextLost() || !pixels) |
| 177 return; |
| 178 |
| 179 Vector<uint8_t> data; |
| 180 bool needConversion = true; |
| 181 // The data from ImageData is always of format RGBA8. |
| 182 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. |
| 183 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un
packPremultiplyAlpha) { |
| 184 needConversion = false; |
| 185 } else { |
| 186 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe
ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { |
| 187 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data
"); |
| 188 return; |
| 189 } |
| 190 } |
| 191 if (m_unpackAlignment != 1) |
| 192 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 193 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, pixels
->width(), pixels->height(), 1, format, type, needConversion ? data.data() : pix
els->data()->data()); |
| 194 if (m_unpackAlignment != 1) |
| 195 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 196 } |
| 197 |
| 198 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLImageEle
ment* image) |
| 199 { |
| 200 if (isContextLost() || !image) |
| 201 return; |
| 202 |
| 203 notImplemented(); |
| 204 } |
| 205 |
| 206 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLCanvasEl
ement* canvas) |
| 207 { |
| 208 if (isContextLost()) |
| 209 return; |
| 210 |
| 211 notImplemented(); |
| 212 } |
| 213 |
| 214 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLVideoEle
ment* video) |
| 215 { |
| 216 if (isContextLost()) |
| 217 return; |
| 218 |
| 219 notImplemented(); |
| 220 } |
| 221 |
| 222 void WebGL2RenderingContextBase::copyTexSubImage3D(GLenum target, GLint level, G
Lint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLs
izei height) |
| 223 { |
| 224 if (isContextLost()) |
| 225 return; |
| 226 |
| 227 notImplemented(); |
| 228 } |
| 229 |
| 230 void WebGL2RenderingContextBase::compressedTexImage3D(GLenum target, GLint level
, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint bor
der, GLsizei imageSize, DOMArrayBufferView* data) |
| 231 { |
| 232 if (isContextLost()) |
| 233 return; |
| 234 |
| 235 notImplemented(); |
| 236 } |
| 237 |
| 238 void WebGL2RenderingContextBase::compressedTexSubImage3D(GLenum target, GLint le
vel, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height,
GLsizei depth, GLenum format, GLsizei imageSize, DOMArrayBufferView* data) |
| 239 { |
| 240 if (isContextLost()) |
| 241 return; |
| 242 |
| 243 notImplemented(); |
| 244 } |
| 245 |
| 246 GLint WebGL2RenderingContextBase::getFragDataLocation(WebGLProgram* program, con
st String& name) |
| 247 { |
| 248 if (isContextLost() || !validateWebGLObject("getFragDataLocation", program)) |
| 249 return -1; |
| 250 |
| 251 return webContext()->getFragDataLocation(objectOrZero(program), name.utf8().
data()); |
| 252 } |
| 253 |
| 254 void WebGL2RenderingContextBase::uniform1ui(const WebGLUniformLocation* location
, GLuint v0) |
| 255 { |
| 256 if (isContextLost() || !location) |
| 257 return; |
| 258 |
| 259 if (location->program() != m_currentProgram) { |
| 260 synthesizeGLError(GL_INVALID_OPERATION, "uniform1ui", "location not for
current program"); |
| 261 return; |
| 262 } |
| 263 |
| 264 webContext()->uniform1ui(location->location(), v0); |
| 265 } |
| 266 |
| 267 void WebGL2RenderingContextBase::uniform2ui(const WebGLUniformLocation* location
, GLuint v0, GLuint v1) |
| 268 { |
| 269 if (isContextLost() || !location) |
| 270 return; |
| 271 |
| 272 if (location->program() != m_currentProgram) { |
| 273 synthesizeGLError(GL_INVALID_OPERATION, "uniform2ui", "location not for
current program"); |
| 274 return; |
| 275 } |
| 276 |
| 277 webContext()->uniform2ui(location->location(), v0, v1); |
| 278 } |
| 279 |
| 280 void WebGL2RenderingContextBase::uniform3ui(const WebGLUniformLocation* location
, GLuint v0, GLuint v1, GLuint v2) |
| 281 { |
| 282 if (isContextLost() || !location) |
| 283 return; |
| 284 |
| 285 if (location->program() != m_currentProgram) { |
| 286 synthesizeGLError(GL_INVALID_OPERATION, "uniform3ui", "location not for
current program"); |
| 287 return; |
| 288 } |
| 289 |
| 290 webContext()->uniform3ui(location->location(), v0, v1, v2); |
| 291 } |
| 292 |
| 293 void WebGL2RenderingContextBase::uniform4ui(const WebGLUniformLocation* location
, GLuint v0, GLuint v1, GLuint v2, GLuint v3) |
| 294 { |
| 295 if (isContextLost() || !location) |
| 296 return; |
| 297 |
| 298 if (location->program() != m_currentProgram) { |
| 299 synthesizeGLError(GL_INVALID_OPERATION, "uniform4ui", "location not for
current program"); |
| 300 return; |
| 301 } |
| 302 |
| 303 webContext()->uniform4ui(location->location(), v0, v1, v2, v3); |
| 304 } |
| 305 |
| 306 void WebGL2RenderingContextBase::uniform1uiv(const WebGLUniformLocation* locatio
n, Vector<GLuint>& value) |
| 307 { |
| 308 if (isContextLost() || validateUniformParameters("uniform1uiv", location, va
lue.data(), value.size(), 1)) |
| 309 return; |
| 310 |
| 311 webContext()->uniform1uiv(location->location(), value.size(), value.data()); |
| 312 } |
| 313 |
| 314 void WebGL2RenderingContextBase::uniform2uiv(const WebGLUniformLocation* locatio
n, Vector<GLuint>& value) |
| 315 { |
| 316 if (isContextLost() || !validateUniformParameters("uniform2uiv", location, v
alue.data(), value.size(), 2)) |
| 317 return; |
| 318 |
| 319 webContext()->uniform2uiv(location->location(), value.size() / 2, value.data
()); |
| 320 } |
| 321 |
| 322 void WebGL2RenderingContextBase::uniform3uiv(const WebGLUniformLocation* locatio
n, Vector<GLuint>& value) |
| 323 { |
| 324 if (isContextLost() || !validateUniformParameters("uniform3uiv", location, v
alue.data(), value.size(), 3)) |
| 325 return; |
| 326 |
| 327 webContext()->uniform3uiv(location->location(), value.size() / 3, value.data
()); |
| 328 } |
| 329 |
| 330 void WebGL2RenderingContextBase::uniform4uiv(const WebGLUniformLocation* locatio
n, Vector<GLuint>& value) |
| 331 { |
| 332 if (isContextLost() || !validateUniformParameters("uniform4uiv", location, v
alue.data(), value.size(), 4)) |
| 333 return; |
| 334 |
| 335 webContext()->uniform4uiv(location->location(), value.size() / 4, value.data
()); |
| 336 } |
| 337 |
| 338 void WebGL2RenderingContextBase::uniformMatrix2x3fv(const WebGLUniformLocation*
location, GLboolean transpose, DOMFloat32Array* value) |
| 339 { |
| 340 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2x3fv"
, location, transpose, value, 6)) |
| 341 return; |
| 342 webContext()->uniformMatrix2x3fv(location->location(), value->length() / 6,
transpose, value->data()); |
| 343 } |
| 344 |
| 345 void WebGL2RenderingContextBase::uniformMatrix2x3fv(const WebGLUniformLocation*
location, GLboolean transpose, Vector<GLfloat>& value) |
| 346 { |
| 347 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2x3fv"
, location, transpose, value.data(), value.size(), 6)) |
| 348 return; |
| 349 webContext()->uniformMatrix2x3fv(location->location(), value.size() / 6, tra
nspose, value.data()); |
| 350 } |
| 351 |
| 352 void WebGL2RenderingContextBase::uniformMatrix3x2fv(const WebGLUniformLocation*
location, GLboolean transpose, DOMFloat32Array* value) |
| 353 { |
| 354 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3x2fv"
, location, transpose, value, 6)) |
| 355 return; |
| 356 webContext()->uniformMatrix3x2fv(location->location(), value->length() / 6,
transpose, value->data()); |
| 357 } |
| 358 |
| 359 void WebGL2RenderingContextBase::uniformMatrix3x2fv(const WebGLUniformLocation*
location, GLboolean transpose, Vector<GLfloat>& value) |
| 360 { |
| 361 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3x2fv"
, location, transpose, value.data(), value.size(), 6)) |
| 362 return; |
| 363 webContext()->uniformMatrix3x2fv(location->location(), value.size() / 6, tra
nspose, value.data()); |
| 364 } |
| 365 |
| 366 void WebGL2RenderingContextBase::uniformMatrix2x4fv(const WebGLUniformLocation*
location, GLboolean transpose, DOMFloat32Array* value) |
| 367 { |
| 368 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2x4fv"
, location, transpose, value, 8)) |
| 369 return; |
| 370 webContext()->uniformMatrix2x4fv(location->location(), value->length() / 8,
transpose, value->data()); |
| 371 } |
| 372 |
| 373 void WebGL2RenderingContextBase::uniformMatrix2x4fv(const WebGLUniformLocation*
location, GLboolean transpose, Vector<GLfloat>& value) |
| 374 { |
| 375 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2x4fv"
, location, transpose, value.data(), value.size(), 8)) |
| 376 return; |
| 377 webContext()->uniformMatrix2x4fv(location->location(), value.size() / 8, tra
nspose, value.data()); |
| 378 } |
| 379 |
| 380 void WebGL2RenderingContextBase::uniformMatrix4x2fv(const WebGLUniformLocation*
location, GLboolean transpose, DOMFloat32Array* value) |
| 381 { |
| 382 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4x2fv"
, location, transpose, value, 8)) |
| 383 return; |
| 384 webContext()->uniformMatrix4x2fv(location->location(), value->length() / 8,
transpose, value->data()); |
| 385 } |
| 386 |
| 387 void WebGL2RenderingContextBase::uniformMatrix4x2fv(const WebGLUniformLocation*
location, GLboolean transpose, Vector<GLfloat>& value) |
| 388 { |
| 389 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4x2fv"
, location, transpose, value.data(), value.size(), 8)) |
| 390 return; |
| 391 webContext()->uniformMatrix4x2fv(location->location(), value.size() / 8, tra
nspose, value.data()); |
| 392 } |
| 393 |
| 394 void WebGL2RenderingContextBase::uniformMatrix3x4fv(const WebGLUniformLocation*
location, GLboolean transpose, DOMFloat32Array* value) |
| 395 { |
| 396 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3x4fv"
, location, transpose, value, 12)) |
| 397 return; |
| 398 webContext()->uniformMatrix3x4fv(location->location(), value->length() / 12,
transpose, value->data()); |
| 399 } |
| 400 |
| 401 void WebGL2RenderingContextBase::uniformMatrix3x4fv(const WebGLUniformLocation*
location, GLboolean transpose, Vector<GLfloat>& value) |
| 402 { |
| 403 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3x4fv"
, location, transpose, value.data(), value.size(), 12)) |
| 404 return; |
| 405 webContext()->uniformMatrix3x4fv(location->location(), value.size() / 12, tr
anspose, value.data()); |
| 406 } |
| 407 |
| 408 void WebGL2RenderingContextBase::uniformMatrix4x3fv(const WebGLUniformLocation*
location, GLboolean transpose, DOMFloat32Array* value) |
| 409 { |
| 410 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4x3fv"
, location, transpose, value, 12)) |
| 411 return; |
| 412 webContext()->uniformMatrix4x3fv(location->location(), value->length() / 12,
transpose, value->data()); |
| 413 } |
| 414 |
| 415 void WebGL2RenderingContextBase::uniformMatrix4x3fv(const WebGLUniformLocation*
location, GLboolean transpose, Vector<GLfloat>& value) |
| 416 { |
| 417 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4x3fv"
, location, transpose, value.data(), value.size(), 12)) |
| 418 return; |
| 419 webContext()->uniformMatrix4x3fv(location->location(), value.size() / 12, tr
anspose, value.data()); |
| 420 } |
| 421 |
| 422 void WebGL2RenderingContextBase::vertexAttribI4i(GLuint index, GLint x, GLint y,
GLint z, GLint w) |
| 423 { |
| 424 if (isContextLost()) |
| 425 return; |
| 426 |
| 427 if (index >= m_maxVertexAttribs) { |
| 428 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4i", "index out of ran
ge"); |
| 429 return; |
| 430 } |
| 431 |
| 432 webContext()->vertexAttribI4i(index, x, y, z, w); |
| 433 // TODO: Pretty sure this won't do what we want it to do. Same with the next
3 functions. |
| 434 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
| 435 attribValue.value[0] = x; |
| 436 attribValue.value[1] = y; |
| 437 attribValue.value[2] = z; |
| 438 attribValue.value[3] = w; |
| 439 } |
| 440 |
| 441 void WebGL2RenderingContextBase::vertexAttribI4iv(GLuint index, const Vector<GLi
nt>& value) |
| 442 { |
| 443 if (isContextLost()) |
| 444 return; |
| 445 |
| 446 if (!value.data()) { |
| 447 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4iv", "no array"); |
| 448 return; |
| 449 } |
| 450 if (value.size() < 4) { |
| 451 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4iv", "invalid size"); |
| 452 return; |
| 453 } |
| 454 if (index >= m_maxVertexAttribs) { |
| 455 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4iv", "index out of ra
nge"); |
| 456 return; |
| 457 } |
| 458 |
| 459 webContext()->vertexAttribI4iv(index, value.data()); |
| 460 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
| 461 attribValue.value[0] = value[0]; |
| 462 attribValue.value[1] = value[1]; |
| 463 attribValue.value[2] = value[2]; |
| 464 attribValue.value[3] = value[3]; |
| 465 } |
| 466 |
| 467 void WebGL2RenderingContextBase::vertexAttribI4ui(GLuint index, GLuint x, GLuint
y, GLuint z, GLuint w) |
| 468 { |
| 469 if (isContextLost()) |
| 470 return; |
| 471 |
| 472 if (index >= m_maxVertexAttribs) { |
| 473 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4ui", "index out of ra
nge"); |
| 474 return; |
| 475 } |
| 476 |
| 477 webContext()->vertexAttribI4ui(index, x, y, z, w); |
| 478 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
| 479 attribValue.value[0] = x; |
| 480 attribValue.value[1] = y; |
| 481 attribValue.value[2] = z; |
| 482 attribValue.value[3] = w; |
| 483 } |
| 484 |
| 485 void WebGL2RenderingContextBase::vertexAttribI4uiv(GLuint index, const Vector<GL
uint>& value) |
| 486 { |
| 487 if (isContextLost()) |
| 488 return; |
| 489 |
| 490 if (!value.data()) { |
| 491 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4uiv", "no array"); |
| 492 return; |
| 493 } |
| 494 if (value.size() < 4) { |
| 495 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4uiv", "invalid size")
; |
| 496 return; |
| 497 } |
| 498 if (index >= m_maxVertexAttribs) { |
| 499 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribI4uiv", "index out of r
ange"); |
| 500 return; |
| 501 } |
| 502 |
| 503 webContext()->vertexAttribI4uiv(index, value.data()); |
| 504 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
| 505 attribValue.value[0] = value[0]; |
| 506 attribValue.value[1] = value[1]; |
| 507 attribValue.value[2] = value[2]; |
| 508 attribValue.value[3] = value[3]; |
| 509 } |
| 510 |
| 511 void WebGL2RenderingContextBase::vertexAttribIPointer(GLuint index, GLint size,
GLenum type, GLsizei stride, GLintptr offset) |
| 512 { |
| 513 if (isContextLost()) |
| 514 return; |
| 515 if (index >= m_maxVertexAttribs) { |
| 516 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribIPointer", "index out o
f range"); |
| 517 return; |
| 518 } |
| 519 if (size < 1 || size > 4 || stride < 0 || stride > 255) { |
| 520 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribIPointer", "bad size or
stride"); |
| 521 return; |
| 522 } |
| 523 if (!validateValueFitNonNegInt32("vertexAttribIPointer", "offset", offset)) |
| 524 return; |
| 525 if (!m_boundArrayBuffer) { |
| 526 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribIPointer", "no boun
d ARRAY_BUFFER"); |
| 527 return; |
| 528 } |
| 529 unsigned typeSize = sizeInBytes(type); |
| 530 ASSERT((typeSize & (typeSize - 1)) == 0); // Ensure that the value is POT. |
| 531 if ((stride & (typeSize - 1)) || (static_cast<GLintptr>(offset) & (typeSize
- 1))) { |
| 532 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribIPointer", "stride
or offset not valid for type"); |
| 533 return; |
| 534 } |
| 535 GLsizei bytesPerElement = size * typeSize; |
| 536 |
| 537 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size,
type, false, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); |
| 538 webContext()->vertexAttribIPointer(index, size, type, stride, static_cast<GL
intptr>(offset)); |
| 539 } |
| 540 |
| 541 /* Writing to the drawing buffer */ |
| 542 void WebGL2RenderingContextBase::vertexAttribDivisor(GLuint index, GLuint diviso
r) |
| 543 { |
| 544 if (isContextLost()) |
| 545 return; |
| 546 |
| 547 if (index >= m_maxVertexAttribs) { |
| 548 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisor", "index out of
range"); |
| 549 return; |
| 550 } |
| 551 |
| 552 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor); |
| 553 webContext()->vertexAttribDivisorANGLE(index, divisor); |
| 554 } |
| 555 |
| 556 void WebGL2RenderingContextBase::drawArraysInstanced(GLenum mode, GLint first, G
Lsizei count, GLsizei instanceCount) |
| 557 { |
| 558 if (!validateDrawArrays("drawArraysInstanced", mode, first, count)) |
| 559 return; |
| 560 |
| 561 if (!validateDrawInstanced("drawArraysInstanced", instanceCount)) |
| 562 return; |
| 563 |
| 564 clearIfComposited(); |
| 565 |
| 566 handleTextureCompleteness("drawArraysInstanced", true); |
| 567 webContext()->drawArraysInstancedANGLE(mode, first, count, instanceCount); |
| 568 handleTextureCompleteness("drawArraysInstanced", false); |
| 569 markContextChanged(CanvasChanged); |
| 570 } |
| 571 |
| 572 void WebGL2RenderingContextBase::drawElementsInstanced(GLenum mode, GLsizei coun
t, GLenum type, GLintptr offset, GLsizei instanceCount) |
| 573 { |
| 574 if (!validateDrawElements("drawElementsInstanced", mode, count, type, offset
)) |
| 575 return; |
| 576 |
| 577 if (!validateDrawInstanced("drawElementsInstanced", instanceCount)) |
| 578 return; |
| 579 |
| 580 clearIfComposited(); |
| 581 |
| 582 handleTextureCompleteness("drawElementsInstanced", true); |
| 583 webContext()->drawElementsInstancedANGLE(mode, count, type, static_cast<GLin
tptr>(offset), instanceCount); |
| 584 handleTextureCompleteness("drawElementsInstanced", false); |
| 585 markContextChanged(CanvasChanged); |
| 586 } |
| 587 |
| 588 void WebGL2RenderingContextBase::drawBuffers(const Vector<GLenum>& buffers) |
| 589 { |
| 590 if (isContextLost()) |
| 591 return; |
| 592 |
| 593 GLsizei n = buffers.size(); |
| 594 const GLenum* bufs = buffers.data(); |
| 595 if (!m_framebufferBinding) { |
| 596 if (n != 1) { |
| 597 synthesizeGLError(GL_INVALID_VALUE, "drawBuffers", "more than one bu
ffer"); |
| 598 return; |
| 599 } |
| 600 if (bufs[0] != GL_BACK && bufs[0] != GL_NONE) { |
| 601 synthesizeGLError(GL_INVALID_OPERATION, "drawBuffers", "BACK or NONE
"); |
| 602 return; |
| 603 } |
| 604 // Because the backbuffer is simulated on all current WebKit ports, we n
eed to change BACK to COLOR_ATTACHMENT0. |
| 605 GLenum value = (bufs[0] == GL_BACK) ? GL_COLOR_ATTACHMENT0 : GL_NONE; |
| 606 webContext()->drawBuffersEXT(1, &value); |
| 607 setBackDrawBuffer(bufs[0]); |
| 608 } else { |
| 609 if (n > maxDrawBuffers()) { |
| 610 synthesizeGLError(GL_INVALID_VALUE, "drawBuffers", "more than max dr
aw buffers"); |
| 611 return; |
| 612 } |
| 613 for (GLsizei i = 0; i < n; ++i) { |
| 614 if (bufs[i] != GL_NONE && bufs[i] != static_cast<GLenum>(GL_COLOR_AT
TACHMENT0_EXT + i)) { |
| 615 synthesizeGLError(GL_INVALID_OPERATION, "drawBuffers", "COLOR_AT
TACHMENTi_EXT or NONE"); |
| 616 return; |
| 617 } |
| 618 } |
| 619 m_framebufferBinding->drawBuffers(buffers); |
| 620 } |
| 621 } |
| 622 |
| 623 bool WebGL2RenderingContextBase::validateClearBuffer(const char* functionName, G
Lenum buffer, GLsizei size) |
| 624 { |
| 625 switch (buffer) { |
| 626 case GL_COLOR: |
| 627 case GL_FRONT: |
| 628 case GL_BACK: |
| 629 case GL_FRONT_AND_BACK: { |
| 630 if (size < 4) { |
| 631 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid array siz
e"); |
| 632 return false; |
| 633 } |
| 634 break; |
| 635 } |
| 636 case GL_DEPTH: |
| 637 case GL_STENCIL: { |
| 638 if (size < 1) { |
| 639 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid array siz
e"); |
| 640 return false; |
| 641 } |
| 642 break; |
| 643 } |
| 644 default: |
| 645 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid buffer"); |
| 646 return false; |
| 647 } |
| 648 return true; |
| 649 } |
| 650 |
| 651 void WebGL2RenderingContextBase::clearBufferiv(GLenum buffer, GLint drawbuffer,
DOMInt32Array* value) |
| 652 { |
| 653 if (isContextLost() || !validateClearBuffer("clearBufferiv", buffer, value->
length())) |
| 654 return; |
| 655 |
| 656 webContext()->clearBufferiv(buffer, drawbuffer, value->data()); |
| 657 } |
| 658 |
| 659 void WebGL2RenderingContextBase::clearBufferiv(GLenum buffer, GLint drawbuffer,
const Vector<GLint>& value) |
| 660 { |
| 661 if (isContextLost() || !validateClearBuffer("clearBufferiv", buffer, value.s
ize())) |
| 662 return; |
| 663 |
| 664 webContext()->clearBufferiv(buffer, drawbuffer, value.data()); |
| 665 } |
| 666 |
| 667 void WebGL2RenderingContextBase::clearBufferuiv(GLenum buffer, GLint drawbuffer,
DOMUint32Array* value) |
| 668 { |
| 669 if (isContextLost() || !validateClearBuffer("clearBufferuiv", buffer, value-
>length())) |
| 670 return; |
| 671 |
| 672 webContext()->clearBufferuiv(buffer, drawbuffer, value->data()); |
| 673 } |
| 674 |
| 675 void WebGL2RenderingContextBase::clearBufferuiv(GLenum buffer, GLint drawbuffer,
const Vector<GLuint>& value) |
| 676 { |
| 677 if (isContextLost() || !validateClearBuffer("clearBufferuiv", buffer, value.
size())) |
| 678 return; |
| 679 |
| 680 webContext()->clearBufferuiv(buffer, drawbuffer, value.data()); |
| 681 } |
| 682 |
| 683 void WebGL2RenderingContextBase::clearBufferfv(GLenum buffer, GLint drawbuffer,
DOMFloat32Array* value) |
| 684 { |
| 685 if (isContextLost() || !validateClearBuffer("clearBufferfv", buffer, value->
length())) |
| 686 return; |
| 687 |
| 688 webContext()->clearBufferfv(buffer, drawbuffer, value->data()); |
| 689 } |
| 690 |
| 691 void WebGL2RenderingContextBase::clearBufferfv(GLenum buffer, GLint drawbuffer,
const Vector<GLfloat>& value) |
| 692 { |
| 693 if (isContextLost() || !validateClearBuffer("clearBufferfv", buffer, value.s
ize())) |
| 694 return; |
| 695 |
| 696 webContext()->clearBufferfv(buffer, drawbuffer, value.data()); |
| 697 } |
| 698 |
| 699 void WebGL2RenderingContextBase::clearBufferfi(GLenum buffer, GLint drawbuffer,
GLfloat depth, GLint stencil) |
| 700 { |
| 701 if (isContextLost()) |
| 702 return; |
| 703 |
| 704 webContext()->clearBufferfi(buffer, drawbuffer, depth, stencil); |
| 705 } |
| 706 |
| 707 PassRefPtr<WebGLQuery> WebGL2RenderingContextBase::createQuery() |
| 708 { |
| 709 if (isContextLost()) |
| 710 return nullptr; |
| 711 RefPtr<WebGLQuery> o = WebGLQuery::create(this); |
| 712 addSharedObject(o.get()); |
| 713 return o; |
| 714 } |
| 715 |
| 716 void WebGL2RenderingContextBase::deleteQuery(WebGLQuery* query) |
| 717 { |
| 718 deleteObject(query); |
| 719 } |
| 720 |
| 721 GLboolean WebGL2RenderingContextBase::isQuery(WebGLQuery* query) |
| 722 { |
| 723 if (isContextLost() || !query) |
| 724 return 0; |
| 725 |
| 726 return webContext()->isQueryEXT(query->object()); |
| 727 } |
| 728 |
| 729 void WebGL2RenderingContextBase::beginQuery(GLenum target, WebGLQuery* query) |
| 730 { |
| 731 if (isContextLost() || !validateWebGLObject("beginQuery", query)) |
| 732 return; |
| 733 |
| 734 webContext()->beginQueryEXT(target, query->object()); |
| 735 } |
| 736 |
| 737 void WebGL2RenderingContextBase::endQuery(GLenum target) |
| 738 { |
| 739 if (isContextLost()) |
| 740 return; |
| 741 |
| 742 webContext()->endQueryEXT(target); |
| 743 } |
| 744 |
| 745 PassRefPtr<WebGLQuery> WebGL2RenderingContextBase::getQuery(GLenum target, GLenu
m pname) |
| 746 { |
| 747 if (isContextLost()) |
| 748 return nullptr; |
| 749 |
| 750 notImplemented(); |
| 751 return nullptr; |
| 752 } |
| 753 |
| 754 ScriptValue WebGL2RenderingContextBase::getQueryParameter(ScriptState* scriptSta
te, WebGLQuery* query, GLenum pname) |
| 755 { |
| 756 if (isContextLost() || !validateWebGLObject("getQueryParameter", query)) |
| 757 return ScriptValue::createNull(scriptState); |
| 758 |
| 759 notImplemented(); |
| 760 return ScriptValue::createNull(scriptState); |
| 761 } |
| 762 |
| 763 PassRefPtr<WebGLSampler> WebGL2RenderingContextBase::createSampler() |
| 764 { |
| 765 if (isContextLost()) |
| 766 return nullptr; |
| 767 RefPtr<WebGLSampler> o = WebGLSampler::create(this); |
| 768 addSharedObject(o.get()); |
| 769 return o; |
| 770 } |
| 771 |
| 772 void WebGL2RenderingContextBase::deleteSampler(WebGLSampler* sampler) |
| 773 { |
| 774 deleteObject(sampler); |
| 775 } |
| 776 |
| 777 GLboolean WebGL2RenderingContextBase::isSampler(WebGLSampler* sampler) |
| 778 { |
| 779 if (isContextLost() || !sampler) |
| 780 return 0; |
| 781 |
| 782 return webContext()->isSampler(sampler->object()); |
| 783 } |
| 784 |
| 785 void WebGL2RenderingContextBase::bindSampler(GLuint unit, WebGLSampler* sampler) |
| 786 { |
| 787 if (isContextLost() || !validateWebGLObject("bindSampler", sampler)) |
| 788 return; |
| 789 |
| 790 webContext()->bindSampler(unit, objectOrZero(sampler)); |
| 791 } |
| 792 |
| 793 void WebGL2RenderingContextBase::samplerParameteri(WebGLSampler* sampler, GLenum
pname, GLint param) |
| 794 { |
| 795 if (isContextLost() || !validateWebGLObject("samplerParameteri", sampler)) |
| 796 return; |
| 797 |
| 798 webContext()->samplerParameteri(objectOrZero(sampler), pname, param); |
| 799 } |
| 800 |
| 801 void WebGL2RenderingContextBase::samplerParameteriv(WebGLSampler* sampler, GLenu
m pname, DOMInt32Array* param) |
| 802 { |
| 803 if (isContextLost() || !validateWebGLObject("samplerParameteriv", sampler)) |
| 804 return; |
| 805 |
| 806 // TODO: Ensure that param is long enough for pname. |
| 807 |
| 808 webContext()->samplerParameteriv(objectOrZero(sampler), pname, param->data()
); |
| 809 } |
| 810 |
| 811 void WebGL2RenderingContextBase::samplerParameteriv(WebGLSampler* sampler, GLenu
m pname, const Vector<GLint>& param) |
| 812 { |
| 813 if (isContextLost() || !validateWebGLObject("samplerParameteriv", sampler)) |
| 814 return; |
| 815 |
| 816 // TODO: Ensure that param is long enough for pname. |
| 817 |
| 818 webContext()->samplerParameteriv(objectOrZero(sampler), pname, param.data())
; |
| 819 } |
| 820 |
| 821 void WebGL2RenderingContextBase::samplerParameterf(WebGLSampler* sampler, GLenum
pname, GLfloat param) |
| 822 { |
| 823 if (isContextLost() || !validateWebGLObject("samplerParameterf", sampler)) |
| 824 return; |
| 825 |
| 826 webContext()->samplerParameterf(objectOrZero(sampler), pname, param); |
| 827 } |
| 828 |
| 829 void WebGL2RenderingContextBase::samplerParameterfv(WebGLSampler* sampler, GLenu
m pname, DOMFloat32Array* param) |
| 830 { |
| 831 if (isContextLost() || !validateWebGLObject("samplerParameterfv", sampler)) |
| 832 return; |
| 833 |
| 834 // TODO: Ensure that param is long enough for pname. |
| 835 |
| 836 webContext()->samplerParameterfv(objectOrZero(sampler), pname, param->data()
); |
| 837 } |
| 838 |
| 839 void WebGL2RenderingContextBase::samplerParameterfv(WebGLSampler* sampler, GLenu
m pname, const Vector<GLfloat>& param) |
| 840 { |
| 841 if (isContextLost() || !validateWebGLObject("samplerParameterfv", sampler)) |
| 842 return; |
| 843 |
| 844 // TODO: Ensure that param is long enough for pname. |
| 845 |
| 846 webContext()->samplerParameterfv(objectOrZero(sampler), pname, param.data())
; |
| 847 } |
| 848 |
| 849 ScriptValue WebGL2RenderingContextBase::getSamplerParameter(ScriptState* scriptS
tate, WebGLSampler* sampler, GLenum pname) |
| 850 { |
| 851 if (isContextLost() || !validateWebGLObject("getSamplerParameter", sampler)) |
| 852 return ScriptValue::createNull(scriptState); |
| 853 |
| 854 switch (pname) { |
| 855 case GL_TEXTURE_COMPARE_FUNC: |
| 856 case GL_TEXTURE_COMPARE_MODE: |
| 857 case GL_TEXTURE_MAG_FILTER: |
| 858 case GL_TEXTURE_MIN_FILTER: |
| 859 case GL_TEXTURE_WRAP_R: |
| 860 case GL_TEXTURE_WRAP_S: |
| 861 case GL_TEXTURE_WRAP_T: |
| 862 { |
| 863 GLint value = 0; |
| 864 webContext()->getSamplerParameteriv(objectOrZero(sampler), pname, &v
alue); |
| 865 return WebGLAny(scriptState, static_cast<unsigned>(value)); |
| 866 } |
| 867 case GL_TEXTURE_MAX_LOD: |
| 868 case GL_TEXTURE_MIN_LOD: |
| 869 { |
| 870 GLfloat value = 0.f; |
| 871 webContext()->getSamplerParameterfv(objectOrZero(sampler), pname, &v
alue); |
| 872 return WebGLAny(scriptState, value); |
| 873 } |
| 874 default: |
| 875 synthesizeGLError(GL_INVALID_ENUM, "getSamplerParameter", "invalid param
eter name"); |
| 876 return ScriptValue::createNull(scriptState); |
| 877 } |
| 878 } |
| 879 |
| 880 PassRefPtr<WebGLSync> WebGL2RenderingContextBase::fenceSync(GLenum condition, GL
bitfield flags) |
| 881 { |
| 882 if (isContextLost()) |
| 883 return nullptr; |
| 884 |
| 885 RefPtr<WebGLSync> o = WebGLFenceSync::create(this, condition, flags); |
| 886 addSharedObject(o.get()); |
| 887 return o.release(); |
| 888 } |
| 889 |
| 890 GLboolean WebGL2RenderingContextBase::isSync(WebGLSync* sync) |
| 891 { |
| 892 if (isContextLost() || !sync) |
| 893 return 0; |
| 894 |
| 895 return webContext()->isSync(sync->object()); |
| 896 } |
| 897 |
| 898 void WebGL2RenderingContextBase::deleteSync(WebGLSync* sync) |
| 899 { |
| 900 deleteObject(sync); |
| 901 } |
| 902 |
| 903 GLenum WebGL2RenderingContextBase::clientWaitSync(WebGLSync* sync, GLbitfield fl
ags, GLuint timeout) |
| 904 { |
| 905 if (isContextLost() || !validateWebGLObject("clientWaitSync", sync)) |
| 906 return GL_WAIT_FAILED; |
| 907 |
| 908 GLuint64 timeout64 = (timeout == WEBGL_TIMEOUT_IGNORED ? GL_TIMEOUT_IGNORED
: timeout); |
| 909 return webContext()->clientWaitSync(objectOrZero(sync), flags, timeout64); |
| 910 } |
| 911 |
| 912 void WebGL2RenderingContextBase::waitSync(WebGLSync* sync, GLbitfield flags, GLu
int timeout) |
| 913 { |
| 914 if (isContextLost() || !validateWebGLObject("waitSync", sync)) |
| 915 return; |
| 916 |
| 917 GLuint64 timeout64 = (timeout == WEBGL_TIMEOUT_IGNORED ? GL_TIMEOUT_IGNORED
: timeout); |
| 918 webContext()->waitSync(objectOrZero(sync), flags, timeout64); |
| 919 } |
| 920 |
| 921 ScriptValue WebGL2RenderingContextBase::getSyncParameter(ScriptState* scriptStat
e, WebGLSync* sync, GLenum pname) |
| 922 { |
| 923 if (isContextLost() || !validateWebGLObject("getSyncParameter", sync)) |
| 924 return ScriptValue::createNull(scriptState); |
| 925 |
| 926 notImplemented(); |
| 927 return ScriptValue::createNull(scriptState); |
| 928 } |
| 929 |
| 930 PassRefPtr<WebGLTransformFeedback> WebGL2RenderingContextBase::createTransformFe
edback() |
| 931 { |
| 932 if (isContextLost()) |
| 933 return nullptr; |
| 934 RefPtr<WebGLTransformFeedback> o = WebGLTransformFeedback::create(this); |
| 935 addSharedObject(o.get()); |
| 936 return o; |
| 937 } |
| 938 |
| 939 void WebGL2RenderingContextBase::deleteTransformFeedback(WebGLTransformFeedback*
feedback) |
| 940 { |
| 941 deleteObject(feedback); |
| 942 } |
| 943 |
| 944 GLboolean WebGL2RenderingContextBase::isTransformFeedback(WebGLTransformFeedback
* feedback) |
| 945 { |
| 946 if (isContextLost() || !feedback) |
| 947 return 0; |
| 948 |
| 949 return webContext()->isTransformFeedback(feedback->object()); |
| 950 } |
| 951 |
| 952 void WebGL2RenderingContextBase::bindTransformFeedback(GLenum target, WebGLTrans
formFeedback* feedback) |
| 953 { |
| 954 if (isContextLost() || !validateWebGLObject("bindTransformFeedback", feedbac
k)) |
| 955 return; |
| 956 |
| 957 webContext()->bindTransformFeedback(target, objectOrZero(feedback)); |
| 958 } |
| 959 |
| 960 void WebGL2RenderingContextBase::beginTransformFeedback(GLenum primitiveMode) |
| 961 { |
| 962 if (isContextLost()) |
| 963 return; |
| 964 |
| 965 webContext()->beginTransformFeedback(primitiveMode); |
| 966 } |
| 967 |
| 968 void WebGL2RenderingContextBase::endTransformFeedback() |
| 969 { |
| 970 if (isContextLost()) |
| 971 return; |
| 972 |
| 973 webContext()->endTransformFeedback(); |
| 974 } |
| 975 |
| 976 void WebGL2RenderingContextBase::transformFeedbackVaryings(WebGLProgram* program
, GLsizei count, const Vector<String>& varyings, GLenum bufferMode) |
| 977 { |
| 978 if (isContextLost() || !validateWebGLObject("transformFeedbackVaryings", pro
gram)) |
| 979 return; |
| 980 |
| 981 notImplemented(); |
| 982 } |
| 983 |
| 984 PassRefPtr<WebGLActiveInfo> WebGL2RenderingContextBase::getTransformFeedbackVary
ing(WebGLProgram* program, GLuint index) |
| 985 { |
| 986 if (isContextLost() || !validateWebGLObject("getTransformFeedbackVarying", p
rogram)) |
| 987 return nullptr; |
| 988 |
| 989 notImplemented(); |
| 990 return nullptr; |
| 991 } |
| 992 |
| 993 void WebGL2RenderingContextBase::pauseTransformFeedback() |
| 994 { |
| 995 if (isContextLost()) |
| 996 return; |
| 997 |
| 998 webContext()->pauseTransformFeedback(); |
| 999 } |
| 1000 |
| 1001 void WebGL2RenderingContextBase::resumeTransformFeedback() |
| 1002 { |
| 1003 if (isContextLost()) |
| 1004 return; |
| 1005 |
| 1006 webContext()->resumeTransformFeedback(); |
| 1007 } |
| 1008 |
| 1009 void WebGL2RenderingContextBase::bindBufferBase(GLenum target, GLuint index, Web
GLBuffer* buffer) |
| 1010 { |
| 1011 if (isContextLost() || !validateWebGLObject("bindBufferBase", buffer)) |
| 1012 return; |
| 1013 |
| 1014 notImplemented(); |
| 1015 } |
| 1016 |
| 1017 void WebGL2RenderingContextBase::bindBufferRange(GLenum target, GLuint index, We
bGLBuffer* buffer, GLintptr offset, GLsizeiptr size) |
| 1018 { |
| 1019 if (isContextLost() || !validateWebGLObject("bindBufferRange", buffer)) |
| 1020 return; |
| 1021 |
| 1022 notImplemented(); |
| 1023 } |
| 1024 |
| 1025 ScriptValue WebGL2RenderingContextBase::getIndexedParameter(ScriptState* scriptS
tate, GLenum target, GLuint index) |
| 1026 { |
| 1027 if (isContextLost()) |
| 1028 return ScriptValue::createNull(scriptState); |
| 1029 |
| 1030 notImplemented(); |
| 1031 return ScriptValue::createNull(scriptState); |
| 1032 } |
| 1033 |
| 1034 Vector<GLuint> WebGL2RenderingContextBase::getUniformIndices(WebGLProgram* progr
am, const Vector<String>& uniformNames) |
| 1035 { |
| 1036 Vector<GLuint> result; |
| 1037 if (isContextLost() || !validateWebGLObject("getUniformIndices", program)) |
| 1038 return result; |
| 1039 |
| 1040 notImplemented(); |
| 1041 // TODO: copy uniform names into array of const char* |
| 1042 /*result.resize(uniformNames.size()); |
| 1043 webContext()->getUniformIndices(objectOrZero(program), uniformNames.size(),
uniformNames.data(), result.data());*/ |
| 1044 return result; |
| 1045 } |
| 1046 |
| 1047 Vector<GLint> WebGL2RenderingContextBase::getActiveUniforms(WebGLProgram* progra
m, const Vector<GLuint>& uniformIndices, GLenum pname) |
| 1048 { |
| 1049 Vector<GLint> result; |
| 1050 if (isContextLost() || !validateWebGLObject("getActiveUniforms", program)) |
| 1051 return result; |
| 1052 |
| 1053 result.resize(uniformIndices.size()); |
| 1054 webContext()->getActiveUniformsiv(objectOrZero(program), uniformIndices.size
(), uniformIndices.data(), pname, result.data()); |
| 1055 return result; |
| 1056 } |
| 1057 |
| 1058 GLuint WebGL2RenderingContextBase::getUniformBlockIndex(WebGLProgram* program, c
onst String& uniformBlockName) |
| 1059 { |
| 1060 if (isContextLost() || !validateWebGLObject("getUniformBlockIndex", program)
) |
| 1061 return 0; |
| 1062 if (!validateString("getUniformBlockIndex", uniformBlockName)) |
| 1063 return 0; |
| 1064 |
| 1065 return webContext()->getUniformBlockIndex(objectOrZero(program), uniformBloc
kName.utf8().data()); |
| 1066 } |
| 1067 |
| 1068 ScriptValue WebGL2RenderingContextBase::getActiveUniformBlockParameter(ScriptSta
te* scriptState, WebGLProgram* program, GLuint uniformBlockIndex, GLenum pname) |
| 1069 { |
| 1070 if (isContextLost() || !validateWebGLObject("getActiveUniformBlockParameter"
, program)) |
| 1071 return ScriptValue::createNull(scriptState); |
| 1072 |
| 1073 switch (pname) { |
| 1074 case GL_UNIFORM_BLOCK_BINDING: |
| 1075 case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 1076 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: { |
| 1077 GLint intValue = 0; |
| 1078 webContext()->getActiveUniformBlockiv(objectOrZero(program), uniformBloc
kIndex, pname, &intValue); |
| 1079 return WebGLAny(scriptState, static_cast<unsigned>(intValue)); |
| 1080 } |
| 1081 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: { |
| 1082 GLint uniformCount = 0; |
| 1083 webContext()->getActiveUniformBlockiv(objectOrZero(program), uniformBloc
kIndex, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &uniformCount); |
| 1084 |
| 1085 Vector<GLint> signedIndices(uniformCount); |
| 1086 Vector<GLuint> indices(uniformCount); |
| 1087 webContext()->getActiveUniformBlockiv(objectOrZero(program), uniformBloc
kIndex, pname, signedIndices.data()); |
| 1088 for (GLint i = 0; i < uniformCount; ++i) { |
| 1089 indices[i] = static_cast<unsigned>(signedIndices[i]); |
| 1090 } |
| 1091 |
| 1092 return WebGLAny(scriptState, DOMUint32Array::create(indices.data(), indi
ces.size())); |
| 1093 } |
| 1094 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 1095 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: { |
| 1096 GLint boolValue = 0; |
| 1097 webContext()->getActiveUniformBlockiv(objectOrZero(program), uniformBloc
kIndex, pname, &boolValue); |
| 1098 return WebGLAny(scriptState, static_cast<bool>(boolValue)); |
| 1099 } |
| 1100 default: |
| 1101 synthesizeGLError(GL_INVALID_ENUM, "getActiveUniformBlockParameter", "in
valid pname"); |
| 1102 return ScriptValue::createNull(scriptState); |
| 1103 } |
| 1104 } |
| 1105 |
| 1106 String WebGL2RenderingContextBase::getActiveUniformBlockName(WebGLProgram* progr
am, GLuint uniformBlockIndex) |
| 1107 { |
| 1108 if (isContextLost() || !validateWebGLObject("getActiveUniformBlockName", pro
gram)) |
| 1109 return String(); |
| 1110 |
| 1111 notImplemented(); |
| 1112 return String(); |
| 1113 } |
| 1114 |
| 1115 void WebGL2RenderingContextBase::uniformBlockBinding(WebGLProgram* program, GLui
nt uniformBlockIndex, GLuint uniformBlockBinding) |
| 1116 { |
| 1117 if (isContextLost() || !validateWebGLObject("uniformBlockBinding", program)) |
| 1118 return; |
| 1119 |
| 1120 webContext()->uniformBlockBinding(objectOrZero(program), uniformBlockIndex,
uniformBlockBinding); |
| 1121 } |
| 1122 |
| 1123 PassRefPtr<WebGLVertexArrayObjectOES> WebGL2RenderingContextBase::createVertexAr
ray() |
| 1124 { |
| 1125 if (isContextLost()) |
| 1126 return nullptr; |
| 1127 |
| 1128 RefPtr<WebGLVertexArrayObjectOES> o = WebGLVertexArrayObjectOES::create(this
, WebGLVertexArrayObjectOES::VaoTypeUser); |
| 1129 addContextObject(o.get()); |
| 1130 return o.release(); |
| 1131 } |
| 1132 |
| 1133 void WebGL2RenderingContextBase::deleteVertexArray(WebGLVertexArrayObjectOES* ve
rtexArray) |
| 1134 { |
| 1135 if (isContextLost() || !vertexArray) |
| 1136 return; |
| 1137 |
| 1138 if (!vertexArray->isDefaultObject() && vertexArray == m_boundVertexArrayObje
ct) |
| 1139 setBoundVertexArrayObject(nullptr); |
| 1140 |
| 1141 vertexArray->deleteObject(webContext()); |
| 1142 } |
| 1143 |
| 1144 GLboolean WebGL2RenderingContextBase::isVertexArray(WebGLVertexArrayObjectOES* v
ertexArray) |
| 1145 { |
| 1146 if (isContextLost() || !vertexArray) |
| 1147 return 0; |
| 1148 |
| 1149 if (!vertexArray->hasEverBeenBound()) |
| 1150 return 0; |
| 1151 |
| 1152 return webContext()->isVertexArrayOES(vertexArray->object()); |
| 1153 } |
| 1154 |
| 1155 void WebGL2RenderingContextBase::bindVertexArray(WebGLVertexArrayObjectOES* vert
exArray) |
| 1156 { |
| 1157 if (isContextLost()) |
| 1158 return; |
| 1159 |
| 1160 if (vertexArray && (vertexArray->isDeleted() || !vertexArray->validate(0, th
is))) { |
| 1161 webContext()->synthesizeGLError(GL_INVALID_OPERATION); |
| 1162 return; |
| 1163 } |
| 1164 |
| 1165 if (vertexArray && !vertexArray->isDefaultObject() && vertexArray->object())
{ |
| 1166 webContext()->bindVertexArrayOES(objectOrZero(vertexArray)); |
| 1167 |
| 1168 vertexArray->setHasEverBeenBound(); |
| 1169 setBoundVertexArrayObject(vertexArray); |
| 1170 } else { |
| 1171 webContext()->bindVertexArrayOES(0); |
| 1172 setBoundVertexArrayObject(nullptr); |
| 1173 } |
| 1174 } |
| 1175 |
| 1176 void WebGL2RenderingContextBase::trace(Visitor* visitor) |
| 1177 { |
| 1178 WebGLRenderingContextBase::trace(visitor); |
| 1179 } |
| 1180 |
| 1181 } // namespace blink |
| OLD | NEW |