Example #1
0
        public void InitWithBitmapGL11(Bitmap imageSource, GL11.All filter)
        {
            //TODO:  Android.Opengl.GLUtils.GetInternalFormat()
            openGLVersion = GLContextVersion.Gles1_1;

            _format = SurfaceFormat.Color;
            if (imageSource.HasAlpha)
            {
                _format = SurfaceFormat.Color;
            }

            // scale up bitmap to be power of 2 dimensions but dont exceed 1024x1024.
            // Note: may not have to do this with OpenGL 2+

            _width  = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Width) / Math.Log10(2))));
            _height = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Height) / Math.Log10(2))));

            _size.Width  = imageSource.Width;
            _size.Height = imageSource.Height;

            using (Bitmap imageScaled = Bitmap.CreateScaledBitmap(imageSource, _width, _height, false))
            {
                GL11.GL.GenTextures(1, ref _name);
                GL11.GL.BindTexture(GL11.All.Texture2D, _name);
                GL11.GL.TexParameter(GL11.All.Texture2D, GL11.All.TextureMinFilter, (int)filter);
                GL11.GL.TexParameter(GL11.All.Texture2D, GL11.All.TextureMagFilter, (int)filter);

                Android.Opengl.GLUtils.TexImage2D((int)GL11.All.Texture2D, 0, imageScaled, 0);
            }

            _maxS = _size.Width / (float)_width;
            _maxT = _size.Height / (float)_height;

            _pixelData = imageSource.Handle;
        }
Example #2
0
        /// <summary>
        /// </summary>
        /// <param name="data"> </param>
        /// <param name="outputFormat"> </param>
        /// <returns> </returns>
        public static PixelBox ConvertToGLformat(PixelBox data, out GLES.All outputFormat)
        {
            GLES.All glFormat = GetGLOriginFormat(data.Format);
            outputFormat = glFormat;
            if (glFormat != 0)
            {
                // format already supported
                return(data);
            }

            PixelBox converted = null;

            if (data.Format == PixelFormat.R8G8B8)
            {
                converted = new PixelBox();
                // Convert BGR -> RGB
                converted.Format = PixelFormat.R8G8B8;
                outputFormat     = GLES.All.Rgb;
                converted        = new PixelBox(data.Width, data.Height, data.Depth, data.Format);
                converted.Data   = data.Data;
                unsafe
                {
                    var dataptr = (uint *)converted.Data;
                    for (uint i = 0; i < converted.Width * converted.Height; i++)
                    {
                        uint *color = dataptr;
                        *     color = (*color & 0x000000ff) << 16 | (*color & 0x0000FF00) | (*color & 0x00FF0000) >> 16;
                        dataptr += 1;
                    }
                }
            }

            return(converted);
        }
 public static void Cull(All11 cullMode)
 {
     if (_cull != cullMode)
     {
         _cull = cullMode;
         GL11.Enable(_cull);
     }
 }
Example #4
0
 public static void Cull(All11 cullMode)
 {
     if (_cull != cullMode)
     {
         _cull = cullMode;
         GL11.Enable(_cull);
     }
 }
Example #5
0
        public static void BlendFunc(All11 source, All11 dest)
        {
            if (source != _blendFuncSource && dest != _blendFuncDest)
            {
                source = _blendFuncSource;
                dest = _blendFuncDest;

                GL11.BlendFunc(source, dest);
            }
        }
        public static void BlendFunc(All11 source, All11 dest)
        {
            if (source != _blendFuncSource && dest != _blendFuncDest)
            {
                source = _blendFuncSource;
                dest   = _blendFuncDest;

                GL11.BlendFunc(source, dest);
            }
        }
Example #7
0
        internal void GenerateBuffer <T>() where T : struct, IVertexType
        {
            var vd = VertexDeclaration.FromType(_type);

            _size = vd.VertexStride * ((T[])_buffer).Length;

            All11 bufferUsage = (_bufferUsage == BufferUsage.WriteOnly) ? All11.StaticDraw : All11.DynamicDraw;

            GL11.GenBuffers(1, out _bufferStore);
            GL11.BindBuffer(All11.ArrayBuffer, _bufferStore);
            GL11.BufferData <T>(All11.ArrayBuffer, (IntPtr)_size, (T[])_buffer, bufferUsage);
        }
