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 "modules/webgl/WebGLDrawBuffers.h" | 26 #include "modules/webgl/WebGLDrawBuffers.h" |
27 | 27 |
| 28 #include "gpu/command_buffer/client/gles2_interface.h" |
28 #include "modules/webgl/WebGLFramebuffer.h" | 29 #include "modules/webgl/WebGLFramebuffer.h" |
29 | 30 |
30 namespace blink { | 31 namespace blink { |
31 | 32 |
32 WebGLDrawBuffers::WebGLDrawBuffers(WebGLRenderingContextBase* context) | 33 WebGLDrawBuffers::WebGLDrawBuffers(WebGLRenderingContextBase* context) |
33 : WebGLExtension(context) | 34 : WebGLExtension(context) |
34 { | 35 { |
35 context->extensionsUtil()->ensureExtensionEnabled("GL_EXT_draw_buffers"); | 36 context->extensionsUtil()->ensureExtensionEnabled("GL_EXT_draw_buffers"); |
36 } | 37 } |
37 | 38 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 95 } |
95 } | 96 } |
96 scoped.context()->m_framebufferBinding->drawBuffers(buffers); | 97 scoped.context()->m_framebufferBinding->drawBuffers(buffers); |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 // static | 101 // static |
101 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContextBase* web
glContext) | 102 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContextBase* web
glContext) |
102 { | 103 { |
103 WebGraphicsContext3D* context = webglContext->webContext(); | 104 WebGraphicsContext3D* context = webglContext->webContext(); |
| 105 gpu::gles2::GLES2Interface* gl = webglContext->contextGL(); |
104 Extensions3DUtil* extensionsUtil = webglContext->extensionsUtil(); | 106 Extensions3DUtil* extensionsUtil = webglContext->extensionsUtil(); |
105 | 107 |
106 // This is called after we make sure GL_EXT_draw_buffers is supported. | 108 // This is called after we make sure GL_EXT_draw_buffers is supported. |
107 GLint maxDrawBuffers = 0; | 109 GLint maxDrawBuffers = 0; |
108 GLint maxColorAttachments = 0; | 110 GLint maxColorAttachments = 0; |
109 context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); | 111 context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); |
110 context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments); | 112 context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments); |
111 if (maxDrawBuffers < 4 || maxColorAttachments < 4) | 113 if (maxDrawBuffers < 4 || maxColorAttachments < 4) |
112 return false; | 114 return false; |
113 | 115 |
(...skipping 20 matching lines...) Expand all Loading... |
134 } | 136 } |
135 | 137 |
136 Vector<Platform3DObject> colors; | 138 Vector<Platform3DObject> colors; |
137 bool ok = true; | 139 bool ok = true; |
138 GLint maxAllowedBuffers = std::min(maxDrawBuffers, maxColorAttachments); | 140 GLint maxAllowedBuffers = std::min(maxDrawBuffers, maxColorAttachments); |
139 for (GLint i = 0; i < maxAllowedBuffers; ++i) { | 141 for (GLint i = 0; i < maxAllowedBuffers; ++i) { |
140 Platform3DObject color = context->createTexture(); | 142 Platform3DObject color = context->createTexture(); |
141 colors.append(color); | 143 colors.append(color); |
142 context->bindTexture(GL_TEXTURE_2D, color); | 144 context->bindTexture(GL_TEXTURE_2D, color); |
143 context->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSI
GNED_BYTE, buffer); | 145 context->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSI
GNED_BYTE, buffer); |
144 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
GL_TEXTURE_2D, color, 0); | 146 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TE
XTURE_2D, color, 0); |
145 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_CO
MPLETE) { | 147 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_CO
MPLETE) { |
146 ok = false; | 148 ok = false; |
147 break; | 149 break; |
148 } | 150 } |
149 if (supportsDepth) { | 151 if (supportsDepth) { |
150 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, depth, 0); | 152 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, depth, 0); |
151 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { | 153 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { |
152 ok = false; | 154 ok = false; |
153 break; | 155 break; |
154 } | 156 } |
155 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, 0, 0); | 157 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, 0, 0); |
156 } | 158 } |
157 if (supportsDepthStencil) { | 159 if (supportsDepthStencil) { |
158 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, depthStencil, 0); | 160 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, depthStencil, 0); |
159 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, depthStencil, 0); | 161 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_T
EXTURE_2D, depthStencil, 0); |
160 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { | 162 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { |
161 ok = false; | 163 ok = false; |
162 break; | 164 break; |
163 } | 165 } |
164 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, G
L_TEXTURE_2D, 0, 0); | 166 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, 0, 0); |
165 context->framebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, 0, 0); | 167 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_T
EXTURE_2D, 0, 0); |
166 } | 168 } |
167 } | 169 } |
168 | 170 |
169 webglContext->restoreCurrentFramebuffer(); | 171 webglContext->restoreCurrentFramebuffer(); |
170 context->deleteFramebuffer(fbo); | 172 context->deleteFramebuffer(fbo); |
171 webglContext->restoreCurrentTexture2D(); | 173 webglContext->restoreCurrentTexture2D(); |
172 if (supportsDepth) | 174 if (supportsDepth) |
173 context->deleteTexture(depth); | 175 context->deleteTexture(depth); |
174 if (supportsDepthStencil) | 176 if (supportsDepthStencil) |
175 context->deleteTexture(depthStencil); | 177 context->deleteTexture(depthStencil); |
176 for (size_t i = 0; i < colors.size(); ++i) | 178 for (size_t i = 0; i < colors.size(); ++i) |
177 context->deleteTexture(colors[i]); | 179 context->deleteTexture(colors[i]); |
178 return ok; | 180 return ok; |
179 } | 181 } |
180 | 182 |
181 } // namespace blink | 183 } // namespace blink |
OLD | NEW |