コード例 #1
0
ファイル: GLES2TextureBuffer.cs プロジェクト: bostich83/axiom
        protected override void Download(PixelBox data)
        {
#if GL_NV_get_tex_image
            if (data.Width != Width || data.Height != Height || data.Depth != Depth)
            {
                throw new Core.AxiomException("only download of entire buffer is supported by GL");
            }

            GL.BindTexture(this.target, this.textureID);
            if (PixelUtil.IsCompressed(data.Format))
            {
                if (data.Format != format || !data.IsConsecutive)
                {
                    throw new Core.AxiomException("Compressed images must be consecutive, in the source format");
                }

                GL.GetCompressedTexImageNV(this.faceTarget, this.level, data.Data);
            }
            else
            {
                if ((data.Width * PixelUtil.GetNumElemBytes(data.Format) & 3) != 0)
                {
                    //Standard alignment of 4 is not right
                    GL.PixelStore(Glenum.PackAlignment, 1);
                }

                //We can only get the entire texture
                GL.GetTexImageNV(this.faceTarget, this.level, GLES2PixelUtil.GetGLOriginFormat(data.Format), GLES2PixelUtil.GetGLOriginDataType(data.Format), data.Data);

                //Restore defaults
                GL.PixelStore(Glenum.PackAlignment, 4);
            }
#else
            throw new Core.AxiomException("Downloading texture buffers is not supported by OpenGL ES");
#endif
        }
コード例 #2
0
ファイル: GLES2TextureBuffer.cs プロジェクト: bostich83/axiom
        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);
        }