Showing the changes to libraries/render-utils/src/FramebufferCache.cpp (1 of 5 files). Show all
Unified · Split
| @@ -35,30 +35,34 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { · 34 unmodified lines | ||
| 35 | 35 | if (_frameBufferSize != frameBufferSize) { |
| 36 | 36 | _frameBufferSize = frameBufferSize; |
| 37 | 37 | _primaryFramebuffer.reset(); |
| 38 | + _primaryDepthTexture.reset(); | |
| 39 | + _primaryColorTexture.reset(); | |
| 40 | + _primaryNormalTexture.reset(); | |
| 41 | + _primarySpecularTexture.reset(); | |
| 38 | 42 | } |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | 45 | void FramebufferCache::createPrimaryFramebuffer() { |
| 42 | 46 | _primaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); |
| 43 | 47 | |
| 44 | − static auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); | |
| 45 | − static auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); | |
| 46 | − | |
| 48 | + auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); | |
| 47 | 49 | auto width = _frameBufferSize.width(); |
| 48 | 50 | auto height = _frameBufferSize.height(); |
| 49 | 51 | |
| 50 | 52 | auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); |
| 51 | − auto colorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); | |
| 52 | − auto normalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); | |
| 53 | − auto specularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); | |
| 53 | + _primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); | |
| 54 | + _primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); | |
| 55 | + _primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); | |
| 56 | + | |
| 57 | + _primaryFramebuffer->setRenderBuffer(0, _primaryColorTexture); | |
| 58 | + _primaryFramebuffer->setRenderBuffer(1, _primaryNormalTexture); | |
| 59 | + _primaryFramebuffer->setRenderBuffer(2, _primarySpecularTexture); | |
| 54 | 60 | |
| 55 | − _primaryFramebuffer->setRenderBuffer(0, colorTexture); | |
| 56 | − _primaryFramebuffer->setRenderBuffer(1, normalTexture); | |
| 57 | − _primaryFramebuffer->setRenderBuffer(2, specularTexture); | |
| 58 | 61 | |
| 62 | + auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); | |
| 63 | + _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); | |
| 59 | 64 | |
| 60 | − auto depthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); | |
| 61 | − _primaryFramebuffer->setDepthStencilBuffer(depthTexture, depthFormat); | |
| 65 | + _primaryFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); | |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { |
| @@ -68,6 +72,36 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { · 3 unmodified lines | ||
| 68 | 72 | return _primaryFramebuffer; |
| 69 | 73 | } |
| 70 | 74 | |
| 75 | + | |
| 76 | + | |
| 77 | +gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { | |
| 78 | + if (!_primaryDepthTexture) { | |
| 79 | + createPrimaryFramebuffer(); | |
| 80 | + } | |
| 81 | + return _primaryDepthTexture; | |
| 82 | +} | |
| 83 | + | |
| 84 | +gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { | |
| 85 | + if (!_primaryColorTexture) { | |
| 86 | + createPrimaryFramebuffer(); | |
| 87 | + } | |
| 88 | + return _primaryColorTexture; | |
| 89 | +} | |
| 90 | + | |
| 91 | +gpu::TexturePointer FramebufferCache::getPrimaryNormalTexture() { | |
| 92 | + if (!_primaryNormalTexture) { | |
| 93 | + createPrimaryFramebuffer(); | |
| 94 | + } | |
| 95 | + return _primaryNormalTexture; | |
| 96 | +} | |
| 97 | + | |
| 98 | +gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { | |
| 99 | + if (!_primarySpecularTexture) { | |
| 100 | + createPrimaryFramebuffer(); | |
| 101 | + } | |
| 102 | + return _primarySpecularTexture; | |
| 103 | +} | |
| 104 | + | |
| 71 | 105 | void FramebufferCache::setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal, bool specular) { |
| 72 | 106 | GLenum buffers[3]; |
| 73 | 107 | int bufferCount = 0; |
| @@ -98,11 +132,6 @@ void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebu · 24 unmodified lines | ||
| 98 | 132 | _cachedFramebuffers.push_back(framebuffer); |
| 99 | 133 | } |
| 100 | 134 | |
| 101 | −gpu::FramebufferPointer FramebufferCache::getSecondaryFramebuffer() { | |
| 102 | − static auto _secondaryFramebuffer = getFramebuffer(); | |
| 103 | − return _secondaryFramebuffer; | |
| 104 | −} | |
| 105 | − | |
| 106 | 135 | gpu::FramebufferPointer FramebufferCache::getShadowFramebuffer() { |
| 107 | 136 | if (!_shadowFramebuffer) { |
| 108 | 137 | const int SHADOW_MAP_SIZE = 2048; |