blob: 355402c622f7724c1b1484c34042f35404d809a2 [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
Jamie Madillce20c7f2014-09-03 11:56:29 -040013#include <vector>
14
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
daniel@transgaming.com16418b12012-11-28 19:32:22 +000019namespace rx
20{
21class Renderer;
22}
23
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000024namespace gl
25{
Jamie Madill3c7fa222014-06-05 13:08:51 -040026class FramebufferAttachment;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027class Colorbuffer;
28class Depthbuffer;
29class Stencilbuffer;
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +000030class DepthStencilbuffer;
Jamie Madill2d96b9e2014-08-29 15:46:47 -040031struct Caps;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032
Jamie Madillce20c7f2014-09-03 11:56:29 -040033typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
34
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000035class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000036{
37 public:
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040038 Framebuffer(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000040 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040042 GLuint id() const { return mId; }
43
Geoff Lang309c92a2013-07-25 16:23:19 -040044 void setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer);
45 void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer);
46 void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer);
47 void setDepthStencilBuffer(GLenum type, GLuint depthStencilBuffer, GLint level, GLint layer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048
49 void detachTexture(GLuint texture);
50 void detachRenderbuffer(GLuint renderbuffer);
51
Jamie Madill3c7fa222014-06-05 13:08:51 -040052 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
53 FramebufferAttachment *getDepthbuffer() const;
54 FramebufferAttachment *getStencilbuffer() const;
55 FramebufferAttachment *getDepthStencilBuffer() const;
56 FramebufferAttachment *getDepthOrStencilbuffer() const;
57 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000058 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040059 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000060
Jamie Madille92a3542014-07-03 10:38:58 -040061 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040062
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000063 GLenum getDrawBufferState(unsigned int colorAttachment) const;
64 void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
65
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +000066 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
67 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000068 bool hasStencil() const;
69 int getSamples() const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +000070 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +000071
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000072 virtual GLenum completeness() const;
Jamie Madille92a3542014-07-03 10:38:58 -040073 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000074
Jamie Madill2d96b9e2014-08-29 15:46:47 -040075 void invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
76 void invalidateSub(const Caps &caps, GLsizei numAttachments, const GLenum *attachments,
77 GLint x, GLint y, GLsizei width, GLsizei height);
Jamie Madill400a4412014-08-29 15:46:45 -040078
Jamie Madillce20c7f2014-09-03 11:56:29 -040079 // Use this method to retrieve the color buffer map when doing rendering.
80 // It will apply a workaround for poor shader performance on some systems
81 // by compacting the list to skip NULL values.
82 ColorbufferInfo getColorbuffersForRender() const;
83
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000084 protected:
Jamie Madille261b442014-06-25 12:42:21 -040085 rx::Renderer *mRenderer;
86
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
Jamie Madillaef95de2014-09-05 10:12:41 -040099 FramebufferAttachment *createAttachment(GLenum binding, GLenum type, GLuint handle, GLint level, GLint layer) const;
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:
daniel@transgaming.com16418b12012-11-28 19:32:22 +0000105 DefaultFramebuffer(rx::Renderer *Renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000106
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000107 virtual GLenum completeness() const;
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
121RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment);
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_