blob: 8b24cf984e5cdc45008fc070ef07cce2a8f78c43 [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
Jamie Madill7147f012015-03-05 15:41:40 -050013#include <vector>
Jamie Madillce20c7f2014-09-03 11:56:29 -040014
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000015#include "common/angleutils.h"
Jamie Madill7147f012015-03-05 15:41:40 -050016#include "libANGLE/Constants.h"
17#include "libANGLE/Error.h"
18#include "libANGLE/RefCountObject.h"
Geoff Lang64f23f62014-09-10 14:40:12 -040019
daniel@transgaming.com16418b12012-11-28 19:32:22 +000020namespace rx
21{
Jamie Madill48115b62015-03-16 10:46:57 -040022class ImplFactory;
Geoff Langda88add2014-12-01 10:22:01 -050023class FramebufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050024class RenderbufferImpl;
Jamie Madilld1405e52015-03-05 15:41:39 -050025struct Workarounds;
26}
27
28namespace egl
29{
30class Surface;
daniel@transgaming.com16418b12012-11-28 19:32:22 +000031}
32
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033namespace gl
34{
Jamie Madill3c7fa222014-06-05 13:08:51 -040035class FramebufferAttachment;
Geoff Langab75a052014-10-15 12:56:37 -040036class Renderbuffer;
Geoff Langb04dc822014-12-01 12:02:02 -050037class State;
Jamie Madilld1405e52015-03-05 15:41:39 -050038class Texture;
39class TextureCapsMap;
40struct Caps;
41struct Data;
42struct Extensions;
43struct ImageIndex;
Geoff Lang9ad4bda2014-12-01 11:03:09 -050044struct Rectangle;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000045
Jamie Madill7147f012015-03-05 15:41:40 -050046typedef std::vector<FramebufferAttachment *> AttachmentList;
Jamie Madillce20c7f2014-09-03 11:56:29 -040047
Geoff Lang9d9132d2014-12-03 14:46:48 -050048class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049{
50 public:
Jamie Madilld1405e52015-03-05 15:41:39 -050051
Jamie Madillf0d10f82015-03-31 12:56:52 -040052 class Data final : angle::NonCopyable
Jamie Madilld1405e52015-03-05 15:41:39 -050053 {
54 public:
Jamie Madill28291c52015-03-16 10:46:54 -040055 explicit Data(const Caps &caps);
Jamie Madilld1405e52015-03-05 15:41:39 -050056 ~Data();
57
Jamie Madill7147f012015-03-05 15:41:40 -050058 FramebufferAttachment *getReadAttachment() const;
59 FramebufferAttachment *getFirstColorAttachment() const;
60 FramebufferAttachment *getDepthOrStencilAttachment() const;
61
62 AttachmentList mColorAttachments;
Jamie Madilld1405e52015-03-05 15:41:39 -050063 FramebufferAttachment *mDepthAttachment;
64 FramebufferAttachment *mStencilAttachment;
65
66 std::vector<GLenum> mDrawBufferStates;
67 GLenum mReadBufferState;
Jamie Madilld1405e52015-03-05 15:41:39 -050068 };
69
Jamie Madill48115b62015-03-16 10:46:57 -040070 Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000071 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072
Geoff Langda88add2014-12-01 10:22:01 -050073 const rx::FramebufferImpl *getImplementation() const { return mImpl; }
74 rx::FramebufferImpl *getImplementation() { return mImpl; }
75
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040076 GLuint id() const { return mId; }
77
Geoff Langab75a052014-10-15 12:56:37 -040078 void setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex);
79 void setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer);
80 void setNULLAttachment(GLenum attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000081
82 void detachTexture(GLuint texture);
83 void detachRenderbuffer(GLuint renderbuffer);
84
Jamie Madill3c7fa222014-06-05 13:08:51 -040085 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
86 FramebufferAttachment *getDepthbuffer() const;
87 FramebufferAttachment *getStencilbuffer() const;
88 FramebufferAttachment *getDepthStencilBuffer() const;
89 FramebufferAttachment *getDepthOrStencilbuffer() const;
90 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000091 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040092 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000093
Geoff Lang528ce3c2014-12-01 10:44:07 -050094 FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040095
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000096 GLenum getDrawBufferState(unsigned int colorAttachment) const;
Geoff Lang164d54e2014-12-01 10:55:33 -050097 void setDrawBuffers(size_t count, const GLenum *buffers);
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000098
Geoff Lang9dd95802014-12-01 11:12:59 -050099 GLenum getReadBufferState() const;
100 void setReadBuffer(GLenum buffer);
101
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +0000102 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
103 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000104 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -0500105 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +0000106 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000107
Geoff Lang748f74e2014-12-01 11:25:34 -0500108 GLenum checkStatus(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -0400109 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000110
Geoff Lang9ad4bda2014-12-01 11:03:09 -0500111 Error invalidate(size_t count, const GLenum *attachments);
112 Error invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area);
Jamie Madill400a4412014-08-29 15:46:45 -0400113
Jamie Madilld1f5ef22015-04-01 14:17:06 -0400114 Error clear(const gl::Data &data, GLbitfield mask);
Geoff Langb04dc822014-12-01 12:02:02 -0500115 Error clearBufferfv(const State &state, GLenum buffer, GLint drawbuffer, const GLfloat *values);
116 Error clearBufferuiv(const State &state, GLenum buffer, GLint drawbuffer, const GLuint *values);
117 Error clearBufferiv(const State &state, GLenum buffer, GLint drawbuffer, const GLint *values);
118 Error clearBufferfi(const State &state, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
119
Geoff Langbce529e2014-12-01 12:48:41 -0500120 GLenum getImplementationColorReadFormat() const;
121 GLenum getImplementationColorReadType() const;
122 Error readPixels(const gl::State &state, const gl::Rectangle &area, GLenum format, GLenum type, GLvoid *pixels) const;
123
Geoff Lang54bd5a42014-12-01 12:51:04 -0500124 Error blit(const gl::State &state, const gl::Rectangle &sourceArea, const gl::Rectangle &destArea,
125 GLbitfield mask, GLenum filter, const gl::Framebuffer *sourceFramebuffer);
126
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000127 protected:
Geoff Lang528ce3c2014-12-01 10:44:07 -0500128 void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
Jamie Madilld1405e52015-03-05 15:41:39 -0500129 void detachResourceById(GLenum resourceType, GLuint resourceId);
Geoff Lang528ce3c2014-12-01 10:44:07 -0500130
Jamie Madilld1405e52015-03-05 15:41:39 -0500131 Data mData;
Geoff Langda88add2014-12-01 10:22:01 -0500132 rx::FramebufferImpl *mImpl;
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -0400133 GLuint mId;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000134};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000135
136class DefaultFramebuffer : public Framebuffer
137{
138 public:
Jamie Madill48115b62015-03-16 10:46:57 -0400139 DefaultFramebuffer(const gl::Caps &caps, rx::ImplFactory *factory, egl::Surface *surface);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000140};
141
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000142}
143
Geoff Lang0a73dd82014-11-19 16:18:08 -0500144#endif // LIBANGLE_FRAMEBUFFER_H_