| 213 | } |
| 214 | |
| 215 | bool RenderBuffers::Init(int32 width, int32 height) |
| 216 | { |
| 217 | // Skip if resolution won't change |
| 218 | if ((width == _width && height == _height) || _useNull) |
| 219 | return false; |
| 220 | CHECK_RETURN(width > 0 && height > 0, true); |
| 221 | |
| 222 | bool result = false; |
| 223 | |
| 224 | // Depth Buffer |
| 225 | auto desc = GPUTextureDescription::New2D(width, height, GPU_DEPTH_BUFFER_PIXEL_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::DepthStencil); |
| 226 | if (!EnumHasAllFlags(GPUDevice::Instance->GetFormatFeatures(desc.Format).Support, FormatSupport::DepthStencil | FormatSupport::Texture2D)) |
| 227 | desc.Format = desc.Format == PixelFormat::D24_UNorm_S8_UInt ? PixelFormat::D32_Float_S8X24_UInt : PixelFormat::D32_Float; |
| 228 | if (GPUDevice::Instance->Limits.HasReadOnlyDepth) |
| 229 | desc.Flags |= GPUTextureFlags::ReadOnlyDepthView; |
| 230 | |
| 231 | result |= DepthBuffer->Init(desc); |
| 232 | |
| 233 | // MotionBlurPass initializes MotionVectors texture if needed (lazy init - not every game needs it) |
| 234 | MotionVectors->ReleaseGPU(); |
| 235 | |
| 236 | // GBuffer 0 |
| 237 | desc.Flags = GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget; |
| 238 | desc.Format = GBUFFER0_FORMAT; |
| 239 | desc.DefaultClearColor = Color::Transparent; |
| 240 | result |= GBuffer0->Init(desc); |
| 241 | |
| 242 | // GBuffer 1 |
| 243 | desc.Format = GBUFFER1_FORMAT; |
| 244 | desc.DefaultClearColor = Color::Transparent; |
| 245 | result |= GBuffer1->Init(desc); |
| 246 | |
| 247 | // GBuffer 2 |
| 248 | desc.Format = GBUFFER2_FORMAT; |
| 249 | desc.DefaultClearColor = Color(1, 0, 0, 0); |
| 250 | result |= GBuffer2->Init(desc); |
| 251 | |
| 252 | // GBuffer 3 |
| 253 | desc.Format = GBUFFER3_FORMAT; |
| 254 | desc.DefaultClearColor = Color::Transparent; |
| 255 | result |= GBuffer3->Init(desc); |
| 256 | |
| 257 | // Cache data |
| 258 | _width = width; |
| 259 | _height = height; |
| 260 | _aspectRatio = static_cast<float>(width) / height; |
| 261 | _viewport = Viewport(0, 0, static_cast<float>(width), static_cast<float>(height)); |
| 262 | LastEyeAdaptationTime = 0; |
| 263 | |
| 264 | // Flush any pool render targets to prevent over-allocating GPU memory when resizing game viewport |
| 265 | RenderTargetPool::Flush(false, 4); |
| 266 | |
| 267 | return result; |
| 268 | } |
| 269 | |
| 270 | void RenderBuffers::Release() |
| 271 | { |
nothing calls this directly
no test coverage detected