Example #8
0
 public void SetData(byte[] data, int level, PixelFormat format)
 {
     if (TextureGl != null)
     {
         if ((int)format != 0)
         {
             TextureGl.SetData(data, level, format);
         }
         else
         {
             TextureGl.SetData(data, level);
         }
     }
 }
Example #9
0
        /// <summary>
        ///   Function to get the closest matching Axiom format to an internal GL format. To be precise, the format will be chosen that is most efficient to transfer to the card without losing precision.
        ///   <remarks>
        ///     It is valid for this function to always return PixelFormat.A8R8G8B8.
        ///   </remarks>
        /// </summary>
        /// <param name="fmt"> </param>
        /// <returns> </returns>
        public static PixelFormat GetClosestAxiomFormat(GLES.All fmt)
        {
            switch (fmt)
            {
#if GL_IMG_texture_compression_pvrtc
            case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
                return(PixelFormat.PVRTC_RGB2);

            case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
                return(PixelFormat.PVRTC_RGBA2);

            case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
                return(PixelFormat.PVRTC_RGB4);

            case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
                return(PixelFormat.PVRTC_RGBA4);
#endif
            case GLES.All.Luminance:
                return(PixelFormat.L8);

            case GLES.All.Alpha:
                return(PixelFormat.A8);

            case GLES.All.LuminanceAlpha:
                return(PixelFormat.BYTE_LA);

            case GLES.All.Rgb:
                return(PixelFormat.A8R8G8B8);

            case GLES.All.Rgba:
#if (AXIOM_PLATFORM_IPHONE)
                // seems that in iPhone we need this value to get the right color
                return(PixelFormat.A8R8G8B8);
#else
                return(PixelFormat.X8B8G8R8);
#endif
#if GL_BGRA
            case GLES.All.Rgba:
#endif
            //                return PixelFormat.X8B8G8R8;
            default:
                //TODO: not supported
                return(PixelFormat.A8R8G8B8);
            }
            ;
        }
Example #10
0
 /// <summary>
 ///   Takes the Axiom pixel format and returns the type that must be provided to GL as internal format. If no match exists, returns the closest match.
 /// </summary>
 /// <param name="mFormat"> mFormat The pixel format </param>
 /// <param name="hwGamma"> hwGamma Whether a hardware gamma-corrected version is requested </param>
 /// <returns> </returns>
 public static GLES.All GetClosestGLInternalFormat(PixelFormat mFormat, bool hwGamma = false)
 {
     GLES.All format = GetGLInternalFormat(mFormat, hwGamma);
     if (format == 0)
     {
         if (hwGamma)
         {
             // TODO not supported
             return(0);
         }
         else
         {
             return(GLES.All.Rgba);
         }
     }
     else
     {
         return(format);
     }
 }
Example #11
0
        public void InitWithDataGL11(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, GL11.All filter)
        {
            openGLVersion = GLContextVersion.Gles1_1;
            GL11.GL.GenTextures(1, ref _name);
            GL11.GL.BindTexture(GL11.All.Texture2D, _name);
            GL11.GL.TexParameter(GL11.All.Texture2D, GL11.All.TextureMinFilter, (int)filter);
            GL11.GL.TexParameter(GL11.All.Texture2D, GL11.All.TextureMagFilter, (int)filter);
            GL11.GL.TexParameter(GL11.All.Texture2D, GL11.All.TextureWrapS, (int)GL11.All.ClampToEdge);
            GL11.GL.TexParameter(GL11.All.Texture2D, GL11.All.TextureWrapT, (int)GL11.All.ClampToEdge);

            int sz = 0;

            switch (pixelFormat)
            {
            case SurfaceFormat.Color /*kTexture2DPixelFormat_RGBA8888*/:
            case SurfaceFormat.Dxt1:
            case SurfaceFormat.Dxt3:
                sz = 4;
                GL11.GL.TexImage2D(GL11.All.Texture2D, 0, (int)GL11.All.Rgba, (int)width, (int)height, 0, GL11.All.Rgba, GL11.All.UnsignedByte, data);
                break;

            case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/:
                sz = 2;
                GL11.GL.TexImage2D(GL11.All.Texture2D, 0, (int)GL11.All.Rgba, (int)width, (int)height, 0, GL11.All.Rgba, GL11.All.UnsignedShort4444, data);
                break;

            case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/:
                sz = 2;
                GL11.GL.TexImage2D(GL11.All.Texture2D, 0, (int)GL11.All.Rgba, (int)width, (int)height, 0, GL11.All.Rgba, GL11.All.UnsignedShort5551, data);
                break;

            case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/:
                sz = 1;
                GL11.GL.TexImage2D(GL11.All.Texture2D, 0, (int)GL11.All.Alpha, (int)width, (int)height, 0, GL11.All.Alpha, GL11.All.UnsignedByte, data);
                break;

            default:
                throw new NotSupportedException("Texture format");
            }

            _size   = size;
            _width  = width;
            _height = height;
            _format = pixelFormat;
            _maxS   = size.Width / (float)width;
            _maxT   = size.Height / (float)height;

            _pixelData = data;
        }
