blob: dffb1e726bab9500a1aac6c176b9d637e44b06d5 [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"
17#include "libANGLE/Error.h"
18#include "libANGLE/RefCountObject.h"
Geoff Lang64f23f62014-09-10 14:40:12 -040019
daniel@transgaming.com16418b12012-11-28 19:32:22 +000020namespace rx
21{
Jamie Madill48115b62015-03-16 10:46:57 -040022class ImplFactory;
Geoff Langda88add2014-12-01 10:22:01 -050023class FramebufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050024class RenderbufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050025struct Workarounds;
26}
27
28namespace egl
29{
30class Surface;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000031}
32
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033namespace gl
34{
Jamie Madill3c7fa222014-06-05 13:08:51 -040035class FramebufferAttachment;
Geoff Langab75a052014-10-15 12:56:37 -040036class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050037class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050038class Texture;
39class TextureCapsMap;
40struct Caps;
41struct Data;
42struct Extensions;
43struct ImageIndex;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050044struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000045
Jamie Madillb6bda4a2015-04-20 12:53:26 -040046typedef std::vector<const FramebufferAttachment *> AttachmentList;
Jamie Madillce20c7f2014-09-03 11:56:29 -040047
Geoff Lang9d9132d2014-12-03 14:46:48 -050048class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049{
50 public:
Jamie Madilld1405e52015-03-05 15:41:39 -050051
Jamie Madillf0d10f82015-03-31 12:56:52 -040052 class Data final : angle::NonCopyable
Jamie Madilld1405e52015-03-05 15:41:39 -050053 {
54 public:
Jamie Madill28291c52015-03-16 10:46:54 -040055 explicit Data(const Caps &caps);
Jamie Madilld1405e52015-03-05 15:41:39 -050056 ~Data();
57
Jamie Madillb6bda4a2015-04-20 12:53:26 -040058 const FramebufferAttachment *getReadAttachment() const;
59 const FramebufferAttachment *getFirstColorAttachment() const;
60 const FramebufferAttachment *getDepthOrStencilAttachment() const;
61 const FramebufferAttachment *getColorAttachment(unsigned int colorAttachment) const;
62 const FramebufferAttachment *getDepthAttachment() const;
63 const FramebufferAttachment *getStencilAttachment() const;
64 const FramebufferAttachment *getDepthStencilAttachment() const;
Jamie Madill7147f012015-03-05 15:41:40 -050065
Jamie Madillb6bda4a2015-04-20 12:53:26 -040066 const std::vector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
67 const std::vector<FramebufferAttachment *> &getColorAttachments() const { return mColorAttachments; }
68
69 private:
70 friend class Framebuffer;
71 FramebufferAttachment *getColorAttachment(unsigned int colorAttachment);
72 FramebufferAttachment *getDepthAttachment();
73 FramebufferAttachment *getStencilAttachment();
74 FramebufferAttachment *getDepthStencilAttachment();
75
76 std::vector<FramebufferAttachment *> mColorAttachments;
Jamie Madilld1405e52015-03-05 15:41:39 -050077 FramebufferAttachment *mDepthAttachment;
78 FramebufferAttachment *mStencilAttachment;
79
80 std::vector<GLenum> mDrawBufferStates;
81 GLenum mReadBufferState;
Jamie Madilld1405e52015-03-05 15:41:39 -050082 };
83
Jamie Madill48115b62015-03-16 10:46:57 -040084 Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000085 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000086
Geoff Langda88add2014-12-01 10:22:01 -050087 const rx::FramebufferImpl *getImplementation() const { return mImpl; }
88 rx::FramebufferImpl *getImplementation() { return mImpl; }
89
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040090 GLuint id() const { return mId; }
91
Geoff Langab75a052014-10-15 12:56:37 -040092 void setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex);
93 void setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer);
94 void setNULLAttachment(GLenum attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095
96 void detachTexture(GLuint texture);
97 void detachRenderbuffer(GLuint renderbuffer);
98
Jamie Madillb6bda4a2015-04-20 12:53:26 -040099 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment);
100 const FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
101 FramebufferAttachment *getDepthbuffer();
102 const FramebufferAttachment *getDepthbuffer() const;
103 FramebufferAttachment *getStencilbuffer();
104 const FramebufferAttachment *getStencilbuffer() const;
105 FramebufferAttachment *getDepthStencilBuffer();
106 const FramebufferAttachment *getDepthStencilBuffer() const;
107 const FramebufferAttachment *getDepthOrStencilbuffer() const;
108 const FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +0000109 GLenum getReadColorbufferType() const;
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400110 const FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000111
Jamie Madillb6bda4a2015-04-20 12:53:26 -0400112 FramebufferAttachment *getAttachment(GLenum attachment);
113 const FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -0400114
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000115 GLenum getDrawBufferState(unsigned int colorAttachment) const;
Geoff Lang164d54e2014-12-01 10:55:33 -0500116 void setDrawBuffers(size_t count, const GLenum *buffers);
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000117
Geoff Lang9dd95802014-12-01 11:12:59 -0500118 GLenum getReadBufferState() const;
119 void setReadBuffer(GLenum buffer);
120
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +0000121 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
122 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000123 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -0500124 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000125 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000126
Geoff Lang748f74e2014-12-01 11:25:34 -0500127 GLenum checkStatus(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -0400128 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000129
Geoff Lang9ad4bda2014-12-01 11:03:09 -0500130 Error invalidate(size_t count, const GLenum *attachments);
131 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400132
Jamie Madilld1f5ef22015-04-01 14:17:06 -0400133 Error clear(const gl::Data &data, GLbitfield mask);
Geoff Langb04dc822014-12-01 12:02:02 -0500134 Error clearBufferfv(const State &state, GLenum buffer, GLint drawbuffer, const GLfloat *values);
135 Error clearBufferuiv(const State &state, GLenum buffer, GLint drawbuffer, const GLuint *values);
136 Error clearBufferiv(const State &state, GLenum buffer, GLint drawbuffer, const GLint *values);
137 Error clearBufferfi(const State &state, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
138
Geoff Langbce529e2014-12-01 12:48:41 -0500139 GLenum getImplementationColorReadFormat() const;
140 GLenum getImplementationColorReadType() const;
141 Error readPixels(const gl::State &state, const gl::Rectangle &area, GLenum format, GLenum type, GLvoid *pixels) const;
142
Geoff Lang54bd5a42014-12-01 12:51:04 -0500143 Error blit(const gl::State &state, const gl::Rectangle &sourceArea, const gl::Rectangle &destArea,
144 GLbitfield mask, GLenum filter, const gl::Framebuffer *sourceFramebuffer);
145
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000146 protected:
Geoff Lang528ce3c2014-12-01 10:44:07 -0500147 void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
Jamie Madilld1405e52015-03-05 15:41:39 -0500148 void detachResourceById(GLenum resourceType, GLuint resourceId);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500149
Jamie Madilld1405e52015-03-05 15:41:39 -0500150 Data mData;
Geoff Langda88add2014-12-01 10:22:01 -0500151 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400152 GLuint mId;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000154
155class DefaultFramebuffer : public Framebuffer
156{
157 public:
Jamie Madill48115b62015-03-16 10:46:57 -0400158 DefaultFramebuffer(const gl::Caps &caps, rx::ImplFactory *factory, egl::Surface *surface);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000159};
160
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000161}
162
Geoff Lang0a73dd82014-11-19 16:18:08 -0500163#endif // LIBANGLE_FRAMEBUFFER_H_