// // Methods // #if OPENGL public Texture(Context3D context, int width, int height, string format, bool optimizeForRenderToTexture, int streamingLevels) : base(TextureTarget.Texture2D) { mContext = context; mWidth = width; mHeight = height; mFormat = format; mOptimizeForRenderToTexture = optimizeForRenderToTexture; mStreamingLevels = streamingLevels; // we do this to clear the texture on creation // $$TODO we dont need to allocate a bitmapdata to do this, we should just use a PBO and clear it var clearData = new BitmapData(width, height); uploadFromBitmapData(clearData); clearData.dispose(); }
public void uploadCompressedTextureFromByteArray (ByteArray data, uint byteArrayOffset, bool async = false) { // $$TODO // this is empty for now #if PLATFORM_MONOMAC System.Console.WriteLine("NotImplementedWarning: Texture.uploadCompressedTextureFromByteArray()"); if (!mDidUpload) { var clearData = new BitmapData(32,32, true, sColors[sColor % sColors.Length]); sColor++; uploadFromBitmapData(clearData); clearData.dispose(); mDidUpload = true; } #endif #if PLATFORM_MONOTOUCH int memUsage = (mWidth * mHeight) / 2; sMemoryUsedForTextures += memUsage; Console.WriteLine("Texture.uploadCompressedTextureFromByteArray() - " + mWidth + "x" + mHeight + " - Mem: " + (memUsage / 1024) + " KB - Total Mem: " + (sMemoryUsedForTextures / 1024) + " KB"); // Bind the texture GL.BindTexture (textureTarget, textureId); if (byteArrayOffset != 0) { throw new NotSupportedException(); } int dataLength = (int)(data.length - byteArrayOffset) - 4; // We remove the 4 bytes footer // TODO: Fix hardcoded value here OpenTK.Graphics.ES20.PixelInternalFormat pixelFormat = (OpenTK.Graphics.ES20.PixelInternalFormat)0x8C02; GL.CompressedTexImage2D(textureTarget, 0, pixelFormat, mWidth, mHeight, 0, dataLength, data.getRawStream().ToArray()); // unbind texture and pixel buffer GL.BindTexture (textureTarget, 0); #endif if (async) { // load with a delay var timer = new flash.utils.Timer(1, 1); timer.addEventListener(TimerEvent.TIMER, (System.Action<Event>)this.OnTextureReady ); timer.start(); } }
public void uploadFromBitmapData (BitmapData source, uint miplevel = 0, bool generateMipmap = false) { int memUsage = (mWidth * mHeight) * 4; sMemoryUsedForTextures += memUsage; Console.WriteLine("Texture.uploadFromBitmapData() - " + mWidth + "x" + mHeight + " - Mem: " + (memUsage / 1024) + " KB - Total Mem: " + (sMemoryUsedForTextures / 1024) + " KB"); // Bind the texture GL.BindTexture (textureTarget, textureId); #if PLATFORM_MONOMAC if (generateMipmap) { GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1); } #endif GL.TexImage2D(textureTarget, (int)miplevel, PixelInternalFormat.Rgba, mWidth, mHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte,source.getRawData()); #if PLATFORM_MONOTOUCH GL.GenerateMipmap(textureTarget); #endif // unbind texture and pixel buffer GL.BindTexture (textureTarget, 0); source.dispose(); }
public void uploadCompressedTextureFromByteArray (ByteArray data, uint byteArrayOffset, bool async = false) { // $$TODO // this is empty for now #if PLATFORM_MONOMAC System.Console.WriteLine("NotImplementedWarning: Texture.uploadCompressedTextureFromByteArray()"); if (!mDidUpload) { var clearData = new BitmapData(32,32, true, sColors[sColor % sColors.Length]); sColor++; uploadFromBitmapData(clearData); clearData.dispose(); mDidUpload = true; } #endif // see if this is an ATF container data.position = byteArrayOffset; string signature = data.readUTFBytes(3); data.position = byteArrayOffset; if (signature == "ATF") { // Bind the texture GL.BindTexture (textureTarget, textureId); uploadATFTextureFromByteArray(data, byteArrayOffset); GL.BindTexture (textureTarget, 0); if (async) { dispatchDelayedTextureReady(); } return; } #if PLATFORM_MONOTOUCH int memUsage = (mWidth * mHeight) / 2; sMemoryUsedForTextures += memUsage; Console.WriteLine("Texture.uploadCompressedTextureFromByteArray() - " + mWidth + "x" + mHeight + " - Mem: " + (memUsage / 1024) + " KB - Total Mem: " + (sMemoryUsedForTextures / 1024) + " KB"); // Bind the texture GL.BindTexture (textureTarget, textureId); if (byteArrayOffset != 0) { throw new NotSupportedException(); } int dataLength = (int)(data.length - byteArrayOffset) - 4; // We remove the 4 bytes footer // TODO: Fix hardcoded value here OpenTK.Graphics.ES20.PixelInternalFormat pixelFormat = (OpenTK.Graphics.ES20.PixelInternalFormat)0x8C02; GL.CompressedTexImage2D(textureTarget, 0, pixelFormat, mWidth, mHeight, 0, dataLength, data.getRawArray()); // unbind texture and pixel buffer GL.BindTexture (textureTarget, 0); #endif if (async) { dispatchDelayedTextureReady(); } }
public void uploadCompressedTextureFromByteArray (ByteArray data, uint byteArrayOffset, bool async = false) { #if PLATFORM_MONOMAC System.Console.WriteLine("NotImplementedWarning: Texture.uploadCompressedTextureFromByteArray()"); if (!mDidUpload) { var clearData = new BitmapData(32,32, true, sColors[sColor % sColors.Length]); sColor++; uploadFromBitmapData(clearData); clearData.dispose(); mDidUpload = true; } #endif // see if this is an ATF container data.position = byteArrayOffset; string signature = data.readUTFBytes(3); data.position = byteArrayOffset; if (signature == "ATF") { // Bind the texture GL.BindTexture (textureTarget, textureId); uploadATFTextureFromByteArray(data, byteArrayOffset); GL.BindTexture (textureTarget, 0); return; } #if PLATFORM_MONOTOUCH || PLATFORM_MONODROID int memUsage = (mWidth * mHeight) / 2; sMemoryUsedForTextures += memUsage; Console.WriteLine("Texture.uploadCompressedTextureFromByteArray() - " + mWidth + "x" + mHeight + " - Mem: " + (memUsage / 1024) + " KB - Total Mem: " + (sMemoryUsedForTextures / 1024) + " KB"); // Bind the texture GL.BindTexture (textureTarget, textureId); if (byteArrayOffset != 0) { throw new NotSupportedException(); } #if PLATFORM_MONOTOUCH int dataLength = (int)(data.length - byteArrayOffset) - 4; // We remove the 4 bytes footer // TODO: Fix hardcoded value here OpenTK.Graphics.ES20.PixelInternalFormat pixelFormat = (OpenTK.Graphics.ES20.PixelInternalFormat)0x8C02; GL.CompressedTexImage2D(textureTarget, 0, pixelFormat, mWidth, mHeight, 0, dataLength, data.getRawArray()); #elif PLATFORM_MONODROID data.position = 16; // skip the header int dataLength = ((int)data.length) - 16; GL.CompressedTexImage2D<byte>(textureTarget, 0, All.Etc1Rgb8Oes, mWidth, mHeight, 0, dataLength, data.getRawArray()); #endif // unbind texture and pixel buffer GL.BindTexture (textureTarget, 0); #endif if (async) { // load with a delay var timer = new flash.utils.Timer(1, 1); timer.addEventListener(TimerEvent.TIMER, (System.Action<Event>)this.OnTextureReady ); timer.start(); } }