Example #12
0
 public GLESHardwarePixelBuffer(int width, int height, int depth, PixelFormat format, BufferUsage usage)
     : base(width, height, depth, format, usage, false, false)
 {
     this._buffer           = new PixelBox(width, height, depth, format);
     this._glInternalFormat = 0;
 }
Example #13
0
 public ESTexture2D(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, GL11.All filter)
 {
     InitWithDataGL11(data, pixelFormat, width, height, size, filter);
 }
Example #14
0
 public ESImage(Bitmap image, float imageScale, GL11.All filter)
 {
     texture = new ESTexture2D(image, filter);
     Initialize(imageScale);
 }
Example #15
0
 public ESImage(Bitmap image, GL11.All filter)
 {
     // By default set the scale to 1.0f
     texture = new ESTexture2D(image, filter);
     Initialize(1.0f);
 }
Example #16
0
 public ESTexture2D(Bitmap image, GL11.All filter)
 {
     InitWithBitmapGL11(image, filter);
 }
Example #17
0
 /// <summary>
 /// </summary>
 /// <param name="attachment"> </param>
 /// <param name="zOffset"> </param>
 public virtual void BindToFramebuffer(TK.All attachment, int zOffset)
 {
     throw new AxiomException("Framebuffer bind not possible for this pixelbuffer type");
 }
		public GLESHardwarePixelBuffer( int width, int height, int depth, PixelFormat format, BufferUsage usage )
			: base( width, height, depth, format, usage, false, false )
		{
			_buffer = new PixelBox( width, height, depth, format );
			_glInternalFormat = 0;
		}
Example #19
0
        protected override BufferBase LockImpl(int offset, int length, BufferLocking locking)
        {
            if (IsLocked)
            {
                throw new AxiomException("Invalid attempt to lock an index buffer that has already been locked.");
            }
            BufferBase retPtr;
            var        glBufManager = (HardwareBufferManager.Instance as GLESHardwareBufferManager);

            //Try to use scratch buffers for smaller buffers
            if (length < glBufManager.MapBufferThreshold)
            {
                retPtr = glBufManager.AllocateScratch(length);

                if (retPtr != null)
                {
                    this._lockedToScratch       = true;
                    this._scratchOffset         = offset;
                    this._scratchSize           = length;
                    this._scratchPtr            = retPtr;
                    this._scratchUploadOnUnlock = (locking != BufferLocking.ReadOnly);

                    if (locking != BufferLocking.Discard)
                    {
                        //have to read back the data before returning the pointer
                        this.ReadData(offset, length, retPtr);
                    }
                }
            }
            else
            {
                throw new AxiomException("Invalid Buffer lockSize");
            }

            if (retPtr == null)
            {
                GLenum access = GLenum.Zero;
                (Root.Instance.RenderSystem as GLESRenderSystem).BindGLBuffer(GLenum.ArrayBuffer, this._bufferID);

                if (locking == BufferLocking.Discard)
                {
                    //Discard the buffer
                    GL.BufferData(GLenum.ArrayBuffer, new IntPtr(sizeInBytes), IntPtr.Zero, GLESHardwareBufferManager.GetGLUsage(usage));
                    GLESConfig.GlCheckError(this);
                }
                if ((usage & BufferUsage.WriteOnly) == BufferUsage.WriteOnly)
                {
                    access = GLenum.WriteOnlyOes;
                }

                var pbuffer = GL.Oes.MapBuffer(GLenum.ArrayBuffer, access);
                GLESConfig.GlCheckError(this);

                if (pbuffer == IntPtr.Zero)
                {
                    throw new AxiomException("Vertex Buffer: Out of memory");
                }

                //return offsetted
                retPtr = BufferBase.Wrap(pbuffer, sizeInBytes) + offset;
                this._lockedToScratch = false;
            }
            isLocked = true;
            return(retPtr);
        }