//public synchronized void update(final GL10 pGL) { public void Update(GL10 pGL) { lock (_methodLock) { //final ArrayList<Letter> lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture; List <Letter> lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture; if (lettersPendingToBeDrawnToTexture.Count > 0) { int hardwareTextureID = this.mTexture.GetHardwareTextureID(); float textureWidth = this.mTextureWidth; float textureHeight = this.mTextureHeight; for (int i = lettersPendingToBeDrawnToTexture.Count - 1; i >= 0; i--) { Letter letter = lettersPendingToBeDrawnToTexture[i]; Bitmap bitmap = this.GetLetterBitmap(letter.mCharacter); GLHelper.BindTexture(pGL, hardwareTextureID); GLUtils.TexSubImage2D(GL10Consts.GlTexture2d, 0, (int)(letter.mTextureX * textureWidth), (int)(letter.mTextureY * textureHeight), bitmap); bitmap.Recycle(); } lettersPendingToBeDrawnToTexture.Clear(); //System.gc(); // TODO: Verify if this is a good match: System.gc() -> Dispose() ... leaving it to standard GC at present } } }
protected void GenerateTexture(Bitmap bitmap) { GL.Hint(HintTarget.GenerateMipmapHint, HintMode.Fastest); uint name = (uint)GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, name); /* TODO is this needed? * if (GLExtensions.TextureMaxAnisotropySupported) * { * float maxAniso; * GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out maxAniso); * GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, maxAniso); * } */ GL.TexStorage2D(TextureTarget2D.Texture2D, 1, // mipmap level, min 1 SizedInternalFormat.Rgba8, bitmap.Width, bitmap.Height); if (bitmap.Width > 0 && bitmap.Height > 0) { GLUtils.TexSubImage2D(GLES20.GlTexture2d, 0, // level 0, // xOffset 0, // yOffset bitmap); } else { Console.Out.WriteLine("WARNING: empty bitmap loaded"); } // see https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Graphics/Texture2D.OpenGL.cs // for how MonoGame does it _glTexture = new GLTexture(name, bitmap.Width, bitmap.Height, false, 1.0f, false); _isLoaded = true; // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. EventHandler <GLTexture> handler = ResourceLoaded; if (handler != null) { handler(this, _glTexture); } }
public GLBitmapAtlas CreateBitmapAtlasFromResources(string[] names) { var bitmaps = new Bitmap[names.Length]; var elementSizeX = 0; var elementSizeY = 0; for (int i = 0; i < names.Length; i++) { var bmp = LoadBitmapFromResourceWithScaling(names[i]); elementSizeX = Math.Max(elementSizeX, bmp.Width); elementSizeY = Math.Max(elementSizeY, bmp.Height); bitmaps[i] = bmp; } var elementsPerRow = MaxAtlasResolution / elementSizeX; var numRows = Utils.DivideAndRoundUp(names.Length, elementsPerRow); var atlasSizeX = elementsPerRow * elementSizeX; var atlasSizeY = numRows * elementSizeY; var textureId = CreateEmptyTexture(atlasSizeX, atlasSizeY, true); var elementRects = new Rectangle[names.Length]; GLES11.GlBindTexture(GLES11.GlTexture2d, textureId); for (int i = 0; i < names.Length; i++) { var bmp = bitmaps[i]; var row = i / elementsPerRow; var col = i % elementsPerRow; elementRects[i] = new Rectangle( col * elementSizeX, row * elementSizeY, bmp.Width, bmp.Height); GLUtils.TexSubImage2D(GLES11.GlTexture2d, 0, elementRects[i].X, elementRects[i].Y, bmp); bmp.Recycle(); } return(new GLBitmapAtlas(textureId, atlasSizeX, atlasSizeY, elementRects, true, true)); }