コード例 #1
0
ファイル: newTexCube.cs プロジェクト: senny970/2007
        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);
            }
        }
コード例 #2
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();
        }
コード例 #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);

        }
コード例 #4
0
ファイル: shade.cs プロジェクト: senny970/2007
        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);
        }
コード例 #5
0
ファイル: shade.cs プロジェクト: steadyfield/SourceEngine2007
        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;
        }
コード例 #6
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();
        }