Esempio n. 1
0
        public void Draw(RenderVM data)
        {
            GL.ClearColor(System.Drawing.Color.MidnightBlue);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.UseProgram(theProgram);
            foreach (var scene_kv in data.scenes)
            {
                var scene           = scene_kv.Value;
                var view_projection = scene.camera.GetViewProjectionMatrix();
                GL.UniformMatrix4(VP_Matrix_Unif, 1, false, ref view_projection.Row0.X);
                GL.BindBuffer(BufferTarget.ArrayBuffer, scene.position_buffer_id);
                // Write null to avoid implicit sync
                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(scene.position_data.Count * Vector3.SizeInBytes), IntPtr.Zero, BufferUsageHint.StreamDraw);
                GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, (IntPtr)(scene.position_data.Count * Vector3.SizeInBytes), scene.position_data.ToArray());

                // 2nd attribute buffer : instance position vectors
                GL.BindBuffer(BufferTarget.ArrayBuffer, scene.position_buffer_id);
                GL.EnableVertexAttribArray(1);
                GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 0, 0);

                GL.VertexAttribDivisor(1, 1); // positions : one per quad (its center) -> 1

                GL.DrawElementsInstanced(PrimitiveType.Triangles, scene.mesh.indices.Count, DrawElementsType.UnsignedInt, IntPtr.Zero, scene.position_data.Count);
            }
            GL.UseProgram(0);

            GL.Flush();
        }
Esempio n. 2
0
 public OpenGLRenderer(RenderVM render_data)
 {
     // shaderList = new List<int>();
     RenderVM              = render_data;
     RenderVM.SceneLoaded += LoadScenes;
 }