1//
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.
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
13#include <vector>
14
15#include "common/angleutils.h"
16#include "common/RefCountObject.h"
17#include "constants.h"
18
19namespace rx
20{
21class Renderer;
22}
23
24namespace gl
25{
26class FramebufferAttachment;
27class Colorbuffer;
28class Depthbuffer;
29class Stencilbuffer;
30class DepthStencilbuffer;
31struct Caps;
32
33typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
34
35class Framebuffer
36{
37  public:
38    Framebuffer(rx::Renderer *renderer, GLuint id);
39
40    virtual ~Framebuffer();
41
42    GLuint id() const { return mId; }
43
44    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);
48
49    void detachTexture(GLuint texture);
50    void detachRenderbuffer(GLuint renderbuffer);
51
52    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;
58    GLenum getReadColorbufferType() const;
59    FramebufferAttachment *getFirstColorbuffer() const;
60
61    virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
62
63    GLenum getDrawBufferState(unsigned int colorAttachment) const;
64    void setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer);
65
66    bool isEnabledColorAttachment(unsigned int colorAttachment) const;
67    bool hasEnabledColorAttachment() const;
68    bool hasStencil() const;
69    int getSamples() const;
70    bool usingExtendedDrawBuffers() const;
71
72    virtual GLenum completeness() const;
73    bool hasValidDepthStencil() const;
74
75    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);
78
79    // 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
84  protected:
85    rx::Renderer *mRenderer;
86
87    GLuint mId;
88
89    FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
90    GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
91    GLenum mReadBufferState;
92
93    FramebufferAttachment *mDepthbuffer;
94    FramebufferAttachment *mStencilbuffer;
95
96  private:
97    DISALLOW_COPY_AND_ASSIGN(Framebuffer);
98
99    FramebufferAttachment *createAttachment(GLenum binding, GLenum type, GLuint handle, GLint level, GLint layer) const;
100};
101
102class DefaultFramebuffer : public Framebuffer
103{
104  public:
105    DefaultFramebuffer(rx::Renderer *Renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil);
106
107    virtual GLenum completeness() const;
108    virtual FramebufferAttachment *getAttachment(GLenum attachment) const;
109
110  private:
111    DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
112};
113
114}
115
116namespace rx
117{
118class RenderTarget;
119
120// TODO: place this in FramebufferD3D.h
121RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment);
122unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment);
123
124}
125
126#endif   // LIBGLESV2_FRAMEBUFFER_H_
127