blob: 67a7ad8fb2f5349400b23c8eae29d4e4a616a502 [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;
100 GLsizei getNumViews() const;
101 const std::vector<Offset> *getViewportOffsets() const;
Martin Radev4e619f52017-08-09 11:50:06 +0300102 GLint getBaseViewIndex() const;
Martin Radev5c00d0d2017-08-07 10:06:59 +0300103
Jamie Madill2274b652018-05-31 10:56:08 -0400104 GLuint id() const { return mId; }
105
Jamie Madill48ef11b2016-04-27 15:21:52 -0400106 private:
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800107 const FramebufferAttachment *getWebGLDepthStencilAttachment() const;
Bryan Bernhart (Intel Americas Inc)5f198102017-12-12 14:21:39 -0800108 const FramebufferAttachment *getWebGLDepthAttachment() const;
109 const FramebufferAttachment *getWebGLStencilAttachment() const;
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800110
Jamie Madill48ef11b2016-04-27 15:21:52 -0400111 friend class Framebuffer;
112
Jamie Madill2274b652018-05-31 10:56:08 -0400113 GLuint mId;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400114 std::string mLabel;
115
116 std::vector<FramebufferAttachment> mColorAttachments;
117 FramebufferAttachment mDepthAttachment;
118 FramebufferAttachment mStencilAttachment;
119
120 std::vector<GLenum> mDrawBufferStates;
121 GLenum mReadBufferState;
Corentin Walleze7557742017-06-01 13:09:57 -0400122 DrawBufferMask mEnabledDrawBuffers;
Brandon Jonesc405ae72017-12-06 14:15:03 -0800123 ComponentTypeMask mDrawBufferTypeMask;
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800124
125 GLint mDefaultWidth;
126 GLint mDefaultHeight;
127 GLint mDefaultSamples;
Geoff Lang92019432017-11-20 13:09:34 -0500128 bool mDefaultFixedSampleLocations;
Jiawei Shaob1e91382018-05-17 14:33:55 +0800129 GLint mDefaultLayers;
Jamie Madilla02315b2017-02-23 14:14:47 -0500130
131 // It's necessary to store all this extra state so we can restore attachments
132 // when DEPTH_STENCIL/DEPTH/STENCIL is unbound in WebGL 1.
133 FramebufferAttachment mWebGLDepthStencilAttachment;
134 FramebufferAttachment mWebGLDepthAttachment;
135 FramebufferAttachment mWebGLStencilAttachment;
136 bool mWebGLDepthStencilConsistent;
Jamie Madill05b35b22017-10-03 09:01:44 -0400137
138 // Tracks if we need to initialize the resources for each attachment.
139 angle::BitSet<IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS + 2> mResourceNeedsInit;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400140};
141
Jamie Madilla11819d2018-07-30 10:26:01 -0400142class Framebuffer final : public angle::ObserverInterface,
143 public LabeledObject,
144 public angle::Subject
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000145{
146 public:
Corentin Wallezccab69d2017-01-27 16:57:15 -0500147 // Constructor to build application-defined framebuffers
Jamie Madill7aea7e02016-05-10 10:39:45 -0400148 Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id);
Geoff Langbf7b95d2018-05-01 16:48:21 -0400149 // Constructor to build default framebuffers for a surface and context pair
150 Framebuffer(const Context *context, egl::Surface *surface);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500151 // Constructor to build a fake default framebuffer when surfaceless
152 Framebuffer(rx::GLImplFactory *factory);
153
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500154 ~Framebuffer() override;
Jamie Madill4928b7c2017-06-20 12:57:39 -0400155 void onDestroy(const Context *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000156
Geoff Lang70d0f492015-12-10 17:45:46 -0500157 void setLabel(const std::string &label) override;
158 const std::string &getLabel() const override;
159
Jamie Madill51f40ec2016-06-15 14:06:00 -0400160 rx::FramebufferImpl *getImplementation() const { return mImpl; }
Geoff Langda88add2014-12-01 10:22:01 -0500161
Jamie Madill2274b652018-05-31 10:56:08 -0400162 GLuint id() const { return mState.mId; }
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400163
Jamie Madilla02315b2017-02-23 14:14:47 -0500164 void setAttachment(const Context *context,
165 GLenum type,
Jamie Madill2d06b732015-04-20 12:53:28 -0400166 GLenum binding,
167 const ImageIndex &textureIndex,
168 FramebufferAttachmentObject *resource);
Martin Radev82ef7742017-08-08 17:44:58 +0300169 void setAttachmentMultiviewLayered(const Context *context,
170 GLenum type,
171 GLenum binding,
172 const ImageIndex &textureIndex,
173 FramebufferAttachmentObject *resource,
174 GLsizei numViews,
175 GLint baseViewIndex);
Martin Radev5dae57b2017-07-14 16:15:55 +0300176 void setAttachmentMultiviewSideBySide(const Context *context,
177 GLenum type,
178 GLenum binding,
179 const ImageIndex &textureIndex,
180 FramebufferAttachmentObject *resource,
181 GLsizei numViews,
182 const GLint *viewportOffsets);
Jamie Madilla02315b2017-02-23 14:14:47 -0500183 void resetAttachment(const Context *context, GLenum binding);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000184
Jamie Madill8693bdb2017-09-02 15:32:14 -0400185 bool detachTexture(const Context *context, GLuint texture);
186 bool detachRenderbuffer(const Context *context, GLuint renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000187
Corentin Wallez37c39792015-08-20 14:19:46 -0400188 const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400189 const FramebufferAttachment *getDepthbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400190 const FramebufferAttachment *getStencilbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400191 const FramebufferAttachment *getDepthStencilBuffer() const;
192 const FramebufferAttachment *getDepthOrStencilbuffer() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500193 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400194 const FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +0000195 GLenum getReadColorbufferType() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400196 const FramebufferAttachment *getFirstColorbuffer() const;
Jamie Madill6dd06ea2017-07-19 13:47:55 -0400197 const FramebufferAttachment *getFirstNonNullAttachment() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000198
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -0800199 const FramebufferAttachment *getAttachment(const Context *context, GLenum attachment) const;
Martin Radev878c8b12017-07-28 09:51:04 +0300200 GLenum getMultiviewLayout() const;
Olli Etuaho8acb1b62018-07-30 16:20:54 +0300201 bool readDisallowedByMultiview() const;
Martin Radev14a26ae2017-07-24 15:56:29 +0300202 GLsizei getNumViews() const;
Martin Radev4e619f52017-08-09 11:50:06 +0300203 GLint getBaseViewIndex() const;
Martin Radev878c8b12017-07-28 09:51:04 +0300204 const std::vector<Offset> *getViewportOffsets() const;
Geoff Langc90d73a2013-07-22 16:39:23 -0400205
Geoff Langa15472a2015-08-11 11:48:03 -0400206 size_t getDrawbufferStateCount() const;
207 GLenum getDrawBufferState(size_t drawBuffer) const;
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500208 const std::vector<GLenum> &getDrawBufferStates() const;
Geoff Lang164d54e2014-12-01 10:55:33 -0500209 void setDrawBuffers(size_t count, const GLenum *buffers);
Geoff Langa15472a2015-08-11 11:48:03 -0400210 const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
Geoff Lange0cff192017-05-30 13:04:56 -0400211 GLenum getDrawbufferWriteType(size_t drawBuffer) const;
Brandon Jonesc405ae72017-12-06 14:15:03 -0800212 ComponentTypeMask getDrawBufferTypeMask() const;
Brandon Jones76746f92017-11-22 11:44:41 -0800213 DrawBufferMask getDrawBufferMask() const;
Geoff Langa15472a2015-08-11 11:48:03 -0400214 bool hasEnabledDrawBuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000215
Geoff Lang9dd95802014-12-01 11:12:59 -0500216 GLenum getReadBufferState() const;
217 void setReadBuffer(GLenum buffer);
218
Corentin Wallez37c39792015-08-20 14:19:46 -0400219 size_t getNumColorBuffers() const;
Jamie Madill0df8fe42015-11-24 16:10:24 -0500220 bool hasDepth() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000221 bool hasStencil() const;
Jamie Madill51f40ec2016-06-15 14:06:00 -0400222
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000223 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000224
Jamie Madill51f40ec2016-06-15 14:06:00 -0400225 // This method calls checkStatus.
Jamie Madill427064d2018-04-13 16:20:34 -0400226 int getSamples(const Context *context);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800227
Geoff Lang13455072018-05-09 11:24:43 -0400228 Error getSamplePosition(const Context *context, size_t index, GLfloat *xy) const;
JiangYizhoubddc46b2016-12-09 09:50:51 +0800229
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800230 GLint getDefaultWidth() const;
231 GLint getDefaultHeight() const;
232 GLint getDefaultSamples() const;
Geoff Lang92019432017-11-20 13:09:34 -0500233 bool getDefaultFixedSampleLocations() const;
Jiawei Shaob1e91382018-05-17 14:33:55 +0800234 GLint getDefaultLayers() const;
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800235 void setDefaultWidth(GLint defaultWidth);
236 void setDefaultHeight(GLint defaultHeight);
237 void setDefaultSamples(GLint defaultSamples);
Geoff Lang92019432017-11-20 13:09:34 -0500238 void setDefaultFixedSampleLocations(bool defaultFixedSampleLocations);
Jiawei Shaob1e91382018-05-17 14:33:55 +0800239 void setDefaultLayers(GLint defaultLayers);
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800240
Geoff Lang9aded172017-04-05 11:07:56 -0400241 void invalidateCompletenessCache();
242
Jamie Madillcc73f242018-08-01 11:34:48 -0400243 GLenum checkStatus(const Context *context)
244 {
245 // The default framebuffer is always complete except when it is surfaceless in which
246 // case it is always unsupported.
247 ASSERT(mState.mId != 0 || mCachedStatus.valid());
248 if (mState.mId == 0 || (!hasAnyDirtyBit() && mCachedStatus.valid()))
249 {
250 return mCachedStatus.value();
251 }
252
253 return checkStatusImpl(context);
254 }
Jamie Madilldd43e6c2017-03-24 14:18:49 -0400255
Jamie Madill9c335862017-07-18 11:51:38 -0400256 // For when we don't want to check completeness in getSamples().
257 int getCachedSamples(const Context *context);
258
Jamie Madill362876b2016-06-16 14:46:59 -0400259 // Helper for checkStatus == GL_FRAMEBUFFER_COMPLETE.
Jamie Madillcc73f242018-08-01 11:34:48 -0400260 bool isComplete(const Context *context)
261 {
262 return (checkStatus(context) == GL_FRAMEBUFFER_COMPLETE);
263 }
Jamie Madill51f40ec2016-06-15 14:06:00 -0400264
Jamie Madille92a3542014-07-03 10:38:58 -0400265 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000266
Jamie Madill4928b7c2017-06-20 12:57:39 -0400267 Error discard(const Context *context, size_t count, const GLenum *attachments);
268 Error invalidate(const Context *context, size_t count, const GLenum *attachments);
269 Error invalidateSub(const Context *context,
270 size_t count,
271 const GLenum *attachments,
Jamie Madilld4442552018-02-27 22:03:47 -0500272 const Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400273
Jamie Madilld4442552018-02-27 22:03:47 -0500274 Error clear(const Context *context, GLbitfield mask);
275 Error clearBufferfv(const Context *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500276 GLenum buffer,
277 GLint drawbuffer,
278 const GLfloat *values);
Jamie Madilld4442552018-02-27 22:03:47 -0500279 Error clearBufferuiv(const Context *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500280 GLenum buffer,
281 GLint drawbuffer,
282 const GLuint *values);
Jamie Madilld4442552018-02-27 22:03:47 -0500283 Error clearBufferiv(const Context *context,
Jamie Madill9082b982016-04-27 15:21:51 -0400284 GLenum buffer,
285 GLint drawbuffer,
286 const GLint *values);
Jamie Madilld4442552018-02-27 22:03:47 -0500287 Error clearBufferfi(const Context *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400288 GLenum buffer,
289 GLint drawbuffer,
290 GLfloat depth,
291 GLint stencil);
Geoff Langb04dc822014-12-01 12:02:02 -0500292
Jamie Madill690c8eb2018-03-12 15:20:03 -0400293 // These two methods call syncState() internally.
294 Error getImplementationColorReadFormat(const Context *context, GLenum *formatOut);
295 Error getImplementationColorReadType(const Context *context, GLenum *typeOut);
296
Jamie Madilld4442552018-02-27 22:03:47 -0500297 Error readPixels(const Context *context,
298 const Rectangle &area,
Jamie Madill1b94d432015-08-07 13:23:23 -0400299 GLenum format,
300 GLenum type,
Jamie Madill05b35b22017-10-03 09:01:44 -0400301 void *pixels);
Geoff Langbce529e2014-12-01 12:48:41 -0500302
Jamie Madilld4442552018-02-27 22:03:47 -0500303 Error blit(const Context *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500304 const Rectangle &sourceArea,
305 const Rectangle &destArea,
Geoff Lang242468f2015-09-24 14:15:41 -0400306 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400307 GLenum filter);
Luc Ferronbf6dc372018-06-28 15:24:19 -0400308 bool isDefault() const;
Geoff Lang54bd5a42014-12-01 12:51:04 -0500309
Jamie Madill05b35b22017-10-03 09:01:44 -0400310 enum DirtyBitType : size_t
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500311 {
312 DIRTY_BIT_COLOR_ATTACHMENT_0,
313 DIRTY_BIT_COLOR_ATTACHMENT_MAX =
Jamie Madilld4442552018-02-27 22:03:47 -0500314 DIRTY_BIT_COLOR_ATTACHMENT_0 + IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500315 DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
316 DIRTY_BIT_STENCIL_ATTACHMENT,
317 DIRTY_BIT_DRAW_BUFFERS,
318 DIRTY_BIT_READ_BUFFER,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800319 DIRTY_BIT_DEFAULT_WIDTH,
320 DIRTY_BIT_DEFAULT_HEIGHT,
321 DIRTY_BIT_DEFAULT_SAMPLES,
322 DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS,
Jiawei Shaob1e91382018-05-17 14:33:55 +0800323 DIRTY_BIT_DEFAULT_LAYERS,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500324 DIRTY_BIT_UNKNOWN,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800325 DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500326 };
327
Yunchao He1f679cc2017-11-29 18:06:00 +0800328 using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500329 bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
330
Jamie Madill19fa1c62018-03-08 09:47:21 -0500331 Error syncState(const Context *context);
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500332
Jamie Madilld4442552018-02-27 22:03:47 -0500333 // Observer implementation
334 void onSubjectStateChange(const Context *context,
335 angle::SubjectIndex index,
336 angle::SubjectMessage message) override;
Jamie Madill362876b2016-06-16 14:46:59 -0400337
Jamie Madilla4595b82017-01-11 17:36:34 -0500338 bool formsRenderingFeedbackLoopWith(const State &state) const;
Jamie Madillfd3dd432017-02-02 19:59:59 -0500339 bool formsCopyingFeedbackLoopWith(GLuint copyTextureID,
340 GLint copyTextureLevel,
341 GLint copyTextureLayer) const;
Jamie Madilla4595b82017-01-11 17:36:34 -0500342
Geoff Langd4fff502017-09-22 11:28:28 -0400343 Error ensureClearAttachmentsInitialized(const Context *context, GLbitfield mask);
344 Error ensureClearBufferAttachmentsInitialized(const Context *context,
345 GLenum buffer,
346 GLint drawbuffer);
Jamie Madill05b35b22017-10-03 09:01:44 -0400347 Error ensureDrawAttachmentsInitialized(const Context *context);
348 Error ensureReadAttachmentInitialized(const Context *context, GLbitfield blitMask);
349 Box getDimensions() const;
350
Jamie Madill42975642017-10-12 12:31:51 -0400351 bool hasTextureAttachment(const Texture *texture) const;
352
Jamie Madill362876b2016-06-16 14:46:59 -0400353 private:
Jamie Madill8693bdb2017-09-02 15:32:14 -0400354 bool detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
355 bool detachMatchingAttachment(const Context *context,
Jamie Madill4928b7c2017-06-20 12:57:39 -0400356 FramebufferAttachment *attachment,
Jamie Madill362876b2016-06-16 14:46:59 -0400357 GLenum matchType,
358 GLuint matchId,
359 size_t dirtyBit);
Jamie Madille98b1b52018-03-08 09:47:23 -0500360 GLenum checkStatusWithGLFrontEnd(const Context *context);
Jamie Madillcc73f242018-08-01 11:34:48 -0400361 GLenum checkStatusImpl(const Context *context);
Martin Radev5dae57b2017-07-14 16:15:55 +0300362 void setAttachment(const Context *context,
363 GLenum type,
364 GLenum binding,
365 const ImageIndex &textureIndex,
366 FramebufferAttachmentObject *resource,
367 GLsizei numViews,
368 GLuint baseViewIndex,
369 GLenum multiviewLayout,
370 const GLint *viewportOffsets);
371 void commitWebGL1DepthStencilIfConsistent(const Context *context,
372 GLsizei numViews,
373 GLuint baseViewIndex,
374 GLenum multiviewLayout,
375 const GLint *viewportOffsets);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400376 void setAttachmentImpl(const Context *context,
377 GLenum type,
Jamie Madilla02315b2017-02-23 14:14:47 -0500378 GLenum binding,
379 const ImageIndex &textureIndex,
Martin Radev5dae57b2017-07-14 16:15:55 +0300380 FramebufferAttachmentObject *resource,
381 GLsizei numViews,
382 GLuint baseViewIndex,
383 GLenum multiviewLayout,
384 const GLint *viewportOffsets);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400385 void updateAttachment(const Context *context,
386 FramebufferAttachment *attachment,
Jamie Madillb8126692017-04-05 11:22:17 -0400387 size_t dirtyBit,
Jamie Madilld4442552018-02-27 22:03:47 -0500388 angle::ObserverBinding *onDirtyBinding,
Jamie Madillb8126692017-04-05 11:22:17 -0400389 GLenum type,
390 GLenum binding,
391 const ImageIndex &textureIndex,
Martin Radev5dae57b2017-07-14 16:15:55 +0300392 FramebufferAttachmentObject *resource,
393 GLsizei numViews,
394 GLuint baseViewIndex,
395 GLenum multiviewLayout,
396 const GLint *viewportOffsets);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500397
Jamie Madill05b35b22017-10-03 09:01:44 -0400398 void markDrawAttachmentsInitialized(bool color, bool depth, bool stencil);
399 void markBufferInitialized(GLenum bufferType, GLint bufferIndex);
400 Error ensureBufferInitialized(const Context *context, GLenum bufferType, GLint bufferIndex);
401
402 // Checks that we have a partially masked clear:
403 // * some color channels are masked out
404 // * some stencil values are masked out
405 // * scissor test partially overlaps the framebuffer
406 bool partialClearNeedsInit(const Context *context, bool color, bool depth, bool stencil);
407 bool partialBufferClearNeedsInit(const Context *context, GLenum bufferType);
408
Jamie Madilld4442552018-02-27 22:03:47 -0500409 FramebufferAttachment *getAttachmentFromSubjectIndex(angle::SubjectIndex index);
410
Jamie Madill48ef11b2016-04-27 15:21:52 -0400411 FramebufferState mState;
Geoff Langda88add2014-12-01 10:22:01 -0500412 rx::FramebufferImpl *mImpl;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500413
Jamie Madill362876b2016-06-16 14:46:59 -0400414 Optional<GLenum> mCachedStatus;
Jamie Madilld4442552018-02-27 22:03:47 -0500415 std::vector<angle::ObserverBinding> mDirtyColorAttachmentBindings;
416 angle::ObserverBinding mDirtyDepthAttachmentBinding;
417 angle::ObserverBinding mDirtyStencilAttachmentBinding;
Jamie Madill362876b2016-06-16 14:46:59 -0400418
419 DirtyBits mDirtyBits;
Jamie Madill42975642017-10-12 12:31:51 -0400420
Jamie Madill888081d2018-02-27 00:24:46 -0500421 // The dirty bits guard is checked when we get a dependent state change message. We verify that
422 // we don't set a dirty bit that isn't already set, when inside the dirty bits syncState.
423 Optional<DirtyBits> mDirtyBitsGuard;
424
Jamie Madill42975642017-10-12 12:31:51 -0400425 // A cache of attached textures for quick validation of feedback loops.
Geoff Langb8430dd2018-08-01 15:27:18 -0400426 using FramebufferTextureAttachmentVector =
427 angle::FixedVector<const FramebufferAttachmentObject *,
428 IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS>;
429 mutable Optional<FramebufferTextureAttachmentVector> mAttachedTextures;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000430};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000431
Jamie Madill362876b2016-06-16 14:46:59 -0400432} // namespace gl
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000433
Jamie Madill231c7f52017-04-26 13:45:37 -0400434#endif // LIBANGLE_FRAMEBUFFER_H_