Example #1
0
        internal static void TakeScreenshot(string name, BaseTexture target, MyEffectScreenshot.ScreenshotTechniqueEnum technique)
        {
            if (ScreenshotOnlyFinal && name != "FinalScreen")
                return;

            //  Screenshot object survives only one DRAW after created. We delete it immediatelly. So if 'm_screenshot'
            //  is not null we know we have to take screenshot and set it to null.
            if (MyGuiManager.GetScreenshot() != null)
            {
                if (target is Texture)
                {
                    Texture renderTarget = target as Texture;
                    Texture rt = new Texture(m_device, renderTarget.GetLevelDescription(0).Width, renderTarget.GetLevelDescription(0).Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                    MyMinerGame.SetRenderTarget(rt, null);
                    BlendState.NonPremultiplied.Apply();

                    MyEffectScreenshot ssEffect = GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;
                    ssEffect.SetSourceTexture(renderTarget);
                    ssEffect.SetTechnique(technique);
                    MyGuiManager.GetFullscreenQuad().Draw(ssEffect);

                    MyMinerGame.SetRenderTarget(null, null);
                    MyGuiManager.GetScreenshot().SaveTexture2D(rt, name);
                    rt.Dispose();
                }
                else if (target is CubeTexture)
                {
                    string filename = MyGuiManager.GetScreenshot().GetFilename(name + ".dds");
                    CubeTexture.ToFile(target, filename, ImageFileFormat.Dds);
                    //MyDDSFile.DDSToFile(filename, true, target, false);
                }
            }  
        }
Example #2
0
        /// <summary>
        /// Renders the source from parameter to the current device's render target.
        /// It just copies one RT into another (but by a rendering pass - so it's probably redundant).
        /// </summary>
        /// <param name="source"></param>
        public static void Blit(Texture source, bool scaleToTarget, MyEffectScreenshot.ScreenshotTechniqueEnum technique = MyEffectScreenshot.ScreenshotTechniqueEnum.Default)
        {
            var screenEffect = m_effects[(int)MyEffects.Screenshot] as MyEffectScreenshot;
            screenEffect.SetSourceTexture(source);

            //For case that source is bigger then camera viewport (back camera etc.)
            Vector2 scale = Vector2.One;

            if (scaleToTarget)
            {
                scale = GetScaleForViewport(source);
            }


            screenEffect.SetScale(scale);
            screenEffect.SetTechnique(technique);


            BlendState bs = BlendState.Current;
            if (technique == MyEffectScreenshot.ScreenshotTechniqueEnum.DepthToAlpha)
            {
                MyStateObjects.AlphaChannels_BlendState.Apply();
            }

            MyGuiManager.GetFullscreenQuad().Draw(screenEffect);

            if (technique == MyEffectScreenshot.ScreenshotTechniqueEnum.DepthToAlpha)
            {
                bs.Apply();
            }
        }