Exemplo n.º 1
0
        internal static void Terminate(GraphicsContext graphics)
        {
            ShaderProgram shaderProgram = null;

            if (graphics != null)
            {
                shaderProgram = graphics.GetShaderProgram();
            }
            ShaderProgramManager.ShaderProgramUnit[] array = ShaderProgramManager.shaderPrograms;
            for (int i = 0; i < array.Length; i++)
            {
                ShaderProgramManager.ShaderProgramUnit shaderProgramUnit = array[i];
                if (shaderProgramUnit != null)
                {
                    if (shaderProgramUnit.ShaderProgram == shaderProgram)
                    {
                        graphics.SetShaderProgram(null);
                    }
                    shaderProgramUnit.ShaderProgram.Dispose();
                }
            }
        }
Exemplo n.º 2
0
        protected internal override void Render()
        {
            if (!this.isExistRenderedVertex())
            {
                return;
            }
            GraphicsContext graphicsContext = UISystem.GraphicsContext;

            ShaderProgramManager.ShaderProgramUnit shaderProgramUnit = ShaderProgramManager.GetShaderProgramUnit(base.InternalShaderType);
            graphicsContext.SetShaderProgram(shaderProgramUnit.ShaderProgram);
            Texture2D texture = base.GetTexture();

            graphicsContext.SetTexture(0, texture);
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            for (int i = 0; i < this.vertexCount; i++)
            {
                UIPrimitiveVertex uIPrimitiveVertex = this.vertices[i];
                flag  |= uIPrimitiveVertex.NeedUpdatePosition;
                flag2 |= uIPrimitiveVertex.NeedUpdateColor;
                flag3 |= uIPrimitiveVertex.NeedUpdateTexcoord;
                uIPrimitiveVertex.NeedUpdatePosition = false;
                uIPrimitiveVertex.NeedUpdateColor    = false;
                uIPrimitiveVertex.NeedUpdateTexcoord = false;
            }
            if (this.needUpdateVertexAll || flag)
            {
                float[] array = new float[this.VertexCount * 3];
                int     num   = 0;
                for (int j = 0; j < this.VertexCount; j++)
                {
                    UIPrimitiveVertex uIPrimitiveVertex2 = this.vertices[j];
                    array[num++] = uIPrimitiveVertex2.X;
                    array[num++] = uIPrimitiveVertex2.Y;
                    array[num++] = uIPrimitiveVertex2.Z;
                }
                this.vertexBuffer.SetVertices(0, array, 0, 0, this.VertexCount);
            }
            if (this.needUpdateVertexAll || flag)
            {
                float[] array2 = new float[this.VertexCount * 4];
                int     num2   = 0;
                for (int k = 0; k < this.VertexCount; k++)
                {
                    UIPrimitiveVertex uIPrimitiveVertex3 = this.vertices[k];
                    array2[num2++] = uIPrimitiveVertex3.Color.R;
                    array2[num2++] = uIPrimitiveVertex3.Color.G;
                    array2[num2++] = uIPrimitiveVertex3.Color.B;
                    array2[num2++] = uIPrimitiveVertex3.Color.A;
                }
                this.vertexBuffer.SetVertices(1, array2, 0, 0, this.VertexCount);
            }
            if (texture != null)
            {
                if (this.needUpdateVertexAll || flag3)
                {
                    float[] array3 = new float[this.VertexCount * 2];
                    int     num3   = 0;
                    for (int l = 0; l < this.VertexCount; l++)
                    {
                        UIPrimitiveVertex uIPrimitiveVertex4 = this.vertices[l];
                        array3[num3++] = uIPrimitiveVertex4.U;
                        array3[num3++] = uIPrimitiveVertex4.V;
                    }
                    this.vertexBuffer.SetVertices(2, array3, 0, 0, this.VertexCount);
                }
            }
            else if ((this.needUpdateVertexAll || flag3) && this.vertexCount > 0)
            {
                this.vertices[0].NeedUpdateTexcoord = true;
            }
            if (this.needUpdateIndices)
            {
                if (this.indexCount > 0)
                {
                    this.vertexBuffer.SetIndices(this.indices, 0, 0, this.indexCount);
                }
                this.needUpdateIndices = false;
            }
            this.needUpdateVertexAll = false;
            graphicsContext.SetVertexBuffer(0, this.vertexBuffer);
            this.updateLocalToWorld();
            Matrix4 matrix;

            UISystem.viewProjectionMatrix.Multiply(ref this.localToWorld, out matrix);
            shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.UniformIndexOfModelViewProjection, ref matrix);
            shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.UniformIndexOfAlpha, this.finalAlpha);
            using (List <string> .Enumerator enumerator = shaderProgramUnit.OtherUniformNames.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    if (base.ShaderUniforms.ContainsKey(current))
                    {
                        shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.Uniforms[current], base.ShaderUniforms[current]);
                    }
                }
            }
            int num4 = (this.indexCount > 0) ? this.indexCount : this.VertexCount;

            graphicsContext.DrawArrays(this.DrawMode, 0, num4);
        }
