public Texture2D(int width, int height, bool hasMipMaps, SurfaceFormat format) : this(true) { Width = width; Height = height; Format = format; Format.GetGLFormat(out glInternalFormat, out glFormat, out glType); LevelCount = hasMipMaps ? CalculateMipLevels(width, height) : 1; currentLevels = hasMipMaps ? (LevelCount - 1) : 0; //Bind the new TextureD GLBind.Trash(); GLBind.BindTexture(4, GL.GL_TEXTURE_2D, ID); //initialise the texture data var imageSize = 0; Dxt1 = format == SurfaceFormat.Dxt1; if (glFormat == GL.GL_NUM_COMPRESSED_TEXTURE_FORMATS) { if (GLExtensions.S3TC) { switch (Format) { case SurfaceFormat.Dxt1: case SurfaceFormat.Dxt3: case SurfaceFormat.Dxt5: imageSize = ((Width + 3) / 4) * ((Height + 3) / 4) * format.GetSize(); break; default: throw new NotSupportedException(); } GL.CompressedTexImage2D(GL.GL_TEXTURE_2D, 0, glInternalFormat, Width, Height, 0, imageSize, IntPtr.Zero); } else { GL.TexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, Width, Height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, IntPtr.Zero); } } else { GL.TexImage2D(GL.GL_TEXTURE_2D, 0, glInternalFormat, Width, Height, 0, glFormat, glType, IntPtr.Zero); } //enable filtering GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); }
public void TrashGLState() { GLBind.Trash(); RenderState.Instance.Trash(); }
public void TrashGLState() { GLBind.Trash(); RenderContext.Instance.Trash(); }