Ejemplo n.º 1
0
        protected internal virtual void drawArraysTriangleFan(int first, int count)
        {
            Memory mem = Memory.Instance;
            CachedTextureResampled cachedTexture    = CachedTexture;
            TriangleRenderer       triangleRenderer = new TriangleRenderer(context, cachedTexture, useVertexTexture);
            VertexState            tv1 = null;
            VertexState            tv2 = null;
            VertexState            tv3 = v1;
            bool readTexture           = context.textureFlag.Enabled && !context.clearMode;

            for (int i = 0; i < count; i++)
            {
                readVertex(mem, first + i, tv3, readTexture);
                if (tv2 != null)
                {
                    drawTriangle(triangleRenderer, tv1, tv2, tv3, false);
                    VertexState v = tv2;
                    tv2 = tv3;
                    tv3 = v;
                }
                else if (tv1 == null)
                {
                    tv1 = tv3;
                    tv3 = v2;
                }
                else
                {
                    tv2 = tv3;
                    tv3 = v3;
                }
            }
        }
Ejemplo n.º 2
0
 protected internal virtual void drawTriangle(TriangleRenderer triangleRenderer, VertexState v1, VertexState v2, VertexState v3, bool invertedFrontFace)
 {
     triangleRenderer.setVertex(v1, v2, v3);
     if (!triangleRenderer.isCulled(invertedFrontFace))
     {
         render(triangleRenderer);
     }
 }
Ejemplo n.º 3
0
        protected internal virtual void drawArraysTriangles(int first, int count)
        {
            Memory mem = Memory.Instance;
            CachedTextureResampled cachedTexture    = CachedTexture;
            TriangleRenderer       triangleRenderer = new TriangleRenderer(context, cachedTexture, useVertexTexture);
            bool readTexture = context.textureFlag.Enabled && !context.clearMode;

            for (int i = 0; i < count; i += 3)
            {
                readVertex(mem, first + i, v1, readTexture);
                readVertex(mem, first + i + 1, v2, readTexture);
                readVertex(mem, first + i + 2, v3, readTexture);

                drawTriangle(triangleRenderer, v1, v2, v3, false);
            }
        }
Ejemplo n.º 4
0
        protected internal virtual void drawArraysTriangleStrips(int first, int count)
        {
            Memory mem = Memory.Instance;
            CachedTextureResampled cachedTexture    = CachedTexture;
            TriangleRenderer       triangleRenderer = new TriangleRenderer(context, cachedTexture, useVertexTexture);
            SpriteRenderer         spriteRenderer   = null;
            VertexState            tv1 = null;
            VertexState            tv2 = null;
            VertexState            tv3 = null;
            VertexState            tv4 = v1;
            bool readTexture           = context.textureFlag.Enabled && !context.clearMode;

            for (int i = 0; i < count; i++)
            {
                readVertex(mem, first + i, tv4, readTexture);
                if (tv3 != null)
                {
                    // Displaying a sprite (i.e. rectangular area) is faster.
                    // Try to merge adjacent triangles if they form a sprite.
                    if (isSprite(context.vinfo, tv1, tv2, tv3, tv4))
                    {
                        if (spriteRenderer == null)
                        {
                            spriteRenderer = new SpriteRenderer(context, cachedTexture, useVertexTexture);
                        }
                        drawSprite(spriteRenderer, tv1, tv4);
                        v5.copy(tv3);
                        v6.copy(tv4);
                        v1.copy(v5);
                        v2.copy(v6);
                        tv1 = v1;
                        tv2 = v2;
                        tv3 = null;
                        tv4 = v3;
                    }
                    else
                    {
                        // The Front face direction is inverted every 2 triangles in the strip.
                        drawTriangle(triangleRenderer, tv1, tv2, tv3, ((i - 3) & 1) != 0);
                        VertexState v = tv1;
                        tv1 = tv2;
                        tv2 = tv3;
                        tv3 = tv4;
                        tv4 = v;
                    }
                }
                else if (tv1 == null)
                {
                    tv1 = tv4;
                    tv4 = v2;
                }
                else if (tv2 == null)
                {
                    tv2 = tv4;
                    tv4 = v3;
                }
                else
                {
                    tv3 = tv4;
                    tv4 = v4;
                }
            }

            if (tv3 != null)
            {
                // The Front face direction is inverted every 2 triangles in the strip.
                drawTriangle(triangleRenderer, tv1, tv2, tv3, (count & 1) == 0);
            }
        }