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