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 }
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     bool clearColor[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS];
39     gl::ColorF colorF;
40     gl::ColorI colorI;
41     gl::ColorUI colorUI;
42     GLenum colorType;
43     bool colorMaskRed;
44     bool colorMaskGreen;
45     bool colorMaskBlue;
46     bool colorMaskAlpha;
47 
48     bool clearDepth;
49     float depthValue;
50 
51     bool clearStencil;
52     GLint stencilValue;
53     GLuint stencilWriteMask;
54 
55     bool scissorEnabled;
56     gl::Rectangle scissor;
57 };
58 
59 class FramebufferD3D : public FramebufferImpl
60 {
61   public:
62     FramebufferD3D(const gl::FramebufferState &data, RendererD3D *renderer);
63     ~FramebufferD3D() override;
64 
65     gl::Error clear(const gl::Context *context, GLbitfield mask) override;
66     gl::Error clearBufferfv(const gl::Context *context,
67                             GLenum buffer,
68                             GLint drawbuffer,
69                             const GLfloat *values) override;
70     gl::Error clearBufferuiv(const gl::Context *context,
71                              GLenum buffer,
72                              GLint drawbuffer,
73                              const GLuint *values) override;
74     gl::Error clearBufferiv(const gl::Context *context,
75                             GLenum buffer,
76                             GLint drawbuffer,
77                             const GLint *values) override;
78     gl::Error clearBufferfi(const gl::Context *context,
79                             GLenum buffer,
80                             GLint drawbuffer,
81                             GLfloat depth,
82                             GLint stencil) override;
83 
84     GLenum getImplementationColorReadFormat(const gl::Context *context) const override;
85     GLenum getImplementationColorReadType(const gl::Context *context) const override;
86     gl::Error readPixels(const gl::Context *context,
87                          const gl::Rectangle &area,
88                          GLenum format,
89                          GLenum type,
90                          void *pixels) override;
91 
92     gl::Error blit(const gl::Context *context,
93                    const gl::Rectangle &sourceArea,
94                    const gl::Rectangle &destArea,
95                    GLbitfield mask,
96                    GLenum filter) override;
97 
98     bool checkStatus(const gl::Context *context) const override;
99 
100     void syncState(const gl::Context *context,
101                    const gl::Framebuffer::DirtyBits &dirtyBits) override;
102 
103     const gl::AttachmentList &getColorAttachmentsForRender(const gl::Context *context);
104 
105   private:
106     virtual gl::Error clearImpl(const gl::Context *context, const ClearParameters &clearParams) = 0;
107 
108     virtual gl::Error readPixelsImpl(const gl::Context *context,
109                                      const gl::Rectangle &area,
110                                      GLenum format,
111                                      GLenum type,
112                                      size_t outputPitch,
113                                      const gl::PixelPackState &pack,
114                                      uint8_t *pixels) = 0;
115 
116     virtual gl::Error blitImpl(const gl::Context *context,
117                                const gl::Rectangle &sourceArea,
118                                const gl::Rectangle &destArea,
119                                const gl::Rectangle *scissor,
120                                bool blitRenderTarget,
121                                bool blitDepth,
122                                bool blitStencil,
123                                GLenum filter,
124                                const gl::Framebuffer *sourceFramebuffer) = 0;
125 
126     virtual GLenum getRenderTargetImplementationFormat(RenderTargetD3D *renderTarget) const = 0;
127 
128     RendererD3D *mRenderer;
129     Optional<gl::AttachmentList> mColorAttachmentsForRender;
130     gl::DrawBufferMask mCurrentActiveProgramOutputs;
131 };
132 }
133 
134 #endif  // LIBANGLE_RENDERER_D3D_FRAMBUFFERD3D_H_
135