Axiom.RenderSystems.OpenGL.GLSL.GLSLProgram.Compile C# (CSharp) Method

Compile() private method

private Compile ( bool checkErrors = true ) : bool
checkErrors bool
return bool
		protected internal bool Compile( bool checkErrors = true )
		{
            if (isCompiled)
            {
                return true;
            }

            if (checkErrors)
            {
                GLSLHelper.LogObjectInfo( "GLSL compiling: " + Name, GLHandle );
            }

            if (IsSupported)
            {
                GLSLHelper.CheckForGLSLError("GL Errors before creating shader object", 0);
                var shaderType = 0;
                switch ( Type )
                {
                    case GpuProgramType.Vertex:
                        shaderType = Gl.GL_VERTEX_SHADER_ARB;
                        break;
                    case GpuProgramType.Fragment:
                        shaderType = Gl.GL_FRAGMENT_SHADER_ARB;
                        break;
                    case GpuProgramType.Geometry:
                        shaderType = Gl.GL_GEOMETRY_SHADER_EXT;
                        break;
                }
                GLHandle = Gl.glCreateShaderObjectARB(shaderType);

                GLSLHelper.CheckForGLSLError("Error creating GLSL shader object", 0);
            }

            // Preprocess the GLSL shader in order to get a clean source
            // CPreprocessor cpp;
            // TODO: preprocessor not supported yet in axiom

            // Add preprocessor extras and main source

            if (!string.IsNullOrEmpty(source))
            {
                Gl.glShaderSourceARB(GLHandle, 1, new []{ source }, new []{ source.Length });
                // check for load errors
                GLSLHelper.CheckForGLSLError("Cannot load GLSL high-level shader source : " + Name, 0);
            }

		    Gl.glCompileShaderARB(GLHandle);
			int compiled;
			// check for compile errors
            Gl.glGetObjectParameterivARB(GLHandle, Gl.GL_OBJECT_COMPILE_STATUS_ARB, out compiled);

			isCompiled = ( compiled != 0 );

			// force exception if not compiled
			if ( checkErrors )
			{
                GLSLHelper.CheckForGLSLError("GLSL : Cannot compile GLSL high-level shader: " + Name + ".", GLHandle, !isCompiled, !isCompiled);

				if ( isCompiled )
				{
                    GLSLHelper.LogObjectInfo("GLSL : " + Name + " : compiled.", GLHandle);
				}
			}

			return isCompiled;
		}

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="programObject"></param>
        public void AttachToProgramObject(int programObject)
        {
            Gl.glAttachObjectARB(programObject, glHandle);
            GLSLHelper.CheckForGLSLError("Error attaching " + this.name + " shader object to GLSL Program Object.", programObject);

            // atach child objects
            for (int i = 0; i < attachedGLSLPrograms.Count; i++)
            {
                GLSLProgram childShader = (GLSLProgram)attachedGLSLPrograms[i];

                // bug in ATI GLSL linker : modules without main function must be recompiled each time
                // they are linked to a different program object
                // don't check for compile errors since there won't be any
                // *** minor inconvenience until ATI fixes there driver
                childShader.Compile(false);
                childShader.AttachToProgramObject(programObject);
            }
        }