} // RenderTarget /// <summary> /// Creates a render target for render to textures. Use size type constructor for screen relative sizes. /// </summary> /// <param name="size">Render target size</param> /// <param name="_surfaceFormat">Surface format</param> /// <param name="_hasDepthBuffer">Has depth buffer?</param> /// <param name="antialiasingType">Multi sampling type: System value or no antialiasing.</param> public RenderTargetCube(int size, SurfaceFormat _surfaceFormat = SurfaceFormat.Color, bool _hasDepthBuffer = true, RenderTarget.AntialiasingType antialiasingType = RenderTarget.AntialiasingType.NoAntialiasing, bool mipMap = false) { Name = "Render Target"; Size = size; SurfaceFormat = _surfaceFormat; DepthFormat = _hasDepthBuffer ? DepthFormat.Depth24 : DepthFormat.None; Antialiasing = antialiasingType; MipMap = mipMap; Create(); } // RenderTarget
/// <summary> /// Creates a render target for render to textures. Use size type constructor for screen relative sizes. /// </summary> /// <param name="size">Render target size</param> /// <param name="_surfaceFormat">Surface format</param> /// <param name="_depthFormat">Depth Format</param> /// <param name="antialiasingType">Multi sampling type: System value or no antialiasing.</param> public RenderTargetCube(int size, SurfaceFormat _surfaceFormat, DepthFormat _depthFormat, RenderTarget.AntialiasingType antialiasingType = RenderTarget.AntialiasingType.NoAntialiasing, bool mipMap = false) { Name = "Render Target"; Size = size; SurfaceFormat = _surfaceFormat; DepthFormat = _depthFormat; Antialiasing = antialiasingType; MipMap = mipMap; Create(); } // RenderTarget
/// <summary> /// There is a pool of render targets to avoid wasting unnecessary graphic memory. /// The idea is that a render target has also a flag that tell us if the content is still need or not. /// So, when a shader needs a render target it search in the pool for an unused render target with the right characteristics (size, surface format, etc.) /// The problem if someone has to turn the flag false when the render target’s content is unnecessary and this could be somehow ugly. /// But the graphic pipeline performance is critical, it’s not an area for the user and its complexity was diminished thanks to the new code’s restructuring. /// The pool should be used in the filters, shadow maps and similar shaders. Not everything. /// Use the Release method to return a render target to the pool. /// </summary> public static RenderTargetCube Fetch(int size, SurfaceFormat surfaceFormat, DepthFormat depthFormat, RenderTarget.AntialiasingType antialiasingType, bool mipMap = false) { RenderTargetCube renderTarget; for (int i = 0; i < renderTargets.Count; i++) { renderTarget = renderTargets[i]; if (renderTarget.Size == size && renderTarget.SurfaceFormat == surfaceFormat && renderTarget.DepthFormat == depthFormat && renderTarget.Antialiasing == antialiasingType && renderTarget.MipMap == mipMap && !renderTarget.looked) { renderTarget.looked = true; return renderTarget; } } // If there is not one unlook or present we create one. AssetContentManager userContentManager = AssetContentManager.CurrentContentManager; AssetContentManager.CurrentContentManager = AssetContentManager.SystemContentManager; renderTarget = new RenderTargetCube(size, surfaceFormat, depthFormat, antialiasingType, mipMap); AssetContentManager.CurrentContentManager = userContentManager; renderTargets.Add(renderTarget); renderTarget.looked = true; return renderTarget; } // Fetch