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