| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 // 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. |
| 109 GLint maxDrawBuffers = 0; | 109 GLint maxDrawBuffers = 0; |
| 110 GLint maxColorAttachments = 0; | 110 GLint maxColorAttachments = 0; |
| 111 context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); | 111 context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers); |
| 112 context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments); | 112 context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAttachments); |
| 113 if (maxDrawBuffers < 4 || maxColorAttachments < 4) | 113 if (maxDrawBuffers < 4 || maxColorAttachments < 4) |
| 114 return false; | 114 return false; |
| 115 | 115 |
| 116 Platform3DObject fbo = context->createFramebuffer(); | 116 Platform3DObject fbo = context->createFramebuffer(); |
| 117 context->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 Platform3DObject depthStencil = 0; | 125 Platform3DObject depthStencil = 0; |
| 126 if (supportsDepthStencil) { | 126 if (supportsDepthStencil) { |
| 127 depthStencil = context->createTexture(); | 127 depthStencil = context->createTexture(); |
| 128 context->bindTexture(GL_TEXTURE_2D, depthStencil); | 128 gl->BindTexture(GL_TEXTURE_2D, depthStencil); |
| 129 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 context->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 Platform3DObject depth = 0; | 131 Platform3DObject depth = 0; |
| 132 if (supportsDepth) { | 132 if (supportsDepth) { |
| 133 depth = context->createTexture(); | 133 depth = context->createTexture(); |
| 134 context->bindTexture(GL_TEXTURE_2D, depth); | 134 gl->BindTexture(GL_TEXTURE_2D, depth); |
| 135 context->texImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, GL_DE
PTH_COMPONENT, GL_UNSIGNED_INT, buffer); | 135 context->texImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, GL_DE
PTH_COMPONENT, 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 Platform3DObject color = context->createTexture(); | 142 Platform3DObject color = context->createTexture(); |
| 143 colors.append(color); | 143 colors.append(color); |
| 144 context->bindTexture(GL_TEXTURE_2D, color); | 144 gl->BindTexture(GL_TEXTURE_2D, color); |
| 145 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); |
| 146 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); |
| 147 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_CO
MPLETE) { | 147 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLET
E) { |
| 148 ok = false; | 148 ok = false; |
| 149 break; | 149 break; |
| 150 } | 150 } |
| 151 if (supportsDepth) { | 151 if (supportsDepth) { |
| 152 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); |
| 153 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { | 153 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COM
PLETE) { |
| 154 ok = false; | 154 ok = false; |
| 155 break; | 155 break; |
| 156 } | 156 } |
| 157 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); |
| 158 } | 158 } |
| 159 if (supportsDepthStencil) { | 159 if (supportsDepthStencil) { |
| 160 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); |
| 161 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); |
| 162 if (context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFE
R_COMPLETE) { | 162 if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COM
PLETE) { |
| 163 ok = false; | 163 ok = false; |
| 164 break; | 164 break; |
| 165 } | 165 } |
| 166 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); |
| 167 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); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 webglContext->restoreCurrentFramebuffer(); | 171 webglContext->restoreCurrentFramebuffer(); |
| 172 context->deleteFramebuffer(fbo); | 172 context->deleteFramebuffer(fbo); |
| 173 webglContext->restoreCurrentTexture2D(); | 173 webglContext->restoreCurrentTexture2D(); |
| 174 if (supportsDepth) | 174 if (supportsDepth) |
| 175 context->deleteTexture(depth); | 175 context->deleteTexture(depth); |
| 176 if (supportsDepthStencil) | 176 if (supportsDepthStencil) |
| 177 context->deleteTexture(depthStencil); | 177 context->deleteTexture(depthStencil); |
| 178 for (size_t i = 0; i < colors.size(); ++i) | 178 for (size_t i = 0; i < colors.size(); ++i) |
| 179 context->deleteTexture(colors[i]); | 179 context->deleteTexture(colors[i]); |
| 180 return ok; | 180 return ok; |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |