Showing the changes to libraries/render-utils/src/TextureCache.cpp (1 of 13 files). Show all
Unified · Split
| @@ -32,13 +32,6 @@ TextureCache::TextureCache() : · 31 unmodified lines | ||
| 32 | 32 | _permutationNormalTexture(0), |
| 33 | 33 | _whiteTexture(0), |
| 34 | 34 | _blueTexture(0), |
| 35 | − _primaryDepthTextureID(0), | |
| 36 | − _primaryNormalTextureID(0), | |
| 37 | − _primarySpecularTextureID(0), | |
| 38 | − _primaryFramebufferObject(NULL), | |
| 39 | − _secondaryFramebufferObject(NULL), | |
| 40 | − _tertiaryFramebufferObject(NULL), | |
| 41 | − _shadowFramebufferObject(NULL), | |
| 42 | 35 | _frameBufferSize(100, 100), |
| 43 | 36 | _associatedWidget(NULL) |
| 44 | 37 | { |
| @@ -47,24 +40,6 @@ TextureCache::TextureCache() : · 2 unmodified lines | ||
| 47 | 40 | } |
| 48 | 41 | |
| 49 | 42 | TextureCache::~TextureCache() { |
| 50 | − | |
| 51 | − if (_primaryFramebufferObject) { | |
| 52 | − glDeleteTextures(1, &_primaryDepthTextureID); | |
| 53 | − glDeleteTextures(1, &_primaryNormalTextureID); | |
| 54 | − glDeleteTextures(1, &_primarySpecularTextureID); | |
| 55 | − } | |
| 56 | − | |
| 57 | − if (_primaryFramebufferObject) { | |
| 58 | − delete _primaryFramebufferObject; | |
| 59 | − } | |
| 60 | − | |
| 61 | − if (_secondaryFramebufferObject) { | |
| 62 | − delete _secondaryFramebufferObject; | |
| 63 | − } | |
| 64 | − | |
| 65 | − if (_tertiaryFramebufferObject) { | |
| 66 | − delete _tertiaryFramebufferObject; | |
| 67 | − } | |
| 68 | 43 | } |
| 69 | 44 | |
| 70 | 45 | void TextureCache::setFrameBufferSize(QSize frameBufferSize) { |
| @@ -72,35 +47,15 @@ void TextureCache::setFrameBufferSize(QSize frameBufferSize) { · 1 unmodified line | ||
| 72 | 47 | if (_frameBufferSize != frameBufferSize) { |
| 73 | 48 | _frameBufferSize = frameBufferSize; |
| 74 | 49 | |
| 75 | − if (_primaryOpaqueFramebuffer) { | |
| 76 | − _primaryOpaqueFramebuffer.reset(); | |
| 77 | − _primaryTransparentFramebuffer.reset(); | |
| 78 | − _primaryDepthTexture.reset(); | |
| 79 | − _primaryColorTexture.reset(); | |
| 80 | − _primaryNormalTexture.reset(); | |
| 81 | − _primarySpecularTexture.reset(); | |
| 82 | − } | |
| 83 | − | |
| 84 | − if (_primaryFramebufferObject) { | |
| 85 | − delete _primaryFramebufferObject; | |
| 86 | − _primaryFramebufferObject = NULL; | |
| 87 | − glDeleteTextures(1, &_primaryDepthTextureID); | |
| 88 | − _primaryDepthTextureID = 0; | |
| 89 | − glDeleteTextures(1, &_primaryNormalTextureID); | |
| 90 | − _primaryNormalTextureID = 0; | |
| 91 | − glDeleteTextures(1, &_primarySpecularTextureID); | |
| 92 | − _primarySpecularTextureID = 0; | |
| 93 | − } | |
| 50 | + _primaryFramebuffer.reset(); | |
| 51 | + _primaryDepthTexture.reset(); | |
| 52 | + _primaryColorTexture.reset(); | |
| 53 | + _primaryNormalTexture.reset(); | |
| 54 | + _primarySpecularTexture.reset(); | |
| 94 | 55 | |
| 95 | − if (_secondaryFramebufferObject) { | |
| 96 | − delete _secondaryFramebufferObject; | |
| 97 | − _secondaryFramebufferObject = NULL; | |
| 98 | − } | |
| 56 | + _secondaryFramebuffer.reset(); | |
| 99 | 57 | |
| 100 | − if (_tertiaryFramebufferObject) { | |
| 101 | − delete _tertiaryFramebufferObject; | |
| 102 | − _tertiaryFramebufferObject = NULL; | |
| 103 | − } | |
| 58 | + _tertiaryFramebuffer.reset(); | |
| 104 | 59 | } |
| 105 | 60 | } |
| 106 | 61 | |
| @@ -215,46 +170,8 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, TextureType type · 108 unmodified lines | ||
| 215 | 170 | return texture; |
| 216 | 171 | } |
| 217 | 172 | |
| 218 | −QOpenGLFramebufferObject* TextureCache::getPrimaryFramebufferObject() { | |
| 219 | − | |
| 220 | − if (!_primaryFramebufferObject) { | |
| 221 | − _primaryFramebufferObject = createFramebufferObject(); | |
| 222 | − | |
| 223 | − glGenTextures(1, &_primaryDepthTextureID); | |
| 224 | − glBindTexture(GL_TEXTURE_2D, _primaryDepthTextureID); | |
| 225 | − glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, _frameBufferSize.width(), _frameBufferSize.height(), | |
| 226 | − 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); | |
| 227 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 228 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 229 | − | |
| 230 | − glGenTextures(1, &_primaryNormalTextureID); | |
| 231 | − glBindTexture(GL_TEXTURE_2D, _primaryNormalTextureID); | |
| 232 | − glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _frameBufferSize.width(), _frameBufferSize.height(), | |
| 233 | − 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| 234 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 235 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 236 | − glBindTexture(GL_TEXTURE_2D, 0); | |
| 237 | − | |
| 238 | − glGenTextures(1, &_primarySpecularTextureID); | |
| 239 | − glBindTexture(GL_TEXTURE_2D, _primarySpecularTextureID); | |
| 240 | − glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _frameBufferSize.width(), _frameBufferSize.height(), | |
| 241 | − 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| 242 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 243 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 244 | − glBindTexture(GL_TEXTURE_2D, 0); | |
| 245 | − | |
| 246 | − _primaryFramebufferObject->bind(); | |
| 247 | − glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _primaryDepthTextureID, 0); | |
| 248 | − glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, _primaryNormalTextureID, 0); | |
| 249 | − glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, _primarySpecularTextureID, 0); | |
| 250 | − _primaryFramebufferObject->release(); | |
| 251 | − } | |
| 252 | − return _primaryFramebufferObject; | |
| 253 | −} | |
| 254 | − | |
| 255 | 173 | void TextureCache::createPrimaryFramebuffer() { |
| 256 | − _primaryOpaqueFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); | |
| 257 | − _primaryTransparentFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); | |
| 174 | + _primaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); | |
| 258 | 175 | |
| 259 | 176 | auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); |
| 260 | 177 | auto width = _frameBufferSize.width(); |
| @@ -265,32 +182,22 @@ void TextureCache::createPrimaryFramebuffer() { · 4 unmodified lines | ||
| 265 | 182 | _primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); |
| 266 | 183 | _primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); |
| 267 | 184 | |
| 268 | − _primaryOpaqueFramebuffer->setRenderBuffer(0, _primaryColorTexture); | |
| 269 | − _primaryOpaqueFramebuffer->setRenderBuffer(1, _primaryNormalTexture); | |
| 270 | − _primaryOpaqueFramebuffer->setRenderBuffer(2, _primarySpecularTexture); | |
| 185 | + _primaryFramebuffer->setRenderBuffer(0, _primaryColorTexture); | |
| 186 | + _primaryFramebuffer->setRenderBuffer(1, _primaryNormalTexture); | |
| 187 | + _primaryFramebuffer->setRenderBuffer(2, _primarySpecularTexture); | |
| 271 | 188 | |
| 272 | − _primaryTransparentFramebuffer->setRenderBuffer(0, _primaryColorTexture); | |
| 273 | 189 | |
| 274 | 190 | auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); |
| 275 | 191 | _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); |
| 276 | 192 | |
| 277 | − _primaryOpaqueFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); | |
| 278 | − | |
| 279 | − _primaryTransparentFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); | |
| 193 | + _primaryFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); | |
| 280 | 194 | } |
| 281 | 195 | |
| 282 | −gpu::FramebufferPointer TextureCache::getPrimaryOpaqueFramebuffer() { | |
| 283 | − if (!_primaryOpaqueFramebuffer) { | |
| 196 | +gpu::FramebufferPointer TextureCache::getPrimaryFramebuffer() { | |
| 197 | + if (!_primaryFramebuffer) { | |
| 284 | 198 | createPrimaryFramebuffer(); |
| 285 | 199 | } |
| 286 | − return _primaryOpaqueFramebuffer; | |
| 287 | −} | |
| 288 | − | |
| 289 | −gpu::FramebufferPointer TextureCache::getPrimaryTransparentFramebuffer() { | |
| 290 | − if (!_primaryTransparentFramebuffer) { | |
| 291 | − createPrimaryFramebuffer(); | |
| 292 | − } | |
| 293 | − return _primaryTransparentFramebuffer; | |
| 200 | + return _primaryFramebuffer; | |
| 294 | 201 | } |
| 295 | 202 | |
| 296 | 203 | gpu::TexturePointer TextureCache::getPrimaryDepthTexture() { |
| @@ -322,28 +229,19 @@ gpu::TexturePointer TextureCache::getPrimarySpecularTexture() { · 25 unmodified lines | ||
| 322 | 229 | } |
| 323 | 230 | |
| 324 | 231 | GLuint TextureCache::getPrimaryDepthTextureID() { |
| 325 | − // ensure that the primary framebuffer object is initialized before returning the depth texture id | |
| 326 | − //getPrimaryFramebufferObject(); | |
| 327 | − | |
| 328 | − _primaryDepthTextureID = gpu::GLBackend::getTextureID(_primaryDepthTexture); | |
| 329 | − return _primaryDepthTextureID; | |
| 232 | + return gpu::GLBackend::getTextureID(getPrimaryDepthTexture()); | |
| 330 | 233 | } |
| 331 | 234 | |
| 332 | 235 | GLuint TextureCache::getPrimaryColorTextureID() { |
| 333 | − return gpu::GLBackend::getTextureID(_primaryColorTexture); | |
| 236 | + return gpu::GLBackend::getTextureID(getPrimaryColorTexture()); | |
| 334 | 237 | } |
| 335 | 238 | |
| 336 | 239 | GLuint TextureCache::getPrimaryNormalTextureID() { |
| 337 | − // ensure that the primary framebuffer object is initialized before returning the normal texture id | |
| 338 | − //getPrimaryFramebufferObject(); | |
| 339 | − _primaryNormalTextureID = gpu::GLBackend::getTextureID(_primaryNormalTexture); | |
| 340 | − return _primaryNormalTextureID; | |
| 240 | + return gpu::GLBackend::getTextureID(getPrimaryNormalTexture()); | |
| 341 | 241 | } |
| 342 | 242 | |
| 343 | 243 | GLuint TextureCache::getPrimarySpecularTextureID() { |
| 344 | − //getPrimaryFramebufferObject(); | |
| 345 | − _primarySpecularTextureID = gpu::GLBackend::getTextureID(_primarySpecularTexture); | |
| 346 | − return _primarySpecularTextureID; | |
| 244 | + return gpu::GLBackend::getTextureID(getPrimarySpecularTexture()); | |
| 347 | 245 | } |
| 348 | 246 | |
| 349 | 247 | void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) { |
| @@ -361,18 +259,18 @@ void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) · 11 unmodified lines | ||
| 361 | 259 | glDrawBuffers(bufferCount, buffers); |
| 362 | 260 | } |
| 363 | 261 | |
| 364 | −QOpenGLFramebufferObject* TextureCache::getSecondaryFramebufferObject() { | |
| 365 | − if (!_secondaryFramebufferObject) { | |
| 366 | − _secondaryFramebufferObject = createFramebufferObject(); | |
| 262 | +gpu::FramebufferPointer TextureCache::getSecondaryFramebuffer() { | |
| 263 | + if (!_secondaryFramebuffer) { | |
| 264 | + _secondaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height())); | |
| 367 | 265 | } |
| 368 | − return _secondaryFramebufferObject; | |
| 266 | + return _secondaryFramebuffer; | |
| 369 | 267 | } |
| 370 | 268 | |
| 371 | −QOpenGLFramebufferObject* TextureCache::getTertiaryFramebufferObject() { | |
| 372 | − if (!_tertiaryFramebufferObject) { | |
| 373 | − _tertiaryFramebufferObject = createFramebufferObject(); | |
| 269 | +gpu::FramebufferPointer TextureCache::getTertiaryFramebuffer() { | |
| 270 | + if (!_tertiaryFramebuffer) { | |
| 271 | + _tertiaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height())); | |
| 374 | 272 | } |
| 375 | − return _tertiaryFramebufferObject; | |
| 273 | + return _tertiaryFramebuffer; | |
| 376 | 274 | } |
| 377 | 275 | |
| 378 | 276 | |
| @@ -386,58 +284,25 @@ gpu::FramebufferPointer TextureCache::getShadowFramebuffer() { · 7 unmodified lines | ||
| 386 | 284 | return _shadowFramebuffer; |
| 387 | 285 | } |
| 388 | 286 | |
| 389 | −QOpenGLFramebufferObject* TextureCache::getShadowFramebufferObject() { | |
| 390 | − if (!_shadowFramebufferObject) { | |
| 391 | − const int SHADOW_MAP_SIZE = 2048; | |
| 392 | − _shadowFramebufferObject = new QOpenGLFramebufferObject(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, | |
| 393 | − QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGB); | |
| 394 | − | |
| 395 | − glGenTextures(1, &_shadowDepthTextureID); | |
| 396 | − glBindTexture(GL_TEXTURE_2D, _shadowDepthTextureID); | |
| 397 | − glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, | |
| 398 | − 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); | |
| 399 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
| 400 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 401 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | |
| 402 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | |
| 403 | − const float DISTANT_BORDER[] = { 1.0f, 1.0f, 1.0f, 1.0f }; | |
| 404 | − glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, DISTANT_BORDER); | |
| 405 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); | |
| 406 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); | |
| 407 | − glBindTexture(GL_TEXTURE_2D, 0); | |
| 408 | − | |
| 409 | − _shadowFramebufferObject->bind(); | |
| 410 | − glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _shadowDepthTextureID, 0); | |
| 411 | − _shadowFramebufferObject->release(); | |
| 412 | − } | |
| 413 | − return _shadowFramebufferObject; | |
| 414 | −} | |
| 415 | − | |
| 416 | 287 | GLuint TextureCache::getShadowDepthTextureID() { |
| 417 | 288 | // ensure that the shadow framebuffer object is initialized before returning the depth texture id |
| 418 | − //getShadowFramebufferObject(); | |
| 419 | − _shadowDepthTextureID = gpu::GLBackend::getTextureID(_shadowTexture); | |
| 420 | − | |
| 421 | − return _shadowDepthTextureID; | |
| 289 | + getShadowFramebuffer(); | |
| 290 | + return gpu::GLBackend::getTextureID(_shadowTexture); | |
| 422 | 291 | } |
| 423 | 292 | |
| 424 | 293 | bool TextureCache::eventFilter(QObject* watched, QEvent* event) { |
| 425 | 294 | if (event->type() == QEvent::Resize) { |
| 426 | 295 | QSize size = static_cast<QResizeEvent*>(event)->size(); |
| 427 | − if (_primaryFramebufferObject && _primaryFramebufferObject->size() != size) { | |
| 428 | − delete _primaryFramebufferObject; | |
| 429 | − _primaryFramebufferObject = NULL; | |
| 430 | − glDeleteTextures(1, &_primaryDepthTextureID); | |
| 431 | − glDeleteTextures(1, &_primaryNormalTextureID); | |
| 432 | − glDeleteTextures(1, &_primarySpecularTextureID); | |
| 433 | − } | |
| 434 | − if (_secondaryFramebufferObject && _secondaryFramebufferObject->size() != size) { | |
| 435 | − delete _secondaryFramebufferObject; | |
| 436 | − _secondaryFramebufferObject = NULL; | |
| 437 | − } | |
| 438 | − if (_tertiaryFramebufferObject && _tertiaryFramebufferObject->size() != size) { | |
| 439 | − delete _tertiaryFramebufferObject; | |
| 440 | − _tertiaryFramebufferObject = NULL; | |
| 296 | + if (_frameBufferSize != size) { | |
| 297 | + _primaryFramebuffer.reset(); | |
| 298 | + _primaryColorTexture.reset(); | |
| 299 | + _primaryDepthTexture.reset(); | |
| 300 | + _primaryNormalTexture.reset(); | |
| 301 | + _primarySpecularTexture.reset(); | |
| 302 | + | |
| 303 | + _secondaryFramebuffer.reset(); | |
| 304 | + | |
| 305 | + _tertiaryFramebuffer.reset(); | |
| 441 | 306 | } |
| 442 | 307 | } |
| 443 | 308 | return false; |
| @@ -458,17 +323,6 @@ void TextureCache::associateWithWidget(QGLWidget* widget) { · 14 unmodified lines | ||
| 458 | 323 | _associatedWidget->installEventFilter(this); |
| 459 | 324 | } |
| 460 | 325 | |
| 461 | −QOpenGLFramebufferObject* TextureCache::createFramebufferObject() { | |
| 462 | − QOpenGLFramebufferObject* fbo = new QOpenGLFramebufferObject(_frameBufferSize); | |
| 463 | − | |
| 464 | − glBindTexture(GL_TEXTURE_2D, fbo->texture()); | |
| 465 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
| 466 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 467 | − glBindTexture(GL_TEXTURE_2D, 0); | |
| 468 | − | |
| 469 | − return fbo; | |
| 470 | −} | |
| 471 | − | |
| 472 | 326 | Texture::Texture() { |
| 473 | 327 | } |
| 474 | 328 | |