CSPspEmu.Core.Gpu.Run.GpuDisplayListRunner.DrawBezier C# (CSharp) Method

DrawBezier() private method

private DrawBezier ( int UCount, int VCount ) : void
UCount int
VCount int
return void
		private void DrawBezier(int UCount, int VCount)
		{
			var DivS = GpuState->PatchState.DivS;
			var DivT = GpuState->PatchState.DivT;

			if ((UCount - 1) % 3 != 0 || (VCount - 1) % 3 != 0)
			{
				Logger.Warning("Unsupported bezier parameters ucount=" + UCount + " vcount=" + VCount);
				return;
			}
			if (DivS <= 0 || DivT <= 0)
			{
				Logger.Warning("Unsupported bezier patches patch_div_s=" + DivS + " patch_div_t=" + DivT);
				return;
			}

			//initRendering();
			//boolean useTexture = context.vinfo.texture != 0 || context.textureFlag.isEnabled();
			//boolean useNormal = context.lightingFlag.isEnabled();

			var anchors = GetControlPoints(UCount, VCount);

			// Don't capture the ram if the vertex list is embedded in the display list. TODO handle stall_addr == 0 better
			// TODO may need to move inside the loop if indices are used, or find the largest index so we can calculate the size of the vertex list
			/*
			if (State.captureGeNextFrame && !isVertexBufferEmbedded()) {
				Logger.Info("Capture drawBezier");
				CaptureManager.captureRAM(context.vinfo.ptr_vertex, context.vinfo.vertexSize * ucount * vcount);
			}
			*/

			// Generate patch VertexState.
			var Patch = new VertexInfo[DivS + 1, DivT + 1];

			// Number of patches in the U and V directions
			int upcount = UCount / 3;
			int vpcount = VCount / 3;

			float[][] ucoeff = new float[DivS + 1][];

			for (int j = 0; j <= DivT; j++)
			{
				float vglobal = (float)j * vpcount / (float)DivT;

				int vpatch = (int)vglobal; // Patch number
				float v = vglobal - vpatch;
				if (j == DivT)
				{
					vpatch--;
					v = 1.0f;
				}
				float[] vcoeff = BernsteinCoeff(v);

				for (int i = 0; i <= DivS; i++)
				{
					float uglobal = (float)i * upcount / (float)DivS;
					int upatch = (int)uglobal;
					float u = uglobal - upatch;
					if (i == DivS)
					{
						upatch--;
						u = 1.0f;
					}
					ucoeff[i] = BernsteinCoeff(u);

					var p = default(VertexInfo);
					p.Position = Vector4f.Zero;
					p.Normal = Vector4f.Zero;

					for (int ii = 0; ii < 4; ++ii)
					{
						for (int jj = 0; jj < 4; ++jj)
						{
							/*
							Console.WriteLine(
								"({0}, {1}) : {2} : {3} : {4}",
								ii, jj,
								p.Position, anchors[3 * upatch + ii, 3 * vpatch + jj].Position,
								ucoeff[i][ii] * vcoeff[jj]
							);
							*/
							PointMultAdd(
								ref p,
								ref anchors[3 * upatch + ii, 3 * vpatch + jj],
								ucoeff[i][ii] * vcoeff[jj]
							);
						}
					}

					p.Texture.X = uglobal;
					p.Texture.Y = vglobal;

					Patch[i, j] = p;

					/*
					Console.WriteLine(
						"W: ({0}, {1}) : {2}",
						i, j,
						patch[i, j] 
					);
					*/

					/*
					if (useTexture && context.vinfo.texture == 0)
					{
						p.t[0] = uglobal;
						p.t[1] = vglobal;
					}
					*/
				}
			}

			GpuDisplayList.GpuProcessor.GpuImpl.BeforeDraw(GpuDisplayList.GpuStateStructPointer);
			GpuDisplayList.GpuProcessor.GpuImpl.DrawCurvedSurface(GlobalGpuState, GpuDisplayList.GpuStateStructPointer, Patch, UCount, VCount);
		}
GpuDisplayListRunner