Exemple #1
0
        /// <summary>
        /// Draws the sprite and the subsprites.
        /// </summary>
        /// <param name="worldMatrixIn">Defines the position and orientation of the sprite</param>
        /// <param name="flagsIn">Copied to LastFlags for use by any callback of Draw (PreDraw, PreSubspriteDraw, PreLocalDraw,
        /// and SetMeshEffect) that wants it</param>
        public void Draw(Matrix?worldMatrixIn = null, ulong flagsIn = 0xFFFFFFFFFFFFFFFF)
        {
            if (BlDebug.ShowThreadWarnings && CreationThread != Thread.CurrentThread.ManagedThreadId)
            {
                BlDebug.Message(String.Format("BlGraphicsDeviceManager.Draw() was called by thread {0} instead of thread {1}", Thread.CurrentThread.ManagedThreadId, CreationThread));
            }

            if (worldMatrixIn == null)
            {
                worldMatrixIn = Matrix.Identity;
            }

            // save incoming parameters for anyone that needs them (like callbacks)
            LastWorldMatrix = worldMatrixIn;
            FlagsParameter  = flagsIn;

#if !DEBUG
            try
            {
#endif
            DrawInternal();
#if !DEBUG
        }
        catch (Exception e)
        {
            Console.WriteLine("Recovered from exception in EsSprite.Draw method:\n\n{0}", e);
        }
#endif
        }
Exemple #2
0
        /// <summary>
        /// When finished with the object, you should call Dispose() from the same thread that created the object.
        /// You can call this multiple times, but once is enough. If it isn't called before the object
        /// becomes inaccessible, then the destructor will call it and, if BlDebug.EnableDisposeErrors is
        /// true (it is true by default for Debug builds), then it will get an exception saying that it
        /// wasn't called by the same thread that created it. This is because the platform's underlying
        /// 3D library (OpenGL, etc.) often requires 3D resources to be managed only by one thread.
        /// </summary>
        public void Dispose()
        {
            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("BlMipmap dispose");
            }
            if (IsDisposed)
            {
                return;
            }

            if (CreationThread != Thread.CurrentThread.ManagedThreadId && BlDebug.ShowThreadWarnings)
            {
                BlDebug.Message(String.Format("BlMipmap.Dispose() was called by thread {0} instead of thread {1}", Thread.CurrentThread.ManagedThreadId, CreationThread));
            }

            GC.SuppressFinalize(this);

            foreach (var tex in this)
            {
                tex.Dispose();
            }

            //base.Dispose();
            IsDisposed = true;

            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("end BlMipmap dispose");
            }
        }
Exemple #3
0
        /// <summary>
        /// When finished with the object, you must call Dispose() from the same thread that created the object.
        /// You can call this multiple times, but once is enough.
        /// </summary>
        public new void Dispose()
        {
            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("BlGraphicsDeviceManager dispose");
            }

            if (IsDisposed)
            {
                return;
            }

            if (CreationThread != Thread.CurrentThread.ManagedThreadId)
            {
                BlDebug.Message(String.Format("BlGraphicsDeviceManager.Dispose() was called by thread {0} instead of thread {1}", Thread.CurrentThread.ManagedThreadId, CreationThread));
            }

            GC.SuppressFinalize(this);

            if (SpriteBatch != null)
            {
                SpriteBatch.Dispose();
            }

            base.Dispose();
            IsDisposed = true;

            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("end BlGraphicsDeviceManager dispose");
            }
        }
Exemple #4
0
        /// <summary>
        /// When finished with the object, you should call Dispose() from the same thread that created the object.
        /// You can call this multiple times, but once is enough. If it isn't called before the object
        /// becomes inaccessible, then the destructor will call it and, if BlDebug.EnableDisposeErrors is
        /// true (it is true by default for Debug builds), then it will get an exception saying that it
        /// wasn't called by the same thread that created it. This is because the platform's underlying
        /// 3D library (OpenGL, etc.) often requires 3D resources to be managed only by one thread.
        /// </summary>
        public void Dispose()
        {
            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("BlSprite {0} dispose", Name);
            }
            if (IsDisposed)
            {
                return;
            }

            if (CreationThread != Thread.CurrentThread.ManagedThreadId && BlDebug.ShowThreadWarnings)
            {
                BlDebug.Message(String.Format("BlSprite {0} Dispose() was called by thread {1} instead of thread {2}", Name, Thread.CurrentThread.ManagedThreadId, CreationThread));
            }

            GC.SuppressFinalize(this);

            // Note: We do NOT dispose the models and mipmaps because we did not create them

            if (FrameProc != null)
            {
                Graphics.Window.FrameProcSpritesRemove(this);
            }

            // Dispose the VerticesEffect if we were the one who created it.
            if (VerticesEffect != null)
            {
                VerticesEffect.Dispose();
            }

            //base.Dispose();
            IsDisposed = true;

            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("end BlSprite {0} dispose", Name);
            }
        }
Exemple #5
0
        /// <summary>
        /// Returns the current 2D view coordinates of the sprite (for passing to DrawText, for example),
        /// or null if it's behind the camera.
        /// </summary>
        /// <returns>The view coords of the sprite</returns>
        public Vector2?GetViewCoords()
        {
            if (BlDebug.ShowThreadWarnings && CreationThread != Thread.CurrentThread.ManagedThreadId)
            {
                BlDebug.Message(String.Format("BlGraphicsDeviceManager.GetViewCoords() was called by thread {0} instead of thread {1}", Thread.CurrentThread.ManagedThreadId, CreationThread));
            }

            Vector4 position            = new Vector4(AbsoluteMatrix.Translation, 1);
            Matrix  worldViewProjection = (Matrix)LastWorldMatrix * Graphics.View * Graphics.Projection;
            Vector4 result = Vector4.Transform(position, worldViewProjection);

            result /= result.W;

            if (result.Z >= 1)
            {
                return(null);
            }

            Viewport vp           = Graphics.GraphicsDevice.Viewport;
            Matrix   invClient    = Matrix.Invert(Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, -1, 1));
            Vector2  clientResult = Vector2.Transform(new Vector2(result.X, result.Y), invClient);

            return(clientResult);
        }