Exemplo n.º 1
0
        //IOpsCommand
        public void Run(OpsContext context, OpsStatement statement)
        {
            TexLoaderArgs texArgs = statement.Arguments as TexLoaderArgs;

            string[] paths = OpsHelpers.ResolvePathToMany(texArgs.Path as string);

            foreach (string path in paths)
            {
                OpsConsole.WriteLine("Loading texture from file: \"{0}\"", path);

                OpsTexture result = new OpsTexture();

                ImageInformation Info = TextureLoader.ImageInformationFromFile(path);
                result.SRGB = texArgs.SRGB;

                if (Info.ResourceType == ResourceType.Textures)
                {
                    result.Texture = TextureLoader.FromFile(context.Device, path);
                }
                else if (Info.ResourceType == ResourceType.VolumeTexture)
                {
                    result.Texture = TextureLoader.FromVolumeFile(context.Device, path);
                }
                else if (Info.ResourceType == ResourceType.CubeTexture)
                {
                    result.Texture = TextureLoader.FromCubeFile(context.Device, path);
                }

                result.Name = System.IO.Path.GetFileNameWithoutExtension(path);

                context.AddTexture(result);
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        public static void CopyToCubeSide(OpsContext context, CubeTexture newTexture, string srcArg, CubeMapFace face, Filter filter)
        {
            if (srcArg == null || srcArg.Length == 0)
            {
                return;
            }

            OpsTexture src = context.GetTexture(srcArg);

            if (src == null)
            {
                throw new OpsException("Could not find source texture: " + srcArg);
            }

            if (src.Texture is CubeTexture)
            {
                SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(face, 0), ((CubeTexture)src.Texture).GetCubeMapSurface(face, 0), filter | (src.SRGB?Filter.SrgbIn:0), 0);
            }
            else if (src.Texture is Texture)
            {
                SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(face, 0), ((Texture)src.Texture).GetSurfaceLevel(0), filter | (src.SRGB?Filter.SrgbIn:0), 0);
            }
            else
            {
                throw new OpsException("Source texture is not a texture2D: " + srcArg);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        //IOpsCommand
        public void Run(OpsContext context, OpsStatement statement)
        {
            TexSaverArgs texArgs = statement.Arguments as TexSaverArgs;

            ArrayList containers = statement.GetContent(context);

            if (containers.Count != 1)
            {
                throw new OpsException("'src' argument resolves to " + containers.Count + " textures where it must be 1 texture");
            }


            OpsTexture container = containers[0] as OpsTexture;

            OpsConsole.WriteLine("Saving texture: {0} to path: {1}", container.Name, texArgs.Path);

            TextureLoader.Save(texArgs.Path, texArgs.Format, container.Texture);
        }
Exemplo n.º 8
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            NewTexCubeArgs args = statement.Arguments as NewTexCubeArgs;

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

            OpsTexture result = new OpsTexture();

            result.Name = args.Name;
            CubeTexture newTexture = new CubeTexture(context.Device, args.Size, args.Mips, Usage.None, args.Format, Pool.Managed);

            result.Texture = newTexture;

            CopyToCubeSide(context, newTexture, args.SrcXP, CubeMapFace.PositiveX, Filter.Triangle | Filter.Dither);
            CopyToCubeSide(context, newTexture, args.SrcYP, CubeMapFace.PositiveY, Filter.Triangle | Filter.Dither);
            CopyToCubeSide(context, newTexture, args.SrcZP, CubeMapFace.PositiveZ, Filter.Triangle | Filter.Dither);

            CopyToCubeSide(context, newTexture, args.SrcXM, CubeMapFace.NegativeX, Filter.Triangle | Filter.Dither);
            CopyToCubeSide(context, newTexture, args.SrcYM, CubeMapFace.NegativeY, Filter.Triangle | Filter.Dither);
            CopyToCubeSide(context, newTexture, args.SrcZM, CubeMapFace.NegativeZ, Filter.Triangle | Filter.Dither);

            context.AddTexture(result);
        }
Exemplo n.º 9
0
        public static void CopyToTexture(OpsContext context, Texture newTexture, string srcArg, Filter filter)
        {
            if (srcArg == null || srcArg.Length == 0)
            {
                return;
            }
            OpsTexture src = context.GetTexture(srcArg);

            if (src == null)
            {
                throw new OpsException("Could not find source texture: " + srcArg);
            }

            if (!(src.Texture is Texture))
            {
                throw new OpsException("Source texture is not a texture2D: " + srcArg);
            }

            Texture srcTex = src.Texture as Texture;

            SurfaceLoader.FromSurface(newTexture.GetSurfaceLevel(0), srcTex.GetSurfaceLevel(0), filter | (src.SRGB?Filter.SrgbIn:0), 0);

            newTexture.GenerateMipSubLevels();
        }
Exemplo n.º 10
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            NewTexCubeArgs args = statement.Arguments as NewTexCubeArgs;

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

            OpsTexture result = new OpsTexture();
            result.Name = args.Name;
            CubeTexture newTexture =  new CubeTexture( context.Device, args.Size , args.Mips , Usage.None , args.Format , Pool.Managed );
            result.Texture = newTexture;

            CopyToCubeSide( context, newTexture, args.SrcXP, CubeMapFace.PositiveX, Filter.Triangle|Filter.Dither);
            CopyToCubeSide( context, newTexture, args.SrcYP, CubeMapFace.PositiveY, Filter.Triangle|Filter.Dither);
            CopyToCubeSide( context, newTexture, args.SrcZP, CubeMapFace.PositiveZ, Filter.Triangle|Filter.Dither);
            
            CopyToCubeSide( context, newTexture, args.SrcXM, CubeMapFace.NegativeX, Filter.Triangle|Filter.Dither);
            CopyToCubeSide( context, newTexture, args.SrcYM, CubeMapFace.NegativeY, Filter.Triangle|Filter.Dither);
            CopyToCubeSide( context, newTexture, args.SrcZM, CubeMapFace.NegativeZ, Filter.Triangle|Filter.Dither);    

            context.AddTexture(result);
        }
