blob: 088a5ebbcc6ad6a0bcf1f9b6d7ddd3a4b09c6ab4 [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{
Geoff Lang6a1e6b92014-11-06 10:42:45 -050023class DefaultAttachmentImpl;
Geoff Langda88add2014-12-01 10:22:01 -050024class FramebufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050025class RenderbufferImpl;
26class Renderer;
27struct Workarounds;
28}
29
30namespace egl
31{
32class Surface;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000033}
34
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035namespace gl
36{
Jamie Madill3c7fa222014-06-05 13:08:51 -040037class FramebufferAttachment;
Geoff Langab75a052014-10-15 12:56:37 -040038class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050039class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050040class Texture;
41class TextureCapsMap;
42struct Caps;
43struct Data;
44struct Extensions;
45struct ImageIndex;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050046struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047
Jamie Madillce20c7f2014-09-03 11:56:29 -040048typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
49
Geoff Lang9d9132d2014-12-03 14:46:48 -050050class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000051{
52 public:
Jamie Madilld1405e52015-03-05 15:41:39 -050053
54 class Data final
55 {
56 public:
57 Data(const Caps &caps);
58 ~Data();
59
60 std::vector<FramebufferAttachment *> mColorAttachments;
61 FramebufferAttachment *mDepthAttachment;
62 FramebufferAttachment *mStencilAttachment;
63
64 std::vector<GLenum> mDrawBufferStates;
65 GLenum mReadBufferState;
66
67 private:
68 DISALLOW_COPY_AND_ASSIGN(Data);
69 };
70
71 Framebuffer(const Caps &caps, rx::Renderer *renderer, GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000072 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073
Geoff Langda88add2014-12-01 10:22:01 -050074 const rx::FramebufferImpl *getImplementation() const { return mImpl; }
75 rx::FramebufferImpl *getImplementation() { return mImpl; }
76
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040077 GLuint id() const { return mId; }
78
Geoff Langab75a052014-10-15 12:56:37 -040079 void setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex);
80 void setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer);
81 void setNULLAttachment(GLenum attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000082
83 void detachTexture(GLuint texture);
84 void detachRenderbuffer(GLuint renderbuffer);
85
Jamie Madill3c7fa222014-06-05 13:08:51 -040086 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
87 FramebufferAttachment *getDepthbuffer() const;
88 FramebufferAttachment *getStencilbuffer() const;
89 FramebufferAttachment *getDepthStencilBuffer() const;
90 FramebufferAttachment *getDepthOrStencilbuffer() const;
91 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000092 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040093 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094
Geoff Lang528ce3c2014-12-01 10:44:07 -050095 FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040096
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000097 GLenum getDrawBufferState(unsigned int colorAttachment) const;
Geoff Lang164d54e2014-12-01 10:55:33 -050098 void setDrawBuffers(size_t count, const GLenum *buffers);
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000099
Geoff Lang9dd95802014-12-01 11:12:59 -0500100 GLenum getReadBufferState() const;
101 void setReadBuffer(GLenum buffer);
102
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +0000103 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
104 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000105 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -0500106 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000107 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000108
Geoff Lang748f74e2014-12-01 11:25:34 -0500109 GLenum checkStatus(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -0400110 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000111
Geoff Lang9ad4bda2014-12-01 11:03:09 -0500112 Error invalidate(size_t count, const GLenum *attachments);
113 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400114
Geoff Langb04dc822014-12-01 12:02:02 -0500115 Error clear(const State &state, GLbitfield mask);
116 Error clearBufferfv(const State &state, GLenum buffer, GLint drawbuffer, const GLfloat *values);
117 Error clearBufferuiv(const State &state, GLenum buffer, GLint drawbuffer, const GLuint *values);
118 Error clearBufferiv(const State &state, GLenum buffer, GLint drawbuffer, const GLint *values);
119 Error clearBufferfi(const State &state, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
120
Geoff Langbce529e2014-12-01 12:48:41 -0500121 GLenum getImplementationColorReadFormat() const;
122 GLenum getImplementationColorReadType() const;
123 Error readPixels(const gl::State &state, const gl::Rectangle &area, GLenum format, GLenum type, GLvoid *pixels) const;
124
Geoff Lang54bd5a42014-12-01 12:51:04 -0500125 Error blit(const gl::State &state, const gl::Rectangle &sourceArea, const gl::Rectangle &destArea,
126 GLbitfield mask, GLenum filter, const gl::Framebuffer *sourceFramebuffer);
127
Jamie Madillce20c7f2014-09-03 11:56:29 -0400128 // Use this method to retrieve the color buffer map when doing rendering.
129 // It will apply a workaround for poor shader performance on some systems
130 // by compacting the list to skip NULL values.
Jamie Madill48faf802014-11-06 15:27:22 -0500131 ColorbufferInfo getColorbuffersForRender(const rx::Workarounds &workarounds) const;
Jamie Madillce20c7f2014-09-03 11:56:29 -0400132
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000133 protected:
Geoff Lang528ce3c2014-12-01 10:44:07 -0500134 void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
Jamie Madilld1405e52015-03-05 15:41:39 -0500135 void detachResourceById(GLenum resourceType, GLuint resourceId);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500136
Jamie Madilld1405e52015-03-05 15:41:39 -0500137 Data mData;
Geoff Langda88add2014-12-01 10:22:01 -0500138 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400139 GLuint mId;
140
Jamie Madillaef95de2014-09-05 10:12:41 -0400141 private:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000142 DISALLOW_COPY_AND_ASSIGN(Framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000144
145class DefaultFramebuffer : public Framebuffer
146{
147 public:
Jamie Madilld1405e52015-03-05 15:41:39 -0500148 DefaultFramebuffer(const gl::Caps &caps, rx::Renderer *renderer, egl::Surface *surface);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000149
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000150 private:
151 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
152};
153
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154}
155
Geoff Lang0a73dd82014-11-19 16:18:08 -0500156#endif // LIBANGLE_FRAMEBUFFER_H_