Ejemplo n.º 1
0
        public Texture CreateFromBytes(byte[] data, int width, int height, uint format, uint type)
        {
            uint textureId;

            uint[] tex = new uint[1];

            NativeGl.glGenTextures(1, tex);

            textureId = tex[0];

            NativeGl.glActiveTexture(NativeGl.GL_TEXTURE0);
            NativeGl.glBindTexture(NativeGl.GL_TEXTURE_2D, textureId);

            var handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_MIN_FILTER, NativeGl.GL_LINEAR);
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_MAG_FILTER, NativeGl.GL_LINEAR);
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_WRAP_S, NativeGl.GL_CLAMP_TO_EDGE);
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_WRAP_T, NativeGl.GL_CLAMP_TO_EDGE);

                NativeGl.glTexImage2D(
                    NativeGl.GL_TEXTURE_2D,
                    0,
                    (int)format,
                    width,
                    height,
                    0,
                    format,
                    type,
                    handle.AddrOfPinnedObject());
            }
            catch (Exception x)
            {
                NativeGl.glDeleteTextures(1, tex);
                throw;
            }
            finally
            {
                handle.Free();
            }

            NativeGl.glBindTexture(NativeGl.GL_TEXTURE_2D, 0);

            var texture = new Texture(NativeGl.GL_TEXTURE_2D, textureId);

            return(texture);
        }
Ejemplo n.º 2
0
 public void ActivateTextureUnit(TextureUnit textureUnit)
 {
     NativeGl.glActiveTexture((uint)textureUnit);
 }