Exemplo n.º 3
0
        protected internal override void Render()
        {
            if (!this.isExistRenderedUnit())
            {
                return;
            }

//			if (__USE_SampleDraw)
//			{
//				Sample.SampleDraw.DrawText("UISprite test", 0xffffffff, 0, 100); //FIXME:
//			}

            GraphicsContext graphicsContext = UISystem.GraphicsContext;

            ShaderProgramManager.ShaderProgramUnit shaderProgramUnit = ShaderProgramManager.GetShaderProgramUnit(base.InternalShaderType);
            graphicsContext.SetShaderProgram(shaderProgramUnit.ShaderProgram);
            Texture2D texture = base.GetTexture();

            if (__USE_SampleDraw)
            {
                texture = Sample.SampleDraw.__DrawText("1234 test", 0xffffffff, 0, 0, new Matrix4(), true);
            }
            graphicsContext.SetTexture(0, texture);
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            for (int i = 0; i < this.unitCount; i++)
            {
                UISpriteUnit uISpriteUnit = this.units[i];
                flag  |= uISpriteUnit.NeedUpdatePosition;
                flag2 |= uISpriteUnit.NeedUpdateColor;
                flag3 |= uISpriteUnit.NeedUpdateTexcoord;
                uISpriteUnit.NeedUpdatePosition = false;
                uISpriteUnit.NeedUpdateColor    = false;
                uISpriteUnit.NeedUpdateTexcoord = false;
            }
            if (this.needUpdateVertexAll | flag)
            {
                float[] array = new float[12 * this.UnitCount];
                int     num   = 0;
                for (int j = 0; j < this.unitCount; j++)
                {
                    UISpriteUnit unit = this.GetUnit(j);
                    array[num++] = unit.X;
                    array[num++] = unit.Y;
                    array[num++] = unit.Z;

                    array[num++] = unit.X;
                    array[num++] = unit.Y + unit.Height;
                    array[num++] = unit.Z;

                    array[num++] = unit.X + unit.Width;
                    array[num++] = unit.Y;
                    array[num++] = unit.Z;

                    array[num++] = unit.X + unit.Width;
                    array[num++] = unit.Y + unit.Height;
                    array[num++] = unit.Z;
                }
                this.vertexBuffer.SetVertices(0, array, 0, 0, 4 * this.UnitCount);                 //len==???  //>attrib['a_Position'].location == 0
            }
            if (this.needUpdateVertexAll | flag2)
            {
                UIColor[] array2 = new UIColor[4 * this.UnitCount];
                int       num2   = 0;
                for (int k = 0; k < this.unitCount; k++)
                {
                    UISpriteUnit uISpriteUnit2 = this.units[k];
                    array2[num2++] = uISpriteUnit2.Color;
                    array2[num2++] = uISpriteUnit2.Color;
                    array2[num2++] = uISpriteUnit2.Color;
                    array2[num2++] = uISpriteUnit2.Color;
                }
                this.vertexBuffer.SetVertices(1, array2, 0, 0, 4 * this.UnitCount);                 //len==4  //>attrib['a_Color'].location == 1
            }
            if (texture != null)
            {
                if (this.needUpdateVertexAll | flag3)
                {
                    float[] array3 = new float[8 * this.UnitCount];
                    int     num3   = 0;
                    for (int l = 0; l < this.unitCount; l++)
                    {
                        UISpriteUnit uISpriteUnit3 = this.units[l];
                        array3[num3++] = uISpriteUnit3.U1;
                        array3[num3++] = uISpriteUnit3.V1;
                        array3[num3++] = uISpriteUnit3.U1;
                        array3[num3++] = uISpriteUnit3.V2;
                        array3[num3++] = uISpriteUnit3.U2;
                        array3[num3++] = uISpriteUnit3.V1;
                        array3[num3++] = uISpriteUnit3.U2;
                        array3[num3++] = uISpriteUnit3.V2;
                    }
                    this.vertexBuffer.SetVertices(2, array3, 0, 0, 4 * this.UnitCount);
                }
            }
            else if ((this.needUpdateVertexAll || flag3) && this.unitCount > 0)
            {
                this.units[0].NeedUpdateTexcoord = true;
            }
            if (this.needUpdateVertexAll)
            {
                ushort[] array4 = new ushort[this.UnitCount * 6 - 2];
                ushort   num4   = 0;
                int      num5   = 0;
                while (true)
                {
                    ushort[] arg_3E8_0 = array4;
                    int      expr_3DB  = num5++;
                    ushort   expr_3E2  = num4;
                    num4 = (ushort)(expr_3E2 + 1);
                    arg_3E8_0[expr_3DB] = expr_3E2;
                    ushort[] arg_3FA_0 = array4;
                    int      expr_3ED  = num5++;
                    ushort   expr_3F4  = num4;
                    num4 = (ushort)(expr_3F4 + 1);
                    arg_3FA_0[expr_3ED] = expr_3F4;
                    ushort[] arg_40C_0 = array4;
                    int      expr_3FF  = num5++;
                    ushort   expr_406  = num4;
                    num4 = (ushort)(expr_406 + 1);
                    arg_40C_0[expr_3FF] = expr_406;
                    array4[num5++]      = num4;
                    if (num5 >= array4.Length)
                    {
                        break;
                    }
                    ushort[] arg_432_0 = array4;
                    int      expr_425  = num5++;
                    ushort   expr_42C  = num4;
                    num4 = (ushort)(expr_42C + 1);
                    arg_432_0[expr_425] = expr_42C;
                    array4[num5++]      = num4;
                }
                this.vertexBuffer.SetIndices(array4, 0, 0, array4.Length);
            }
            this.needUpdateVertexAll = false;
            graphicsContext.SetVertexBuffer(0, this.vertexBuffer);
            this.updateLocalToWorld();
            Matrix4 matrix;

            UISystem.viewProjectionMatrix.Multiply(ref this.localToWorld, out matrix);
            shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.UniformIndexOfModelViewProjection, ref matrix);
            shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.UniformIndexOfAlpha, this.finalAlpha);
