Exemple #1
0
        protected override void CompileAndLink()
        {
            //Compile and attach vertex program
            if (!vertexProgram.GLSLProgram.Compile(true))
            {
                triedToLinkAndFailed = true;
                return;
            }
            vertexProgram.GLSLProgram.AttachToProgramObject(glProgramHandle);
            SkeletalAnimationIncluded = vertexProgram.IsSkeletalAnimationIncluded;

            //Compile and attach fragment program
            if (!fragmentProgram.GLSLProgram.Compile(true))
            {
                triedToLinkAndFailed = true;
                return;
            }
            fragmentProgram.GLSLProgram.AttachToProgramObject(glProgramHandle);

            //The link
            GL.LinkProgram(glProgramHandle);
            GLES2Config.GlCheckError(this);
            GL.GetProgram(glProgramHandle, GLenum.LinkStatus, ref linked);
            GLES2Config.GlCheckError(this);

            triedToLinkAndFailed = (linked == 0) ? true : false;
        }
Exemple #2
0
        /// <summary>
        ///Initialize shaders and program on OpenGLES2.0
        /// </summary>
        private void InitGL20()
        {
            string vertexShaderSrc = @" uniform mat4 uMVPMatrix;
											attribute vec4 aPosition;
											attribute vec2 aTexCoord;
											attribute vec4 aTint;
											varying vec2 vTexCoord;
											varying vec4 vTint;
											void main()
											{
												vTexCoord = aTexCoord;
												vTint = aTint;
												gl_Position = uMVPMatrix * aPosition;
											}"                                            ;

            string fragmentShaderSrc = @"precision mediump float;
											varying vec2 vTexCoord;
											varying vec4 vTint;
											uniform sampler2D sTexture;
											void main()
											{
												vec4 baseColor = texture2D(sTexture, vTexCoord);
												gl_FragColor = baseColor * vTint;
											}"                                            ;

            int vertexShader   = LoadShader(ALL20.VertexShader, vertexShaderSrc);
            int fragmentShader = LoadShader(ALL20.FragmentShader, fragmentShaderSrc);

            program = GL20.CreateProgram();

            if (program == 0)
            {
                throw new InvalidOperationException("Unable to create program");
            }

            GL20.AttachShader(program, vertexShader);
            GL20.AttachShader(program, fragmentShader);

            //Set position
            GL20.BindAttribLocation(program, _batcher.attributePosition, "aPosition");
            GL20.BindAttribLocation(program, _batcher.attributeTexCoord, "aTexCoord");
            GL20.BindAttribLocation(program, _batcher.attributeTint, "aTint");

            GL20.LinkProgram(program);

            int linked = 0;

            GL20.GetProgram(program, ALL20.LinkStatus, ref linked);
            if (linked == 0)
            {
                // link failed
                int length = 0;
                GL20.GetProgram(program, ALL20.InfoLogLength, ref length);
                if (length > 0)
                {
                    var log = new StringBuilder(length);
                    GL20.GetProgramInfoLog(program, length, ref length, log);
#if DEBUG
                    //Console.WriteLine ("GL2.0 error: " + log.ToString ());
#endif
                }

                GL20.DeleteProgram(program);
                throw new InvalidOperationException("Unable to link program");
            }

            UpdateWorldMatrixOrientation();
            GetUniformVariables();
        }
