Ejemplo n.º 1
0
        protected override void Attached(SystemRegistry registry)
        {
            _as             = registry.GetSystem <AssetSystem>();
            _meshData       = _as.Database.LoadAsset <MeshData>(_meshAsset.ID);
            _textureData    = _as.Database.LoadAsset <ImageSharpTexture>(_textureAsset.ID);
            _transform      = GameObject.Transform;
            _centeredBounds = _meshData.GetBoundingBox();
            _objectCenter   = _centeredBounds.GetCenter();

            // _gs.ExecuteOnMainThread(() =>
            // {
            //     InitializeContextObjects(_gs.Context, _gs.MaterialCache, _gs.BufferCache);
            // });


            // _gs = registry.GetSystem<GraphicsSystem>();
            // _ad = registry.GetSystem<AssetSystem>().Database;
            // _texstture = Texture.Get(_ad);
            // _mesh = Mesh.Get(_ad);
            // _centeredBoundingSphere = _mesh.GetBoundingSphere();
            // _centeredBoundingBox = _mesh.GetBoundingBox();
            // _gs.ExecuteOnMainThread(() =>
            // {
            //     InitializeContextObjects(_gs.Context, _gs.MaterialCache, _gs.BufferCache);
            // });
        }
Ejemplo n.º 2
0
 public TexturedMesh(RawModel model, ImageSharpTexture textureData, Shader vertexShader, Shader fragmentShader)
 {
     this.model          = model;
     this.textureData    = textureData;
     this.vertexShader   = vertexShader;
     this.fragmentShader = fragmentShader;
 }
