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 { 425 return gl::GetRedBits(getActualFormat(), mRenderer->getCurrentClientVersion()); 426 } 427 428 GLuint FramebufferAttachment::getGreenSize() const 429 { 430 return gl::GetGreenBits(getActualFormat(), mRenderer->getCurrentClientVersion()); 431 } 432 433 GLuint FramebufferAttachment::getBlueSize() const 434 { 435 return gl::GetBlueBits(getActualFormat(), mRenderer->getCurrentClientVersion()); 436 } 437 438 GLuint FramebufferAttachment::getAlphaSize() const 439 { 440 return gl::GetAlphaBits(getActualFormat(), mRenderer->getCurrentClientVersion()); 441 } 442 443 GLuint FramebufferAttachment::getDepthSize() const 444 { 445 return gl::GetDepthBits(getActualFormat(), mRenderer->getCurrentClientVersion()); 446 } 447 448 GLuint FramebufferAttachment::getStencilSize() const 449 { 450 return gl::GetStencilBits(getActualFormat(), mRenderer->getCurrentClientVersion()); 451 } 452 453 GLenum FramebufferAttachment::getComponentType() const 454 { 455 return gl::GetComponentType(getActualFormat(), mRenderer->getCurrentClientVersion()); 456 } 457 458 GLenum FramebufferAttachment::getColorEncoding() const 459 { 460 return gl::GetColorEncoding(getActualFormat(), mRenderer->getCurrentClientVersion()); 461 } 462 463 GLsizei FramebufferAttachment::getSamples() const 464 { 465 return mInstance->getSamples(); 466 } 467 468 unsigned int FramebufferAttachment::getSerial() const 469 { 470 return mInstance->getSerial(); 471 } 472 473 bool FramebufferAttachment::isTexture() const 474 { 475 return mInstance->isTexture(); 476 } 477 478 unsigned int FramebufferAttachment::getTextureSerial() const 479 { 480 return mInstance->getTextureSerial(); 481 } 482 483 void FramebufferAttachment::setStorage(RenderbufferStorage *newStorage) 484 { 485 ASSERT(newStorage != NULL); 486 487 delete mInstance; 488 mInstance = newStorage; 489 } 490 491 } 492