示例#1
0
        public BackgroundRenderer(IBackground background)
        {
            _program = new ShaderProgram("Shaders/Background.vert", "Shaders/Background.frag");
            _vao     = new VAO();
            var flatBuffer = new VBO();

            using (Bind.These(_vao, flatBuffer))
            {
                var data = new List <float>();
                data.AddRange(new float[] { -1, -1 });
                data.AddRange(background.BottomLeft.ToFloatArray());
                data.AddRange(new float[] { 1, -1 });
                data.AddRange(background.BottomRight.ToFloatArray());
                data.AddRange(new float[] { 1, 1 });
                data.AddRange(background.TopRight.ToFloatArray());
                data.AddRange(new float[] { -1, 1 });
                data.AddRange(background.TopLeft.ToFloatArray());
                var flatData = data.ToArray();
                flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                const int stride = sizeof(float) * 6;

                GL.EnableVertexAttribArray(0);
                GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, stride, new IntPtr(0));
                GL.EnableVertexAttribArray(1);
                GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, stride, new IntPtr(sizeof(float) * 2));
            }
        }
示例#2
0
        public PolygonLayerRenderer(IEnumerable <PolygonLayer> polygons)
        {
            _program = new ShaderProgram("Shaders/PolygonModel.vert", "Shaders/PolygonModel.frag");
            var polygonModel = polygons.First();

            _vao = new VAO();
            var flatBuffer = new VBO();

            using (Bind.These(_vao, flatBuffer))
            {
                var data = new List <float>();

                foreach (var edge in polygonModel.Polygons.SelectMany(p => p.Edges))
                {
                    count++;
                    data.AddRange(edge.Start.Position.ToArray().Select(d => (float)d));
                    data.AddRange(edge.Start.Color.ToFloatArray());
                    data.AddRange(edge.End.Position.ToArray().Select(d => (float)d));
                    data.AddRange(Color.Aqua.ToFloatArray());
                }

                var flatData = data.ToArray();
                flatBuffer.Update(flatData, flatData.Length * sizeof(float));

                const int stride = sizeof(float) * 7;

                GL.EnableVertexAttribArray(0);
                GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, stride, new IntPtr(0));
                GL.EnableVertexAttribArray(1);
                GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, stride, new IntPtr(sizeof(float) * 3));
            }
        }
示例#3
0
        protected override int Submit(Instance[] instances, int count)
        {
            Array.Sort(keys, instances, 0, count);

            var ncalls = 0;

            var i = 0;

            while (i < count)
            {
                // find the range of the group.
                var k = keys[i].key;
                var j = i;
                while (j < count && k.CompareTo(keys[j].key) == 0)
                {
                    j++;
                }

                var range = j - i;

                // copy the range to the gpu.
                VBO.Update(instances, i, 0, range);

                // submit the render call
                Submit(k, range);
                ncalls++;

                i = j;
            }

            return(ncalls);
        }
示例#4
0
        public OctreeRenderer(OctreeModel model, OpenGL gl)
        {
            _gl            = gl;
            _octreeProgram = new OctreeShader(gl);
            _cubes         = new VAO(gl);
            _cubeBuffer    = new VBO(gl);


            var filled = model.Node.Flatten().Where(o => o.State == NodeState.Filled).ToArray();

            _count = filled.Length;
            var list = new List <float>();

            foreach (var octreeNode in filled)
            {
                list.AddRange(octreeNode.Center.ToArray().Select(d => (float)d));

                list.AddRange(new[]
                {
                    (float)MathsHelper.Map(octreeNode.Color.R, 0, 255, 0, 1),
                    (float)MathsHelper.Map(octreeNode.Color.G, 0, 255, 0, 1),
                    (float)MathsHelper.Map(octreeNode.Color.B, 0, 255, 0, 1),
                    (float)MathsHelper.Map(octreeNode.Color.A, 0, 255, 0, 1),
                    (float)octreeNode.Size
                });
            }

            var vertices = list.ToArray();

            using (new Bind(_cubes))
                using (new Bind(_cubeBuffer))
                {
                    _cubeBuffer.Update(vertices, vertices.Length * sizeof(float));
                    const int stride = sizeof(float) * 8;
                    gl.EnableVertexAttribArray(0);
                    gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, stride, new IntPtr(0));


                    gl.EnableVertexAttribArray(1);
                    gl.VertexAttribPointer(1, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 3));

                    gl.EnableVertexAttribArray(2);

                    gl.VertexAttribPointer(2, 1, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 7));
                    gl.BindVertexArray(0);
                }
        }
