Пример #1
0
        private void FillLightDiffuseMap(CubeMapFace face, uint color)
        {
            var dst = lightDiffuseMap.LockRectangle(face, 0, LockFlags.None);

            dst.Data.Write(color);
            lightDiffuseMap.UnlockRectangle(face, 0);
        }
Пример #2
0
        private void LoadCubeMapFace(CubeTexture tex, CubeMapFace face, string fileName, int size, Format format)
        {
            var data = Surface.CreateOffscreenPlain(device, size, size, format, Pool.Scratch);

            Surface.FromFileInStream(data, this.GetType().Assembly.GetManifestResourceStream(fileName), Filter.None, 0);
            var dstRect = tex.LockRectangle(face, 0, LockFlags.None);
            var srcRect = data.LockRectangle(LockFlags.ReadOnly);

            srcRect.Data.CopyTo(dstRect.Data);

            data.UnlockRectangle();
            tex.UnlockRectangle(face, 0);

            data.Dispose();
        }
Пример #3
0
        public void Add(TextureSection textureSection)
        {
            Texture     texture = null;
            CubeTexture cube    = null;

            try
            {
                TextureHolder texHolder = new TextureHolder();
                int           texWidth  = textureSection.Gtex.Header.Width;
                int           texHeight = textureSection.Gtex.Header.Height;
                if (textureSection.Gtex.Header.IsCubeMap)
                {
                    cube = new CubeTexture(device, texWidth, 0, Usage.None, textureSection.Gtex.Format, Pool.Managed);
                    texHolder.Texture = cube;
                    texHolder.Name    = textureSection.ResourceId;
                    texHolder.Gtex    = textureSection.Gtex;

                    CubeMapFace[] faces = new CubeMapFace[] { CubeMapFace.NegativeX,
                                                              CubeMapFace.NegativeY,
                                                              CubeMapFace.NegativeZ,
                                                              CubeMapFace.PositiveX,
                                                              CubeMapFace.PositiveY,
                                                              CubeMapFace.PositiveZ };
                    for (var i = 0; i < 6; i++)
                    {
                        var texData = cube.LockRectangle(faces[i], 0, LockFlags.None);
                        texData.Data.Write(texHolder.Gtex.TextureData[i], 0, texHolder.Gtex.TextureData[i].Length);
                        cube.UnlockRectangle(faces[i], 0);
                    }
                }
                else
                {
                    int    numMipMaps = textureSection.Gtex.Header.MipMapCount;
                    Format format     = textureSection.Gtex.Format;

                    texture = new Texture(device, texWidth, texHeight, numMipMaps, Usage.None, format, Pool.Managed);

                    texHolder.Texture = texture;
                    texHolder.Name    = textureSection.ResourceId;
                    texHolder.Gtex    = textureSection.Gtex;

                    for (var i = 0; i < numMipMaps; i++)
                    {
                        var texData = texture.LockRectangle(i, LockFlags.None);
                        texData.Data.Write(texHolder.Gtex.TextureData[i], 0, texHolder.Gtex.TextureData[i].Length);
                        texture.UnlockRectangle(i);
                    }
                }

                TextureHolder removeMe;
                if (this.textureLookup.TryGetValue(texHolder.Name, out removeMe))
                {
                    removeMe.Texture.Dispose();
                    this.textures.Remove(removeMe);
                    this.textureLookup.Remove(texHolder.Name);
                }

                this.textures.Add(texHolder);
                this.textureLookup.Add(texHolder.Name, texHolder);
            }
            catch
            {
                if (texture != null)
                {
                    texture.Dispose();
                }
                if (cube != null)
                {
                    cube.Dispose();
                }

                throw;
            }
        }
Пример #4
0
        public void Add(TextureSection textureSection)
        {
            Texture texture = null;
            CubeTexture cube = null;
            try
            {
                TextureHolder texHolder = new TextureHolder();
                int texWidth = textureSection.Gtex.Header.Width;
                int texHeight = textureSection.Gtex.Header.Height;
                if (textureSection.Gtex.Header.IsCubeMap)
                {
                    cube = new CubeTexture(device, texWidth, 0, Usage.None, textureSection.Gtex.Format, Pool.Managed);
                    texHolder.Texture = cube;
                    texHolder.Name = textureSection.ResourceId;
                    texHolder.Gtex = textureSection.Gtex;

                    CubeMapFace[] faces = new CubeMapFace[] { CubeMapFace.NegativeX,
                                                              CubeMapFace.NegativeY,
                                                              CubeMapFace.NegativeZ,
                                                              CubeMapFace.PositiveX,
                                                              CubeMapFace.PositiveY,
                                                              CubeMapFace.PositiveZ };
                    for (var i = 0; i < 6; i++)
                    {
                        var texData = cube.LockRectangle(faces[i], 0, LockFlags.None);
                        texData.Data.Write(texHolder.Gtex.TextureData[i], 0, texHolder.Gtex.TextureData[i].Length);
                        cube.UnlockRectangle(faces[i], 0);
                    }
                }
                else
                {
                    int numMipMaps = textureSection.Gtex.Header.MipMapCount;
                    Format format = textureSection.Gtex.Format;

                    texture = new Texture(device, texWidth, texHeight, numMipMaps, Usage.None, format, Pool.Managed);

                    texHolder.Texture = texture;
                    texHolder.Name = textureSection.ResourceId;
                    texHolder.Gtex = textureSection.Gtex;

                    for (var i = 0; i < numMipMaps; i++)
                    {
                        var texData = texture.LockRectangle(i, LockFlags.None);
                        texData.Data.Write(texHolder.Gtex.TextureData[i], 0, texHolder.Gtex.TextureData[i].Length);
                        texture.UnlockRectangle(i);
                    }
                }

                TextureHolder removeMe;
                if (this.textureLookup.TryGetValue(texHolder.Name, out removeMe))
                {
                    removeMe.Texture.Dispose();
                    this.textures.Remove(removeMe);
                    this.textureLookup.Remove(texHolder.Name);
                }

                this.textures.Add(texHolder);
                this.textureLookup.Add(texHolder.Name, texHolder);
            }
            catch
            {
                if (texture != null) { texture.Dispose(); }
                if (cube != null) { cube.Dispose(); }

                throw;
            }
        }
Пример #5
0
        private void LoadCubeMapFace(CubeTexture tex, CubeMapFace face, string fileName, int size, Format format)
        {
            var data = Surface.CreateOffscreenPlain(device, size, size, format, Pool.Scratch);
            Surface.FromFileInStream(data, this.GetType().Assembly.GetManifestResourceStream(fileName), Filter.None, 0);
            var dstRect = tex.LockRectangle(face, 0, LockFlags.None);
            var srcRect = data.LockRectangle(LockFlags.ReadOnly);

            srcRect.Data.CopyTo(dstRect.Data);

            data.UnlockRectangle();
            tex.UnlockRectangle(face, 0);

            data.Dispose();
        }