private static void DrawScene() { AddDebugQueueMessage("Frame render start"); MyGpuProfiler.IC_BeginBlock("UpdateSceneFrame"); UpdateSceneFrame(); MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Clear"); MyGBuffer.Main.Clear(VRageMath.Color.Black); MyGpuProfiler.IC_EndBlock(); if (MyOpenVR.Static != null) { ProfilerShort.Begin("OpenVR.WaitForNextStart"); MyOpenVR.WaitForNextStart(); ProfilerShort.End(); } IBorrowedRtvTexture debugAmbientOcclusion; // TODO: Think of another way to get this texture to the DebugRenderer... ProfilerShort.Begin("DrawGameScene"); DrawGameScene(Backbuffer, out debugAmbientOcclusion); ProfilerShort.End(); if (MyOpenVR.Static != null) { ProfilerShort.Begin("OpenVR.DisplayEye"); MyGpuProfiler.IC_BeginBlock("OpenVR.DisplayEye"); MyGBuffer.Main.Clear(VRageMath.Color.Black);//image is in HMD now, lets draw the rest for overlay MyOpenVR.Static.DisplayEye(MyRender11.Backbuffer.Resource.NativePointer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); } ProfilerShort.Begin("Draw scene debug"); MyGpuProfiler.IC_BeginBlock("Draw scene debug"); DrawSceneDebug(); ProfilerShort.End(); ProfilerShort.Begin("ProcessDebugMessages"); ProcessDebugMessages(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyDebugRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyDebugRenderer.Draw"); MyDebugRenderer.Draw(MyRender11.Backbuffer, debugAmbientOcclusion); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); debugAmbientOcclusion.Release(); ProfilerShort.Begin("MyPrimitivesRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyPrimitivesRenderer.Draw"); MyPrimitivesRenderer.Draw(MyRender11.Backbuffer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyLinesRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyLinesRenderer.Draw"); MyLinesRenderer.Draw(MyRender11.Backbuffer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); if (m_screenshot.HasValue && m_screenshot.Value.IgnoreSprites) { ProfilerShort.Begin("Screenshot"); if (m_screenshot.Value.SizeMult == Vector2.One) { SaveScreenshotFromResource(Backbuffer); } else { TakeCustomSizedScreenshot(m_screenshot.Value.SizeMult); } ProfilerShort.End(); } ProfilerShort.Begin("ProcessDebugOutput"); AddDebugQueueMessage("Frame render end"); ProcessDebugOutput(); ProfilerShort.End(); }
private static void DrawScene() { AddDebugQueueMessage("Frame render start"); MyGpuProfiler.IC_BeginBlock("UpdateSceneFrame"); UpdateSceneFrame(); MyGpuProfiler.IC_EndBlock(); var testingDepth = MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth : MyGBuffer.Main.DepthStencil; MyGpuProfiler.IC_BeginBlock("Clear"); MyGBuffer.Main.Clear(VRageMath.Color.Black); MyGpuProfiler.IC_EndBlock(); if (MyOpenVR.Static != null) { ProfilerShort.Begin("OpenVR.WaitForNextStart"); MyOpenVR.WaitForNextStart(); ProfilerShort.End(); } ProfilerShort.Begin("DrawGameScene"); DrawGameScene(Backbuffer); ProfilerShort.End(); if (MyOpenVR.Static != null) { ProfilerShort.Begin("OpenVR.DisplayEye"); MyGpuProfiler.IC_BeginBlock("OpenVR.DisplayEye"); MyGBuffer.Main.Clear(VRageMath.Color.Black);//image is in HMD now, lets draw the rest for overlay MyOpenVR.Static.DisplayEye(MyRender11.Backbuffer.Resource.NativePointer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); } ProfilerShort.Begin("Draw scene debug"); MyGpuProfiler.IC_BeginBlock("Draw scene debug"); DrawSceneDebug(); ProfilerShort.End(); ProfilerShort.Begin("ProcessDebugMessages"); ProcessDebugMessages(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyDebugRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyDebugRenderer.Draw"); MyDebugRenderer.Draw(MyRender11.Backbuffer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyPrimitivesRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyPrimitivesRenderer.Draw"); MyPrimitivesRenderer.Draw(MyRender11.Backbuffer, testingDepth); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyLinesRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyLinesRenderer.Draw"); MyLinesRenderer.Draw(MyRender11.Backbuffer, testingDepth); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); if (m_screenshot.HasValue && m_screenshot.Value.IgnoreSprites) { ProfilerShort.Begin("Screenshot"); if (m_screenshot.Value.SizeMult == Vector2.One) { SaveScreenshotFromResource(Backbuffer.Resource); } else { TakeCustomSizedScreenshot(m_screenshot.Value.SizeMult); } ProfilerShort.End(); } ProfilerShort.Begin("ProcessDebugOutput"); AddDebugQueueMessage("Frame render end"); ProcessDebugOutput(); ProfilerShort.End(); }
private static void ProcessDrawMessage(MyRenderMessageBase drawMessage) { switch (drawMessage.MessageType) { case MyRenderMessageEnum.SpriteScissorPush: { var msg = drawMessage as MyRenderMessageSpriteScissorPush; MySpritesRenderer.ScissorStackPush(msg.ScreenRectangle); break; } case MyRenderMessageEnum.SpriteScissorPop: { MySpritesRenderer.ScissorStackPop(); break; } case MyRenderMessageEnum.DrawSprite: { MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage; MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, sprite.Origin, sprite.RightVector, sprite.SourceRectangle, sprite.DestinationRectangle); break; } case MyRenderMessageEnum.DrawSpriteNormalized: { MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage; var rotation = sprite.Rotation; if (sprite.RotationSpeed != 0) { rotation += sprite.RotationSpeed * (float)(MyRender11.CurrentDrawTime - MyRender11.CurrentUpdateTime).Seconds; } Vector2 rightVector = rotation != 0f ? new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) : sprite.RightVector; int safeGuiSizeY = MyRender11.ResolutionI.Y; int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f); // This will mantain same aspect ratio for GUI elements var safeGuiRectangle = new VRageMath.Rectangle(MyRender11.ResolutionI.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY); var safeScreenScale = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT; float fixedScale = sprite.Scale * safeScreenScale; var tex = MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true); var normalizedCoord = sprite.NormalizedCoord; var screenCoord = new Vector2(safeGuiRectangle.Left + safeGuiRectangle.Width * normalizedCoord.X, safeGuiRectangle.Top + safeGuiRectangle.Height * normalizedCoord.Y); var sizeInPixels = MyTextures.GetSize(tex); var sizeInPixelsScaled = sizeInPixels * fixedScale; Vector2 alignedScreenCoord = screenCoord; var drawAlign = sprite.DrawAlign; if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP) { // Nothing to do as position is already at this point } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER) { // Move position to the texture center alignedScreenCoord -= sizeInPixelsScaled / 2.0f; } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP) { alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f; } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM) { alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f; alignedScreenCoord.Y -= sizeInPixelsScaled.Y; } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM) { alignedScreenCoord -= sizeInPixelsScaled; } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER) { alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f; } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER) { alignedScreenCoord.X -= sizeInPixelsScaled.X; alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f; } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM) { alignedScreenCoord.Y -= sizeInPixelsScaled.Y; // *0.75f; } else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP) { alignedScreenCoord.X -= sizeInPixelsScaled.X; } screenCoord = alignedScreenCoord; var rect = new RectangleF(screenCoord.X, screenCoord.Y, fixedScale * sizeInPixels.X, fixedScale * sizeInPixels.Y); Vector2 origin; if (sprite.OriginNormalized.HasValue) { origin = sprite.OriginNormalized.Value * sizeInPixels; } else { origin = sizeInPixels / 2; } sprite.OriginNormalized = sprite.OriginNormalized ?? new Vector2(0.5f); MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, origin, rightVector, null, rect); break; } case MyRenderMessageEnum.DrawSpriteAtlas: { MyRenderMessageDrawSpriteAtlas sprite = (MyRenderMessageDrawSpriteAtlas)drawMessage; var tex = MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true); var textureSize = MyTextures.GetSize(tex); Rectangle?sourceRect = new Rectangle( (int)(textureSize.X * sprite.TextureOffset.X), (int)(textureSize.Y * sprite.TextureOffset.Y), (int)(textureSize.X * sprite.TextureSize.X), (int)(textureSize.Y * sprite.TextureSize.Y)); VRageMath.RectangleF destRect = new VRageMath.RectangleF( (sprite.Position.X) * sprite.Scale.X, (sprite.Position.Y) * sprite.Scale.Y, sprite.HalfSize.X * sprite.Scale.X * 2, sprite.HalfSize.Y * sprite.Scale.Y * 2); Vector2 origin = new Vector2(textureSize.X * sprite.TextureSize.X * 0.5f, textureSize.Y * sprite.TextureSize.Y * 0.5f); MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true), sprite.Color, origin, sprite.RightVector, sourceRect, destRect); break; } case MyRenderMessageEnum.DrawString: { var message = drawMessage as MyRenderMessageDrawString; var font = MyRender11.GetFont(message.FontIndex); font.DrawString( message.ScreenCoord, message.ColorMask, message.Text, message.ScreenScale, message.ScreenMaxWidth); break; } case MyRenderMessageEnum.DrawScene: { AddDebugQueueMessage("Frame render start"); MyGpuProfiler.IC_BeginBlock("UpdateSceneFrame"); UpdateSceneFrame(); MyGpuProfiler.IC_EndBlock(); var testingDepth = MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth : MyGBuffer.Main.DepthStencil; MyGpuProfiler.IC_BeginBlock("Clear"); MyGBuffer.Main.Clear(VRageMath.Color.Black); MyGpuProfiler.IC_EndBlock(); if (MyOpenVR.Static != null) { ProfilerShort.Begin("OpenVR.WaitForNextStart"); MyOpenVR.WaitForNextStart(); ProfilerShort.End(); } ProfilerShort.Begin("DrawGameScene"); DrawGameScene(Backbuffer); ProfilerShort.End(); if (MyOpenVR.Static != null) { ProfilerShort.Begin("OpenVR.DisplayEye"); MyGpuProfiler.IC_BeginBlock("OpenVR.DisplayEye"); MyGBuffer.Main.Clear(VRageMath.Color.Black); //image is in HMD now, lets draw the rest for overlay MyOpenVR.Static.DisplayEye(MyRender11.Backbuffer.m_resource.NativePointer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); } ProfilerShort.Begin("TransferPerformanceStats"); TransferPerformanceStats(); ProfilerShort.End(); ProfilerShort.Begin("Draw scene debug"); MyGpuProfiler.IC_BeginBlock("Draw scene debug"); DrawSceneDebug(); ProfilerShort.End(); ProfilerShort.Begin("ProcessDebugMessages"); ProcessDebugMessages(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyDebugRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyDebugRenderer.Draw"); MyDebugRenderer.Draw(MyRender11.Backbuffer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyPrimitivesRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyPrimitivesRenderer.Draw"); MyPrimitivesRenderer.Draw(MyRender11.Backbuffer, testingDepth); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); ProfilerShort.Begin("MyLinesRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MyLinesRenderer.Draw"); MyLinesRenderer.Draw(MyRender11.Backbuffer, testingDepth); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); if (m_screenshot.HasValue && m_screenshot.Value.IgnoreSprites) { ProfilerShort.Begin("Screenshot"); if (m_screenshot.Value.SizeMult == Vector2.One) { SaveScreenshotFromResource(Backbuffer.m_resource); } else { TakeCustomSizedScreenshot(m_screenshot.Value.SizeMult); } ProfilerShort.End(); } ProfilerShort.Begin("MySpritesRenderer.Draw"); MyGpuProfiler.IC_BeginBlock("MySpritesRenderer.Draw"); MySpritesRenderer.Draw(MyRender11.Backbuffer.m_RTV, new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y)); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); if (MyRenderProxy.DRAW_RENDER_STATS) { ProfilerShort.Begin("MyRenderStatsDraw.Draw"); MyGpuProfiler.IC_BeginBlock("MyLinesRenderer.Draw"); MyRenderStatsDraw.Draw(MyRenderStats.m_stats, 0.6f, VRageMath.Color.Yellow); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); } ProfilerShort.Begin("ProcessDebugOutput"); AddDebugQueueMessage("Frame render end"); ProcessDebugOutput(); ProfilerShort.End(); break; } } }