Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 1 | // |
2 | // Copyright (c) 2014 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 | // FramebufferAttachment.cpp: the gl::FramebufferAttachment class and its derived classes | ||||
8 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108. | ||||
9 | |||||
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 11 | |
12 | #include "common/utilities.h" | ||||
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 13 | #include "libANGLE/Renderbuffer.h" |
14 | #include "libANGLE/Texture.h" | ||||
15 | #include "libANGLE/formatutils.h" | ||||
16 | #include "libANGLE/renderer/DefaultAttachmentImpl.h" | ||||
17 | #include "libANGLE/renderer/FramebufferImpl.h" | ||||
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 18 | |
19 | namespace gl | ||||
20 | { | ||||
21 | |||||
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 22 | ////// FramebufferAttachment Implementation ////// |
23 | |||||
Jamie Madill | aef95de | 2014-09-05 10:12:41 -0400 | [diff] [blame] | 24 | FramebufferAttachment::FramebufferAttachment(GLenum binding) |
25 | : mBinding(binding) | ||||
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 26 | { |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 27 | } |
28 | |||||
29 | FramebufferAttachment::~FramebufferAttachment() | ||||
30 | { | ||||
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 31 | } |
32 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 33 | GLuint FramebufferAttachment::getRedSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 34 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 35 | return GetInternalFormatInfo(getInternalFormat()).redBits; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 36 | } |
37 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 38 | GLuint FramebufferAttachment::getGreenSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 39 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 40 | return GetInternalFormatInfo(getInternalFormat()).greenBits; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 41 | } |
42 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 43 | GLuint FramebufferAttachment::getBlueSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 44 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 45 | return GetInternalFormatInfo(getInternalFormat()).blueBits; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 46 | } |
47 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 48 | GLuint FramebufferAttachment::getAlphaSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 49 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 50 | return GetInternalFormatInfo(getInternalFormat()).alphaBits; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 51 | } |
52 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 53 | GLuint FramebufferAttachment::getDepthSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 54 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 55 | return GetInternalFormatInfo(getInternalFormat()).depthBits; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 56 | } |
57 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 58 | GLuint FramebufferAttachment::getStencilSize() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 59 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 60 | return GetInternalFormatInfo(getInternalFormat()).stencilBits; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 61 | } |
62 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 63 | GLenum FramebufferAttachment::getComponentType() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 64 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 65 | return GetInternalFormatInfo(getInternalFormat()).componentType; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 66 | } |
67 | |||||
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 68 | GLenum FramebufferAttachment::getColorEncoding() const |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 69 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 70 | return GetInternalFormatInfo(getInternalFormat()).colorEncoding; |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 71 | } |
72 | |||||
Jamie Madill | 3592a33 | 2014-09-03 15:07:15 -0400 | [diff] [blame] | 73 | ///// TextureAttachment Implementation //////// |
74 | |||||
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 75 | TextureAttachment::TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index) |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 76 | : FramebufferAttachment(binding), |
77 | mIndex(index) | ||||
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 78 | { |
79 | mTexture.set(texture); | ||||
80 | } | ||||
81 | |||||
82 | TextureAttachment::~TextureAttachment() | ||||
83 | { | ||||
84 | mTexture.set(NULL); | ||||
85 | } | ||||
Jamie Madill | aef95de | 2014-09-05 10:12:41 -0400 | [diff] [blame] | 86 | |
Jamie Madill | 3592a33 | 2014-09-03 15:07:15 -0400 | [diff] [blame] | 87 | GLsizei TextureAttachment::getSamples() const |
88 | { | ||||
89 | return 0; | ||||
90 | } | ||||
91 | |||||
92 | GLuint TextureAttachment::id() const | ||||
93 | { | ||||
Jamie Madill | eeb7b0e | 2014-09-03 15:07:20 -0400 | [diff] [blame] | 94 | return mTexture->id(); |
Jamie Madill | 3592a33 | 2014-09-03 15:07:15 -0400 | [diff] [blame] | 95 | } |
96 | |||||
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 97 | GLsizei TextureAttachment::getWidth() const |
98 | { | ||||
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 99 | return mTexture->getWidth(mIndex.type, mIndex.mipIndex); |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 100 | } |
101 | |||||
102 | GLsizei TextureAttachment::getHeight() const | ||||
103 | { | ||||
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 104 | return mTexture->getHeight(mIndex.type, mIndex.mipIndex); |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 105 | } |
106 | |||||
107 | GLenum TextureAttachment::getInternalFormat() const | ||||
108 | { | ||||
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 109 | return mTexture->getInternalFormat(mIndex.type, mIndex.mipIndex); |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 110 | } |
111 | |||||
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 112 | GLenum TextureAttachment::type() const |
113 | { | ||||
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 114 | return GL_TEXTURE; |
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 115 | } |
116 | |||||
117 | GLint TextureAttachment::mipLevel() const | ||||
118 | { | ||||
119 | return mIndex.mipIndex; | ||||
120 | } | ||||
121 | |||||
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 122 | GLenum TextureAttachment::cubeMapFace() const |
123 | { | ||||
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 124 | return IsCubeMapTextureTarget(mIndex.type) ? mIndex.type : GL_NONE; |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 125 | } |
126 | |||||
Jamie Madill | de3ed70 | 2014-09-03 15:07:17 -0400 | [diff] [blame] | 127 | GLint TextureAttachment::layer() const |
128 | { | ||||
129 | return mIndex.layerIndex; | ||||
130 | } | ||||
131 | |||||
Geoff Lang | 4f4207f | 2014-12-01 10:07:56 -0500 | [diff] [blame] | 132 | Texture *TextureAttachment::getTexture() const |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 133 | { |
134 | return mTexture.get(); | ||||
135 | } | ||||
136 | |||||
Jamie Madill | ac7579c | 2014-09-17 16:59:33 -0400 | [diff] [blame] | 137 | const ImageIndex *TextureAttachment::getTextureImageIndex() const |
138 | { | ||||
139 | return &mIndex; | ||||
140 | } | ||||
141 | |||||
Geoff Lang | 4f4207f | 2014-12-01 10:07:56 -0500 | [diff] [blame] | 142 | Renderbuffer *TextureAttachment::getRenderbuffer() const |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 143 | { |
144 | UNREACHABLE(); | ||||
145 | return NULL; | ||||
146 | } | ||||
147 | |||||
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 148 | ////// RenderbufferAttachment Implementation ////// |
149 | |||||
Jamie Madill | aef95de | 2014-09-05 10:12:41 -0400 | [diff] [blame] | 150 | RenderbufferAttachment::RenderbufferAttachment(GLenum binding, Renderbuffer *renderbuffer) |
151 | : FramebufferAttachment(binding) | ||||
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 152 | { |
153 | ASSERT(renderbuffer); | ||||
154 | mRenderbuffer.set(renderbuffer); | ||||
155 | } | ||||
156 | |||||
157 | RenderbufferAttachment::~RenderbufferAttachment() | ||||
158 | { | ||||
159 | mRenderbuffer.set(NULL); | ||||
160 | } | ||||
161 | |||||
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 162 | GLsizei RenderbufferAttachment::getWidth() const |
163 | { | ||||
164 | return mRenderbuffer->getWidth(); | ||||
165 | } | ||||
166 | |||||
167 | GLsizei RenderbufferAttachment::getHeight() const | ||||
168 | { | ||||
169 | return mRenderbuffer->getHeight(); | ||||
170 | } | ||||
171 | |||||
172 | GLenum RenderbufferAttachment::getInternalFormat() const | ||||
173 | { | ||||
174 | return mRenderbuffer->getInternalFormat(); | ||||
175 | } | ||||
176 | |||||
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 177 | GLsizei RenderbufferAttachment::getSamples() const |
178 | { | ||||
Shannon Woods | e2632d2 | 2014-10-17 13:08:51 -0400 | [diff] [blame] | 179 | return mRenderbuffer->getSamples(); |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 180 | } |
181 | |||||
Jamie Madill | 218b6ed | 2014-06-16 10:34:01 -0400 | [diff] [blame] | 182 | GLuint RenderbufferAttachment::id() const |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 183 | { |
Jamie Madill | 218b6ed | 2014-06-16 10:34:01 -0400 | [diff] [blame] | 184 | return mRenderbuffer->id(); |
185 | } | ||||
186 | |||||
187 | GLenum RenderbufferAttachment::type() const | ||||
188 | { | ||||
189 | return GL_RENDERBUFFER; | ||||
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 190 | } |
191 | |||||
Jamie Madill | 9c074a3 | 2014-06-16 10:34:02 -0400 | [diff] [blame] | 192 | GLint RenderbufferAttachment::mipLevel() const |
193 | { | ||||
194 | return 0; | ||||
195 | } | ||||
196 | |||||
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 197 | GLenum RenderbufferAttachment::cubeMapFace() const |
198 | { | ||||
199 | return GL_NONE; | ||||
200 | } | ||||
201 | |||||
Jamie Madill | 9c074a3 | 2014-06-16 10:34:02 -0400 | [diff] [blame] | 202 | GLint RenderbufferAttachment::layer() const |
203 | { | ||||
204 | return 0; | ||||
205 | } | ||||
206 | |||||
Geoff Lang | 4f4207f | 2014-12-01 10:07:56 -0500 | [diff] [blame] | 207 | Texture *RenderbufferAttachment::getTexture() const |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame] | 208 | { |
209 | UNREACHABLE(); | ||||
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 210 | return NULL; |
211 | } | ||||
212 | |||||
Jamie Madill | ac7579c | 2014-09-17 16:59:33 -0400 | [diff] [blame] | 213 | const ImageIndex *RenderbufferAttachment::getTextureImageIndex() const |
214 | { | ||||
215 | UNREACHABLE(); | ||||
216 | return NULL; | ||||
217 | } | ||||
218 | |||||
Geoff Lang | 4f4207f | 2014-12-01 10:07:56 -0500 | [diff] [blame] | 219 | Renderbuffer *RenderbufferAttachment::getRenderbuffer() const |
Jamie Madill | 5b5d124 | 2014-09-09 15:15:36 -0400 | [diff] [blame] | 220 | { |
221 | return mRenderbuffer.get(); | ||||
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 222 | } |
223 | |||||
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 224 | |
225 | DefaultAttachment::DefaultAttachment(GLenum binding, rx::DefaultAttachmentImpl *impl) | ||||
226 | : FramebufferAttachment(binding), | ||||
227 | mImpl(impl) | ||||
228 | { | ||||
229 | ASSERT(mImpl); | ||||
230 | } | ||||
231 | |||||
232 | DefaultAttachment::~DefaultAttachment() | ||||
233 | { | ||||
234 | SafeDelete(mImpl); | ||||
235 | } | ||||
236 | |||||
237 | GLsizei DefaultAttachment::getWidth() const | ||||
238 | { | ||||
239 | return mImpl->getWidth(); | ||||
240 | } | ||||
241 | |||||
242 | GLsizei DefaultAttachment::getHeight() const | ||||
243 | { | ||||
244 | return mImpl->getHeight(); | ||||
245 | } | ||||
246 | |||||
247 | GLenum DefaultAttachment::getInternalFormat() const | ||||
248 | { | ||||
249 | return mImpl->getInternalFormat(); | ||||
250 | } | ||||
251 | |||||
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 252 | GLsizei DefaultAttachment::getSamples() const |
253 | { | ||||
254 | return mImpl->getSamples(); | ||||
255 | } | ||||
256 | |||||
257 | GLuint DefaultAttachment::id() const | ||||
258 | { | ||||
259 | return 0; | ||||
260 | } | ||||
261 | |||||
262 | GLenum DefaultAttachment::type() const | ||||
263 | { | ||||
264 | return GL_FRAMEBUFFER_DEFAULT; | ||||
265 | } | ||||
266 | |||||
267 | GLint DefaultAttachment::mipLevel() const | ||||
268 | { | ||||
269 | return 0; | ||||
270 | } | ||||
271 | |||||
272 | GLenum DefaultAttachment::cubeMapFace() const | ||||
273 | { | ||||
274 | return GL_NONE; | ||||
275 | } | ||||
276 | |||||
277 | GLint DefaultAttachment::layer() const | ||||
278 | { | ||||
279 | return 0; | ||||
280 | } | ||||
281 | |||||
Geoff Lang | 4f4207f | 2014-12-01 10:07:56 -0500 | [diff] [blame] | 282 | Texture *DefaultAttachment::getTexture() const |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 283 | { |
284 | UNREACHABLE(); | ||||
285 | return NULL; | ||||
286 | } | ||||
287 | |||||
288 | const ImageIndex *DefaultAttachment::getTextureImageIndex() const | ||||
289 | { | ||||
290 | UNREACHABLE(); | ||||
291 | return NULL; | ||||
292 | } | ||||
293 | |||||
Geoff Lang | 4f4207f | 2014-12-01 10:07:56 -0500 | [diff] [blame] | 294 | Renderbuffer *DefaultAttachment::getRenderbuffer() const |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 295 | { |
296 | UNREACHABLE(); | ||||
297 | return NULL; | ||||
298 | } | ||||
299 | |||||
300 | rx::DefaultAttachmentImpl *DefaultAttachment::getImplementation() const | ||||
301 | { | ||||
302 | return mImpl; | ||||
303 | } | ||||
304 | |||||
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 305 | } |