Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 1 | #include "precompiled.h" |
| 2 | // |
| 3 | // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. |
| 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // FramebufferAttachment.cpp: the gl::FramebufferAttachment class and its derived classes |
| 9 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108. |
| 10 | |
| 11 | #include "libGLESv2/FramebufferAttachment.h" |
| 12 | #include "libGLESv2/renderer/RenderTarget.h" |
| 13 | |
| 14 | #include "libGLESv2/Texture.h" |
| 15 | #include "libGLESv2/renderer/Renderer.h" |
| 16 | #include "libGLESv2/renderer/TextureStorage.h" |
| 17 | #include "common/utilities.h" |
| 18 | #include "libGLESv2/formatutils.h" |
| 19 | #include "libGLESv2/Renderbuffer.h" |
| 20 | |
| 21 | namespace gl |
| 22 | { |
| 23 | |
| 24 | FramebufferAttachmentInterface::FramebufferAttachmentInterface() |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | // The default case for classes inherited from FramebufferAttachmentInterface is not to |
| 29 | // need to do anything upon the reference count to the parent FramebufferAttachment incrementing |
| 30 | // or decrementing. |
| 31 | void FramebufferAttachmentInterface::addProxyRef(const FramebufferAttachment *proxy) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | void FramebufferAttachmentInterface::releaseProxy(const FramebufferAttachment *proxy) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | ///// Texture2DAttachment Implementation //////// |
| 40 | |
| 41 | Texture2DAttachment::Texture2DAttachment(Texture2D *texture, GLint level) : mLevel(level) |
| 42 | { |
| 43 | mTexture2D.set(texture); |
| 44 | } |
| 45 | |
| 46 | Texture2DAttachment::~Texture2DAttachment() |
| 47 | { |
| 48 | mTexture2D.set(NULL); |
| 49 | } |
| 50 | |
| 51 | // Textures need to maintain their own reference count for references via |
| 52 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 53 | void Texture2DAttachment::addProxyRef(const FramebufferAttachment *proxy) |
| 54 | { |
| 55 | mTexture2D->addProxyRef(proxy); |
| 56 | } |
| 57 | |
| 58 | void Texture2DAttachment::releaseProxy(const FramebufferAttachment *proxy) |
| 59 | { |
| 60 | mTexture2D->releaseProxy(proxy); |
| 61 | } |
| 62 | |
| 63 | rx::RenderTarget *Texture2DAttachment::getRenderTarget() |
| 64 | { |
| 65 | return mTexture2D->getRenderTarget(mLevel); |
| 66 | } |
| 67 | |
| 68 | rx::RenderTarget *Texture2DAttachment::getDepthStencil() |
| 69 | { |
| 70 | return mTexture2D->getDepthSencil(mLevel); |
| 71 | } |
| 72 | |
| 73 | rx::TextureStorage *Texture2DAttachment::getTextureStorage() |
| 74 | { |
| 75 | return mTexture2D->getNativeTexture()->getStorageInstance(); |
| 76 | } |
| 77 | |
| 78 | GLsizei Texture2DAttachment::getWidth() const |
| 79 | { |
| 80 | return mTexture2D->getWidth(mLevel); |
| 81 | } |
| 82 | |
| 83 | GLsizei Texture2DAttachment::getHeight() const |
| 84 | { |
| 85 | return mTexture2D->getHeight(mLevel); |
| 86 | } |
| 87 | |
| 88 | GLenum Texture2DAttachment::getInternalFormat() const |
| 89 | { |
| 90 | return mTexture2D->getInternalFormat(mLevel); |
| 91 | } |
| 92 | |
| 93 | GLenum Texture2DAttachment::getActualFormat() const |
| 94 | { |
| 95 | return mTexture2D->getActualFormat(mLevel); |
| 96 | } |
| 97 | |
| 98 | GLsizei Texture2DAttachment::getSamples() const |
| 99 | { |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | unsigned int Texture2DAttachment::getSerial() const |
| 104 | { |
| 105 | return mTexture2D->getRenderTargetSerial(mLevel); |
| 106 | } |
| 107 | |
| 108 | bool Texture2DAttachment::isTexture() const |
| 109 | { |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | unsigned int Texture2DAttachment::getTextureSerial() const |
| 114 | { |
| 115 | return mTexture2D->getTextureSerial(); |
| 116 | } |
| 117 | |
| 118 | ///// TextureCubeMapAttachment Implementation //////// |
| 119 | |
| 120 | TextureCubeMapAttachment::TextureCubeMapAttachment(TextureCubeMap *texture, GLenum faceTarget, GLint level) |
| 121 | : mFaceTarget(faceTarget), mLevel(level) |
| 122 | { |
| 123 | mTextureCubeMap.set(texture); |
| 124 | } |
| 125 | |
| 126 | TextureCubeMapAttachment::~TextureCubeMapAttachment() |
| 127 | { |
| 128 | mTextureCubeMap.set(NULL); |
| 129 | } |
| 130 | |
| 131 | // Textures need to maintain their own reference count for references via |
| 132 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 133 | void TextureCubeMapAttachment::addProxyRef(const FramebufferAttachment *proxy) |
| 134 | { |
| 135 | mTextureCubeMap->addProxyRef(proxy); |
| 136 | } |
| 137 | |
| 138 | void TextureCubeMapAttachment::releaseProxy(const FramebufferAttachment *proxy) |
| 139 | { |
| 140 | mTextureCubeMap->releaseProxy(proxy); |
| 141 | } |
| 142 | |
| 143 | rx::RenderTarget *TextureCubeMapAttachment::getRenderTarget() |
| 144 | { |
| 145 | return mTextureCubeMap->getRenderTarget(mFaceTarget, mLevel); |
| 146 | } |
| 147 | |
| 148 | rx::RenderTarget *TextureCubeMapAttachment::getDepthStencil() |
| 149 | { |
| 150 | return mTextureCubeMap->getDepthStencil(mFaceTarget, mLevel); |
| 151 | } |
| 152 | |
| 153 | rx::TextureStorage *TextureCubeMapAttachment::getTextureStorage() |
| 154 | { |
| 155 | return mTextureCubeMap->getNativeTexture()->getStorageInstance(); |
| 156 | } |
| 157 | |
| 158 | GLsizei TextureCubeMapAttachment::getWidth() const |
| 159 | { |
| 160 | return mTextureCubeMap->getWidth(mFaceTarget, mLevel); |
| 161 | } |
| 162 | |
| 163 | GLsizei TextureCubeMapAttachment::getHeight() const |
| 164 | { |
| 165 | return mTextureCubeMap->getHeight(mFaceTarget, mLevel); |
| 166 | } |
| 167 | |
| 168 | GLenum TextureCubeMapAttachment::getInternalFormat() const |
| 169 | { |
| 170 | return mTextureCubeMap->getInternalFormat(mFaceTarget, mLevel); |
| 171 | } |
| 172 | |
| 173 | GLenum TextureCubeMapAttachment::getActualFormat() const |
| 174 | { |
| 175 | return mTextureCubeMap->getActualFormat(mFaceTarget, mLevel); |
| 176 | } |
| 177 | |
| 178 | GLsizei TextureCubeMapAttachment::getSamples() const |
| 179 | { |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | unsigned int TextureCubeMapAttachment::getSerial() const |
| 184 | { |
| 185 | return mTextureCubeMap->getRenderTargetSerial(mFaceTarget, mLevel); |
| 186 | } |
| 187 | |
| 188 | bool TextureCubeMapAttachment::isTexture() const |
| 189 | { |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | unsigned int TextureCubeMapAttachment::getTextureSerial() const |
| 194 | { |
| 195 | return mTextureCubeMap->getTextureSerial(); |
| 196 | } |
| 197 | |
| 198 | ///// Texture3DAttachment Implementation //////// |
| 199 | |
| 200 | Texture3DAttachment::Texture3DAttachment(Texture3D *texture, GLint level, GLint layer) |
| 201 | : mLevel(level), mLayer(layer) |
| 202 | { |
| 203 | mTexture3D.set(texture); |
| 204 | } |
| 205 | |
| 206 | Texture3DAttachment::~Texture3DAttachment() |
| 207 | { |
| 208 | mTexture3D.set(NULL); |
| 209 | } |
| 210 | |
| 211 | // Textures need to maintain their own reference count for references via |
| 212 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 213 | void Texture3DAttachment::addProxyRef(const FramebufferAttachment *proxy) |
| 214 | { |
| 215 | mTexture3D->addProxyRef(proxy); |
| 216 | } |
| 217 | |
| 218 | void Texture3DAttachment::releaseProxy(const FramebufferAttachment *proxy) |
| 219 | { |
| 220 | mTexture3D->releaseProxy(proxy); |
| 221 | } |
| 222 | |
| 223 | rx::RenderTarget *Texture3DAttachment::getRenderTarget() |
| 224 | { |
| 225 | return mTexture3D->getRenderTarget(mLevel, mLayer); |
| 226 | } |
| 227 | |
| 228 | rx::RenderTarget *Texture3DAttachment::getDepthStencil() |
| 229 | { |
| 230 | return mTexture3D->getDepthStencil(mLevel, mLayer); |
| 231 | } |
| 232 | |
| 233 | rx::TextureStorage *Texture3DAttachment::getTextureStorage() |
| 234 | { |
| 235 | return mTexture3D->getNativeTexture()->getStorageInstance(); |
| 236 | } |
| 237 | |
| 238 | GLsizei Texture3DAttachment::getWidth() const |
| 239 | { |
| 240 | return mTexture3D->getWidth(mLevel); |
| 241 | } |
| 242 | |
| 243 | GLsizei Texture3DAttachment::getHeight() const |
| 244 | { |
| 245 | return mTexture3D->getHeight(mLevel); |
| 246 | } |
| 247 | |
| 248 | GLenum Texture3DAttachment::getInternalFormat() const |
| 249 | { |
| 250 | return mTexture3D->getInternalFormat(mLevel); |
| 251 | } |
| 252 | |
| 253 | GLenum Texture3DAttachment::getActualFormat() const |
| 254 | { |
| 255 | return mTexture3D->getActualFormat(mLevel); |
| 256 | } |
| 257 | |
| 258 | GLsizei Texture3DAttachment::getSamples() const |
| 259 | { |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | unsigned int Texture3DAttachment::getSerial() const |
| 264 | { |
| 265 | return mTexture3D->getRenderTargetSerial(mLevel, mLayer); |
| 266 | } |
| 267 | |
| 268 | bool Texture3DAttachment::isTexture() const |
| 269 | { |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | unsigned int Texture3DAttachment::getTextureSerial() const |
| 274 | { |
| 275 | return mTexture3D->getTextureSerial(); |
| 276 | } |
| 277 | |
| 278 | ////// Texture2DArrayAttachment Implementation ////// |
| 279 | |
| 280 | Texture2DArrayAttachment::Texture2DArrayAttachment(Texture2DArray *texture, GLint level, GLint layer) |
| 281 | : mLevel(level), mLayer(layer) |
| 282 | { |
| 283 | mTexture2DArray.set(texture); |
| 284 | } |
| 285 | |
| 286 | Texture2DArrayAttachment::~Texture2DArrayAttachment() |
| 287 | { |
| 288 | mTexture2DArray.set(NULL); |
| 289 | } |
| 290 | |
| 291 | void Texture2DArrayAttachment::addProxyRef(const FramebufferAttachment *proxy) |
| 292 | { |
| 293 | mTexture2DArray->addProxyRef(proxy); |
| 294 | } |
| 295 | |
| 296 | void Texture2DArrayAttachment::releaseProxy(const FramebufferAttachment *proxy) |
| 297 | { |
| 298 | mTexture2DArray->releaseProxy(proxy); |
| 299 | } |
| 300 | |
| 301 | rx::RenderTarget *Texture2DArrayAttachment::getRenderTarget() |
| 302 | { |
| 303 | return mTexture2DArray->getRenderTarget(mLevel, mLayer); |
| 304 | } |
| 305 | |
| 306 | rx::RenderTarget *Texture2DArrayAttachment::getDepthStencil() |
| 307 | { |
| 308 | return mTexture2DArray->getDepthStencil(mLevel, mLayer); |
| 309 | } |
| 310 | |
| 311 | rx::TextureStorage *Texture2DArrayAttachment::getTextureStorage() |
| 312 | { |
| 313 | return mTexture2DArray->getNativeTexture()->getStorageInstance(); |
| 314 | } |
| 315 | |
| 316 | GLsizei Texture2DArrayAttachment::getWidth() const |
| 317 | { |
| 318 | return mTexture2DArray->getWidth(mLevel); |
| 319 | } |
| 320 | |
| 321 | GLsizei Texture2DArrayAttachment::getHeight() const |
| 322 | { |
| 323 | return mTexture2DArray->getHeight(mLevel); |
| 324 | } |
| 325 | |
| 326 | GLenum Texture2DArrayAttachment::getInternalFormat() const |
| 327 | { |
| 328 | return mTexture2DArray->getInternalFormat(mLevel); |
| 329 | } |
| 330 | |
| 331 | GLenum Texture2DArrayAttachment::getActualFormat() const |
| 332 | { |
| 333 | return mTexture2DArray->getActualFormat(mLevel); |
| 334 | } |
| 335 | |
| 336 | GLsizei Texture2DArrayAttachment::getSamples() const |
| 337 | { |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | unsigned int Texture2DArrayAttachment::getSerial() const |
| 342 | { |
| 343 | return mTexture2DArray->getRenderTargetSerial(mLevel, mLayer); |
| 344 | } |
| 345 | |
| 346 | bool Texture2DArrayAttachment::isTexture() const |
| 347 | { |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | unsigned int Texture2DArrayAttachment::getTextureSerial() const |
| 352 | { |
| 353 | return mTexture2DArray->getTextureSerial(); |
| 354 | } |
| 355 | |
| 356 | ////// FramebufferAttachment Implementation ////// |
| 357 | |
| 358 | FramebufferAttachment::FramebufferAttachment(rx::Renderer *renderer, GLuint id, FramebufferAttachmentInterface *instance) : RefCountObject(id) |
| 359 | { |
| 360 | ASSERT(instance != NULL); |
| 361 | mInstance = instance; |
| 362 | |
| 363 | ASSERT(renderer != NULL); |
| 364 | mRenderer = renderer; |
| 365 | } |
| 366 | |
| 367 | FramebufferAttachment::~FramebufferAttachment() |
| 368 | { |
| 369 | delete mInstance; |
| 370 | } |
| 371 | |
| 372 | // The FramebufferAttachmentInterface contained in this FramebufferAttachment may need to maintain |
| 373 | // its own reference count, so we pass it on here. |
| 374 | void FramebufferAttachment::addRef() const |
| 375 | { |
| 376 | mInstance->addProxyRef(this); |
| 377 | |
| 378 | RefCountObject::addRef(); |
| 379 | } |
| 380 | |
| 381 | void FramebufferAttachment::release() const |
| 382 | { |
| 383 | mInstance->releaseProxy(this); |
| 384 | |
| 385 | RefCountObject::release(); |
| 386 | } |
| 387 | |
| 388 | rx::RenderTarget *FramebufferAttachment::getRenderTarget() |
| 389 | { |
| 390 | return mInstance->getRenderTarget(); |
| 391 | } |
| 392 | |
| 393 | rx::RenderTarget *FramebufferAttachment::getDepthStencil() |
| 394 | { |
| 395 | return mInstance->getDepthStencil(); |
| 396 | } |
| 397 | |
| 398 | rx::TextureStorage *FramebufferAttachment::getTextureStorage() |
| 399 | { |
| 400 | return mInstance->getTextureStorage(); |
| 401 | } |
| 402 | |
| 403 | GLsizei FramebufferAttachment::getWidth() const |
| 404 | { |
| 405 | return mInstance->getWidth(); |
| 406 | } |
| 407 | |
| 408 | GLsizei FramebufferAttachment::getHeight() const |
| 409 | { |
| 410 | return mInstance->getHeight(); |
| 411 | } |
| 412 | |
| 413 | GLenum FramebufferAttachment::getInternalFormat() const |
| 414 | { |
| 415 | return mInstance->getInternalFormat(); |
| 416 | } |
| 417 | |
| 418 | GLenum FramebufferAttachment::getActualFormat() const |
| 419 | { |
| 420 | return mInstance->getActualFormat(); |
| 421 | } |
| 422 | |
| 423 | GLuint FramebufferAttachment::getRedSize() const |
| 424 | { |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 425 | if (gl::GetRedBits(getInternalFormat(), mRenderer->getCurrentClientVersion()) > 0) |
| 426 | { |
| 427 | return gl::GetRedBits(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | return 0; |
| 432 | } |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | GLuint FramebufferAttachment::getGreenSize() const |
| 436 | { |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 437 | if (gl::GetGreenBits(getInternalFormat(), mRenderer->getCurrentClientVersion()) > 0) |
| 438 | { |
| 439 | return gl::GetGreenBits(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 440 | } |
| 441 | else |
| 442 | { |
| 443 | return 0; |
| 444 | } |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | GLuint FramebufferAttachment::getBlueSize() const |
| 448 | { |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 449 | if (gl::GetBlueBits(getInternalFormat(), mRenderer->getCurrentClientVersion()) > 0) |
| 450 | { |
| 451 | return gl::GetBlueBits(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | return 0; |
| 456 | } |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | GLuint FramebufferAttachment::getAlphaSize() const |
| 460 | { |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 461 | if (gl::GetAlphaBits(getInternalFormat(), mRenderer->getCurrentClientVersion()) > 0) |
| 462 | { |
| 463 | return gl::GetAlphaBits(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | return 0; |
| 468 | } |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | GLuint FramebufferAttachment::getDepthSize() const |
| 472 | { |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 473 | if (gl::GetDepthBits(getInternalFormat(), mRenderer->getCurrentClientVersion()) > 0) |
| 474 | { |
| 475 | return gl::GetDepthBits(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | return 0; |
| 480 | } |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | GLuint FramebufferAttachment::getStencilSize() const |
| 484 | { |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 485 | if (gl::GetStencilBits(getInternalFormat(), mRenderer->getCurrentClientVersion()) > 0) |
| 486 | { |
| 487 | return gl::GetStencilBits(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | return 0; |
| 492 | } |
Jamie Madill | afc21c0 | 2014-06-04 15:29:47 -0400 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | GLenum FramebufferAttachment::getComponentType() const |
| 496 | { |
| 497 | return gl::GetComponentType(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 498 | } |
| 499 | |
| 500 | GLenum FramebufferAttachment::getColorEncoding() const |
| 501 | { |
| 502 | return gl::GetColorEncoding(getActualFormat(), mRenderer->getCurrentClientVersion()); |
| 503 | } |
| 504 | |
| 505 | GLsizei FramebufferAttachment::getSamples() const |
| 506 | { |
| 507 | return mInstance->getSamples(); |
| 508 | } |
| 509 | |
| 510 | unsigned int FramebufferAttachment::getSerial() const |
| 511 | { |
| 512 | return mInstance->getSerial(); |
| 513 | } |
| 514 | |
| 515 | bool FramebufferAttachment::isTexture() const |
| 516 | { |
| 517 | return mInstance->isTexture(); |
| 518 | } |
| 519 | |
| 520 | unsigned int FramebufferAttachment::getTextureSerial() const |
| 521 | { |
| 522 | return mInstance->getTextureSerial(); |
| 523 | } |
| 524 | |
| 525 | void FramebufferAttachment::setStorage(RenderbufferStorage *newStorage) |
| 526 | { |
| 527 | ASSERT(newStorage != NULL); |
| 528 | |
| 529 | delete mInstance; |
| 530 | mInstance = newStorage; |
| 531 | } |
| 532 | |
| 533 | } |