Ejemplo n.º 1
0
        public static void Create(Query[] queries, int index, int count)
        {
            if (queries == null)
            {
                throw new ArgumentNullException("queries");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", index, "index is less than 0.");
            }
            if (index + count > queries.Length)
            {
                throw new ArgumentOutOfRangeException("count", count, "index + count is greater than queries.Length.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", count, "count is less than 0.");
            }

            unsafe
            {
                uint *ids = stackalloc uint[count];
                Gl.GenQueries(count, ids);
                GlHelper.GetError();
                for (int i = 0; i < count; ++i)
                {
                    var query = new Query();
                    query.Id           = ids[i];
                    queries[index + i] = query;
                }
            }
        }
Ejemplo n.º 2
0
        public static void Create(Buffer[] buffers, int index, int count)
        {
            if (buffers == null)
            {
                throw new ArgumentNullException("buffers");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", index, "index is less than 0.");
            }
            if (index + count > buffers.Length)
            {
                throw new ArgumentOutOfRangeException("count", count, "index + count is greater than buffers.Length.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", count, "count is less than 0.");
            }

            unsafe
            {
                uint *ids = stackalloc uint[count];
                Gl.GenBuffers(count, ids);
                GlHelper.GetError();
                for (int i = 0; i < count; ++i)
                {
                    var buffer = new Buffer();
                    buffer.Id          = ids[i];
                    buffers[index + i] = buffer;
                }
            }
        }
Ejemplo n.º 3
0
 public bool Link()
 {
     GlHelper.ThrowNullException(Id);
     Gl.LinkProgram(Id);
     GlHelper.GetError();
     return(Status);
 }
Ejemplo n.º 4
0
 public bool Compile()
 {
     GlHelper.ThrowNullException(Id);
     Gl.CompileShader(Id);
     GlHelper.GetError();
     return(Status);
 }
Ejemplo n.º 5
0
        public static void Create(VertexArray[] arrays, int index, int count)
        {
            if (arrays == null)
            {
                throw new ArgumentNullException("arrays");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", index, "index is less than 0.");
            }
            if (index + count > arrays.Length)
            {
                throw new ArgumentOutOfRangeException("count", count, "index + count is greater than arrays.Length.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", count, "count is less than 0.");
            }

            unsafe
            {
                uint *ids = stackalloc uint[count];
                Gl.GenVertexArrays(count, ids);
                GlHelper.GetError();
                for (int i = 0; i < count; ++i)
                {
                    var array = new VertexArray();
                    array.Id          = ids[i];
                    arrays[index + i] = array;
                }
            }
        }
Ejemplo n.º 6
0
        public static void Create(Texture[] textures, int index, int count)
        {
            if (textures == null)
            {
                throw new ArgumentNullException("textures");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", index, "index is less than 0.");
            }
            if (index + count > textures.Length)
            {
                throw new ArgumentOutOfRangeException("count", count, "index + count is greater than textures.Length.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", count, "count is less than 0.");
            }

            unsafe
            {
                uint *ids = stackalloc uint[count];
                Gl.GenTextures(count, ids);
                GlHelper.GetError();
                for (int i = 0; i < count; ++i)
                {
                    var texture = new Texture();
                    texture.Id          = ids[i];
                    textures[index + i] = texture;
                }
            }
        }
Ejemplo n.º 7
0
 public void VertexAttributePointer(int size, DataType type, bool normalized, int stride, int offset)
 {
     unsafe
     {
         Gl.VertexAttribPointer(Index, size, (uint)type, (byte)(normalized ? 1 : 0), stride, (void *)offset);
         GlHelper.GetError();
     }
 }
Ejemplo n.º 8
0
 public static void SetUniform(int location, Ibasa.Numerics.Matrix4x3f value)
 {
     unsafe
     {
         Gl.UniformMatrix4x3fv(location, 1, 0, (float *)(&value));
         GlHelper.GetError();
     }
 }
Ejemplo n.º 9
0
 public static void SetUniform(int location, Ibasa.Interop.UnmanagedArray <Ibasa.Numerics.Matrix4x3f> value)
 {
     unsafe
     {
         Gl.UniformMatrix4x3fv(location, value.Count, 0, (float *)value.Pointer.ToPointer());
         GlHelper.GetError();
     }
 }
Ejemplo n.º 10
0
 public static void SetUniform(int location, Ibasa.Interop.UnmanagedArray <Ibasa.Numerics.Vector4ui> value)
 {
     unsafe
     {
         Gl.Uniform4uiv(location, value.Count, (uint *)value.Pointer.ToPointer());
         GlHelper.GetError();
     }
 }
Ejemplo n.º 11
0
 public static void SetUniform(int location, Ibasa.Interop.UnmanagedArray <int> value)
 {
     unsafe
     {
         Gl.Uniform1iv(location, value.Count, (int *)value.Pointer.ToPointer());
         GlHelper.GetError();
     }
 }
Ejemplo n.º 12
0
 public void GetBufferSubData(long offset, long size, IntPtr data)
 {
     unsafe
     {
         Gl.GetBufferSubData(Target, (void *)offset, (void *)size, data.ToPointer());
         GlHelper.GetError();
     }
 }
Ejemplo n.º 13
0
 public void BufferData(long size, IntPtr data, Usage usage)
 {
     unsafe
     {
         Gl.BufferData(Target, (void *)size, data.ToPointer(), (uint)usage);
         GlHelper.GetError();
     }
 }
