예제 #1
0
 public static VertexReaderDelegate GenerateMethod(VertexTypeStruct VertexType)
 {
     return SafeILGenerator.Generate<VertexReaderDelegate>("VertexReaderDynarec.GenerateMethod", (Generator) =>
     {
         var VertexReaderDynarec = new VertexReaderDynarec(Generator, VertexType);
         VertexReaderDynarec.GenerateCode();
     }, CheckTypes: false);
 }
예제 #2
0
 protected VertexReaderDynarec(SafeILGenerator SafeILGenerator, VertexTypeStruct VertexType)
 {
     this.Offset = 0;
     this.SafeILGenerator = SafeILGenerator;
     this.VertexType = VertexType;
     this.VertexDataArgument = SafeILGenerator.DeclareArgument(typeof(void*), 0);
     this.VertexInfoArgument = SafeILGenerator.DeclareArgument(typeof(VertexInfo*), 0);
     this.IndexArgument = SafeILGenerator.DeclareArgument(typeof(int), 0);
     this.CountArgument = SafeILGenerator.DeclareArgument(typeof(int), 0);
     this.LocalColor = SafeILGenerator.DeclareLocal<uint>("LocalColor", false);
 }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="GpuState"></param>
        private unsafe void _Prim(GpuStateStruct* GpuState, GuPrimitiveType PrimitiveType, ushort VertexCount)
        {
            //if (PrimitiveType == GuPrimitiveType.TriangleStrip) VertexCount++;

            //Console.WriteLine("Prim: {0}, {1}", PrimitiveType, VertexCount);
            this.GpuState = GpuState;

            //Console.WriteLine("--------------------------------------------------------");
            VertexType = GpuState->VertexState.Type;

            ReadVertexDelegate ReadVertex = ReadVertex_Void;
            VertexReader.SetVertexTypeStruct(
                VertexType,
                (byte*)Memory.PspAddressToPointerSafe(GpuState->GetAddressRelativeToBaseOffset(GpuState->VertexAddress), 0)
            );

            #if DEBUG_VERTEX_TYPE
            try
            {
                if (!File.Exists("VertexType_" + VertexType.Value))
                {
                    File.WriteAllBytes(
                        "VertexType_" + VertexType.Value,
                        PointerUtils.PointerToByteArray((byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress), 16 * 1024)
                    );
                    File.WriteAllText(
                        "VertexType_" + VertexType.Value + "_str",
                        VertexCount + "," + PrimitiveType + "\n" +
                        VertexType.ToString()
                    );
                    OutputVertexInfoStream = File.OpenWrite("VertexType_" + VertexType.Value + "_list");
                }
            }
            catch
            {
            }
            #endif
            //IndexReader.SetVertexTypeStruct(VertexType, VertexCount, (byte*)Memory.PspAddressToPointerSafe(GpuState->IndexAddress));

            uint TotalVerticesWithoutMorphing = VertexCount;

            //Console.Error.WriteLine("GpuState->IndexAddress: {0:X}", GpuState->IndexAddress);

            // Invalid
            /*
            if (GpuState->IndexAddress == 0xFFFFFFFF)
            {
                //Debug.Fail("Invalid IndexAddress");
                throw (new Exception("Invalid IndexAddress == 0xFFFFFFFF"));
            }
            */

            void* IndexPointer = null;
            if (VertexType.Index != VertexTypeStruct.IndexEnum.Void)
            {
                IndexPointer = Memory.PspAddressToPointerSafe(GpuState->GetAddressRelativeToBaseOffset(GpuState->IndexAddress), 0);
            }

            //Console.Error.WriteLine(VertexType.Index);
            switch (VertexType.Index)
            {
                case VertexTypeStruct.IndexEnum.Void:
                    break;
                case VertexTypeStruct.IndexEnum.Byte:
                    ReadVertex = ReadVertex_Byte;
                    IndexListByte = (byte *)IndexPointer;
                    TotalVerticesWithoutMorphing = 0;
                    for (int n = 0; n < VertexCount; n++)
                    {
                        if (TotalVerticesWithoutMorphing < IndexListByte[n]) TotalVerticesWithoutMorphing = IndexListByte[n];
                    }
                    break;
                case VertexTypeStruct.IndexEnum.Short:
                    ReadVertex = ReadVertex_Short;
                    IndexListShort = (ushort*)IndexPointer;
                    TotalVerticesWithoutMorphing = 0;
                    //VertexCount--;
                    for (int n = 0; n < VertexCount; n++)
                    {
                        //Console.Error.WriteLine(IndexListShort[n]);
                        if (TotalVerticesWithoutMorphing < IndexListShort[n]) TotalVerticesWithoutMorphing = IndexListShort[n];
                    }
                    break;
                default:
                    throw (new NotImplementedException());
            }
            TotalVerticesWithoutMorphing++;

            //Console.WriteLine(TotalVerticesWithoutMorphing);

            int MorpingVertexCount = (int)VertexType.MorphingVertexCount + 1;
            int z = 0;
            VertexInfo TempVertexInfo;

            float* Morphs = &GpuState->MorphingState.MorphWeight0;

            //for (int n = 0; n < MorpingVertexCount; n++) Console.Write("{0}, ", Morphs[n]); Console.WriteLine("");

            //int VertexInfoFloatCount = (sizeof(Color4F) + sizeof(Vector3F) * 3) / sizeof(float);
            int VertexInfoFloatCount = (sizeof(VertexInfo)) / sizeof(float);
            fixed (VertexInfo* VerticesPtr = Vertices)
            {
            #if true
                if (MorpingVertexCount == 1)
                {
                    VertexReader.ReadVertices(0, VerticesPtr, (int)TotalVerticesWithoutMorphing);
                }
                else
                {
                    var ComponentsIn = (float*)&TempVertexInfo;
                    for (int n = 0; n < TotalVerticesWithoutMorphing; n++)
                    {
                        var ComponentsOut = (float*)&VerticesPtr[n];
                        for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] = 0;
                        for (int m = 0; m < MorpingVertexCount; m++)
                        {
                            VertexReader.ReadVertex(z++, &TempVertexInfo);
                            for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] += ComponentsIn[cc] * Morphs[m];
                        }
                        VerticesPtr[n].Normal = VerticesPtr[n].Normal.Normalize();
                    }
                }
            #else
                var ComponentsIn = (float*)&TempVertexInfo;
                for (int n = 0; n < TotalVerticesWithoutMorphing; n++)
                {
                    if (MorpingVertexCount == 1)
                    {
                        VertexReader.ReadVertex(z++, &TempVertexInfo);
                        VerticesPtr[n] = TempVertexInfo;
                        //VertexReader.ReadVertices(0, VerticesPtr, TotalVerticesWithoutMorphing);
                    }
                    else
                    {
                        var ComponentsOut = (float*)&VerticesPtr[n];
                        for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] = 0;
                        for (int m = 0; m < MorpingVertexCount; m++)
                        {
                            VertexReader.ReadVertex(z++, &TempVertexInfo);
                            for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] += ComponentsIn[cc] * Morphs[m];
                        }
                    }
                }
            #endif
            }

            //VertexType.Texture == VertexTypeStruct.TextureEnum.Byte
            //return;
            //PrepareRead(GpuState);

            PrepareStateCommon(GpuState);

            if (GpuState->ClearingMode)
            {
                PrepareStateClear(GpuState);
            }
            else
            {
                PrepareStateDraw(GpuState);
            }

            PrepareStateMatrix(GpuState);

            //GL.Enable(EnableCap.Blend);

            /*
            if (CurrentTexture != null)
            {
                if (CurrentTexture.TextureHash == 0x2202293873)
                {
                    Console.Error.WriteLine(CurrentTexture);
                    Console.Error.WriteLine(VertexCount);
                }
            }
            */

            _CaptureStartPrimitive(PrimitiveType, GpuState->GetAddressRelativeToBaseOffset(GpuState->VertexAddress), VertexCount, ref VertexType);

            // DRAW ACTUALLY
            {
                //uint VertexSize = GpuState->VertexState.Type.GetVertexSize();

                //byte* VertexPtr = (byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress);

                //Console.WriteLine(VertexSize);

                var BeginMode = default(BeginMode);

                switch (PrimitiveType)
                {
                    case GuPrimitiveType.Lines: BeginMode = BeginMode.Lines; break;
                    case GuPrimitiveType.LineStrip: BeginMode = BeginMode.LineStrip; break;
                    case GuPrimitiveType.Triangles: BeginMode = BeginMode.Triangles; break;
                    case GuPrimitiveType.Points: BeginMode = BeginMode.Points; break;
                    case GuPrimitiveType.TriangleFan: BeginMode = BeginMode.TriangleFan; break;
                    case GuPrimitiveType.TriangleStrip: BeginMode = BeginMode.TriangleStrip; break;
                    case GuPrimitiveType.Sprites: BeginMode = BeginMode.Quads; break;
                    default: throw (new NotImplementedException("Not implemented PrimitiveType:'" + PrimitiveType + "'"));
                }

                if (PrimitiveType == GuPrimitiveType.Sprites)
                {
                    GL.Disable(EnableCap.CullFace);
                }

                //Console.WriteLine(BeginMode);

                //lock (GpuLock)
                {
                    //Console.Error.WriteLine("GL.Begin : Thread : {0}", Thread.CurrentThread.ManagedThreadId);
                    GL.Begin(BeginMode);
                    {
                        if (PrimitiveType == GuPrimitiveType.Sprites)
                        {
                            GL.Disable(EnableCap.CullFace);
                            for (int n = 0; n < VertexCount; n += 2)
                            {
                                VertexInfo V1, V2, V3, V4;

                                ReadVertex(n + 0, &V1);
                                ReadVertex(n + 1, &V3);
                                {
                                    //if (GpuState->ClearingMode) Console.WriteLine("{0} - {1}", VertexInfoTopLeft, VertexInfoBottomRight);

                                    var Color = V3.Color;
                                    var TZ = V1.Texture.Z;
                                    var PZ = V1.Position.Z;
                                    var NZ = V1.Normal.Z;

                                    V2 = new VertexInfo()
                                    {
                                        Texture = new Vector3F(V3.Texture.X, V1.Texture.Y, TZ),
                                        Position = new Vector3F(V3.Position.X, V1.Position.Y, PZ),
                                        Normal = new Vector3F(V3.Normal.X, V1.Normal.Y, NZ),
                                    };

                                    V4 = new VertexInfo()
                                    {
                                        Texture = new Vector3F(V1.Texture.X, V3.Texture.Y, TZ),
                                        Position = new Vector3(V1.Position.X, V3.Position.Y, PZ),
                                        Normal = new Vector3F(V1.Normal.X, V3.Normal.Y, NZ),
                                    };

                                    V4.Color = V3.Color = V2.Color = V1.Color = Color;
                                    V4.Position.Z = V3.Position.Z = V2.Position.Z = V1.Position.Z = PZ;
                                    V4.Normal.Z = V3.Normal.Z = V2.Normal.Z = V1.Normal.Z = NZ;
                                    V4.Texture.Z = V3.Texture.Z = V2.Texture.Z = V1.Texture.Z = NZ;
                                }
                                PutVertex(ref V1, ref VertexType);
                                PutVertex(ref V2, ref VertexType);
                                PutVertex(ref V3, ref VertexType);
                                PutVertex(ref V4, ref VertexType);
                            }
                        }
                        else
                        {
                            VertexInfo VertexInfo;
                            //Console.Error.WriteLine("{0} : {1} : {2}", BeginMode, VertexCount, VertexType.Index);
                            for (int n = 0; n < VertexCount; n++)
                            {
                                ReadVertex(n, &VertexInfo);
                                PutVertex(ref VertexInfo, ref VertexType);
                            }
                        }
                    }
                    GL.End();
                }
            }

            _CaptureEndPrimitive();

            //Console.WriteLine(VertexCount);

            //PrepareWrite(GpuState);

            #if DEBUG_VERTEX_TYPE
            if (OutputVertexInfoStream != null)
            {
                OutputVertexInfoStream.Close();
                OutputVertexInfoStream = null;
            }
            #endif
        }
