private static void LoadContent()
        {
            MyRender.Log.WriteLine("MyRender.LoadContent() - START");

            MyRender.GetRenderProfiler().StartProfilingBlock("MyRender::LoadContent");

            m_screenshot = null;

            DumpSettingsToLog();

            UpdateScreenSize();

            CreateRenderTargets();
            CreateEnvironmentMapsRT(MyRenderConstants.ENVIRONMENT_MAP_SIZE);

            DefaultSurface           = GraphicsDevice.GetRenderTarget(0);
            DefaultSurface.DebugName = "DefaultSurface";
            DefaultDepth             = GraphicsDevice.DepthStencilSurface;
            DefaultDepth.DebugName   = "DefaultDepth";

            m_randomTexture = CreateRandomTexture();

            LoadEffects();

            if (m_shadowRenderer == null)
            {
                m_shadowRenderer = new MyShadowRenderer(GetShadowCascadeSize(), MyRenderTargets.ShadowMap, MyRenderTargets.ShadowMapZBuffer, true);
            }

            if (m_spotShadowRenderer == null)
            {
                m_spotShadowRenderer = new MySpotShadowRenderer();
            }


            foreach (var renderComponent in m_renderComponents)
            {
                renderComponent.Value.LoadContent(GraphicsDevice);
            }

            m_spriteBatch    = new Graphics.SpriteBatch(GraphicsDevice, "SpriteBatch");
            m_fullscreenQuad = new MyFullScreenQuad();

            BlankTexture = MyTextureManager.GetTexture <MyTexture2D>("Textures\\GUI\\Blank.dds", flags: TextureFlags.IgnoreQuality);

            MyEnvironmentMap.Reset();

            foreach (var ro in m_renderObjects)
            {
                ro.Value.LoadContent();
            }

            LoadContent_Video();

            MyRender.GetRenderProfiler().EndProfilingBlock();

            MyRender.Log.WriteLine("MyRender.LoadContent() - END");
        }
        /// <summary>
        /// Sets the environment render targets.
        /// </summary>
        private static void SetEnvironmentRenderTargets()
        {
            var rt1 = MyRender.GetRenderTargetCube(MyRenderTargets.EnvironmentCube);
            var rt2 = MyRender.GetRenderTargetCube(MyRenderTargets.EnvironmentCubeAux);
            var rt3 = MyRender.GetRenderTargetCube(MyRenderTargets.AmbientCube);
            var rt4 = MyRender.GetRenderTargetCube(MyRenderTargets.AmbientCubeAux);
            var rt5 = MyRender.GetRenderTarget(MyRenderTargets.EnvironmentMap);

            MyEnvironmentMap.SetRenderTargets((CubeTexture)rt1, (CubeTexture)rt2, (CubeTexture)rt3, (CubeTexture)rt4, (Texture)rt5);
        }
Exemple #3
0
 public void ResetEnvironmentProbes()
 {
     MyEnvironmentMap.Reset();
 }
