Пример #1
0
        protected override void UnloadHighLevelImpl()
        {
            if (IsSupported)
            {
                GL.DeleteShader(this.glShaderHandle);
                GLES2Config.GlCheckError(this);

                // TODO : Root.Instance.RenderSystem.Capabilities.HasCapability(Capabilities.SeperateShaderObjects))
                if (false)
                {
                    GL.DeleteProgram(this.glProgramHandle);
                    GLES2Config.GlCheckError(this);
                }
            }
        }
Пример #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);
                    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();
        }
Пример #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);
#if DEBUG
                    //Console.WriteLine ("GL2.0 error: " + log.ToString ());
#endif
                }

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

            UpdateWorldMatrixOrientation();
            GetUniformVariables();
        }