예제 #4
0
 private void Read_Type0(VertexTypeStruct.NumericEnum Type, string[] Fields, bool Signed = true)
 {
     if (Type == VertexTypeStruct.NumericEnum.Void) return;
     var Size = TypeSize(Type);
     _SaveFloatFields(Fields, () =>
     {
         switch (Type)
         {
             case VertexTypeStruct.NumericEnum.Byte:
             case VertexTypeStruct.NumericEnum.Short:
                 _LoadIntegerScaledIfNotTransform2D(Size: Size, Signed: Signed);
                 break;
             case VertexTypeStruct.NumericEnum.Float:
                 _LoadFloat();
                 break;
         }
     });
 }
예제 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="VertexInfo"></param>
        /// <param name="VertexType"></param>
        private void PutVertex(ref VertexInfo _VertexInfo, ref VertexTypeStruct VertexType)
        {
            VertexInfo VertexInfo = PerformSkinning(_VertexInfo);

            _CapturePutVertex(ref VertexInfo);

            //Console.WriteLine(VertexType);
            //Console.WriteLine(VertexInfo);
            /*
            if (GpuState->ClearingMode)
            {
                Console.WriteLine(VertexInfo);
            }
            */
            //Console.WriteLine(VertexInfo);

            //Console.WriteLine(VertexInfo);
            //Console.WriteLine(VertexInfo);

            #if DEBUG_VERTEX_TYPE
            if (OutputVertexInfoStream != null) OutputVertexInfoStream.WriteBytes(Encoding.UTF8.GetBytes(String.Format("{0}\n", VertexInfo)));
            #endif

            #if false
            GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            GL.Vertex3(VertexInfo.PX, VertexInfo.PY, 0.5f);
            #else

            if (VertexType.Color != VertexTypeStruct.ColorEnum.Void)
            {
                GL.Color4(VertexInfo.Color.R, VertexInfo.Color.G, VertexInfo.Color.B, VertexInfo.Color.A);
            }
            if (VertexType.Texture != VertexTypeStruct.NumericEnum.Void)
            {
                /*
                if (VertexType.Texture == VertexTypeStruct.NumericEnum.Short)
                {
                    var Texture = CurrentTexture;

                    Console.WriteLine(
                        "U={0}, V={1}, OFFSET({2}, {3}), SCALE({4}, {5}) : SIZE({6},{7}) : {8}",
                        VertexInfo.U, VertexInfo.V,
                        GpuState->TextureMappingState.TextureState.OffsetU, GpuState->TextureMappingState.TextureState.OffsetV,
                        GpuState->TextureMappingState.TextureState.ScaleU, GpuState->TextureMappingState.TextureState.ScaleV,
                        Texture.Width, Texture.Height,
                        GpuState->TextureMappingState.TextureState
                    );

                    //return;
                }
                */

                //Console.WriteLine("{0}, {1}", VertexInfo.U, VertexInfo.V);
                //GL.TexCoord2(VertexInfo.TX, VertexInfo.TY);
                GL.TexCoord3(VertexInfo.Texture.X, VertexInfo.Texture.Y, VertexInfo.Texture.Z);
            }
            //Console.Write(",{0}", VertexInfo.PZ);
            if (VertexType.Normal != VertexTypeStruct.NumericEnum.Void)
            {
            #if false
                if (VertexType.ReversedNormal)
                {
                    GL.Normal3(-VertexInfo.Normal.X, -VertexInfo.Normal.Y, -VertexInfo.Normal.Z);
                }
                else
            #endif
                {
                    GL.Normal3(VertexInfo.Normal.X, VertexInfo.Normal.Y, VertexInfo.Normal.Z);
                }
            }
            if (VertexType.Position != VertexTypeStruct.NumericEnum.Void)
            {
                GL.Vertex3(VertexInfo.Position.X, VertexInfo.Position.Y, VertexInfo.Position.Z);
            }
            #endif
        }
