/// <summary> /// Texture. /// </summary> /// <param name="imageBuilder"></param> /// <param name="parameters"></param> /// <param name="mipmapFiltering"></param> /// <param name="target"></param> public Texture(NewImageBuilder imageBuilder, SamplerParameters parameters = null, MipmapFilter mipmapFiltering = MipmapFilter.LinearMipmapLinear, BindTextureTarget target = BindTextureTarget.Texture2D) : this(imageBuilder, new FakeSampler(parameters, mipmapFiltering), target) { }
public Texture(BindTextureTarget target, uint id) { this.Target = target; this.Id = id; this.InitParameters(); // TODO: Is this needed? }
private void BindTexture(BindTextureTarget target, uint name) { if (!Enum.IsDefined(typeof(BindTextureTarget), target)) { SetLastError(ErrorCode.InvalidEnum); return; } if ((name != 0) && (!this.textureNameList.Contains(name))) { SetLastError(ErrorCode.InvalidValue); return; } Texture texture = null; if (name != 0) { Dictionary <uint, Texture> dict = this.nameTextureDict; if (dict.TryGetValue(name, out texture)) { if (texture.Target != target) { SetLastError(ErrorCode.InvalidOperation); return; } } else // create a new texture object. { texture = new Texture(target, name); dict.Add(name, texture); } } this.SetCurrentTexture(target, texture); }
private void SetCurrentTexture(BindTextureTarget target, Texture texture) { TextureUnit currentUnit = this.textureUnits[this.currentTextureUnitIndex]; switch (target) { case BindTextureTarget.Texture1D: currentUnit.texture1D = texture; break; case BindTextureTarget.Texture2D: currentUnit.texture2D = texture; break; case BindTextureTarget.Texture3D: currentUnit.texture3D = texture; break; case BindTextureTarget.Texture1DArray: currentUnit.texture1DArray = texture; break; case BindTextureTarget.Texture2DArray: currentUnit.texture2DArray = texture; break; case BindTextureTarget.TextureRectangle: currentUnit.textureRectangle = texture; break; case BindTextureTarget.TextureCubeMap: currentUnit.textureCubeMap = texture; break; case BindTextureTarget.Texture2DMultisample: currentUnit.texture2DMultisample = texture; break; case BindTextureTarget.Texture2DMultisampleArray: currentUnit.texture2DMultisampleArray = texture; break; case BindTextureTarget.TextureBuffer: currentUnit.textureBuffer = texture; break; case BindTextureTarget.TextureCubeMapArray: currentUnit.textureCubeMapArray = texture; break; default: throw new NotImplementedException(); } }
private Texture GetCurrentTexture(BindTextureTarget target) { Texture texture = null; TextureUnit currentUnit = this.textureUnits[this.currentTextureUnitIndex]; switch (target) { case BindTextureTarget.Texture1D: texture = currentUnit.texture1D; break; case BindTextureTarget.Texture2D: texture = currentUnit.texture2D; break; case BindTextureTarget.Texture3D: texture = currentUnit.texture3D; break; case BindTextureTarget.Texture1DArray: texture = currentUnit.texture1DArray; break; case BindTextureTarget.Texture2DArray: texture = currentUnit.texture2DArray; break; case BindTextureTarget.TextureRectangle: texture = currentUnit.textureRectangle; break; case BindTextureTarget.TextureCubeMap: texture = currentUnit.textureCubeMap; break; case BindTextureTarget.Texture2DMultisample: texture = currentUnit.texture2DMultisample; break; case BindTextureTarget.Texture2DMultisampleArray: texture = currentUnit.texture2DMultisampleArray; break; case BindTextureTarget.TextureBuffer: texture = currentUnit.textureBuffer; break; case BindTextureTarget.TextureCubeMapArray: texture = currentUnit.textureCubeMapArray; break; default: throw new NotImplementedException(); } return(texture); }
/// <summary> /// Texture. /// </summary> /// <param name="bitmap"></param> /// <param name="parameters"></param> /// <param name="mipmapFiltering"></param> /// <param name="target"></param> public Texture(Bitmap bitmap, SamplerParameters parameters = null, MipmapFilter mipmapFiltering = MipmapFilter.LinearMipmapLinear, BindTextureTarget target = BindTextureTarget.Texture2D) : this(new NewBitmapBuilder(bitmap), new FakeSampler(parameters, mipmapFiltering), target) { }
/// <summary> /// /// </summary> public void Initialize(uint unit, BindTextureTarget target) { if (!this.initialized) { this.DoInitialize(unit, target); this.initialized = true; } }
public static samplerValue Parse(string value) { string[] parts = value.Split(separator, StringSplitOptions.RemoveEmptyEntries); BindTextureTarget target = (BindTextureTarget)Enum.Parse(typeof(BindTextureTarget), parts[1]); uint textureId = uint.Parse(parts[3]); uint activeTextureIndex = uint.Parse(parts[5]); return(new samplerValue(target, textureId, activeTextureIndex)); }
/// <summary> /// texture's settings. /// </summary> /// <param name="unit"></param> /// <param name="target"></param> public override void Bind(uint unit, BindTextureTarget target) { if (!this.initialized) { this.Initialize(unit, target); } OpenGL.BindSampler(unit, this.Id); }
void ILoadFromString.Load(string value) { string[] parts = value.Split(separator, StringSplitOptions.RemoveEmptyEntries); BindTextureTarget target = (BindTextureTarget)Enum.Parse(typeof(BindTextureTarget), parts[1]); uint textureId = uint.Parse(parts[3]); uint activeTextureIndex = uint.Parse(parts[5]); this.target = (uint)target; this.textureId = textureId; this.activeTextureIndex = (activeTextureIndex - OpenGL.GL_TEXTURE0); }
/// <summary> /// texture's settings. /// </summary> /// <param name="unit"></param> /// <param name="target"></param> public override void Bind(uint unit, BindTextureTarget target) { /* Clamping to edges is important to prevent artifacts when scaling */ OpenGL.TexParameteri((uint)target, OpenGL.GL_TEXTURE_WRAP_R, (int)this.parameters.wrapR); OpenGL.TexParameteri((uint)target, OpenGL.GL_TEXTURE_WRAP_S, (int)this.parameters.wrapS); OpenGL.TexParameteri((uint)target, OpenGL.GL_TEXTURE_WRAP_T, (int)this.parameters.wrapT); /* Linear filtering usually looks best for text */ OpenGL.TexParameteri((uint)target, OpenGL.GL_TEXTURE_MIN_FILTER, (int)this.parameters.minFilter); OpenGL.TexParameteri((uint)target, OpenGL.GL_TEXTURE_MAG_FILTER, (int)this.parameters.magFilter); // TODO: mipmap filter not working yet. }
/// <summary> /// Texture. /// </summary> /// <param name="imageBuilder"></param> /// <param name="samplerBuilder"></param> /// <param name="target"></param> public Texture(NewImageBuilder imageBuilder, SamplerBase samplerBuilder, BindTextureTarget target = BindTextureTarget.Texture2D) { if (imageBuilder == null || samplerBuilder == null) { throw new ArgumentNullException(); } this.ImageBuilder = imageBuilder; this.SamplerBuilder = samplerBuilder; this.ActiveTexture = OpenGL.GL_TEXTURE0; this.Target = target; }
private void TexParameterf(BindTextureTarget target, uint pname, float param) { if (!Enum.IsDefined(typeof(BindTextureTarget), target)) { SetLastError(ErrorCode.InvalidEnum); return; } Texture texture = this.GetCurrentTexture(target); if (texture != null) { texture.SetProperty(pname, param); } }
private void DoInitialize(uint unit, BindTextureTarget target) { var ids = new uint[1]; OpenGL.GenSamplers(1, ids); this.Id = ids[0]; //OpenGL.BindSampler(unit, ids[0]); OpenGL.BindSampler(unit, ids[0]); /* Clamping to edges is important to prevent artifacts when scaling */ OpenGL.SamplerParameteri(ids[0], OpenGL.GL_TEXTURE_WRAP_R, (int)this.parameters.wrapR); OpenGL.SamplerParameteri(ids[0], OpenGL.GL_TEXTURE_WRAP_S, (int)this.parameters.wrapS); OpenGL.SamplerParameteri(ids[0], OpenGL.GL_TEXTURE_WRAP_T, (int)this.parameters.wrapT); /* Linear filtering usually looks best for text */ OpenGL.SamplerParameteri(ids[0], OpenGL.GL_TEXTURE_MIN_FILTER, (int)this.parameters.minFilter); OpenGL.SamplerParameteri(ids[0], OpenGL.GL_TEXTURE_MAG_FILTER, (int)this.parameters.magFilter); // TODO: mipmap not used yet. OpenGL.BindSampler(unit, 0); }
/// <summary> /// build texture's content with Bitmap. /// </summary> public override void Build(BindTextureTarget target) { // generate texture. // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); if (target == BindTextureTarget.Texture1D) { OpenGL.TexImage1D((uint)target, 0, (int)OpenGL.GL_RGBA, bitmap.Width, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); } else if (target == BindTextureTarget.Texture2D) { OpenGL.TexImage2D((uint)target, 0, (int)OpenGL.GL_RGBA, bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); } else { throw new NotImplementedException(); } // Unlock the image. bitmap.UnlockBits(bitmapData); }
/// <summary> /// Texture. /// </summary> /// <param name="bitmap"></param> /// <param name="samplerBuilder"></param> /// <param name="target"></param> public Texture(Bitmap bitmap, SamplerBase samplerBuilder, BindTextureTarget target = BindTextureTarget.Texture2D) : this(new NewBitmapBuilder(bitmap), samplerBuilder, target) { }
/// <summary> /// /// </summary> /// <param name="target"></param> public abstract void Apply(BindTextureTarget target);
/// <summary> /// /// </summary> /// <param name="target"></param> public override void Apply(BindTextureTarget target) { GL.Instance.TexParameteri((uint)target, PName, PValue); }
/// <summary> /// /// </summary> public abstract void Bind(uint unit, BindTextureTarget target);
/// <summary> /// build texture's content. /// </summary> /// <returns></returns> public abstract void Build(BindTextureTarget target);
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="textureId"></param> /// <param name="activeTextureIndex">OpenGL.GL_TEXTURE0 etc</param> public samplerValue(BindTextureTarget target, uint textureId, uint activeTextureIndex) { this.target = (uint)target; this.textureId = textureId; this.activeTextureIndex = (activeTextureIndex - OpenGL.GL_TEXTURE0); }