Exemple #1
0
        internal void SetData(DataRectangle data, int mipLevel)
        {
            if (mipLevel >= this.MipLevels)
            {
                throw new ArgumentOutOfRangeException("MipLevel exceeds the amount of mip levels.");
            }
            if (mipLevel < 0)
            {
                throw new ArgumentOutOfRangeException("MipLevel must not be smaller than zero.");
            }
            if (data.Size < 0)
            {
                throw new ArgumentOutOfRangeException("ImageSize must not be smaller than zero.");
            }

            var format = EnumConverter.Convert(Format);
            int width  = Width / (int)Math.Pow(2, mipLevel);
            int height = Height / (int)Math.Pow(2, mipLevel);

            if (graphicsDevice.OpenGLCapabilities.DirectStateAccess == DirectStateAccess.None)
            {
                graphicsDevice.BindManager.SetTexture(this, 0);

                if (!TextureFormatHelper.IsCompressed(Format))
                {
                    GL.TexSubImage2D(TextureTarget.Texture2D, mipLevel, 0, 0, width, height, format.Item2, format.Item3, data.Pointer);
                }
                else
                {
                    if (isInitialized)
                    {
                        GL.CompressedTexSubImage2D(TextureTarget.Texture2D, mipLevel, 0, 0, width, height, format.Item2, data.Size, data.Pointer);
                    }
                    else
                    {
                        GL.CompressedTexImage2D(TextureTarget.Texture2D, mipLevel, format.Item1, width, height, 0, data.Size, data.Pointer);
                    }
                }
            }
            else if (graphicsDevice.OpenGLCapabilities.DirectStateAccess == DirectStateAccess.Extension)
            {
                if (!TextureFormatHelper.IsCompressed(Format))
                {
                    Ext.TextureSubImage2D(TextureID, OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, mipLevel, 0, 0, width, height, (OpenTK.Graphics.OpenGL.PixelFormat)format.Item2, (OpenTK.Graphics.OpenGL.PixelType)format.Item3, data.Pointer);
                }
                else
                {
                    if (isInitialized)
                    {
                        Ext.CompressedTextureSubImage2D(TextureID, OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, mipLevel, 0, 0, width, height, (OpenTK.Graphics.OpenGL.PixelFormat)format.Item2, data.Size, data.Pointer);
                    }
                    else
                    {
                        Ext.CompressedTextureImage2D(TextureID, OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, mipLevel, (OpenTK.Graphics.OpenGL.ExtDirectStateAccess)format.Item1, width, height, 0, data.Size, data.Pointer);
                    }
                }
            }
            else if (graphicsDevice.OpenGLCapabilities.DirectStateAccess == DirectStateAccess.Core)
            {
                //OpenGL 4.5
            }

            graphicsDevice.CheckGLError("Texture2D SetData");
        }