blob: 478ce08d64bc9bf79194572e9ca2272252b96d94 [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{
35class 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 Madill48ef11b2016-04-27 15:21:52 -040041class Framebuffer;
Geoff Langab75a052014-10-15 12:56:37 -040042class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050043class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050044class Texture;
45class TextureCapsMap;
46struct Caps;
Jamie Madilldfde6ab2016-06-09 07:07:18 -070047class ContextState;
Jamie Madilld1405e52015-03-05 15:41:39 -050048struct Extensions;
49struct ImageIndex;
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();
56 explicit FramebufferState(const Caps &caps);
57 ~FramebufferState();
58
59 const std::string &getLabel();
60
Geoff Lang4b7f12b2016-06-21 16:47:07 -040061 const FramebufferAttachment *getAttachment(GLenum attachment) const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040062 const FramebufferAttachment *getReadAttachment() const;
Jamie Madill7b57b9d2017-01-13 09:33:38 -050063 const FramebufferAttachment *getFirstNonNullAttachment() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040064 const FramebufferAttachment *getFirstColorAttachment() const;
65 const FramebufferAttachment *getDepthOrStencilAttachment() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -050066 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040067 const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
68 const FramebufferAttachment *getDepthAttachment() const;
69 const FramebufferAttachment *getStencilAttachment() const;
70 const FramebufferAttachment *getDepthStencilAttachment() const;
71
72 const std::vector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
73 GLenum getReadBufferState() const { return mReadBufferState; }
74 const std::vector<FramebufferAttachment> &getColorAttachments() const
75 {
76 return mColorAttachments;
77 }
78
79 bool attachmentsHaveSameDimensions() const;
Geoff Langb21e20d2016-07-19 15:35:41 -040080 bool colorAttachmentsAreUniqueImages() const;
Jamie Madill48ef11b2016-04-27 15:21:52 -040081
Geoff Lang4b7f12b2016-06-21 16:47:07 -040082 const FramebufferAttachment *getDrawBuffer(size_t drawBufferIdx) const;
83 size_t getDrawBufferCount() const;
84
Jamie Madill48ef11b2016-04-27 15:21:52 -040085 private:
86 friend class Framebuffer;
87
88 std::string mLabel;
89
90 std::vector<FramebufferAttachment> mColorAttachments;
91 FramebufferAttachment mDepthAttachment;
92 FramebufferAttachment mStencilAttachment;
93
94 std::vector<GLenum> mDrawBufferStates;
95 GLenum mReadBufferState;
Jamie Madilla4595b82017-01-11 17:36:34 -050096 std::bitset<IMPLEMENTATION_MAX_DRAW_BUFFERS> mEnabledDrawBuffers;
Jamie Madill48ef11b2016-04-27 15:21:52 -040097};
98
Jamie Madill362876b2016-06-16 14:46:59 -040099class Framebuffer final : public LabeledObject, public angle::SignalReceiver
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000100{
101 public:
Corentin Wallezccab69d2017-01-27 16:57:15 -0500102 // Constructor to build application-defined framebuffers
Jamie Madill7aea7e02016-05-10 10:39:45 -0400103 Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500104 // Constructor to build default framebuffers for a surface
Corentin Wallez37c39792015-08-20 14:19:46 -0400105 Framebuffer(rx::SurfaceImpl *surface);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500106 // Constructor to build a fake default framebuffer when surfaceless
107 Framebuffer(rx::GLImplFactory *factory);
108
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000109 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000110
Geoff Lang70d0f492015-12-10 17:45:46 -0500111 void setLabel(const std::string &label) override;
112 const std::string &getLabel() const override;
113
Jamie Madill51f40ec2016-06-15 14:06:00 -0400114 rx::FramebufferImpl *getImplementation() const { return mImpl; }
Geoff Langda88add2014-12-01 10:22:01 -0500115
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400116 GLuint id() const { return mId; }
117
Jamie Madill2d06b732015-04-20 12:53:28 -0400118 void setAttachment(GLenum type,
119 GLenum binding,
120 const ImageIndex &textureIndex,
121 FramebufferAttachmentObject *resource);
122 void resetAttachment(GLenum binding);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123
124 void detachTexture(GLuint texture);
125 void detachRenderbuffer(GLuint renderbuffer);
126
Corentin Wallez37c39792015-08-20 14:19:46 -0400127 const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400128 const FramebufferAttachment *getDepthbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400129 const FramebufferAttachment *getStencilbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400130 const FramebufferAttachment *getDepthStencilBuffer() const;
131 const FramebufferAttachment *getDepthOrStencilbuffer() const;
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500132 const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400133 const FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +0000134 GLenum getReadColorbufferType() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400135 const FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000136
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400137 const FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -0400138
Geoff Langa15472a2015-08-11 11:48:03 -0400139 size_t getDrawbufferStateCount() const;
140 GLenum getDrawBufferState(size_t drawBuffer) const;
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500141 const std::vector<GLenum> &getDrawBufferStates() const;
Geoff Lang164d54e2014-12-01 10:55:33 -0500142 void setDrawBuffers(size_t count, const GLenum *buffers);
Geoff Langa15472a2015-08-11 11:48:03 -0400143 const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
144 bool hasEnabledDrawBuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000145
Geoff Lang9dd95802014-12-01 11:12:59 -0500146 GLenum getReadBufferState() const;
147 void setReadBuffer(GLenum buffer);
148
Corentin Wallez37c39792015-08-20 14:19:46 -0400149 size_t getNumColorBuffers() const;
Jamie Madill0df8fe42015-11-24 16:10:24 -0500150 bool hasDepth() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000151 bool hasStencil() const;
Jamie Madill51f40ec2016-06-15 14:06:00 -0400152
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000153 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000154
Jamie Madill51f40ec2016-06-15 14:06:00 -0400155 // This method calls checkStatus.
156 int getSamples(const ContextState &state);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800157
158 Error getSamplePosition(size_t index, GLfloat *xy) const;
159
Jamie Madill51f40ec2016-06-15 14:06:00 -0400160 GLenum checkStatus(const ContextState &state);
161
Jamie Madill362876b2016-06-16 14:46:59 -0400162 // Helper for checkStatus == GL_FRAMEBUFFER_COMPLETE.
163 bool complete(const ContextState &state);
Jamie Madill51f40ec2016-06-15 14:06:00 -0400164
Jamie Madille92a3542014-07-03 10:38:58 -0400165 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000166
Austin Kinross08332632015-05-05 13:35:47 -0700167 Error discard(size_t count, const GLenum *attachments);
Geoff Lang9ad4bda2014-12-01 11:03:09 -0500168 Error invalidate(size_t count, const GLenum *attachments);
169 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400170
Jamie Madill8415b5f2016-04-26 13:41:39 -0400171 Error clear(rx::ContextImpl *context, GLbitfield mask);
172 Error clearBufferfv(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500173 GLenum buffer,
174 GLint drawbuffer,
175 const GLfloat *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400176 Error clearBufferuiv(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500177 GLenum buffer,
178 GLint drawbuffer,
179 const GLuint *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400180 Error clearBufferiv(rx::ContextImpl *context,
Jamie Madill9082b982016-04-27 15:21:51 -0400181 GLenum buffer,
182 GLint drawbuffer,
183 const GLint *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400184 Error clearBufferfi(rx::ContextImpl *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400185 GLenum buffer,
186 GLint drawbuffer,
187 GLfloat depth,
188 GLint stencil);
Geoff Langb04dc822014-12-01 12:02:02 -0500189
Geoff Langbce529e2014-12-01 12:48:41 -0500190 GLenum getImplementationColorReadFormat() const;
191 GLenum getImplementationColorReadType() const;
Jamie Madill8415b5f2016-04-26 13:41:39 -0400192 Error readPixels(rx::ContextImpl *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400193 const gl::Rectangle &area,
194 GLenum format,
195 GLenum type,
196 GLvoid *pixels) const;
Geoff Langbce529e2014-12-01 12:48:41 -0500197
Jamie Madill8415b5f2016-04-26 13:41:39 -0400198 Error blit(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500199 const Rectangle &sourceArea,
200 const Rectangle &destArea,
Geoff Lang242468f2015-09-24 14:15:41 -0400201 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400202 GLenum filter);
Geoff Lang54bd5a42014-12-01 12:51:04 -0500203
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500204 enum DirtyBitType
205 {
206 DIRTY_BIT_COLOR_ATTACHMENT_0,
207 DIRTY_BIT_COLOR_ATTACHMENT_MAX =
208 DIRTY_BIT_COLOR_ATTACHMENT_0 + gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
209 DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
210 DIRTY_BIT_STENCIL_ATTACHMENT,
211 DIRTY_BIT_DRAW_BUFFERS,
212 DIRTY_BIT_READ_BUFFER,
213 DIRTY_BIT_UNKNOWN,
214 DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN,
215 };
216
217 typedef std::bitset<DIRTY_BIT_MAX> DirtyBits;
218 bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
219
Jamie Madill362876b2016-06-16 14:46:59 -0400220 void syncState();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500221
Jamie Madill362876b2016-06-16 14:46:59 -0400222 // angle::SignalReceiver implementation
223 void signal(angle::SignalToken token) override;
224
Jamie Madilla4595b82017-01-11 17:36:34 -0500225 bool formsRenderingFeedbackLoopWith(const State &state) const;
Jamie Madillf695a3a2017-01-11 17:36:35 -0500226 bool formsCopyingFeedbackLoopWith(GLuint copyTextureID, GLint copyTextureLevel) const;
Jamie Madilla4595b82017-01-11 17:36:34 -0500227
Jamie Madill362876b2016-06-16 14:46:59 -0400228 private:
Jamie Madilld1405e52015-03-05 15:41:39 -0500229 void detachResourceById(GLenum resourceType, GLuint resourceId);
Jamie Madill362876b2016-06-16 14:46:59 -0400230 void detachMatchingAttachment(FramebufferAttachment *attachment,
231 GLenum matchType,
232 GLuint matchId,
233 size_t dirtyBit);
234 GLenum checkStatusImpl(const ContextState &state);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500235
Jamie Madill48ef11b2016-04-27 15:21:52 -0400236 FramebufferState mState;
Geoff Langda88add2014-12-01 10:22:01 -0500237 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400238 GLuint mId;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500239
Jamie Madill362876b2016-06-16 14:46:59 -0400240 Optional<GLenum> mCachedStatus;
241 std::vector<angle::ChannelBinding> mDirtyColorAttachmentBindings;
242 angle::ChannelBinding mDirtyDepthAttachmentBinding;
243 angle::ChannelBinding mDirtyStencilAttachmentBinding;
244
245 DirtyBits mDirtyBits;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000246};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000247
Jamie Madill362876b2016-06-16 14:46:59 -0400248} // namespace gl
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000249
Geoff Lang0a73dd82014-11-19 16:18:08 -0500250#endif // LIBANGLE_FRAMEBUFFER_H_