Ejemplo n.º 3
0
        private Texture LoadImpl(FileSystemEntry entry, GraphicsDevice graphicsDevice)
        {
            switch (Path.GetExtension(entry.FilePath).ToLowerInvariant())
            {
            case ".dds":
                if (!DdsFile.IsDdsFile(entry))
                {
                    goto case ".tga";
                }
                var ddsFile = DdsFile.FromFileSystemEntry(entry);
                return(CreateTextureFromDds(ddsFile, graphicsDevice));

            case ".tga":
                var tgaFile = TgaFile.FromFileSystemEntry(entry);
                return(CreateTextureFromTga(tgaFile, graphicsDevice));

            case ".jpg":
                using (var stream = entry.Open())
                {
                    var jpgFile = new ImageSharpTexture(stream);
                    return(CreateFromImageSharpTexture(jpgFile, graphicsDevice));
                }

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 4
0
 public (bool TextureExists, IntPtr TextureHandle) GetFfxTextureIntPtr(int textureId)
 {
     if (!_loadedTexturesDictionary.ContainsKey(textureId))
     {
         var a = _ffxTexturesIEnumerable.Where(item => item.Name.Contains($"s{textureId.ToString("00000")}.tpf"));
         if (a.Any())
         {
             var tpfBytes        = a.First().Bytes;
             var tpfTexturesList = TPF.Read(tpfBytes).Textures;
             if (tpfTexturesList.Any())
             {
                 var            ddsBytes       = tpfTexturesList.First().Bytes;
                 DdsImage       ddsImage       = new DdsImage(ddsBytes);
                 Image <Rgba32> image          = Image.LoadPixelData <Rgba32>(ddsImage.Data, ddsImage.Width, ddsImage.Height);
                 var            img            = new ImageSharpTexture(image);
                 var            veldridTexture = img.CreateDeviceTexture(MainUserInterface.Gd, MainUserInterface.Gd.ResourceFactory);
                 var            textureHandle  = MainUserInterface.Controller.GetOrCreateImGuiBinding(MainUserInterface.Gd.ResourceFactory, veldridTexture);
                 veldridTexture.Dispose();
                 _loadedTexturesDictionary.Add(textureId, textureHandle);
                 return(true, textureHandle);
             }
         }
         return(false, IntPtr.Zero);
     }
     else
     {
         return(true, _loadedTexturesDictionary[textureId]);
     }
 }
Ejemplo n.º 5
0
        public void ChooseMesh()
        {
            // CPU Resources

            // Texture
            ImageSharpTexture inputImage = new ImageSharpTexture("JoshIconC.png", false);

            // Vertices
            mVertices = GetCubeVertices();

            // Indices
            mIndices = GetCubeIndices();

            // GPU Resources

            // Texture
            mSurfaceTexture     = inputImage.CreateDeviceTexture(mGraphicsDevice, mFactory);
            mSurfaceTextureView = mFactory.CreateTextureView(mSurfaceTexture);

            // VertexBuffer
            mVertexBuffer = mFactory.CreateBuffer(new BufferDescription((uint)(VertexPositionTexture.SizeInBytes * mVertices.Length), BufferUsage.VertexBuffer));
            mGraphicsDevice.UpdateBuffer(mVertexBuffer, 0, mVertices);

            // IndexBuffer
            mIndexBuffer = mFactory.CreateBuffer(new BufferDescription(sizeof(ushort) * (uint)mIndices.Length, BufferUsage.IndexBuffer));
            mGraphicsDevice.UpdateBuffer(mIndexBuffer, 0, mIndices);
        }
Ejemplo n.º 6
0
        static void Main()
        {
            var renderer = new Renderer();
            var game     = new Game(renderer);

            var vertShaderString = File.ReadAllText("Assets/Shaders/basic.vert");
            var fragShaderString = File.ReadAllText("Assets/Shaders/basic.frag");

            RawModel model;

            using (var reader = new StreamReader("Assets/Models/dragon.obj"))
            {
                model = new RawModel(ObjParser.LoadModel(reader));
            }

            var textureData = new ImageSharpTexture("Assets/Textures/white.png");
            var shaderSet   = new ShaderSet(vertShaderString, fragShaderString);

            renderer.Initialize(true);

            var mesh   = renderer.CreateMesh(model, textureData, shaderSet);
            var entity = new RenderableEntity(new Transform(new Vector3(0, -5, -10), new Vector3(), 1), mesh);

            entity.InitializeMesh(renderer);

            game.AddEntity(entity);
            game.AddEntity(new CameraController());

            game.RunMainLoop();
            renderer.DisposeGraphicsDevices();
        }
Ejemplo n.º 7
0
 /// <summary>Projects the on change project.</summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">if set to <c>true</c> [e].</param>
 private void Project_OnChangeProject(object sender, bool e)
 {
     image             = Image.LoadPixelData <Rgba32>(Project.Current.VideoGame.PreviewRender(), 512, 512);
     imageSharpTexture = new ImageSharpTexture(image, true);
     texture           = imageSharpTexture.CreateDeviceTexture(imGuiController.graphicsDevice, imGuiController.graphicsDevice.ResourceFactory);
     intPtr            = imGuiController.GetOrCreateImGuiBinding(imGuiController.graphicsDevice.ResourceFactory, texture);
 }
Ejemplo n.º 8
0
        public SpriteRenderable()
        {
            uint quadCap = 1024 * 16;

            batch  = new GeometryBatch <VertexPositionColorTexture>(6 * quadCap, 4 * quadCap);
            image0 = new ImageSharpTexture("Assets/Textures/DurrrSpaceShip.png", false);
        }
Ejemplo n.º 9
0
        public VxTexture(string imagePath)
        {
            ImageSharpTexture imageSharpTex = new ImageSharpTexture(imagePath);

            Tex  = imageSharpTex.CreateDeviceTexture(VxContext.Instance.Device, VxContext.Instance.Factory);
            View = VxContext.Instance.Factory.CreateTextureView(Tex);
        }
Ejemplo n.º 10
0
        protected System.IntPtr NewImage(string path)
        {
            var     ist = new ImageSharpTexture(path);
            Texture t   = ist.CreateDeviceTexture(_gd, _gd.ResourceFactory);

            //_newImguiTex.Add(path, t);
            return(_ren.GetOrCreateImGuiBinding(_gd.ResourceFactory, t));
        }
Ejemplo n.º 11
0
        private void InitTextures()
        {
            _tileSetAddresser = new TileSetAddresser();
            var imageSharpTexture = new ImageSharpTexture(_tileSetAddresser.TileSet);

            _skeletonTexture     = imageSharpTexture.CreateDeviceTexture(_graphicsDevice, _graphicsDevice.ResourceFactory);
            _skeletonTextureView = _graphicsDevice.ResourceFactory.CreateTextureView(_skeletonTexture);
        }
Ejemplo n.º 12
0
        public TrueColorTexture(string name, Image <Rgba32> image)
        {
            Name = name;
            ImageSharpTexture imageSharpTexture = new ImageSharpTexture(image, false);

            _texture = imageSharpTexture;
            IsDirty  = true;
        }
Ejemplo n.º 13
0
        public static GraphicsDevice CreateTextureFromFile(this GraphicsDevice device,
                                                           string filename, out Texture texture)
        {
            var img = new ImageSharpTexture(filename);

            texture = img.CreateDeviceTexture(device, device.ResourceFactory);
            return(device);
        }
Ejemplo n.º 14
0
        public Texture(ImageSharpTexture imageTexture, Veldrid.Texture deviceTexture, TextureView textureView, long hash)
        {
            _imageTexture  = imageTexture;
            _deviceTexture = deviceTexture;
            _textureView   = textureView;
            _hash          = hash;

            _size = new Vector2(_imageTexture.Width, _imageTexture.Height);
        }
Ejemplo n.º 15
0
        private void UpdateResources(GraphicsDevice device, RenderingContext context)
        {
            var factory       = device.ResourceFactory;
            var texture       = new ImageSharpTexture(_image.Data, false);
            var deviceTexture = texture.CreateDeviceTexture(device, factory);

            _textureView     = factory.CreateTextureView(new TextureViewDescription(deviceTexture));
            _worldTextureSet = context.Renderer.MakeTextureViewSet(_textureView);
        }
Ejemplo n.º 16
0
        private void AddSponzaAtriumObjects()
        {
            ObjParser parser = new ObjParser();

            using (FileStream objStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.obj")))
            {
                ObjFile atriumFile = parser.Parse(objStream);
                MtlFile atriumMtls;
                using (FileStream mtlStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.mtl")))
                {
                    atriumMtls = new MtlParser().Parse(mtlStream);
                }

                foreach (ObjFile.MeshGroup group in atriumFile.MeshGroups)
                {
                    Vector3                scale               = new Vector3(0.1f);
                    ConstructedMeshInfo    mesh                = atriumFile.GetMesh(group);
                    MaterialDefinition     materialDef         = atriumMtls.Definitions[mesh.MaterialName];
                    ImageSharpTexture      overrideTextureData = null;
                    ImageSharpTexture      alphaTexture        = null;
                    MaterialPropsAndBuffer materialProps       = CommonMaterials.Brick;
                    if (materialDef.DiffuseTexture != null)
                    {
                        string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.DiffuseTexture);
                        overrideTextureData = LoadTexture(texturePath, true);
                    }
                    if (materialDef.AlphaMap != null)
                    {
                        string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.AlphaMap);
                        alphaTexture = LoadTexture(texturePath, false);
                    }
                    if (materialDef.Name.Contains("vase"))
                    {
                        materialProps = CommonMaterials.Vase;
                    }
                    if (group.Name == "sponza_117")
                    {
                        MirrorMesh.Plane = Plane.CreateFromVertices(
                            atriumFile.Positions[group.Faces[0].Vertex0.PositionIndex] * scale.X,
                            atriumFile.Positions[group.Faces[0].Vertex1.PositionIndex] * scale.Y,
                            atriumFile.Positions[group.Faces[0].Vertex2.PositionIndex] * scale.Z);
                        materialProps = CommonMaterials.Reflective;
                    }

                    AddTexturedMesh(
                        mesh,
                        overrideTextureData,
                        alphaTexture,
                        materialProps,
                        Vector3.Zero,
                        Quaternion.Identity,
                        scale,
                        group.Name);
                }
            }
        }
Ejemplo n.º 17
0
        // TODO: Change how sampler is passed in
        public Texture2D(string path, Sampler sampler)
        {
            Sampler       = sampler;
            _textureData  = new ImageSharpTexture(path);
            DeviceTexture = _textureData.CreateDeviceTexture(Renderer.GraphicsDevice, Renderer.ResourceFactory);
            TextureView   = Renderer.ResourceFactory.CreateTextureView(DeviceTexture);

            Width  = (int)_textureData.Width;
            Height = (int)_textureData.Height;
        }
Ejemplo n.º 18
0
        public ImageView(Stream stream, GraphicsDevice gd, ImGuiRenderer renderer)
        {
            _graphicsDevice = gd;
            _imguiRenderer  = renderer;

            var imageSharpTex = new ImageSharpTexture(stream);

            _texture      = imageSharpTex.CreateDeviceTexture(_graphicsDevice, _graphicsDevice.ResourceFactory);
            _textureViews = new Dictionary <TextureViewDescription, TextureView>();
        }
Ejemplo n.º 19
0
        private ImageSharpTexture LoadTexture(string texturePath, bool mipmap) // Plz don't call this with the same texturePath and different mipmap values.
        {
            if (!_textures.TryGetValue(texturePath, out ImageSharpTexture tex))
            {
                tex = new ImageSharpTexture(texturePath, mipmap, true);
                _textures.Add(texturePath, tex);
            }

            return(tex);
        }
Ejemplo n.º 20
0
 public MeshRenderer(string name, MeshData meshData, ImageSharpTexture textureData, ImageSharpTexture alphaTexture, MaterialPropsAndBuffer materialProps)
 {
     _name             = name;
     _meshData         = meshData;
     _centeredBounds   = meshData.GetBoundingBox();
     _objectCenter     = _centeredBounds.GetCenter();
     _textureData      = textureData;
     _alphaTextureData = alphaTexture;
     _materialProps    = materialProps;
 }
Ejemplo n.º 21
0
        public Texture GenerateRgbaVeldridTextureFromPixelData(Rgba32[] data, uint width, uint height, bool mipMap)
        {
            var image = SixLabors.ImageSharp.Image.LoadPixelData(data, (int)width, (int)height);

            var imageSharpTexture = new ImageSharpTexture(image, mipMap);

            var veldridTexture = imageSharpTexture.CreateDeviceTexture(_systemComponents.Device.RawVeldridDevice, _systemComponents.Factory.RawFactory);

            return(veldridTexture);
        }
        /// <summary>
        /// Adds the image to the Graphic Device as a texture.
        /// Then returns the pointer of the added texture. It also
        /// cache the image internally rather than creating a new texture on every call,
        /// so this function can be called multiple times per image (per FPS).
        /// </summary>
        /// <param name="filePath">
        /// Path to the image on disk. If the image is loaded in the memory
        /// save it on the disk before sending to this function. Reason for this
        /// is to cache the Image Texture using filePath as the key.
        /// </param>
        /// <returns>
        /// A pointer to the Texture in the Graphic Device.
        /// </returns>
        public IntPtr AddOrGetImagePointer(string filePath)
        {
            if (!loadedImages.TryGetValue(filePath, out Texture texture))
            {
                ImageSharpTexture imgSharpTexture = new ImageSharpTexture(filePath);
                texture = imgSharpTexture.CreateDeviceTexture(graphicsDevice, graphicsDevice.ResourceFactory);
                loadedImages.Add(filePath, texture);
            }

            return imController.GetOrCreateImGuiBinding(graphicsDevice.ResourceFactory, texture);
        }
Ejemplo n.º 23
0
        public Texture GenerateSingleWhitePixel()
        {
            var image = SixLabors.ImageSharp.Image.LoadPixelData(new Rgba32[] {
                new Rgba32(1.0f, 1.0f, 1.0f, 1.0f)
            }, 1, 1);
            var imageSharpTexture = new ImageSharpTexture(image, false);

            var veldridTexture = imageSharpTexture.CreateDeviceTexture(_systemComponents.Device.RawVeldridDevice, _systemComponents.Factory.RawFactory);

            return(veldridTexture);
        }
Ejemplo n.º 24
0
 public Skybox(
     ImageSharpTexture front, ImageSharpTexture back, ImageSharpTexture left,
     ImageSharpTexture right, ImageSharpTexture top, ImageSharpTexture bottom)
 {
     _front  = front;
     _back   = back;
     _left   = left;
     _right  = right;
     _top    = top;
     _bottom = bottom;
 }
Ejemplo n.º 25
0
        public static Texture FromFile(GraphicsDevice device, string filename)
        {
            var tex     = new Texture();
            var factory = device.ResourceFactory;
            var image   = new ImageSharpTexture(filename);

            tex.DeviceTexture     = image.CreateDeviceTexture(device, factory);
            tex.DeviceTextureView = factory.CreateTextureView(new TextureViewDescription(tex.DeviceTexture));

            return(tex);
        }
Ejemplo n.º 26
0
        public static Texture FromImage(GraphicsDevice device, Image <Rgba32> img)
        {
            var tex     = new Texture();
            var factory = device.ResourceFactory;
            var image   = new ImageSharpTexture(img);

            tex.DeviceTexture     = image.CreateDeviceTexture(device, factory);
            tex.DeviceTextureView = factory.CreateTextureView(new TextureViewDescription(tex.DeviceTexture));

            return(tex);
        }
Ejemplo n.º 27
0
        protected override materials.UIMaterial Load(string name)
        {
            using var bitmap = LoadMaskedBitmap(resourcePool, name);
            var texture = new ImageSharpTexture(bitmap, mipmap: false)
                          .CreateDeviceTexture(graphicsDevice, resourceFactory);
            var material = new materials.UIMaterial(diContainer, isFont: false);

            material.Texture.Texture   = texture;
            material.Sampler.Sampler   = graphicsDevice.LinearSampler;
            material.ScreenSize.Buffer = ui.ProjectionBuffer;
            return(material);
        }
Ejemplo n.º 28
0
 public Skybox(RenderContext rc, AssetDatabase ad,
               ImageSharpTexture front, ImageSharpTexture back, ImageSharpTexture left,
               ImageSharpTexture right, ImageSharpTexture top, ImageSharpTexture bottom)
 {
     _front  = front;
     _back   = back;
     _left   = left;
     _right  = right;
     _top    = top;
     _bottom = bottom;
     ChangeRenderContext(ad, rc);
 }
        public ImageSharpTrueColorTexture(string name, Image <Rgba32> image)
        {
            Name = name;
            ImageSharpTexture imageSharpTexture = new ImageSharpTexture(image, false);

            _texture = imageSharpTexture;
            IsDirty  = true;

            _subImage = new SubImage(
                Vector2.Zero,
                new Vector2(_texture.Width, _texture.Height),
                new Vector2(_texture.Width, _texture.Height),
                0);
        }
Ejemplo n.º 30
0
        public static ResourceSet GenerateTextureResourceSetForDiffuseMapping <T>(ModelRuntimeDescriptor <T> modelRuntimeState, int meshIndex, DisposeCollectorResourceFactory factory, GraphicsDevice graphicsDevice) where T : struct, VertexLocateable
        {
            RealtimeMaterial material = modelRuntimeState.Model.GetMaterial(meshIndex);

            ImageSharpTexture diffuseTextureIS   = new ImageSharpTexture(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.textureDiffuse));
            Texture           diffuseTexture     = diffuseTextureIS.CreateDeviceTexture(graphicsDevice, factory);
            TextureView       diffuseTextureView = factory.CreateTextureView(diffuseTexture);

            return(factory.CreateResourceSet(new ResourceSetDescription(
                                                 modelRuntimeState.TextureResourceLayout,
                                                 diffuseTextureView,
                                                 modelRuntimeState.TextureSampler
                                                 )));
        }