예제 #1
0
            public override void GetNonMaterialTextureNames(ref List <ShaderProperty.TextureValue> dest)
            {
                if (expectingAVolume && !volumeTexture)
                {
                    volumeTexture    = painter.gameObject.GetComponent <VolumeTexture>();
                    expectingAVolume = false;
                }

                if (volumeTexture)
                {
                    dest.Add(volumeTexture.TextureInShaderProperty);
                }
            }
예제 #2
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            Slice2dArgs args = statement.Arguments as Slice2dArgs;

            ArrayList containers = statement.GetContent(context);

            if (containers.Count != 1)
            {
                throw new OpsException("Src argument does not resolve to 1 texture.  Textures found: " + containers.Count);
            }

            OpsTexture container = containers[0] as OpsTexture;

            OpsConsole.WriteLine("Slicing from texture:{0} and saving as {1}", container.Name, args.Dst);

            OpsTexture result = new OpsTexture();

            result.Name = args.Dst;
            result.SRGB = container.SRGB;

            Texture newTexture = null;

            if (container.Texture is Texture)
            {
                Texture            srcTexture = container.Texture as Texture;
                SurfaceDescription sd         = srcTexture.GetLevelDescription(args.Mips);

                newTexture = new Texture(srcTexture.Device, sd.Width, sd.Height, 1, Usage.None, sd.Format, Pool.Managed);
                SurfaceLoader.FromSurface(newTexture.GetSurfaceLevel(0), srcTexture.GetSurfaceLevel(0), Filter.Dither | Filter.Triangle | (container.SRGB?Filter.Srgb:0), 0);
            }
            else if (container.Texture is VolumeTexture)
            {
                VolumeTexture     srcTexture = container.Texture as VolumeTexture;
                VolumeDescription vd         = srcTexture.GetLevelDescription(args.Mips);

                newTexture = new Texture(srcTexture.Device, vd.Width, vd.Height, 1, Usage.None, vd.Format, Pool.Managed);
                OpsTextureHelper.LoadSurfaceFromVolumeSlice(srcTexture, args.Mips, args.Volume, Filter.Dither | Filter.Triangle | (container.SRGB?Filter.Srgb:0), newTexture.GetSurfaceLevel(0));
            }
            else if (container.Texture is CubeTexture)
            {
                CubeTexture        srcTexture = container.Texture as CubeTexture;
                SurfaceDescription sd         = srcTexture.GetLevelDescription(args.Mips);

                newTexture = new Texture(srcTexture.Device, sd.Width, sd.Height, 1, Usage.None, sd.Format, Pool.Managed);
                SurfaceLoader.FromSurface(newTexture.GetSurfaceLevel(0), srcTexture.GetCubeMapSurface(args.Face, 0), Filter.Dither | Filter.Triangle | (container.SRGB?Filter.Srgb:0), 0);
            }

            result.Texture = newTexture;

            context.AddTexture(result);
        }
