Пример #1
0
            /// <summary>
            /// Create a shader object from this Object.
            /// </summary>
            /// <returns></returns>
            public ShaderObject Create()
            {
                ShaderObject shaderObject = new ShaderObject(Stage);

                // Load source
                shaderObject.LoadSource(Path);

                return(shaderObject);
            }
Пример #2
0
            /// <summary>
            /// Create a program from this Program.
            /// </summary>
            /// <param name="cctx"></param>
            /// <returns></returns>
            public ShaderProgram Create(ShaderCompilerContext cctx)
            {
                if (String.IsNullOrEmpty(Id))
                {
                    throw new InvalidOperationException("invalid program identifier");
                }
                if (cctx == null)
                {
                    throw new ArgumentNullException("cctx");
                }

                ShaderProgram shaderProgram = new ShaderProgram(Id);

                // Attach required objects
                foreach (Object shaderProgramObject in Objects)
                {
                    ShaderObject shaderObject = new ShaderObject(shaderProgramObject.Stage);

                    // Load source
                    shaderObject.LoadSource(shaderProgramObject.Path);
                    // Attach object
                    shaderProgram.AttachShader(shaderObject);
                }

                // Register attributes semantic
                foreach (Attribute attribute in Attributes)
                {
                    shaderProgram.SetAttributeSemantic(attribute.Name, attribute.Semantic);
                    if (attribute.Location >= 0)
                    {
                        shaderProgram.SetAttributeLocation(attribute.Name, attribute.Location);
                    }
                }

                // Register uniforms semantic
                foreach (Uniform uniform in Uniforms)
                {
                    shaderProgram.SetUniformSemantic(uniform.Name, uniform.Semantic);
                }

                shaderProgram.Create(cctx);

                return(shaderProgram);
            }
Пример #3
0
        /// <summary>
        /// Actually create this ShaderObject resources.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for allocating resources.
        /// </param>
        protected override void CreateObject(GraphicsContext ctx)
        {
            CheckCurrentContext(ctx);

            if (ctx.Extensions.ShadingLanguageInclude_ARB)
            {
                List <string> source = ShaderObject.CleanSource(Source);

                // Build include source string
                StringBuilder sb = new StringBuilder();
                foreach (string line in Source)
                {
                    sb.Append(line);
                }

                // Create shader include
                Gl.NamedStringARB(Gl.SHADER_INCLUDE_ARB, -1, IncludePath, -1, sb.ToString());
            }
        }
Пример #4
0
 /// <summary>
 /// Load the shader source from an embedded resource
 /// </summary>
 /// <param name="resourcePath">
 /// A <see cref="String"/> that specify the embedded resource path.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Exception thrown if <paramref name="resourcePath"/> is null.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// Exception thrown if no embedded resource can be found.
 /// </exception>
 public void LoadSource(string resourcePath)
 {
     _SourceStrings = ShaderObject.LoadSourceLines(resourcePath);
 }
Пример #5
0
 /// <summary>
 /// Load the shader source from a stream.
 /// </summary>
 /// <param name="sourceStream">
 /// A <see cref="Stream"/>that holds the source lines.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Exception thrown in the case <paramref name="sourceStream"/> is null.
 /// </exception>
 public void LoadSource(Stream sourceStream)
 {
     _SourceStrings = ShaderObject.LoadSourceLines(sourceStream);
 }