Пример #1
0
        public static Shader Create(ShaderType type, uint id)
        {
            Shader result = null;

            switch (type)
            {
            case ShaderType.VertexShader: result = new VertexShader(id); break;

            case ShaderType.TessControlShader: result = new TessControlShader(id); break;

            case ShaderType.TessEvaluationShader: result = new TessEvaluationShader(id); break;

            case ShaderType.GeometryShader: result = new GeometryShader(id); break;

            case ShaderType.FragmentShader: result = new FragmentShader(id); break;

            case ShaderType.ComputeShader: result = new ComputeShader(id); break;

            default:
                throw new NotImplementedException();
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// find the vertex shader and other shaders.
        /// </summary>
        /// <returns></returns>
        private bool FindTypedShaders()
        {
            bool result = true;

            VertexShader         vertexShader         = null;
            TessControlShader    tessControlShader    = null;
            TessEvaluationShader tessEvaluationShader = null;
            GeometryShader       geometryShader       = null;
            FragmentShader       fragmentShader       = null;
            ComputeShader        computeShader        = null;

            foreach (var item in this.attachedShaders)
            {
                if (item.InfoLog != string.Empty)
                {
                    this.logInfo = "Shader Compiling Error!"; result = false; break;
                }

                switch (item.ShaderType)
                {
                case ShaderType.VertexShader:
                    if (vertexShader != null)
                    {
                        this.logInfo = "Multiple VertexShader!"; result = false; break;
                    }
                    else
                    {
                        vertexShader = item as VertexShader;
                    }
                    break;

                case ShaderType.TessControlShader:
                    if (tessControlShader != null)
                    {
                        this.logInfo = "Multiple TessControlShader!"; result = false; break;
                    }
                    else
                    {
                        tessControlShader = item as TessControlShader;
                    }
                    break;

                case ShaderType.TessEvaluationShader:
                    if (tessEvaluationShader != null)
                    {
                        this.logInfo = "Multiple TessEvaluationShader!"; result = false; break;
                    }
                    else
                    {
                        tessEvaluationShader = item as TessEvaluationShader;
                    }
                    break;

                case ShaderType.GeometryShader:
                    if (geometryShader != null)
                    {
                        this.logInfo = "Multiple GeometryShader!"; result = false; break;
                    }
                    else
                    {
                        geometryShader = item as GeometryShader;
                    }
                    break;

                case ShaderType.FragmentShader:
                    if (fragmentShader != null)
                    {
                        this.logInfo = "Multiple FragmentShader!"; result = false; break;
                    }
                    else
                    {
                        fragmentShader = item as FragmentShader;
                    }
                    break;

                case ShaderType.ComputeShader:
                    if (computeShader != null)
                    {
                        this.logInfo = "Multiple ComputeShader!"; result = false; break;
                    }
                    else
                    {
                        computeShader = item as ComputeShader;
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            if (vertexShader == null)
            {
                this.logInfo = "No VertexShader found!"; result = false; return(result);
            }

            {
                // TODO: support other shaders.
                this.VertexShader = vertexShader;
                //this.tessControlShader = tessControlShader;
                //this.tessEvaluationShader = tessEvaluationShader;
                //this.geometryShader = geometryShader;
                this.FragmentShader = fragmentShader;
                //this.computeShader = computeShader;
            }

            return(result);
        }