| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 int WebGLRenderingContextBase::drawingBufferWidth() const | 1405 int WebGLRenderingContextBase::drawingBufferWidth() const |
| 1406 { | 1406 { |
| 1407 return isContextLost() ? 0 : drawingBuffer()->size().width(); | 1407 return isContextLost() ? 0 : drawingBuffer()->size().width(); |
| 1408 } | 1408 } |
| 1409 | 1409 |
| 1410 int WebGLRenderingContextBase::drawingBufferHeight() const | 1410 int WebGLRenderingContextBase::drawingBufferHeight() const |
| 1411 { | 1411 { |
| 1412 return isContextLost() ? 0 : drawingBuffer()->size().height(); | 1412 return isContextLost() ? 0 : drawingBuffer()->size().height(); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 unsigned WebGLRenderingContextBase::sizeInBytes(GLenum type) const | |
| 1416 { | |
| 1417 switch (type) { | |
| 1418 case GL_BYTE: | |
| 1419 return sizeof(GLbyte); | |
| 1420 case GL_UNSIGNED_BYTE: | |
| 1421 return sizeof(GLubyte); | |
| 1422 case GL_SHORT: | |
| 1423 return sizeof(GLshort); | |
| 1424 case GL_UNSIGNED_SHORT: | |
| 1425 return sizeof(GLushort); | |
| 1426 case GL_INT: | |
| 1427 return sizeof(GLint); | |
| 1428 case GL_UNSIGNED_INT: | |
| 1429 return sizeof(GLuint); | |
| 1430 case GL_FLOAT: | |
| 1431 return sizeof(GLfloat); | |
| 1432 case GL_HALF_FLOAT: | |
| 1433 return sizeof(GLushort); | |
| 1434 case GL_INT_2_10_10_10_REV: | |
| 1435 return sizeof(GLint); | |
| 1436 case GL_UNSIGNED_INT_2_10_10_10_REV: | |
| 1437 return sizeof(GLuint); | |
| 1438 } | |
| 1439 ASSERT_NOT_REACHED(); | |
| 1440 return 0; | |
| 1441 } | |
| 1442 | |
| 1443 void WebGLRenderingContextBase::activeTexture(GLenum texture) | 1415 void WebGLRenderingContextBase::activeTexture(GLenum texture) |
| 1444 { | 1416 { |
| 1445 if (isContextLost()) | 1417 if (isContextLost()) |
| 1446 return; | 1418 return; |
| 1447 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) { | 1419 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) { |
| 1448 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of
range"); | 1420 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of
range"); |
| 1449 return; | 1421 return; |
| 1450 } | 1422 } |
| 1451 m_activeTextureUnit = texture - GL_TEXTURE0; | 1423 m_activeTextureUnit = texture - GL_TEXTURE0; |
| 1452 webContext()->activeTexture(texture); | 1424 webContext()->activeTexture(texture); |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 | 2243 |
| 2272 void WebGLRenderingContextBase::disableVertexAttribArray(GLuint index) | 2244 void WebGLRenderingContextBase::disableVertexAttribArray(GLuint index) |
| 2273 { | 2245 { |
| 2274 if (isContextLost()) | 2246 if (isContextLost()) |
| 2275 return; | 2247 return; |
| 2276 if (index >= m_maxVertexAttribs) { | 2248 if (index >= m_maxVertexAttribs) { |
| 2277 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray", "index o
ut of range"); | 2249 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray", "index o
ut of range"); |
| 2278 return; | 2250 return; |
| 2279 } | 2251 } |
| 2280 | 2252 |
| 2281 WebGLVertexArrayObjectBase::VertexAttribState* state = m_boundVertexArrayObj
ect->getVertexAttribState(index); | |
| 2282 state->enabled = false; | |
| 2283 | |
| 2284 webContext()->disableVertexAttribArray(index); | 2253 webContext()->disableVertexAttribArray(index); |
| 2285 } | 2254 } |
| 2286 | 2255 |
| 2287 bool WebGLRenderingContextBase::validateRenderingState(const char* functionName) | 2256 bool WebGLRenderingContextBase::validateRenderingState(const char* functionName) |
| 2288 { | 2257 { |
| 2289 if (!m_currentProgram) { | 2258 if (!m_currentProgram) { |
| 2290 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no valid shader p
rogram in use"); | 2259 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no valid shader p
rogram in use"); |
| 2291 return false; | 2260 return false; |
| 2292 } | 2261 } |
| 2293 | 2262 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2383 | 2352 |
| 2384 void WebGLRenderingContextBase::enableVertexAttribArray(GLuint index) | 2353 void WebGLRenderingContextBase::enableVertexAttribArray(GLuint index) |
| 2385 { | 2354 { |
| 2386 if (isContextLost()) | 2355 if (isContextLost()) |
| 2387 return; | 2356 return; |
| 2388 if (index >= m_maxVertexAttribs) { | 2357 if (index >= m_maxVertexAttribs) { |
| 2389 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray", "index ou
t of range"); | 2358 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray", "index ou
t of range"); |
| 2390 return; | 2359 return; |
| 2391 } | 2360 } |
| 2392 | 2361 |
| 2393 WebGLVertexArrayObjectBase::VertexAttribState* state = m_boundVertexArrayObj
ect->getVertexAttribState(index); | |
| 2394 state->enabled = true; | |
| 2395 | |
| 2396 webContext()->enableVertexAttribArray(index); | 2362 webContext()->enableVertexAttribArray(index); |
| 2397 } | 2363 } |
| 2398 | 2364 |
| 2399 void WebGLRenderingContextBase::finish() | 2365 void WebGLRenderingContextBase::finish() |
| 2400 { | 2366 { |
| 2401 if (isContextLost()) | 2367 if (isContextLost()) |
| 2402 return; | 2368 return; |
| 2403 webContext()->flush(); // Intentionally a flush, not a finish. | 2369 webContext()->flush(); // Intentionally a flush, not a finish. |
| 2404 } | 2370 } |
| 2405 | 2371 |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3491 } | 3457 } |
| 3492 | 3458 |
| 3493 ScriptValue WebGLRenderingContextBase::getVertexAttrib(ScriptState* scriptState,
GLuint index, GLenum pname) | 3459 ScriptValue WebGLRenderingContextBase::getVertexAttrib(ScriptState* scriptState,
GLuint index, GLenum pname) |
| 3494 { | 3460 { |
| 3495 if (isContextLost()) | 3461 if (isContextLost()) |
| 3496 return ScriptValue::createNull(scriptState); | 3462 return ScriptValue::createNull(scriptState); |
| 3497 if (index >= m_maxVertexAttribs) { | 3463 if (index >= m_maxVertexAttribs) { |
| 3498 synthesizeGLError(GL_INVALID_VALUE, "getVertexAttrib", "index out of ran
ge"); | 3464 synthesizeGLError(GL_INVALID_VALUE, "getVertexAttrib", "index out of ran
ge"); |
| 3499 return ScriptValue::createNull(scriptState); | 3465 return ScriptValue::createNull(scriptState); |
| 3500 } | 3466 } |
| 3501 const WebGLVertexArrayObjectBase::VertexAttribState* state = m_boundVertexAr
rayObject->getVertexAttribState(index); | |
| 3502 | 3467 |
| 3503 if ((extensionEnabled(ANGLEInstancedArraysName) || isWebGL2OrHigher()) | 3468 if ((extensionEnabled(ANGLEInstancedArraysName) || isWebGL2OrHigher()) |
| 3504 && pname == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE) | 3469 && pname == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE) |
| 3505 return WebGLAny(scriptState, state->divisor); | 3470 { |
| 3471 GLint value = 0; |
| 3472 webContext()->getVertexAttribiv(index, pname, &value); |
| 3473 return WebGLAny(scriptState, value); |
| 3474 } |
| 3506 | 3475 |
| 3507 switch (pname) { | 3476 switch (pname) { |
| 3508 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: | 3477 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 3509 if (!state->bufferBinding || !state->bufferBinding->object()) | 3478 return WebGLAny(scriptState, m_boundVertexArrayObject->getArrayBufferFor
Attrib(index)); |
| 3510 return ScriptValue::createNull(scriptState); | |
| 3511 return WebGLAny(scriptState, state->bufferBinding.get()); | |
| 3512 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: | 3479 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 3513 return WebGLAny(scriptState, state->enabled); | |
| 3514 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: | 3480 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 3515 return WebGLAny(scriptState, state->normalized); | 3481 { |
| 3482 GLint value = 0; |
| 3483 webContext()->getVertexAttribiv(index, pname, &value); |
| 3484 return WebGLAny(scriptState, static_cast<bool>(value)); |
| 3485 } |
| 3516 case GL_VERTEX_ATTRIB_ARRAY_SIZE: | 3486 case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 3517 return WebGLAny(scriptState, state->size); | |
| 3518 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: | 3487 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 3519 return WebGLAny(scriptState, state->originalStride); | 3488 { |
| 3489 GLint value = 0; |
| 3490 webContext()->getVertexAttribiv(index, pname, &value); |
| 3491 return WebGLAny(scriptState, value); |
| 3492 } |
| 3520 case GL_VERTEX_ATTRIB_ARRAY_TYPE: | 3493 case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 3521 return WebGLAny(scriptState, state->type); | 3494 { |
| 3495 GLint value = 0; |
| 3496 webContext()->getVertexAttribiv(index, pname, &value); |
| 3497 return WebGLAny(scriptState, static_cast<GLenum>(value)); |
| 3498 } |
| 3522 case GL_CURRENT_VERTEX_ATTRIB: | 3499 case GL_CURRENT_VERTEX_ATTRIB: |
| 3523 { | 3500 { |
| 3524 VertexAttribValue& attribValue = m_vertexAttribValue[index]; | 3501 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
| 3525 switch (attribValue.type) { | 3502 switch (attribValue.type) { |
| 3526 case Float32ArrayType: | 3503 case Float32ArrayType: |
| 3527 return WebGLAny(scriptState, DOMFloat32Array::create(attribValue
.value.floatValue, 4)); | 3504 return WebGLAny(scriptState, DOMFloat32Array::create(attribValue
.value.floatValue, 4)); |
| 3528 case Int32ArrayType: | 3505 case Int32ArrayType: |
| 3529 return WebGLAny(scriptState, DOMInt32Array::create(attribValue.v
alue.intValue, 4)); | 3506 return WebGLAny(scriptState, DOMInt32Array::create(attribValue.v
alue.intValue, 4)); |
| 3530 case Uint32ArrayType: | 3507 case Uint32ArrayType: |
| 3531 return WebGLAny(scriptState, DOMUint32Array::create(attribValue.
value.uintValue, 4)); | 3508 return WebGLAny(scriptState, DOMUint32Array::create(attribValue.
value.uintValue, 4)); |
| (...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5137 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, const DOMFloat32Ar
ray* v) | 5114 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, const DOMFloat32Ar
ray* v) |
| 5138 { | 5115 { |
| 5139 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4); | 5116 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4); |
| 5140 } | 5117 } |
| 5141 | 5118 |
| 5142 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, const Vector<GLflo
at>& v) | 5119 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, const Vector<GLflo
at>& v) |
| 5143 { | 5120 { |
| 5144 vertexAttribfvImpl("vertexAttrib4fv", index, v.data(), v.size(), 4); | 5121 vertexAttribfvImpl("vertexAttrib4fv", index, v.data(), v.size(), 4); |
| 5145 } | 5122 } |
| 5146 | 5123 |
| 5147 bool WebGLRenderingContextBase::validateVertexAttribPointerTypeAndSize(GLenum ty
pe, GLint size) | |
| 5148 { | |
| 5149 switch (type) { | |
| 5150 case GL_BYTE: | |
| 5151 case GL_UNSIGNED_BYTE: | |
| 5152 case GL_SHORT: | |
| 5153 case GL_UNSIGNED_SHORT: | |
| 5154 case GL_FLOAT: | |
| 5155 if (size < 1 || size > 4) { | |
| 5156 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "bad size
"); | |
| 5157 return false; | |
| 5158 } | |
| 5159 return true; | |
| 5160 default: | |
| 5161 synthesizeGLError(GL_INVALID_ENUM, "vertexAttribPointer", "invalid type"
); | |
| 5162 return false; | |
| 5163 } | |
| 5164 } | |
| 5165 | |
| 5166 void WebGLRenderingContextBase::vertexAttribPointer(ScriptState* scriptState, GL
uint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, long
long offset) | 5124 void WebGLRenderingContextBase::vertexAttribPointer(ScriptState* scriptState, GL
uint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, long
long offset) |
| 5167 { | 5125 { |
| 5168 if (isContextLost() || !validateVertexAttribPointerTypeAndSize(type, size)) | 5126 if (isContextLost()) |
| 5169 return; | 5127 return; |
| 5170 if (index >= m_maxVertexAttribs) { | 5128 if (index >= m_maxVertexAttribs) { |
| 5171 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of
range"); | 5129 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of
range"); |
| 5172 return; | 5130 return; |
| 5173 } | 5131 } |
| 5174 if (stride < 0 || stride > 255) { | |
| 5175 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "bad stride")
; | |
| 5176 return; | |
| 5177 } | |
| 5178 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) | 5132 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) |
| 5179 return; | 5133 return; |
| 5180 if (!m_boundArrayBuffer) { | 5134 if (!m_boundArrayBuffer) { |
| 5181 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound
ARRAY_BUFFER"); | 5135 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound
ARRAY_BUFFER"); |
| 5182 return; | 5136 return; |
| 5183 } | 5137 } |
| 5184 unsigned typeSize = sizeInBytes(type); | |
| 5185 ASSERT((typeSize & (typeSize - 1)) == 0); // Ensure that the value is POT. | |
| 5186 if ((stride & (typeSize - 1)) || (static_cast<GLintptr>(offset) & (typeSize
- 1))) { | |
| 5187 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "stride o
r offset not valid for type"); | |
| 5188 return; | |
| 5189 } | |
| 5190 GLsizei bytesPerElement = size * typeSize; | |
| 5191 | 5138 |
| 5192 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size,
type, normalized, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); | 5139 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer.
get()); |
| 5193 webContext()->vertexAttribPointer(index, size, type, normalized, stride, sta
tic_cast<GLintptr>(offset)); | 5140 webContext()->vertexAttribPointer(index, size, type, normalized, stride, sta
tic_cast<GLintptr>(offset)); |
| 5194 maybePreserveDefaultVAOObjectWrapper(scriptState); | 5141 maybePreserveDefaultVAOObjectWrapper(scriptState); |
| 5195 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, "arraybuffer",
index, m_boundArrayBuffer); | 5142 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, "arraybuffer",
index, m_boundArrayBuffer); |
| 5196 } | 5143 } |
| 5197 | 5144 |
| 5198 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di
visor) | 5145 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di
visor) |
| 5199 { | 5146 { |
| 5200 if (isContextLost()) | 5147 if (isContextLost()) |
| 5201 return; | 5148 return; |
| 5202 | 5149 |
| 5203 if (index >= m_maxVertexAttribs) { | 5150 if (index >= m_maxVertexAttribs) { |
| 5204 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o
ut of range"); | 5151 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o
ut of range"); |
| 5205 return; | 5152 return; |
| 5206 } | 5153 } |
| 5207 | 5154 |
| 5208 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor); | |
| 5209 webContext()->vertexAttribDivisorANGLE(index, divisor); | 5155 webContext()->vertexAttribDivisorANGLE(index, divisor); |
| 5210 } | 5156 } |
| 5211 | 5157 |
| 5212 void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsize
i height) | 5158 void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsize
i height) |
| 5213 { | 5159 { |
| 5214 if (isContextLost()) | 5160 if (isContextLost()) |
| 5215 return; | 5161 return; |
| 5216 if (!validateSize("viewport", width, height)) | 5162 if (!validateSize("viewport", width, height)) |
| 5217 return; | 5163 return; |
| 5218 webContext()->viewport(x, y, width, height); | 5164 webContext()->viewport(x, y, width, height); |
| (...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7071 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); | 7017 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 7072 } | 7018 } |
| 7073 | 7019 |
| 7074 void WebGLRenderingContextBase::restoreUnpackParameters() | 7020 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 7075 { | 7021 { |
| 7076 if (m_unpackAlignment != 1) | 7022 if (m_unpackAlignment != 1) |
| 7077 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 7023 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 7078 } | 7024 } |
| 7079 | 7025 |
| 7080 } // namespace blink | 7026 } // namespace blink |
| OLD | NEW |