blob: 3437d2a8aa8132cffd588e5d88882f7a2a52e1e9 [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
Geoff Lang2b5420c2014-11-19 14:20:15 -050013#include "libANGLE/Error.h"
Geoff Lang22072132014-11-20 15:15:01 -050014#include "libANGLE/RefCountObject.h"
15#include "libANGLE/Constants.h"
Jamie Madillce20c7f2014-09-03 11:56:29 -040016
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000017#include "common/angleutils.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018
Geoff Lang64f23f62014-09-10 14:40:12 -040019#include <vector>
20
daniel@transgaming.com16418b12012-11-28 19:32:22 +000021namespace rx
22{
Shannon Woodse2632d22014-10-17 13:08:51 -040023class RenderbufferImpl;
Jamie Madill48faf802014-11-06 15:27:22 -050024struct Workarounds;
Geoff Lang6a1e6b92014-11-06 10:42:45 -050025class DefaultAttachmentImpl;
Geoff Langda88add2014-12-01 10:22:01 -050026class FramebufferImpl;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000027}
28
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000029namespace gl
30{
Jamie Madill3c7fa222014-06-05 13:08:51 -040031class FramebufferAttachment;
Geoff Langab75a052014-10-15 12:56:37 -040032class Texture;
33class Renderbuffer;
34struct ImageIndex;
Jamie Madill2d96b9e2014-08-29 15:46:47 -040035struct Caps;
Jamie Madill48faf802014-11-06 15:27:22 -050036struct Extensions;
37class TextureCapsMap;
38struct Data;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050039struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000040
Jamie Madillce20c7f2014-09-03 11:56:29 -040041typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
42
Geoff Lang9d9132d2014-12-03 14:46:48 -050043class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044{
45 public:
Geoff Langda88add2014-12-01 10:22:01 -050046 Framebuffer(rx::FramebufferImpl *impl, GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000047 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048
Geoff Langda88add2014-12-01 10:22:01 -050049 const rx::FramebufferImpl *getImplementation() const { return mImpl; }
50 rx::FramebufferImpl *getImplementation() { return mImpl; }
51
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040052 GLuint id() const { return mId; }
53
Geoff Langab75a052014-10-15 12:56:37 -040054 void setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex);
55 void setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer);
56 void setNULLAttachment(GLenum attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000057
58 void detachTexture(GLuint texture);
59 void detachRenderbuffer(GLuint renderbuffer);
60
Jamie Madill3c7fa222014-06-05 13:08:51 -040061 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
62 FramebufferAttachment *getDepthbuffer() const;
63 FramebufferAttachment *getStencilbuffer() const;
64 FramebufferAttachment *getDepthStencilBuffer() const;
65 FramebufferAttachment *getDepthOrStencilbuffer() const;
66 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000067 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040068 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000069
Geoff Lang528ce3c2014-12-01 10:44:07 -050070 FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040071
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000072 GLenum getDrawBufferState(unsigned int colorAttachment) const;
Geoff Lang164d54e2014-12-01 10:55:33 -050073 void setDrawBuffers(size_t count, const GLenum *buffers);
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000074
Geoff Lang9dd95802014-12-01 11:12:59 -050075 GLenum getReadBufferState() const;
76 void setReadBuffer(GLenum buffer);
77
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +000078 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
79 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000080 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -050081 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +000082 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +000083
Geoff Lang528ce3c2014-12-01 10:44:07 -050084 GLenum completeness(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -040085 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000086
Geoff Lang9ad4bda2014-12-01 11:03:09 -050087 Error invalidate(size_t count, const GLenum *attachments);
88 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -040089
Jamie Madillce20c7f2014-09-03 11:56:29 -040090 // Use this method to retrieve the color buffer map when doing rendering.
91 // It will apply a workaround for poor shader performance on some systems
92 // by compacting the list to skip NULL values.
Jamie Madill48faf802014-11-06 15:27:22 -050093 ColorbufferInfo getColorbuffersForRender(const rx::Workarounds &workarounds) const;
Jamie Madillce20c7f2014-09-03 11:56:29 -040094
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000095 protected:
Geoff Lang528ce3c2014-12-01 10:44:07 -050096 void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
97
Geoff Langda88add2014-12-01 10:22:01 -050098 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040099 GLuint mId;
100
Jamie Madille261b442014-06-25 12:42:21 -0400101 FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +0000102 GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
103 GLenum mReadBufferState;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000104
Jamie Madille261b442014-06-25 12:42:21 -0400105 FramebufferAttachment *mDepthbuffer;
106 FramebufferAttachment *mStencilbuffer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000107
Jamie Madillaef95de2014-09-05 10:12:41 -0400108 private:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000109 DISALLOW_COPY_AND_ASSIGN(Framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000110};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000111
112class DefaultFramebuffer : public Framebuffer
113{
114 public:
Geoff Langda88add2014-12-01 10:22:01 -0500115 DefaultFramebuffer(rx::FramebufferImpl *impl, rx::DefaultAttachmentImpl *colorAttachment,
116 rx::DefaultAttachmentImpl *depthAttachment, rx::DefaultAttachmentImpl *stencilAttachment);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000117
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000118 private:
119 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
120};
121
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000122}
123
Geoff Lang0a73dd82014-11-19 16:18:08 -0500124#endif // LIBANGLE_FRAMEBUFFER_H_