Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WEBGLFRAMEBUFFER_H_
7 #define WEBGLFRAMEBUFFER_H_
9 #include "WebGLObjectModel.h"
11 #include "nsWrapperCache.h"
13 #include "mozilla/LinkedList.h"
15 namespace mozilla {
17 class WebGLFramebufferAttachable;
18 class WebGLTexture;
19 class WebGLRenderbuffer;
20 namespace gl {
21 class GLContext;
22 }
24 class WebGLFramebuffer MOZ_FINAL
25 : public nsWrapperCache
26 , public WebGLRefCountedObject<WebGLFramebuffer>
27 , public LinkedListElement<WebGLFramebuffer>
28 , public WebGLContextBoundObject
29 {
30 public:
31 WebGLFramebuffer(WebGLContext* context);
33 ~WebGLFramebuffer() {
34 DeleteOnce();
35 }
37 struct Attachment
38 {
39 // deleting a texture or renderbuffer immediately detaches it
40 WebGLRefPtr<WebGLTexture> mTexturePtr;
41 WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
42 GLenum mAttachmentPoint;
43 GLenum mTexImageTarget;
44 GLint mTexImageLevel;
45 mutable bool mNeedsFinalize;
47 Attachment(GLenum aAttachmentPoint = LOCAL_GL_COLOR_ATTACHMENT0)
48 : mAttachmentPoint(aAttachmentPoint)
49 , mNeedsFinalize(false)
50 {}
52 bool IsDefined() const {
53 return Texture() || Renderbuffer();
54 }
56 bool IsDeleteRequested() const;
58 bool HasAlpha() const;
59 bool IsReadableFloat() const;
61 void SetTexImage(WebGLTexture* tex, GLenum target, GLint level);
62 void SetRenderbuffer(WebGLRenderbuffer* rb);
64 const WebGLTexture* Texture() const {
65 return mTexturePtr;
66 }
67 WebGLTexture* Texture() {
68 return mTexturePtr;
69 }
70 const WebGLRenderbuffer* Renderbuffer() const {
71 return mRenderbufferPtr;
72 }
73 WebGLRenderbuffer* Renderbuffer() {
74 return mRenderbufferPtr;
75 }
76 GLenum TexImageTarget() const {
77 return mTexImageTarget;
78 }
79 GLint TexImageLevel() const {
80 return mTexImageLevel;
81 }
83 bool HasUninitializedImageData() const;
84 void SetImageDataStatus(WebGLImageDataStatus x);
86 void Reset() {
87 mTexturePtr = nullptr;
88 mRenderbufferPtr = nullptr;
89 }
91 const WebGLRectangleObject& RectangleObject() const;
93 bool HasImage() const;
94 bool IsComplete() const;
96 void FinalizeAttachment(gl::GLContext* gl, GLenum attachmentLoc) const;
97 };
99 void Delete();
101 bool HasEverBeenBound() { return mHasEverBeenBound; }
102 void SetHasEverBeenBound(bool x) { mHasEverBeenBound = x; }
103 GLuint GLName() { return mGLName; }
105 void FramebufferRenderbuffer(GLenum target,
106 GLenum attachment,
107 GLenum rbtarget,
108 WebGLRenderbuffer* wrb);
110 void FramebufferTexture2D(GLenum target,
111 GLenum attachment,
112 GLenum textarget,
113 WebGLTexture* wtex,
114 GLint level);
116 private:
117 void DetachAttachment(WebGLFramebuffer::Attachment& attachment);
118 void DetachAllAttachments();
119 const WebGLRectangleObject& GetAnyRectObject() const;
120 Attachment* GetAttachmentOrNull(GLenum attachment);
122 public:
123 bool HasDefinedAttachments() const;
124 bool HasIncompleteAttachments() const;
125 bool AllImageRectsMatch() const;
126 GLenum PrecheckFramebufferStatus() const;
127 GLenum CheckFramebufferStatus() const;
129 bool HasDepthStencilConflict() const {
130 return int(mDepthAttachment.IsDefined()) +
131 int(mStencilAttachment.IsDefined()) +
132 int(mDepthStencilAttachment.IsDefined()) >= 2;
133 }
135 size_t ColorAttachmentCount() const {
136 return mColorAttachments.Length();
137 }
138 const Attachment& ColorAttachment(size_t colorAttachmentId) const {
139 return mColorAttachments[colorAttachmentId];
140 }
142 const Attachment& DepthAttachment() const {
143 return mDepthAttachment;
144 }
146 const Attachment& StencilAttachment() const {
147 return mStencilAttachment;
148 }
150 const Attachment& DepthStencilAttachment() const {
151 return mDepthStencilAttachment;
152 }
154 const Attachment& GetAttachment(GLenum attachment) const;
156 void DetachTexture(const WebGLTexture* tex);
158 void DetachRenderbuffer(const WebGLRenderbuffer* rb);
160 const WebGLRectangleObject& RectangleObject() const;
162 WebGLContext* GetParentObject() const {
163 return Context();
164 }
166 void FinalizeAttachments() const;
168 virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
170 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer)
171 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer)
173 // mask mirrors glClear.
174 bool HasCompletePlanes(GLbitfield mask);
176 bool CheckAndInitializeAttachments();
178 bool CheckColorAttachmentNumber(GLenum attachment, const char* functionName) const;
180 void EnsureColorAttachments(size_t colorAttachmentId);
182 Attachment* AttachmentFor(GLenum attachment);
183 void NotifyAttachableChanged() const;
185 private:
186 mutable GLenum mStatus;
188 GLuint mGLName;
189 bool mHasEverBeenBound;
191 // we only store pointers to attached renderbuffers, not to attached textures, because
192 // we will only need to initialize renderbuffers. Textures are already initialized.
193 nsTArray<Attachment> mColorAttachments;
194 Attachment mDepthAttachment,
195 mStencilAttachment,
196 mDepthStencilAttachment;
197 };
199 } // namespace mozilla
201 #endif