예제 #6
0
 private void _CaptureStartPrimitive(GuPrimitiveType PrimitiveType, uint VertexAddress, int VetexCount, ref VertexTypeStruct VertexType)
 {
     if (PspWavefrontObjWriter != null)
     {
         lock (PspWavefrontObjWriterLock)
         {
             if (PspWavefrontObjWriter != null) PspWavefrontObjWriter.StartPrimitive(GpuState, PrimitiveType, VertexAddress, VetexCount, ref VertexType);
         }
     }
 }
예제 #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="VertexInfo"></param>
        /// <param name="VertexType"></param>
        private void PutVertex(ref VertexInfo VertexInfo, ref VertexTypeStruct VertexType)
        {
            /*
            if (GpuState->ClearingMode)
            {
                Console.WriteLine(VertexInfo);
            }
            */
            //Console.WriteLine(VertexInfo);

            //Console.WriteLine(VertexInfo);
            //Console.WriteLine(VertexInfo);
            if (VertexType.Color != VertexTypeStruct.ColorEnum.Void)
            {
                GL.Color4((float)VertexInfo.R, (float)VertexInfo.G, (float)VertexInfo.B, (float)VertexInfo.A);
            }
            if (VertexType.Texture != VertexTypeStruct.NumericEnum.Void)
            {
                //Console.WriteLine("{0}, {1}", VertexInfo.U, VertexInfo.V);
                GL.TexCoord2(VertexInfo.U, VertexInfo.V);
            }
            if (VertexType.Normal != VertexTypeStruct.NumericEnum.Void)
            {
                GL.Normal3(VertexInfo.NX, VertexInfo.NY, VertexInfo.NZ);
            }
            if (VertexType.Position != VertexTypeStruct.NumericEnum.Void)
            {
                GL.Vertex3(VertexInfo.PX, VertexInfo.PY, VertexInfo.PZ);
            }
        }
