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