예제 #3
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            Splice2dArgs args = statement.Arguments as Splice2dArgs;

            ArrayList srcList = statement.GetContent(context);

            if (srcList.Count != 1)
            {
                throw new OpsException("Could not find the source texture.  1 is require but found " + srcList.Count);
            }

            OpsTexture srcContainer = ((OpsTexture)srcList[0]);

            if (!(srcContainer.Texture is Texture))
            {
                throw new OpsException("Source texture is not 2D");
            }

            Texture srcTexture = srcContainer.Texture as Texture;

            OpsConsole.WriteLine("Splicing texture:{0} into one or more textures", srcContainer.Name);


            ArrayList dstContainers = context.FindTextures(args.Dst);

            foreach (OpsTexture dstContainer in dstContainers)
            {
                if (dstContainer.Texture is Texture)
                {
                    Texture dstTexture = dstContainer.Texture as Texture;

                    SurfaceLoader.FromSurface(dstTexture.GetSurfaceLevel(args.Mips), srcTexture.GetSurfaceLevel(0), Filter.Dither | Filter.Triangle | (srcContainer.SRGB?Filter.SrgbIn:0) | (dstContainer.SRGB?Filter.SrgbOut:0), 0);
                }
                else if (dstContainer.Texture is VolumeTexture)
                {
                    VolumeTexture dstTexture = dstContainer.Texture as VolumeTexture;

                    OpsTextureHelper.LoadVolumeSliceFromSurface(dstTexture, args.Mips, args.Volume, Filter.Dither | Filter.Triangle | (srcContainer.SRGB?Filter.SrgbIn:0) | (dstContainer.SRGB?Filter.SrgbOut:0), srcTexture.GetSurfaceLevel(0));
                }
                else if (dstContainer.Texture is CubeTexture)
                {
                    CubeTexture dstTexture = dstContainer.Texture as CubeTexture;

                    SurfaceLoader.FromSurface(dstTexture.GetCubeMapSurface(args.Face, args.Mips), srcTexture.GetSurfaceLevel(0), Filter.Dither | Filter.Triangle | (srcContainer.SRGB?Filter.SrgbIn:0) | (dstContainer.SRGB?Filter.SrgbOut:0), 0);
                }
            }
        }
예제 #4
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            NewTex3dArgs args = statement.Arguments as NewTex3dArgs;

            OpsConsole.WriteLine("Creating new volume texture named " + args.Name);

            OpsTexture result = new OpsTexture();

            result.Name = args.Name;
            VolumeTexture newTexture = new VolumeTexture(context.Device, args.Width, args.Height, args.Depth, args.Mips, Usage.None, args.Format, Pool.Managed);

            result.Texture = newTexture;

            CopyToVolume(context, newTexture, args.Src, Filter.Triangle | Filter.Dither);

            context.AddTexture(result);
        }
예제 #5
0
        /// <summary>
        /// The device has been created.  Resources that are not lost on
        /// Reset() can be created here -- resources in Pool.Managed,
        /// Pool.Scratch, or Pool.SystemMemory.  Image surfaces created via
        /// CreateImageSurface are never lost and can be created here.  Vertex
        /// shaders and pixel shaders can also be created here as they are not
        /// lost on Reset().
        /// </summary>
        protected override void InitializeDeviceObjects()
        {
            // Initialize all of the fonts
            drawingFont.InitializeDeviceObjects(device);
            // Create a volume texture
            volume = new VolumeTexture(device, 16, 16, 16, 1, Format.A8R8G8B8, Pool.Managed);
            // Fill the volume texture
            int[,,] data = (int[, , ])volume.LockBox(typeof(int), 0, 0, 16, 16, 16);
            for (int w = 0; w < 16; w++)
            {
                for (int v = 0; v < 16; v++)
                {
                    for (int u = 0; u < 16; u++)
                    {
                        float du     = (u - 7.5f) / 7.5f;
                        float dv     = (v - 7.5f) / 7.5f;
                        float dw     = (w - 7.5f) / 7.5f;
                        float fScale = (float)Math.Sqrt(du * du + dv * dv + dw * dw) / (float)Math.Sqrt(1.0f);

                        if (fScale > 1.0f)
                        {
                            fScale = 0.0f;
                        }
                        else
                        {
                            fScale = 1.0f - fScale;
                        }

                        int r = (int)((w << 4) * fScale);
                        int g = (int)((v << 4) * fScale);
                        int b = (int)((u << 4) * fScale);

                        data[w, v, u] = unchecked ((int)0xff000000 + (r << 16) + (g << 8) + (b));
                    }
                }
            }
            volume.UnlockBox(0);

            // Create a vertex buffer
            vertex = new VertexBuffer(typeof(VolumeVertex), 4, device, Usage.WriteOnly, VolumeVertex.Format, Pool.Managed);
            GraphicsStream vertStream = vertex.Lock(0, 0, 0);

            // Copy our vertices in
            vertStream.Write(vertices);
            vertex.Unlock();
        }
        private void GenerateTexture(double[,,] array)
        {
            int index = 0;

            byte[] buffer = new byte[4 * textureSizeX * textureSizeY * textureSizeZ];

            for (int i = 0; i < textureSizeX; i++)
            {
                for (int j = 0; j < textureSizeY; j++)
                {
                    for (int k = 0; k < textureSizeZ; k++)
                    {
                        float i1 = (float)(i * (float)(array.GetLength(0) - 1) / textureSizeX);
                        float j1 = (float)(j * (float)(array.GetLength(1) - 1) / textureSizeY);
                        float k1 = (float)(k * (float)(array.GetLength(2) - 1) / textureSizeZ);

                        float  value = MathHelper.GetValue(new Vector3(i1, j1, k1), array);
                        byte[] color = RgbPalette.GetColorBytes(value, dataSource.Maximum, dataSource.Minimum, dataSource.MissingValue);

                        if (value > dataSource.Maximum)
                        {
                            value = dataSource.Maximum;
                        }
                        if (value < dataSource.Minimum)
                        {
                            value = dataSource.Minimum;
                        }

                        buffer[index++] = color[3];
                        buffer[index++] = color[2];
                        buffer[index++] = color[1];
                        buffer[index++] = (byte)((value - dataSource.Minimum) / (dataSource.Maximum - dataSource.Minimum) * 255);
                    }
                }
            }

            texture = new VolumeTexture(device, textureSizeX, textureSizeY, textureSizeZ, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);

            DataBox dbox = texture.LockBox(0, LockFlags.None);

            dbox.Data.WriteRange(buffer);
            texture.UnlockBox(0);
        }
