<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpGL
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Texture : IDisposable
    {
        /// <summary>
        /// 0 means GL.GL_TEXTURE0, 1 means GL.GL_TEXTURE1, ...
        /// </summary>
        public uint TextureUnitIndex { get; set; }

        /// <summary>
        /// binding target of this texture.
        /// </summary>
        public TextureTarget Target { get; protected set; }

        /// <summary>
        /// texture's id/name from glGenTextures().
        /// 纹理名（用于标识一个纹理，由OpenGL指定）。
        /// </summary>
        protected uint[] ids = new uint[1];

        /// <summary>
        /// texture's id/name from glGenTextures().
        /// 纹理名（用于标识一个纹理，由OpenGL指定）。
        /// </summary>
        public uint Id { get { return this.ids[0]; } }

        ///// <summary>
        /////
        ///// </summary>
        //public bool UseMipmap { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="target"></param>
        /// <param name="storage"></param>
        /// <param name="texParameters"></param>
        public Texture(TextureTarget target, TexStorageBase storage, params TexParameter[] texParameters)
        {
            this.Target = target;
            this.Storage = storage;
            this.builtInSampler.AddRange(texParameters);
        }
        /// <summary>
        ///
        /// </summary>
        public void Bind()
        {
            GL.Instance.BindTexture((uint)this.Target, this.Id);
        }

        /// <summary>
        ///
        /// </summary>
        public void Unbind()
        {
            GL.Instance.BindTexture((uint)this.Target, 0);
        }

        private bool initialized = false;

        /// <summary>
        /// resources(bitmap etc.) can be disposed  after this initialization.
        /// </summary>
        public void Initialize()
        {
            if (!this.initialized)
            {
                GL.Instance.GenTextures(1, ids);
                TextureTarget target = this.Target;
                GL.Instance.BindTexture((uint)target, ids[0]);
                this.Storage.Apply();
                this.BuiltInSampler.Apply(this.Target);
                //OpenGL.GenerateMipmap((MipmapTarget)((uint)target));// TODO: does this work?
                GL.Instance.BindTexture((uint)this.Target, 0);
                this.initialized = true;
            }
        }

        /// <summary>
        /// setup texture's image data.
        /// </summary>
        public TexStorageBase Storage { get; private set; }

        private BuiltInSampler builtInSampler = new BuiltInSampler();

        /// <summary>
        /// setup texture's sampler properties with default built-in sampler object.
        /// </summary>
        public BuiltInSampler BuiltInSampler
        {
            get { return builtInSampler; }
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("Target:{0}, Id:{1}", this.Target, this.Id);
        }
    }
}<commit_msg>Generates mipmap for texture<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpGL
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Texture : IDisposable
    {
        /// <summary>
        /// 0 means GL.GL_TEXTURE0, 1 means GL.GL_TEXTURE1, ...
        /// </summary>
        public uint TextureUnitIndex { get; set; }

        /// <summary>
        /// binding target of this texture.
        /// </summary>
        public TextureTarget Target { get; protected set; }

        /// <summary>
        /// texture's id/name from glGenTextures().
        /// 纹理名（用于标识一个纹理，由OpenGL指定）。
        /// </summary>
        protected uint[] ids = new uint[1];

        /// <summary>
        /// texture's id/name from glGenTextures().
        /// 纹理名（用于标识一个纹理，由OpenGL指定）。
        /// </summary>
        public uint Id { get { return this.ids[0]; } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="target"></param>
        /// <param name="storage"></param>
        /// <param name="texParameters"></param>
        public Texture(TextureTarget target, TexStorageBase storage, params TexParameter[] texParameters)
        {
            this.Target = target;
            this.Storage = storage;
            this.builtInSampler.AddRange(texParameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="target"></param>
        /// <param name="storage"></param>
        /// <param name="mipmapBuilder"></param>
        /// <param name="texParameters"></param>
        public Texture(TextureTarget target, TexStorageBase storage, MipmapBuilder mipmapBuilder, params TexParameter[] texParameters)
        {
            this.Target = target;
            this.Storage = storage;
            this.mipmapBuilder = mipmapBuilder;
            this.builtInSampler.AddRange(texParameters);
        }

        /// <summary>
        ///
        /// </summary>
        public void Bind()
        {
            GL.Instance.BindTexture((uint)this.Target, this.Id);
        }

        /// <summary>
        ///
        /// </summary>
        public void Unbind()
        {
            GL.Instance.BindTexture((uint)this.Target, 0);
        }

        private bool initialized = false;

        /// <summary>
        /// resources(bitmap etc.) can be disposed  after this initialization.
        /// </summary>
        public void Initialize()
        {
            if (!this.initialized)
            {
                GL.Instance.GenTextures(1, ids);
                TextureTarget target = this.Target;
                GL.Instance.BindTexture((uint)target, ids[0]);

                this.Storage.Apply();
                this.builtInSampler.Apply(this.Target);
                MipmapBuilder mipmapBuilder = this.mipmapBuilder;
                if (mipmapBuilder != null) { mipmapBuilder.GenerateMipmmap((uint)this.Target); }

                GL.Instance.BindTexture((uint)this.Target, 0);

                this.initialized = true;
            }
        }

        /// <summary>
        /// setup texture's image data.
        /// </summary>
        public TexStorageBase Storage { get; private set; }

        private BuiltInSampler builtInSampler = new BuiltInSampler();

        /// <summary>
        /// setup texture's sampler properties with default built-in sampler object.
        /// </summary>
        public BuiltInSampler BuiltInSampler
        {
            get { return builtInSampler; }
        }

        private MipmapBuilder mipmapBuilder;

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("Target:{0}, Id:{1}", this.Target, this.Id);
        }
    }
}
{'fraction_non_alphanumeric': 0.13924586922751023, 'fraction_numerical': 0.0033893517864708373, 'mean_word_length': 1.5060155697098372, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4808065', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1904, 'n_words': 415}