예제 #8
0
		public override void Prim(GlobalGpuState GlobalGpuState, GpuStateStruct* GpuState, GuPrimitiveType PrimitiveType, ushort VertexCount)
		{
			VertexType = GpuState->VertexState.Type;
			var TextureState = &GpuState->TextureMappingState.TextureState;

			VertexReader.SetVertexTypeStruct(
				VertexType,
				(byte*)Memory.PspAddressToPointerSafe(GlobalGpuState.GetAddressRelativeToBaseOffset(GpuState->VertexAddress), 0)
			);

			// Set Matrices
			this.ShaderProgram.Use();

			PrepareStateCommon(GpuState);

			if (GpuState->ClearingMode)
			{
				PrepareStateClear(GpuState);
			}
			else
			{
				PrepareStateDraw(GpuState);
			}

			PrepareStateMatrix(GpuState);

			fixed (VertexInfo* VertexInfoBufferPtr = VertexInfoBuffer)
			{
				switch (PrimitiveType)
				{
					case GuPrimitiveType.Sprites:
						int m = 0;
						for (int n = 0; n < VertexCount; n += 2)
						{
							VertexInfo TopLeft, _TopRight, BottomRight, _BottomLeft;

							VertexReader.ReadVertex(n + 0, &TopLeft);
							VertexReader.ReadVertex(n + 1, &BottomRight);
							TopLeft.Color.W = 1.0f;
							BottomRight.Color.W = 1.0f;

							//Console.WriteLine("--------------");
							//Console.WriteLine("({0},{1}) ({2},{3})", TopLeft.Position.X, TopLeft.Position.Y, TopLeft.Texture.X, TopLeft.Texture.Y);
							//Console.WriteLine("({0},{1}) ({2},{3})", BottomRight.Position.X, BottomRight.Position.Y, BottomRight.Texture.X, BottomRight.Texture.Y);

							{
								//if (GpuState->ClearingMode) Console.WriteLine("{0} - {1}", VertexInfoTopLeft, VertexInfoBottomRight);

								var Color = BottomRight.Color;
								var TZ = TopLeft.Texture.Z;
								var PZ = TopLeft.Position.Z;
								var NZ = TopLeft.Normal.Z;

								_TopRight = new VertexInfo()
								{
									Texture = new Vector4f(BottomRight.Texture.X, TopLeft.Texture.Y, TZ, 0),
									Position = new Vector4f(BottomRight.Position.X, TopLeft.Position.Y, PZ, 0),
									Normal = new Vector4f(BottomRight.Normal.X, TopLeft.Normal.Y, NZ, 0),
								};

								_BottomLeft = new VertexInfo()
								{
									Texture = new Vector4f(TopLeft.Texture.X, BottomRight.Texture.Y, TZ, 0),
									Position = new Vector4f(TopLeft.Position.X, BottomRight.Position.Y, PZ, 0),
									Normal = new Vector4f(TopLeft.Normal.X, BottomRight.Normal.Y, NZ, 0),
								};

								_BottomLeft.Color = BottomRight.Color = _TopRight.Color = TopLeft.Color = Color;
								_BottomLeft.Position.Z = BottomRight.Position.Z = _TopRight.Position.Z = TopLeft.Position.Z = PZ;
								_BottomLeft.Normal.Z = BottomRight.Normal.Z = _TopRight.Normal.Z = TopLeft.Normal.Z = NZ;
								_BottomLeft.Texture.Z = BottomRight.Texture.Z = _TopRight.Texture.Z = TopLeft.Texture.Z = NZ;
							}

							//VertexInfoBufferPtr[m++] = _TopRight;
							//VertexInfoBufferPtr[m++] = BottomRight;
							//VertexInfoBufferPtr[m++] = TopLeft;
							//VertexInfoBufferPtr[m++] = _BottomLeft;

							VertexInfoBufferPtr[m++] = _TopRight;
							VertexInfoBufferPtr[m++] = TopLeft;
							VertexInfoBufferPtr[m++] = BottomRight;
							VertexInfoBufferPtr[m++] = _BottomLeft;

							//Console.WriteLine("-----");
							//Console.WriteLine("({0},{1}) ({2},{3})", _TopRight.Position.X, _TopRight.Position.Y, _TopRight.Texture.X, _TopRight.Texture.Y);
							//Console.WriteLine("({0},{1}) ({2},{3})", TopLeft.Position.X, TopLeft.Position.Y, TopLeft.Texture.X, TopLeft.Texture.Y);
							//Console.WriteLine("({0},{1}) ({2},{3})", BottomRight.Position.X, BottomRight.Position.Y, BottomRight.Texture.X, BottomRight.Texture.Y);
							//Console.WriteLine("({0},{1}) ({2},{3})", _BottomLeft.Position.X, _BottomLeft.Position.Y, _BottomLeft.Texture.X, _BottomLeft.Texture.Y);

							//VertexInfoBufferPtr[m++] = _BottomLeft;
							//VertexInfoBufferPtr[m++] = BottomRight;
							//VertexInfoBufferPtr[m++] = _TopRight;
							//VertexInfoBufferPtr[m++] = TopLeft;

							//VertexInfoBufferPtr[m++] = _BottomLeft;
							//VertexInfoBufferPtr[m++] = TopLeft;
							//VertexInfoBufferPtr[m++] = BottomRight;
							//VertexInfoBufferPtr[m++] = _TopRight;

							//VertexInfoBufferPtr[m++] = _BottomLeft;
							//VertexInfoBufferPtr[m++] = TopLeft;
							//VertexInfoBufferPtr[m++] = BottomRight;
							//VertexInfoBufferPtr[m++] = _TopRight;
						}
						VertexCount = (ushort)m;
						break;
					default:
						VertexReader.ReadVertices(0, VertexInfoBufferPtr, VertexCount);
						break;
				}

				//if (PrimitiveType == GuPrimitiveType.LineStrip)
				{
					aPositionLocation.Pointer(3, GL.GL_FLOAT, false, sizeof(VertexInfo), ((byte*)VertexInfoBufferPtr) + (int)Marshal.OffsetOf(typeof(VertexInfo), "Position"));
					aPositionLocation.Enable();

					if (VertexType.ColorSize != 0)
					{
						aColorLocation.Pointer(4, GL.GL_FLOAT, false, sizeof(VertexInfo), ((byte*)VertexInfoBufferPtr) + (int)Marshal.OffsetOf(typeof(VertexInfo), "Color"));
						aColorLocation.Enable();
						u_has_vertex_color.SetBool(true);
					}
					else
					{
						aColorLocation.Disable();
						u_has_vertex_color.SetBool(false);
					}

					u_transform_2d.SetBool(VertexType.Transform2D);

					if (GpuState->TextureMappingState.Enabled)
					{
						aTexCoord.Pointer(3, GL.GL_FLOAT, false, sizeof(VertexInfo), ((byte*)VertexInfoBufferPtr) + (int)Marshal.OffsetOf(typeof(VertexInfo), "Texture"));
						aTexCoord.Enable();
						u_has_texture.SetBool(true);
						u_texture.SetInt(0);
						u_texture_effect.SetInt((int)TextureState->Effect);
					}
					else
					{
						aTexCoord.Disable();
						u_has_texture.SetBool(false);
					}

					GL.glDrawArrays(PrimitiveTypeTranslate[(int)PrimitiveType], 0, VertexCount);
				}

				//TestingRender();
			}
		}
