blob: e07bfbceaff088933ed04205c813b7e4a1c9f3bd [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +00002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Framebuffer.h: Defines the gl::Framebuffer class. Implements GL framebuffer
8// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
9
Geoff Lang0a73dd82014-11-19 16:18:08 -050010#ifndef LIBANGLE_FRAMEBUFFER_H_
11#define LIBANGLE_FRAMEBUFFER_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012
Jamie Madill7147f012015-03-05 15:41:40 -050013#include <vector>
Jamie Madillce20c7f2014-09-03 11:56:29 -040014
Geoff Langb8430dd2018-08-01 15:27:18 -040015#include "common/FixedVector.h"
Jamie Madill362876b2016-06-16 14:46:59 -040016#include "common/Optional.h"
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000017#include "common/angleutils.h"
Jamie Madill7147f012015-03-05 15:41:40 -050018#include "libANGLE/Constants.h"
Geoff Lang70d0f492015-12-10 17:45:46 -050019#include "libANGLE/Debug.h"
Jamie Madill7147f012015-03-05 15:41:40 -050020#include "libANGLE/Error.h"
Jamie Madill2d06b732015-04-20 12:53:28 -040021#include "libANGLE/FramebufferAttachment.h"
Jamie Madill6f683082018-02-28 00:35:16 -050022#include "libANGLE/Observer.h"
Jamie Madill7147f012015-03-05 15:41:40 -050023#include "libANGLE/RefCountObject.h"
Geoff Lang64f23f62014-09-10 14:40:12 -040024
daniel@transgaming.com16418b12012-11-28 19:32:22 +000025namespace rx
26{
Jamie Madill7aea7e02016-05-10 10:39:45 -040027class GLImplFactory;
Geoff Langda88add2014-12-01 10:22:01 -050028class FramebufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050029class RenderbufferImpl;
Corentin Wallez37c39792015-08-20 14:19:46 -040030class SurfaceImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050031}
32
33namespace egl
34{
Jamie Madill6c1f6712017-02-14 19:08:04 -050035class Display;
Jamie Madilld1405e52015-03-05 15:41:39 -050036class Surface;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000037}
38
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039namespace gl
40{
Jamie Madill1b94d432015-08-07 13:23:23 -040041class Context;
Jamie Madilldd43e6c2017-03-24 14:18:49 -040042class ContextState;
Jamie Madill48ef11b2016-04-27 15:21:52 -040043class Framebuffer;
Jamie Madillcc129372018-04-12 09:13:18 -040044class ImageIndex;
Geoff Langab75a052014-10-15 12:56:37 -040045class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050046class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050047class Texture;
48class TextureCapsMap;
49struct Caps;
Jamie Madilld1405e52015-03-05 15:41:39 -050050struct Extensions;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050051struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052
Jamie Madill48ef11b2016-04-27 15:21:52 -040053class FramebufferState final : angle::NonCopyable
54{
55 public:
56 FramebufferState();
Jamie Madill2274b652018-05-31 10:56:08 -040057 explicit FramebufferState(const Caps &caps, GLuint id);
Jamie Madill48ef11b2016-04-27 15:21:52 -040058 ~FramebufferState();
59
60 const std::string &getLabel();
Jamie Madill05b35b22017-10-03 09:01:44 -040061 size_t getReadIndex() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040062
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -080063 const FramebufferAttachment *getAttachment(const Context *context, GLenum attachment) const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040064 const FramebufferAttachment *getReadAttachment() const;
Jamie Madill7b57b9d2017-01-13 09:33:38 -050065 const FramebufferAttachment *getFirstNonNullAttachment() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040066 const FramebufferAttachment *getFirstColorAttachment() const;
67 const FramebufferAttachment *getDepthOrStencilAttachment() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -050068 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040069 const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
70 const FramebufferAttachment *getDepthAttachment() const;
71 const FramebufferAttachment *getStencilAttachment() const;
72 const FramebufferAttachment *getDepthStencilAttachment() const;
73
74 const std::vector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
Corentin Walleze7557742017-06-01 13:09:57 -040075 DrawBufferMask getEnabledDrawBuffers() const { return mEnabledDrawBuffers; }
Jamie Madill48ef11b2016-04-27 15:21:52 -040076 GLenum getReadBufferState() const { return mReadBufferState; }
77 const std::vector<FramebufferAttachment> &getColorAttachments() const
78 {
79 return mColorAttachments;
80 }
81
82 bool attachmentsHaveSameDimensions() const;
Luc Ferron5bdf8bd2018-06-20 09:51:37 -040083 bool hasSeparateDepthAndStencilAttachments() const;
Geoff Langb21e20d2016-07-19 15:35:41 -040084 bool colorAttachmentsAreUniqueImages() const;
Jamie Madill05b35b22017-10-03 09:01:44 -040085 Box getDimensions() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040086
Geoff Lang4b7f12b2016-06-21 16:47:07 -040087 const FramebufferAttachment *getDrawBuffer(size_t drawBufferIdx) const;
88 size_t getDrawBufferCount() const;
89
JiangYizhouf7bbc8a2016-11-16 09:57:22 +080090 GLint getDefaultWidth() const { return mDefaultWidth; };
91 GLint getDefaultHeight() const { return mDefaultHeight; };
92 GLint getDefaultSamples() const { return mDefaultSamples; };
Geoff Lang92019432017-11-20 13:09:34 -050093 bool getDefaultFixedSampleLocations() const { return mDefaultFixedSampleLocations; };
Jiawei Shaob1e91382018-05-17 14:33:55 +080094 GLint getDefaultLayers() const { return mDefaultLayers; }
JiangYizhouf7bbc8a2016-11-16 09:57:22 +080095
Jamie Madill9c335862017-07-18 11:51:38 -040096 bool hasDepth() const;
97 bool hasStencil() const;
98
Martin Radev5c00d0d2017-08-07 10:06:59 +030099 GLenum getMultiviewLayout() const;
Jamie Madill31116732018-10-09 18:30:01 -0400100
101 ANGLE_INLINE GLsizei getNumViews() const
102 {
103 const FramebufferAttachment *attachment = getFirstNonNullAttachment();
104 if (attachment == nullptr)
105 {
106 return FramebufferAttachment::kDefaultNumViews;
107 }
108 return attachment->getNumViews();
109 }
110
Martin Radev5c00d0d2017-08-07 10:06:59 +0300111 const std::vector<Offset> *getViewportOffsets() const;
Martin Radev4e619f52017-08-09 11:50:06 +0300112 GLint getBaseViewIndex() const;
Martin Radev5c00d0d2017-08-07 10:06:59 +0300113
Jamie Madill2274b652018-05-31 10:56:08 -0400114 GLuint id() const { return mId; }
115
Jamie Madill48ef11b2016-04-27 15:21:52 -0400116 private:
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800117 const FramebufferAttachment *getWebGLDepthStencilAttachment() const;
Bryan Bernhart (Intel Americas Inc)5f198102017-12-12 14:21:39 -0800118 const FramebufferAttachment *getWebGLDepthAttachment() const;
119 const FramebufferAttachment *getWebGLStencilAttachment() const;
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800120
Jamie Madill48ef11b2016-04-27 15:21:52 -0400121 friend class Framebuffer;
122
Jamie Madill2274b652018-05-31 10:56:08 -0400123 GLuint mId;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400124 std::string mLabel;
125
126 std::vector<FramebufferAttachment> mColorAttachments;
127 FramebufferAttachment mDepthAttachment;
128 FramebufferAttachment mStencilAttachment;
129
130 std::vector<GLenum> mDrawBufferStates;
131 GLenum mReadBufferState;
Corentin Walleze7557742017-06-01 13:09:57 -0400132 DrawBufferMask mEnabledDrawBuffers;
Brandon Jonesc405ae72017-12-06 14:15:03 -0800133 ComponentTypeMask mDrawBufferTypeMask;
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800134
135 GLint mDefaultWidth;
136 GLint mDefaultHeight;
137 GLint mDefaultSamples;
Geoff Lang92019432017-11-20 13:09:34 -0500138 bool mDefaultFixedSampleLocations;
Jiawei Shaob1e91382018-05-17 14:33:55 +0800139 GLint mDefaultLayers;
Jamie Madilla02315b2017-02-23 14:14:47 -0500140
141 // It's necessary to store all this extra state so we can restore attachments
142 // when DEPTH_STENCIL/DEPTH/STENCIL is unbound in WebGL 1.
143 FramebufferAttachment mWebGLDepthStencilAttachment;
144 FramebufferAttachment mWebGLDepthAttachment;
145 FramebufferAttachment mWebGLStencilAttachment;
146 bool mWebGLDepthStencilConsistent;
Jamie Madill05b35b22017-10-03 09:01:44 -0400147
148 // Tracks if we need to initialize the resources for each attachment.
149 angle::BitSet<IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS + 2> mResourceNeedsInit;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400150};
151
Jamie Madilla11819d2018-07-30 10:26:01 -0400152class Framebuffer final : public angle::ObserverInterface,
153 public LabeledObject,
154 public angle::Subject
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000155{
156 public:
Corentin Wallezccab69d2017-01-27 16:57:15 -0500157 // Constructor to build application-defined framebuffers
Jamie Madill7aea7e02016-05-10 10:39:45 -0400158 Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id);
Geoff Langbf7b95d2018-05-01 16:48:21 -0400159 // Constructor to build default framebuffers for a surface and context pair
160 Framebuffer(const Context *context, egl::Surface *surface);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500161 // Constructor to build a fake default framebuffer when surfaceless
162 Framebuffer(rx::GLImplFactory *factory);
163
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500164 ~Framebuffer() override;
Jamie Madill4928b7c2017-06-20 12:57:39 -0400165 void onDestroy(const Context *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000166
Geoff Lang70d0f492015-12-10 17:45:46 -0500167 void setLabel(const std::string &label) override;
168 const std::string &getLabel() const override;
169
Jamie Madill51f40ec2016-06-15 14:06:00 -0400170 rx::FramebufferImpl *getImplementation() const { return mImpl; }
Geoff Langda88add2014-12-01 10:22:01 -0500171
Jamie Madill2274b652018-05-31 10:56:08 -0400172 GLuint id() const { return mState.mId; }
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400173
Jamie Madilla02315b2017-02-23 14:14:47 -0500174 void setAttachment(const Context *context,
175 GLenum type,
Jamie Madill2d06b732015-04-20 12:53:28 -0400176 GLenum binding,
177 const ImageIndex &textureIndex,
178 FramebufferAttachmentObject *resource);
Martin Radev82ef7742017-08-08 17:44:58 +0300179 void setAttachmentMultiviewLayered(const Context *context,
180 GLenum type,
181 GLenum binding,
182 const ImageIndex &textureIndex,
183 FramebufferAttachmentObject *resource,
184 GLsizei numViews,
185 GLint baseViewIndex);
Martin Radev5dae57b2017-07-14 16:15:55 +0300186 void setAttachmentMultiviewSideBySide(const Context *context,
187 GLenum type,
188 GLenum binding,
189 const ImageIndex &textureIndex,
190 FramebufferAttachmentObject *resource,
191 GLsizei numViews,
192 const GLint *viewportOffsets);
Jamie Madilla02315b2017-02-23 14:14:47 -0500193 void resetAttachment(const Context *context, GLenum binding);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000194
Jamie Madill8693bdb2017-09-02 15:32:14 -0400195 bool detachTexture(const Context *context, GLuint texture);
196 bool detachRenderbuffer(const Context *context, GLuint renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000197
Corentin Wallez37c39792015-08-20 14:19:46 -0400198 const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400199 const FramebufferAttachment *getDepthbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400200 const FramebufferAttachment *getStencilbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400201 const FramebufferAttachment *getDepthStencilBuffer() const;
202 const FramebufferAttachment *getDepthOrStencilbuffer() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500203 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400204 const FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +0000205 GLenum getReadColorbufferType() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400206 const FramebufferAttachment *getFirstColorbuffer() const;
Jamie Madill6dd06ea2017-07-19 13:47:55 -0400207 const FramebufferAttachment *getFirstNonNullAttachment() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000208
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800209 const FramebufferAttachment *getAttachment(const Context *context, GLenum attachment) const;
Martin Radev878c8b12017-07-28 09:51:04 +0300210 GLenum getMultiviewLayout() const;
Olli Etuaho8acb1b62018-07-30 16:20:54 +0300211 bool readDisallowedByMultiview() const;
Martin Radev14a26ae2017-07-24 15:56:29 +0300212 GLsizei getNumViews() const;
Martin Radev4e619f52017-08-09 11:50:06 +0300213 GLint getBaseViewIndex() const;
Martin Radev878c8b12017-07-28 09:51:04 +0300214 const std::vector<Offset> *getViewportOffsets() const;
Geoff Langc90d73a2013-07-22 16:39:23 -0400215
Geoff Langa15472a2015-08-11 11:48:03 -0400216 size_t getDrawbufferStateCount() const;
217 GLenum getDrawBufferState(size_t drawBuffer) const;
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500218 const std::vector<GLenum> &getDrawBufferStates() const;
Geoff Lang164d54e2014-12-01 10:55:33 -0500219 void setDrawBuffers(size_t count, const GLenum *buffers);
Geoff Langa15472a2015-08-11 11:48:03 -0400220 const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
Geoff Lange0cff192017-05-30 13:04:56 -0400221 GLenum getDrawbufferWriteType(size_t drawBuffer) const;
Brandon Jonesc405ae72017-12-06 14:15:03 -0800222 ComponentTypeMask getDrawBufferTypeMask() const;
Brandon Jones76746f92017-11-22 11:44:41 -0800223 DrawBufferMask getDrawBufferMask() const;
Geoff Langa15472a2015-08-11 11:48:03 -0400224 bool hasEnabledDrawBuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000225
Geoff Lang9dd95802014-12-01 11:12:59 -0500226 GLenum getReadBufferState() const;
227 void setReadBuffer(GLenum buffer);
228
Corentin Wallez37c39792015-08-20 14:19:46 -0400229 size_t getNumColorBuffers() const;
Jamie Madill0df8fe42015-11-24 16:10:24 -0500230 bool hasDepth() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000231 bool hasStencil() const;
Jamie Madill51f40ec2016-06-15 14:06:00 -0400232
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000233 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000234
Jamie Madill51f40ec2016-06-15 14:06:00 -0400235 // This method calls checkStatus.
Jamie Madill427064d2018-04-13 16:20:34 -0400236 int getSamples(const Context *context);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800237
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400238 angle::Result getSamplePosition(const Context *context, size_t index, GLfloat *xy) const;
JiangYizhoubddc46b2016-12-09 09:50:51 +0800239
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800240 GLint getDefaultWidth() const;
241 GLint getDefaultHeight() const;
242 GLint getDefaultSamples() const;
Geoff Lang92019432017-11-20 13:09:34 -0500243 bool getDefaultFixedSampleLocations() const;
Jiawei Shaob1e91382018-05-17 14:33:55 +0800244 GLint getDefaultLayers() const;
Jamie Madillb983a4b2018-08-01 11:34:51 -0400245 void setDefaultWidth(const Context *context, GLint defaultWidth);
246 void setDefaultHeight(const Context *context, GLint defaultHeight);
247 void setDefaultSamples(const Context *context, GLint defaultSamples);
248 void setDefaultFixedSampleLocations(const Context *context, bool defaultFixedSampleLocations);
Jiawei Shaob1e91382018-05-17 14:33:55 +0800249 void setDefaultLayers(GLint defaultLayers);
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800250
Jamie Madillb983a4b2018-08-01 11:34:51 -0400251 void invalidateCompletenessCache(const Context *context);
Geoff Lang9aded172017-04-05 11:07:56 -0400252
Jamie Madill31116732018-10-09 18:30:01 -0400253 ANGLE_INLINE GLenum checkStatus(const Context *context)
Jamie Madillcc73f242018-08-01 11:34:48 -0400254 {
255 // The default framebuffer is always complete except when it is surfaceless in which
256 // case it is always unsupported.
257 ASSERT(mState.mId != 0 || mCachedStatus.valid());
258 if (mState.mId == 0 || (!hasAnyDirtyBit() && mCachedStatus.valid()))
259 {
260 return mCachedStatus.value();
261 }
262
263 return checkStatusImpl(context);
264 }
Jamie Madilldd43e6c2017-03-24 14:18:49 -0400265
Jamie Madill9c335862017-07-18 11:51:38 -0400266 // For when we don't want to check completeness in getSamples().
267 int getCachedSamples(const Context *context);
268
Jamie Madill362876b2016-06-16 14:46:59 -0400269 // Helper for checkStatus == GL_FRAMEBUFFER_COMPLETE.
Jamie Madill31116732018-10-09 18:30:01 -0400270 ANGLE_INLINE bool isComplete(const Context *context)
Jamie Madillcc73f242018-08-01 11:34:48 -0400271 {
272 return (checkStatus(context) == GL_FRAMEBUFFER_COMPLETE);
273 }
Jamie Madill51f40ec2016-06-15 14:06:00 -0400274
Jamie Madille92a3542014-07-03 10:38:58 -0400275 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000276
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400277 angle::Result discard(const Context *context, size_t count, const GLenum *attachments);
278 angle::Result invalidate(const Context *context, size_t count, const GLenum *attachments);
279 angle::Result invalidateSub(const Context *context,
280 size_t count,
281 const GLenum *attachments,
282 const Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400283
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400284 angle::Result clear(const Context *context, GLbitfield mask);
285 angle::Result clearBufferfv(const Context *context,
286 GLenum buffer,
287 GLint drawbuffer,
288 const GLfloat *values);
289 angle::Result clearBufferuiv(const Context *context,
290 GLenum buffer,
291 GLint drawbuffer,
292 const GLuint *values);
293 angle::Result clearBufferiv(const Context *context,
294 GLenum buffer,
295 GLint drawbuffer,
296 const GLint *values);
297 angle::Result clearBufferfi(const Context *context,
298 GLenum buffer,
299 GLint drawbuffer,
300 GLfloat depth,
301 GLint stencil);
Geoff Langb04dc822014-12-01 12:02:02 -0500302
Jamie Madill690c8eb2018-03-12 15:20:03 -0400303 // These two methods call syncState() internally.
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400304 angle::Result getImplementationColorReadFormat(const Context *context, GLenum *formatOut);
305 angle::Result getImplementationColorReadType(const Context *context, GLenum *typeOut);
Jamie Madill690c8eb2018-03-12 15:20:03 -0400306
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400307 angle::Result readPixels(const Context *context,
308 const Rectangle &area,
309 GLenum format,
310 GLenum type,
311 void *pixels);
Geoff Langbce529e2014-12-01 12:48:41 -0500312
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400313 angle::Result blit(const Context *context,
314 const Rectangle &sourceArea,
315 const Rectangle &destArea,
316 GLbitfield mask,
317 GLenum filter);
Luc Ferronbf6dc372018-06-28 15:24:19 -0400318 bool isDefault() const;
Geoff Lang54bd5a42014-12-01 12:51:04 -0500319
Jamie Madill05b35b22017-10-03 09:01:44 -0400320 enum DirtyBitType : size_t
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500321 {
322 DIRTY_BIT_COLOR_ATTACHMENT_0,
323 DIRTY_BIT_COLOR_ATTACHMENT_MAX =
Jamie Madilld4442552018-02-27 22:03:47 -0500324 DIRTY_BIT_COLOR_ATTACHMENT_0 + IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500325 DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
326 DIRTY_BIT_STENCIL_ATTACHMENT,
327 DIRTY_BIT_DRAW_BUFFERS,
328 DIRTY_BIT_READ_BUFFER,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800329 DIRTY_BIT_DEFAULT_WIDTH,
330 DIRTY_BIT_DEFAULT_HEIGHT,
331 DIRTY_BIT_DEFAULT_SAMPLES,
332 DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS,
Jiawei Shaob1e91382018-05-17 14:33:55 +0800333 DIRTY_BIT_DEFAULT_LAYERS,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500334 DIRTY_BIT_UNKNOWN,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800335 DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500336 };
337
Yunchao He1f679cc2017-11-29 18:06:00 +0800338 using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500339 bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
340
Jamie Madill6f755b22018-10-09 12:48:54 -0400341 angle::Result syncState(const Context *context);
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500342
Jamie Madilld4442552018-02-27 22:03:47 -0500343 // Observer implementation
344 void onSubjectStateChange(const Context *context,
345 angle::SubjectIndex index,
346 angle::SubjectMessage message) override;
Jamie Madill362876b2016-06-16 14:46:59 -0400347
Jamie Madilla4595b82017-01-11 17:36:34 -0500348 bool formsRenderingFeedbackLoopWith(const State &state) const;
Jamie Madillfd3dd432017-02-02 19:59:59 -0500349 bool formsCopyingFeedbackLoopWith(GLuint copyTextureID,
350 GLint copyTextureLevel,
351 GLint copyTextureLayer) const;
Jamie Madilla4595b82017-01-11 17:36:34 -0500352
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400353 angle::Result ensureClearAttachmentsInitialized(const Context *context, GLbitfield mask);
354 angle::Result ensureClearBufferAttachmentsInitialized(const Context *context,
355 GLenum buffer,
356 GLint drawbuffer);
Jamie Madill6f755b22018-10-09 12:48:54 -0400357 angle::Result ensureDrawAttachmentsInitialized(const Context *context);
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400358 angle::Result ensureReadAttachmentInitialized(const Context *context, GLbitfield blitMask);
Jamie Madill05b35b22017-10-03 09:01:44 -0400359 Box getDimensions() const;
360
Jamie Madill362876b2016-06-16 14:46:59 -0400361 private:
Jamie Madill8693bdb2017-09-02 15:32:14 -0400362 bool detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
363 bool detachMatchingAttachment(const Context *context,
Jamie Madill4928b7c2017-06-20 12:57:39 -0400364 FramebufferAttachment *attachment,
Jamie Madill362876b2016-06-16 14:46:59 -0400365 GLenum matchType,
Olli Etuaho4ebd8f32018-09-20 11:12:46 +0300366 GLuint matchId);
Jamie Madille98b1b52018-03-08 09:47:23 -0500367 GLenum checkStatusWithGLFrontEnd(const Context *context);
Jamie Madillcc73f242018-08-01 11:34:48 -0400368 GLenum checkStatusImpl(const Context *context);
Martin Radev5dae57b2017-07-14 16:15:55 +0300369 void setAttachment(const Context *context,
370 GLenum type,
371 GLenum binding,
372 const ImageIndex &textureIndex,
373 FramebufferAttachmentObject *resource,
374 GLsizei numViews,
375 GLuint baseViewIndex,
376 GLenum multiviewLayout,
377 const GLint *viewportOffsets);
378 void commitWebGL1DepthStencilIfConsistent(const Context *context,
379 GLsizei numViews,
380 GLuint baseViewIndex,
381 GLenum multiviewLayout,
382 const GLint *viewportOffsets);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400383 void setAttachmentImpl(const Context *context,
384 GLenum type,
Jamie Madilla02315b2017-02-23 14:14:47 -0500385 GLenum binding,
386 const ImageIndex &textureIndex,
Martin Radev5dae57b2017-07-14 16:15:55 +0300387 FramebufferAttachmentObject *resource,
388 GLsizei numViews,
389 GLuint baseViewIndex,
390 GLenum multiviewLayout,
391 const GLint *viewportOffsets);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400392 void updateAttachment(const Context *context,
393 FramebufferAttachment *attachment,
Jamie Madillb8126692017-04-05 11:22:17 -0400394 size_t dirtyBit,
Jamie Madilld4442552018-02-27 22:03:47 -0500395 angle::ObserverBinding *onDirtyBinding,
Jamie Madillb8126692017-04-05 11:22:17 -0400396 GLenum type,
397 GLenum binding,
398 const ImageIndex &textureIndex,
Martin Radev5dae57b2017-07-14 16:15:55 +0300399 FramebufferAttachmentObject *resource,
400 GLsizei numViews,
401 GLuint baseViewIndex,
402 GLenum multiviewLayout,
403 const GLint *viewportOffsets);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500404
Jamie Madill05b35b22017-10-03 09:01:44 -0400405 void markDrawAttachmentsInitialized(bool color, bool depth, bool stencil);
406 void markBufferInitialized(GLenum bufferType, GLint bufferIndex);
Jamie Madill64b7c4f2018-10-19 11:38:04 -0400407 angle::Result ensureBufferInitialized(const Context *context,
408 GLenum bufferType,
409 GLint bufferIndex);
Jamie Madill05b35b22017-10-03 09:01:44 -0400410
411 // Checks that we have a partially masked clear:
412 // * some color channels are masked out
413 // * some stencil values are masked out
414 // * scissor test partially overlaps the framebuffer
415 bool partialClearNeedsInit(const Context *context, bool color, bool depth, bool stencil);
416 bool partialBufferClearNeedsInit(const Context *context, GLenum bufferType);
417
Jamie Madilld4442552018-02-27 22:03:47 -0500418 FramebufferAttachment *getAttachmentFromSubjectIndex(angle::SubjectIndex index);
419
Jamie Madill48ef11b2016-04-27 15:21:52 -0400420 FramebufferState mState;
Geoff Langda88add2014-12-01 10:22:01 -0500421 rx::FramebufferImpl *mImpl;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500422
Jamie Madill362876b2016-06-16 14:46:59 -0400423 Optional<GLenum> mCachedStatus;
Jamie Madilld4442552018-02-27 22:03:47 -0500424 std::vector<angle::ObserverBinding> mDirtyColorAttachmentBindings;
425 angle::ObserverBinding mDirtyDepthAttachmentBinding;
426 angle::ObserverBinding mDirtyStencilAttachmentBinding;
Jamie Madill362876b2016-06-16 14:46:59 -0400427
428 DirtyBits mDirtyBits;
Jamie Madill42975642017-10-12 12:31:51 -0400429
Jamie Madill888081d2018-02-27 00:24:46 -0500430 // The dirty bits guard is checked when we get a dependent state change message. We verify that
431 // we don't set a dirty bit that isn't already set, when inside the dirty bits syncState.
432 Optional<DirtyBits> mDirtyBitsGuard;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000433};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000434
Jamie Madill362876b2016-06-16 14:46:59 -0400435} // namespace gl
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000436
Jamie Madill231c7f52017-04-26 13:45:37 -0400437#endif // LIBANGLE_FRAMEBUFFER_H_