blob: d0fe8935ea8ca1d580be9c6db3f06b16d934c58f [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
10#ifndef LIBGLESV2_FRAMEBUFFER_H_
11#define LIBGLESV2_FRAMEBUFFER_H_
12
Geoff Lang64f23f62014-09-10 14:40:12 -040013#include "libGLESv2/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;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000025}
26
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027namespace gl
28{
Jamie Madill3c7fa222014-06-05 13:08:51 -040029class FramebufferAttachment;
Geoff Langab75a052014-10-15 12:56:37 -040030class Texture;
31class Renderbuffer;
32struct ImageIndex;
Jamie Madill2d96b9e2014-08-29 15:46:47 -040033struct Caps;
Jamie Madill48faf802014-11-06 15:27:22 -050034struct Extensions;
35class TextureCapsMap;
36struct Data;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000037
Jamie Madillce20c7f2014-09-03 11:56:29 -040038typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
39
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000040class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041{
42 public:
Jamie Madill48faf802014-11-06 15:27:22 -050043 Framebuffer(GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000044 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000045
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040046 GLuint id() const { return mId; }
47
Geoff Langab75a052014-10-15 12:56:37 -040048 void setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex);
49 void setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer);
50 void setNULLAttachment(GLenum attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000051
52 void detachTexture(GLuint texture);
53 void detachRenderbuffer(GLuint renderbuffer);
54
Jamie Madill3c7fa222014-06-05 13:08:51 -040055 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
56 FramebufferAttachment *getDepthbuffer() const;
57 FramebufferAttachment *getStencilbuffer() const;
58 FramebufferAttachment *getDepthStencilBuffer() const;
59 FramebufferAttachment *getDepthOrStencilbuffer() const;
60 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000061 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040062 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063
Jamie Madille92a3542014-07-03 10:38:58 -040064 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040065
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000066 GLenum getDrawBufferState(unsigned int colorAttachment) const;
67 void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
68
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +000069 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
70 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000071 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -050072 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +000073 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +000074
Jamie Madill48faf802014-11-06 15:27:22 -050075 virtual GLenum completeness(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -040076 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000077
Geoff Lang64f23f62014-09-10 14:40:12 -040078 Error invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
79 Error invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
Jamie Madill400a4412014-08-29 15:46:45 -040080
Jamie Madillce20c7f2014-09-03 11:56:29 -040081 // Use this method to retrieve the color buffer map when doing rendering.
82 // It will apply a workaround for poor shader performance on some systems
83 // by compacting the list to skip NULL values.
Jamie Madill48faf802014-11-06 15:27:22 -050084 ColorbufferInfo getColorbuffersForRender(const rx::Workarounds &workarounds) const;
Jamie Madillce20c7f2014-09-03 11:56:29 -040085
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000086 protected:
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040087 GLuint mId;
88
Jamie Madille261b442014-06-25 12:42:21 -040089 FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000090 GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
91 GLenum mReadBufferState;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000092
Jamie Madille261b442014-06-25 12:42:21 -040093 FramebufferAttachment *mDepthbuffer;
94 FramebufferAttachment *mStencilbuffer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095
Jamie Madillaef95de2014-09-05 10:12:41 -040096 private:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000097 DISALLOW_COPY_AND_ASSIGN(Framebuffer);
98
Geoff Langab75a052014-10-15 12:56:37 -040099 void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000100};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000101
102class DefaultFramebuffer : public Framebuffer
103{
104 public:
Jamie Madill48faf802014-11-06 15:27:22 -0500105 DefaultFramebuffer(rx::RenderbufferImpl *colorbuffer, rx::RenderbufferImpl *depthStencil);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000106
Jamie Madill48faf802014-11-06 15:27:22 -0500107 GLenum completeness(const gl::Data &data) const override;
Jamie Madille92a3542014-07-03 10:38:58 -0400108 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000109
110 private:
111 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
112};
113
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000114}
115
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400116namespace rx
117{
118class RenderTarget;
119
120// TODO: place this in FramebufferD3D.h
Geoff Lang64f23f62014-09-10 14:40:12 -0400121gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT);
Jamie Madill612e2e42014-09-12 13:26:55 -0400122unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment);
123
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400124}
125
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000126#endif // LIBGLESV2_FRAMEBUFFER_H_