• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // Renderbuffer.h: Defines the renderer-agnostic container class gl::Renderbuffer.
8 // Implements GL renderbuffer objects and related functionality.
9 // [OpenGL ES 2.0.24] section 4.4.3 page 108.
10 
11 #ifndef LIBANGLE_RENDERBUFFER_H_
12 #define LIBANGLE_RENDERBUFFER_H_
13 
14 #include "angle_gl.h"
15 #include "common/angleutils.h"
16 #include "libANGLE/Debug.h"
17 #include "libANGLE/Error.h"
18 #include "libANGLE/FramebufferAttachment.h"
19 #include "libANGLE/Image.h"
20 #include "libANGLE/formatutils.h"
21 #include "libANGLE/renderer/RenderbufferImpl.h"
22 
23 namespace rx
24 {
25 class GLImplFactory;
26 }  // namespace rx
27 
28 namespace gl
29 {
30 // A GL renderbuffer object is usually used as a depth or stencil buffer attachment
31 // for a framebuffer object. The renderbuffer itself is a distinct GL object, see
32 // FramebufferAttachment and Framebuffer for how they are applied to an FBO via an
33 // attachment point.
34 
35 class RenderbufferState final : angle::NonCopyable
36 {
37   public:
38     RenderbufferState();
39     ~RenderbufferState();
40 
41     GLsizei getWidth() const;
42     GLsizei getHeight() const;
43     const Format &getFormat() const;
44     GLsizei getSamples() const;
45 
46   private:
47     friend class Renderbuffer;
48 
49     void update(GLsizei width,
50                 GLsizei height,
51                 const Format &format,
52                 GLsizei samples,
53                 InitState initState);
54 
55     GLsizei mWidth;
56     GLsizei mHeight;
57     Format mFormat;
58     GLsizei mSamples;
59 
60     // For robust resource init.
61     InitState mInitState;
62 };
63 
64 class Renderbuffer final : public RefCountObject, public egl::ImageSibling, public LabeledObject
65 {
66   public:
67     Renderbuffer(rx::GLImplFactory *implFactory, RenderbufferID id);
68     ~Renderbuffer() override;
69 
70     void onDestroy(const Context *context) override;
71 
72     void setLabel(const Context *context, const std::string &label) override;
73     const std::string &getLabel() const override;
74 
75     angle::Result setStorage(const Context *context,
76                              GLenum internalformat,
77                              size_t width,
78                              size_t height);
79     angle::Result setStorageMultisample(const Context *context,
80                                         size_t samples,
81                                         GLenum internalformat,
82                                         size_t width,
83                                         size_t height);
84     angle::Result setStorageEGLImageTarget(const Context *context, egl::Image *imageTarget);
85 
86     rx::RenderbufferImpl *getImplementation() const;
87 
88     GLsizei getWidth() const;
89     GLsizei getHeight() const;
90     const Format &getFormat() const;
91     GLsizei getSamples() const;
92     GLuint getRedSize() const;
93     GLuint getGreenSize() const;
94     GLuint getBlueSize() const;
95     GLuint getAlphaSize() const;
96     GLuint getDepthSize() const;
97     GLuint getStencilSize() const;
98 
99     GLint getMemorySize() const;
100 
101     // FramebufferAttachmentObject Impl
102     Extents getAttachmentSize(const ImageIndex &imageIndex) const override;
103     Format getAttachmentFormat(GLenum binding, const ImageIndex &imageIndex) const override;
104     GLsizei getAttachmentSamples(const ImageIndex &imageIndex) const override;
105     bool isRenderable(const Context *context,
106                       GLenum binding,
107                       const ImageIndex &imageIndex) const override;
108 
109     void onAttach(const Context *context) override;
110     void onDetach(const Context *context) override;
111     GLuint getId() const override;
112 
113     InitState initState(const ImageIndex &imageIndex) const override;
114     void setInitState(const ImageIndex &imageIndex, InitState initState) override;
115 
116   private:
117     rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override;
118 
119     RenderbufferState mState;
120     std::unique_ptr<rx::RenderbufferImpl> mImplementation;
121 
122     std::string mLabel;
123 };
124 
125 }  // namespace gl
126 
127 #endif  // LIBANGLE_RENDERBUFFER_H_
128