예제 #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="GpuState"></param>
        public unsafe override void Prim(GpuStateStruct* GpuState, PrimitiveType PrimitiveType, ushort VertexCount)
        {
            this.GpuState = GpuState;

            if (!IsCurrentWindow)
            {
                IsCurrentWindow = true;
                GraphicsContext.MakeCurrent(NativeWindow.WindowInfo);
            }

            //Console.WriteLine("--------------------------------------------------------");
            VertexType = GpuState->VertexState.Type;

            VertexReader.SetVertexTypeStruct(VertexType, (byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress));
            //IndexReader.SetVertexTypeStruct(VertexType, VertexCount, (byte*)Memory.PspAddressToPointerSafe(GpuState->IndexAddress));

            int TotalVerticesWithoutMorphing = VertexCount;

            void* IndexAddress = Memory.PspAddressToPointerSafe(GpuState->IndexAddress);

            switch (VertexType.Index)
            {
                case VertexTypeStruct.IndexEnum.Void:
                    break;
                case VertexTypeStruct.IndexEnum.Byte:
                    Marshal.Copy(new IntPtr(IndexAddress), IndexListByte, 0, VertexCount);
                    TotalVerticesWithoutMorphing = IndexListByte.Take(VertexCount).Max() + 1;
                    break;
                case VertexTypeStruct.IndexEnum.Short:
                    Marshal.Copy(new IntPtr(IndexAddress), IndexListShort, 0, VertexCount);
                    TotalVerticesWithoutMorphing = IndexListShort.Take(VertexCount).Max() + 1;
                    break;
                default:
                    throw (new NotImplementedException());
            }

            //Console.WriteLine(TotalVerticesWithoutMorphing);

            int MorpingVertexCount = (int)VertexType.MorphingVertexCount + 1;
            int z = 0;
            VertexInfo TempVertexInfo;

            float* Morphs = &GpuState->MorphingState.MorphWeight0;

            //for (int n = 0; n < MorpingVertexCount; n++) Console.Write("{0}, ", Morphs[n]); Console.WriteLine("");

            fixed (VertexInfo* VerticesPtr = Vertices)
            {
                for (int n = 0; n < TotalVerticesWithoutMorphing; n++)
                {
                    //Console.WriteLine(MorpingVertexCount);
                    if (MorpingVertexCount == 1)
                    {
                        VertexReader.ReadVertex(z++, &TempVertexInfo);
                        //Console.WriteLine(TempVertexInfo);
                        VerticesPtr[n] = TempVertexInfo;
                    }
                    else
                    {
                        var ComponentsIn = (float*)&TempVertexInfo;
                        var ComponentsOut = (float*)&VerticesPtr[n];
                        for (int cc = 0; cc < 20; cc++) ComponentsOut[cc] = 0;
                        for (int m = 0; m < MorpingVertexCount; m++)
                        {
                            VertexReader.ReadVertex(z++, &TempVertexInfo);
                            for (int cc = 0; cc < 20; cc++) ComponentsOut[cc] += ComponentsIn[cc] * Morphs[m];
                        }
                    }
                }
            }

            //VertexType.Texture == VertexTypeStruct.TextureEnum.Byte
            //return;
            //PrepareRead(GpuState);

            if (GpuState->ClearingMode)
            {
                //return;
                //GL.ClearColor(1, 1, 0, 0);

                // @TODO: Fake
                /*
                */
                //PrepareState(GpuState);
                //return;
                //Console.WriteLine(VertexCount);
                drawBeginClear(GpuState);
                /*
                GL.ClearColor(0, 0, 0, 1);
                GL.ClearDepth(0);
                GL.ClearStencil(0);
                GL.ClearAccum(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.AccumBufferBit);
                return;
                */
            }
            else
            {
                PrepareState(GpuState);
            }

            // DRAW BEGIN COMMON
            {
                if (GpuState->VertexState.Type.Transform2D)
                {
                    GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity();
                    GL.Ortho(0, 512, 272, 0, -0x7FFF, +0x7FFF);
                    GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity();
                }
                else
                {
                    GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity();
                    GL.MultMatrix(GpuState->VertexState.ProjectionMatrix.Values);

                    GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity();
                    GL.MultMatrix(GpuState->VertexState.ViewMatrix.Values);
                    GL.MultMatrix(GpuState->VertexState.WorldMatrix.Values);

                    if (GpuState->VertexState.WorldMatrix.Values[0] == float.NaN)
                    {
                        throw (new Exception("Invalid WorldMatrix"));
                    }

                    //GpuState->VertexState.ViewMatrix.Dump();
                    //GpuState->VertexState.WorldMatrix.Dump();

                    //Console.WriteLine("NO Transform2D");
                }
            }

            // DRAW ACTUALLY
            {
                uint VertexSize = GpuState->VertexState.Type.GetVertexSize();

                byte* VertexPtr = (byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress);

                //Console.WriteLine(VertexSize);

                var BeginMode = default(BeginMode);

                switch (PrimitiveType)
                {
                    case PrimitiveType.Lines: BeginMode = BeginMode.Lines; break;
                    case PrimitiveType.LineStrip: BeginMode = BeginMode.LineStrip; break;
                    case PrimitiveType.Triangles: BeginMode = BeginMode.Triangles; break;
                    case PrimitiveType.Points: BeginMode = BeginMode.Points; break;
                    case PrimitiveType.TriangleFan: BeginMode = BeginMode.TriangleFan; break;
                    case PrimitiveType.TriangleStrip: BeginMode = BeginMode.TriangleStrip; break;
                    case PrimitiveType.Sprites: BeginMode = BeginMode.Quads; break;
                    default: throw (new NotImplementedException("Not implemented PrimitiveType:'" + PrimitiveType + "'"));
                }

                //Console.WriteLine(BeginMode);

                GL.Begin(BeginMode);
                {
                    if (PrimitiveType == PrimitiveType.Sprites)
                    {
                        GL.Disable(EnableCap.CullFace);
                        for (int n = 0; n < VertexCount; n += 2)
                        {
                            VertexInfo VertexInfoTopLeft;
                            VertexInfo VertexInfoTopRight;
                            VertexInfo VertexInfoBottomRight;
                            VertexInfo VertexInfoBottomLeft;
                            ReadVertex(n + 0, &VertexInfoTopLeft);
                            ReadVertex(n + 1, &VertexInfoBottomRight);

                            //if (GpuState->ClearingMode) Console.WriteLine("{0} - {1}", VertexInfoTopLeft, VertexInfoBottomRight);

                            float R = VertexInfoBottomRight.R, G = VertexInfoBottomRight.G, B = VertexInfoBottomRight.B, A = VertexInfoBottomRight.A;
                            float PZ = VertexInfoTopLeft.PZ;
                            float NZ = VertexInfoTopLeft.NZ;

                            VertexInfoTopRight = new VertexInfo()
                            {
                                U = VertexInfoBottomRight.U,
                                V = VertexInfoTopLeft.V,
                                PX = VertexInfoBottomRight.PX,
                                PY = VertexInfoTopLeft.PY,
                                NX = VertexInfoBottomRight.NX,
                                NY = VertexInfoTopLeft.NY,
                            };

                            VertexInfoBottomLeft = new VertexInfo()
                            {
                                U = VertexInfoTopLeft.U,
                                V = VertexInfoBottomRight.V,
                                PX = VertexInfoTopLeft.PX,
                                PY = VertexInfoBottomRight.PY,
                                NX = VertexInfoTopLeft.NX,
                                NY = VertexInfoBottomRight.NY,
                            };

                            VertexInfoBottomLeft.R = VertexInfoBottomRight.R = VertexInfoTopRight.R = VertexInfoTopLeft.R = R;
                            VertexInfoBottomLeft.G = VertexInfoBottomRight.G = VertexInfoTopRight.G = VertexInfoTopLeft.G = G;
                            VertexInfoBottomLeft.B = VertexInfoBottomRight.B = VertexInfoTopRight.B = VertexInfoTopLeft.B = B;
                            VertexInfoBottomLeft.A = VertexInfoBottomRight.A = VertexInfoTopRight.A = VertexInfoTopLeft.A = R;
                            VertexInfoBottomLeft.PZ = VertexInfoBottomRight.PZ = VertexInfoTopRight.PZ = VertexInfoTopLeft.PZ = PZ;
                            VertexInfoBottomLeft.NZ = VertexInfoBottomRight.NZ = VertexInfoTopRight.NZ = VertexInfoTopLeft.NZ = NZ;

                            PutVertex(ref VertexInfoTopLeft, ref VertexType);
                            PutVertex(ref VertexInfoTopRight, ref VertexType);
                            PutVertex(ref VertexInfoBottomRight, ref VertexType);
                            PutVertex(ref VertexInfoBottomLeft, ref VertexType);
                        }
                    }
                    else
                    {
                        for (int n = 0; n < VertexCount; n++)
                        {
                            VertexInfo VertexInfo;
                            ReadVertex(n, &VertexInfo);
                            PutVertex(ref VertexInfo, ref VertexType);

                        }
                    }
                }
                GL.End();
                GL.Flush();
            }
            //Console.WriteLine(VertexCount);

            //PrepareWrite(GpuState);
        }
