/// <summary> /// </summary> /// <param name="vertexCount"></param> public override void Prim(ushort vertexCount) { VertexType = GpuState->VertexState.Type; if (_doPrimStart || (VertexType != _cachedVertexType)) { _cachedVertexType = VertexType; _doPrimStart = false; OpenglGpuImplCommon.PrepareStateCommon(GpuState, ScaleViewport); if (GpuState->ClearingMode) { OpenglGpuImplClear.PrepareStateClear(GpuState); } else { PrepareStateDraw(GpuState); } OpenglGpuImplMatrix.PrepareStateMatrix(GpuState, out _worldViewProjectionMatrix); PrepareDrawStateFirst(); } var morpingVertexCount = VertexType.MorphingVertexCount + 1; //if (PrimitiveType == GuPrimitiveType.TriangleStrip) VertexCount++; // ReSharper disable once RedundantAssignment (Resharper BUG) ReadVertexDelegate readVertex = ReadVertex_Void; VertexReader.SetVertexTypeStruct( VertexType, (byte *)Memory.PspAddressToPointerSafe( GpuState->GetAddressRelativeToBaseOffset(GpuState->VertexAddress), 0) ); // Fix missing geometry! At least! if (VertexType.Index == VertexTypeStruct.IndexEnum.Void) { GpuState->VertexAddress += (uint)(VertexReader.VertexSize * vertexCount * morpingVertexCount); //GpuState->VertexAddress += (uint)(VertexReader.VertexSize * VertexCount); } if (morpingVertexCount != 1 || VertexType.RealSkinningWeightCount != 0) { //Console.WriteLine("PRIM: {0}, {1}, Morphing:{2}, Skinning:{3}", PrimitiveType, VertexCount, MorpingVertexCount, VertexType.RealSkinningWeightCount); } uint totalVerticesWithoutMorphing = vertexCount; 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("VertexType.Index: " + VertexType.Index)); } totalVerticesWithoutMorphing++; //Console.WriteLine(TotalVerticesWithoutMorphing); var z = 0; //for (int n = 0; n < MorpingVertexCount; n++) Console.Write("{0}, ", Morphs[n]); Console.WriteLine(""); //int VertexInfoFloatCount = (sizeof(Color4F) + sizeof(Vector3F) * 3) / sizeof(float); var vertexInfoFloatCount = (sizeof(VertexInfo)) / sizeof(float); fixed(VertexInfo *verticesPtr = Vertices) { if (morpingVertexCount == 1) { VertexReader.ReadVertices(0, verticesPtr, (int)totalVerticesWithoutMorphing); } else { VertexInfo tempVertexInfo; var componentsIn = (float *)&tempVertexInfo; for (var n = 0; n < totalVerticesWithoutMorphing; n++) { var componentsOut = (float *)&verticesPtr[n]; for (var cc = 0; cc < vertexInfoFloatCount; cc++) { componentsOut[cc] = 0; } for (var m = 0; m < morpingVertexCount; m++) { VertexReader.ReadVertex(z++, &tempVertexInfo); for (int cc = 0; cc < vertexInfoFloatCount; cc++) { componentsOut[cc] += componentsIn[cc] * GpuState->MorphingState.MorphWeight[m]; } } verticesPtr[n].Normal = verticesPtr[n].Normal.Normalize(); } } } _CapturePrimitive(_primitiveType, GpuState->GetAddressRelativeToBaseOffset(GpuState->VertexAddress), vertexCount, ref VertexType, () => { // Continuation if (_indicesList.Length > 0) { switch (_primitiveType) { // Degenerate. case GuPrimitiveType.TriangleStrip: case GuPrimitiveType.Sprites: if (vertexCount > 0) { PutVertexIndexRelative(-1); PutVertexIndexRelative(0); } break; // Can't degenerate, flush. default: EndVertex(); break; } } if (_primitiveType == GuPrimitiveType.Sprites) { GL.glDisable(GL.GL_CULL_FACE); for (int n = 0; n < vertexCount; n += 2) { VertexInfo v0, v1, v2, v3; readVertex(n + 0, out v0); readVertex(n + 1, out v3); VertexUtils.GenerateTriangleStripFromSpriteVertices(ref v0, out v1, out v2, ref v3); if (n > 0) { PutVertexIndexRelative(-1); PutVertexIndexRelative(0); } PutVertices(v0, v1, v2, v3); } } else { VertexInfo VertexInfo; //Console.Error.WriteLine("{0} : {1} : {2}", BeginMode, VertexCount, VertexType.Index); for (int n = 0; n < vertexCount; n++) { readVertex(n, out VertexInfo); PutVertex(VertexInfo); } } }); }
/// <summary> /// </summary> /// <param name="vertexCount"></param> public override void Prim(ushort vertexCount) { VertexType = GpuState.VertexState.Type; if (_doPrimStart || (VertexType != _cachedVertexType)) { _cachedVertexType = VertexType; _doPrimStart = false; OpenglGpuImplCommon.PrepareStateCommon(GpuState, ScaleViewport); if (GpuState.ClearingMode) { OpenglGpuImplClear.PrepareStateClear(GpuState); } else { PrepareStateDraw(GpuState); } OpenglGpuImplMatrix.PrepareStateMatrix(GpuState, out _worldViewProjectionMatrix); PrepareDrawStateFirst(); } //if (PrimitiveType == GuPrimitiveType.TriangleStrip) VertexCount++; uint morpingVertexCount, totalVerticesWithoutMorphing; PreparePrim(GpuState, out totalVerticesWithoutMorphing, vertexCount, out morpingVertexCount); var z = 0; //for (int n = 0; n < MorpingVertexCount; n++) Console.Write("{0}, ", Morphs[n]); Console.WriteLine(""); //int VertexInfoFloatCount = (sizeof(Color4F) + sizeof(Vector3F) * 3) / sizeof(float); var vertexInfoFloatCount = (sizeof(VertexInfo)) / sizeof(float); fixed(VertexInfo *verticesPtr = Vertices) { if (morpingVertexCount == 1) { VertexReader.ReadVertices(0, verticesPtr, (int)totalVerticesWithoutMorphing); } else { VertexInfo tempVertexInfo; var componentsIn = (float *)&tempVertexInfo; for (var n = 0; n < totalVerticesWithoutMorphing; n++) { var componentsOut = (float *)&verticesPtr[n]; for (var cc = 0; cc < vertexInfoFloatCount; cc++) { componentsOut[cc] = 0; } for (var m = 0; m < morpingVertexCount; m++) { VertexReader.ReadVertex(z++, &tempVertexInfo); for (var cc = 0; cc < vertexInfoFloatCount; cc++) { componentsOut[cc] += componentsIn[cc] * GpuState.MorphingState.MorphWeight(m); } } verticesPtr[n].Normal = verticesPtr[n].Normal.Normalize(); } } } _CapturePrimitive(_primitiveType, GpuState.GetAddressRelativeToBaseOffset(GpuState.VertexAddress), vertexCount, ref VertexType, () => { // Continuation if (_indicesList.Length > 0) { switch (_primitiveType) { // Degenerate. case GuPrimitiveType.TriangleStrip: case GuPrimitiveType.Sprites: if (vertexCount > 0) { PutVertexIndexRelative(-1); PutVertexIndexRelative(0); } break; // Can't degenerate, flush. default: EndVertex(); break; } } if (_primitiveType == GuPrimitiveType.Sprites) { GL.glDisable(GL.GL_CULL_FACE); for (var n = 0; n < vertexCount; n += 2) { VertexInfo v0, v1, v2, v3; readVertex(n + 0, out v0); readVertex(n + 1, out v3); VertexUtils.GenerateTriangleStripFromSpriteVertices(ref v0, out v1, out v2, ref v3); if (n > 0) { PutVertexIndexRelative(-1); PutVertexIndexRelative(0); } PutVertices(v0, v1, v2, v3); } } else { VertexInfo VertexInfo; //Console.Error.WriteLine("{0} : {1} : {2}", BeginMode, VertexCount, VertexType.Index); for (var n = 0; n < vertexCount; n++) { readVertex(n, out VertexInfo); PutVertex(VertexInfo); } } }); }