Exemple #3
0
        /// <summary>
        ///Initialize shaders and program on OpenGLES2.0
        /// </summary>
        private void InitGL20()
        {
            string vertexShaderSrc = @"uniform mat4 uMVPMatrix;
                                                    attribute vec4 aPosition; 
                                                    attribute vec2 aTexCoord;
                                                    attribute vec4 aTint;
                                                    varying vec2 vTexCoord;
                                                    varying vec4 vTint;
                                                    void main()                  
                                                    {                         
                                                       vTexCoord = aTexCoord;
                                                       vTint = aTint;
                                                       gl_Position = uMVPMatrix * aPosition; 
                                                    }";


            string fragmentShaderSrc = @"precision mediump float;

                                         varying vec2 vTexCoord;
										 varying vec4 vTint;
                                         uniform sampler2D sTexture;
                                           void main()                                
                                           {                                         
                                             vec4 baseColor = texture2D(sTexture, vTexCoord);
											 gl_FragColor = baseColor * vTint;

                                           }";

            int vertexShader   = LoadShader(All20.VertexShader, vertexShaderSrc);
            int fragmentShader = LoadShader(All20.FragmentShader, fragmentShaderSrc);

            program = GL20.CreateProgram();
            if (program == 0)
            {
                throw new InvalidOperationException("Unable to create program");
            }

            GL20.AttachShader(program, vertexShader);
            GL20.AttachShader(program, fragmentShader);

            //Set position
            GL20.BindAttribLocation(program, _batcher.attributePosition, "aPosition");
            GL20.BindAttribLocation(program, _batcher.attributeTexCoord, "aTexCoord");
            GL20.BindAttribLocation(program, _batcher.attributeTint, "aTint");

            GL20.LinkProgram(program);

            int linked = 0;

            GL20.GetProgram(program, All20.LinkStatus, ref linked);
            if (linked == 0)
            {
                // link failed
                int length = 0;
                GL20.GetProgram(program, All20.InfoLogLength, ref length);
                if (length > 0)
                {
                    var log = new StringBuilder(length);
                    GL20.GetProgramInfoLog(program, length, ref length, log);
                    Console.WriteLine("GL2" + log.ToString());
                }

                GL20.DeleteProgram(program);
                throw new InvalidOperationException("Unable to link program");
            }


            matWorld      = Matrix4.Identity;
            matViewScreen = Matrix4.CreateRotationZ((float)Math.PI) *
                            Matrix4.CreateRotationY((float)Math.PI) *
                            Matrix4.CreateTranslation(-this.graphicsDevice.Viewport.Width / 2,
                                                      this.graphicsDevice.Viewport.Height / 2,
                                                      1);
            matViewFramebuffer = Matrix4.CreateTranslation(-this.graphicsDevice.Viewport.Width / 2,
                                                           -this.graphicsDevice.Viewport.Height / 2,
                                                           1);
            matProjection = Matrix4.CreateOrthographic(this.graphicsDevice.Viewport.Width,
                                                       this.graphicsDevice.Viewport.Height,
                                                       -1f, 1f);

            matWVPScreen      = matWorld * matViewScreen * matProjection;
            matWVPFramebuffer = matWorld * matViewFramebuffer * matProjection;

            GetUniformVariables();
        }
Exemple #4
0
        protected override void CompileAndLink()
        {
            int linkStatus = 0;

            //Compile and attach vertex program
            if (vertexProgram != null && !vertexProgram.IsLinked)
            {
                if (!vertexProgram.GLSLProgram.Compile())
                {
                    triedToLinkAndFailed = true;
                    return;
                }

                int programHandle = vertexProgram.GLSLProgram.GLProgramHandle;
                //GL.ProgramParameter(programHandle, GLenum.LinkStatus, ref linkStatus);
                vertexProgram.GLSLProgram.AttachToProgramObject(programHandle);
                GL.LinkProgram(programHandle);
                GLES2Config.GlCheckError(this);
                GL.GetProgram(programHandle, GLenum.LinkStatus, ref linkStatus);
                GLES2Config.GlCheckError(this);

                if (linkStatus != 0)
                {
                    vertexProgram.IsLinked = true;
                    linked |= (int)Linked.VertexProgram;
                }
                bool bLinkStatus = (linkStatus != 0);
                triedToLinkAndFailed = !bLinkStatus;

                SkeletalAnimationIncluded = vertexProgram.IsSkeletalAnimationIncluded;
            }

            //Compile and attach Fragment program
            if (fragmentProgram != null && !fragmentProgram.IsLinked)
            {
                if (!fragmentProgram.GLSLProgram.Compile(true))
                {
                    triedToLinkAndFailed = true;
                    return;
                }

                int programHandle = fragmentProgram.GLSLProgram.GLProgramHandle;
                //GL.ProgramParameter(programHandle, GLenum.ProgramSeperableExt, true);
                fragmentProgram.GLSLProgram.AttachToProgramObject(programHandle);
                GL.LinkProgram(programHandle);
                GLES2Config.GlCheckError(this);
                GL.GetProgram(programHandle, GLenum.LinkStatus, ref linkStatus);
                GLES2Config.GlCheckError(this);

                if (linkStatus != 0)
                {
                    fragmentProgram.IsLinked = true;
                    linked |= (int)Linked.FragmentProgram;
                }
                triedToLinkAndFailed = !fragmentProgram.IsLinked;
            }

            if (linked != 0)
            {
            }
        }