/src/3rdparty/webkit/Source/WebCore/html/canvas/WebGLFramebuffer.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 99 lines · 43 code · 23 blank · 33 comment · 5 complexity · 07232a76b168e52b0ba846bac386f2c3 MD5 · raw file

  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. #ifndef WebGLFramebuffer_h
  26. #define WebGLFramebuffer_h
  27. #include "WebGLObject.h"
  28. #include <wtf/PassRefPtr.h>
  29. #include <wtf/RefCounted.h>
  30. namespace WebCore {
  31. class WebGLRenderbuffer;
  32. class WebGLTexture;
  33. class WebGLFramebuffer : public WebGLObject {
  34. public:
  35. virtual ~WebGLFramebuffer() { deleteObject(); }
  36. static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*);
  37. void setAttachment(GC3Denum attachment, GC3Denum texTarget, WebGLTexture*, GC3Dint level);
  38. void setAttachment(GC3Denum attachment, WebGLRenderbuffer*);
  39. // If an object is attached to the framebuffer, remove it.
  40. void removeAttachment(WebGLObject*);
  41. WebGLObject* getAttachment(GC3Denum) const;
  42. GC3Denum getColorBufferFormat() const;
  43. GC3Dsizei getWidth() const;
  44. GC3Dsizei getHeight() const;
  45. // This should always be called before drawArray, drawElements, clear,
  46. // readPixels, copyTexImage2D, copyTexSubImage2D if this framebuffer is
  47. // currently bound.
  48. // Return false if the framebuffer is incomplete; otherwise initialize
  49. // the buffers if they haven't been initialized and
  50. // needToInitializeRenderbuffers is true.
  51. bool onAccess(bool needToInitializeRenderbuffers);
  52. // Return false does not mean COMPLETE, might still be INCOMPLETE.
  53. bool isIncomplete(bool checkInternalFormat) const;
  54. bool hasEverBeenBound() const { return object() && m_hasEverBeenBound; }
  55. void setHasEverBeenBound() { m_hasEverBeenBound = true; }
  56. protected:
  57. WebGLFramebuffer(WebGLRenderingContext*);
  58. virtual void deleteObjectImpl(Platform3DObject);
  59. private:
  60. virtual bool isFramebuffer() const { return true; }
  61. // Return false if framebuffer is incomplete.
  62. bool initializeRenderbuffers();
  63. bool isColorAttached() const { return (m_colorAttachment && m_colorAttachment->object()); }
  64. bool isDepthAttached() const { return (m_depthAttachment && m_depthAttachment->object()); }
  65. bool isStencilAttached() const { return (m_stencilAttachment && m_stencilAttachment->object()); }
  66. bool isDepthStencilAttached() const { return (m_depthStencilAttachment && m_depthStencilAttachment->object()); }
  67. RefPtr<WebGLObject> m_colorAttachment;
  68. RefPtr<WebGLObject> m_depthAttachment;
  69. RefPtr<WebGLObject> m_stencilAttachment;
  70. RefPtr<WebGLObject> m_depthStencilAttachment;
  71. bool m_hasEverBeenBound;
  72. GC3Denum m_texTarget;
  73. GC3Dint m_texLevel;
  74. };
  75. } // namespace WebCore
  76. #endif // WebGLFramebuffer_h