WebCore/html/canvas/WebGLFramebuffer.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2009 Apple Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  * 1. Redistributions of source code must retain the above copyright
       
     8  *    notice, this list of conditions and the following disclaimer.
       
     9  * 2. Redistributions in binary form must reproduce the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer in the
       
    11  *    documentation and/or other materials provided with the distribution.
       
    12  *
       
    13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
       
    14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
       
    17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
       
    21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
       
    24  */
       
    25 
       
    26 #ifndef WebGLFramebuffer_h
       
    27 #define WebGLFramebuffer_h
       
    28 
       
    29 #include "CanvasObject.h"
       
    30 
       
    31 #include <wtf/PassRefPtr.h>
       
    32 #include <wtf/RefCounted.h>
       
    33 
       
    34 namespace WebCore {
       
    35 
       
    36     class WebGLFramebuffer : public CanvasObject {
       
    37     public:
       
    38         virtual ~WebGLFramebuffer() { deleteObject(); }
       
    39         
       
    40         static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*);
       
    41 
       
    42         bool isDepthAttached() const { return (m_depthAttachment && m_depthAttachment->object()); }
       
    43         bool isStencilAttached() const { return (m_stencilAttachment && m_stencilAttachment->object()); }
       
    44         bool isDepthStencilAttached() const { return (m_depthStencilAttachment && m_depthStencilAttachment->object()); }
       
    45 
       
    46         void setAttachment(unsigned long, CanvasObject*);
       
    47 
       
    48         // This function is called right after a framebuffer is bound.
       
    49         // Because renderbuffers and textures attached to the framebuffer might
       
    50         // have changed and the framebuffer might have become complete when it
       
    51         // isn't bound, so we need to clear un-initialized renderbuffers.
       
    52         void onBind();
       
    53 
       
    54         // When a texture or a renderbuffer changes, we need to check the
       
    55         // current bound framebuffer; if the newly changed object is attached
       
    56         // to the framebuffer and the framebuffer becomes complete, we need to
       
    57         // clear un-initialized renderbuffers.
       
    58         void onAttachedObjectChange(CanvasObject*);
       
    59 
       
    60         unsigned long getColorBufferFormat();
       
    61 
       
    62     protected:
       
    63         WebGLFramebuffer(WebGLRenderingContext*);
       
    64         
       
    65         virtual void _deleteObject(Platform3DObject);
       
    66 
       
    67     private:
       
    68         virtual bool isFramebuffer() const { return true; }
       
    69 
       
    70         bool isUninitialized(CanvasObject*);
       
    71         void setInitialized(CanvasObject*);
       
    72         void initializeRenderbuffers();
       
    73 
       
    74         // These objects are kept alive by the global table in
       
    75         // WebGLRenderingContext.
       
    76         CanvasObject* m_colorAttachment;
       
    77         CanvasObject* m_depthAttachment;
       
    78         CanvasObject* m_stencilAttachment;
       
    79         CanvasObject* m_depthStencilAttachment;
       
    80     };
       
    81     
       
    82 } // namespace WebCore
       
    83 
       
    84 #endif // WebGLFramebuffer_h