コード例 #1
0
ファイル: ChunkModel.cs プロジェクト: hariton27sy/Landscaper
        public ChunkModel(BaseChunk chunk, ITextureStorage storage)
        {
            this.chunk   = chunk;
            this.storage = storage;

            UpdateModel();
        }
コード例 #2
0
        private static int RegisterImage(ITextureStorage storage, Image <Rgba32> img)
        {
            var id = storage.CreateTexture(img.Width, img.Height, TextureFormat.Rgba32);
            ReadOnlySpan <Rgba32> pixelSpan = img.GetPixelSpan();

            storage.SetData(id, pixelSpan);
            return(id);
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: hariton27sy/Landscaper
 public Game(IWorld world, IPlayer player, ITextureStorage textures, IRenderer renderer)
 {
     World         = world;
     Player        = player;
     this.textures = textures;
     this.renderer = renderer;
     Load         += OnLoad;
     VSync         = VSyncMode.On;
 }
コード例 #4
0
        /// <summary>
        /// Load a system font and register  it in the texture storage.
        /// </summary>
        /// <param name="name">Name of the system font.</param>
        /// <param name="size">Size to render the font at.</param>
        /// <param name="ranges">The character ranges to render to the font atlas.</param>
        /// <param name="fallbackCharacter">Optional fallback character for the font. Defaults to <c>0</c> (no fallback).</param>
        public static TextureFont LoadSystemFont(this ITextureStorage storage, string name, float size, IEnumerable <Range <int> > ranges, int fallbackCharacter = 0)
        {
            FontAtlasHelpers.CreateSystemFont(name, size, ranges, out var glyphMap, out var image);
            var width  = image.Width;
            var height = image.Height;
            var texId  = RegisterImage(storage, image);

            image.Dispose();
            return(new TextureFont(glyphMap.ToUvGlyphMap(width, height), texId, fallbackCharacter));
        }
コード例 #5
0
        /// <summary>
        /// Load a font and register it in the texture storage.
        /// </summary>
        /// <param name="storage">The texture storage to register the font atlas.</param>
        /// <param name="path">Path to the font file.</param>
        /// <param name="size">Size to render the font at.</param>
        /// <param name="fallbackCharacter">Optional fallback character for the font. Defaults to <c>0</c> (no fallback).</param>
        public static TextureFont LoadFont(this ITextureStorage storage, string path, float size, int fallbackCharacter = 0)
        {
            FontAtlasHelpers.CreateFont(path, size, out var glyphMap, out var image);
            var width  = image.Width;
            var height = image.Height;
            var texId  = RegisterImage(storage, image);

            image.Dispose();
            return(new TextureFont(glyphMap.ToUvGlyphMap(width, height), texId, fallbackCharacter));
        }
コード例 #6
0
        public virtual IModel GetModel(ITextureStorage storage, ICamera camera)
        {
            if (Model == null)
            {
                if (!isPendingModel)
                {
                    isPendingModel = true;
                    Task.Run(() => GenerateModel(storage));
                }
            }

            return(Model);
        }
コード例 #7
0
 public void Render(ICamera camera, ITextureStorage storage, IEnumerable <IEntity> entities)
 {
     using (shader.Start())
     {
         foreach (var entity in entities)
         {
             var model = entity.GetModel(storage, camera);
             if (model == null)
             {
                 continue;
             }
             using (model.Start())
             {
                 shader.SetIsTextured(model.IsTextured);
                 shader.SetTransformationMatrix(entity.TransformMatrix);
                 shader.SetViewMatrix(camera.ViewMatrix);
                 GL.DrawElements(model.DrawingMode, model.VerticesCount,
                                 DrawElementsType.UnsignedInt, 0);
             }
         }
     }
 }
コード例 #8
0
 /// <summary>
 /// Load an image from a path and register it in the texture storage.
 /// </summary>
 /// <param name="storage">The texture storage to register the texture in.</param>
 /// <param name="path">Path to the image.</param>
 public static int LoadTexture(this ITextureStorage storage, string path)
 {
     using (var img = Image.Load <Rgba32>(path))
         return(RegisterImage(storage, img));
 }
コード例 #9
0
 /// <summary>
 /// Load an image from a stream and register it in the texture storage.
 /// </summary>
 /// <param name="storage">The texture storage to register the texture in.</param>
 /// <param name="imageStream">Stream of the image data.</param>
 public static int LoadTexture(this ITextureStorage storage, Stream imageStream)
 {
     using (var img = Image.Load <Rgba32>(imageStream))
         return(RegisterImage(storage, img));
 }
コード例 #10
0
 public IModel GetModel(ITextureStorage storage, ICamera camera)
 {
     return(model);
 }
コード例 #11
0
 IModel IEntity.GetModel(ITextureStorage storage, ICamera camera)
 {
     return(GetModel(storage, camera));
 }
コード例 #12
0
 private void GenerateModel(ITextureStorage textureStorage)
 {
     Model          = new ChunkModel(this, textureStorage);
     isPendingModel = false;
 }