private static void DrawDebugMessages()
        {
            //DepthStencilState.None.Apply();
            DepthStencilState.DepthRead.Apply();
            BlendState.NonPremultiplied.Apply();

            while (m_debugDrawMessages.Count > 0)
            {
                MyRenderMessageBase debugDrawMessage = m_debugDrawMessages.Dequeue();

                MyRenderMessageEnum messageType = debugDrawMessage.MessageType;

                switch (messageType)
                {
                case MyRenderMessageEnum.DebugDrawLine3D:
                {
                    MyRenderMessageDebugDrawLine3D message = (MyRenderMessageDebugDrawLine3D)debugDrawMessage;

                    MyDebugDraw.DrawLine3D(
                        message.PointFrom,
                        message.PointTo,
                        message.ColorFrom,
                        message.ColorTo,
                        message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawLine2D:
                {
                    MyRenderMessageDebugDrawLine2D message = (MyRenderMessageDebugDrawLine2D)debugDrawMessage;

                    MyDebugDraw.DrawLine2D(
                        message.PointFrom,
                        message.PointTo,
                        message.ColorFrom,
                        message.ColorTo,
                        message.Projection);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawSphere:
                {
                    MyRenderMessageDebugDrawSphere message = (MyRenderMessageDebugDrawSphere)debugDrawMessage;

                    MyDebugDraw.DrawSphere(
                        message.Position,
                        message.Radius,
                        message.Color,
                        message.Alpha,
                        message.DepthRead,
                        message.Smooth,
                        message.Cull);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawAABB:
                {
                    MyRenderMessageDebugDrawAABB message = (MyRenderMessageDebugDrawAABB)debugDrawMessage;

                    Color color = new Color(message.Color, message.Alpha);
                    var   aabb  = new BoundingBoxD(message.AABB.Min, message.AABB.Max);
                    MyDebugDraw.DrawAABBLine(
                        ref aabb,
                        ref color,
                        message.Scale,
                        message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawAxis:
                {
                    MyRenderMessageDebugDrawAxis message = (MyRenderMessageDebugDrawAxis)debugDrawMessage;

                    MyDebugDraw.DrawAxis(
                        (MatrixD)message.Matrix,
                        message.AxisLength,
                        1,
                        message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawOBB:
                {
                    MyRenderMessageDebugDrawOBB message = (MyRenderMessageDebugDrawOBB)debugDrawMessage;

                    if (message.Smooth)
                    {
                        MyDebugDraw.DrawLowresBoxSmooth(
                            message.Matrix,
                            message.Color,
                            message.Alpha,
                            message.DepthRead,
                            message.Cull);
                    }
                    else
                    {
                        MyDebugDraw.DrawOBBLine(
                            new MyOrientedBoundingBoxD(message.Matrix),
                            message.Color,
                            message.Alpha,
                            message.DepthRead);

                        //BoundingBoxD bd = new BoundingBoxD(message.Matrix.Translation - new Vector3(100),message.Matrix.Translation + new Vector3(100));

                        //Vector4 c = new Vector4(message.Color.X, message.Color.Y, message.Color.Z, message.Alpha);
                        //MyDebugDraw.DrawAABBLine(ref bd, ref c, 1, false);
                    }
                    break;
                }

                case MyRenderMessageEnum.DebugDrawCylinder:
                {
                    MyRenderMessageDebugDrawCylinder message = (MyRenderMessageDebugDrawCylinder)debugDrawMessage;

                    if (message.Smooth)
                    {
                        MyDebugDraw.DrawLowresCylinderSmooth(
                            (MatrixD)message.Matrix,
                            message.Color,
                            message.Alpha,
                            message.DepthRead);
                    }
                    else
                    {
                        MyDebugDraw.DrawLowresCylinderWireframe(
                            (MatrixD)message.Matrix,
                            message.Color,
                            message.Alpha,
                            message.DepthRead);
                    }
                    break;
                }

                case MyRenderMessageEnum.DebugDrawTriangle:
                {
                    MyRenderMessageDebugDrawTriangle message = (MyRenderMessageDebugDrawTriangle)debugDrawMessage;

                    MyDebugDraw.DrawTriangle((Vector3D)message.Vertex0, (Vector3D)message.Vertex1, (Vector3D)message.Vertex2, message.Color, message.Color, message.Color, message.Smooth, message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawTriangles:
                {
                    MyRenderMessageDebugDrawTriangles message = (MyRenderMessageDebugDrawTriangles)debugDrawMessage;

                    MyDebugDraw.DrawTriangles(message.WorldMatrix, message.Vertices, message.Indices, message.Color,
                                              message.DepthRead, message.Shaded);
                    break;
                }

                case MyRenderMessageEnum.DebugDrawCapsule:
                {
                    MyRenderMessageDebugDrawCapsule message = (MyRenderMessageDebugDrawCapsule)debugDrawMessage;

                    if (message.Shaded)
                    {
                        MyDebugDraw.DrawCapsuleShaded(message.P0, message.P1, message.Radius, message.Color, message.DepthRead);
                    }
                    else
                    {
                        MyDebugDraw.DrawCapsule(message.P0, message.P1, message.Radius, message.Color, message.DepthRead);
                    }

                    break;
                }

                case MyRenderMessageEnum.DebugDrawText2D:
                {
                    MyRenderMessageDebugDrawText2D message = (MyRenderMessageDebugDrawText2D)debugDrawMessage;

                    MyDebugDraw.DrawText(
                        message.Coord,
                        new StringBuilder(message.Text),
                        message.Color,
                        message.Scale,
                        false,
                        message.Align);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawText3D:
                {
                    MyRenderMessageDebugDrawText3D message = (MyRenderMessageDebugDrawText3D)debugDrawMessage;

                    MyDebugDraw.DrawText(
                        (Vector3D)message.Coord,
                        new StringBuilder(message.Text),
                        message.Color,
                        message.Scale,
                        message.DepthRead,
                        message.Align,
                        message.CustomViewProjection);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawModel:
                {
                    MyRenderMessageDebugDrawModel message = (MyRenderMessageDebugDrawModel)debugDrawMessage;

                    MyDebugDraw.DrawModel(MyRenderModels.GetModel(message.Model), message.WorldMatrix, message.Color,
                                          message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawPlane:
                {
                    MyRenderMessageDebugDrawPlane message = (MyRenderMessageDebugDrawPlane)debugDrawMessage;

                    MyDebugDraw.DrawPlane((Vector3D)message.Position, message.Normal, message.Color, message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugWaitForPresent:
                {
                    MyRenderMessageDebugWaitForPresent rMessage = (MyRenderMessageDebugWaitForPresent)debugDrawMessage;
                    MyRenderProxy.RenderThread.DebugAddWaitingForPresent(rMessage.WaitHandle);
                    break;
                }

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