2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
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.
10 #ifndef LIBGLESV2_FRAMEBUFFER_H_
11 #define LIBGLESV2_FRAMEBUFFER_H_
13 #include "libGLESv2/Error.h"
15 #include "common/angleutils.h"
16 #include "common/RefCountObject.h"
17 #include "Constants.h"
28 class FramebufferAttachment;
32 class DepthStencilbuffer;
35 typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
40 Framebuffer(rx::Renderer *renderer, GLuint id);
42 virtual ~Framebuffer();
44 GLuint id() const { return mId; }
46 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);
51 void detachTexture(GLuint texture);
52 void detachRenderbuffer(GLuint renderbuffer);
54 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;
60 GLenum getReadColorbufferType() const;
61 FramebufferAttachment *getFirstColorbuffer() const;
63 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
65 GLenum getDrawBufferState(unsigned int colorAttachment) const;
66 void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
68 bool isEnabledColorAttachment(unsigned int colorAttachment) const;
69 bool hasEnabledColorAttachment() const;
70 bool hasStencil() const;
71 int getSamples() const;
72 bool usingExtendedDrawBuffers() const;
74 virtual GLenum completeness() const;
75 bool hasValidDepthStencil() const;
77 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);
80 // 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;
86 rx::Renderer *mRenderer;
90 FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
91 GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
92 GLenum mReadBufferState;
94 FramebufferAttachment *mDepthbuffer;
95 FramebufferAttachment *mStencilbuffer;
98 DISALLOW_COPY_AND_ASSIGN(Framebuffer);
100 FramebufferAttachment *createAttachment(GLenum binding, GLenum type, GLuint handle, GLint level, GLint layer) const;
103 class DefaultFramebuffer : public Framebuffer
106 DefaultFramebuffer(rx::Renderer *Renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil);
108 virtual GLenum completeness() const;
109 virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
112 DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
121 // TODO: place this in FramebufferD3D.h
122 gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT);
123 unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment);
127 #endif // LIBGLESV2_FRAMEBUFFER_H_