blob: 49345336e6879cbbd074bf3f092fdb27cc94ae3d [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"
Jamie Madillce20c7f2014-09-03 11:56:29 -040014
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000015#include "common/angleutils.h"
apatrick@chromium.orgb66a7012012-01-23 20:04:48 +000016#include "common/RefCountObject.h"
Jacek Cabana5521de2014-10-01 17:23:46 +020017#include "Constants.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;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000026}
27
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028namespace gl
29{
Jamie Madill3c7fa222014-06-05 13:08:51 -040030class FramebufferAttachment;
Geoff Langab75a052014-10-15 12:56:37 -040031class Texture;
32class Renderbuffer;
33struct ImageIndex;
Jamie Madill2d96b9e2014-08-29 15:46:47 -040034struct Caps;
Jamie Madill48faf802014-11-06 15:27:22 -050035struct Extensions;
36class TextureCapsMap;
37struct Data;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038
Jamie Madillce20c7f2014-09-03 11:56:29 -040039typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
40
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000041class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042{
43 public:
Jamie Madill48faf802014-11-06 15:27:22 -050044 Framebuffer(GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000045 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040047 GLuint id() const { return mId; }
48
Geoff Langab75a052014-10-15 12:56:37 -040049 void setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex);
50 void setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer);
51 void setNULLAttachment(GLenum attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052
53 void detachTexture(GLuint texture);
54 void detachRenderbuffer(GLuint renderbuffer);
55
Jamie Madill3c7fa222014-06-05 13:08:51 -040056 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
57 FramebufferAttachment *getDepthbuffer() const;
58 FramebufferAttachment *getStencilbuffer() const;
59 FramebufferAttachment *getDepthStencilBuffer() const;
60 FramebufferAttachment *getDepthOrStencilbuffer() const;
61 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000062 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040063 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
Jamie Madille92a3542014-07-03 10:38:58 -040065 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040066
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000067 GLenum getDrawBufferState(unsigned int colorAttachment) const;
68 void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
69
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +000070 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
71 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000072 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -050073 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +000074 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +000075
Jamie Madill48faf802014-11-06 15:27:22 -050076 virtual GLenum completeness(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -040077 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000078
Geoff Lang64f23f62014-09-10 14:40:12 -040079 Error invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
80 Error invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
Jamie Madill400a4412014-08-29 15:46:45 -040081
Jamie Madillce20c7f2014-09-03 11:56:29 -040082 // Use this method to retrieve the color buffer map when doing rendering.
83 // It will apply a workaround for poor shader performance on some systems
84 // by compacting the list to skip NULL values.
Jamie Madill48faf802014-11-06 15:27:22 -050085 ColorbufferInfo getColorbuffersForRender(const rx::Workarounds &workarounds) const;
Jamie Madillce20c7f2014-09-03 11:56:29 -040086
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000087 protected:
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040088 GLuint mId;
89
Jamie Madille261b442014-06-25 12:42:21 -040090 FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000091 GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
92 GLenum mReadBufferState;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000093
Jamie Madille261b442014-06-25 12:42:21 -040094 FramebufferAttachment *mDepthbuffer;
95 FramebufferAttachment *mStencilbuffer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000096
Jamie Madillaef95de2014-09-05 10:12:41 -040097 private:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098 DISALLOW_COPY_AND_ASSIGN(Framebuffer);
99
Geoff Langab75a052014-10-15 12:56:37 -0400100 void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000101};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000102
103class DefaultFramebuffer : public Framebuffer
104{
105 public:
Geoff Lang6a1e6b92014-11-06 10:42:45 -0500106 DefaultFramebuffer(rx::DefaultAttachmentImpl *colorAttachment, rx::DefaultAttachmentImpl *depthAttachment,
107 rx::DefaultAttachmentImpl *stencilAttachment);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000108
Jamie Madill48faf802014-11-06 15:27:22 -0500109 GLenum completeness(const gl::Data &data) const override;
Jamie Madille92a3542014-07-03 10:38:58 -0400110 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000111
112 private:
113 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
114};
115
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116}
117
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400118namespace rx
119{
120class RenderTarget;
121
122// TODO: place this in FramebufferD3D.h
Geoff Lang64f23f62014-09-10 14:40:12 -0400123gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT);
Jamie Madill612e2e42014-09-12 13:26:55 -0400124unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment);
125
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400126}
127
Geoff Lang0a73dd82014-11-19 16:18:08 -0500128#endif // LIBANGLE_FRAMEBUFFER_H_