Beispiel #1
0
        CanvasRenderCommand nextCommand(PrimitiveType prim, Projection projection, int textureId, Fill fill, bool clip)
        {
            CanvasRenderCommand cmd = null;

            if (myDrawCmds.Count == 0)
            {
                cmd = createCommand(prim, projection, textureId, fill, clip);
                myDrawCmds.Add(cmd);
                return(cmd);
            }

            CanvasRenderCommand currentCmd = myDrawCmds[myDrawCmds.Count - 1] as CanvasRenderCommand;

            //this command profile matches, so keep using it
            if (currentCmd != null &&
                currentCmd.myPrimative == prim &&
                currentCmd.myProjection == projection &&
                currentCmd.myTextureId == textureId &&
                currentCmd.myFill == fill &&
                currentCmd.myClip == clip)
            {
                if (prim == PrimitiveType.TriangleStrip || prim == PrimitiveType.LineStrip)
                {
                    addIndex(currentCmd, PRIM_RESTART);
                }
                return(currentCmd);
            }

            //new type of command
            cmd = createCommand(prim, projection, textureId, fill, clip);
            myDrawCmds.Add(cmd);

            return(cmd);
        }
Beispiel #2
0
        public void addTexture2d(Vector2 start, Vector2 end, TextureBufferObject t, bool LinearDepth)
        {
            CanvasRenderCommand cmd = nextCommand(PrimitiveType.Triangles, Projection.ORTHO, t.textureId, Fill.SOLID, false);

            cmd.renderState.setTexture(t.textureId, 0, TextureTarget.TextureBuffer);
            cmd.renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));
            cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 0));

            UInt32 baseVertex = (UInt32)myVertCount;

            Vector2 mid1 = new Vector2(end.X, start.Y);
            Vector2 mid2 = new Vector2(start.X, end.Y);

            addVertex(new Vector3(start), uvSolid, Color4.White);
            addVertex(new Vector3(mid1), uvSolid, Color4.White);
            addVertex(new Vector3(end), uvSolid, Color4.White);
            addVertex(new Vector3(mid2), uvSolid, Color4.White);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 1);
            addIndex(cmd, baseVertex + 2);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 2);
            addIndex(cmd, baseVertex + 3);
        }
Beispiel #3
0
        public void addRect2d(Vector2 start, Vector2 end, Color4 color, Fill fill, bool clip)
        {
            CanvasRenderCommand cmd = nextCommand(PrimitiveType.Triangles, Projection.ORTHO, myTexture.id(), fill, clip);
            UInt32 baseVertex       = (UInt32)myVertCount;

            if (fill == Fill.TRANSPARENT)
            {
                color.A = 0.5f;
            }

            Vector2 mid1 = new Vector2(end.X, start.Y);
            Vector2 mid2 = new Vector2(start.X, end.Y);

            addVertex(new Vector3(start), uvSolid, color);
            addVertex(new Vector3(mid1), uvSolid, color);
            addVertex(new Vector3(end), uvSolid, color);
            addVertex(new Vector3(mid2), uvSolid, color);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 1);
            addIndex(cmd, baseVertex + 2);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 2);
            addIndex(cmd, baseVertex + 3);
        }
Beispiel #4
0
        void addIndexListWithOffset(CanvasRenderCommand cmd, UInt32[] idx, UInt32 offset)
        {
            for (int i = 0; i < idx.Length; i++)
            {
                myIndexes[myIndexCount] = idx[i] + offset;
                myIndexCount++;
            }

            cmd.myCount += idx.Length;
        }
Beispiel #5
0
        void addIndexListWithOffset(CanvasRenderCommand cmd, List <UInt32> idx, UInt32 offset)
        {
            for (int i = 0; i < idx.Count; i++)
            {
                myIndexes[myIndexCount] = idx[i] == PRIM_RESTART ? idx[i] : idx[i] + offset;
                myIndexCount++;
            }

            cmd.myCount += idx.Count;
        }
