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