OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 | 27 |
28 #include "core/html/canvas/WebGLDrawBuffers.h" | 28 #include "core/html/canvas/WebGLDrawBuffers.h" |
29 | 29 |
30 #include "platform/graphics/Extensions3D.h" | |
31 | |
32 namespace WebCore { | 30 namespace WebCore { |
33 | 31 |
34 WebGLDrawBuffers::WebGLDrawBuffers(WebGLRenderingContext* context) | 32 WebGLDrawBuffers::WebGLDrawBuffers(WebGLRenderingContext* context) |
35 : WebGLExtension(context) | 33 : WebGLExtension(context) |
36 { | 34 { |
37 ScriptWrappable::init(this); | 35 ScriptWrappable::init(this); |
38 context->graphicsContext3D()->extensions()->ensureEnabled("GL_EXT_draw_buffe
rs"); | 36 context->graphicsContext3D()->ensureExtensionEnabled("GL_EXT_draw_buffers"); |
39 } | 37 } |
40 | 38 |
41 WebGLDrawBuffers::~WebGLDrawBuffers() | 39 WebGLDrawBuffers::~WebGLDrawBuffers() |
42 { | 40 { |
43 } | 41 } |
44 | 42 |
45 WebGLExtension::ExtensionName WebGLDrawBuffers::name() const | 43 WebGLExtension::ExtensionName WebGLDrawBuffers::name() const |
46 { | 44 { |
47 return WebGLExtension::WebGLDrawBuffersName; | 45 return WebGLExtension::WebGLDrawBuffersName; |
48 } | 46 } |
49 | 47 |
50 PassRefPtr<WebGLDrawBuffers> WebGLDrawBuffers::create(WebGLRenderingContext* con
text) | 48 PassRefPtr<WebGLDrawBuffers> WebGLDrawBuffers::create(WebGLRenderingContext* con
text) |
51 { | 49 { |
52 return adoptRef(new WebGLDrawBuffers(context)); | 50 return adoptRef(new WebGLDrawBuffers(context)); |
53 } | 51 } |
54 | 52 |
55 // static | 53 // static |
56 bool WebGLDrawBuffers::supported(WebGLRenderingContext* context) | 54 bool WebGLDrawBuffers::supported(WebGLRenderingContext* context) |
57 { | 55 { |
58 Extensions3D* extensions = context->graphicsContext3D()->extensions(); | 56 return (context->graphicsContext3D()->supportsExtension("GL_EXT_draw_buffers
") |
59 return (extensions->supports("GL_EXT_draw_buffers") | |
60 && satisfiesWebGLRequirements(context)); | 57 && satisfiesWebGLRequirements(context)); |
61 } | 58 } |
62 | 59 |
63 const char* WebGLDrawBuffers::extensionName() | 60 const char* WebGLDrawBuffers::extensionName() |
64 { | 61 { |
65 return "WEBGL_draw_buffers"; | 62 return "WEBGL_draw_buffers"; |
66 } | 63 } |
67 | 64 |
68 void WebGLDrawBuffers::drawBuffersWEBGL(const Vector<GLenum>& buffers) | 65 void WebGLDrawBuffers::drawBuffersWEBGL(const Vector<GLenum>& buffers) |
69 { | 66 { |
70 if (isLost()) | 67 if (isLost()) |
71 return; | 68 return; |
72 GLsizei n = buffers.size(); | 69 GLsizei n = buffers.size(); |
73 const GLenum* bufs = buffers.data(); | 70 const GLenum* bufs = buffers.data(); |
74 if (!m_context->m_framebufferBinding) { | 71 if (!m_context->m_framebufferBinding) { |
75 if (n != 1) { | 72 if (n != 1) { |
76 m_context->synthesizeGLError(GL_INVALID_VALUE, "drawBuffersWEBGL", "
more than one buffer"); | 73 m_context->synthesizeGLError(GL_INVALID_VALUE, "drawBuffersWEBGL", "
more than one buffer"); |
77 return; | 74 return; |
78 } | 75 } |
79 if (bufs[0] != GL_BACK && bufs[0] != GL_NONE) { | 76 if (bufs[0] != GL_BACK && bufs[0] != GL_NONE) { |
80 m_context->synthesizeGLError(GL_INVALID_OPERATION, "drawBuffersWEBGL
", "BACK or NONE"); | 77 m_context->synthesizeGLError(GL_INVALID_OPERATION, "drawBuffersWEBGL
", "BACK or NONE"); |
81 return; | 78 return; |
82 } | 79 } |
83 // Because the backbuffer is simulated on all current WebKit ports, we n
eed to change BACK to COLOR_ATTACHMENT0. | 80 // Because the backbuffer is simulated on all current WebKit ports, we n
eed to change BACK to COLOR_ATTACHMENT0. |
84 GLenum value = (bufs[0] == GL_BACK) ? GL_COLOR_ATTACHMENT0 : GL_NONE; | 81 GLenum value = (bufs[0] == GL_BACK) ? GL_COLOR_ATTACHMENT0 : GL_NONE; |
85 m_context->graphicsContext3D()->extensions()->drawBuffersEXT(1, &value); | 82 m_context->webGraphicsContext3D()->drawBuffersEXT(1, &value); |
86 m_context->setBackDrawBuffer(bufs[0]); | 83 m_context->setBackDrawBuffer(bufs[0]); |
87 } else { | 84 } else { |
88 if (n > m_context->maxDrawBuffers()) { | 85 if (n > m_context->maxDrawBuffers()) { |
89 m_context->synthesizeGLError(GL_INVALID_VALUE, "drawBuffersWEBGL", "
more than max draw buffers"); | 86 m_context->synthesizeGLError(GL_INVALID_VALUE, "drawBuffersWEBGL", "
more than max draw buffers"); |
90 return; | 87 return; |
91 } | 88 } |
92 for (GLsizei i = 0; i < n; ++i) { | 89 for (GLsizei i = 0; i < n; ++i) { |
93 if (bufs[i] != GL_NONE && bufs[i] != static_cast<GLenum>(Extensions3
D::COLOR_ATTACHMENT0_EXT + i)) { | 90 if (bufs[i] != GL_NONE && bufs[i] != static_cast<GLenum>(GL_COLOR_AT
TACHMENT0_EXT + i)) { |
94 m_context->synthesizeGLError(GL_INVALID_OPERATION, "drawBuffersW
EBGL", "COLOR_ATTACHMENTi_EXT or NONE"); | 91 m_context->synthesizeGLError(GL_INVALID_OPERATION, "drawBuffersW
EBGL", "COLOR_ATTACHMENTi_EXT or NONE"); |
95 return; | 92 return; |
96 } | 93 } |
97 } | 94 } |
98 m_context->m_framebufferBinding->drawBuffers(buffers); | 95 m_context->m_framebufferBinding->drawBuffers(buffers); |
99 } | 96 } |
100 } | 97 } |
101 | 98 |
102 // static | 99 // static |
103 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContext* webglCo
ntext) | 100 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContext* webglCo
ntext) |
104 { | 101 { |
105 GraphicsContext3D* context = webglContext->graphicsContext3D(); | 102 blink::WebGraphicsContext3D* context = webglContext->webGraphicsContext3D(); |
| 103 GraphicsContext3D* contextSupport = webglContext->graphicsContext3D(); |
106 | 104 |
107 // This is called after we make sure GL_EXT_draw_buffers is supported. | 105 // This is called after we make sure GL_EXT_draw_buffers is supported. |
108 GLint maxDrawBuffers = 0; | 106 GLint maxDrawBuffers = 0; |
109 GLint maxColorAttachments = 0; | 107 GLint maxColorAttachments = 0; |
110 context->getIntegerv(Extensions3D::MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); | 108 context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); |
111 context->getIntegerv(Extensions3D::MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttac
hments); | 109 context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments); |
112 if (maxDrawBuffers < 4 || maxColorAttachments < 4) | 110 if (maxDrawBuffers < 4 || maxColorAttachments < 4) |
113 return false; | 111 return false; |
114 | 112 |
115 Platform3DObject fbo = context->createFramebuffer(); | 113 Platform3DObject fbo = context->createFramebuffer(); |
116 context->bindFramebuffer(GL_FRAMEBUFFER, fbo); | 114 context->bindFramebuffer(GL_FRAMEBUFFER, fbo); |
117 | 115 |
118 const unsigned char* buffer = 0; // Chromium doesn't allow init data for dep
th/stencil tetxures. | 116 const unsigned char* buffer = 0; // Chromium doesn't allow init data for dep
th/stencil tetxures. |
119 bool supportsDepth = (context->extensions()->supports("GL_CHROMIUM_depth_tex
ture") | 117 bool supportsDepth = (contextSupport->supportsExtension("GL_CHROMIUM_depth_t
exture") |
120 || context->extensions()->supports("GL_OES_depth_texture") | 118 || contextSupport->supportsExtension("GL_OES_depth_texture") |
121 || context->extensions()->supports("GL_ARB_depth_texture")); | 119 || contextSupport->supportsExtension("GL_ARB_depth_texture")); |
122 bool supportsDepthStencil = (context->extensions()->supports("GL_EXT_packed_
depth_stencil") | 120 bool supportsDepthStencil = (contextSupport->supportsExtension("GL_EXT_packe
d_depth_stencil") |
123 || context->extensions()->supports("GL_OES_packed_depth_stencil")); | 121 || contextSupport->supportsExtension("GL_OES_packed_depth_stencil")); |
124 Platform3DObject depthStencil = 0; | 122 Platform3DObject depthStencil = 0; |
125 if (supportsDepthStencil) { | 123 if (supportsDepthStencil) { |
126 depthStencil = context->createTexture(); | 124 depthStencil = context->createTexture(); |
127 context->bindTexture(GL_TEXTURE_2D, depthStencil); | 125 context->bindTexture(GL_TEXTURE_2D, depthStencil); |
128 context->texImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, 1, 1, 0, GL_
DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, buffer); | 126 context->texImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, 1, 1, 0, GL_
DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, buffer); |
129 } | 127 } |
130 Platform3DObject depth = 0; | 128 Platform3DObject depth = 0; |
131 if (supportsDepth) { | 129 if (supportsDepth) { |
132 depth = context->createTexture(); | 130 depth = context->createTexture(); |
133 context->bindTexture(GL_TEXTURE_2D, depth); | 131 context->bindTexture(GL_TEXTURE_2D, depth); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 if (supportsDepth) | 171 if (supportsDepth) |
174 context->deleteTexture(depth); | 172 context->deleteTexture(depth); |
175 if (supportsDepthStencil) | 173 if (supportsDepthStencil) |
176 context->deleteTexture(depthStencil); | 174 context->deleteTexture(depthStencil); |
177 for (size_t i = 0; i < colors.size(); ++i) | 175 for (size_t i = 0; i < colors.size(); ++i) |
178 context->deleteTexture(colors[i]); | 176 context->deleteTexture(colors[i]); |
179 return ok; | 177 return ok; |
180 } | 178 } |
181 | 179 |
182 } // namespace WebCore | 180 } // namespace WebCore |
OLD | NEW |