Ejemplo n.º 14
0
 public static void DrawElements(PrimitiveTopology topology, int count, DataType type, int offset, int basevertex)
 {
     unsafe
     {
         Gl.DrawElementsBaseVertex((uint)topology, count, (uint)type, (void *)offset, basevertex);
         GlHelper.GetError();
     }
 }
Ejemplo n.º 15
0
 public static void DrawElements(PrimitiveTopology topology, int count, DataType type, IntPtr indices, int basevertex)
 {
     unsafe
     {
         Gl.DrawElementsBaseVertex((uint)topology, count, (uint)type, indices.ToPointer(), basevertex);
         GlHelper.GetError();
     }
 }
Ejemplo n.º 16
0
 public IntPtr Map(MapAccess access)
 {
     unsafe
     {
         var result = Gl.MapBuffer(Target, (uint)access);
         GlHelper.GetError();
         return(new IntPtr(result));
     }
 }
Ejemplo n.º 17
0
 public static Sync Fence()
 {
     unsafe
     {
         var handle = Gl.FenceSync(Gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
         GlHelper.GetError();
         return(new Sync(new IntPtr(handle)));
     }
 }
Ejemplo n.º 18
0
        public void Unmap()
        {
            bool result = Gl.UnmapBuffer(Target) != 0;

            GlHelper.GetError();
            if (!result)
            {
                throw new OpenGLException("glUnmapBuffer returned false.");
            }
        }
Ejemplo n.º 19
0
 public void Delete()
 {
     unsafe
     {
         GlHelper.ThrowNullException(Handle);
         Gl.DeleteSync(Handle.ToPointer());
         Handle = IntPtr.Zero;
         GlHelper.GetError();
     }
 }
Ejemplo n.º 20
0
 public static Shader Create(ShaderType type)
 {
     unsafe
     {
         uint id = Gl.CreateShader((uint)type);
         GlHelper.GetError();
         var shader = new Shader();
         shader.Id = id;
         return(shader);
     }
 }
Ejemplo n.º 21
0
 public static Program Create()
 {
     unsafe
     {
         uint id = Gl.CreateProgram();
         GlHelper.GetError();
         var program = new Program();
         program.Id = id;
         return(program);
     }
 }
Ejemplo n.º 22
0
 public static Buffer Create()
 {
     unsafe
     {
         uint id;
         Gl.GenBuffers(1, &id);
         GlHelper.GetError();
         var buffer = new Buffer();
         buffer.Id = id;
         return(buffer);
     }
 }
Ejemplo n.º 23
0
 public static Query Create()
 {
     unsafe
     {
         uint id;
         Gl.GenQueries(1, &id);
         GlHelper.GetError();
         var query = new Query();
         query.Id = id;
         return(query);
     }
 }
Ejemplo n.º 24
0
 public static VertexArray Create()
 {
     unsafe
     {
         uint id;
         Gl.GenVertexArrays(1, &id);
         GlHelper.GetError();
         var array = new VertexArray();
         array.Id = id;
         return(array);
     }
 }
Ejemplo n.º 25
0
 public static Texture Create()
 {
     unsafe
     {
         uint id;
         Gl.GenTextures(1, &id);
         GlHelper.GetError();
         var texture = new Texture();
         texture.Id = id;
         return(texture);
     }
 }
Ejemplo n.º 26
0
        public static void Wait(Sync sync)
        {
            if (sync == Sync.Null)
            {
                throw new ArgumentNullException("sync");
            }

            unsafe
            {
                Gl.WaitSync(sync.Handle.ToPointer(), 0, Gl.TIMEOUT_IGNORED);
                GlHelper.GetError();
            }
        }
Ejemplo n.º 27
0
        public int GetUniformLocation(string name)
        {
            GlHelper.ThrowNullException(Id);
            unsafe
            {
                int   bytes = Encoding.ASCII.GetByteCount(name);
                byte *str   = stackalloc byte[bytes + 1];
                str[bytes] = 0; //null terminated string

                fixed(char *name_ptr = name)
                {
                    Encoding.ASCII.GetBytes(name_ptr, name.Length, str, bytes);
                }

                var location = Gl.GetUniformLocation(Id, str);
                GlHelper.GetError();
                return(location);
            }
        }
Ejemplo n.º 28
0
        public static SyncStatus ClientWait(Sync sync, bool flush, TimeSpan timeout)
        {
            if (sync == Sync.Null)
            {
                throw new ArgumentNullException("sync");
            }

            unsafe
            {
                uint result = Gl.ClientWaitSync(
                    sync.Handle.ToPointer(),
                    flush ? Gl.SYNC_FLUSH_COMMANDS_BIT : 0,
                    (ulong)timeout.Ticks * 100);

                GlHelper.GetError();

                return((SyncStatus)result);
            }
        }
Ejemplo n.º 29
0
 public void DetachShader(Shader shader)
 {
     GlHelper.ThrowNullException(Id);
     Gl.DetachShader(Id, shader.Id);
     GlHelper.GetError();
 }
Ejemplo n.º 30
0
 public void Bind(Texture texture)
 {
     GlHelper.ThrowNullException(Target);
     Gl.BindTexture(Target, texture.Id);
     GlHelper.GetError();
 }