xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/FramebufferGL.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2015 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 // FramebufferGL.h: Defines the class interface for FramebufferGL.
8 
9 #ifndef LIBANGLE_RENDERER_GL_FRAMEBUFFERGL_H_
10 #define LIBANGLE_RENDERER_GL_FRAMEBUFFERGL_H_
11 
12 #include "libANGLE/Context.h"
13 #include "libANGLE/renderer/FramebufferImpl.h"
14 
15 namespace rx
16 {
17 
18 class BlitGL;
19 class ClearMultiviewGL;
20 class FunctionsGL;
21 class StateManagerGL;
22 
23 class FramebufferGL : public FramebufferImpl
24 {
25   public:
26     FramebufferGL(const gl::FramebufferState &data, GLuint id, bool emulatedAlpha);
27     ~FramebufferGL() override;
28 
29     void destroy(const gl::Context *context) override;
30 
31     angle::Result discard(const gl::Context *context,
32                           size_t count,
33                           const GLenum *attachments) override;
34     angle::Result invalidate(const gl::Context *context,
35                              size_t count,
36                              const GLenum *attachments) override;
37     angle::Result invalidateSub(const gl::Context *context,
38                                 size_t count,
39                                 const GLenum *attachments,
40                                 const gl::Rectangle &area) override;
41 
42     angle::Result clear(const gl::Context *context, GLbitfield mask) override;
43     angle::Result clearBufferfv(const gl::Context *context,
44                                 GLenum buffer,
45                                 GLint drawbuffer,
46                                 const GLfloat *values) override;
47     angle::Result clearBufferuiv(const gl::Context *context,
48                                  GLenum buffer,
49                                  GLint drawbuffer,
50                                  const GLuint *values) override;
51     angle::Result clearBufferiv(const gl::Context *context,
52                                 GLenum buffer,
53                                 GLint drawbuffer,
54                                 const GLint *values) override;
55     angle::Result clearBufferfi(const gl::Context *context,
56                                 GLenum buffer,
57                                 GLint drawbuffer,
58                                 GLfloat depth,
59                                 GLint stencil) override;
60 
61     angle::Result readPixels(const gl::Context *context,
62                              const gl::Rectangle &area,
63                              GLenum format,
64                              GLenum type,
65                              const gl::PixelPackState &pack,
66                              gl::Buffer *packBuffer,
67                              void *pixels) override;
68 
69     angle::Result blit(const gl::Context *context,
70                        const gl::Rectangle &sourceArea,
71                        const gl::Rectangle &destArea,
72                        GLbitfield mask,
73                        GLenum filter) override;
74 
75     angle::Result getSamplePosition(const gl::Context *context,
76                                     size_t index,
77                                     GLfloat *xy) const override;
78 
79     // The GL back-end requires a full sync state before we call checkStatus.
80     bool shouldSyncStateBeforeCheckStatus() const override;
81 
82     gl::FramebufferStatus checkStatus(const gl::Context *context) const override;
83 
84     angle::Result ensureAttachmentsInitialized(const gl::Context *context,
85                                                const gl::DrawBufferMask &colorAttachments,
86                                                bool depth,
87                                                bool stencil) override;
88 
89     angle::Result syncState(const gl::Context *context,
90                             GLenum binding,
91                             const gl::Framebuffer::DirtyBits &dirtyBits,
92                             gl::Command command) override;
93 
94     void updateDefaultFramebufferID(GLuint framebufferID);
isDefault()95     bool isDefault() const { return mState.isDefault(); }
96 
setHasEmulatedAlphaAttachment(bool hasEmulatedAlphaAttachment)97     void setHasEmulatedAlphaAttachment(bool hasEmulatedAlphaAttachment)
98     {
99         mHasEmulatedAlphaAttachment = hasEmulatedAlphaAttachment;
100     }
101     bool hasEmulatedAlphaChannelTextureAttachment() const;
102 
setFramebufferID(GLuint id)103     void setFramebufferID(GLuint id) { mFramebufferID = id; }
getFramebufferID()104     GLuint getFramebufferID() const { return mFramebufferID; }
105 
106   private:
107     void syncClearState(const gl::Context *context, GLbitfield mask);
108     void syncClearBufferState(const gl::Context *context, GLenum buffer, GLint drawBuffer);
109 
110     bool modifyInvalidateAttachmentsForEmulatedDefaultFBO(
111         size_t count,
112         const GLenum *attachments,
113         std::vector<GLenum> *modifiedAttachments) const;
114 
115     angle::Result readPixelsRowByRow(const gl::Context *context,
116                                      const gl::Rectangle &area,
117                                      GLenum originalReadFormat,
118                                      GLenum format,
119                                      GLenum type,
120                                      const gl::PixelPackState &pack,
121                                      GLubyte *pixels) const;
122 
123     angle::Result readPixelsAllAtOnce(const gl::Context *context,
124                                       const gl::Rectangle &area,
125                                       GLenum originalReadFormat,
126                                       GLenum format,
127                                       GLenum type,
128                                       const gl::PixelPackState &pack,
129                                       GLubyte *pixels,
130                                       bool readLastRowSeparately) const;
131 
132     void maskOutInactiveOutputDrawBuffersImpl(const gl::Context *context,
133                                               gl::DrawBufferMask targetAppliedDrawBuffers);
134 
135     angle::Result adjustSrcDstRegion(const gl::Context *context,
136                                      const gl::Rectangle &sourceArea,
137                                      const gl::Rectangle &destArea,
138                                      gl::Rectangle *newSourceArea,
139                                      gl::Rectangle *newDestArea);
140 
141     angle::Result clipSrcRegion(const gl::Context *context,
142                                 const gl::Rectangle &sourceArea,
143                                 const gl::Rectangle &destArea,
144                                 gl::Rectangle *newSourceArea,
145                                 gl::Rectangle *newDestArea);
146 
147     GLuint mFramebufferID;
148     bool mHasEmulatedAlphaAttachment;
149     gl::DrawBufferMask mAppliedEnabledDrawBuffers;
150 };
151 }  // namespace rx
152 
153 #endif  // LIBANGLE_RENDERER_GL_FRAMEBUFFERGL_H_
154