public GpuDisplayListRunner(GpuDisplayList GpuDisplayList, State.GlobalGpuState GlobalGpuState) { this.GpuDisplayList = GpuDisplayList; this.GlobalGpuState = GlobalGpuState; }
public abstract void Prim(GlobalGpuState GlobalGpuState, GpuStateStruct* GpuState, GuPrimitiveType PrimitiveType, ushort VertexCount);
public override void Prim(GlobalGpuState GlobalGpuState, GpuStateStruct* GpuState, GuPrimitiveType PrimitiveType, ushort VertexCount) { }
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(); } }
public virtual void DrawCurvedSurface(GlobalGpuState GlobalGpuState, GpuStateStruct* GpuStateStruct, VertexInfo[,] Patch, int UCount, int VCount) { Console.Error.WriteLine("GpuImpl.DrawCurvedSurface Not Implemented!!"); }
/// <summary> /// /// </summary> /// <param name="GpuState"></param> private unsafe void _Prim(GlobalGpuState GlobalGpuState, 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(GlobalGpuState.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(GlobalGpuState.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, GlobalGpuState.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); //var CurrentTexture = new Texture(this).Load("Bezier2.png"); //CurrentTexture.Bind(); //lock (GpuLock) { //Console.Error.WriteLine("GL.Begin : Thread : {0}", Thread.CurrentThread.ManagedThreadId); GL.Begin(BeginMode); { if (PrimitiveType == GuPrimitiveType.Sprites) { #if DEBUG_PRIM if (!GpuState->ClearingMode) { Console.WriteLine("************************"); } #endif 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); V1.Color.W = 1.0f; V3.Color.W = 1.0f; { //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 Vector4f(V3.Texture.X, V1.Texture.Y, TZ, 0), Position = new Vector4f(V3.Position.X, V1.Position.Y, PZ, 0), Normal = new Vector4f(V3.Normal.X, V1.Normal.Y, NZ, 0), }; V4 = new VertexInfo() { Texture = new Vector4f(V1.Texture.X, V3.Texture.Y, TZ, 0), Position = new Vector4f(V1.Position.X, V3.Position.Y, PZ, 0), Normal = new Vector4f(V1.Normal.X, V3.Normal.Y, NZ, 0), }; 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; } #if DEBUG_PRIM if (!GpuState->ClearingMode) { Console.WriteLine("--------------------"); Console.WriteLine("{0}", V1); Console.WriteLine("{0}", V2); Console.WriteLine("{0}", V3); Console.WriteLine("{0}", V4); } #endif 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 }
public unsafe override void Prim(GlobalGpuState GlobalGpuState, GpuStateStruct* GpuState, GuPrimitiveType PrimitiveType, ushort VertexCount) { #if SLOW_SIMPLE_RENDER_TARGET PrepareRead(GpuState); #endif //Console.WriteLine("VertexCount: {0}", VertexCount); var Start = DateTime.UtcNow; { _Prim(GlobalGpuState, GpuState, PrimitiveType, VertexCount); } var End = DateTime.UtcNow; #if SLOW_SIMPLE_RENDER_TARGET PrepareWrite(GpuState); #endif //Console.Error.WriteLine("Prim: {0}", End - Start); if (!GpuState->ClearingMode) { //Console.WriteLine("{0}", (*GpuState).ToStringDefault()); } #if false if (GpuState->ClearingMode) { ResetState(); GL.Begin(BeginMode.Quads); { GL.Vertex2(0, 0); GL.Vertex2(100, 0); GL.Vertex2(100, 100); GL.Vertex2(0, 100); } GL.End(); SaveFrameBuffer(GpuState, "frameBuffer.png"); } #endif }
public override void DrawCurvedSurface(GlobalGpuState GlobalGpuState, GpuStateStruct* GpuStateStruct, VertexInfo[,] Patch, int UCount, int VCount) { //GpuState->TextureMappingState.Enabled = true; //ResetState(); PrepareStateCommon(GpuState); PrepareStateDraw(GpuState); PrepareStateMatrix(GpuState); PrepareState_Texture_Common(GpuState); PrepareState_Texture_3D(GpuState); GL.ActiveTexture(TextureUnit.Texture0); /* GL.Enable(EnableCap.Texture2D); GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.CullFace); //GL.Disable(EnableCap.Texture2D); //var CurrentTexture = TextureCache.Get(GpuState); var CurrentTexture = new Texture(this).Load("Bezier2.png"); CurrentTexture.Bind(); var Mipmap0 = &GpuStateStruct->TextureMappingState.TextureState.Mipmap0; int MipmapWidth = Mipmap0->BufferWidth; int MipmapHeight = Mipmap0->TextureHeight; */ /* GL.Scale( 1.0f * Mipmap0->BufferWidth, 1.0f * Mipmap0->TextureHeight, 1.0f ); */ //GL.LoadIdentity(); //var CurrentTexture = TextureCache.Get(GpuState); //CurrentTexture.Save("Bezier.png"); var VertexType = GpuStateStruct->VertexState.Type; //GL.Color3(Color.White); #if true GL.Begin(BeginMode.Triangles); for (int t = 0; t < Patch.GetLength(1) - 1; t++) { for (int s = 0; s < Patch.GetLength(0) - 1; s++) { var VertexInfo1 = Patch[s + 0, t + 0]; var VertexInfo2 = Patch[s + 0, t + 1]; var VertexInfo3 = Patch[s + 1, t + 1]; var VertexInfo4 = Patch[s + 1, t + 0]; /* VertexInfo1.Texture.X = (s + 0) * MipmapWidth / Patch.GetLength(0); VertexInfo1.Texture.Y = (t + 0) * MipmapWidth / Patch.GetLength(1); VertexInfo2.Texture.X = (s + 0) * MipmapWidth / Patch.GetLength(0); VertexInfo2.Texture.Y = (t + 1) * MipmapWidth / Patch.GetLength(1); VertexInfo3.Texture.X = (s + 1) * MipmapWidth / Patch.GetLength(0); VertexInfo3.Texture.Y = (t + 1) * MipmapWidth / Patch.GetLength(1); VertexInfo4.Texture.X = (s + 1) * MipmapWidth / Patch.GetLength(0); VertexInfo4.Texture.Y = (t + 0) * MipmapWidth / Patch.GetLength(1); */ PutVertex(ref VertexInfo1, ref VertexType); PutVertex(ref VertexInfo2, ref VertexType); PutVertex(ref VertexInfo3, ref VertexType); PutVertex(ref VertexInfo1, ref VertexType); PutVertex(ref VertexInfo3, ref VertexType); PutVertex(ref VertexInfo4, ref VertexType); //GL.Color3(Color.White); //Console.WriteLine("{0}, {1} : {2}", s, t, VertexInfo1); } } GL.End(); #else GL.Begin(BeginMode.TriangleStrip); //GL.Begin(BeginMode.LineStrip); //GL.Begin(BeginMode.Points); for (int t = 0; t < Patch.GetLength(1) - 1; t++) { for (int s = 0; s < Patch.GetLength(0); s++) { var VertexInfo1 = Patch[s, t]; var VertexInfo2 = Patch[s, t + 1]; PutVertex(ref VertexInfo1, ref VertexType); PutVertex(ref VertexInfo2, ref VertexType); //GL.Color3(Color.White); Console.WriteLine("{0}, {1} : {2}", s, t, VertexInfo1); } } GL.End(); #endif }
public virtual void PrimStart(GlobalGpuState GlobalGpuState, GpuStateStruct* GpuState, GuPrimitiveType PrimitiveType) { }
//Action[] InstructionSwitch = new Action[256]; /// <summary> /// Constructor /// </summary> internal GpuDisplayList(PspMemory Memory, GpuProcessor GpuProcessor, int Id) { this.Memory = Memory; this.GpuProcessor = GpuProcessor; this.Id = Id; this.GlobalGpuState = GpuProcessor.GlobalGpuState; this.GpuDisplayListRunner = new GpuDisplayListRunner(this, GpuProcessor.GlobalGpuState); }