blob: c1f787dc0d262f91f1697ed9134fe75f412ecfc3 [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
Jamie Madill362876b2016-06-16 14:46:59 -040015#include "common/Optional.h"
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000016#include "common/angleutils.h"
Jamie Madill7147f012015-03-05 15:41:40 -050017#include "libANGLE/Constants.h"
Geoff Lang70d0f492015-12-10 17:45:46 -050018#include "libANGLE/Debug.h"
Jamie Madill7147f012015-03-05 15:41:40 -050019#include "libANGLE/Error.h"
Jamie Madill2d06b732015-04-20 12:53:28 -040020#include "libANGLE/FramebufferAttachment.h"
Jamie Madill6f683082018-02-28 00:35:16 -050021#include "libANGLE/Observer.h"
Jamie Madill7147f012015-03-05 15:41:40 -050022#include "libANGLE/RefCountObject.h"
Geoff Lang64f23f62014-09-10 14:40:12 -040023
daniel@transgaming.com16418b12012-11-28 19:32:22 +000024namespace rx
25{
Jamie Madill7aea7e02016-05-10 10:39:45 -040026class GLImplFactory;
Geoff Langda88add2014-12-01 10:22:01 -050027class FramebufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050028class RenderbufferImpl;
Corentin Wallez37c39792015-08-20 14:19:46 -040029class SurfaceImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050030}
31
32namespace egl
33{
Jamie Madill6c1f6712017-02-14 19:08:04 -050034class Display;
Jamie Madilld1405e52015-03-05 15:41:39 -050035class Surface;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000036}
37
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038namespace gl
39{
Jamie Madill1b94d432015-08-07 13:23:23 -040040class Context;
Jamie Madilldd43e6c2017-03-24 14:18:49 -040041class ContextState;
Jamie Madill48ef11b2016-04-27 15:21:52 -040042class Framebuffer;
Jamie Madillcc129372018-04-12 09:13:18 -040043class ImageIndex;
Geoff Langab75a052014-10-15 12:56:37 -040044class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050045class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050046class Texture;
47class TextureCapsMap;
48struct Caps;
Jamie Madilld1405e52015-03-05 15:41:39 -050049struct Extensions;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050050struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000051
Jamie Madill48ef11b2016-04-27 15:21:52 -040052class FramebufferState final : angle::NonCopyable
53{
54 public:
55 FramebufferState();
Jamie Madill2274b652018-05-31 10:56:08 -040056 explicit FramebufferState(const Caps &caps, GLuint id);
Jamie Madill48ef11b2016-04-27 15:21:52 -040057 ~FramebufferState();
58
59 const std::string &getLabel();
Jamie Madill05b35b22017-10-03 09:01:44 -040060 size_t getReadIndex() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040061
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -080062 const FramebufferAttachment *getAttachment(const Context *context, GLenum attachment) const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040063 const FramebufferAttachment *getReadAttachment() const;
Jamie Madill7b57b9d2017-01-13 09:33:38 -050064 const FramebufferAttachment *getFirstNonNullAttachment() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040065 const FramebufferAttachment *getFirstColorAttachment() const;
66 const FramebufferAttachment *getDepthOrStencilAttachment() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -050067 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040068 const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
69 const FramebufferAttachment *getDepthAttachment() const;
70 const FramebufferAttachment *getStencilAttachment() const;
71 const FramebufferAttachment *getDepthStencilAttachment() const;
72
73 const std::vector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
Corentin Walleze7557742017-06-01 13:09:57 -040074 DrawBufferMask getEnabledDrawBuffers() const { return mEnabledDrawBuffers; }
Jamie Madill48ef11b2016-04-27 15:21:52 -040075 GLenum getReadBufferState() const { return mReadBufferState; }
76 const std::vector<FramebufferAttachment> &getColorAttachments() const
77 {
78 return mColorAttachments;
79 }
80
81 bool attachmentsHaveSameDimensions() const;
Luc Ferron5bdf8bd2018-06-20 09:51:37 -040082 bool hasSeparateDepthAndStencilAttachments() const;
Geoff Langb21e20d2016-07-19 15:35:41 -040083 bool colorAttachmentsAreUniqueImages() const;
Jamie Madill05b35b22017-10-03 09:01:44 -040084 Box getDimensions() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040085
Geoff Lang4b7f12b2016-06-21 16:47:07 -040086 const FramebufferAttachment *getDrawBuffer(size_t drawBufferIdx) const;
87 size_t getDrawBufferCount() const;
88
JiangYizhouf7bbc8a2016-11-16 09:57:22 +080089 GLint getDefaultWidth() const { return mDefaultWidth; };
90 GLint getDefaultHeight() const { return mDefaultHeight; };
91 GLint getDefaultSamples() const { return mDefaultSamples; };
Geoff Lang92019432017-11-20 13:09:34 -050092 bool getDefaultFixedSampleLocations() const { return mDefaultFixedSampleLocations; };
Jiawei Shaob1e91382018-05-17 14:33:55 +080093 GLint getDefaultLayers() const { return mDefaultLayers; }
JiangYizhouf7bbc8a2016-11-16 09:57:22 +080094
Jamie Madill9c335862017-07-18 11:51:38 -040095 bool hasDepth() const;
96 bool hasStencil() const;
97
Martin Radev5c00d0d2017-08-07 10:06:59 +030098 GLenum getMultiviewLayout() const;
99 GLsizei getNumViews() const;
100 const std::vector<Offset> *getViewportOffsets() const;
Martin Radev4e619f52017-08-09 11:50:06 +0300101 GLint getBaseViewIndex() const;
Martin Radev5c00d0d2017-08-07 10:06:59 +0300102
Jamie Madill2274b652018-05-31 10:56:08 -0400103 GLuint id() const { return mId; }
104
Jamie Madill48ef11b2016-04-27 15:21:52 -0400105 private:
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800106 const FramebufferAttachment *getWebGLDepthStencilAttachment() const;
Bryan Bernhart (Intel Americas Inc)5f198102017-12-12 14:21:39 -0800107 const FramebufferAttachment *getWebGLDepthAttachment() const;
108 const FramebufferAttachment *getWebGLStencilAttachment() const;
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800109
Jamie Madill48ef11b2016-04-27 15:21:52 -0400110 friend class Framebuffer;
111
Jamie Madill2274b652018-05-31 10:56:08 -0400112 GLuint mId;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400113 std::string mLabel;
114
115 std::vector<FramebufferAttachment> mColorAttachments;
116 FramebufferAttachment mDepthAttachment;
117 FramebufferAttachment mStencilAttachment;
118
119 std::vector<GLenum> mDrawBufferStates;
120 GLenum mReadBufferState;
Corentin Walleze7557742017-06-01 13:09:57 -0400121 DrawBufferMask mEnabledDrawBuffers;
Brandon Jonesc405ae72017-12-06 14:15:03 -0800122 ComponentTypeMask mDrawBufferTypeMask;
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800123
124 GLint mDefaultWidth;
125 GLint mDefaultHeight;
126 GLint mDefaultSamples;
Geoff Lang92019432017-11-20 13:09:34 -0500127 bool mDefaultFixedSampleLocations;
Jiawei Shaob1e91382018-05-17 14:33:55 +0800128 GLint mDefaultLayers;
Jamie Madilla02315b2017-02-23 14:14:47 -0500129
130 // It's necessary to store all this extra state so we can restore attachments
131 // when DEPTH_STENCIL/DEPTH/STENCIL is unbound in WebGL 1.
132 FramebufferAttachment mWebGLDepthStencilAttachment;
133 FramebufferAttachment mWebGLDepthAttachment;
134 FramebufferAttachment mWebGLStencilAttachment;
135 bool mWebGLDepthStencilConsistent;
Jamie Madill05b35b22017-10-03 09:01:44 -0400136
137 // Tracks if we need to initialize the resources for each attachment.
138 angle::BitSet<IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS + 2> mResourceNeedsInit;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400139};
140
Jamie Madilla11819d2018-07-30 10:26:01 -0400141class Framebuffer final : public angle::ObserverInterface,
142 public LabeledObject,
143 public angle::Subject
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000144{
145 public:
Corentin Wallezccab69d2017-01-27 16:57:15 -0500146 // Constructor to build application-defined framebuffers
Jamie Madill7aea7e02016-05-10 10:39:45 -0400147 Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id);
Geoff Langbf7b95d2018-05-01 16:48:21 -0400148 // Constructor to build default framebuffers for a surface and context pair
149 Framebuffer(const Context *context, egl::Surface *surface);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500150 // Constructor to build a fake default framebuffer when surfaceless
151 Framebuffer(rx::GLImplFactory *factory);
152
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500153 ~Framebuffer() override;
Jamie Madill4928b7c2017-06-20 12:57:39 -0400154 void onDestroy(const Context *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000155
Geoff Lang70d0f492015-12-10 17:45:46 -0500156 void setLabel(const std::string &label) override;
157 const std::string &getLabel() const override;
158
Jamie Madill51f40ec2016-06-15 14:06:00 -0400159 rx::FramebufferImpl *getImplementation() const { return mImpl; }
Geoff Langda88add2014-12-01 10:22:01 -0500160
Jamie Madill2274b652018-05-31 10:56:08 -0400161 GLuint id() const { return mState.mId; }
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400162
Jamie Madilla02315b2017-02-23 14:14:47 -0500163 void setAttachment(const Context *context,
164 GLenum type,
Jamie Madill2d06b732015-04-20 12:53:28 -0400165 GLenum binding,
166 const ImageIndex &textureIndex,
167 FramebufferAttachmentObject *resource);
Martin Radev82ef7742017-08-08 17:44:58 +0300168 void setAttachmentMultiviewLayered(const Context *context,
169 GLenum type,
170 GLenum binding,
171 const ImageIndex &textureIndex,
172 FramebufferAttachmentObject *resource,
173 GLsizei numViews,
174 GLint baseViewIndex);
Martin Radev5dae57b2017-07-14 16:15:55 +0300175 void setAttachmentMultiviewSideBySide(const Context *context,
176 GLenum type,
177 GLenum binding,
178 const ImageIndex &textureIndex,
179 FramebufferAttachmentObject *resource,
180 GLsizei numViews,
181 const GLint *viewportOffsets);
Jamie Madilla02315b2017-02-23 14:14:47 -0500182 void resetAttachment(const Context *context, GLenum binding);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000183
Jamie Madill8693bdb2017-09-02 15:32:14 -0400184 bool detachTexture(const Context *context, GLuint texture);
185 bool detachRenderbuffer(const Context *context, GLuint renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000186
Corentin Wallez37c39792015-08-20 14:19:46 -0400187 const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400188 const FramebufferAttachment *getDepthbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400189 const FramebufferAttachment *getStencilbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400190 const FramebufferAttachment *getDepthStencilBuffer() const;
191 const FramebufferAttachment *getDepthOrStencilbuffer() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500192 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400193 const FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +0000194 GLenum getReadColorbufferType() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400195 const FramebufferAttachment *getFirstColorbuffer() const;
Jamie Madill6dd06ea2017-07-19 13:47:55 -0400196 const FramebufferAttachment *getFirstNonNullAttachment() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000197
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800198 const FramebufferAttachment *getAttachment(const Context *context, GLenum attachment) const;
Martin Radev878c8b12017-07-28 09:51:04 +0300199 GLenum getMultiviewLayout() const;
Olli Etuaho8acb1b62018-07-30 16:20:54 +0300200 bool readDisallowedByMultiview() const;
Martin Radev14a26ae2017-07-24 15:56:29 +0300201 GLsizei getNumViews() const;
Martin Radev4e619f52017-08-09 11:50:06 +0300202 GLint getBaseViewIndex() const;
Martin Radev878c8b12017-07-28 09:51:04 +0300203 const std::vector<Offset> *getViewportOffsets() const;
Geoff Langc90d73a2013-07-22 16:39:23 -0400204
Geoff Langa15472a2015-08-11 11:48:03 -0400205 size_t getDrawbufferStateCount() const;
206 GLenum getDrawBufferState(size_t drawBuffer) const;
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500207 const std::vector<GLenum> &getDrawBufferStates() const;
Geoff Lang164d54e2014-12-01 10:55:33 -0500208 void setDrawBuffers(size_t count, const GLenum *buffers);
Geoff Langa15472a2015-08-11 11:48:03 -0400209 const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
Geoff Lange0cff192017-05-30 13:04:56 -0400210 GLenum getDrawbufferWriteType(size_t drawBuffer) const;
Brandon Jonesc405ae72017-12-06 14:15:03 -0800211 ComponentTypeMask getDrawBufferTypeMask() const;
Brandon Jones76746f92017-11-22 11:44:41 -0800212 DrawBufferMask getDrawBufferMask() const;
Geoff Langa15472a2015-08-11 11:48:03 -0400213 bool hasEnabledDrawBuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000214
Geoff Lang9dd95802014-12-01 11:12:59 -0500215 GLenum getReadBufferState() const;
216 void setReadBuffer(GLenum buffer);
217
Corentin Wallez37c39792015-08-20 14:19:46 -0400218 size_t getNumColorBuffers() const;
Jamie Madill0df8fe42015-11-24 16:10:24 -0500219 bool hasDepth() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000220 bool hasStencil() const;
Jamie Madill51f40ec2016-06-15 14:06:00 -0400221
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000222 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000223
Jamie Madill51f40ec2016-06-15 14:06:00 -0400224 // This method calls checkStatus.
Jamie Madill427064d2018-04-13 16:20:34 -0400225 int getSamples(const Context *context);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800226
Geoff Lang13455072018-05-09 11:24:43 -0400227 Error getSamplePosition(const Context *context, size_t index, GLfloat *xy) const;
JiangYizhoubddc46b2016-12-09 09:50:51 +0800228
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800229 GLint getDefaultWidth() const;
230 GLint getDefaultHeight() const;
231 GLint getDefaultSamples() const;
Geoff Lang92019432017-11-20 13:09:34 -0500232 bool getDefaultFixedSampleLocations() const;
Jiawei Shaob1e91382018-05-17 14:33:55 +0800233 GLint getDefaultLayers() const;
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800234 void setDefaultWidth(GLint defaultWidth);
235 void setDefaultHeight(GLint defaultHeight);
236 void setDefaultSamples(GLint defaultSamples);
Geoff Lang92019432017-11-20 13:09:34 -0500237 void setDefaultFixedSampleLocations(bool defaultFixedSampleLocations);
Jiawei Shaob1e91382018-05-17 14:33:55 +0800238 void setDefaultLayers(GLint defaultLayers);
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800239
Geoff Lang9aded172017-04-05 11:07:56 -0400240 void invalidateCompletenessCache();
241
Jamie Madill427064d2018-04-13 16:20:34 -0400242 GLenum checkStatus(const Context *context);
Jamie Madilldd43e6c2017-03-24 14:18:49 -0400243
Jamie Madill9c335862017-07-18 11:51:38 -0400244 // For when we don't want to check completeness in getSamples().
245 int getCachedSamples(const Context *context);
246
Jamie Madill362876b2016-06-16 14:46:59 -0400247 // Helper for checkStatus == GL_FRAMEBUFFER_COMPLETE.
Jamie Madill427064d2018-04-13 16:20:34 -0400248 bool isComplete(const Context *context);
Jamie Madill51f40ec2016-06-15 14:06:00 -0400249
Jamie Madille92a3542014-07-03 10:38:58 -0400250 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000251
Jamie Madill4928b7c2017-06-20 12:57:39 -0400252 Error discard(const Context *context, size_t count, const GLenum *attachments);
253 Error invalidate(const Context *context, size_t count, const GLenum *attachments);
254 Error invalidateSub(const Context *context,
255 size_t count,
256 const GLenum *attachments,
Jamie Madilld4442552018-02-27 22:03:47 -0500257 const Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400258
Jamie Madilld4442552018-02-27 22:03:47 -0500259 Error clear(const Context *context, GLbitfield mask);
260 Error clearBufferfv(const Context *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500261 GLenum buffer,
262 GLint drawbuffer,
263 const GLfloat *values);
Jamie Madilld4442552018-02-27 22:03:47 -0500264 Error clearBufferuiv(const Context *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500265 GLenum buffer,
266 GLint drawbuffer,
267 const GLuint *values);
Jamie Madilld4442552018-02-27 22:03:47 -0500268 Error clearBufferiv(const Context *context,
Jamie Madill9082b982016-04-27 15:21:51 -0400269 GLenum buffer,
270 GLint drawbuffer,
271 const GLint *values);
Jamie Madilld4442552018-02-27 22:03:47 -0500272 Error clearBufferfi(const Context *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400273 GLenum buffer,
274 GLint drawbuffer,
275 GLfloat depth,
276 GLint stencil);
Geoff Langb04dc822014-12-01 12:02:02 -0500277
Jamie Madill690c8eb2018-03-12 15:20:03 -0400278 // These two methods call syncState() internally.
279 Error getImplementationColorReadFormat(const Context *context, GLenum *formatOut);
280 Error getImplementationColorReadType(const Context *context, GLenum *typeOut);
281
Jamie Madilld4442552018-02-27 22:03:47 -0500282 Error readPixels(const Context *context,
283 const Rectangle &area,
Jamie Madill1b94d432015-08-07 13:23:23 -0400284 GLenum format,
285 GLenum type,
Jamie Madill05b35b22017-10-03 09:01:44 -0400286 void *pixels);
Geoff Langbce529e2014-12-01 12:48:41 -0500287
Jamie Madilld4442552018-02-27 22:03:47 -0500288 Error blit(const Context *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500289 const Rectangle &sourceArea,
290 const Rectangle &destArea,
Geoff Lang242468f2015-09-24 14:15:41 -0400291 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400292 GLenum filter);
Luc Ferronbf6dc372018-06-28 15:24:19 -0400293 bool isDefault() const;
Geoff Lang54bd5a42014-12-01 12:51:04 -0500294
Jamie Madill05b35b22017-10-03 09:01:44 -0400295 enum DirtyBitType : size_t
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500296 {
297 DIRTY_BIT_COLOR_ATTACHMENT_0,
298 DIRTY_BIT_COLOR_ATTACHMENT_MAX =
Jamie Madilld4442552018-02-27 22:03:47 -0500299 DIRTY_BIT_COLOR_ATTACHMENT_0 + IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500300 DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
301 DIRTY_BIT_STENCIL_ATTACHMENT,
302 DIRTY_BIT_DRAW_BUFFERS,
303 DIRTY_BIT_READ_BUFFER,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800304 DIRTY_BIT_DEFAULT_WIDTH,
305 DIRTY_BIT_DEFAULT_HEIGHT,
306 DIRTY_BIT_DEFAULT_SAMPLES,
307 DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS,
Jiawei Shaob1e91382018-05-17 14:33:55 +0800308 DIRTY_BIT_DEFAULT_LAYERS,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500309 DIRTY_BIT_UNKNOWN,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800310 DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500311 };
312
Yunchao He1f679cc2017-11-29 18:06:00 +0800313 using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500314 bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
315
Jamie Madill19fa1c62018-03-08 09:47:21 -0500316 Error syncState(const Context *context);
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500317
Jamie Madilld4442552018-02-27 22:03:47 -0500318 // Observer implementation
319 void onSubjectStateChange(const Context *context,
320 angle::SubjectIndex index,
321 angle::SubjectMessage message) override;
Jamie Madill362876b2016-06-16 14:46:59 -0400322
Jamie Madilla4595b82017-01-11 17:36:34 -0500323 bool formsRenderingFeedbackLoopWith(const State &state) const;
Jamie Madillfd3dd432017-02-02 19:59:59 -0500324 bool formsCopyingFeedbackLoopWith(GLuint copyTextureID,
325 GLint copyTextureLevel,
326 GLint copyTextureLayer) const;
Jamie Madilla4595b82017-01-11 17:36:34 -0500327
Geoff Langd4fff502017-09-22 11:28:28 -0400328 Error ensureClearAttachmentsInitialized(const Context *context, GLbitfield mask);
329 Error ensureClearBufferAttachmentsInitialized(const Context *context,
330 GLenum buffer,
331 GLint drawbuffer);
Jamie Madill05b35b22017-10-03 09:01:44 -0400332 Error ensureDrawAttachmentsInitialized(const Context *context);
333 Error ensureReadAttachmentInitialized(const Context *context, GLbitfield blitMask);
334 Box getDimensions() const;
335
Jamie Madill42975642017-10-12 12:31:51 -0400336 bool hasTextureAttachment(const Texture *texture) const;
337
Jamie Madill362876b2016-06-16 14:46:59 -0400338 private:
Jamie Madill8693bdb2017-09-02 15:32:14 -0400339 bool detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
340 bool detachMatchingAttachment(const Context *context,
Jamie Madill4928b7c2017-06-20 12:57:39 -0400341 FramebufferAttachment *attachment,
Jamie Madill362876b2016-06-16 14:46:59 -0400342 GLenum matchType,
343 GLuint matchId,
344 size_t dirtyBit);
Jamie Madille98b1b52018-03-08 09:47:23 -0500345 GLenum checkStatusWithGLFrontEnd(const Context *context);
Martin Radev5dae57b2017-07-14 16:15:55 +0300346 void setAttachment(const Context *context,
347 GLenum type,
348 GLenum binding,
349 const ImageIndex &textureIndex,
350 FramebufferAttachmentObject *resource,
351 GLsizei numViews,
352 GLuint baseViewIndex,
353 GLenum multiviewLayout,
354 const GLint *viewportOffsets);
355 void commitWebGL1DepthStencilIfConsistent(const Context *context,
356 GLsizei numViews,
357 GLuint baseViewIndex,
358 GLenum multiviewLayout,
359 const GLint *viewportOffsets);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400360 void setAttachmentImpl(const Context *context,
361 GLenum type,
Jamie Madilla02315b2017-02-23 14:14:47 -0500362 GLenum binding,
363 const ImageIndex &textureIndex,
Martin Radev5dae57b2017-07-14 16:15:55 +0300364 FramebufferAttachmentObject *resource,
365 GLsizei numViews,
366 GLuint baseViewIndex,
367 GLenum multiviewLayout,
368 const GLint *viewportOffsets);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400369 void updateAttachment(const Context *context,
370 FramebufferAttachment *attachment,
Jamie Madillb8126692017-04-05 11:22:17 -0400371 size_t dirtyBit,
Jamie Madilld4442552018-02-27 22:03:47 -0500372 angle::ObserverBinding *onDirtyBinding,
Jamie Madillb8126692017-04-05 11:22:17 -0400373 GLenum type,
374 GLenum binding,
375 const ImageIndex &textureIndex,
Martin Radev5dae57b2017-07-14 16:15:55 +0300376 FramebufferAttachmentObject *resource,
377 GLsizei numViews,
378 GLuint baseViewIndex,
379 GLenum multiviewLayout,
380 const GLint *viewportOffsets);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500381
Jamie Madill05b35b22017-10-03 09:01:44 -0400382 void markDrawAttachmentsInitialized(bool color, bool depth, bool stencil);
383 void markBufferInitialized(GLenum bufferType, GLint bufferIndex);
384 Error ensureBufferInitialized(const Context *context, GLenum bufferType, GLint bufferIndex);
385
386 // Checks that we have a partially masked clear:
387 // * some color channels are masked out
388 // * some stencil values are masked out
389 // * scissor test partially overlaps the framebuffer
390 bool partialClearNeedsInit(const Context *context, bool color, bool depth, bool stencil);
391 bool partialBufferClearNeedsInit(const Context *context, GLenum bufferType);
392
Jamie Madilld4442552018-02-27 22:03:47 -0500393 FramebufferAttachment *getAttachmentFromSubjectIndex(angle::SubjectIndex index);
394
Jamie Madill48ef11b2016-04-27 15:21:52 -0400395 FramebufferState mState;
Geoff Langda88add2014-12-01 10:22:01 -0500396 rx::FramebufferImpl *mImpl;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500397
Jamie Madill362876b2016-06-16 14:46:59 -0400398 Optional<GLenum> mCachedStatus;
Jamie Madilld4442552018-02-27 22:03:47 -0500399 std::vector<angle::ObserverBinding> mDirtyColorAttachmentBindings;
400 angle::ObserverBinding mDirtyDepthAttachmentBinding;
401 angle::ObserverBinding mDirtyStencilAttachmentBinding;
Jamie Madill362876b2016-06-16 14:46:59 -0400402
403 DirtyBits mDirtyBits;
Jamie Madill42975642017-10-12 12:31:51 -0400404
Jamie Madill888081d2018-02-27 00:24:46 -0500405 // The dirty bits guard is checked when we get a dependent state change message. We verify that
406 // we don't set a dirty bit that isn't already set, when inside the dirty bits syncState.
407 Optional<DirtyBits> mDirtyBitsGuard;
408
Jamie Madill42975642017-10-12 12:31:51 -0400409 // A cache of attached textures for quick validation of feedback loops.
410 mutable Optional<std::set<const FramebufferAttachmentObject *>> mAttachedTextures;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000411};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000412
Jamie Madill362876b2016-06-16 14:46:59 -0400413} // namespace gl
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000414
Jamie Madill231c7f52017-04-26 13:45:37 -0400415#endif // LIBANGLE_FRAMEBUFFER_H_