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 MultisamplingMode getMultisamplingMode() const; 46 InitState getInitState() const; 47 48 private: 49 friend class Renderbuffer; 50 51 void update(GLsizei width, 52 GLsizei height, 53 const Format &format, 54 GLsizei samples, 55 MultisamplingMode multisamplingMode, 56 InitState initState); 57 58 GLsizei mWidth; 59 GLsizei mHeight; 60 Format mFormat; 61 GLsizei mSamples; 62 MultisamplingMode mMultisamplingMode; 63 64 // For robust resource init. 65 InitState mInitState; 66 }; 67 68 class Renderbuffer final : public RefCountObject<RenderbufferID>, 69 public egl::ImageSibling, 70 public LabeledObject 71 { 72 public: 73 Renderbuffer(rx::GLImplFactory *implFactory, RenderbufferID id); 74 ~Renderbuffer() override; 75 76 void onDestroy(const Context *context) override; 77 78 void setLabel(const Context *context, const std::string &label) override; 79 const std::string &getLabel() const override; 80 81 angle::Result setStorage(const Context *context, 82 GLenum internalformat, 83 GLsizei width, 84 GLsizei height); 85 angle::Result setStorageMultisample(const Context *context, 86 GLsizei samples, 87 GLenum internalformat, 88 GLsizei width, 89 GLsizei height, 90 MultisamplingMode mode); 91 angle::Result setStorageEGLImageTarget(const Context *context, egl::Image *imageTarget); 92 93 angle::Result copyRenderbufferSubData(Context *context, 94 const gl::Renderbuffer *srcBuffer, 95 GLint srcLevel, 96 GLint srcX, 97 GLint srcY, 98 GLint srcZ, 99 GLint dstLevel, 100 GLint dstX, 101 GLint dstY, 102 GLint dstZ, 103 GLsizei srcWidth, 104 GLsizei srcHeight, 105 GLsizei srcDepth); 106 107 angle::Result copyTextureSubData(Context *context, 108 const gl::Texture *srcTexture, 109 GLint srcLevel, 110 GLint srcX, 111 GLint srcY, 112 GLint srcZ, 113 GLint dstLevel, 114 GLint dstX, 115 GLint dstY, 116 GLint dstZ, 117 GLsizei srcWidth, 118 GLsizei srcHeight, 119 GLsizei srcDepth); 120 121 rx::RenderbufferImpl *getImplementation() const; 122 123 GLsizei getWidth() const; 124 GLsizei getHeight() const; 125 const Format &getFormat() const; 126 GLsizei getSamples() const; 127 MultisamplingMode getMultisamplingMode() const; 128 GLuint getRedSize() const; 129 GLuint getGreenSize() const; 130 GLuint getBlueSize() const; 131 GLuint getAlphaSize() const; 132 GLuint getDepthSize() const; 133 GLuint getStencilSize() const; 134 const RenderbufferState &getState() const; 135 136 GLint getMemorySize() const; 137 138 // FramebufferAttachmentObject Impl 139 Extents getAttachmentSize(const ImageIndex &imageIndex) const override; 140 Format getAttachmentFormat(GLenum binding, const ImageIndex &imageIndex) const override; 141 GLsizei getAttachmentSamples(const ImageIndex &imageIndex) const override; 142 bool isRenderable(const Context *context, 143 GLenum binding, 144 const ImageIndex &imageIndex) const override; 145 146 void onAttach(const Context *context, rx::Serial framebufferSerial) override; 147 void onDetach(const Context *context, rx::Serial framebufferSerial) override; 148 GLuint getId() const override; 149 150 InitState initState(const ImageIndex &imageIndex) const override; 151 void setInitState(const ImageIndex &imageIndex, InitState initState) override; 152 153 GLenum getImplementationColorReadFormat(const Context *context) const; 154 GLenum getImplementationColorReadType(const Context *context) const; 155 156 // We pass the pack buffer and state explicitly so they can be overridden during capture. 157 angle::Result getRenderbufferImage(const Context *context, 158 const PixelPackState &packState, 159 Buffer *packBuffer, 160 GLenum format, 161 GLenum type, 162 void *pixels) const; 163 164 private: 165 // ObserverInterface implementation. 166 void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override; 167 168 rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override; 169 170 RenderbufferState mState; 171 std::unique_ptr<rx::RenderbufferImpl> mImplementation; 172 173 std::string mLabel; 174 angle::ObserverBinding mImplObserverBinding; 175 }; 176 177 } // namespace gl 178 179 #endif // LIBANGLE_RENDERBUFFER_H_ 180