public OpenGLESTexture2D( int mipLevels, int width, int height, PixelFormat veldridFormat, OpenTK.Graphics.ES30.PixelFormat pixelFormat, PixelType pixelType) : base(TextureTarget.Texture2D, width, height) { MipLevels = mipLevels; _veldridFormat = veldridFormat; _pixelFormat = pixelFormat; _pixelType = pixelType; _texComponentCount = OpenGLESFormats.MapTextureComponentCount(veldridFormat, pixelFormat == OpenTK.Graphics.ES30.PixelFormat.DepthComponent); Bind(); for (int currentLevel = 0; currentLevel < mipLevels; currentLevel++) { // Set size, load empty data into texture GL.TexImage2D( TextureTarget2d.Texture2D, currentLevel, _texComponentCount, width, height, 0, // border _pixelFormat, _pixelType, IntPtr.Zero); Utilities.CheckLastGLES3Error(); width = Math.Max(1, width / 2); height = Math.Max(1, height / 2); } }
public OpenGLESCubemapTexture( IntPtr pixelsFront, IntPtr pixelsBack, IntPtr pixelsLeft, IntPtr pixelsRight, IntPtr pixelsTop, IntPtr pixelsBottom, int width, int height, PixelFormat format) : base(TextureTarget.TextureCubeMap, width, height) { _texComponentCount = OpenGLESFormats.MapTextureComponentCount(format, false); _format = OpenGLESFormats.MapPixelFormat(format); _type = OpenGLESFormats.MapPixelType(format); Bind(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMagFilter.Linear); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge); Utilities.CheckLastGLES3Error(); SetFacePixels(0, pixelsRight); SetFacePixels(1, pixelsLeft); SetFacePixels(2, pixelsTop); SetFacePixels(3, pixelsBottom); SetFacePixels(4, pixelsBack); SetFacePixels(5, pixelsFront); }
public Texture2D(int width, int height, PixelFormat pixelFormat, TextureComponentCount componentCount, TextureUnit slot) { Width = width; Height = height; PixelFormat = pixelFormat; TextureSlot = slot; ComponentCount = componentCount; GLTexture = GL.GenTexture(); GLException.CheckError("Texture2D"); }
/// <summary> /// Creates a custom texture from bytes and other data. /// </summary> /// <param name="data">The bytes to upload to OpenGL.</param> /// <param name="width">The width of the texture.</param> /// <param name="height">The height of the texture.</param> /// <param name="componentCount">The texture's component count.</param> /// <param name="format">The format of the bytes.</param> /// <param name="textureMatrix">An additional matrix to multiply the texture matrix by.</param> public Texture(byte[] data, int width, int height, TextureComponentCount componentCount, PixelFormat format, Matrix4?textureMatrix = null) { Name = "Custom Texture"; Size = new Vector2(width, height); TextureMatrix = Matrix4.CreateOrthographicOffCenter(0, Size.X * 2, Size.Y * 2, 0, 0, 1); if (textureMatrix != null) { TextureMatrix *= (Matrix4)textureMatrix; } CreateFromBytes(data, componentCount, format); }
/// <summary> /// Create a texture from bytes. /// </summary> /// <param name="data">The texture data.</param> /// <param name="componentCount">The component count.</param> /// <param name="format">The texture format.</param> private void CreateFromBytes(byte[] data, TextureComponentCount componentCount, PixelFormat format) { Pointer = GL.GenTexture(); // Bind the texture. Bind(0); // Set scaling to pixel perfect. GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)All.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)All.Nearest); // Upload the texture. GL.TexImage2D(TextureTarget2d.Texture2D, 0, componentCount, (int)Size.X, (int)Size.Y, 0, format, PixelType.UnsignedByte, data); Helpers.CheckError("uploading texture"); }
public Texture2D(int width, int height, PixelFormat pixelFormat, TextureComponentCount componentCount, TextureUnit slot, IntPtr data) : this(width, height, pixelFormat, componentCount, slot) { Copy(data); GLException.CheckError("Texture2D"); }