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