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<RenderbufferID>, 65 public egl::ImageSibling, 66 public LabeledObject 67 { 68 public: 69 Renderbuffer(rx::GLImplFactory *implFactory, RenderbufferID id); 70 ~Renderbuffer() override; 71 72 void onDestroy(const Context *context) override; 73 74 void setLabel(const Context *context, const std::string &label) override; 75 const std::string &getLabel() const override; 76 77 angle::Result setStorage(const Context *context, 78 GLenum internalformat, 79 size_t width, 80 size_t height); 81 angle::Result setStorageMultisample(const Context *context, 82 size_t samples, 83 GLenum internalformat, 84 size_t width, 85 size_t height); 86 angle::Result setStorageEGLImageTarget(const Context *context, egl::Image *imageTarget); 87 88 rx::RenderbufferImpl *getImplementation() const; 89 90 GLsizei getWidth() const; 91 GLsizei getHeight() const; 92 const Format &getFormat() const; 93 GLsizei getSamples() const; 94 GLuint getRedSize() const; 95 GLuint getGreenSize() const; 96 GLuint getBlueSize() const; 97 GLuint getAlphaSize() const; 98 GLuint getDepthSize() const; 99 GLuint getStencilSize() const; 100 101 GLint getMemorySize() const; 102 103 // FramebufferAttachmentObject Impl 104 Extents getAttachmentSize(const ImageIndex &imageIndex) const override; 105 Format getAttachmentFormat(GLenum binding, const ImageIndex &imageIndex) const override; 106 GLsizei getAttachmentSamples(const ImageIndex &imageIndex) const override; 107 bool isRenderable(const Context *context, 108 GLenum binding, 109 const ImageIndex &imageIndex) const override; 110 111 void onAttach(const Context *context) override; 112 void onDetach(const Context *context) override; 113 GLuint getId() const override; 114 115 InitState initState(const ImageIndex &imageIndex) const override; 116 void setInitState(const ImageIndex &imageIndex, InitState initState) override; 117 118 GLenum getImplementationColorReadFormat(const Context *context) const; 119 GLenum getImplementationColorReadType(const Context *context) const; 120 121 // We pass the pack buffer and state explicitly so they can be overridden during capture. 122 angle::Result getRenderbufferImage(const Context *context, 123 const PixelPackState &packState, 124 Buffer *packBuffer, 125 GLenum format, 126 GLenum type, 127 void *pixels) const; 128 129 private: 130 rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override; 131 132 RenderbufferState mState; 133 std::unique_ptr<rx::RenderbufferImpl> mImplementation; 134 135 std::string mLabel; 136 }; 137 138 } // namespace gl 139 140 #endif // LIBANGLE_RENDERBUFFER_H_ 141