예제 #1
0
        protected override void Upload(PixelBox data, BasicBox dest)
        {
            GL.BindTexture(this.target, this.textureID);
            GLES2Config.GlCheckError(this);

            if (PixelUtil.IsCompressed(data.Format))
            {
                if (data.Format != format || !data.IsConsecutive)
                {
                    var glFormat = GLES2PixelUtil.GetClosestGLInternalFormat(format);
                    //Data must be consecutive and at beginning of buffer as PixelStore is not allowed
                    //for compressed formats
                    if (dest.Left == 0 && dest.Top == 0)
                    {
                        GL.CompressedTexImage2D(this.faceTarget, this.level, glFormat, dest.Width, dest.Height, 0, data.ConsecutiveSize, data.Data.Pin());
                        GLES2Config.GlCheckError(this);
                    }
                    else
                    {
                        GL.CompressedTexSubImage2D(this.faceTarget, this.level, dest.Left, dest.Top, dest.Width, dest.Height, glFormat, data.ConsecutiveSize, data.Data.Pin());
                        GLES2Config.GlCheckError(this);
                    }
                }
            }
            else if (this.softwareMipmap)
            {
                if (data.Width != data.RowPitch)
                {
                    //Ogre TODO
                    throw new Core.AxiomException("Unsupported texture format");
                }
                if (data.Height * data.Width != data.SlicePitch)
                {
                    //Ogre TODO
                    throw new Core.AxiomException("Unsupported texture format");
                }

                GL.PixelStore(All.UnpackAlignment, 1);
                GLES2Config.GlCheckError(this);

                this.BuildMipmaps(data);
            }
            else
            {
                if (data.Width != data.RowPitch)
                {
                    //Ogre TODO
                    throw new Core.AxiomException("Unsupported texture format");
                }
                if (data.Height * data.Width != data.SlicePitch)
                {
                    //Ogre TODO
                    throw new Core.AxiomException("Unsupported texture format");
                }

                if ((data.Width * PixelUtil.GetNumElemBytes(data.Format) & 3) != 0)
                {
                    //Standard alignment of 4 is not right
                    GL.PixelStore(All.UnpackAlignment, 1);
                    GLES2Config.GlCheckError(this);
                }
                var dataPtr = data.Data.Pin();
                GL.TexImage2D(this.faceTarget, this.level, (int)GLES2PixelUtil.GetClosestGLInternalFormat(data.Format), data.Width, data.Height, 0, GLES2PixelUtil.GetGLOriginFormat(data.Format), GLES2PixelUtil.GetGLOriginDataType(data.Format), dataPtr);
                //GL.TexSubImage2D( this.faceTarget, this.level, dest.Left, dest.Top, dest.Width, dest.Height, GLES2PixelUtil.GetGLOriginFormat( data.Format ), GLES2PixelUtil.GetGLOriginDataType( data.Format ), dataPtr );
                data.Data.UnPin();
                GLES2Config.GlCheckError(this);
            }
            GL.PixelStore(All.UnpackAlignment, 4);
            GLES2Config.GlCheckError(this);
        }