//			Debug.WriteLine(">>>>>>><<<<<<<<<>>>>>>> base.ShaderUniforms.Count : " + base.ShaderUniforms.Count);
            using (List <string> .Enumerator enumerator = shaderProgramUnit.OtherUniformNames.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    if (base.ShaderUniforms.ContainsKey(current))
                    {
                        shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.Uniforms[current], base.ShaderUniforms[current]);
                    }
                }
            }


//			if (false)
//			{
//			    graphicsContext.Enable(EnableMode.Blend);
//			    graphicsContext.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha);
//			}

            graphicsContext.DrawArrays((DrawMode)4, 0, this.UnitCount * 6 - 2);
//			Debug.WriteLine(">>>>>>>>>>>>>>" + (this.UnitCount * 6 - 2));

//			if (__USE_SampleDraw)
//			{
//				Sample.SampleDraw.__DrawText("UISprite test", 0xffffffff, 0, 0, matrix, false); //FIXME:
//			}
        }
Exemplo n.º 4
0
        private static void loadShaderProgramUnit(int index)
        {
            ShaderProgramManager.ShaderProgramUnit shaderProgramUnit = new ShaderProgramManager.ShaderProgramUnit();
#if false
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            byte[]   array             = null;
            byte[]   array2            = null;
            using (Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(ShaderProgramManager.shaderFileNamePrifix + ShaderProgramManager.shaderFileName[index, 0]))
            {
                if (manifestResourceStream == null)
                {
                    throw new FileNotFoundException("Shader file not found.", ShaderProgramManager.shaderFileName[index, 0]);
                }
                array = new byte[manifestResourceStream.Length];
                manifestResourceStream.Read(array, 0, array.Length);
            }
            using (Stream manifestResourceStream2 = executingAssembly.GetManifestResourceStream(ShaderProgramManager.shaderFileNamePrifix + ShaderProgramManager.shaderFileName[index, 1]))
            {
                if (manifestResourceStream2 == null)
                {
                    throw new FileNotFoundException("Shader file not found.", ShaderProgramManager.shaderFileName[index, 1]);
                }
                array2 = new byte[manifestResourceStream2.Length];
                manifestResourceStream2.Read(array2, 0, array2.Length);
            }
            shaderProgramUnit.ShaderProgram = new ShaderProgram(array, array2);
#else
            Debug.WriteLine("shaderFileNamePrifix == " + shaderFileNamePrifix);
            shaderProgramUnit.ShaderProgram = new ShaderProgram(
                "/Application/Sce.Pss.HighLevel/UI/shaders/" + ShaderProgramManager.shaderFileName[index, 0],
                "/Application/Sce.Pss.HighLevel/UI/shaders/" + ShaderProgramManager.shaderFileName[index, 1]);
#endif
            shaderProgramUnit.ShaderProgram.SetAttributeBinding(0, "a_Position");
            shaderProgramUnit.AttributeIndexOfPosition = 0;
            shaderProgramUnit.ShaderProgram.SetAttributeBinding(1, "a_Color");
            shaderProgramUnit.AttributeIndexOfColor = 1;
//			int testIndex = shaderProgramUnit.ShaderProgram.FindAttribute("a_Position");
//			Debug.WriteLine(">>>>>>testIndex == " + testIndex);
            if (shaderProgramUnit.ShaderProgram.FindAttribute("a_TexCoord") >= 0)
            {
                shaderProgramUnit.ShaderProgram.SetAttributeBinding(2, "a_TexCoord");
                shaderProgramUnit.AttributeIndexOfTexcoord = 2;
            }
//			else
//			{
//				//FIXME:
//				Debug.Assert(false);//???
//			}
            int uniformCount = shaderProgramUnit.ShaderProgram.UniformCount;
            shaderProgramUnit.Uniforms          = new Dictionary <string, int>(uniformCount);
            shaderProgramUnit.OtherUniformNames = new List <string>(Math.Min(uniformCount - 2, 0));
            for (int i = 0; i < shaderProgramUnit.ShaderProgram.UniformCount; i++)
            {
                string uniformName = shaderProgramUnit.ShaderProgram.GetUniformName(i);
                //Debug.WriteLine(">>>>>>>>>uuu>>>>>>>>>uniformName:" + uniformName);
                if (!shaderProgramUnit.Uniforms.ContainsKey(uniformName))
                {
                    shaderProgramUnit.Uniforms.Add(uniformName, i);
                    if (uniformName == "u_WorldMatrix")
                    {
                        shaderProgramUnit.UniformIndexOfModelViewProjection = i;
                    }
                    else if (uniformName == "u_Alpha")
                    {
                        shaderProgramUnit.UniformIndexOfAlpha = i;
                    }
                    else if (uniformName != "s_Texture" && uniformName != "Texture0")                      //FIXME:
                    {
                        shaderProgramUnit.OtherUniformNames.Add(uniformName);
                    }
                }
            }
            ShaderProgramManager.shaderPrograms[index] = shaderProgramUnit;
        }