Beispiel #1
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();
        }
        public void Run(OpsContext context, OpsStatement statement)
        {
            TexFormatArgs args = statement.Arguments as TexFormatArgs;

            ArrayList containers = statement.GetContent(context);

            OpsConsole.WriteLine("Changing texture formats to " + args.Format);

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

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

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

                    container.Texture = OpsTextureHelper.CloneCube(oldTexture, sd.Width, oldTexture.LevelCount, args.Format, Usage.None, Filter.Triangle | Filter.Dither | (container.SRGB?Filter.Srgb:0), Pool.Managed);
                }
            }
        }
Beispiel #3
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            OpsConsole.WriteLine("Texture information");
            OpsConsole.WriteLine(format, "Names", "Type", "Width", "Height", "Depth", "Mips", "Format");

            foreach (OpsTexture container in statement.GetContent(context))
            {
                string name        = container.Name;
                string type        = container.Texture.GetType().Name;
                int    width       = 0;
                int    height      = 0;
                int    depth       = 0;
                int    mips        = 0;
                string pixelFormat = "";

                if (container.Texture is Texture)
                {
                    Texture            texture = container.Texture as Texture;
                    SurfaceDescription sd      = texture.GetLevelDescription(0);
                    width       = sd.Width;
                    height      = sd.Height;
                    mips        = texture.LevelCount;
                    pixelFormat = sd.Format.ToString();
                }
                else if (container.Texture is VolumeTexture)
                {
                    VolumeTexture     texture = container.Texture as VolumeTexture;
                    VolumeDescription vd      = texture.GetLevelDescription(0);
                    width       = vd.Width;
                    height      = vd.Height;
                    depth       = vd.Depth;
                    mips        = texture.LevelCount;
                    pixelFormat = vd.Format.ToString();
                }
                else if (container.Texture is CubeTexture)
                {
                    CubeTexture        texture = container.Texture as CubeTexture;
                    SurfaceDescription sd      = texture.GetLevelDescription(0);
                    width       = sd.Width;
                    height      = sd.Height;
                    mips        = texture.LevelCount;
                    pixelFormat = sd.Format.ToString();
                }

                OpsConsole.WriteLine(format,
                                     name,
                                     type,
                                     width,
                                     height,
                                     depth,
                                     mips,
                                     pixelFormat);
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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);
                }
            }
        }
Beispiel #6
0
        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;
                }
            }
        }
Beispiel #7
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));
        }
        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);
        }
        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();
         }