private static uint ToOpenTKTextureWrapMode(TextureWrapMode value) { switch (value) { default: case TextureWrapMode.Clamp: return(WebGLRenderingContextBase.CLAMP_TO_EDGE); //case TextureWrapMode.Repeat: return WebGLRenderingContextBase.REPEAT; //case TextureWrapMode.MirroredRepeat: return WebGLRenderingContextBase.MIRRORED_REPEAT; } }
private static GLTexWrapMode ToOpenTKTextureWrapMode(TextureWrapMode value) { switch (value) { default: case TextureWrapMode.Clamp: return(GLTexWrapMode.ClampToEdge); case TextureWrapMode.Repeat: return(GLTexWrapMode.Repeat); case TextureWrapMode.MirroredRepeat: return(GLTexWrapMode.MirroredRepeat); } }
void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps) { DefaultOpenTKBackendPlugin.GuardSingleThreadState(); int lastTexId; GL.GetInteger(GetPName.TextureBinding2D, out lastTexId); if (lastTexId != this.handle) { GL.BindTexture(TextureTarget.Texture2D, this.handle); } // Set texture parameters GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)ToOpenTKTextureMinFilter(minFilter)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)ToOpenTKTextureMagFilter(magFilter)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)ToOpenTKTextureWrapMode(wrapX)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)ToOpenTKTextureWrapMode(wrapY)); // Anisotropic filtering if (anisoLevel > 0) { GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)anisoLevel); } // If needed, care for Mipmaps GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, mipmaps ? 1 : 0); // Setup pixel format GL.TexImage2D(TextureTarget.Texture2D, 0, ToOpenTKPixelFormat(format), width, height, 0, GLPixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); this.width = width; this.height = height; this.format = format; this.mipmaps = mipmaps; if (lastTexId != this.handle) { GL.BindTexture(TextureTarget.Texture2D, lastTexId); } }
void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps) { // Removed thread guards because of performance //DefaultOpenTKBackendPlugin.GuardSingleThreadState(); if (width == 0 || height == 0) { return; } int lastTexId; GL.GetInteger(GetPName.TextureBinding2D, out lastTexId); if (lastTexId != this.handle) { GL.BindTexture(TextureTarget.Texture2D, this.handle); } // Set texture parameters GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)ToOpenTKTextureMinFilter(minFilter)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)ToOpenTKTextureMagFilter(magFilter)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)ToOpenTKTextureWrapMode(wrapX)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)ToOpenTKTextureWrapMode(wrapY)); // Anisotropic filtering // ToDo: Add similar code for OpenGL ES //if (anisoLevel > 0) { // GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)anisoLevel); //} // If needed, care for Mipmaps // ToDo: Why are mipmaps disabled here? //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, mipmaps ? 1 : 0); // Setup pixel format GL.TexImage2D(TextureTarget2d.Texture2D, 0, ToOpenTKPixelInternalFormat(format), width, height, 0, ToOpenTKPixelFormat(format), PixelType.UnsignedByte, IntPtr.Zero); //GL.GenerateMipmap(TextureTarget.Texture2D); this.width = width; this.height = height; this.format = format; this.mipmaps = mipmaps; if (lastTexId != this.handle) { GL.BindTexture(TextureTarget.Texture2D, lastTexId); } }
void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps) { // Removed thread guards because of performance //DefaultOpenTKBackendPlugin.GuardSingleThreadState(); WebGLTexture lastTexId = (WebGLTexture)GraphicsBackend.GL.GetParameter(WebGLRenderingContextBase.TEXTURE_BINDING_2D); if (lastTexId != this.handle) { GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, this.handle); } // Set texture parameters GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_MIN_FILTER, (int)ToOpenTKTextureMinFilter(minFilter)); GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_MAG_FILTER, (int)ToOpenTKTextureMagFilter(magFilter)); GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_WRAP_S, (int)ToOpenTKTextureWrapMode(wrapX)); GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_WRAP_T, (int)ToOpenTKTextureWrapMode(wrapY)); // Anisotropic filtering // ToDo: Add similar code for OpenGL ES //if (anisoLevel > 0) { // GraphicsBackend.GL.TexParameter(WebGLRenderingContextBase.TEXTURE_2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)anisoLevel); //} // If needed, care for Mipmaps // ToDo: Why are mipmaps disabled here? //GraphicsBackend.GL.TexParameter(WebGLRenderingContextBase.TEXTURE_2D, TextureParameterName.GenerateMipmap, mipmaps ? 1 : 0); // Setup pixel format GraphicsBackend.GL.TexImage2D(WebGLRenderingContextBase.TEXTURE_2D, 0, ToOpenTKPixelInternalFormat(format), width, height, 0, ToOpenTKPixelFormat(format), WebGLRenderingContextBase.UNSIGNED_BYTE, null); //GraphicsBackend.GL.GenerateMipmap(WebGLRenderingContextBase.TEXTURE_2D); this.width = width; this.height = height; this.format = format; this.mipmaps = mipmaps; if (lastTexId != this.handle) { GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, lastTexId); } }