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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize, 1); | 720 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize, 1); |
721 m_maxRenderbufferSize = 0; | 721 m_maxRenderbufferSize = 0; |
722 webContext()->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize); | 722 webContext()->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize); |
723 | 723 |
724 // These two values from EXT_draw_buffers are lazily queried. | 724 // These two values from EXT_draw_buffers are lazily queried. |
725 m_maxDrawBuffers = 0; | 725 m_maxDrawBuffers = 0; |
726 m_maxColorAttachments = 0; | 726 m_maxColorAttachments = 0; |
727 | 727 |
728 m_backDrawBuffer = GL_BACK; | 728 m_backDrawBuffer = GL_BACK; |
729 | 729 |
730 m_readBufferOfDefaultFramebuffer = GL_BACK; | |
731 | |
730 if (isWebGL2OrHigher()) { | 732 if (isWebGL2OrHigher()) { |
731 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV ertexArrayObjectBase::VaoTypeDefault); | 733 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV ertexArrayObjectBase::VaoTypeDefault); |
732 } else { | 734 } else { |
733 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web GLVertexArrayObjectBase::VaoTypeDefault); | 735 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web GLVertexArrayObjectBase::VaoTypeDefault); |
734 } | 736 } |
735 addContextObject(m_defaultVertexArrayObject.get()); | 737 addContextObject(m_defaultVertexArrayObject.get()); |
736 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 738 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
737 | 739 |
738 m_vertexAttribValue.resize(m_maxVertexAttribs); | 740 m_vertexAttribValue.resize(m_maxVertexAttribs); |
739 | 741 |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1536 | 1538 |
1537 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) | 1539 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) |
1538 { | 1540 { |
1539 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) { | 1541 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) { |
1540 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); | 1542 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); |
1541 return false; | 1543 return false; |
1542 } | 1544 } |
1543 return true; | 1545 return true; |
1544 } | 1546 } |
1545 | 1547 |
1548 bool WebGLRenderingContextBase::validateReadBufferAttachment(const char* functio nName, const WebGLFramebuffer* readFramebufferBinding) | |
1549 { | |
1550 if (readFramebufferBinding) { | |
1551 GLenum readBuffer = readFramebufferBinding->getReadBuffer(); | |
1552 if (readBuffer == GL_NONE) | |
1553 return false; | |
1554 WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachm entObject(readBuffer); | |
1555 if (!attachmentObject) { | |
1556 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no image atta ched to read buffer"); | |
1557 return false; | |
1558 } | |
1559 } else if (m_readBufferOfDefaultFramebuffer == GL_NONE) { | |
1560 return false; | |
Ken Russell (switch to Gerrit)
2015/07/07 18:21:26
This must synthesize an INVALID_OPERATION error pe
yunchao
2015/07/08 06:43:52
Done.
| |
1561 } | |
1562 return true; | |
1563 } | |
1564 | |
1546 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) | 1565 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
1547 { | 1566 { |
1548 if (isContextLost()) | 1567 if (isContextLost()) |
1549 return; | 1568 return; |
1550 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) | 1569 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) |
1551 return; | 1570 return; |
1552 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) | 1571 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) |
1553 return; | 1572 return; |
1554 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); | 1573 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); |
1555 if (!tex) | 1574 if (!tex) |
(...skipping 10 matching lines...) Expand all Loading... | |
1566 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); | 1585 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); |
1567 return; | 1586 return; |
1568 } | 1587 } |
1569 const char* reason = "framebuffer incomplete"; | 1588 const char* reason = "framebuffer incomplete"; |
1570 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; | 1589 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; |
1571 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); | 1590 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); |
1572 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { | 1591 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { |
1573 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); | 1592 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); |
1574 return; | 1593 return; |
1575 } | 1594 } |
1595 if (!validateReadBufferAttachment("copyTexImage2D", readFramebufferBinding)) | |
1596 return; | |
1576 clearIfComposited(); | 1597 clearIfComposited(); |
1577 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); | 1598 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
1578 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border); | 1599 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border); |
1579 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. | 1600 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. |
1580 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN ED_BYTE); | 1601 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN ED_BYTE); |
1581 } | 1602 } |
1582 | 1603 |
1583 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) | 1604 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) |
1584 { | 1605 { |
1585 if (isContextLost()) | 1606 if (isContextLost()) |
(...skipping 25 matching lines...) Expand all Loading... | |
1611 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); | 1632 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); |
1612 return; | 1633 return; |
1613 } | 1634 } |
1614 const char* reason = "framebuffer incomplete"; | 1635 const char* reason = "framebuffer incomplete"; |
1615 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; | 1636 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; |
1616 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); | 1637 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); |
1617 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { | 1638 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { |
1618 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); | 1639 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); |
1619 return; | 1640 return; |
1620 } | 1641 } |
1642 if (!validateReadBufferAttachment("copyTexSubImage2D", readFramebufferBindin g)) | |
1643 return; | |
1621 clearIfComposited(); | 1644 clearIfComposited(); |
1622 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); | 1645 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
1623 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height); | 1646 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height); |
1624 } | 1647 } |
1625 | 1648 |
1626 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() | 1649 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() |
1627 { | 1650 { |
1628 if (isContextLost()) | 1651 if (isContextLost()) |
1629 return nullptr; | 1652 return nullptr; |
1630 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); | 1653 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); |
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3352 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); | 3375 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); |
3353 if (error != GL_NO_ERROR) { | 3376 if (error != GL_NO_ERROR) { |
3354 synthesizeGLError(error, "readPixels", "invalid dimensions"); | 3377 synthesizeGLError(error, "readPixels", "invalid dimensions"); |
3355 return; | 3378 return; |
3356 } | 3379 } |
3357 if (pixels->byteLength() < totalBytesRequired) { | 3380 if (pixels->byteLength() < totalBytesRequired) { |
3358 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); | 3381 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); |
3359 return; | 3382 return; |
3360 } | 3383 } |
3361 | 3384 |
3385 if (!validateReadBufferAttachment("readPixels", readFramebufferBinding)) | |
3386 return; | |
3387 | |
3362 clearIfComposited(); | 3388 clearIfComposited(); |
3363 void* data = pixels->baseAddress(); | 3389 void* data = pixels->baseAddress(); |
3364 | 3390 |
3365 { | 3391 { |
3366 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding ); | 3392 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding ); |
3367 webContext()->readPixels(x, y, width, height, format, type, data); | 3393 webContext()->readPixels(x, y, width, height, format, type, data); |
3368 } | 3394 } |
3369 | 3395 |
3370 #if OS(MACOSX) | 3396 #if OS(MACOSX) |
3371 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., | 3397 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., |
(...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6232 | 6258 |
6233 return totalBytesPerPixel; | 6259 return totalBytesPerPixel; |
6234 } | 6260 } |
6235 | 6261 |
6236 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6262 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
6237 { | 6263 { |
6238 return m_drawingBuffer.get(); | 6264 return m_drawingBuffer.get(); |
6239 } | 6265 } |
6240 | 6266 |
6241 } // namespace blink | 6267 } // namespace blink |
OLD | NEW |