예제 #10
0
        public void SetVertexTypeStruct(VertexTypeStruct VertexType, byte* BasePointer)
        {
            this.VertexType = VertexType;
            Transform2D = VertexType.Transform2D;

            //Console.Error.WriteLine("SetVertexTypeStruct: " + VertexTypeStruct);
            SkinningWeightCount = VertexType.RealSkinningWeightCount;
            //Console.WriteLine(SkinningWeightCount);
            VertexSize = VertexType.GetVertexSize();
            {
                ReadWeights = ReadWeightsList[(int)VertexType.Weight];
                ReadTextureCoordinates = ReadTextureCoordinatesList[(int)VertexType.Texture];
                ReadColor = ReadColorList[(int)VertexType.Color];
                ReadNormal = ReadNormalList[(int)VertexType.Normal];
                ReadPosition = ReadPositionList[(int)VertexType.Position];

                switch (VertexType.StructAlignment)
                {
                    case 4: VertexAlignment = Align4; break;
                    case 2: VertexAlignment = Align2; break;
                    default: VertexAlignment = Align1; break;
                }
            }
            //public VertexTypeStruct VertexTypeStruct;
            this.BasePointer = BasePointer;
            this.PointerOffset = PointerOffset;
        }
예제 #11
0
		/*
		private void _LoadSignedByteScaled(ref int Offset, ILGenerator ILGenerator)
		{
			_LoadIntegerScaled(ref Offset, ILGenerator, Size: 1, Scale: 128f);
		}

		private void _LoadSignedShortScaled(ref int Offset, ILGenerator ILGenerator)
		{
			_LoadIntegerScaled(ref Offset, ILGenerator, Size: 2, Scale: 32768f);
		}
		*/

		private static int TypeSize(VertexTypeStruct.NumericEnum Type)
		{
			return VertexTypeStruct.TypeSizeTable[(int)Type];
		}
예제 #12
0
 public bool Equals(VertexTypeStruct other) => ReversedNormal == other.ReversedNormal &&
 NormalCount == other.NormalCount && Value == other.Value;
예제 #13
0
 public void SetVertexTypeStruct(VertexTypeStruct VertexTypeStruct, byte* BasePointer)
 {
     SkinningWeightCount = VertexTypeStruct.SkinningWeightCount;
     //Console.WriteLine(SkinningWeightCount);
     VertexSize = VertexTypeStruct.GetVertexSize();
     {
         ReadWeights = ReadWeightsList[(int)VertexTypeStruct.Weight];
         ReadTextureCoordinates = ReadTextureCoordinatesList[(int)VertexTypeStruct.Texture];
         ReadColor = ReadColorList[(int)VertexTypeStruct.Color];
         ReadNormal = ReadNormalList[(int)VertexTypeStruct.Normal];
         ReadPosition = ReadPositionList[(int)VertexTypeStruct.Position];
         switch (VertexAlignSize)
         {
             case 4: VertexAlignment = Align4; break;
             case 2: VertexAlignment = Align2; break;
             default: VertexAlignment = Align1; break;
         }
     }
     //public VertexTypeStruct VertexTypeStruct;
     this.BasePointer = BasePointer;
 }