示例#5
0
        public GUIRenderer()
        {
            Texture  = new Texture();
            _program = new ShaderProgram("Shaders/GUI.vert", "Shaders/GUI.frag");
            _vao     = new VAO();
            var flatBuffer = new VBO();

            using (Bind.These(_vao, flatBuffer))
            {
                var flatData = new float[] { -1, -1, 0, 1, 1, -1, 1, 1, 1, 1, 1, 0, -1, 1, 0, 0 };
                flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                const int stride = sizeof(float) * 4;
                GL.EnableVertexAttribArray(0);
                GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, stride, new IntPtr(0));
                GL.EnableVertexAttribArray(1);
                GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, stride, new IntPtr(sizeof(float) * 2));
            }
        }
示例#6
0
        public BackgroundRenderer(OpenGL gl)
        {
            _gl = gl;

            _program    = new BackgroundShader(gl);
            _flat       = new VAO(gl);
            _flatBuffer = new VBO(gl);

            using (new Bind(_flat))
                using (new Bind(_flatBuffer))
                {
                    var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
                    _flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                    gl.EnableVertexAttribArray(0);
                    gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
                    gl.BindVertexArray(0);
                }
        }
示例#7
0
        public PostProcesser(OpenGL gl, int width, int height)
        {
            _gl  = gl;
            _fbo = new FBO(gl, width, height);

            _flatProgram = new FlatShader(gl);

            _flat       = new VAO(gl);
            _flatBuffer = new VBO(gl);

            using (new Bind(_flat))
                using (new Bind(_flatBuffer))
                {
                    var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
                    _flatBuffer.Update(flatData, flatData.Length * sizeof(float));
                    gl.EnableVertexAttribArray(0);
                    gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
                    gl.BindVertexArray(0);
                }
        }
示例#8
0
        public PointRenderer(OpenGL gl, IStaticScene scene)
        {
            _gl    = gl;
            _scene = scene;

            _program = new ShaderBindable(gl, "Shaders/Point.vert", "Shaders/Point.frag");
            _vao     = new VAO(gl);
            _vbo     = new VBO(gl);

            using (Bind.These(_vao, _vbo))
            {
                count = scene.Points.Count;

                _vbo.Update(scene.Points.Select(p => new Vertex(p.Position, p.Color)));

                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, Vertex.Stride, new IntPtr(0));

                gl.EnableVertexAttribArray(1);
                gl.VertexAttribPointer(1, 4, OpenGL.GL_FLOAT, false, Vertex.Stride, new IntPtr(sizeof(float) * 3));
            }
        }
示例#9
0
        public BackgroundRenderer(OpenGL gl, IBackground background)
        {
            _gl      = gl;
            _program = new ShaderBindable(gl, "Shaders/Background.vert", "Shaders/Background.frag");

            _vao = new VAO(gl);
            var flatBuffer = new VBO(gl);

            using (new Bind(_vao))
                using (new Bind(flatBuffer))
                {
                    var data = new List <float>();
                    data.AddRange(new float[] { -1, -1 });
                    data.AddRange(background.BottomLeft.ToFloatArray());
                    data.AddRange(new float[] { 1, -1 });
                    data.AddRange(background.BottomRight.ToFloatArray());
                    data.AddRange(new float[] { 1, 1 });
                    data.AddRange(background.TopRight.ToFloatArray());
                    data.AddRange(new float[] { -1, 1 });
                    data.AddRange(background.TopLeft.ToFloatArray());

                    var flatData = data.ToArray();

                    flatBuffer.Update(flatData, flatData.Length * sizeof(float));

                    const int stride = sizeof(float) * 6;

                    gl.EnableVertexAttribArray(0);
                    gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, stride, new IntPtr(0));

                    gl.EnableVertexAttribArray(1);
                    gl.VertexAttribPointer(1, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 2));

                    gl.BindVertexArray(0);
                }
        }
示例#10
0
 protected override int Submit(Instance[] instances, int count)
 {
     VBO.Update(instances, 0, count);
     Submit(count);
     return(1);
 }