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