Line data Source code
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/. */
5 :
6 : #ifndef WEBGL_RENDERBUFFER_H_
7 : #define WEBGL_RENDERBUFFER_H_
8 :
9 : #include "mozilla/LinkedList.h"
10 : #include "nsWrapperCache.h"
11 :
12 : #include "WebGLFramebufferAttachable.h"
13 : #include "WebGLObjectModel.h"
14 : #include "WebGLStrongTypes.h"
15 :
16 : namespace mozilla {
17 : namespace webgl {
18 : struct FormatUsageInfo;
19 : }
20 :
21 : class WebGLRenderbuffer final
22 : : public nsWrapperCache
23 : , public WebGLRefCountedObject<WebGLRenderbuffer>
24 : , public LinkedListElement<WebGLRenderbuffer>
25 : , public WebGLRectangleObject
26 : , public WebGLFramebufferAttachable
27 : {
28 : friend class WebGLContext;
29 : friend class WebGLFramebuffer;
30 : friend class WebGLFBAttachPoint;
31 :
32 : public:
33 : const GLuint mPrimaryRB;
34 : protected:
35 : const bool mEmulatePackedDepthStencil;
36 : GLuint mSecondaryRB;
37 : const webgl::FormatUsageInfo* mFormat;
38 : GLsizei mSamples;
39 :
40 : WebGLImageDataStatus mImageDataStatus;
41 :
42 : bool mHasBeenBound;
43 :
44 : public:
45 0 : NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLRenderbuffer)
46 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLRenderbuffer)
47 :
48 : explicit WebGLRenderbuffer(WebGLContext* webgl);
49 :
50 : void Delete();
51 :
52 0 : bool HasUninitializedImageData() const {
53 0 : MOZ_ASSERT(mImageDataStatus != WebGLImageDataStatus::NoImageData);
54 0 : return mImageDataStatus == WebGLImageDataStatus::UninitializedImageData;
55 : }
56 :
57 0 : bool IsDefined() const {
58 0 : if (!mFormat) {
59 0 : MOZ_ASSERT(!mWidth && !mHeight);
60 0 : return false;
61 : }
62 0 : return true;
63 : }
64 :
65 0 : GLsizei Samples() const { return mSamples; }
66 :
67 0 : const webgl::FormatUsageInfo* Format() const { return mFormat; }
68 :
69 : int64_t MemoryUsage() const;
70 :
71 0 : WebGLContext* GetParentObject() const {
72 0 : return mContext;
73 : }
74 :
75 : void RenderbufferStorage(const char* funcName, uint32_t samples,
76 : GLenum internalFormat, uint32_t width, uint32_t height);
77 : // Only handles a subset of `pname`s.
78 : GLint GetRenderbufferParameter(RBTarget target, RBParam pname) const;
79 :
80 : virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
81 :
82 : protected:
83 0 : ~WebGLRenderbuffer() {
84 0 : DeleteOnce();
85 0 : }
86 :
87 : void DoFramebufferRenderbuffer(FBTarget target, GLenum attachment) const;
88 : GLenum DoRenderbufferStorage(uint32_t samples, const webgl::FormatUsageInfo* format,
89 : uint32_t width, uint32_t height);
90 : };
91 :
92 : } // namespace mozilla
93 :
94 : #endif // WEBGL_RENDERBUFFER_H_
|