예제 #7
0
        /// <summary>Create a volume texture from a file</summary>
        public VolumeTexture CreateVolumeTextureFromFileEx(Device device, string filename, int w, int h, int d, int mip, Usage usage, Format fmt, Pool pool, Filter filter, Filter mipfilter, int colorkey)
        {
            // Search the cache first
            foreach (CachedTexture ct in textureCache.Keys)
            {
                if ((string.Compare(ct.Source, filename, true) == 0) &&
                    ct.Width == w &&
                    ct.Height == h &&
                    ct.Depth == d &&
                    ct.MipLevels == mip &&
                    ct.Usage == usage &&
                    ct.Format == fmt &&
                    ct.Pool == pool &&
                    ct.Type == ResourceType.VolumeTexture)
                {
                    // A match was found, return that
                    return(textureCache[ct] as VolumeTexture);
                }
            }

            // No matching entry, load the resource and add it to the cache
            VolumeTexture t     = TextureLoader.FromVolumeFile(device, filename, w, h, d, mip, usage, fmt, pool, filter, mipfilter, colorkey);
            CachedTexture entry = new CachedTexture();

            entry.Source    = filename;
            entry.Width     = w;
            entry.Height    = h;
            entry.Depth     = d;
            entry.MipLevels = mip;
            entry.Usage     = usage;
            entry.Format    = fmt;
            entry.Pool      = pool;
            entry.Type      = ResourceType.VolumeTexture;

            textureCache.Add(entry, t);

            return(t);
        }
        private void GenerateTexture(double[, ,] array)
        {
            int index = 0;
            byte[] buffer = new byte[4 * textureSizeX * textureSizeY * textureSizeZ];
            
            for (int i = 0; i < textureSizeX; i++)
            {
                for (int j = 0; j < textureSizeY; j++)
                {
                    for (int k = 0; k < textureSizeZ; k++)
                    {
                        float i1 = (float)(i * (float)(array.GetLength(0) - 1) / textureSizeX);
                        float j1 = (float)(j * (float)(array.GetLength(1) - 1) / textureSizeY);
                        float k1 = (float)(k * (float)(array.GetLength(2) - 1) / textureSizeZ);

                        float value = MathHelper.GetValue(new Vector3(i1, j1, k1), array);
                        byte[] color = RgbPalette.GetColorBytes(value, dataSource.Maximum, dataSource.Minimum, dataSource.MissingValue);

                        if (value > dataSource.Maximum) value = dataSource.Maximum;
                        if (value < dataSource.Minimum) value = dataSource.Minimum;
                        
                        buffer[index++] = color[3];
                        buffer[index++] = color[2];
                        buffer[index++] = color[1];
                        buffer[index++] = (byte)((value - dataSource.Minimum) / (dataSource.Maximum - dataSource.Minimum) * 255);

                    }
                }
            }

            texture = new VolumeTexture(device, textureSizeX, textureSizeY, textureSizeZ, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);

            DataBox dbox = texture.LockBox(0, LockFlags.None);
            dbox.Data.WriteRange(buffer);
            texture.UnlockBox(0);
        }