Exemplo n.º 11
0
        private ConstantTable SetupDevice(OpsContext context, ShadeArgs args)
        {
            string         errStr = null;
            ConstantTable  constantTable;
            GraphicsStream pshader;
            GraphicsStream vshader;

            try
            {
                ConstantTable dummyTable;
                errStr  = null;
                vshader = ShaderLoader.CompileShader(ShadeVertex.VertexShader, "VertexShader", null, null, "vs_3_0", ShaderFlags.None, out errStr, out dummyTable);
            }
            finally
            {
                if (errStr != null && errStr.Length > 0)
                {
                    OpsConsole.WriteLine("Vertex Shader Compiler messages: " + errStr);
                    OpsConsole.WriteLine("If this message is regarding your entry point, it may be something other than the default 'main'.  Please use the argument 'Shader' to specify it.");
                }
            }


            try
            {
                Macro dxopsMacro = new Macro();
                dxopsMacro.Name       = "__DXOPS";
                dxopsMacro.Definition = "1";
                errStr  = null;
                pshader = ShaderLoader.CompileShaderFromFile(args.File, args.Shader, new Macro[] { dxopsMacro }, null, "ps_3_0", ShaderFlags.None, out errStr, out constantTable);
            }
            finally
            {
                if (errStr != null && errStr.Length > 0)
                {
                    OpsConsole.WriteLine("Pixel Shader Compiler messages: " + errStr);
                    OpsConsole.WriteLine("If this message is regarding your entry point, it may be something other than the default 'main'.  Please use the argument 'Shader' to specify it.");
                }
            }

            context.Device.SetRenderState(RenderStates.CullMode, (int)Cull.None);
            context.Device.SetRenderState(RenderStates.FillMode, (int)FillMode.Solid);
            context.Device.SetRenderState(RenderStates.AlphaTestEnable, false);
            context.Device.SetRenderState(RenderStates.AlphaBlendEnable, false);
            context.Device.SetRenderState(RenderStates.StencilEnable, false);
            context.Device.SetRenderState(RenderStates.ZEnable, false);
            context.Device.SetRenderState(RenderStates.ZBufferWriteEnable, false);

            context.Device.DepthStencilSurface = null;

            VertexDeclaration decl = new VertexDeclaration(context.Device, ShadeVertex.VertexDeclaration);

            context.Device.VertexDeclaration = decl;

            VertexShader vs = new VertexShader(context.Device, vshader);

            context.Device.VertexShader = vs;

            PixelShader ps = new PixelShader(context.Device, pshader);

            context.Device.PixelShader = ps;



            constantTable.SetDefaults(context.Device);

            foreach (OpsParsedArgument constant in args.Constants)
            {
                EffectHandle h = constantTable.GetConstant(null, constant.Name);
                if (h == null)
                {
                    OpsConsole.WriteLine("WARNING: Parameter '{0}' was not found in shader.", constant.Name);
                    continue;
                }

                ConstantDescription[] cds = constantTable.GetConstantDescription(h, 1);
                ConstantDescription   cd  = cds[0];
                switch (cd.Class)
                {
                case ParameterClass.Object:
                {    //texture
                    switch (cd.ParameterType)
                    {
                    case ParameterType.Texture:
                    case ParameterType.Texture1D:
                    case ParameterType.Texture2D:
                    case ParameterType.Texture3D:
                    case ParameterType.TextureCube:
                    {
                        OpsTexture container = context.GetTexture(constant.Value);

                        int sampler = constantTable.GetSamplerIndex(h);
                        context.Device.SetTexture(sampler, container.Texture);
                    }
                    break;
                    }
                    break;
                }

                case ParameterClass.Scalar:
                case ParameterClass.Vector:
                case ParameterClass.MatrixColumns:
                case ParameterClass.MatrixRows:
                {
                    ArrayList floatList    = new ArrayList();
                    string[]  floatStrings = constant.Value.Split(new char[] { ' ', ',' });
                    foreach (string floatStr in floatStrings)
                    {
                        if (floatStr.Length > 0)
                        {
                            floatList.Add(float.Parse(floatStr));
                        }
                    }
                    float[] floats = (float[])floatList.ToArray(typeof(float));

                    constantTable.SetValue(context.Device, h, floats);
                }
                break;
                }
            }

            return(constantTable);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        //IOpsCommand
        public void Run(OpsContext context, OpsStatement statement)
        {

            TexLoaderArgs texArgs = statement.Arguments as TexLoaderArgs;

            string[] paths = OpsHelpers.ResolvePathToMany( texArgs.Path as string );
            
            foreach(string path in paths )
            {
                OpsConsole.WriteLine("Loading texture from file: \"{0}\"", path );
                
                OpsTexture result = new OpsTexture();

                ImageInformation Info = TextureLoader.ImageInformationFromFile( path );
                result.SRGB = texArgs.SRGB;

                if( Info.ResourceType == ResourceType.Textures )
                {
                    result.Texture = TextureLoader.FromFile(context.Device, path);
                }
                else if( Info.ResourceType == ResourceType.VolumeTexture  )
                {
                    result.Texture = TextureLoader.FromVolumeFile(context.Device, path);
                }
                else if( Info.ResourceType == ResourceType.CubeTexture )
                {
                    result.Texture = TextureLoader.FromCubeFile(context.Device, path);
                }

                result.Name = System.IO.Path.GetFileNameWithoutExtension(path );

                context.AddTexture(result);
            }
        }
Exemplo n.º 14
0
        public void Run(OpsContext context, OpsStatement statement)
        {
            NewTex2dArgs args = statement.Arguments as NewTex2dArgs;

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

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

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

            context.AddTexture(result);
        }