Chromium Code Reviews| 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 { |
| 3510 return ScriptValue::createNull(scriptState); | 3479 WeakMember<WebGLBuffer> buffer = m_boundVertexArrayObject->getArrayB ufferForAttrib(index); |
| 3511 return WebGLAny(scriptState, state->bufferBinding.get()); | 3480 if (!buffer || !buffer->object()) |
| 3481 return ScriptValue::createNull(scriptState); | |
| 3482 return WebGLAny(scriptState, buffer.get()); | |
|
yunchao
2016/01/06 17:31:42
The simplest way is to use "WebGLBuffer* buffer" t
Zhenyao Mo
2016/01/06 18:04:08
Can't you just return WebGLAny(scriptState, m_boun
Ken Russell (switch to Gerrit)
2016/01/06 20:53:54
It should definitely be possible to do this. There
yunchao
2016/01/07 00:24:08
Ah... I have made a detour, and it turned out to b
| |
| 3483 } | |
| 3512 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: | 3484 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 3513 return WebGLAny(scriptState, state->enabled); | |
| 3514 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: | 3485 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 3515 return WebGLAny(scriptState, state->normalized); | 3486 { |
| 3487 GLint value = 0; | |
| 3488 webContext()->getVertexAttribiv(index, pname, &value); | |
| 3489 return WebGLAny(scriptState, static_cast<bool>(value)); | |
| 3490 } | |
| 3516 case GL_VERTEX_ATTRIB_ARRAY_SIZE: | 3491 case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 3517 return WebGLAny(scriptState, state->size); | |
| 3518 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: | 3492 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 3519 return WebGLAny(scriptState, state->originalStride); | 3493 { |
| 3494 GLint value = 0; | |
| 3495 webContext()->getVertexAttribiv(index, pname, &value); | |
| 3496 return WebGLAny(scriptState, value); | |
| 3497 } | |
| 3520 case GL_VERTEX_ATTRIB_ARRAY_TYPE: | 3498 case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 3521 return WebGLAny(scriptState, state->type); | 3499 { |
| 3500 GLint value = 0; | |
| 3501 webContext()->getVertexAttribiv(index, pname, &value); | |
| 3502 return WebGLAny(scriptState, static_cast<GLenum>(value)); | |
| 3503 } | |
| 3522 case GL_CURRENT_VERTEX_ATTRIB: | 3504 case GL_CURRENT_VERTEX_ATTRIB: |
| 3523 { | 3505 { |
| 3524 VertexAttribValue& attribValue = m_vertexAttribValue[index]; | 3506 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
| 3525 switch (attribValue.type) { | 3507 switch (attribValue.type) { |
| 3526 case Float32ArrayType: | 3508 case Float32ArrayType: |
| 3527 return WebGLAny(scriptState, DOMFloat32Array::create(attribValue .value.floatValue, 4)); | 3509 return WebGLAny(scriptState, DOMFloat32Array::create(attribValue .value.floatValue, 4)); |
| 3528 case Int32ArrayType: | 3510 case Int32ArrayType: |
| 3529 return WebGLAny(scriptState, DOMInt32Array::create(attribValue.v alue.intValue, 4)); | 3511 return WebGLAny(scriptState, DOMInt32Array::create(attribValue.v alue.intValue, 4)); |
| 3530 case Uint32ArrayType: | 3512 case Uint32ArrayType: |
| 3531 return WebGLAny(scriptState, DOMUint32Array::create(attribValue. value.uintValue, 4)); | 3513 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) | 5119 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, const DOMFloat32Ar ray* v) |
| 5138 { | 5120 { |
| 5139 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4); | 5121 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4); |
| 5140 } | 5122 } |
| 5141 | 5123 |
| 5142 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, const Vector<GLflo at>& v) | 5124 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, const Vector<GLflo at>& v) |
| 5143 { | 5125 { |
| 5144 vertexAttribfvImpl("vertexAttrib4fv", index, v.data(), v.size(), 4); | 5126 vertexAttribfvImpl("vertexAttrib4fv", index, v.data(), v.size(), 4); |
| 5145 } | 5127 } |
| 5146 | 5128 |
| 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) | 5129 void WebGLRenderingContextBase::vertexAttribPointer(ScriptState* scriptState, GL uint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, long long offset) |
| 5167 { | 5130 { |
| 5168 if (isContextLost() || !validateVertexAttribPointerTypeAndSize(type, size)) | 5131 if (isContextLost()) |
| 5169 return; | 5132 return; |
| 5170 if (index >= m_maxVertexAttribs) { | 5133 if (index >= m_maxVertexAttribs) { |
| 5171 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of range"); | 5134 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of range"); |
| 5172 return; | 5135 return; |
| 5173 } | 5136 } |
| 5174 if (stride < 0 || stride > 255) { | |
| 5175 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "bad stride") ; | |
| 5176 return; | |
| 5177 } | |
| 5178 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) | 5137 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) |
| 5179 return; | 5138 return; |
| 5180 if (!m_boundArrayBuffer) { | 5139 if (!m_boundArrayBuffer) { |
| 5181 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); | 5140 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); |
| 5182 return; | 5141 return; |
| 5183 } | 5142 } |
| 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 | 5143 |
| 5192 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); | 5144 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get()); |
| 5193 webContext()->vertexAttribPointer(index, size, type, normalized, stride, sta tic_cast<GLintptr>(offset)); | 5145 webContext()->vertexAttribPointer(index, size, type, normalized, stride, sta tic_cast<GLintptr>(offset)); |
| 5194 maybePreserveDefaultVAOObjectWrapper(scriptState); | 5146 maybePreserveDefaultVAOObjectWrapper(scriptState); |
| 5195 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, "arraybuffer", index, m_boundArrayBuffer); | 5147 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, "arraybuffer", index, m_boundArrayBuffer); |
| 5196 } | 5148 } |
| 5197 | 5149 |
| 5198 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) | 5150 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) |
| 5199 { | 5151 { |
| 5200 if (isContextLost()) | 5152 if (isContextLost()) |
| 5201 return; | 5153 return; |
| 5202 | 5154 |
| 5203 if (index >= m_maxVertexAttribs) { | 5155 if (index >= m_maxVertexAttribs) { |
| 5204 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); | 5156 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); |
| 5205 return; | 5157 return; |
| 5206 } | 5158 } |
| 5207 | 5159 |
| 5208 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor); | |
| 5209 webContext()->vertexAttribDivisorANGLE(index, divisor); | 5160 webContext()->vertexAttribDivisorANGLE(index, divisor); |
| 5210 } | 5161 } |
| 5211 | 5162 |
| 5212 void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsize i height) | 5163 void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsize i height) |
| 5213 { | 5164 { |
| 5214 if (isContextLost()) | 5165 if (isContextLost()) |
| 5215 return; | 5166 return; |
| 5216 if (!validateSize("viewport", width, height)) | 5167 if (!validateSize("viewport", width, height)) |
| 5217 return; | 5168 return; |
| 5218 webContext()->viewport(x, y, width, height); | 5169 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); | 7022 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 7072 } | 7023 } |
| 7073 | 7024 |
| 7074 void WebGLRenderingContextBase::restoreUnpackParameters() | 7025 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 7075 { | 7026 { |
| 7076 if (m_unpackAlignment != 1) | 7027 if (m_unpackAlignment != 1) |
| 7077 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 7028 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 7078 } | 7029 } |
| 7079 | 7030 |
| 7080 } // namespace blink | 7031 } // namespace blink |
| OLD | NEW |