예제 #9
0
 float BrushScaleMaxForCpu(VolumeTexture volTex) => volTex.size * volTex.Width * 0.025f;
예제 #10
0
파일: shade.cs 프로젝트: senny970/2007
        public void Run(OpsContext context, OpsStatement statement)
        {
            ShadeArgs args = statement.Arguments as ShadeArgs;

            ConstantTable constantTable = SetupDevice(context, args);

            EffectHandle hTarget = constantTable.GetConstant(null, "Target");


            ArrayList containers = statement.GetContent(context);

            OpsConsole.WriteLine("Shading textures with \"{0}\"", args.File);

            foreach (OpsTexture container in containers)
            {
                if (hTarget != null)
                {
                    context.Device.SetTexture(
                        constantTable.GetSamplerIndex(hTarget),
                        container.Texture);
                }


                if (container.Texture is Texture)
                {
                    Texture oldTexture = container.Texture as Texture;
                    Texture newTexture = OpsTextureHelper.CloneTexture(oldTexture, Usage.None, Pool.Managed);

                    for (int mip = 0; mip < oldTexture.LevelCount; mip++)
                    {
                        SurfaceDescription sd = oldTexture.GetLevelDescription(mip);

                        CheckFormatValid(sd.Format);

                        Surface rt = context.Device.CreateRenderTarget(sd.Width, sd.Height, sd.Format, MultiSampleType.None, 0, true);

                        context.Device.SetRenderTarget(0, rt);


                        ShadeVertex[] vb = new ShadeVertex[]
                        {
                            ShadeVertex.ForTexture(-1.0f, -1.0f, sd.Width, sd.Height),
                            ShadeVertex.ForTexture(1.0f, -1.0f, sd.Width, sd.Height),
                            ShadeVertex.ForTexture(-1.0f, 1.0f, sd.Width, sd.Height),
                            ShadeVertex.ForTexture(1.0f, 1.0f, sd.Width, sd.Height),
                        };

                        context.Device.BeginScene();
                        context.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vb);
                        context.Device.EndScene();

                        context.Device.SetRenderTarget(0, context.Device.GetBackBuffer(0, 0, BackBufferType.Mono));

                        SurfaceLoader.FromSurface(newTexture.GetSurfaceLevel(mip), rt, Filter.None | (container.SRGB?Filter.SrgbOut:0), 0);
                    }

                    oldTexture.Dispose();
                    container.Texture = newTexture;
                }
                else if (container.Texture is VolumeTexture)
                {
                    VolumeTexture oldTexture = container.Texture as VolumeTexture;
                    VolumeTexture newTexture = OpsTextureHelper.CloneVolume(oldTexture, Usage.None, Pool.Managed);

                    for (int mip = 0; mip < oldTexture.LevelCount; mip++)
                    {
                        VolumeDescription vd = oldTexture.GetLevelDescription(mip);

                        CheckFormatValid(vd.Format);

                        Surface sliceRT = context.Device.CreateRenderTarget(vd.Width, vd.Height, vd.Format, MultiSampleType.None, 0, true);

                        for (int slice = 0; slice < vd.Depth; slice++)
                        {
                            context.Device.SetRenderTarget(0, sliceRT);

                            ShadeVertex[] vb = new ShadeVertex[]
                            {
                                ShadeVertex.ForVolume(-1.0f, -1.0f, slice, vd.Width, vd.Height, vd.Depth),
                                ShadeVertex.ForVolume(1.0f, -1.0f, slice, vd.Width, vd.Height, vd.Depth),
                                ShadeVertex.ForVolume(-1.0f, 1.0f, slice, vd.Width, vd.Height, vd.Depth),
                                ShadeVertex.ForVolume(1.0f, 1.0f, slice, vd.Width, vd.Height, vd.Depth),
                            };

                            context.Device.BeginScene();
                            context.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vb);
                            context.Device.EndScene();

                            context.Device.SetRenderTarget(0, context.Device.GetBackBuffer(0, 0, BackBufferType.Mono));

                            OpsTextureHelper.LoadVolumeSliceFromSurface(newTexture, mip, slice, Filter.None | (container.SRGB?Filter.SrgbOut:0), sliceRT);
                        }

                        sliceRT.Dispose();
                    }

                    oldTexture.Dispose();
                    container.Texture = newTexture;
                }
                else if (container.Texture is CubeTexture)
                {
                    CubeTexture oldTexture = container.Texture as CubeTexture;
                    CubeTexture newTexture = OpsTextureHelper.CloneCube(oldTexture, Usage.None, Pool.Managed);

                    for (int mip = 0; mip < oldTexture.LevelCount; mip++)
                    {
                        SurfaceDescription sd = oldTexture.GetLevelDescription(mip);

                        CheckFormatValid(sd.Format);

                        Surface rt = context.Device.CreateRenderTarget(sd.Width, sd.Height, sd.Format, MultiSampleType.None, 0, true);

                        RenderCubeMapFace(context, newTexture, rt, CubeMapFace.PositiveX, mip, sd.Width, container.SRGB);
                        RenderCubeMapFace(context, newTexture, rt, CubeMapFace.PositiveY, mip, sd.Width, container.SRGB);
                        RenderCubeMapFace(context, newTexture, rt, CubeMapFace.PositiveZ, mip, sd.Width, container.SRGB);
                        RenderCubeMapFace(context, newTexture, rt, CubeMapFace.NegativeX, mip, sd.Width, container.SRGB);
                        RenderCubeMapFace(context, newTexture, rt, CubeMapFace.NegativeY, mip, sd.Width, container.SRGB);
                        RenderCubeMapFace(context, newTexture, rt, CubeMapFace.NegativeZ, mip, sd.Width, container.SRGB);
                    }

                    oldTexture.Dispose();

                    container.Texture = newTexture;
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Decodes the texture from the specified stream.
        /// </summary>
        /// <param name="stream">The stream, where the texture should be decoded from. Cannot be null.</param>
        /// <returns>The decoded image.</returns>
        public Texture DecodeTexture(Stream stream)
        {
            try
            {
                this.ReadFileHeader(stream);

                if (this.ddsHeader.Width == 0 || this.ddsHeader.Height == 0)
                {
                    throw new UnknownTextureFormatException("Width or height cannot be 0");
                }

                var ddsProcessor = new DdsProcessor(this.ddsHeader, this.ddsDxt10header);

                int width  = (int)this.ddsHeader.Width;
                int height = (int)this.ddsHeader.Height;
                int count  = this.ddsHeader.TextureCount();

                if (this.ddsHeader.IsVolumeTexture())
                {
                    int depths = this.ddsHeader.ComputeDepth();

                    var texture  = new VolumeTexture();
                    var surfaces = new FlatTexture[depths];

                    for (int i = 0; i < count; i++)
                    {
                        for (int depth = 0; depth < depths; depth++)
                        {
                            if (i == 0)
                            {
                                surfaces[depth] = new FlatTexture();
                            }

                            MipMap[] mipMaps = ddsProcessor.DecodeDds(stream, width, height, 1);
                            surfaces[depth].MipMaps.AddRange(mipMaps);
                        }

                        depths >>= 1;
                        width  >>= 1;
                        height >>= 1;
                    }

                    texture.Slices.AddRange(surfaces);
                    return(texture);
                }
                else if (this.ddsHeader.IsCubemap())
                {
                    DdsSurfaceType[] faces = this.ddsHeader.GetExistingCubemapFaces();

                    var texture = new CubemapTexture();
                    for (int face = 0; face < faces.Length; face++)
                    {
                        MipMap[] mipMaps = ddsProcessor.DecodeDds(stream, width, height, count);
                        if (faces[face] == DdsSurfaceType.CubemapPositiveX)
                        {
                            texture.PositiveX.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapNegativeX)
                        {
                            texture.NegativeX.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapPositiveY)
                        {
                            texture.PositiveY.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapNegativeY)
                        {
                            texture.NegativeY.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapPositiveZ)
                        {
                            texture.PositiveZ.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapNegativeZ)
                        {
                            texture.NegativeZ.MipMaps.AddRange(mipMaps);
                        }
                    }

                    return(texture);
                }
                else
                {
                    var      texture = new FlatTexture();
                    MipMap[] mipMaps = ddsProcessor.DecodeDds(stream, width, height, count);
                    texture.MipMaps.AddRange(mipMaps);
                    return(texture);
                }
            }
            catch (IndexOutOfRangeException e)
            {
                throw new TextureFormatException("Dds image does not have a valid format.", e);
            }
        }
예제 #12
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            NewTex3dArgs args = statement.Arguments as NewTex3dArgs;

            OpsConsole.WriteLine( "Creating new volume texture named " + args.Name);

            OpsTexture result = new OpsTexture();
            result.Name = args.Name;
            VolumeTexture newTexture =  new VolumeTexture( context.Device, args.Width , args.Height , args.Depth , args.Mips , Usage.None , args.Format , Pool.Managed );
            result.Texture = newTexture;

            CopyToVolume(context, newTexture, args.Src, Filter.Triangle|Filter.Dither);

            context.AddTexture(result);
        }
