Ejemplo n.º 1
0
        private VertexInfo[,] GetControlPoints(int uCount,int vCount)
        {
            var controlPoints = new VertexInfo[uCount,vCount];

            var vertexPtr =
                (byte*)GpuProcessor.Memory.PspAddressToPointerSafe(
                    GpuStateStructPointer.GetAddressRelativeToBaseOffset(GpuStateStructPointer.VertexAddress));
            var vertexReader = new VertexReader();

            vertexReader.SetVertexTypeStruct(GpuStateStructPointer.VertexState.Type,vertexPtr);

            for (var u = 0; u < uCount; u++)
            {
                for (var v = 0; v < vCount; v++)
                {
                    controlPoints[u,v] = vertexReader.ReadVertex(v * uCount + u);
                    //Console.WriteLine("getControlPoints({0}, {1}) : {2}", u, v, controlPoints[u, v]);
                }
            }
            return(controlPoints);
        }
Ejemplo n.º 2
0
        /// <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);
                    }
                }
            });
        }