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 // set the default read color buffer for FBO |
| 731 m_readbufferOfFBO = GL_COLOR_ATTACHMENT0; |
| 732 |
730 if (isWebGL2OrHigher()) { | 733 if (isWebGL2OrHigher()) { |
731 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV
ertexArrayObjectBase::VaoTypeDefault); | 734 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV
ertexArrayObjectBase::VaoTypeDefault); |
732 } else { | 735 } else { |
733 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web
GLVertexArrayObjectBase::VaoTypeDefault); | 736 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web
GLVertexArrayObjectBase::VaoTypeDefault); |
734 } | 737 } |
735 addContextObject(m_defaultVertexArrayObject.get()); | 738 addContextObject(m_defaultVertexArrayObject.get()); |
736 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 739 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
737 | 740 |
738 m_vertexAttribValue.resize(m_maxVertexAttribs); | 741 m_vertexAttribValue.resize(m_maxVertexAttribs); |
739 | 742 |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 | 1539 |
1537 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa
me, GLenum format) | 1540 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa
me, GLenum format) |
1538 { | 1541 { |
1539 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers
ion::ChannelDepthStencil) { | 1542 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers
ion::ChannelDepthStencil) { |
1540 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be
set, only rendered to"); | 1543 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be
set, only rendered to"); |
1541 return false; | 1544 return false; |
1542 } | 1545 } |
1543 return true; | 1546 return true; |
1544 } | 1547 } |
1545 | 1548 |
| 1549 bool WebGLRenderingContextBase::validateReadBufferAttachment(const char* functio
nName, const WebGLFramebuffer* readFramebufferBinding) |
| 1550 { |
| 1551 if (readFramebufferBinding) { |
| 1552 WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachm
entObject(m_readbufferOfFBO); |
| 1553 if (!attachmentObject) { |
| 1554 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no image atta
ched to read buffer"); |
| 1555 return false; |
| 1556 } |
| 1557 } |
| 1558 return true; |
| 1559 } |
| 1560 |
1546 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu
m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) | 1561 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu
m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
1547 { | 1562 { |
1548 if (isContextLost()) | 1563 if (isContextLost()) |
1549 return; | 1564 return; |
1550 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l
evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) | 1565 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l
evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) |
1551 return; | 1566 return; |
1552 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) | 1567 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) |
1553 return; | 1568 return; |
1554 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); | 1569 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); |
1555 if (!tex) | 1570 if (!tex) |
(...skipping 10 matching lines...) Expand all Loading... |
1566 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow
er of 2"); | 1581 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow
er of 2"); |
1567 return; | 1582 return; |
1568 } | 1583 } |
1569 const char* reason = "framebuffer incomplete"; | 1584 const char* reason = "framebuffer incomplete"; |
1570 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA
MEBUFFER; | 1585 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA
MEBUFFER; |
1571 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer
Target); | 1586 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer
Target); |
1572 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext()
, &reason)) { | 1587 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext()
, &reason)) { |
1573 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re
ason); | 1588 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re
ason); |
1574 return; | 1589 return; |
1575 } | 1590 } |
| 1591 if (!validateReadBufferAttachment("copyTexImage2D", readFramebufferBinding)) |
| 1592 return; |
1576 clearIfComposited(); | 1593 clearIfComposited(); |
1577 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); | 1594 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
1578 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei
ght, border); | 1595 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. | 1596 // 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); | 1597 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN
ED_BYTE); |
1581 } | 1598 } |
1582 | 1599 |
1583 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL
int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) | 1600 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL
int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) |
1584 { | 1601 { |
1585 if (isContextLost()) | 1602 if (isContextLost()) |
(...skipping 25 matching lines...) Expand all Loading... |
1611 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe
r is incompatible format"); | 1628 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe
r is incompatible format"); |
1612 return; | 1629 return; |
1613 } | 1630 } |
1614 const char* reason = "framebuffer incomplete"; | 1631 const char* reason = "framebuffer incomplete"; |
1615 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA
MEBUFFER; | 1632 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA
MEBUFFER; |
1616 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer
Target); | 1633 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer
Target); |
1617 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext()
, &reason)) { | 1634 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext()
, &reason)) { |
1618 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D",
reason); | 1635 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D",
reason); |
1619 return; | 1636 return; |
1620 } | 1637 } |
| 1638 if (!validateReadBufferAttachment("copyTexSubImage2D", readFramebufferBindin
g)) |
| 1639 return; |
1621 clearIfComposited(); | 1640 clearIfComposited(); |
1622 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); | 1641 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
1623 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width
, height); | 1642 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width
, height); |
1624 } | 1643 } |
1625 | 1644 |
1626 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() | 1645 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() |
1627 { | 1646 { |
1628 if (isContextLost()) | 1647 if (isContextLost()) |
1629 return nullptr; | 1648 return nullptr; |
1630 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); | 1649 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); | 3371 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w
idth, height, m_packAlignment, &totalBytesRequired, &padding); |
3353 if (error != GL_NO_ERROR) { | 3372 if (error != GL_NO_ERROR) { |
3354 synthesizeGLError(error, "readPixels", "invalid dimensions"); | 3373 synthesizeGLError(error, "readPixels", "invalid dimensions"); |
3355 return; | 3374 return; |
3356 } | 3375 } |
3357 if (pixels->byteLength() < totalBytesRequired) { | 3376 if (pixels->byteLength() < totalBytesRequired) { |
3358 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n
ot large enough for dimensions"); | 3377 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n
ot large enough for dimensions"); |
3359 return; | 3378 return; |
3360 } | 3379 } |
3361 | 3380 |
| 3381 if (!validateReadBufferAttachment("readPixels", readFramebufferBinding)) |
| 3382 return; |
| 3383 |
3362 clearIfComposited(); | 3384 clearIfComposited(); |
3363 void* data = pixels->baseAddress(); | 3385 void* data = pixels->baseAddress(); |
3364 | 3386 |
3365 { | 3387 { |
3366 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding
); | 3388 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding
); |
3367 webContext()->readPixels(x, y, width, height, format, type, data); | 3389 webContext()->readPixels(x, y, width, height, format, type, data); |
3368 } | 3390 } |
3369 | 3391 |
3370 #if OS(MACOSX) | 3392 #if OS(MACOSX) |
3371 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., | 3393 // 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 | 6254 |
6233 return totalBytesPerPixel; | 6255 return totalBytesPerPixel; |
6234 } | 6256 } |
6235 | 6257 |
6236 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6258 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
6237 { | 6259 { |
6238 return m_drawingBuffer.get(); | 6260 return m_drawingBuffer.get(); |
6239 } | 6261 } |
6240 | 6262 |
6241 } // namespace blink | 6263 } // namespace blink |
OLD | NEW |