1 //
2 // Copyright 2014 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 // FramebufferD3D.h: Defines the DefaultAttachmentD3D and FramebufferD3D classes.
8 
9 #ifndef LIBANGLE_RENDERER_D3D_FRAMBUFFERD3D_H_
10 #define LIBANGLE_RENDERER_D3D_FRAMBUFFERD3D_H_
11 
12 #include <cstdint>
13 #include <vector>
14 
15 #include "common/Color.h"
16 #include "common/Optional.h"
17 #include "libANGLE/angletypes.h"
18 #include "libANGLE/renderer/FramebufferImpl.h"
19 
20 namespace gl
21 {
22 class FramebufferAttachment;
23 struct PixelPackState;
24 
25 typedef std::vector<const FramebufferAttachment *> AttachmentList;
26 }  // namespace gl
27 
28 namespace rx
29 {
30 class RendererD3D;
31 class RenderTargetD3D;
32 
33 struct ClearParameters
34 {
35     ClearParameters();
36     ClearParameters(const ClearParameters &other);
37 
38     gl::DrawBufferMask clearColor;
39     gl::ColorF colorF;
40     gl::ColorI colorI;
41     gl::ColorUI colorUI;
42     GLenum colorType;
43     gl::BlendStateExt::ColorMaskStorage::Type colorMask;
44 
45     bool clearDepth;
46     float depthValue;
47 
48     bool clearStencil;
49     GLint stencilValue;
50     GLuint stencilWriteMask;
51 
52     bool scissorEnabled;
53     gl::Rectangle scissor;
54 };
55 
56 class FramebufferD3D : public FramebufferImpl
57 {
58   public:
59     FramebufferD3D(const gl::FramebufferState &data, RendererD3D *renderer);
60     ~FramebufferD3D() override;
61 
62     angle::Result clear(const gl::Context *context, GLbitfield mask) override;
63     angle::Result clearBufferfv(const gl::Context *context,
64                                 GLenum buffer,
65                                 GLint drawbuffer,
66                                 const GLfloat *values) override;
67     angle::Result clearBufferuiv(const gl::Context *context,
68                                  GLenum buffer,
69                                  GLint drawbuffer,
70                                  const GLuint *values) override;
71     angle::Result clearBufferiv(const gl::Context *context,
72                                 GLenum buffer,
73                                 GLint drawbuffer,
74                                 const GLint *values) override;
75     angle::Result clearBufferfi(const gl::Context *context,
76                                 GLenum buffer,
77                                 GLint drawbuffer,
78                                 GLfloat depth,
79                                 GLint stencil) override;
80 
81     angle::Result readPixels(const gl::Context *context,
82                              const gl::Rectangle &area,
83                              GLenum format,
84                              GLenum type,
85                              const gl::PixelPackState &pack,
86                              gl::Buffer *packBuffer,
87                              void *pixels) override;
88 
89     angle::Result blit(const gl::Context *context,
90                        const gl::Rectangle &sourceArea,
91                        const gl::Rectangle &destArea,
92                        GLbitfield mask,
93                        GLenum filter) override;
94 
95     gl::FramebufferStatus checkStatus(const gl::Context *context) const override;
96 
97     angle::Result syncState(const gl::Context *context,
98                             GLenum binding,
99                             const gl::Framebuffer::DirtyBits &dirtyBits,
100                             gl::Command command) override;
101 
102     const gl::AttachmentList &getColorAttachmentsForRender(const gl::Context *context);
103 
getLastColorAttachmentsForRenderMask()104     const gl::DrawBufferMask getLastColorAttachmentsForRenderMask() const
105     {
106         return mColorAttachmentsForRenderMask;
107     }
108 
109     void destroy(const gl::Context *context) override;
110 
111   private:
112     virtual angle::Result clearImpl(const gl::Context *context,
113                                     const ClearParameters &clearParams) = 0;
114 
115     virtual angle::Result readPixelsImpl(const gl::Context *context,
116                                          const gl::Rectangle &area,
117                                          GLenum format,
118                                          GLenum type,
119                                          size_t outputPitch,
120                                          const gl::PixelPackState &pack,
121                                          gl::Buffer *packBuffer,
122                                          uint8_t *pixels) = 0;
123 
124     virtual angle::Result blitImpl(const gl::Context *context,
125                                    const gl::Rectangle &sourceArea,
126                                    const gl::Rectangle &destArea,
127                                    const gl::Rectangle *scissor,
128                                    bool blitRenderTarget,
129                                    bool blitDepth,
130                                    bool blitStencil,
131                                    GLenum filter,
132                                    const gl::Framebuffer *sourceFramebuffer) = 0;
133 
134     RendererD3D *mRenderer;
135     Optional<gl::AttachmentList> mColorAttachmentsForRender;
136     gl::DrawBufferMask mCurrentActiveProgramOutputs;
137     gl::DrawBufferMask mColorAttachmentsForRenderMask;
138 
139     gl::FramebufferAttachment mMockAttachment;
140 };
141 }  // namespace rx
142 
143 #endif  // LIBANGLE_RENDERER_D3D_FRAMBUFFERD3D_H_
144