Beispiel #1
0
        public Renderer2D(RenderState rstate)
        {
            rs         = rstate;
            FT         = new Library();
            textShader = new Shader(vertex_source, text_fragment_source);
            textShader.SetInteger(textShader.GetLocation("tex"), 0);
            imgShader = new Shader(vertex_source, img_fragment_source);
            imgShader.SetInteger(imgShader.GetLocation("tex"), 0);
            vbo = new VertexBuffer(typeof(Vertex2D), MAX_VERT, true);
            el  = new ElementBuffer(MAX_INDEX);
            var indices = new ushort[MAX_INDEX];
            //vertices = new Vertex2D[MAX_VERT];
            int iptr = 0;

            for (int i = 0; i < MAX_VERT; i += 4)
            {
                /* Triangle 1 */
                indices[iptr++] = (ushort)i;
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 2);
                /* Triangle 2 */
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 3);
                indices[iptr++] = (ushort)(i + 2);
            }
            el.SetData(indices);
            vbo.SetElementBuffer(el);
            dot = new Texture2D(1, 1, false, SurfaceFormat.R8);
            dot.SetData(new byte[] { 255 });
        }
Beispiel #2
0
        internal Renderer2D(RenderContext rstate)
        {
            rs = rstate;
            string glslVer = GL.GLES ? "300 es\nprecision mediump float;" : "140";

            imgShader = new Shader(vertex_source.Replace("{0}", glslVer), img_fragment_source.Replace("{0}", glslVer));
            imgShader.SetInteger(imgShader.GetLocation("tex"), 4);
            blendLocation  = imgShader.GetLocation("blend");
            circleLocation = imgShader.GetLocation("circle");
            vbo            = new VertexBuffer(typeof(Vertex2D), MAX_VERT, true);
            el             = new ElementBuffer(MAX_INDEX);
            var indices = new ushort[MAX_INDEX];
            //vertices = new Vertex2D[MAX_VERT];
            int iptr = 0;

            for (int i = 0; i < MAX_VERT; i += 4)
            {
                /* Triangle 1 */
                indices[iptr++] = (ushort)i;
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 2);
                /* Triangle 2 */
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 3);
                indices[iptr++] = (ushort)(i + 2);
            }
            el.SetData(indices);
            vbo.SetElementBuffer(el);
            dot = new Texture2D(1, 1, false, SurfaceFormat.R8);
            dot.SetData(new byte[] { 255 });
        }
Beispiel #3
0
        public NebulaVertices()
        {
            var indices = new ushort[MAX_QUADS * 6];
            int iptr    = 0;

            for (int i = 0; i < (MAX_QUADS * 4); i += 4)
            {
                /* Triangle 1 */
                indices[iptr++] = (ushort)i;
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 2);
                /* Triangle 2 */
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 3);
                indices[iptr++] = (ushort)(i + 2);
            }
            vbo = new VertexBuffer(typeof(VertexPositionTexture), (MAX_QUADS * 4), true);
            el  = new ElementBuffer(indices.Length);
            el.SetData(indices);
            vbo.SetElementBuffer(el);
            shader    = ShaderCache.Get("NebulaInterior.vs", "NebulaInterior.frag").Shader;
            _viewproj = shader.GetLocation("ViewProjection");
            _world    = shader.GetLocation("World");
            _tint     = shader.GetLocation("Tint");
            _texture  = shader.GetLocation("Texture");
        }
Beispiel #4
0
 public void UnsetElementBuffer()
 {
     GLBind.VertexBuffer(VBO);
     GLBind.VertexArray(VAO);
     GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
     HasElements = false;
     _elements   = null;
 }
Beispiel #5
0
 public void SetElementBuffer(ElementBuffer elems)
 {
     GLBind.VertexBuffer(VBO);
     GLBind.VertexArray(VAO);
     GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, elems.Handle);
     HasElements = true;
     _elements   = elems;
 }
Beispiel #6
0
        //Code for baking an asteroid cube into a mesh
        void CreateBufferObject()
        {
            verts   = new List <VertexPositionNormalColorTexture>();
            indices = new List <ushort>();
            //Gather a list of all materials
            List <Material> mats = new List <Material>();

            if (field.AllowMultipleMaterials)
            {
                foreach (var ast in field.Cube)
                {
                    var l0 = (ast.Drawable as ModelFile).Levels[0];
                    for (int i = l0.StartMesh; i < l0.StartMesh + l0.MeshCount; i++)
                    {
                        var  m   = l0.Mesh.Meshes[i].Material;
                        bool add = true;
                        foreach (var mat in mats)
                        {
                            if (m.Name == mat.Name)
                            {
                                add = false;
                                break;
                            }
                        }
                        if (add)
                        {
                            mats.Add(m);
                        }
                    }
                }
            }
            else
            {
                var msh = (field.Cube[0].Drawable as ModelFile).Levels[0];
                mats.Add(msh.Mesh.Meshes[msh.StartMesh].Material);
            }
            //Create the draw calls
            foreach (var mat in mats)
            {
                var start = indices.Count;
                foreach (var ast in field.Cube)
                {
                    AddAsteroidToBuffer(ast, mat);
                }
                var count = indices.Count - start;
                cubeDrawCalls.Add(new DrawCall()
                {
                    Material = mat, StartIndex = start, Count = count
                });
            }
            cube_vbo = new VertexBuffer(typeof(VertexPositionNormalColorTexture), verts.Count);
            cube_ibo = new ElementBuffer(indices.Count);
            cube_ibo.SetData(indices.ToArray());
            cube_vbo.SetData(verts.ToArray());
            cube_vbo.SetElementBuffer(cube_ibo);
            verts   = null;
            indices = null;
        }