예제 #13
0
 public static VolumeTexture CloneVolume( VolumeTexture oldTexture, int width, int height, int depth, int mips, Format format, Usage usage, Filter filter, Pool pool )
 {
     VolumeTexture newTexture = new VolumeTexture(oldTexture.Device, width, height, depth, mips, usage, format, pool);
     VolumeLoader.FromVolume(newTexture.GetVolumeLevel(0), oldTexture.GetVolumeLevel(0), filter, 0);
     return newTexture;
 }
예제 #14
0
        public static VolumeTexture CloneVolume( VolumeTexture oldTexture, Usage usage, Pool pool )
        {
            VolumeDescription vd = oldTexture.GetLevelDescription(0);

            return CloneVolume(oldTexture, vd.Width, vd.Height, vd.Depth, oldTexture.LevelCount, vd.Format, usage, Filter.None, pool);
        }
예제 #15
0
        public static void LoadSurfaceFromVolumeSlice( VolumeTexture volumeTex, int mip, int slice, Filter filter, Surface surface)
        {
            VolumeDescription vd = volumeTex.GetLevelDescription(mip);
            OpsFormatHelper formatHelp = OpsFormatHelper.FindByFormat( vd.Format );

            Texture sliceTex = new Texture(volumeTex.Device, vd.Width, vd.Height, 1, Usage.None, formatHelp.Format, Pool.SystemMemory);

            Box box = new Box();
            box.Left = 0;
            box.Right = vd.Width;
            box.Top = 0;
            box.Bottom = vd.Height;
            box.Front = slice;
            box.Back = slice + 1;
            
            LockedBox volumeLB;
            GraphicsStream volumeData = volumeTex.LockBox(0, box, LockFlags.ReadOnly, out volumeLB);

            int slicePitch;
            GraphicsStream sliceData = sliceTex.LockRectangle(mip, LockFlags.None, out slicePitch);

            CopyTextureData(volumeData, vd.Width, vd.Height, formatHelp, volumeLB.RowPitch, sliceData, slicePitch);

            sliceTex.UnlockRectangle(0);
            volumeTex.UnlockBox(mip);

            SurfaceLoader.FromSurface(surface, sliceTex.GetSurfaceLevel(0), filter, 0);

            sliceTex.Dispose();
         }
