Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webgl/WebGL2RenderingContextBase.h" | 5 #include "modules/webgl/WebGL2RenderingContextBase.h" |
| 6 | 6 |
| 7 #include "bindings/modules/v8/WebGLAny.h" | 7 #include "bindings/modules/v8/WebGLAny.h" |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/html/HTMLImageElement.h" | 9 #include "core/html/HTMLImageElement.h" |
| 10 #include "core/html/HTMLVideoElement.h" | 10 #include "core/html/HTMLVideoElement.h" |
| (...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1444 | 1444 |
| 1445 webContext()->vertexAttribI4uiv(index, value); | 1445 webContext()->vertexAttribI4uiv(index, value); |
| 1446 VertexAttribValue& attribValue = m_vertexAttribValue[index]; | 1446 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
| 1447 attribValue.type = Uint32ArrayType; | 1447 attribValue.type = Uint32ArrayType; |
| 1448 attribValue.value.uintValue[0] = value[0]; | 1448 attribValue.value.uintValue[0] = value[0]; |
| 1449 attribValue.value.uintValue[1] = value[1]; | 1449 attribValue.value.uintValue[1] = value[1]; |
| 1450 attribValue.value.uintValue[2] = value[2]; | 1450 attribValue.value.uintValue[2] = value[2]; |
| 1451 attribValue.value.uintValue[3] = value[3]; | 1451 attribValue.value.uintValue[3] = value[3]; |
| 1452 } | 1452 } |
| 1453 | 1453 |
| 1454 bool WebGL2RenderingContextBase::validateVertexAttribPointerTypeAndSize(GLenum t ype, GLint size) | |
| 1455 { | |
| 1456 switch (type) { | |
| 1457 case GL_BYTE: | |
| 1458 case GL_UNSIGNED_BYTE: | |
| 1459 case GL_SHORT: | |
| 1460 case GL_UNSIGNED_SHORT: | |
| 1461 case GL_INT: | |
| 1462 case GL_UNSIGNED_INT: | |
| 1463 case GL_FLOAT: | |
| 1464 case GL_HALF_FLOAT: | |
| 1465 if (size < 1 || size > 4) { | |
| 1466 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "invalid size"); | |
| 1467 return false; | |
| 1468 } | |
| 1469 return true; | |
| 1470 case GL_INT_2_10_10_10_REV: | |
| 1471 case GL_UNSIGNED_INT_2_10_10_10_REV: | |
| 1472 if (size < 1 || size > 4) { | |
| 1473 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "invalid size"); | |
| 1474 return false; | |
| 1475 } | |
| 1476 if (size != 4) { | |
| 1477 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "size != 4"); | |
| 1478 return false; | |
| 1479 } | |
| 1480 return true; | |
| 1481 default: | |
| 1482 synthesizeGLError(GL_INVALID_ENUM, "vertexAttribPointer", "invalid type" ); | |
| 1483 return false; | |
| 1484 } | |
| 1485 } | |
| 1486 | |
| 1487 void WebGL2RenderingContextBase::vertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, long long offset) | 1454 void WebGL2RenderingContextBase::vertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, long long offset) |
| 1488 { | 1455 { |
| 1489 if (isContextLost()) | 1456 if (isContextLost()) |
| 1490 return; | 1457 return; |
| 1491 | |
| 1492 switch (type) { | |
| 1493 case GL_BYTE: | |
| 1494 case GL_UNSIGNED_BYTE: | |
| 1495 case GL_SHORT: | |
| 1496 case GL_UNSIGNED_SHORT: | |
| 1497 case GL_INT: | |
| 1498 case GL_UNSIGNED_INT: | |
| 1499 break; | |
| 1500 default: | |
| 1501 synthesizeGLError(GL_INVALID_ENUM, "vertexAttribIPointer", "invalid type "); | |
| 1502 return; | |
| 1503 } | |
| 1504 if (index >= m_maxVertexAttribs) { | |
| 1505 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribIPointer", "index out o f range"); | |
| 1506 return; | |
| 1507 } | |
| 1508 if (size < 1 || size > 4 || stride < 0 || stride > 255) { | |
| 1509 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribIPointer", "bad size or stride"); | |
| 1510 return; | |
| 1511 } | |
| 1512 if (!validateValueFitNonNegInt32("vertexAttribIPointer", "offset", offset)) | |
| 1513 return; | |
| 1514 if (!m_boundArrayBuffer) { | |
| 1515 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribIPointer", "no boun d ARRAY_BUFFER"); | |
| 1516 return; | |
| 1517 } | |
| 1518 unsigned typeSize = sizeInBytes(type); | 1458 unsigned typeSize = sizeInBytes(type); |
| 1519 ASSERT((typeSize & (typeSize - 1)) == 0); // Ensure that the value is POT. | |
| 1520 if ((stride & (typeSize - 1)) || (static_cast<GLintptr>(offset) & (typeSize - 1))) { | |
| 1521 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribIPointer", "stride or offset not valid for type"); | |
| 1522 return; | |
| 1523 } | |
| 1524 GLsizei bytesPerElement = size * typeSize; | 1459 GLsizei bytesPerElement = size * typeSize; |
| 1525 | 1460 |
| 1526 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, false, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); | 1461 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, false, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); |
|
Zhenyao Mo
2015/12/29 22:04:04
When you remove the above validation, then you end
yunchao
2015/12/30 01:02:11
Yeah, that's true. But Chromium will report error/
| |
| 1527 webContext()->vertexAttribIPointer(index, size, type, stride, static_cast<GL intptr>(offset)); | 1462 webContext()->vertexAttribIPointer(index, size, type, stride, static_cast<GL intptr>(offset)); |
| 1528 } | 1463 } |
| 1529 | 1464 |
| 1530 /* Writing to the drawing buffer */ | 1465 /* Writing to the drawing buffer */ |
| 1531 void WebGL2RenderingContextBase::vertexAttribDivisor(GLuint index, GLuint diviso r) | 1466 void WebGL2RenderingContextBase::vertexAttribDivisor(GLuint index, GLuint diviso r) |
| 1532 { | 1467 { |
| 1533 if (isContextLost()) | 1468 if (isContextLost()) |
| 1534 return; | 1469 return; |
| 1535 | 1470 |
| 1536 if (index >= m_maxVertexAttribs) { | 1471 if (index >= m_maxVertexAttribs) { |
| (...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3492 | 3427 |
| 3493 WebGLSampler* sampler = m_samplerUnits[unit]; | 3428 WebGLSampler* sampler = m_samplerUnits[unit]; |
| 3494 | 3429 |
| 3495 if (sampler) | 3430 if (sampler) |
| 3496 return sampler->getSamplerState(); | 3431 return sampler->getSamplerState(); |
| 3497 | 3432 |
| 3498 return WebGLRenderingContextBase::getTextureUnitSamplerState(target, unit); | 3433 return WebGLRenderingContextBase::getTextureUnitSamplerState(target, unit); |
| 3499 } | 3434 } |
| 3500 | 3435 |
| 3501 } // namespace blink | 3436 } // namespace blink |
| OLD | NEW |