1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | // Framebuffer.h: Defines the Framebuffer class. Implements GL framebuffer |
16 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105. |
17 | |
18 | #ifndef LIBGLESV2_FRAMEBUFFER_H_ |
19 | #define LIBGLESV2_FRAMEBUFFER_H_ |
20 | |
21 | #include "Context.h" |
22 | #include "common/Object.hpp" |
23 | #include "common/Image.hpp" |
24 | |
25 | #include <GLES2/gl2.h> |
26 | |
27 | namespace es2 |
28 | { |
29 | class Renderbuffer; |
30 | class Colorbuffer; |
31 | class Depthbuffer; |
32 | class Stencilbuffer; |
33 | class DepthStencilbuffer; |
34 | |
35 | class Framebuffer |
36 | { |
37 | public: |
38 | Framebuffer(); |
39 | |
40 | virtual ~Framebuffer(); |
41 | |
42 | void setColorbuffer(GLenum type, GLuint colorbuffer, GLuint index, GLint level = 0, GLint layer = 0); |
43 | void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level = 0, GLint layer = 0); |
44 | void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level = 0, GLint layer = 0); |
45 | |
46 | void setReadBuffer(GLenum buf); |
47 | void setDrawBuffer(GLuint index, GLenum buf); |
48 | GLenum getReadBuffer() const; |
49 | GLenum getDrawBuffer(GLuint index) const; |
50 | |
51 | void detachTexture(GLuint texture); |
52 | void detachRenderbuffer(GLuint renderbuffer); |
53 | |
54 | egl::Image *getRenderTarget(GLuint index); |
55 | egl::Image *getReadRenderTarget(); |
56 | egl::Image *getDepthBuffer(); |
57 | egl::Image *getStencilBuffer(); |
58 | |
59 | Renderbuffer *getColorbuffer(GLuint index) const; |
60 | Renderbuffer *getReadColorbuffer() const; |
61 | Renderbuffer *getDepthbuffer() const; |
62 | Renderbuffer *getStencilbuffer() const; |
63 | |
64 | GLenum getReadBufferType(); |
65 | GLenum getColorbufferType(GLuint index); |
66 | GLenum getDepthbufferType(); |
67 | GLenum getStencilbufferType(); |
68 | |
69 | GLuint getColorbufferName(GLuint index); |
70 | GLuint getDepthbufferName(); |
71 | GLuint getStencilbufferName(); |
72 | |
73 | GLint getColorbufferLayer(GLuint index); |
74 | GLint getDepthbufferLayer(); |
75 | GLint getStencilbufferLayer(); |
76 | |
77 | bool hasStencil(); |
78 | |
79 | GLenum completeness(); |
80 | GLenum completeness(int &width, int &height, int &samples); |
81 | |
82 | GLenum getImplementationColorReadFormat() const; |
83 | GLenum getImplementationColorReadType() const; |
84 | GLenum getDepthReadFormat() const; |
85 | GLenum getDepthReadType() const; |
86 | |
87 | virtual bool isDefaultFramebuffer() const { return false; } |
88 | |
89 | static bool IsRenderbuffer(GLenum type); |
90 | |
91 | protected: |
92 | GLuint getReadBufferIndex() const; |
93 | |
94 | GLenum readBuffer; |
95 | GLenum drawBuffer[MAX_COLOR_ATTACHMENTS]; |
96 | |
97 | GLenum mColorbufferType[MAX_COLOR_ATTACHMENTS]; |
98 | gl::BindingPointer<Renderbuffer> mColorbufferPointer[MAX_COLOR_ATTACHMENTS]; |
99 | GLint mColorbufferLayer[MAX_COLOR_ATTACHMENTS]; |
100 | |
101 | GLenum mDepthbufferType; |
102 | gl::BindingPointer<Renderbuffer> mDepthbufferPointer; |
103 | GLint mDepthbufferLayer; |
104 | |
105 | GLenum mStencilbufferType; |
106 | gl::BindingPointer<Renderbuffer> mStencilbufferPointer; |
107 | GLint mStencilbufferLayer; |
108 | |
109 | private: |
110 | Renderbuffer *lookupRenderbuffer(GLenum type, GLuint handle, GLint level) const; |
111 | }; |
112 | |
113 | class DefaultFramebuffer : public Framebuffer |
114 | { |
115 | public: |
116 | DefaultFramebuffer(); |
117 | DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil); |
118 | |
119 | bool isDefaultFramebuffer() const override { return true; } |
120 | }; |
121 | |
122 | } |
123 | |
124 | #endif // LIBGLESV2_FRAMEBUFFER_H_ |
125 | |