public virtual void MakeTexture() { if (PrepDevice != null) { // PrepDevice.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1); try { texture2d = PrepDevice.createTexture(); if (dataset.Extension == ".fits" && RenderContext.UseGlVersion2) { PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE); PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.R32F, (int)fitsImage.SizeX, (int)fitsImage.SizeY, 0, GL.RED, GL.FLOAT, fitsImage.dataUnit); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST); } else { ImageElement image = texture; // Before we bind resize to a power of two if nessesary so we can MIPMAP if (!Texture.IsPowerOfTwo(texture.Height) | !Texture.IsPowerOfTwo(texture.Width)) { CanvasElement temp = (CanvasElement)Document.CreateElement("canvas"); temp.Height = Texture.FitPowerOfTwo(image.Height); temp.Width = Texture.FitPowerOfTwo(image.Width); CanvasContext2D ctx = (CanvasContext2D)temp.GetContext(Rendering.Render2D); ctx.DrawImage(image, 0, 0, temp.Width, temp.Height); //Substitute the resized image image = (ImageElement)(Element)temp; } PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE); PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, image); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST); PrepDevice.generateMipmap(GL.TEXTURE_2D); } PrepDevice.bindTexture(GL.TEXTURE_2D, null); } catch { errored = true; } } }
public static Bitmap Create(int width, int height) { height = Texture.FitPowerOfTwo(height); width = Texture.FitPowerOfTwo(width); Bitmap bmp = new Bitmap(); bmp.Height = height; bmp.Width = width; bmp.buffer = new Uint8Array(width * height * 4); return(bmp); }