blob: 19edb824de9e22f6bd03999db5586c4dcf8735ec [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
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000015#include "common/angleutils.h"
Jamie Madill7147f012015-03-05 15:41:40 -050016#include "libANGLE/Constants.h"
Geoff Lang70d0f492015-12-10 17:45:46 -050017#include "libANGLE/Debug.h"
Jamie Madill7147f012015-03-05 15:41:40 -050018#include "libANGLE/Error.h"
Jamie Madill2d06b732015-04-20 12:53:28 -040019#include "libANGLE/FramebufferAttachment.h"
Jamie Madill7147f012015-03-05 15:41:40 -050020#include "libANGLE/RefCountObject.h"
Geoff Lang64f23f62014-09-10 14:40:12 -040021
daniel@transgaming.com16418b12012-11-28 19:32:22 +000022namespace rx
23{
Jamie Madill8415b5f2016-04-26 13:41:39 -040024class ContextImpl;
Jamie Madill7aea7e02016-05-10 10:39:45 -040025class GLImplFactory;
Geoff Langda88add2014-12-01 10:22:01 -050026class FramebufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050027class RenderbufferImpl;
Corentin Wallez37c39792015-08-20 14:19:46 -040028class SurfaceImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050029}
30
31namespace egl
32{
33class Surface;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000034}
35
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000036namespace gl
37{
Jamie Madill1b94d432015-08-07 13:23:23 -040038class Context;
Jamie Madill48ef11b2016-04-27 15:21:52 -040039class Framebuffer;
Geoff Langab75a052014-10-15 12:56:37 -040040class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050041class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050042class Texture;
43class TextureCapsMap;
44struct Caps;
Jamie Madilldfde6ab2016-06-09 07:07:18 -070045class ContextState;
Jamie Madilld1405e52015-03-05 15:41:39 -050046struct Extensions;
47struct ImageIndex;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050048struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049
Jamie Madill48ef11b2016-04-27 15:21:52 -040050class FramebufferState final : angle::NonCopyable
51{
52 public:
53 FramebufferState();
54 explicit FramebufferState(const Caps &caps);
55 ~FramebufferState();
56
57 const std::string &getLabel();
58
59 const FramebufferAttachment *getReadAttachment() const;
60 const FramebufferAttachment *getFirstColorAttachment() const;
61 const FramebufferAttachment *getDepthOrStencilAttachment() const;
62 const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
63 const FramebufferAttachment *getDepthAttachment() const;
64 const FramebufferAttachment *getStencilAttachment() const;
65 const FramebufferAttachment *getDepthStencilAttachment() const;
66
67 const std::vector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
68 GLenum getReadBufferState() const { return mReadBufferState; }
69 const std::vector<FramebufferAttachment> &getColorAttachments() const
70 {
71 return mColorAttachments;
72 }
73
74 bool attachmentsHaveSameDimensions() const;
75
76 private:
77 friend class Framebuffer;
78
79 std::string mLabel;
80
81 std::vector<FramebufferAttachment> mColorAttachments;
82 FramebufferAttachment mDepthAttachment;
83 FramebufferAttachment mStencilAttachment;
84
85 std::vector<GLenum> mDrawBufferStates;
86 GLenum mReadBufferState;
87};
88
Geoff Lang70d0f492015-12-10 17:45:46 -050089class Framebuffer final : public LabeledObject
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090{
91 public:
Jamie Madill7aea7e02016-05-10 10:39:45 -040092 Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id);
Corentin Wallez37c39792015-08-20 14:19:46 -040093 Framebuffer(rx::SurfaceImpl *surface);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000094 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095
Geoff Lang70d0f492015-12-10 17:45:46 -050096 void setLabel(const std::string &label) override;
97 const std::string &getLabel() const override;
98
Jamie Madill51f40ec2016-06-15 14:06:00 -040099 rx::FramebufferImpl *getImplementation() const { return mImpl; }
Geoff Langda88add2014-12-01 10:22:01 -0500100
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400101 GLuint id() const { return mId; }
102
Jamie Madill2d06b732015-04-20 12:53:28 -0400103 void setAttachment(GLenum type,
104 GLenum binding,
105 const ImageIndex &textureIndex,
106 FramebufferAttachmentObject *resource);
107 void resetAttachment(GLenum binding);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000108
109 void detachTexture(GLuint texture);
110 void detachRenderbuffer(GLuint renderbuffer);
111
Corentin Wallez37c39792015-08-20 14:19:46 -0400112 const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400113 const FramebufferAttachment *getDepthbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400114 const FramebufferAttachment *getStencilbuffer() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400115 const FramebufferAttachment *getDepthStencilBuffer() const;
116 const FramebufferAttachment *getDepthOrStencilbuffer() const;
117 const FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +0000118 GLenum getReadColorbufferType() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400119 const FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400121 const FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -0400122
Geoff Langa15472a2015-08-11 11:48:03 -0400123 size_t getDrawbufferStateCount() const;
124 GLenum getDrawBufferState(size_t drawBuffer) const;
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500125 const std::vector<GLenum> &getDrawBufferStates() const;
Geoff Lang164d54e2014-12-01 10:55:33 -0500126 void setDrawBuffers(size_t count, const GLenum *buffers);
Geoff Langa15472a2015-08-11 11:48:03 -0400127 const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
128 bool hasEnabledDrawBuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000129
Geoff Lang9dd95802014-12-01 11:12:59 -0500130 GLenum getReadBufferState() const;
131 void setReadBuffer(GLenum buffer);
132
Corentin Wallez37c39792015-08-20 14:19:46 -0400133 size_t getNumColorBuffers() const;
Jamie Madill0df8fe42015-11-24 16:10:24 -0500134 bool hasDepth() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000135 bool hasStencil() const;
Jamie Madill51f40ec2016-06-15 14:06:00 -0400136
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000137 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000138
Jamie Madill51f40ec2016-06-15 14:06:00 -0400139 // This method calls checkStatus.
140 int getSamples(const ContextState &state);
141 GLenum checkStatus(const ContextState &state);
142
143 // These methods do not change any state.
144 // TODO(jmadill): Remove ContextState parameter when able.
145 int getCachedSamples(const ContextState &state) const;
146 GLenum getCachedStatus(const ContextState &state) const;
147
Jamie Madille92a3542014-07-03 10:38:58 -0400148 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000149
Austin Kinross08332632015-05-05 13:35:47 -0700150 Error discard(size_t count, const GLenum *attachments);
Geoff Lang9ad4bda2014-12-01 11:03:09 -0500151 Error invalidate(size_t count, const GLenum *attachments);
152 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400153
Jamie Madill8415b5f2016-04-26 13:41:39 -0400154 Error clear(rx::ContextImpl *context, GLbitfield mask);
155 Error clearBufferfv(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500156 GLenum buffer,
157 GLint drawbuffer,
158 const GLfloat *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400159 Error clearBufferuiv(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500160 GLenum buffer,
161 GLint drawbuffer,
162 const GLuint *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400163 Error clearBufferiv(rx::ContextImpl *context,
Jamie Madill9082b982016-04-27 15:21:51 -0400164 GLenum buffer,
165 GLint drawbuffer,
166 const GLint *values);
Jamie Madill8415b5f2016-04-26 13:41:39 -0400167 Error clearBufferfi(rx::ContextImpl *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400168 GLenum buffer,
169 GLint drawbuffer,
170 GLfloat depth,
171 GLint stencil);
Geoff Langb04dc822014-12-01 12:02:02 -0500172
Geoff Langbce529e2014-12-01 12:48:41 -0500173 GLenum getImplementationColorReadFormat() const;
174 GLenum getImplementationColorReadType() const;
Jamie Madill8415b5f2016-04-26 13:41:39 -0400175 Error readPixels(rx::ContextImpl *context,
Jamie Madill1b94d432015-08-07 13:23:23 -0400176 const gl::Rectangle &area,
177 GLenum format,
178 GLenum type,
179 GLvoid *pixels) const;
Geoff Langbce529e2014-12-01 12:48:41 -0500180
Jamie Madill8415b5f2016-04-26 13:41:39 -0400181 Error blit(rx::ContextImpl *context,
Jamie Madillc29968b2016-01-20 11:17:23 -0500182 const Rectangle &sourceArea,
183 const Rectangle &destArea,
Geoff Lang242468f2015-09-24 14:15:41 -0400184 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400185 GLenum filter);
Geoff Lang54bd5a42014-12-01 12:51:04 -0500186
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500187 enum DirtyBitType
188 {
189 DIRTY_BIT_COLOR_ATTACHMENT_0,
190 DIRTY_BIT_COLOR_ATTACHMENT_MAX =
191 DIRTY_BIT_COLOR_ATTACHMENT_0 + gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
192 DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
193 DIRTY_BIT_STENCIL_ATTACHMENT,
194 DIRTY_BIT_DRAW_BUFFERS,
195 DIRTY_BIT_READ_BUFFER,
196 DIRTY_BIT_UNKNOWN,
197 DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN,
198 };
199
200 typedef std::bitset<DIRTY_BIT_MAX> DirtyBits;
201 bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
202
203 void syncState() const;
204
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000205 protected:
Jamie Madilld1405e52015-03-05 15:41:39 -0500206 void detachResourceById(GLenum resourceType, GLuint resourceId);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500207
Jamie Madill48ef11b2016-04-27 15:21:52 -0400208 FramebufferState mState;
Geoff Langda88add2014-12-01 10:22:01 -0500209 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400210 GLuint mId;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500211
212 // TODO(jmadill): See if we can make this non-mutable.
213 mutable DirtyBits mDirtyBits;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000214};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000215
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000216}
217
Geoff Lang0a73dd82014-11-19 16:18:08 -0500218#endif // LIBANGLE_FRAMEBUFFER_H_