/ContentSystem/Rendering/ImageData.cs
C# | 220 lines | 119 code | 16 blank | 85 comment | 0 complexity | 8a900bd3400c6b8264075fd6641093d8 MD5 | raw file
Possible License(s): Apache-2.0
- using System.Collections.Generic;
- using Delta.Utilities.Datatypes;
- using Delta.Utilities.Graphics;
- using Delta.Utilities.Helpers;
-
- namespace Delta.ContentSystem.Rendering
- {
- /// <summary>
- /// Helper class for accessing image content, which is needed in the Texture
- /// class (but it can also be used in other places when loading images).
- /// </summary>
- public class ImageData : Content
- {
- #region Get (Static)
- /// <summary>
- /// Get and load content based on the content name. This method makes sure
- /// we do not load the same content twice (the constructor is protected).
- /// </summary>
- /// <param name="contentName">Content name we want to load, this is
- /// passed onto the Content System, which will do the actual loading with
- /// help of the Load method in this class.</param>
- /// <returns>The loaded Content object, always unique for the same
- /// name, this helps comparing data.</returns>
- public static ImageData Get(string contentName)
- {
- return Get<ImageData>(contentName, ContentType.Image);
- }
- #endregion
-
- #region GetAllContentNames (Static)
- /// <summary>
- /// Get list of all image content names available in the current project.
- /// </summary>
- /// <returns>List of all image content names</returns>
- public static string[] GetAllContentNames()
- {
- Dictionary<string, ContentMetaData> meshContents =
- ContentManager.GetAllContentMetaData(ContentType.Image);
- return ArrayHelper.ToArray(meshContents.Keys);
- }
- #endregion
-
- #region PixelSize (Public)
- /// <summary>
- /// The size of the image in pixels (NOT in quadratic space and also NOT
- /// necessarily the size of the real bitmap from disk, which might be
- /// an atlas texture that is much bigger than this image size).
- /// </summary>
- public Size PixelSize
- {
- get
- {
- return data.PixelSize;
- }
- }
- #endregion
-
- #region BlendMode (Public)
- /// <summary>
- /// Blend mode used for this image, set in constructor and can't be
- /// changed. This is important for the MaterialManager sorting logic!
- /// </summary>
- public BlendMode BlendMode
- {
- get
- {
- return data.BlendMode;
- }
- }
- #endregion
-
- #region UseLinearFiltering (Public)
- /// <summary>
- /// Helper property to determinate if we need to enable filtering for
- /// rendering this image (usually in a shader). True is the default and
- /// means we are going to use Trilinear filtering, false means no
- /// filtering, which is often called Nearest or Point filtering.
- /// Note: For fonts and the default image (4x4 pixels) this is
- /// automatically set to false for more accurate and sharp rendering.
- /// </summary>
- public bool UseLinearFiltering
- {
- get
- {
- return data.UseFiltering;
- }
- }
- #endregion
-
- #region AllowTiling (Public)
- /// <summary>
- /// Allow tiling for this texture? By default this is off and using this
- /// prevents us from using atlas textures and many optimizations, so it
- /// should be avoided as much as possible.
- /// </summary>
- public bool AllowTiling
- {
- get
- {
- return data.AllowTiling;
- }
- }
- #endregion
-
- #region UV (Public)
- /// <summary>
- /// The texture coordinates of this image. Normally (0, 0, 1, 1)
- /// But necessary when using atlas textures (what we are mostly doing).
- /// </summary>
- public Rectangle UV
- {
- get
- {
- return data.UV;
- }
- }
- #endregion
-
- #region InnerDrawArea (Public)
- /// <summary>
- /// Helper for the inner rectangle for rendering, which will reduce any
- /// draw rectangle by this to make it fit in case there were empty pixels
- /// around this image.
- /// </summary>
- public Rectangle InnerDrawArea
- {
- get
- {
- return data.InnerDrawArea;
- }
- }
- #endregion
-
- #region AtlasFileId (Public)
- /// <summary>
- /// Atlas file id, needed to compare for atlas textures. Each content file
- /// with the same PlatformFileId will use the same native texture object
- /// (sharing it with all the other content entries using the same atlas).
- /// By comparing this we can quickly group all rendering by atlas textures
- /// to make best use of draw call batching and speeding up the rendering.
- /// </summary>
- public int AtlasFileId
- {
- get
- {
- return data.PlatformFileId;
- }
- }
- #endregion
-
- #region IsCubeMap (Public)
- /// <summary>
- /// Is this image data for a cube map texture? Usually off.
- /// </summary>
- public bool IsCubeMap
- {
- get
- {
- return data.IsCubeMap;
- }
- }
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create a base texture, just makes sure we use the image content type.
- /// Use the static Get method to call this.
- /// </summary>
- /// <param name="setImageName">Set image name</param>
- protected ImageData(string setImageName)
- : base(setImageName, ContentType.Image)
- {
- // Nothing to be done here, same for Load, we do not actually load
- // any data here, the magic happens in classes that use us.
- }
- #endregion
-
- #region ToString (Public)
- /// <summary>
- /// To string, will display the image name and some extra data.
- /// </summary>
- /// <returns>
- /// A <see cref="System.String"/> that represents this ImageData instance
- /// with the content name, pixel size, blend mode and uv meta data.
- /// </returns>
- public override string ToString()
- {
- return GetType().GetClassName() +
- " Name=" + Name +
- ", PixelSize=" + data.PixelSize +
- ", BlendMode=" + data.BlendMode +
- ", UV=" + data.UV;
- }
- #endregion
-
- #region Methods (Private)
-
- #region Load
- /// <summary>
- /// Load texture content data. This method does not load the content yet,
- /// it only provides the common functionality for all derived classes that
- /// actually contain the image data. No loading happens here (it all
- /// happens in Texture), we can obviously clone all ImageDatas with the
- /// same name as they are not loaded here.
- /// </summary>
- /// <param name="alreadyLoadedNativeData">If we already have native data
- /// loaded, clone it from this instance. Only used if not null. Please
- /// note that this is only used for other objects that had the same
- /// RawFileId and are already loaded and returned true for this method.
- /// </param>
- protected override void Load(Content alreadyLoadedNativeData)
- {
- // Nothing to do here, it all happens in the Texture class
- }
- #endregion
-
- #endregion
- }
- }
-