예제 #16
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            TexResizeArgs args = statement.Arguments as TexResizeArgs;

            ArrayList containers = statement.GetContent(context);

            OpsConsole.WriteLine("Resizing textures to width:{0} height:{1} depth:{2}", args.Width, args.Height, args.Depth);

            foreach (OpsTexture container in containers)
            {
                if (container.Texture is Texture)
                {
                    Texture            oldTexture = container.Texture as Texture;
                    SurfaceDescription sd         = oldTexture.GetLevelDescription(0);

                    if (args.Width == -1)
                    {
                        args.Width = sd.Width;
                    }
                    if (args.Height == -1)
                    {
                        args.Height = sd.Height;
                    }

                    int mips = OpsTextureHelper.NumMips(args.Width, args.Height, 1);

                    container.Texture = OpsTextureHelper.CloneTexture(oldTexture, args.Width, args.Height, mips, sd.Format, Usage.None, args.Filter | (container.SRGB ? Filter.Srgb : 0), Pool.Managed);
                }
                else if (container.Texture is VolumeTexture)
                {
                    VolumeTexture     oldTexture = container.Texture as VolumeTexture;
                    VolumeDescription vd         = oldTexture.GetLevelDescription(0);

                    if (args.Width == -1)
                    {
                        args.Width = vd.Width;
                    }
                    if (args.Height == -1)
                    {
                        args.Height = vd.Height;
                    }
                    if (args.Depth == -1)
                    {
                        args.Depth = vd.Depth;
                    }

                    int mips = OpsTextureHelper.NumMips(args.Width, args.Height, args.Depth);

                    container.Texture = OpsTextureHelper.CloneVolume(oldTexture, args.Width, args.Height, args.Depth, mips, vd.Format, Usage.None, args.Filter | (container.SRGB ? Filter.Srgb : 0), Pool.Managed);
                }
                else if (container.Texture is CubeTexture)
                {
                    CubeTexture        oldTexture = container.Texture as CubeTexture;
                    SurfaceDescription sd         = oldTexture.GetLevelDescription(0);

                    if (args.Width == -1)
                    {
                        args.Width = sd.Width;
                    }

                    int mips = OpsTextureHelper.NumMips(args.Width, args.Width, 1);

                    container.Texture = OpsTextureHelper.CloneCube(oldTexture, args.Width, mips, sd.Format, Usage.None, args.Filter | (container.SRGB ? Filter.Srgb : 0), Pool.Managed);
                }
            }
        }
