private static GLTexture BindGLTexture(STGenericTexture texture, STGenericTextureMap textureMap, ShaderProgram shader) { if (texture.RenderableTex == null) { texture.LoadRenderableTexture(); } if (texture.RenderableTex == null) { return(null); } var target = ((GLTexture)texture.RenderableTex).Target; GL.BindTexture(target, texture.RenderableTex.ID); GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)OpenGLHelper.WrapMode[textureMap.WrapU]); GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)OpenGLHelper.WrapMode[textureMap.WrapV]); GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)OpenGLHelper.MinFilter[textureMap.MinFilter]); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)OpenGLHelper.MagFilter[textureMap.MagFilter]); GL.TexParameter(target, TextureParameterName.TextureLodBias, textureMap.LODBias); GL.TexParameter(target, TextureParameterName.TextureMaxLod, textureMap.MaxLOD); GL.TexParameter(target, TextureParameterName.TextureMinLod, textureMap.MinLOD); int[] mask = new int[4] { OpenGLHelper.GetSwizzle(texture.RedChannel), OpenGLHelper.GetSwizzle(texture.GreenChannel), OpenGLHelper.GetSwizzle(texture.BlueChannel), OpenGLHelper.GetSwizzle(texture.AlphaChannel), }; GL.TexParameter(target, TextureParameterName.TextureSwizzleRgba, mask); return((GLTexture)texture.RenderableTex); }
static void BindTexture(STGenericTexture tex) { if (tex == null) { return; } if (tex.RenderableTex == null) { tex.LoadRenderableTexture(); } var target = ((GLTexture)tex.RenderableTex).Target; var texID = tex.RenderableTex.ID; if (tex.Platform.OutputFormat == TexFormat.BC5_SNORM) { if (!GLTextureCache.DecodedFormats.ContainsKey(texID)) { var reloaded = GLTexture2D.FromGeneric(tex, new ImageParameters() { UseSoftwareDecoder = (tex.Platform.OutputFormat == TexFormat.BC5_SNORM), }); GLTextureCache.DecodedFormats.Add(texID, reloaded.ID); } texID = GLTextureCache.DecodedFormats[texID]; } //Fixed mip layer with nearest setting GL.BindTexture(target, texID); GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(target, TextureParameterName.TextureMaxLod, (int)15); GL.TexParameter(target, TextureParameterName.TextureMinLod, (int)mipLevel); int[] mask = new int[4] { (int)All.Red, (int)All.Green, (int)All.Blue, (int)All.Alpha }; if (ImageEditor.UseChannelComponents) { mask = new int[4] { OpenGLHelper.GetSwizzle(tex.RedChannel), OpenGLHelper.GetSwizzle(tex.GreenChannel), OpenGLHelper.GetSwizzle(tex.BlueChannel), //For now prevent full disappearance of zero alpha types on alpha channel. //This is typically used on BC4 and BC5 types when not using alpha data. tex.AlphaChannel == STChannelType.Zero ? 1 : OpenGLHelper.GetSwizzle(tex.AlphaChannel), }; } GL.TexParameter(target, TextureParameterName.TextureSwizzleRgba, mask); }
public static int CreateTextureRender(STGenericTexture texture, int width, int height, bool displayAlpha = true) { if (texture.RenderableTex == null) { texture.LoadRenderableTexture(); } if (texture.RenderableTex == null) { return(-1); } int ID = texture.RenderableTex.ID; if (texture.Platform.OutputFormat == TexFormat.BC5_SNORM) { var reloaded = GLTexture2D.FromGeneric(texture, new ImageParameters() { UseSoftwareDecoder = (texture.Platform.OutputFormat == TexFormat.BC5_SNORM), }); ID = reloaded.ID; } var shader = GlobalShaders.GetShader("TEXTURE_ICON"); Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height, PixelInternalFormat.Rgba, 1); frameBuffer.Bind(); GL.ClearColor(0, 0, 0, 0); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Viewport(0, 0, width, height); GL.Disable(EnableCap.Blend); shader.Enable(); shader.SetBoolToInt("isSRGB", texture.IsSRGB); int[] mask = new int[4] { OpenGLHelper.GetSwizzle(texture.RedChannel), OpenGLHelper.GetSwizzle(texture.GreenChannel), OpenGLHelper.GetSwizzle(texture.BlueChannel), OpenGLHelper.GetSwizzle(displayAlpha ? texture.AlphaChannel : STChannelType.One), }; ((GLTexture)texture.RenderableTex).Bind(); GL.TexParameter(((GLTexture)texture.RenderableTex).Target, TextureParameterName.TextureSwizzleRgba, mask); //Draw the texture onto the framebuffer ScreenQuadRender.Draw(shader, ID); //Disable shader and textures GL.UseProgram(0); GL.BindTexture(TextureTarget.Texture2D, 0); var image = (GLTexture2D)frameBuffer.Attachments[0]; return(image.ID); /* //Dispose frame buffer * frameBuffer.Dispoe(); * frameBuffer.DisposeRenderBuffer();*/ }