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 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 | 1399 |
1400 webContext()->vertexAttribI4uiv(index, value); | 1400 webContext()->vertexAttribI4uiv(index, value); |
1401 VertexAttribValue& attribValue = m_vertexAttribValue[index]; | 1401 VertexAttribValue& attribValue = m_vertexAttribValue[index]; |
1402 attribValue.type = Uint32ArrayType; | 1402 attribValue.type = Uint32ArrayType; |
1403 attribValue.value.uintValue[0] = value[0]; | 1403 attribValue.value.uintValue[0] = value[0]; |
1404 attribValue.value.uintValue[1] = value[1]; | 1404 attribValue.value.uintValue[1] = value[1]; |
1405 attribValue.value.uintValue[2] = value[2]; | 1405 attribValue.value.uintValue[2] = value[2]; |
1406 attribValue.value.uintValue[3] = value[3]; | 1406 attribValue.value.uintValue[3] = value[3]; |
1407 } | 1407 } |
1408 | 1408 |
1409 bool WebGL2RenderingContextBase::validateVertexAttribPointerTypeAndSize(GLenum t
ype, GLint size) | |
1410 { | |
1411 switch (type) { | |
1412 case GL_BYTE: | |
1413 case GL_UNSIGNED_BYTE: | |
1414 case GL_SHORT: | |
1415 case GL_UNSIGNED_SHORT: | |
1416 case GL_INT: | |
1417 case GL_UNSIGNED_INT: | |
1418 case GL_FLOAT: | |
1419 case GL_HALF_FLOAT: | |
1420 if (size < 1 || size > 4) { | |
1421 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "invalid
size"); | |
1422 return false; | |
1423 } | |
1424 return true; | |
1425 case GL_INT_2_10_10_10_REV: | |
1426 case GL_UNSIGNED_INT_2_10_10_10_REV: | |
1427 if (size < 1 || size > 4) { | |
1428 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "invalid
size"); | |
1429 return false; | |
1430 } | |
1431 if (size != 4) { | |
1432 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "size
!= 4"); | |
1433 return false; | |
1434 } | |
1435 return true; | |
1436 default: | |
1437 synthesizeGLError(GL_INVALID_ENUM, "vertexAttribPointer", "invalid type"
); | |
1438 return false; | |
1439 } | |
1440 } | |
1441 | |
1442 void WebGL2RenderingContextBase::vertexAttribIPointer(GLuint index, GLint size,
GLenum type, GLsizei stride, long long offset) | 1409 void WebGL2RenderingContextBase::vertexAttribIPointer(GLuint index, GLint size,
GLenum type, GLsizei stride, long long offset) |
1443 { | 1410 { |
1444 if (isContextLost()) | 1411 if (isContextLost()) |
1445 return; | 1412 return; |
1446 | |
1447 switch (type) { | |
1448 case GL_BYTE: | |
1449 case GL_UNSIGNED_BYTE: | |
1450 case GL_SHORT: | |
1451 case GL_UNSIGNED_SHORT: | |
1452 case GL_INT: | |
1453 case GL_UNSIGNED_INT: | |
1454 break; | |
1455 default: | |
1456 synthesizeGLError(GL_INVALID_ENUM, "vertexAttribIPointer", "invalid type
"); | |
1457 return; | |
1458 } | |
1459 if (index >= m_maxVertexAttribs) { | 1413 if (index >= m_maxVertexAttribs) { |
1460 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribIPointer", "index out o
f range"); | 1414 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribIPointer", "index out o
f range"); |
1461 return; | 1415 return; |
1462 } | 1416 } |
1463 if (size < 1 || size > 4 || stride < 0 || stride > 255) { | |
1464 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribIPointer", "bad size or
stride"); | |
1465 return; | |
1466 } | |
1467 if (!validateValueFitNonNegInt32("vertexAttribIPointer", "offset", offset)) | |
1468 return; | |
1469 if (!m_boundArrayBuffer) { | 1417 if (!m_boundArrayBuffer) { |
1470 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribIPointer", "no boun
d ARRAY_BUFFER"); | 1418 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribIPointer", "no boun
d ARRAY_BUFFER"); |
1471 return; | 1419 return; |
1472 } | 1420 } |
1473 unsigned typeSize = sizeInBytes(type); | |
1474 ASSERT((typeSize & (typeSize - 1)) == 0); // Ensure that the value is POT. | |
1475 if ((stride & (typeSize - 1)) || (static_cast<GLintptr>(offset) & (typeSize
- 1))) { | |
1476 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribIPointer", "stride
or offset not valid for type"); | |
1477 return; | |
1478 } | |
1479 GLsizei bytesPerElement = size * typeSize; | |
1480 | 1421 |
1481 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size,
type, false, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); | 1422 m_boundVertexArrayObject->setVertexAttribState(index, m_boundArrayBuffer); |
1482 webContext()->vertexAttribIPointer(index, size, type, stride, static_cast<GL
intptr>(offset)); | 1423 webContext()->vertexAttribIPointer(index, size, type, stride, static_cast<GL
intptr>(offset)); |
1483 } | 1424 } |
1484 | 1425 |
1485 /* Writing to the drawing buffer */ | 1426 /* Writing to the drawing buffer */ |
1486 void WebGL2RenderingContextBase::vertexAttribDivisor(GLuint index, GLuint diviso
r) | 1427 void WebGL2RenderingContextBase::vertexAttribDivisor(GLuint index, GLuint diviso
r) |
1487 { | 1428 { |
1488 if (isContextLost()) | 1429 if (isContextLost()) |
1489 return; | 1430 return; |
1490 | 1431 |
1491 if (index >= m_maxVertexAttribs) { | 1432 if (index >= m_maxVertexAttribs) { |
1492 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisor", "index out of
range"); | 1433 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisor", "index out of
range"); |
1493 return; | 1434 return; |
1494 } | 1435 } |
1495 | 1436 |
1496 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor); | |
1497 webContext()->vertexAttribDivisorANGLE(index, divisor); | 1437 webContext()->vertexAttribDivisorANGLE(index, divisor); |
1498 } | 1438 } |
1499 | 1439 |
1500 void WebGL2RenderingContextBase::drawArraysInstanced(GLenum mode, GLint first, G
Lsizei count, GLsizei instanceCount) | 1440 void WebGL2RenderingContextBase::drawArraysInstanced(GLenum mode, GLint first, G
Lsizei count, GLsizei instanceCount) |
1501 { | 1441 { |
1502 if (!validateDrawArrays("drawArraysInstanced", mode, first, count)) | 1442 if (!validateDrawArrays("drawArraysInstanced", mode, first, count)) |
1503 return; | 1443 return; |
1504 | 1444 |
1505 if (!validateDrawInstanced("drawArraysInstanced", instanceCount)) | 1445 if (!validateDrawInstanced("drawArraysInstanced", instanceCount)) |
1506 return; | 1446 return; |
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3447 | 3387 |
3448 WebGLSampler* sampler = m_samplerUnits[unit]; | 3388 WebGLSampler* sampler = m_samplerUnits[unit]; |
3449 | 3389 |
3450 if (sampler) | 3390 if (sampler) |
3451 return sampler->getSamplerState(); | 3391 return sampler->getSamplerState(); |
3452 | 3392 |
3453 return WebGLRenderingContextBase::getTextureUnitSamplerState(target, unit); | 3393 return WebGLRenderingContextBase::getTextureUnitSamplerState(target, unit); |
3454 } | 3394 } |
3455 | 3395 |
3456 } // namespace blink | 3396 } // namespace blink |
OLD | NEW |