예제 #17
0
        public static VolumeTexture CloneVolume(VolumeTexture oldTexture, Usage usage, Pool pool)
        {
            VolumeDescription vd = oldTexture.GetLevelDescription(0);

            return(CloneVolume(oldTexture, vd.Width, vd.Height, vd.Depth, oldTexture.LevelCount, vd.Format, usage, Filter.None, pool));
        }
예제 #18
0
        public static void CopyToVolume(OpsContext context, VolumeTexture newTexture, string srcArg, Filter filter )
        {
            if(srcArg == null || srcArg.Length == 0)
                return;

            ArrayList srcList = context.FindTextures(srcArg);
                
            if(srcList == null || srcList.Count == 0)
                throw new OpsException("Could not find source texture: "+srcArg );
            
            if(((OpsTexture)srcList[0]).Texture is VolumeTexture )
            {
                VolumeLoader.FromVolume(newTexture.GetVolumeLevel(0), ((VolumeTexture)((OpsTexture)srcList[0]).Texture).GetVolumeLevel(0), filter, 0);    
            }
            else
            {
                for( int i = 0; i < srcList.Count; i++)
                {
                    OpsTexture src = srcList[i] as OpsTexture;

                    if(!(src.Texture is Texture))
                        throw new OpsException("Source texture pattern is not 1 volume texture or all 2D textures: "+srcArg);

                    OpsTextureHelper.LoadVolumeSliceFromSurface(newTexture, 0, i, filter, ((Texture)src.Texture).GetSurfaceLevel(0) );
                }
            }

            newTexture.GenerateMipSubLevels();
        }