blob: 1f55b4333aa78b0b7753544adc3a8e3db9b17b3e [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{
23class Renderer;
24}
25
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000026namespace gl
27{
Jamie Madill3c7fa222014-06-05 13:08:51 -040028class FramebufferAttachment;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000029class Colorbuffer;
30class Depthbuffer;
31class Stencilbuffer;
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +000032class DepthStencilbuffer;
Jamie Madill2d96b9e2014-08-29 15:46:47 -040033struct Caps;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034
Jamie Madillce20c7f2014-09-03 11:56:29 -040035typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
36
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000037class Framebuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038{
39 public:
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040040 Framebuffer(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000042 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000043
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040044 GLuint id() const { return mId; }
45
Geoff Lang309c92a2013-07-25 16:23:19 -040046 void setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer);
47 void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer);
48 void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer);
49 void setDepthStencilBuffer(GLenum type, GLuint depthStencilBuffer, GLint level, GLint layer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000050
51 void detachTexture(GLuint texture);
52 void detachRenderbuffer(GLuint renderbuffer);
53
Jamie Madill3c7fa222014-06-05 13:08:51 -040054 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
55 FramebufferAttachment *getDepthbuffer() const;
56 FramebufferAttachment *getStencilbuffer() const;
57 FramebufferAttachment *getDepthStencilBuffer() const;
58 FramebufferAttachment *getDepthOrStencilbuffer() const;
59 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000060 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040061 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062
Jamie Madille92a3542014-07-03 10:38:58 -040063 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040064
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000065 GLenum getDrawBufferState(unsigned int colorAttachment) const;
66 void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
67
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +000068 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
69 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000070 bool hasStencil() const;
71 int getSamples() const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +000072 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +000073
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000074 virtual GLenum completeness() const;
Jamie Madille92a3542014-07-03 10:38:58 -040075 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000076
Geoff Lang64f23f62014-09-10 14:40:12 -040077 Error invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
78 Error invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
Jamie Madill400a4412014-08-29 15:46:45 -040079
Jamie Madillce20c7f2014-09-03 11:56:29 -040080 // Use this method to retrieve the color buffer map when doing rendering.
81 // It will apply a workaround for poor shader performance on some systems
82 // by compacting the list to skip NULL values.
83 ColorbufferInfo getColorbuffersForRender() const;
84
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000085 protected:
Jamie Madille261b442014-06-25 12:42:21 -040086 rx::Renderer *mRenderer;
87
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
Jamie Madillaef95de2014-09-05 10:12:41 -0400100 FramebufferAttachment *createAttachment(GLenum binding, GLenum type, GLuint handle, GLint level, GLint layer) const;
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:
daniel@transgaming.com16418b12012-11-28 19:32:22 +0000106 DefaultFramebuffer(rx::Renderer *Renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000107
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +0000108 virtual GLenum completeness() const;
Jamie Madille92a3542014-07-03 10:38:58 -0400109 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000110
111 private:
112 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
113};
114
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000115}
116
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400117namespace rx
118{
119class RenderTarget;
120
121// TODO: place this in FramebufferD3D.h
Geoff Lang64f23f62014-09-10 14:40:12 -0400122gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT);
Jamie Madill612e2e42014-09-12 13:26:55 -0400123unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment);
124
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400125}
126
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000127#endif // LIBGLESV2_FRAMEBUFFER_H_