Beispiel #6
0
        public void addCube(Vector3 min, Vector3 max, Color4 color, Fill fill, bool clip)
        {
            UInt32 baseVertex = (UInt32)myVertCount;

            if (fill == Fill.WIREFRAME)
            {
                CanvasRenderCommand cmd = nextCommand(PrimitiveType.LineStrip, Projection.PERSPECTIVE, myTexture.id(), fill, clip);
                addVertex(min, uvSolid, color);
                addVertex(new Vector3(max[0], min[1], min[2]), uvSolid, color);
                addVertex(new Vector3(min[0], max[1], min[2]), uvSolid, color);
                addVertex(new Vector3(max[0], max[1], min[2]), uvSolid, color);
                addVertex(new Vector3(min[0], min[1], max[2]), uvSolid, color);
                addVertex(new Vector3(max[0], min[1], max[2]), uvSolid, color);
                addVertex(new Vector3(min[0], max[1], max[2]), uvSolid, color);
                addVertex(max, uvSolid, color);

                List <UInt32> indexes = new List <UInt32> {
                    4, 6, 2, 3, PRIM_RESTART,
                    1, 3, 7, 6, PRIM_RESTART,
                    7, 5, 1, 0, PRIM_RESTART,
                    2, 0, 4, 5
                };

                addIndexListWithOffset(cmd, indexes, baseVertex);
            }
            else
            {
                CanvasRenderCommand cmd = nextCommand(PrimitiveType.Triangles, Projection.PERSPECTIVE, myTexture.id(), fill, clip);
                if (fill == Fill.TRANSPARENT)
                {
                    color.A = 0.5f;
                }

                addVertex(min, uvSolid, color);
                addVertex(new Vector3(max[0], min[1], min[2]), uvSolid, color);
                addVertex(new Vector3(min[0], max[1], min[2]), uvSolid, color);
                addVertex(new Vector3(max[0], max[1], min[2]), uvSolid, color);
                addVertex(new Vector3(min[0], min[1], max[2]), uvSolid, color);
                addVertex(new Vector3(max[0], min[1], max[2]), uvSolid, color);
                addVertex(new Vector3(min[0], max[1], max[2]), uvSolid, color);
                addVertex(max, uvSolid, color);

                List <UInt32> indexes = new List <UInt32> {
                    0, 1, 5, 0, 5, 4,
                    1, 3, 7, 1, 7, 5,
                    3, 2, 6, 3, 6, 7,
                    2, 0, 4, 2, 4, 6,
                    4, 5, 7, 4, 7, 6,
                    2, 3, 1, 2, 1, 0
                };

                addIndexListWithOffset(cmd, indexes, baseVertex);
            }
        }
Beispiel #7
0
        public void addTexture2d(Vector2 start, Vector2 end, Texture t, int layer = 0, bool linearDepth = false)
        {
            CanvasRenderCommand cmd = nextCommand(PrimitiveType.Triangles, Projection.ORTHO, t.id(), Fill.SOLID, false);

            switch (t.target)
            {
            case TextureTarget.Texture2D:
                cmd.renderState.setTexture(t.id(), 0, t.target);
                cmd.renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));
                cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 0));
                cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth));
                break;

            case TextureTarget.TextureCubeMap:
                cmd.renderState.setTexture(t.id(), 0, t.target);
                cmd.renderState.setUniform(new UniformData(21, Uniform.UniformType.Int, 0));
                cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 1));
                cmd.renderState.setUniform(new UniformData(24, Uniform.UniformType.Int, layer));
                cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth));
                break;

            case TextureTarget.Texture2DArray:
                cmd.renderState.setTexture(t.id(), 0, t.target);
                cmd.renderState.setUniform(new UniformData(22, Uniform.UniformType.Int, 0));
                cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 2));
                cmd.renderState.setUniform(new UniformData(24, Uniform.UniformType.Int, layer));
                cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth));
                break;
            }

            cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth));

            UInt32 baseVertex = (UInt32)myVertCount;

            Vector2 mid1 = new Vector2(end.X, start.Y);
            Vector2 mid2 = new Vector2(start.X, end.Y);

            addVertex(new Vector3(start), uvSolid, Color4.White);
            addVertex(new Vector3(mid1), uvSolid, Color4.White);
            addVertex(new Vector3(end), uvSolid, Color4.White);
            addVertex(new Vector3(mid2), uvSolid, Color4.White);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 1);
            addIndex(cmd, baseVertex + 2);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 2);
            addIndex(cmd, baseVertex + 3);
        }
