blob: 78d598d84f00cbec97b796a51784f9b408b7f9f5 [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 Madill7147f012015-03-05 15:41:40 -050021#include "libANGLE/RefCountObject.h"
Jamie Madill362876b2016-06-16 14:46:59 -040022#include "libANGLE/signal_utils.h"
Geoff Lang64f23f62014-09-10 14:40:12 -040023
daniel@transgaming.com16418b12012-11-28 19:32:22 +000024namespace rx
25{
Jamie Madill8415b5f2016-04-26 13:41:39 -040026class ContextImpl;
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 Madill48ef11b2016-04-27 15:21:52 -040042class Framebuffer;
Geoff Langab75a052014-10-15 12:56:37 -040043class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050044class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050045class Texture;
46class TextureCapsMap;
47struct Caps;
Jamie Madilldfde6ab2016-06-09 07:07:18 -070048class ContextState;
Jamie Madilld1405e52015-03-05 15:41:39 -050049struct Extensions;
50struct ImageIndex;
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();
57 explicit FramebufferState(const Caps &caps);
58 ~FramebufferState();
59
60 const std::string &getLabel();
61
Geoff Lang4b7f12b2016-06-21 16:47:07 -040062 const FramebufferAttachment *getAttachment(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; }
74 GLenum getReadBufferState() const { return mReadBufferState; }
75 const std::vector<FramebufferAttachment> &getColorAttachments() const
76 {
77 return mColorAttachments;
78 }
79
80 bool attachmentsHaveSameDimensions() const;
Geoff Langb21e20d2016-07-19 15:35:41 -040081 bool colorAttachmentsAreUniqueImages() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040082
Geoff Lang4b7f12b2016-06-21 16:47:07 -040083 const FramebufferAttachment *getDrawBuffer(size_t drawBufferIdx) const;
84 size_t getDrawBufferCount() const;
85
JiangYizhouf7bbc8a2016-11-16 09:57:22 +080086 GLint getDefaultWidth() const { return mDefaultWidth; };
87 GLint getDefaultHeight() const { return mDefaultHeight; };
88 GLint getDefaultSamples() const { return mDefaultSamples; };
89 GLboolean getDefaultFixedSampleLocations() const { return mDefaultFixedSampleLocations; };
90
Jamie Madill48ef11b2016-04-27 15:21:52 -040091 private:
92 friend class Framebuffer;
93
94 std::string mLabel;
95
96 std::vector<FramebufferAttachment> mColorAttachments;
97 FramebufferAttachment mDepthAttachment;
98 FramebufferAttachment mStencilAttachment;
99
100 std::vector<GLenum> mDrawBufferStates;
101 GLenum mReadBufferState;
Jamie Madilla4595b82017-01-11 17:36:34 -0500102 std::bitset<IMPLEMENTATION_MAX_DRAW_BUFFERS> mEnabledDrawBuffers;
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800103
104 GLint mDefaultWidth;
105 GLint mDefaultHeight;
106 GLint mDefaultSamples;
107 GLboolean mDefaultFixedSampleLocations;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400108};
109
Jamie Madill362876b2016-06-16 14:46:59 -0400110class Framebuffer final : public LabeledObject, public angle::SignalReceiver
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000111{
112 public:
Corentin Wallezccab69d2017-01-27 16:57:15 -0500113 // Constructor to build application-defined framebuffers
Jamie Madill7aea7e02016-05-10 10:39:45 -0400114 Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500115 // Constructor to build default framebuffers for a surface
Jamie Madill6f60d052017-02-22 15:20:11 -0500116 Framebuffer(egl::Surface *surface);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500117 // Constructor to build a fake default framebuffer when surfaceless
118 Framebuffer(rx::GLImplFactory *factory);
119
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000120 virtual ~Framebuffer();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500121 void destroy(const Context *context);
122 void destroyDefault(const egl::Display *display);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123
Geoff Lang70d0f492015-12-10 17:45:46 -0500124 void setLabel(const std::string &label) override;
125 const std::string &getLabel() const override;
126
Jamie Madill51f40ec2016-06-15 14:06:00 -0400127 rx::FramebufferImpl *getImplementation() const { return mImpl; }
Geoff Langda88add2014-12-01 10:22:01 -0500128
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400129 GLuint id() const { return mId; }
130
Jamie Madill2d06b732015-04-20 12:53:28 -0400131 void setAttachment(GLenum type,
132 GLenum binding,
133 const ImageIndex &textureIndex,
134 FramebufferAttachmentObject *resource);
135 void resetAttachment(GLenum binding);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000136
137 void detachTexture(GLuint texture);
138 void detachRenderbuffer(GLuint renderbuffer);
139
Corentin Wallez37c39792015-08-20 14:19:46 -0400140 const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400141 const FramebufferAttachment *getDepthbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400142 const FramebufferAttachment *getStencilbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400143 const FramebufferAttachment *getDepthStencilBuffer() const;
144 const FramebufferAttachment *getDepthOrStencilbuffer() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500145 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400146 const FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +0000147 GLenum getReadColorbufferType() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400148 const FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400150 const FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -0400151
Geoff Langa15472a2015-08-11 11:48:03 -0400152 size_t getDrawbufferStateCount() const;
153 GLenum getDrawBufferState(size_t drawBuffer) const;
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500154 const std::vector<GLenum> &getDrawBufferStates() const;
Geoff Lang164d54e2014-12-01 10:55:33 -0500155 void setDrawBuffers(size_t count, const GLenum *buffers);
Geoff Langa15472a2015-08-11 11:48:03 -0400156 const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
157 bool hasEnabledDrawBuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000158
Geoff Lang9dd95802014-12-01 11:12:59 -0500159 GLenum getReadBufferState() const;
160 void setReadBuffer(GLenum buffer);
161
Corentin Wallez37c39792015-08-20 14:19:46 -0400162 size_t getNumColorBuffers() const;
Jamie Madill0df8fe42015-11-24 16:10:24 -0500163 bool hasDepth() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000164 bool hasStencil() const;
Jamie Madill51f40ec2016-06-15 14:06:00 -0400165
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000166 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000167
Jamie Madill51f40ec2016-06-15 14:06:00 -0400168 // This method calls checkStatus.
169 int getSamples(const ContextState &state);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800170
171 Error getSamplePosition(size_t index, GLfloat *xy) const;
172
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800173 GLint getDefaultWidth() const;
174 GLint getDefaultHeight() const;
175 GLint getDefaultSamples() const;
176 GLboolean getDefaultFixedSampleLocations() const;
177 void setDefaultWidth(GLint defaultWidth);
178 void setDefaultHeight(GLint defaultHeight);
179 void setDefaultSamples(GLint defaultSamples);
180 void setDefaultFixedSampleLocations(GLboolean defaultFixedSampleLocations);
181
Jamie Madill51f40ec2016-06-15 14:06:00 -0400182 GLenum checkStatus(const ContextState &state);
183
Jamie Madill362876b2016-06-16 14:46:59 -0400184 // Helper for checkStatus == GL_FRAMEBUFFER_COMPLETE.
185 bool complete(const ContextState &state);
Jamie Madill51f40ec2016-06-15 14:06:00 -0400186
Jamie Madille92a3542014-07-03 10:38:58 -0400187 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000188
Austin Kinross08332632015-05-05 13:35:47 -0700189 Error discard(size_t count, const GLenum *attachments);
Geoff Lang9ad4bda2014-12-01 11:03:09 -0500190 Error invalidate(size_t count, const GLenum *attachments);
191 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400192
Jamie Madill8415b5f2016-04-26 13:41:39 -0400193 Error clear(rx::ContextImpl *context, GLbitfield mask);
194 Error clearBufferfv(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500195 GLenum buffer,
196 GLint drawbuffer,
197 const GLfloat *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400198 Error clearBufferuiv(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500199 GLenum buffer,
200 GLint drawbuffer,
201 const GLuint *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400202 Error clearBufferiv(rx::ContextImpl *context,
Jamie Madill9082b982016-04-27 15:21:51 -0400203 GLenum buffer,
204 GLint drawbuffer,
205 const GLint *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400206 Error clearBufferfi(rx::ContextImpl *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400207 GLenum buffer,
208 GLint drawbuffer,
209 GLfloat depth,
210 GLint stencil);
Geoff Langb04dc822014-12-01 12:02:02 -0500211
Geoff Langbce529e2014-12-01 12:48:41 -0500212 GLenum getImplementationColorReadFormat() const;
213 GLenum getImplementationColorReadType() const;
Jamie Madill8415b5f2016-04-26 13:41:39 -0400214 Error readPixels(rx::ContextImpl *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400215 const gl::Rectangle &area,
216 GLenum format,
217 GLenum type,
218 GLvoid *pixels) const;
Geoff Langbce529e2014-12-01 12:48:41 -0500219
Jamie Madill8415b5f2016-04-26 13:41:39 -0400220 Error blit(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500221 const Rectangle &sourceArea,
222 const Rectangle &destArea,
Geoff Lang242468f2015-09-24 14:15:41 -0400223 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400224 GLenum filter);
Geoff Lang54bd5a42014-12-01 12:51:04 -0500225
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500226 enum DirtyBitType
227 {
228 DIRTY_BIT_COLOR_ATTACHMENT_0,
229 DIRTY_BIT_COLOR_ATTACHMENT_MAX =
230 DIRTY_BIT_COLOR_ATTACHMENT_0 + gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
231 DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
232 DIRTY_BIT_STENCIL_ATTACHMENT,
233 DIRTY_BIT_DRAW_BUFFERS,
234 DIRTY_BIT_READ_BUFFER,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800235 DIRTY_BIT_DEFAULT_WIDTH,
236 DIRTY_BIT_DEFAULT_HEIGHT,
237 DIRTY_BIT_DEFAULT_SAMPLES,
238 DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500239 DIRTY_BIT_UNKNOWN,
JiangYizhouf7bbc8a2016-11-16 09:57:22 +0800240 DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500241 };
242
243 typedef std::bitset<DIRTY_BIT_MAX> DirtyBits;
244 bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
245
Jamie Madill362876b2016-06-16 14:46:59 -0400246 void syncState();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500247
Jamie Madill362876b2016-06-16 14:46:59 -0400248 // angle::SignalReceiver implementation
249 void signal(angle::SignalToken token) override;
250
Jamie Madilla4595b82017-01-11 17:36:34 -0500251 bool formsRenderingFeedbackLoopWith(const State &state) const;
Jamie Madillfd3dd432017-02-02 19:59:59 -0500252 bool formsCopyingFeedbackLoopWith(GLuint copyTextureID,
253 GLint copyTextureLevel,
254 GLint copyTextureLayer) const;
Jamie Madilla4595b82017-01-11 17:36:34 -0500255
Jamie Madill362876b2016-06-16 14:46:59 -0400256 private:
Jamie Madilld1405e52015-03-05 15:41:39 -0500257 void detachResourceById(GLenum resourceType, GLuint resourceId);
Jamie Madill362876b2016-06-16 14:46:59 -0400258 void detachMatchingAttachment(FramebufferAttachment *attachment,
259 GLenum matchType,
260 GLuint matchId,
261 size_t dirtyBit);
262 GLenum checkStatusImpl(const ContextState &state);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500263
Jamie Madill48ef11b2016-04-27 15:21:52 -0400264 FramebufferState mState;
Geoff Langda88add2014-12-01 10:22:01 -0500265 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400266 GLuint mId;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500267
Jamie Madill362876b2016-06-16 14:46:59 -0400268 Optional<GLenum> mCachedStatus;
269 std::vector<angle::ChannelBinding> mDirtyColorAttachmentBindings;
270 angle::ChannelBinding mDirtyDepthAttachmentBinding;
271 angle::ChannelBinding mDirtyStencilAttachmentBinding;
272
273 DirtyBits mDirtyBits;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000274};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000275
Jamie Madill362876b2016-06-16 14:46:59 -0400276} // namespace gl
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000277
Geoff Lang0a73dd82014-11-19 16:18:08 -0500278#endif // LIBANGLE_FRAMEBUFFER_H_