Beispiel #7
0
 public Billboards()
 {
     shaderBasic = Shaders.Billboard.Get();
     shaderBasic.Shader.SetInteger(shaderBasic.Shader.GetLocation("tex0"), 0);
     rendat   = new RenderData[MAX_BILLBOARDS];
     vboBasic = new VertexBuffer(typeof(BillboardVert), MAX_BILLBOARDS * 4, true);
     iboBasic = new ElementBuffer(MAX_BILLBOARDS * 6, true);
     vboBasic.SetElementBuffer(iboBasic);
 }
        public VertexResourceBuffer()
        {
            var ivert = (IVertexType)Activator.CreateInstance <T>();
            var decl  = ivert.GetVertexDeclaration();

            TotalVertex = VERTEX_BUFSIZE / decl.Stride;
            TotalIndex  = INDEX_BUFSIZE / 2;
            Elements    = new ElementBuffer(TotalIndex);
            Buffer      = new VertexBuffer(typeof(T), TotalVertex);
            Buffer.SetElementBuffer(Elements);
        }
Beispiel #9
0
 public Billboards()
 {
     shader = ShaderCache.Get(
         "Billboard.vs",
         "Billboard.frag"
         );
     shader.Shader.SetInteger(shader.Shader.GetLocation("tex0"), 0);
     vertices = new BillboardVert[MAX_BILLBOARDS * 4];
     rendat   = new RenderData[MAX_BILLBOARDS];
     vbo      = new VertexBuffer(typeof(BillboardVert), MAX_BILLBOARDS * 4, true);
     ibo      = new ElementBuffer(MAX_BILLBOARDS * 6, true);
     vbo.SetElementBuffer(ibo);
 }
Beispiel #10
0
        public BeamsBuffer()
        {
            var idx1 = ConstructIndices(spearIndices, MAX_BEAMS);

            bufferSpear = new VertexBuffer(typeof(VertexPositionColorTexture), MAX_BEAMS * 12, true);
            var el1 = new ElementBuffer(idx1.Length);

            el1.SetData(idx1);
            bufferSpear.SetElementBuffer(el1);
            var idx2 = ConstructIndices(boltIndices, MAX_BEAMS);

            bufferBolt = new VertexBuffer(typeof(VertexPositionColorTexture), MAX_BEAMS * 17, true);
            var el2 = new ElementBuffer(idx2.Length);

            el2.SetData(idx2);
            bufferBolt.SetElementBuffer(el2);
            shader = ShaderCache.Get("Projectile.vs", "Billboard.frag");
            shader.Shader.SetInteger(shader.Shader.GetLocation("tex0"), 0);
        }
        public StaticBillboards()
        {
            VertexBuffer = new VertexBuffer(typeof(VertexBillboardColor2), MAX_QUADS * 4);
            ibo          = new ElementBuffer(MAX_QUADS * 6);
            var indices = new ushort[MAX_QUADS * 6];
            int iptr    = 0;

            for (int i = 0; i < (MAX_QUADS * 4); i += 4)
            {
                /* Triangle 1 */
                indices[iptr++] = (ushort)i;
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 2);
                /* Triangle 2 */
                indices[iptr++] = (ushort)(i + 1);
                indices[iptr++] = (ushort)(i + 3);
                indices[iptr++] = (ushort)(i + 2);
            }
            ibo.SetData(indices);
            VertexBuffer.SetElementBuffer(ibo);
        }
Beispiel #12
0
        public Billboards()
        {
            shaderBasic = ShaderCache.Get(
                "Billboard.vs",
                "Billboard.frag"
                );
            shaderBasic.Shader.SetInteger(shaderBasic.Shader.GetLocation("tex0"), 0);
            shaderRect = ShaderCache.Get(
                "Polyline.vs",
                "Billboard.frag"
                );
            shaderRect.Shader.SetInteger(shaderRect.Shader.GetLocation("tex0"), 0);
            verticesBasic = new BillboardVert[MAX_BILLBOARDS * 4];
            rendat        = new RenderData[MAX_BILLBOARDS];
            vboBasic      = new VertexBuffer(typeof(BillboardVert), MAX_BILLBOARDS * 4, true);
            iboBasic      = new ElementBuffer(MAX_BILLBOARDS * 6, true);
            vboBasic.SetElementBuffer(iboBasic);

            vboRect = new VertexBuffer(typeof(VertexPositionColorTexture), MAX_BILLBOARDS * 4, true);
            iboRect = new ElementBuffer(MAX_BILLBOARDS * 6, true);
            vboRect.SetElementBuffer(iboRect);
        }