Beispiel #8
0
        public void addFrustum(Matrix4 invertedClip, Color4 color, bool clip)
        {
            //frustum after view/projection transform, in clip space
            Vector4[] points = new Vector4[8];
            points[0] = new Vector4(-1, -1, 0, 1);             //near
            points[1] = new Vector4(1, -1, 0, 1);
            points[2] = new Vector4(1, 1, 0, 1);
            points[3] = new Vector4(-1, 1, 0, 1);

            points[4] = new Vector4(-1, -1, 1, 1);             //far
            points[5] = new Vector4(1, -1, 1, 1);
            points[6] = new Vector4(1, 1, 1, 1);
            points[7] = new Vector4(-1, 1, 1, 1);

            //transform back into world space
            for (int i = 0; i < 8; i++)
            {
                points[i]  = points[i] * invertedClip;
                points[i] /= points[i].W;
            }

            //draw the frustum
            UInt32 baseVertex = (UInt32)myVertCount;

            CanvasRenderCommand cmd = nextCommand(PrimitiveType.Lines, Projection.PERSPECTIVE, myTexture.id(), Fill.WIREFRAME, clip);

            for (int i = 0; i < 8; i++)
            {
                addVertex(points[i].Xyz, uvSolid, color);
            }

            List <UInt32> indexes = new List <UInt32> {
                0, 1,                                         //near plane
                1, 2,
                2, 3,
                3, 0,
                4, 5,                                         //far plane
                5, 6,
                6, 7,
                7, 4,
                0, 4,                                         //sides
                1, 5,
                2, 6,
                3, 7
            };

            addIndexListWithOffset(cmd, indexes, baseVertex);
        }
Beispiel #9
0
        public void addLine(Vector3 start, Vector3 end, Color4 color, Fill fill, bool clip)
        {
            if (fill == Fill.WIREFRAME)
            {
                fill = Fill.SOLID;
            }

            CanvasRenderCommand cmd = nextCommand(PrimitiveType.Lines, Projection.PERSPECTIVE, myTexture.id(), fill, clip);
            UInt32 baseVertex       = (UInt32)myVertCount;

            addVertex(start, uvSolid, color);
            addVertex(end, uvSolid, color);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 1);
        }
Beispiel #10
0
        CanvasRenderCommand createCommand(PrimitiveType prim, Projection projection, int textureId, Fill fill, bool clip)
        {
            CanvasRenderCommand cmd = new CanvasRenderCommand(prim, projection, textureId, myIndexCount, 0, clip, fill);

            cmd.renderState.setVertexBuffer(myVbo.id, 0, 0, V3T2B4.stride);
            cmd.renderState.setIndexBuffer(myIbo.id);
            cmd.renderState.setTexture(myTexture.id(), 0, TextureTarget.Texture2D);
            cmd.renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));
            cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 0));
            cmd.renderState.wireframe.enabled           = fill == Fill.WIREFRAME;
            cmd.pipelineState.shaderState.shaderProgram = myShader;
            cmd.pipelineState.vaoState.vao     = myVao;
            cmd.pipelineState.blending.enabled = true;
            cmd.pipelineState.generateId();

            return(cmd);
        }
Beispiel #11
0
        public void addSphere(Vector3 position, float radius, Color4 color, Fill fill, bool clip)
        {
            CanvasRenderCommand cmd = nextCommand(PrimitiveType.Triangles, Projection.PERSPECTIVE, myTexture.id(), fill, clip);
            UInt32 baseVertex       = (UInt32)myVertCount;

            if (fill == Fill.TRANSPARENT)
            {
                color.A = 0.5f;
            }

            for (int i = 0; i < theSphereVertCount; i++)
            {
                Vector3 v = theSphereVerts[i] * radius + position;
                addVertex(v, uvSolid, color);
            }

            addIndexListWithOffset(cmd, theSphereIndexes, baseVertex);
        }
Beispiel #12
0
        public void addLine(Vector2 start, Vector2 end, Color4 color, Fill fill, bool clip)
        {
            if (fill == Fill.WIREFRAME)
            {
                fill = Fill.SOLID;
            }

            if (fill == Fill.TRANSPARENT)
            {
                color.A = 0.5f;
            }

            CanvasRenderCommand cmd = nextCommand(PrimitiveType.Lines, Projection.ORTHO, myTexture.id(), fill, clip);
            UInt32 baseVertex       = (UInt32)myVertCount;

            addVertex(new Vector3(start), uvSolid, color);
            addVertex(new Vector3(end), uvSolid, color);

            addIndex(cmd, baseVertex);
            addIndex(cmd, baseVertex + 1);
        }
Beispiel #13
0
 void addIndex(CanvasRenderCommand cmd, UInt32 idx)
 {
     myIndexes[myIndexCount] = idx;
     myIndexCount++;
     cmd.myCount++;
 }