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 | // Renderbuffer.h: Defines the wrapper class Renderbuffer, as well as the |
16 | // class hierarchy used to store its contents: RenderbufferStorage, Colorbuffer, |
17 | // DepthStencilbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer |
18 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108. |
19 | |
20 | #ifndef LIBGLESV2_RENDERBUFFER_H_ |
21 | #define LIBGLESV2_RENDERBUFFER_H_ |
22 | |
23 | #include "common/Object.hpp" |
24 | #include "common/Image.hpp" |
25 | |
26 | #include <GLES2/gl2.h> |
27 | |
28 | namespace es2 |
29 | { |
30 | |
31 | class Texture2D; |
32 | class Texture3D; |
33 | class TextureCubeMap; |
34 | class Texture2DRect; |
35 | class Renderbuffer; |
36 | class Colorbuffer; |
37 | class DepthStencilbuffer; |
38 | |
39 | class RenderbufferInterface |
40 | { |
41 | public: |
42 | RenderbufferInterface(); |
43 | |
44 | virtual ~RenderbufferInterface() {} |
45 | |
46 | virtual void addProxyRef(const Renderbuffer *proxy); |
47 | virtual void releaseProxy(const Renderbuffer *proxy); |
48 | |
49 | virtual egl::Image *getRenderTarget() = 0; |
50 | virtual egl::Image *createSharedImage() = 0; |
51 | virtual bool isShared() const = 0; |
52 | |
53 | virtual GLsizei getWidth() const = 0; |
54 | virtual GLsizei getHeight() const = 0; |
55 | virtual GLsizei getDepth() const { return 1; } |
56 | virtual GLint getLevel() const { return 0; } |
57 | virtual GLint getFormat() const = 0; |
58 | virtual GLsizei getSamples() const = 0; |
59 | |
60 | virtual void setLevel(GLint) {} |
61 | |
62 | GLuint getRedSize() const; |
63 | GLuint getGreenSize() const; |
64 | GLuint getBlueSize() const; |
65 | GLuint getAlphaSize() const; |
66 | GLuint getDepthSize() const; |
67 | GLuint getStencilSize() const; |
68 | }; |
69 | |
70 | class RenderbufferTexture2D : public RenderbufferInterface |
71 | { |
72 | public: |
73 | RenderbufferTexture2D(Texture2D *texture, GLint level); |
74 | |
75 | ~RenderbufferTexture2D() override; |
76 | |
77 | void addProxyRef(const Renderbuffer *proxy) override; |
78 | void releaseProxy(const Renderbuffer *proxy) override; |
79 | |
80 | egl::Image *getRenderTarget() override; |
81 | egl::Image *createSharedImage() override; |
82 | bool isShared() const override; |
83 | |
84 | GLsizei getWidth() const override; |
85 | GLsizei getHeight() const override; |
86 | GLint getLevel() const override { return mLevel; } |
87 | GLint getFormat() const override; |
88 | GLsizei getSamples() const override; |
89 | |
90 | void setLevel(GLint level) override { mLevel = level; } |
91 | |
92 | private: |
93 | gl::BindingPointer<Texture2D> mTexture2D; |
94 | GLint mLevel; |
95 | }; |
96 | |
97 | class RenderbufferTexture2DRect : public RenderbufferInterface |
98 | { |
99 | public: |
100 | RenderbufferTexture2DRect(Texture2DRect *texture); |
101 | |
102 | ~RenderbufferTexture2DRect() override; |
103 | |
104 | void addProxyRef(const Renderbuffer *proxy) override; |
105 | void releaseProxy(const Renderbuffer *proxy) override; |
106 | |
107 | egl::Image *getRenderTarget() override; |
108 | egl::Image *createSharedImage() override; |
109 | bool isShared() const override; |
110 | |
111 | GLsizei getWidth() const override; |
112 | GLsizei getHeight() const override; |
113 | GLint getFormat() const override; |
114 | GLsizei getSamples() const override; |
115 | |
116 | private: |
117 | gl::BindingPointer<Texture2DRect> mTexture2DRect; |
118 | }; |
119 | |
120 | class RenderbufferTexture3D : public RenderbufferInterface |
121 | { |
122 | public: |
123 | RenderbufferTexture3D(Texture3D *texture, GLint level); |
124 | |
125 | ~RenderbufferTexture3D() override; |
126 | |
127 | void addProxyRef(const Renderbuffer *proxy) override; |
128 | void releaseProxy(const Renderbuffer *proxy) override; |
129 | |
130 | egl::Image *getRenderTarget() override; |
131 | egl::Image *createSharedImage() override; |
132 | bool isShared() const override; |
133 | |
134 | GLsizei getWidth() const override; |
135 | GLsizei getHeight() const override; |
136 | GLsizei getDepth() const override; |
137 | GLint getLevel() const override { return mLevel; } |
138 | GLint getFormat() const override; |
139 | GLsizei getSamples() const override; |
140 | |
141 | void setLevel(GLint level) override { mLevel = level; } |
142 | |
143 | private: |
144 | gl::BindingPointer<Texture3D> mTexture3D; |
145 | GLint mLevel; |
146 | }; |
147 | |
148 | class RenderbufferTextureCubeMap : public RenderbufferInterface |
149 | { |
150 | public: |
151 | RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target, GLint level); |
152 | |
153 | ~RenderbufferTextureCubeMap() override; |
154 | |
155 | void addProxyRef(const Renderbuffer *proxy) override; |
156 | void releaseProxy(const Renderbuffer *proxy) override; |
157 | |
158 | egl::Image *getRenderTarget() override; |
159 | egl::Image *createSharedImage() override; |
160 | bool isShared() const override; |
161 | |
162 | GLsizei getWidth() const override; |
163 | GLsizei getHeight() const override; |
164 | GLint getLevel() const override { return mLevel; } |
165 | GLint getFormat() const override; |
166 | GLsizei getSamples() const override; |
167 | |
168 | void setLevel(GLint level) override { mLevel = level; } |
169 | |
170 | private: |
171 | gl::BindingPointer<TextureCubeMap> mTextureCubeMap; |
172 | GLenum mTarget; |
173 | GLint mLevel; |
174 | }; |
175 | |
176 | // A class derived from RenderbufferStorage is created whenever glRenderbufferStorage |
177 | // is called. The specific concrete type depends on whether the internal format is |
178 | // colour depth, stencil or packed depth/stencil. |
179 | class RenderbufferStorage : public RenderbufferInterface |
180 | { |
181 | public: |
182 | RenderbufferStorage(); |
183 | |
184 | ~RenderbufferStorage() override = 0; |
185 | |
186 | egl::Image *getRenderTarget() override = 0; |
187 | egl::Image *createSharedImage() override = 0; |
188 | bool isShared() const override = 0; |
189 | |
190 | GLsizei getWidth() const override; |
191 | GLsizei getHeight() const override; |
192 | GLint getFormat() const override; |
193 | GLsizei getSamples() const override; |
194 | |
195 | protected: |
196 | GLsizei mWidth; |
197 | GLsizei mHeight; |
198 | GLenum format; |
199 | GLsizei mSamples; |
200 | }; |
201 | |
202 | // Renderbuffer implements the GL renderbuffer object. |
203 | // It's only a proxy for a RenderbufferInterface instance; the internal object |
204 | // can change whenever glRenderbufferStorage is called. |
205 | class Renderbuffer : public gl::NamedObject |
206 | { |
207 | public: |
208 | Renderbuffer(GLuint name, RenderbufferInterface *storage); |
209 | |
210 | ~Renderbuffer() override; |
211 | |
212 | // These functions from Object are overloaded here because |
213 | // Textures need to maintain their own count of references to them via |
214 | // Renderbuffers/RenderbufferTextures. These functions invoke those |
215 | // reference counting functions on the RenderbufferInterface. |
216 | void addRef() override; |
217 | void release() override; |
218 | |
219 | egl::Image *getRenderTarget(); |
220 | virtual egl::Image *createSharedImage(); |
221 | virtual bool isShared() const; |
222 | |
223 | GLsizei getWidth() const; |
224 | GLsizei getHeight() const; |
225 | GLsizei getDepth() const; |
226 | GLint getLevel() const; |
227 | GLint getFormat() const; |
228 | GLuint getRedSize() const; |
229 | GLuint getGreenSize() const; |
230 | GLuint getBlueSize() const; |
231 | GLuint getAlphaSize() const; |
232 | GLuint getDepthSize() const; |
233 | GLuint getStencilSize() const; |
234 | GLsizei getSamples() const; |
235 | |
236 | void setLevel(GLint level); |
237 | void setStorage(RenderbufferStorage *newStorage); |
238 | |
239 | private: |
240 | RenderbufferInterface *mInstance; |
241 | }; |
242 | |
243 | class Colorbuffer : public RenderbufferStorage |
244 | { |
245 | public: |
246 | explicit Colorbuffer(egl::Image *renderTarget); |
247 | Colorbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples); |
248 | |
249 | ~Colorbuffer() override; |
250 | |
251 | egl::Image *getRenderTarget() override; |
252 | egl::Image *createSharedImage() override; |
253 | bool isShared() const override; |
254 | |
255 | private: |
256 | egl::Image *mRenderTarget; |
257 | }; |
258 | |
259 | class DepthStencilbuffer : public RenderbufferStorage |
260 | { |
261 | public: |
262 | explicit DepthStencilbuffer(egl::Image *depthStencil); |
263 | DepthStencilbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples); |
264 | |
265 | ~DepthStencilbuffer(); |
266 | |
267 | egl::Image *getRenderTarget() override; |
268 | egl::Image *createSharedImage() override; |
269 | bool isShared() const override; |
270 | |
271 | protected: |
272 | egl::Image *mDepthStencil; |
273 | }; |
274 | |
275 | class Depthbuffer : public DepthStencilbuffer |
276 | { |
277 | public: |
278 | explicit Depthbuffer(egl::Image *depthStencil); |
279 | Depthbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples); |
280 | |
281 | ~Depthbuffer() override; |
282 | }; |
283 | |
284 | class Stencilbuffer : public DepthStencilbuffer |
285 | { |
286 | public: |
287 | explicit Stencilbuffer(egl::Image *depthStencil); |
288 | Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples); |
289 | |
290 | ~Stencilbuffer() override; |
291 | }; |
292 | } |
293 | |
294 | #endif // LIBGLESV2_RENDERBUFFER_H_ |
295 | |