| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/html/canvas/WebGL2RenderingContextBase.h" | 6 #include "core/html/canvas/WebGL2RenderingContextBase.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/WebGLAny.h" | 8 #include "bindings/core/v8/WebGLAny.h" |
| 9 #include "core/html/HTMLCanvasElement.h" | 9 #include "core/html/HTMLCanvasElement.h" |
| 10 #include "core/html/HTMLImageElement.h" | 10 #include "core/html/HTMLImageElement.h" |
| (...skipping 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1538 } | 1538 } |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 WebGLFramebuffer* WebGL2RenderingContextBase::getFramebufferBinding(GLenum targe
t) | 1541 WebGLFramebuffer* WebGL2RenderingContextBase::getFramebufferBinding(GLenum targe
t) |
| 1542 { | 1542 { |
| 1543 if (target == GL_READ_FRAMEBUFFER) | 1543 if (target == GL_READ_FRAMEBUFFER) |
| 1544 return m_readFramebufferBinding.get(); | 1544 return m_readFramebufferBinding.get(); |
| 1545 return m_framebufferBinding.get(); | 1545 return m_framebufferBinding.get(); |
| 1546 } | 1546 } |
| 1547 | 1547 |
| 1548 bool WebGL2RenderingContextBase::validateGetFramebufferAttachmentParameterFunc(c
onst char* functionName, GLenum target, GLenum attachment) |
| 1549 { |
| 1550 if (!validateFramebufferTarget(target)) { |
| 1551 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); |
| 1552 return false; |
| 1553 } |
| 1554 |
| 1555 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| 1556 ASSERT(framebufferBinding || drawingBuffer()); |
| 1557 if (!framebufferBinding) { |
| 1558 // for the default framebuffer |
| 1559 switch (attachment) { |
| 1560 case GL_BACK: |
| 1561 case GL_DEPTH: |
| 1562 case GL_STENCIL: |
| 1563 break; |
| 1564 default: |
| 1565 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment
"); |
| 1566 return false; |
| 1567 } |
| 1568 } else { |
| 1569 // for the FBO |
| 1570 switch (attachment) { |
| 1571 case GL_COLOR_ATTACHMENT0: |
| 1572 case GL_DEPTH_ATTACHMENT: |
| 1573 case GL_STENCIL_ATTACHMENT: |
| 1574 break; |
| 1575 case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1576 if (framebufferBinding->getAttachmentObject(GL_DEPTH_ATTACHMENT) !=
framebufferBinding->getAttachmentObject(GL_STENCIL_ATTACHMENT)) { |
| 1577 synthesizeGLError(GL_INVALID_OPERATION, functionName, "different
objects are bound to the depth and stencil attachment points"); |
| 1578 return false; |
| 1579 } |
| 1580 break; |
| 1581 default: |
| 1582 if (attachment > GL_COLOR_ATTACHMENT0 |
| 1583 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxCo
lorAttachments())) |
| 1584 break; |
| 1585 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment
"); |
| 1586 return false; |
| 1587 } |
| 1588 } |
| 1589 return true; |
| 1590 } |
| 1591 |
| 1592 ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(Script
State* scriptState, GLenum target, GLenum attachment, GLenum pname) |
| 1593 { |
| 1594 if (isContextLost() || !validateGetFramebufferAttachmentParameterFunc("getFr
amebufferAttachmentParameter", target, attachment)) |
| 1595 return ScriptValue::createNull(scriptState); |
| 1596 |
| 1597 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| 1598 ASSERT(!framebufferBinding || framebufferBinding->object()); |
| 1599 |
| 1600 WebGLSharedObject* attachmentObject = framebufferBinding ? framebufferBindin
g->getAttachmentObject(attachment) : 0; |
| 1601 if (framebufferBinding && !attachmentObject) { |
| 1602 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) |
| 1603 return WebGLAny(scriptState, GL_NONE); |
| 1604 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) |
| 1605 return WebGLAny(scriptState, 0); |
| 1606 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet
er", "invalid parameter name"); |
| 1607 return ScriptValue::createNull(scriptState); |
| 1608 } |
| 1609 |
| 1610 switch (pname) { |
| 1611 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 1612 if (!attachmentObject) { |
| 1613 ASSERT(!framebufferBinding); |
| 1614 return WebGLAny(scriptState, GL_FRAMEBUFFER_DEFAULT); |
| 1615 } |
| 1616 ASSERT(attachmentObject->isTexture() || attachmentObject->isRenderbuffer
()); |
| 1617 if (attachmentObject->isTexture()) |
| 1618 return WebGLAny(scriptState, GL_TEXTURE); |
| 1619 if (attachmentObject->isRenderbuffer()) |
| 1620 return WebGLAny(scriptState, GL_RENDERBUFFER); |
| 1621 break; |
| 1622 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 1623 if (!attachmentObject) |
| 1624 break; |
| 1625 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(attachm
entObject)); |
| 1626 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 1627 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 1628 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 1629 if (!attachmentObject || !attachmentObject->isTexture()) |
| 1630 break; |
| 1631 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 1632 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 1633 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 1634 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 1635 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 1636 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 1637 { |
| 1638 GLint value = 0; |
| 1639 webContext()->getFramebufferAttachmentParameteriv(target, attachment
, pname, &value); |
| 1640 return WebGLAny(scriptState, value); |
| 1641 } |
| 1642 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 1643 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 1644 { |
| 1645 GLint value = 0; |
| 1646 webContext()->getFramebufferAttachmentParameteriv(target, attachment
, pname, &value); |
| 1647 return WebGLAny(scriptState, static_cast<unsigned>(value)); |
| 1648 } |
| 1649 default: |
| 1650 break; |
| 1651 } |
| 1652 synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParameter", "inv
alid parameter name"); |
| 1653 return ScriptValue::createNull(scriptState); |
| 1654 } |
| 1655 |
| 1548 DEFINE_TRACE(WebGL2RenderingContextBase) | 1656 DEFINE_TRACE(WebGL2RenderingContextBase) |
| 1549 { | 1657 { |
| 1550 visitor->trace(m_readFramebufferBinding); | 1658 visitor->trace(m_readFramebufferBinding); |
| 1551 WebGLRenderingContextBase::trace(visitor); | 1659 WebGLRenderingContextBase::trace(visitor); |
| 1552 } | 1660 } |
| 1553 | 1661 |
| 1554 WebGLTexture* WebGL2RenderingContextBase::validateTextureBinding(const char* fun
ctionName, GLenum target, bool useSixEnumsForCubeMap) | 1662 WebGLTexture* WebGL2RenderingContextBase::validateTextureBinding(const char* fun
ctionName, GLenum target, bool useSixEnumsForCubeMap) |
| 1555 { | 1663 { |
| 1556 switch (target) { | 1664 switch (target) { |
| 1557 // FIXME: add 2D Array texture binding point and 3D texture binding point. | 1665 // FIXME: add 2D Array texture binding point and 3D texture binding point. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 GLfloat value = 0.f; | 1706 GLfloat value = 0.f; |
| 1599 webContext()->getTexParameterfv(target, pname, &value); | 1707 webContext()->getTexParameterfv(target, pname, &value); |
| 1600 return WebGLAny(scriptState, value); | 1708 return WebGLAny(scriptState, value); |
| 1601 } | 1709 } |
| 1602 default: | 1710 default: |
| 1603 return WebGLRenderingContextBase::getTexParameter(scriptState, target, p
name); | 1711 return WebGLRenderingContextBase::getTexParameter(scriptState, target, p
name); |
| 1604 } | 1712 } |
| 1605 } | 1713 } |
| 1606 | 1714 |
| 1607 } // namespace blink | 1715 } // namespace blink |
| OLD | NEW |