blob: 4d3b344c7fb5262e6fef6b4f38aa13745dcbb435 [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"
Geoff Lang8bc361e2014-11-20 16:23:31 -050016#include "libANGLE/export.h"
Jamie Madillce20c7f2014-09-03 11:56:29 -040017
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000018#include "common/angleutils.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000019
Geoff Lang64f23f62014-09-10 14:40:12 -040020#include <vector>
21
daniel@transgaming.com16418b12012-11-28 19:32:22 +000022namespace rx
23{
Shannon Woodse2632d22014-10-17 13:08:51 -040024class RenderbufferImpl;
Jamie Madill48faf802014-11-06 15:27:22 -050025struct Workarounds;
Geoff Lang6a1e6b92014-11-06 10:42:45 -050026class DefaultAttachmentImpl;
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;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039
Jamie Madillce20c7f2014-09-03 11:56:29 -040040typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
41
Geoff Lang8bc361e2014-11-20 16:23:31 -050042class ANGLE_EXPORT Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000043{
44 public:
Jamie Madill48faf802014-11-06 15:27:22 -050045 Framebuffer(GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000046 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040048 GLuint id() const { return mId; }
49
Geoff Langab75a052014-10-15 12:56:37 -040050 void setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex);
51 void setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer);
52 void setNULLAttachment(GLenum attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000053
54 void detachTexture(GLuint texture);
55 void detachRenderbuffer(GLuint renderbuffer);
56
Jamie Madill3c7fa222014-06-05 13:08:51 -040057 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
58 FramebufferAttachment *getDepthbuffer() const;
59 FramebufferAttachment *getStencilbuffer() const;
60 FramebufferAttachment *getDepthStencilBuffer() const;
61 FramebufferAttachment *getDepthOrStencilbuffer() const;
62 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000063 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040064 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000065
Jamie Madille92a3542014-07-03 10:38:58 -040066 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040067
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000068 GLenum getDrawBufferState(unsigned int colorAttachment) const;
69 void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
70
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +000071 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
72 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000073 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -050074 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +000075 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +000076
Jamie Madill48faf802014-11-06 15:27:22 -050077 virtual GLenum completeness(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -040078 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000079
Geoff Lang64f23f62014-09-10 14:40:12 -040080 Error invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
81 Error invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
Jamie Madill400a4412014-08-29 15:46:45 -040082
Jamie Madillce20c7f2014-09-03 11:56:29 -040083 // Use this method to retrieve the color buffer map when doing rendering.
84 // It will apply a workaround for poor shader performance on some systems
85 // by compacting the list to skip NULL values.
Jamie Madill48faf802014-11-06 15:27:22 -050086 ColorbufferInfo getColorbuffersForRender(const rx::Workarounds &workarounds) const;
Jamie Madillce20c7f2014-09-03 11:56:29 -040087
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000088 protected:
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040089 GLuint mId;
90
Jamie Madille261b442014-06-25 12:42:21 -040091 FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000092 GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
93 GLenum mReadBufferState;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000094
Jamie Madille261b442014-06-25 12:42:21 -040095 FramebufferAttachment *mDepthbuffer;
96 FramebufferAttachment *mStencilbuffer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000097
Jamie Madillaef95de2014-09-05 10:12:41 -040098 private:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099 DISALLOW_COPY_AND_ASSIGN(Framebuffer);
100
Geoff Langab75a052014-10-15 12:56:37 -0400101 void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000102};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000103
104class DefaultFramebuffer : public Framebuffer
105{
106 public:
Geoff Lang6a1e6b92014-11-06 10:42:45 -0500107 DefaultFramebuffer(rx::DefaultAttachmentImpl *colorAttachment, rx::DefaultAttachmentImpl *depthAttachment,
108 rx::DefaultAttachmentImpl *stencilAttachment);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000109
Jamie Madill48faf802014-11-06 15:27:22 -0500110 GLenum completeness(const gl::Data &data) const override;
Jamie Madille92a3542014-07-03 10:38:58 -0400111 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000112
113 private:
114 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
115};
116
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000117}
118
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400119namespace rx
120{
121class RenderTarget;
122
123// TODO: place this in FramebufferD3D.h
Geoff Lang4f4207f2014-12-01 10:07:56 -0500124gl::Error GetAttachmentRenderTarget(const gl::FramebufferAttachment *attachment, RenderTarget **outRT);
125unsigned int GetAttachmentSerial(const gl::FramebufferAttachment *attachment);
Jamie Madill612e2e42014-09-12 13:26:55 -0400126
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400127}
128
Geoff Lang0a73dd82014-11-19 16:18:08 -0500129#endif // LIBANGLE_FRAMEBUFFER_H_