Exemple #4
0
        internal static void DrawMessageQueue()
        {
            if (m_spriteBatch == null)
            {
                return;
            }

            DrawSpriteStencilEnum currentStencil = DrawSpriteStencilEnum.None;


            BeginSpriteBatch();

            /*
             * if (m_drawMessages.Count == 0)
             * {
             *  GraphicsDevice.Clear(ClearFlags.All, new SharpDX.ColorBGRA(1.0f, 1, 0, 1), 1, 0);
             *  DrawText(new Vector2(0, 300), new StringBuilder("No draw input"), Color.White, 1);
             * } */


            while (m_drawMessages.Count > 0)
            {
                IMyRenderMessage drawMessage = m_drawMessages.Dequeue();

                MyRenderMessageEnum messageType = drawMessage.MessageType;
                switch (messageType)
                {
                case MyRenderMessageEnum.SpriteScissorPush:
                {
                    var msg = drawMessage as MyRenderMessageSpriteScissorPush;
                    m_spriteBatch.ScissorStack.Push(msg.ScreenRectangle);
                    break;
                }

                case MyRenderMessageEnum.SpriteScissorPop:
                {
                    m_spriteBatch.ScissorStack.Pop();
                    break;
                }

                case MyRenderMessageEnum.DrawSprite:
                {
                    MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage;

                    ProcessSpriteMessage(sprite);
                    break;
                }

                case MyRenderMessageEnum.DrawSpriteNormalized:
                {
                    MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage;

                    ProcessNormalizedSpriteMessage(sprite);

                    break;
                }

                case MyRenderMessageEnum.DrawSpriteAtlas:
                {
                    MyRenderMessageDrawSpriteAtlas sprite = (MyRenderMessageDrawSpriteAtlas)drawMessage;

                    ProcessAtlasSprite(sprite);

                    break;
                }

                case MyRenderMessageEnum.DrawString:
                {
                    var message = drawMessage as MyRenderMessageDrawString;

                    var font = MyRender.GetFont(message.FontIndex);
                    font.DrawString(
                        message.ScreenCoord * m_sizeMultiplierForStrings,
                        message.ColorMask,
                        message.Text,
                        message.ScreenScale * m_sizeMultiplierForStrings.X,
                        message.ScreenMaxWidth * m_sizeMultiplierForStrings.X);

                    break;
                }

                case MyRenderMessageEnum.DrawScene:
                {
                    EndSpriteBatch();

                    MyRenderCamera.UpdateCamera();
                    MyRender.SetDeviceViewport(MyRenderCamera.Viewport);

                    Draw3D();

                    DrawDebugMessages();

                    BeginSpriteBatch();

                    break;
                }

                case MyRenderMessageEnum.DrawVideo:
                {
                    var rMessage = (MyRenderMessageDrawVideo)drawMessage;
                    MyRender.DrawVideo(rMessage.ID, rMessage.Rectangle, rMessage.Color, rMessage.FitMode);

                    break;
                }

                case MyRenderMessageEnum.UpdateEnvironmentMap:
                {
                    MyRender.GetRenderProfiler().StartProfilingBlock("MyEnvironmentMap.Update");
                    MyEnvironmentMap.Update();
                    MyRender.GetRenderProfiler().EndProfilingBlock();

                    break;
                }

                case MyRenderMessageEnum.DrawSecondaryCamera:
                {
                    var rMessage = (MyRenderMessageDrawSecondaryCamera)drawMessage;

                    MySecondaryCameraRenderer.Instance.ViewMatrix = (MatrixD)rMessage.ViewMatrix;
                    MySecondaryCameraRenderer.Instance.Render();

                    break;
                }

                case MyRenderMessageEnum.DrawSecondaryCameraSprite:
                {
                    MyRenderMessageDrawSecondaryCameraSprite sprite = (MyRenderMessageDrawSecondaryCameraSprite)drawMessage;

                    Vector2 rightVector = sprite.Rotation != 0f ? new Vector2((float)Math.Cos(sprite.Rotation), (float)Math.Sin(sprite.Rotation)) : sprite.RightVector;
                    //rightVector = new Vector2(1, 1);

                    DrawSpriteMain(
                        MySecondaryCameraRenderer.Instance.GetRenderedTexture(),
                        null,
                        ref sprite.DestinationRectangle,
                        sprite.ScaleDestination,
                        sprite.SourceRectangle,
                        sprite.Color,
                        rightVector,
                        ref sprite.Origin,
                        sprite.Effects,
                        sprite.Depth
                        );

                    break;
                }

                case MyRenderMessageEnum.UpdateBillboardsColorize:
                {
                    var rMessage = (MyRenderMessageUpdateBillboardsColorize)drawMessage;

                    MyTransparentGeometry.EnableColorize        = rMessage.Enable;
                    MyTransparentGeometry.ColorizeColor         = rMessage.Color;
                    MyTransparentGeometry.ColorizePlaneDistance = rMessage.Distance;
                    MyTransparentGeometry.ColorizePlaneNormal   = rMessage.Normal;

                    break;
                }

                default:
                {
                    System.Diagnostics.Debug.Assert(false, "Unknown draw message");
                    break;
                }
                }
            }

            GetRenderProfiler().StartProfilingBlock("SpriteBatchRestart");
            EndSpriteBatch();
            BeginSpriteBatch();
            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().StartProfilingBlock("DrawDebugMessages");
            DrawDebugMessages();
            GetRenderProfiler().EndProfilingBlock();

            if (MyRenderProxy.DRAW_RENDER_STATS)
            {
                MyRenderStatsDraw.Draw(MyRenderStats.m_stats, 0.6f, Color.Yellow);
            }

            if (MyRender.Settings.TearingTest)
            {
                DrawTearingTest();
            }

            if (MyRender.Settings.MultimonTest)
            {
                // Middle screen
                var from = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, 0);
                var to   = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height);
                VRageRender.MyRenderProxy.DebugDrawLine2D(from, to, Color.Orange, Color.Orange);

                from = new Vector2(GraphicsDevice.Viewport.Width / 3.0f, 0);
                to   = new Vector2(GraphicsDevice.Viewport.Width / 3.0f, GraphicsDevice.Viewport.Height);
                VRageRender.MyRenderProxy.DebugDrawLine2D(from, to, Color.Yellow, Color.Yellow);
                from = new Vector2(GraphicsDevice.Viewport.Width / 3.0f * 2.0f, 0);
                to   = new Vector2(GraphicsDevice.Viewport.Width / 3.0f * 2.0f, GraphicsDevice.Viewport.Height);
                VRageRender.MyRenderProxy.DebugDrawLine2D(from, to, Color.Yellow, Color.Yellow);
            }

            GetRenderProfiler().StartProfilingBlock("SpriteBatchEnd");
            EndSpriteBatch();
            GetRenderProfiler().EndProfilingBlock();


            System.Diagnostics.Debug.Assert(m_spriteBatchUsageCount == 0);
        }