| 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 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 scoped.context()->m_framebufferBinding->drawBuffers(buffers); | 97 scoped.context()->m_framebufferBinding->drawBuffers(buffers); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 // static | 101 // static |
| 102 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContextBase* web
glContext) | 102 bool WebGLDrawBuffers::satisfiesWebGLRequirements(WebGLRenderingContextBase* web
glContext) |
| 103 { | 103 { |
| 104 WebGraphicsContext3D* context = webglContext->webContext(); |
| 104 gpu::gles2::GLES2Interface* gl = webglContext->contextGL(); | 105 gpu::gles2::GLES2Interface* gl = webglContext->contextGL(); |
| 105 Extensions3DUtil* extensionsUtil = webglContext->extensionsUtil(); | 106 Extensions3DUtil* extensionsUtil = webglContext->extensionsUtil(); |
| 106 | 107 |
| 107 // 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. |
| 108 GLint maxDrawBuffers = 0; | 109 GLint maxDrawBuffers = 0; |
| 109 GLint maxColorAttachments = 0; | 110 GLint maxColorAttachments = 0; |
| 110 gl->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); | 111 gl->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); |
| 111 gl->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments); | 112 gl->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments); |
| 112 if (maxDrawBuffers < 4 || maxColorAttachments < 4) | 113 if (maxDrawBuffers < 4 || maxColorAttachments < 4) |
| 113 return false; | 114 return false; |
| 114 | 115 |
| 115 GLuint fbo; | 116 Platform3DObject fbo = context->createFramebuffer(); |
| 116 gl->GenFramebuffers(1, &fbo); | |
| 117 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); | 117 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 118 | 118 |
| 119 const unsigned char* buffer = 0; // Chromium doesn't allow init data for dep
th/stencil tetxures. | 119 const unsigned char* buffer = 0; // Chromium doesn't allow init data for dep
th/stencil tetxures. |
| 120 bool supportsDepth = (extensionsUtil->supportsExtension("GL_CHROMIUM_depth_t
exture") | 120 bool supportsDepth = (extensionsUtil->supportsExtension("GL_CHROMIUM_depth_t
exture") |
| 121 || extensionsUtil->supportsExtension("GL_OES_depth_texture") | 121 || extensionsUtil->supportsExtension("GL_OES_depth_texture") |
| 122 || extensionsUtil->supportsExtension("GL_ARB_depth_texture")); | 122 || extensionsUtil->supportsExtension("GL_ARB_depth_texture")); |
| 123 bool supportsDepthStencil = (extensionsUtil->supportsExtension("GL_EXT_packe
d_depth_stencil") | 123 bool supportsDepthStencil = (extensionsUtil->supportsExtension("GL_EXT_packe
d_depth_stencil") |
| 124 || extensionsUtil->supportsExtension("GL_OES_packed_depth_stencil")); | 124 || extensionsUtil->supportsExtension("GL_OES_packed_depth_stencil")); |
| 125 GLuint depthStencil = 0; | 125 Platform3DObject depthStencil = 0; |
| 126 if (supportsDepthStencil) { | 126 if (supportsDepthStencil) { |
| 127 gl->GenTextures(1, &depthStencil); | 127 depthStencil = context->createTexture(); |
| 128 gl->BindTexture(GL_TEXTURE_2D, depthStencil); | 128 gl->BindTexture(GL_TEXTURE_2D, depthStencil); |
| 129 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, 1, 1, 0, GL_DEPTH
_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, buffer); | 129 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, 1, 1, 0, GL_DEPTH
_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, buffer); |
| 130 } | 130 } |
| 131 GLuint depth = 0; | 131 Platform3DObject depth = 0; |
| 132 if (supportsDepth) { | 132 if (supportsDepth) { |
| 133 gl->GenTextures(1, &depth); | 133 depth = context->createTexture(); |
| 134 gl->BindTexture(GL_TEXTURE_2D, depth); | 134 gl->BindTexture(GL_TEXTURE_2D, depth); |
| 135 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, GL_DEPTH_C
OMPONENT, GL_UNSIGNED_INT, buffer); | 135 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, GL_DEPTH_C
OMPONENT, GL_UNSIGNED_INT, buffer); |
| 136 } | 136 } |
| 137 | 137 |
| 138 Vector<Platform3DObject> colors; | 138 Vector<Platform3DObject> colors; |
| 139 bool ok = true; | 139 bool ok = true; |
| 140 GLint maxAllowedBuffers = std::min(maxDrawBuffers, maxColorAttachments); | 140 GLint maxAllowedBuffers = std::min(maxDrawBuffers, maxColorAttachments); |
| 141 for (GLint i = 0; i < maxAllowedBuffers; ++i) { | 141 for (GLint i = 0; i < maxAllowedBuffers; ++i) { |
| 142 GLuint color; | 142 Platform3DObject color = context->createTexture(); |
| 143 gl->GenTextures(1, &color); | |
| 144 colors.append(color); | 143 colors.append(color); |
| 145 gl->BindTexture(GL_TEXTURE_2D, color); | 144 gl->BindTexture(GL_TEXTURE_2D, color); |
| 146 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_
BYTE, buffer); | 145 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_
BYTE, buffer); |
| 147 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TE
XTURE_2D, color, 0); | 146 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TE
XTURE_2D, color, 0); |
| 148 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLET
E) { | 147 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLET
E) { |
| 149 ok = false; | 148 ok = false; |
| 150 break; | 149 break; |
| 151 } | 150 } |
| 152 if (supportsDepth) { | 151 if (supportsDepth) { |
| 153 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, depth, 0); | 152 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, depth, 0); |
| 154 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COM
PLETE) { | 153 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COM
PLETE) { |
| 155 ok = false; | 154 ok = false; |
| 156 break; | 155 break; |
| 157 } | 156 } |
| 158 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, 0, 0); | 157 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, 0, 0); |
| 159 } | 158 } |
| 160 if (supportsDepthStencil) { | 159 if (supportsDepthStencil) { |
| 161 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, depthStencil, 0); | 160 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, depthStencil, 0); |
| 162 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_T
EXTURE_2D, depthStencil, 0); | 161 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_T
EXTURE_2D, depthStencil, 0); |
| 163 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COM
PLETE) { | 162 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COM
PLETE) { |
| 164 ok = false; | 163 ok = false; |
| 165 break; | 164 break; |
| 166 } | 165 } |
| 167 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, 0, 0); | 166 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEX
TURE_2D, 0, 0); |
| 168 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_T
EXTURE_2D, 0, 0); | 167 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_T
EXTURE_2D, 0, 0); |
| 169 } | 168 } |
| 170 } | 169 } |
| 171 | 170 |
| 172 webglContext->restoreCurrentFramebuffer(); | 171 webglContext->restoreCurrentFramebuffer(); |
| 173 gl->DeleteFramebuffers(1, &fbo); | 172 context->deleteFramebuffer(fbo); |
| 174 webglContext->restoreCurrentTexture2D(); | 173 webglContext->restoreCurrentTexture2D(); |
| 175 if (supportsDepth) | 174 if (supportsDepth) |
| 176 gl->DeleteTextures(1, &depth); | 175 context->deleteTexture(depth); |
| 177 if (supportsDepthStencil) | 176 if (supportsDepthStencil) |
| 178 gl->DeleteTextures(1, &depthStencil); | 177 context->deleteTexture(depthStencil); |
| 179 gl->DeleteTextures(colors.size(), colors.data()); | 178 for (size_t i = 0; i < colors.size(); ++i) |
| 179 context->deleteTexture(colors[i]); |
| 180 return ok; | 180 return ok; |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |