blob: d70c2a4f926fe07673d2be26f74ebe63c1999f8a [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 Madill48115b62015-03-16 10:46:57 -040024class ImplFactory;
Geoff Langda88add2014-12-01 10:22:01 -050025class FramebufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050026class RenderbufferImpl;
Corentin Wallez37c39792015-08-20 14:19:46 -040027class SurfaceImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050028}
29
30namespace egl
31{
32class Surface;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000033}
34
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035namespace gl
36{
Jamie Madill1b94d432015-08-07 13:23:23 -040037class Context;
Jamie Madill48ef11b2016-04-27 15:21:52 -040038class Framebuffer;
Geoff Langab75a052014-10-15 12:56:37 -040039class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050040class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050041class Texture;
42class TextureCapsMap;
43struct Caps;
Jamie Madill9082b982016-04-27 15:21:51 -040044struct ContextState;
Jamie Madilld1405e52015-03-05 15:41:39 -050045struct Extensions;
46struct ImageIndex;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050047struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048
Jamie Madill48ef11b2016-04-27 15:21:52 -040049class FramebufferState final : angle::NonCopyable
50{
51 public:
52 FramebufferState();
53 explicit FramebufferState(const Caps &caps);
54 ~FramebufferState();
55
56 const std::string &getLabel();
57
58 const FramebufferAttachment *getReadAttachment() const;
59 const FramebufferAttachment *getFirstColorAttachment() const;
60 const FramebufferAttachment *getDepthOrStencilAttachment() const;
61 const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
62 const FramebufferAttachment *getDepthAttachment() const;
63 const FramebufferAttachment *getStencilAttachment() const;
64 const FramebufferAttachment *getDepthStencilAttachment() const;
65
66 const std::vector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
67 GLenum getReadBufferState() const { return mReadBufferState; }
68 const std::vector<FramebufferAttachment> &getColorAttachments() const
69 {
70 return mColorAttachments;
71 }
72
73 bool attachmentsHaveSameDimensions() const;
74
75 private:
76 friend class Framebuffer;
77
78 std::string mLabel;
79
80 std::vector<FramebufferAttachment> mColorAttachments;
81 FramebufferAttachment mDepthAttachment;
82 FramebufferAttachment mStencilAttachment;
83
84 std::vector<GLenum> mDrawBufferStates;
85 GLenum mReadBufferState;
86};
87
Geoff Lang70d0f492015-12-10 17:45:46 -050088class Framebuffer final : public LabeledObject
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000089{
90 public:
Jamie Madill48115b62015-03-16 10:46:57 -040091 Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id);
Corentin Wallez37c39792015-08-20 14:19:46 -040092 Framebuffer(rx::SurfaceImpl *surface);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000093 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094
Geoff Lang70d0f492015-12-10 17:45:46 -050095 void setLabel(const std::string &label) override;
96 const std::string &getLabel() const override;
97
Geoff Langda88add2014-12-01 10:22:01 -050098 const rx::FramebufferImpl *getImplementation() const { return mImpl; }
99 rx::FramebufferImpl *getImplementation() { return mImpl; }
100
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 Madill9082b982016-04-27 15:21:51 -0400136 int getSamples(const ContextState &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000137 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000138
Jamie Madill9082b982016-04-27 15:21:51 -0400139 GLenum checkStatus(const ContextState &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -0400140 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000141
Austin Kinross08332632015-05-05 13:35:47 -0700142 Error discard(size_t count, const GLenum *attachments);
Geoff Lang9ad4bda2014-12-01 11:03:09 -0500143 Error invalidate(size_t count, const GLenum *attachments);
144 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400145
Jamie Madill9082b982016-04-27 15:21:51 -0400146 Error clear(const ContextState &data, GLbitfield mask);
147 Error clearBufferfv(const ContextState &data,
Jamie Madillc29968b2016-01-20 11:17:23 -0500148 GLenum buffer,
149 GLint drawbuffer,
150 const GLfloat *values);
Jamie Madill9082b982016-04-27 15:21:51 -0400151 Error clearBufferuiv(const ContextState &data,
Jamie Madillc29968b2016-01-20 11:17:23 -0500152 GLenum buffer,
153 GLint drawbuffer,
154 const GLuint *values);
Jamie Madill9082b982016-04-27 15:21:51 -0400155 Error clearBufferiv(const ContextState &data,
156 GLenum buffer,
157 GLint drawbuffer,
158 const GLint *values);
159 Error clearBufferfi(const ContextState &data,
Jamie Madill1b94d432015-08-07 13:23:23 -0400160 GLenum buffer,
161 GLint drawbuffer,
162 GLfloat depth,
163 GLint stencil);
Geoff Langb04dc822014-12-01 12:02:02 -0500164
Geoff Langbce529e2014-12-01 12:48:41 -0500165 GLenum getImplementationColorReadFormat() const;
166 GLenum getImplementationColorReadType() const;
Jamie Madillc29968b2016-01-20 11:17:23 -0500167 Error readPixels(const gl::State &state,
Jamie Madill1b94d432015-08-07 13:23:23 -0400168 const gl::Rectangle &area,
169 GLenum format,
170 GLenum type,
171 GLvoid *pixels) const;
Geoff Langbce529e2014-12-01 12:48:41 -0500172
Jamie Madillc29968b2016-01-20 11:17:23 -0500173 Error blit(const State &state,
174 const Rectangle &sourceArea,
175 const Rectangle &destArea,
Geoff Lang242468f2015-09-24 14:15:41 -0400176 GLbitfield mask,
177 GLenum filter,
Jamie Madillc29968b2016-01-20 11:17:23 -0500178 const Framebuffer *sourceFramebuffer);
Geoff Lang54bd5a42014-12-01 12:51:04 -0500179
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500180 enum DirtyBitType
181 {
182 DIRTY_BIT_COLOR_ATTACHMENT_0,
183 DIRTY_BIT_COLOR_ATTACHMENT_MAX =
184 DIRTY_BIT_COLOR_ATTACHMENT_0 + gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
185 DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
186 DIRTY_BIT_STENCIL_ATTACHMENT,
187 DIRTY_BIT_DRAW_BUFFERS,
188 DIRTY_BIT_READ_BUFFER,
189 DIRTY_BIT_UNKNOWN,
190 DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN,
191 };
192
193 typedef std::bitset<DIRTY_BIT_MAX> DirtyBits;
194 bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
195
196 void syncState() const;
197
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000198 protected:
Jamie Madilld1405e52015-03-05 15:41:39 -0500199 void detachResourceById(GLenum resourceType, GLuint resourceId);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500200
Jamie Madill48ef11b2016-04-27 15:21:52 -0400201 FramebufferState mState;
Geoff Langda88add2014-12-01 10:22:01 -0500202 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400203 GLuint mId;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500204
205 // TODO(jmadill): See if we can make this non-mutable.
206 mutable DirtyBits mDirtyBits;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000207};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000208
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000209}
210
Geoff Lang0a73dd82014-11-19 16:18:08 -0500211#endif // LIBANGLE_FRAMEBUFFER_H_