Changeset 56074 in webkit
- Timestamp:
- Mar 16, 2010 11:53:34 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r56073 r56074 1 2010-03-16 Zhenyao Mo <zmo@google.com> 2 3 Reviewed by Darin Fisher. 4 5 Hook up WebGLContextAttributes to OpenGL context creation code 6 https://bugs.webkit.org/show_bug.cgi?id=33416 7 8 * fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias-expected.txt: Added. 9 * fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias.html: Added. 10 * fast/canvas/webgl/context-attributes-expected.txt: WebGL context attributes behavior changed with this fix. 11 * fast/canvas/webgl/context-attributes.html: Ditto. 12 * fast/canvas/webgl/gl-get-calls-expected.txt: Stencil buffer is enabled, thus Stencil Bits is no longer 0. 13 * fast/canvas/webgl/gl-get-calls.html: Ditto. 14 1 15 2010-03-16 Joanmarie Diggs <joanmarie.diggs@gmail.com> 2 16 -
trunk/LayoutTests/fast/canvas/webgl/context-attributes-expected.txt
r53238 r56074 8 8 PASS attribs.depth is true 9 9 PASS attribs.alpha is true 10 PASS (attribs.stencil == true || attribs.stencil == false)is true11 PASS (attribs.antialias == true || attribs.antialias == false)is true10 PASS attribs.stencil is true 11 PASS attribs.antialias is true 12 12 PASS attribs.premultipliedAlpha is true 13 13 Test customized values … … 19 19 PASS attribs.antialias is false 20 20 PASS attribs.premultipliedAlpha is true 21 Test customized values 22 PASS context = create3DContext({ depth: false, stencil: true }) is non-null. 23 PASS attribs = context.getContextAttributes() is non-null. 24 PASS attribs.depth is true 25 PASS attribs.alpha is true 26 PASS attribs.stencil is true 27 PASS attribs.antialias is true 28 PASS attribs.premultipliedAlpha is true 29 Test customized values 30 PASS context = create3DContext({ premultipliedAlpha: false }) is non-null. 31 PASS attribs = context.getContextAttributes() is non-null. 32 PASS attribs.depth is true 33 PASS attribs.alpha is true 34 PASS attribs.stencil is true 35 PASS attribs.antialias is true 36 PASS attribs.premultipliedAlpha is true 21 37 PASS successfullyParsed is true 22 38 -
trunk/LayoutTests/fast/canvas/webgl/context-attributes.html
r53238 r56074 19 19 shouldBe("attribs.depth", "true"); 20 20 shouldBe("attribs.alpha", "true"); 21 // The following two depend on whether the implementation actually supports them 22 shouldBe("(attribs.stencil == true || attribs.stencil == false)", "true"); 23 shouldBe("(attribs.antialias == true || attribs.antialias == false)", "true"); 21 shouldBe("attribs.stencil", "true"); 22 shouldBe("attribs.antialias", "true"); 24 23 shouldBe("attribs.premultipliedAlpha", "true"); 25 24 … … 33 32 shouldBe("attribs.premultipliedAlpha", "true"); 34 33 34 debug("Test customized values"); 35 // (stencil == true && depth == false) is not supported, default depth to true 36 shouldBeNonNull("context = create3DContext({ depth: false, stencil: true })"); 37 shouldBeNonNull("attribs = context.getContextAttributes()"); 38 shouldBe("attribs.depth", "true"); 39 shouldBe("attribs.alpha", "true"); 40 shouldBe("attribs.stencil", "true"); 41 shouldBe("attribs.antialias", "true"); 42 shouldBe("attribs.premultipliedAlpha", "true"); 43 44 debug("Test customized values"); 45 // (premultipliedAlpha == false) is not supported, default to true 46 shouldBeNonNull("context = create3DContext({ premultipliedAlpha: false })"); 47 shouldBeNonNull("attribs = context.getContextAttributes()"); 48 shouldBe("attribs.depth", "true"); 49 shouldBe("attribs.alpha", "true"); 50 shouldBe("attribs.stencil", "true"); 51 shouldBe("attribs.antialias", "true"); 52 shouldBe("attribs.premultipliedAlpha", "true"); 53 35 54 successfullyParsed = true; 36 55 </script> -
trunk/LayoutTests/fast/canvas/webgl/gl-get-calls-expected.txt
r55282 r56074 54 54 PASS context.getParameter(context.STENCIL_BACK_PASS_DEPTH_PASS) is context.KEEP 55 55 PASS context.getParameter(context.STENCIL_BACK_REF) is 0 56 PASS context.getParameter(context.STENCIL_BITS) is 056 PASS context.getParameter(context.STENCIL_BITS) > 0 is true 57 57 PASS context.getParameter(context.STENCIL_CLEAR_VALUE) is 0 58 58 PASS context.getParameter(context.STENCIL_FAIL) is context.KEEP -
trunk/LayoutTests/fast/canvas/webgl/gl-get-calls.html
r55282 r56074 83 83 //shouldBe('context.getParameter(context.STENCIL_BACK_VALUE_MASK)', '0xFFFFFFFF'); 84 84 //shouldBe('context.getParameter(context.STENCIL_BACK_WRITEMASK)', '0xFFFFFFFF'); 85 shouldBe('context.getParameter(context.STENCIL_BITS) ', '0');85 shouldBe('context.getParameter(context.STENCIL_BITS) > 0', 'true'); 86 86 shouldBe('context.getParameter(context.STENCIL_CLEAR_VALUE)', '0'); 87 87 shouldBe('context.getParameter(context.STENCIL_FAIL)', 'context.KEEP'); -
trunk/WebCore/ChangeLog
r56073 r56074 1 2010-03-16 Zhenyao Mo <zmo@google.com> 2 3 Reviewed by Darin Fisher. 4 5 Hook up WebGLContextAttributes to OpenGL context creation code 6 https://bugs.webkit.org/show_bug.cgi?id=33416 7 8 Test: fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias.html 9 10 * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp: Fix an index bug. 11 * platform/graphics/GraphicsContext3D.h: Add members/functions for multisampling/stencil buffer purpose. 12 * platform/graphics/mac/Canvas3DLayer.h: Add GraphicsContext3D as a member of Canvas3DLayer. 13 * platform/graphics/mac/Canvas3DLayer.mm: Add multisampling support. 14 * platform/graphics/mac/GraphicsContext3DMac.cpp: Hook up WebGLContextAttributes to OpenGL context creation code for Mac. 15 * platform/graphics/mac/GraphicsLayerCA.mm: Adjust to modified Canvas3DLayer init call. 16 1 17 2010-03-16 Joanmarie Diggs <joanmarie.diggs@gmail.com> 2 18 -
trunk/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
r55854 r56074 57 57 attrs = WebGLContextAttributes::create(); 58 58 WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get()); 59 if (args.Length() > 1 && args[ 0]->IsObject()) {59 if (args.Length() > 1 && args[1]->IsObject()) { 60 60 v8::Handle<v8::Object> jsAttrs = args[1]->ToObject(); 61 61 v8::Handle<v8::String> alpha = v8::String::New("alpha"); -
trunk/WebCore/platform/graphics/GraphicsContext3D.h
r55283 r56074 426 426 #endif 427 427 void makeContextCurrent(); 428 428 429 #if PLATFORM(MAC) 430 // With multisampling on, blit from multisampleFBO to regular FBO. 431 void prepareTexture(); 432 #endif 433 429 434 // Helper to return the size in bytes of OpenGL data types 430 435 // like GL_FLOAT, GL_INT, etc. … … 718 723 GLuint m_texture; 719 724 GLuint m_fbo; 720 GLuint m_depthBuffer; 725 GLuint m_depthStencilBuffer; 726 727 // For tracking which FBO is bound 728 GLuint m_boundFBO; 729 730 // For multisampling 731 GLuint m_multisampleFBO; 732 GLuint m_multisampleDepthStencilBuffer; 733 GLuint m_multisampleColorBuffer; 734 721 735 // Errors raised by synthesizeGLError(). 722 736 ListHashSet<unsigned long> m_syntheticErrors; -
trunk/WebCore/platform/graphics/mac/Canvas3DLayer.h
r50067 r56074 33 33 namespace WebCore { 34 34 class GraphicsLayer; 35 class GraphicsContext3D; 35 36 } 36 37 … … 38 39 { 39 40 WebCore::GraphicsLayer* m_layerOwner; 41 WebCore::GraphicsContext3D* m_context; 40 42 CGLContextObj m_contextObj; 41 43 GLuint m_texture; 42 44 } 43 45 44 - (id)initWithContext:( CGLContextObj)context texture:(GLuint)texture;46 - (id)initWithContext:(WebCore::GraphicsContext3D*)context; 45 47 46 48 - (CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace; -
trunk/WebCore/platform/graphics/mac/Canvas3DLayer.mm
r53510 r56074 42 42 @implementation Canvas3DLayer 43 43 44 -(id)initWithContext:( CGLContextObj)context texture:(GLuint)texture44 -(id)initWithContext:(GraphicsContext3D*)context 45 45 { 46 m_contextObj = context; 47 m_texture = texture; 46 m_context = context; 47 m_contextObj = static_cast<CGLContextObj>(context->platformGraphicsContext3D()); 48 m_texture = static_cast<GLuint>(context->platformTexture()); 48 49 self = [super init]; 49 50 return self; … … 71 72 -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp 72 73 { 73 CGLSetCurrentContext(m_contextObj);74 glFinish(); 74 m_context->prepareTexture(); 75 75 76 CGLSetCurrentContext(glContext); 76 77 -
trunk/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
r54907 r56074 87 87 , m_texture(0) 88 88 , m_fbo(0) 89 , m_depthBuffer(0) 90 { 91 // FIXME: we need to take into account the user's requested 92 // context creation attributes, in particular stencil and 93 // antialias, and determine which could and could not be honored 94 // based on the capabilities of the OpenGL implementation. 95 m_attrs.alpha = true; 96 m_attrs.depth = true; 97 m_attrs.stencil = false; 98 m_attrs.antialias = false; 89 , m_depthStencilBuffer(0) 90 , m_boundFBO(0) 91 , m_multisampleFBO(0) 92 , m_multisampleDepthStencilBuffer(0) 93 , m_multisampleColorBuffer(0) 94 { 95 // Take into account the user's requested context creation attributes, in 96 // particular stencil and antialias, and determine which could and could 97 // not be honored based on the capabilities of the OpenGL implementation. 98 if (m_attrs.stencil && !m_attrs.depth) 99 m_attrs.depth = true; 100 // FIXME: instead of enforcing premultipliedAlpha = true, implement the 101 // correct behavior when premultipliedAlpha = false is requested. 99 102 m_attrs.premultipliedAlpha = true; 100 103 … … 153 156 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 154 157 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 155 ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);156 158 ::glBindTexture(GL_TEXTURE_2D, 0); 157 159 158 160 // create an FBO 159 161 ::glGenFramebuffersEXT(1, &m_fbo); 160 162 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 161 162 ::glGenRenderbuffersEXT(1, &m_depthBuffer); 163 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer); 164 ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, 1, 1); 165 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 166 167 ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0); 168 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer); 169 163 m_boundFBO = m_fbo; 164 if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) 165 ::glGenRenderbuffersEXT(1, &m_depthStencilBuffer); 166 167 // create an multisample FBO 168 if (m_attrs.antialias) { 169 ::glGenFramebuffersEXT(1, &m_multisampleFBO); 170 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO); 171 m_boundFBO = m_multisampleFBO; 172 ::glGenRenderbuffersEXT(1, &m_multisampleColorBuffer); 173 if (m_attrs.stencil || m_attrs.depth) 174 ::glGenRenderbuffersEXT(1, &m_multisampleDepthStencilBuffer); 175 } 176 170 177 ::glClearColor(0, 0, 0, 0); 171 178 } … … 175 182 if (m_contextObj) { 176 183 CGLSetCurrentContext(m_contextObj); 177 ::glDeleteRenderbuffersEXT(1, & m_depthBuffer);178 184 ::glDeleteTextures(1, &m_texture); 185 if (m_attrs.antialias) { 186 ::glDeleteRenderbuffersEXT(1, &m_multisampleColorBuffer); 187 if (m_attrs.stencil || m_attrs.depth) 188 ::glDeleteRenderbuffersEXT(1, &m_multisampleDepthStencilBuffer); 189 ::glDeleteFramebuffersEXT(1, &m_multisampleFBO); 190 } else { 191 if (m_attrs.stencil || m_attrs.depth) 192 ::glDeleteRenderbuffersEXT(1, &m_depthStencilBuffer); 193 } 179 194 ::glDeleteFramebuffersEXT(1, &m_fbo); 180 195 CGLSetCurrentContext(0); … … 206 221 207 222 CGLSetCurrentContext(m_contextObj); 208 223 224 GLuint internalColorFormat, colorFormat, internalDepthStencilFormat = 0; 225 if (m_attrs.alpha) { 226 internalColorFormat = GL_RGBA8; 227 colorFormat = GL_RGBA; 228 } else { 229 internalColorFormat = GL_RGB8; 230 colorFormat = GL_RGB; 231 } 232 if (m_attrs.stencil || m_attrs.depth) { 233 // We don't allow the logic where stencil is required and depth is not. 234 // See GraphicsContext3D constructor. 235 if (m_attrs.stencil && m_attrs.depth) 236 internalDepthStencilFormat = GL_DEPTH24_STENCIL8_EXT; 237 else 238 internalDepthStencilFormat = GL_DEPTH_COMPONENT; 239 } 240 241 bool mustRestoreFBO = false; 242 243 // resize multisample FBO 244 if (m_attrs.antialias) { 245 GLint maxSampleCount; 246 ::glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSampleCount); 247 GLint sampleCount = std::min(8, maxSampleCount); 248 if (sampleCount > maxSampleCount) 249 sampleCount = maxSampleCount; 250 if (m_boundFBO != m_multisampleFBO) { 251 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO); 252 mustRestoreFBO = true; 253 } 254 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_multisampleColorBuffer); 255 ::glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleCount, internalColorFormat, width, height); 256 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, m_multisampleColorBuffer); 257 if (m_attrs.stencil || m_attrs.depth) { 258 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer); 259 ::glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleCount, internalDepthStencilFormat, width, height); 260 if (m_attrs.stencil) 261 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer); 262 if (m_attrs.depth) 263 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer); 264 } 265 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 266 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) { 267 // FIXME: cleanup. 268 notImplemented(); 269 } 270 } 271 272 // resize regular FBO 273 if (m_boundFBO != m_fbo) { 274 mustRestoreFBO = true; 275 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 276 } 209 277 ::glBindTexture(GL_TEXTURE_2D, m_texture); 210 ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); 278 ::glTexImage2D(GL_TEXTURE_2D, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0); 279 ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0); 211 280 ::glBindTexture(GL_TEXTURE_2D, 0); 212 213 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);214 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer);215 ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);216 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);217 218 ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0);219 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer);220 GLenum status = ::glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);221 if ( status!= GL_FRAMEBUFFER_COMPLETE_EXT) {222 // FIXME: cleanup 281 if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) { 282 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthStencilBuffer); 283 ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalDepthStencilFormat, width, height); 284 if (m_attrs.stencil) 285 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer); 286 if (m_attrs.depth) 287 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer); 288 ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 289 } 290 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) { 291 // FIXME: cleanup. 223 292 notImplemented(); 224 293 } 225 294 226 ::glClear(GL_COLOR_BUFFER_BIT); 295 if (mustRestoreFBO) 296 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO); 297 298 GLenum clearMask = GL_COLOR_BUFFER_BIT; 299 if (m_attrs.depth) 300 clearMask |= GL_DEPTH_BUFFER_BIT; 301 if (m_attrs.stencil) 302 clearMask |= GL_STENCIL_BUFFER_BIT; 303 ::glClear(clearMask); 227 304 ::glFlush(); 228 305 } … … 244 321 } 245 322 323 void GraphicsContext3D::prepareTexture() 324 { 325 if (m_attrs.antialias) { 326 ensureContext(m_contextObj); 327 ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); 328 ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo); 329 ::glBlitFramebufferEXT(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); 330 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO); 331 ::glFinish(); 332 } 333 } 334 246 335 void GraphicsContext3D::attachShader(WebGLProgram* program, WebGLShader* shader) 247 336 { … … 269 358 { 270 359 ensureContext(m_contextObj); 271 ::glBindFramebufferEXT(target, (buffer && buffer->object()) ? (GLuint) buffer->object() : m_fbo); 360 GLuint fbo; 361 if (buffer && buffer->object()) 362 fbo = (GLuint)buffer->object(); 363 else 364 fbo = (m_attrs.antialias ? m_multisampleFBO : m_fbo); 365 if (fbo != m_boundFBO) { 366 ::glBindFramebufferEXT(target, fbo); 367 m_boundFBO = fbo; 368 } 272 369 } 273 370 … … 676 773 if (type != GL_UNSIGNED_BYTE || format != GL_RGBA) 677 774 return 0; 678 775 776 if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) { 777 ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); 778 ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo); 779 ::glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR); 780 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 781 } 679 782 RefPtr<WebGLUnsignedByteArray> array = WebGLUnsignedByteArray::create(width * height * 4); 680 783 ::glReadPixels(x, y, width, height, format, type, (GLvoid*) array->data()); 784 if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) 785 ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO); 786 if (!m_attrs.alpha) { 787 // If alpha is off, by default glReadPixels should set the alpha to 255 instead of 0. 788 // This is a hack until ::glReadPixels fixes its behavior. 789 GLubyte* data = reinterpret_cast<GLubyte*>(array->data()); 790 unsigned byteLength = array->byteLength(); 791 for (unsigned i = 3; i < byteLength; i += 4) 792 data[i] = 255; 793 } 681 794 return array; 682 795 } -
trunk/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
r55601 r56074 1717 1717 if (m_platformGraphicsContext3D != NullPlatformGraphicsContext3D && m_platformTexture != NullPlatform3DObject) { 1718 1718 // create the inner 3d layer 1719 m_contentsLayer.adoptNS([[Canvas3DLayer alloc] initWithContext: static_cast<CGLContextObj>(m_platformGraphicsContext3D) texture:static_cast<GLuint>(m_platformTexture)]);1719 m_contentsLayer.adoptNS([[Canvas3DLayer alloc] initWithContext:const_cast<GraphicsContext3D*>(graphicsContext3D)]); 1720 1720 #ifndef NDEBUG 1721 1721 [m_contentsLayer.get() setName:@"3D Layer"]; -
trunk/WebKit/chromium/ChangeLog
r56070 r56074 1 2010-03-16 Zhenyao Mo <zmo@google.com> 2 3 Reviewed by Darin Fisher. 4 5 Hook up WebGLContextAttributes to OpenGL context creation code 6 https://bugs.webkit.org/show_bug.cgi?id=33416 7 8 Test: fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias.html 9 10 * src/GraphicsContext3D.cpp: Hook up WebGLContextAttributes to OpenGL context creation code for Windows. 11 1 12 2010-03-16 Yury Semikhatsky <yurys@chromium.org> 2 13 -
trunk/WebKit/chromium/src/GraphicsContext3D.cpp
r54907 r56074 125 125 void viewportImpl(long x, long y, unsigned long width, unsigned long height); 126 126 127 void readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* buffer); 128 127 129 void synthesizeGLError(unsigned long error); 128 130 129 131 private: 130 132 GraphicsContext3D::Attributes m_attrs; 131 133 132 134 unsigned int m_texture; 133 135 unsigned int m_fbo; 134 unsigned int m_depth Buffer;136 unsigned int m_depthStencilBuffer; 135 137 unsigned int m_cachedWidth, m_cachedHeight; 138 139 // For multisampling 140 unsigned int m_multisampleFBO; 141 unsigned int m_multisampleDepthStencilBuffer; 142 unsigned int m_multisampleColorBuffer; 136 143 137 144 // For tracking which FBO is bound … … 352 359 , m_texture(0) 353 360 , m_fbo(0) 354 , m_depthBuffer(0) 361 , m_depthStencilBuffer(0) 362 , m_multisampleFBO(0) 363 , m_multisampleDepthStencilBuffer(0) 364 , m_multisampleColorBuffer(0) 355 365 , m_boundFBO(0) 356 366 #ifdef FLIP_FRAMEBUFFER_VERTICALLY … … 376 386 #endif 377 387 { 378 // FIXME: we need to take into account the user's requested 379 // context creation attributes, in particular stencil and 380 // antialias, and determine which could and could not be honored 381 // based on the capabilities of the OpenGL implementation. 382 m_attrs.alpha = true; 383 m_attrs.depth = true; 384 m_attrs.stencil = false; 385 m_attrs.antialias = false; 388 // Take into account the user's requested context creation attributes, in 389 // particular stencil and antialias, and determine which could and could 390 // not be honored based on the capabilities of the OpenGL implementation. 391 if (m_attrs.stencil) { 392 if (GLEW_EXT_packed_depth_stencil) { 393 if (!m_attrs.depth) 394 m_attrs.depth = true; 395 } else { 396 m_attrs.stencil = false; 397 } 398 } 399 if (m_attrs.antialias && !GLEW_EXT_framebuffer_multisample) 400 m_attrs.antialias = false; 401 // FIXME: instead of enforcing premultipliedAlpha = true, implement the 402 // correct behavior when premultipliedAlpha = false is requested. 386 403 m_attrs.premultipliedAlpha = true; 387 404 … … 573 590 makeContextCurrent(); 574 591 #ifndef RENDER_TO_DEBUGGING_WINDOW 575 glDeleteRenderbuffersEXT(1, &m_depthBuffer); 592 if (m_attrs.antialias) { 593 glDeleteRenderbuffersEXT(1, &m_multisampleColorBuffer); 594 if (m_attrs.depth || m_attrs.stencil) 595 glDeleteRenderbuffersEXT(1, &m_multisampleDepthStencilBuffer); 596 glDeleteFramebuffersEXT(1, &m_multisampleFBO); 597 } else { 598 if (m_attrs.depth || m_attrs.stencil) 599 glDeleteRenderbuffersEXT(1, &m_depthStencilBuffer); 600 } 576 601 glDeleteTextures(1, &m_texture); 577 602 #ifdef FLIP_FRAMEBUFFER_VERTICALLY … … 670 695 // Generate the framebuffer object 671 696 glGenFramebuffersEXT(1, &m_fbo); 672 // Generate the depth buffer 673 glGenRenderbuffersEXT(1, &m_depthBuffer); 674 } 675 676 // Reallocate the color and depth buffers 697 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 698 m_boundFBO = m_fbo; 699 if (m_attrs.depth || m_attrs.stencil) 700 glGenRenderbuffersEXT(1, &m_depthStencilBuffer); 701 // Generate the multisample framebuffer object 702 if (m_attrs.antialias) { 703 glGenFramebuffersEXT(1, &m_multisampleFBO); 704 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO); 705 m_boundFBO = m_multisampleFBO; 706 glGenRenderbuffersEXT(1, &m_multisampleColorBuffer); 707 if (m_attrs.depth || m_attrs.stencil) 708 glGenRenderbuffersEXT(1, &m_multisampleDepthStencilBuffer); 709 } 710 } 711 712 GLint internalColorFormat, colorFormat, internalDepthStencilFormat; 713 if (m_attrs.alpha) { 714 internalColorFormat = GL_RGBA8; 715 colorFormat = GL_RGBA; 716 } else { 717 internalColorFormat = GL_RGB8; 718 colorFormat = GL_RGB; 719 } 720 if (m_attrs.stencil || m_attrs.depth) { 721 // We don't allow the logic where stencil is required and depth is not. 722 // See GraphicsContext3DInternal constructor. 723 if (m_attrs.stencil && m_attrs.depth) 724 internalDepthStencilFormat = GL_DEPTH24_STENCIL8_EXT; 725 else 726 internalDepthStencilFormat = GL_DEPTH_COMPONENT; 727 } 728 729 bool mustRestoreFBO = false; 730 731 // Resize multisampling FBO 732 if (m_attrs.antialias) { 733 GLint maxSampleCount; 734 glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSampleCount); 735 GLint sampleCount = std::min(8, maxSampleCount); 736 if (m_boundFBO != m_multisampleFBO) { 737 mustRestoreFBO = true; 738 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO); 739 } 740 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_multisampleColorBuffer); 741 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleCount, internalColorFormat, width, height); 742 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, m_multisampleColorBuffer); 743 if (m_attrs.stencil || m_attrs.depth) { 744 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer); 745 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleCount, internalDepthStencilFormat, width, height); 746 if (m_attrs.stencil) 747 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer); 748 if (m_attrs.depth) 749 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer); 750 } 751 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 752 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 753 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { 754 printf("GraphicsContext3D: multisampling framebuffer was incomplete\n"); 755 756 // FIXME: cleanup. 757 notImplemented(); 758 } 759 } 760 761 // Resize regular FBO 762 if (m_boundFBO != m_fbo) { 763 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 764 mustRestoreFBO = true; 765 } 677 766 glBindTexture(target, m_texture); 678 glTexImage2D(target, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); 767 glTexImage2D(target, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0); 768 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, m_texture, 0); 679 769 glBindTexture(target, 0); 680 681 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);682 m_boundFBO = m_fbo;683 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer);684 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);685 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);686 687 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, m_texture, 0);688 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer);770 if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) { 771 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthStencilBuffer); 772 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalDepthStencilFormat, width, height); 773 if (m_attrs.stencil) 774 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer); 775 if (m_attrs.depth) 776 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer); 777 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 778 } 689 779 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 690 780 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { … … 694 784 notImplemented(); 695 785 } 786 787 if (mustRestoreFBO) 788 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO); 696 789 #endif // RENDER_TO_DEBUGGING_WINDOW 697 790 … … 704 797 #endif // FLIP_FRAMEBUFFER_VERTICALLY 705 798 706 glClear(GL_COLOR_BUFFER_BIT); 799 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; 800 if (m_attrs.stencil) 801 clearMask |= GL_STENCIL_BUFFER_BIT; 802 if (m_attrs.depth) 803 clearMask |= GL_DEPTH_BUFFER_BIT; 804 glClear(clearMask); 707 805 708 806 #if PLATFORM(CG) … … 759 857 ImageBuffer* imageBuffer = canvas->buffer(); 760 858 unsigned char* pixels = 0; 761 bool mustRestoreFBO = (m_boundFBO != m_fbo); 762 if (mustRestoreFBO) 859 bool mustRestoreFBO; 860 if (m_attrs.antialias) { 861 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); 862 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo); 863 glBlitFramebufferEXT(0, 0, m_cachedWidth, m_cachedHeight, 0, 0, m_cachedWidth, m_cachedHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); 763 864 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 865 mustRestoreFBO = true; 866 } else { 867 if (m_boundFBO != m_fbo) { 868 mustRestoreFBO = true; 869 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 870 } 871 } 764 872 #if PLATFORM(SKIA) 765 873 const SkBitmap* canvasBitmap = imageBuffer->context()->platformContext()->bitmap(); … … 866 974 } 867 975 976 void GraphicsContext3DInternal::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* buffer) 977 { 978 #ifndef RENDER_TO_DEBUGGING_WINDOW 979 if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) { 980 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); 981 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo); 982 glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR); 983 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 984 } 985 #endif 986 glReadPixels(x, y, width, height, format, type, buffer); 987 #ifndef RENDER_TO_DEBUGGING_WINDOW 988 if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) 989 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO); 990 #endif 991 } 992 868 993 void GraphicsContext3DInternal::activeTexture(unsigned long texture) 869 994 { … … 893 1018 GLuint id = EXTRACT(framebuffer); 894 1019 if (!id) 895 id = m_fbo; 896 glBindFramebufferEXT(target, id); 897 m_boundFBO = id; 1020 id = (m_attrs.antialias ? m_multisampleFBO : m_fbo); 1021 if (id != m_boundFBO) { 1022 glBindFramebufferEXT(target, id); 1023 m_boundFBO = id; 1024 } 898 1025 } 899 1026 … … 1810 1937 // FIXME: take into account pack alignment. 1811 1938 RefPtr<WebGLUnsignedByteArray> array = WebGLUnsignedByteArray::create(width * height * 4); 1812 glReadPixels(x, y, width, height, format, type, array->baseAddress()); 1939 m_internal->readPixels(x, y, width, height, format, type, array->baseAddress()); 1940 #if OS(DARWIN) 1941 GraphicsContext3D::Attributes attrs = m_internal->getContextAttributes(); 1942 if (!attrs.alpha) { 1943 // If alpha is off, by default glReadPixels should set the alpha to 255 instead of 0. 1944 // This is a hack until ::glReadPixels fixes its behavior. 1945 GLubyte* data = reinterpret_cast<GLubyte*>(array->baseAddress()); 1946 unsigned byteLength = array->byteLength(); 1947 for (unsigned i = 3; i < byteLength; i += 4) 1948 data[i] = 255; 1949 } 1950 #endif 1813 1951 return array; 1814 1952 }
Note: See TracChangeset
for help on using the changeset viewer.