blob: 87f44c5146d15ee17cc6eb44055d57979131bd1f [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;
Jamie Madill2d96b9e2014-08-29 15:46:47 -040030struct Caps;
Jamie Madill48faf802014-11-06 15:27:22 -050031struct Extensions;
32class TextureCapsMap;
33struct Data;
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:
Jamie Madill48faf802014-11-06 15:27:22 -050040 Framebuffer(GLuint id);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000041 virtual ~Framebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040043 GLuint id() const { return mId; }
44
Geoff Lang309c92a2013-07-25 16:23:19 -040045 void setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer);
46 void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer);
47 void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer);
48 void setDepthStencilBuffer(GLenum type, GLuint depthStencilBuffer, GLint level, GLint layer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049
50 void detachTexture(GLuint texture);
51 void detachRenderbuffer(GLuint renderbuffer);
52
Jamie Madill3c7fa222014-06-05 13:08:51 -040053 FramebufferAttachment *getColorbuffer(unsigned int colorAttachment) const;
54 FramebufferAttachment *getDepthbuffer() const;
55 FramebufferAttachment *getStencilbuffer() const;
56 FramebufferAttachment *getDepthStencilBuffer() const;
57 FramebufferAttachment *getDepthOrStencilbuffer() const;
58 FramebufferAttachment *getReadColorbuffer() const;
shannon.woods%transgaming.com@gtempaccount.comf6863e02013-04-13 03:34:00 +000059 GLenum getReadColorbufferType() const;
Jamie Madill3c7fa222014-06-05 13:08:51 -040060 FramebufferAttachment *getFirstColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061
Jamie Madille92a3542014-07-03 10:38:58 -040062 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
Geoff Langc90d73a2013-07-22 16:39:23 -040063
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000064 GLenum getDrawBufferState(unsigned int colorAttachment) const;
65 void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
66
shannon.woods%transgaming.com@gtempaccount.comdae24092013-04-13 03:31:31 +000067 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
68 bool hasEnabledColorAttachment() const;
shannon.woods%transgaming.com@gtempaccount.com3b57b4f2013-04-13 03:28:29 +000069 bool hasStencil() const;
Jamie Madill48faf802014-11-06 15:27:22 -050070 int getSamples(const gl::Data &data) const;
shannonwoods@chromium.org24ac8502013-05-30 00:01:37 +000071 bool usingExtendedDrawBuffers() const;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +000072
Jamie Madill48faf802014-11-06 15:27:22 -050073 virtual GLenum completeness(const gl::Data &data) const;
Jamie Madille92a3542014-07-03 10:38:58 -040074 bool hasValidDepthStencil() const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000075
Geoff Lang64f23f62014-09-10 14:40:12 -040076 Error invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
77 Error invalidateSub(GLsizei numAttachments, const GLenum *attachments, 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.
Jamie Madill48faf802014-11-06 15:27:22 -050082 ColorbufferInfo getColorbuffersForRender(const rx::Workarounds &workarounds) const;
Jamie Madillce20c7f2014-09-03 11:56:29 -040083
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000084 protected:
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040085 GLuint mId;
86
Jamie Madille261b442014-06-25 12:42:21 -040087 FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
shannon.woods%transgaming.com@gtempaccount.comf30ccc22013-04-13 03:28:36 +000088 GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
89 GLenum mReadBufferState;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000090
Jamie Madille261b442014-06-25 12:42:21 -040091 FramebufferAttachment *mDepthbuffer;
92 FramebufferAttachment *mStencilbuffer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000093
Jamie Madillaef95de2014-09-05 10:12:41 -040094 private:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095 DISALLOW_COPY_AND_ASSIGN(Framebuffer);
96
Jamie Madillaef95de2014-09-05 10:12:41 -040097 FramebufferAttachment *createAttachment(GLenum binding, GLenum type, GLuint handle, GLint level, GLint layer) const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098};
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000099
100class DefaultFramebuffer : public Framebuffer
101{
102 public:
Jamie Madill48faf802014-11-06 15:27:22 -0500103 DefaultFramebuffer(rx::RenderbufferImpl *colorbuffer, rx::RenderbufferImpl *depthStencil);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000104
Jamie Madill48faf802014-11-06 15:27:22 -0500105 GLenum completeness(const gl::Data &data) const override;
Jamie Madille92a3542014-07-03 10:38:58 -0400106 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000107
108 private:
109 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
110};
111
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000112}
113
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400114namespace rx
115{
116class RenderTarget;
117
118// TODO: place this in FramebufferD3D.h
Geoff Lang64f23f62014-09-10 14:40:12 -0400119gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT);
Jamie Madill612e2e42014-09-12 13:26:55 -0400120unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment);
121
Jamie Madill9f0b42a2014-09-12 10:25:27 -0400122}
123
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000124#endif // LIBGLESV2_FRAMEBUFFER_H_