コード例 #1
0
ファイル: MipmapLoading.cs プロジェクト: Hengle/SFGraphics
        /// <summary>
        ///
        /// </summary>
        /// <param name="target">The target of the texture or cube face for loading mip maps</param>
        /// <param name="width">The width of the texture or cube map face in pixels</param>
        /// <param name="height">The height of the texture or cube map face in pixels</param>
        /// <param name="baseMipLevel"></param>
        /// <param name="format">The input format and internal format information</param>
        public static void LoadBaseLevelGenerateMipmaps(TextureTarget target, int width, int height,
                                                        BufferObject baseMipLevel, TextureFormatUncompressed format)
        {
            LoadUncompressedMipLevel(target, width, height, baseMipLevel, format, 0);

            GL.GenerateMipmap((GenerateMipmapTarget)target);
        }
コード例 #2
0
ファイル: SBSurface.cs プロジェクト: ScanMountGoat/StudioSB
        /// <summary>
        /// Gets the SFTexture of this surface
        /// </summary>
        /// <returns></returns>
        public Texture CreateRenderTexture()
        {
            if (renderTexture == null)
            {
                var sfTex = new Texture2D()
                {
                    // Set defaults until all the sampler parameters are added.
                    TextureWrapS = TextureWrapMode.Repeat,
                    TextureWrapT = TextureWrapMode.Repeat
                };

                if (TextureFormatTools.IsCompressed(InternalFormat))
                {
                    sfTex.LoadImageData(Width, Height, Mipmaps, InternalFormat);
                }
                else
                {
                    // TODO: Uncompressed mipmaps.
                    var format = new TextureFormatUncompressed((PixelInternalFormat)PixelFormat, PixelFormat, PixelType.UnsignedByte);
                    sfTex.LoadImageData(Width, Height, Mipmaps[0], format);
                }
                renderTexture = sfTex;
            }
            return(renderTexture);
        }
コード例 #3
0
ファイル: MipmapLoading.cs プロジェクト: Hengle/SFGraphics
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T">The value type used for the image data. This includes arithmetic types.</typeparam>
        /// <param name="target">The target of the texture or cube face for loading mipmaps</param>
        /// <param name="width">The width of the texture or cube map face in pixels</param>
        /// <param name="height">The height of the texture or cube map face in pixels</param>
        /// <param name="baseMipLevel"></param>
        /// <param name="format">The input format and internal format information</param>
        public static void LoadBaseLevelGenerateMipmaps <T>(TextureTarget target, int width, int height,
                                                            T[] baseMipLevel, TextureFormatUncompressed format) where T : struct
        {
            LoadUncompressedMipLevel(target, width, height, baseMipLevel, format, 0);

            GL.GenerateMipmap((GenerateMipmapTarget)target);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="width">The width of the base mip level in pixels</param>
        /// <param name="height">The height of the base mip level in pixels</param>
        /// <param name="mipmaps">The image data for each mip level</param>
        /// <param name="format">The image format of <paramref name="mipmaps"/></param>
        public void LoadImageData(int width, int height, IList <BufferObject> mipmaps,
                                  TextureFormatUncompressed format)
        {
            Width  = width;
            Height = height;

            MipmapLoading.LoadUncompressedMipmaps(TextureTarget.Texture2D, width, height, mipmaps, format);
        }
コード例 #5
0
        /// <summary>
        /// Loads a mip level of uncompressed texture data
        /// for each array in <paramref name="mipmaps"/>.
        /// </summary>
        /// <typeparam name="T">The data type of the image data</typeparam>
        /// <param name="width">The width of the base mip level in pixels</param>
        /// <param name="height">The height of the base mip level in pixels</param>
        /// <param name="mipmaps">The image data for each mip level</param>
        /// <param name="format">The image format of <paramref name="mipmaps"/></param>
        public void LoadImageData <T>(int width, int height, IList <T[]> mipmaps, TextureFormatUncompressed format)
            where T : struct
        {
            Width  = width;
            Height = height;

            MipmapLoading.LoadUncompressedMipmaps(TextureTarget.Texture2D, width, height, mipmaps, format);
        }
コード例 #6
0
        /// <summary>
        /// Loads texture data of the specified format for the first mip level.
        /// Mipmaps are generated by OpenGL.
        /// </summary>
        /// <param name="width">The width of the base mip level in pixels</param>
        /// <param name="height">The height of the base mip level in pixels</param>
        /// <param name="baseMipLevel">The image data of the first mip level</param>
        /// <param name="format">The image format for all mipmaps</param>
        public void LoadImageData(int width, int height, BufferObject baseMipLevel, TextureFormatUncompressed format)
        {
            Width  = width;
            Height = height;

            Bind();
            MipmapLoading.LoadBaseLevelGenerateMipmaps(TextureTarget, width, height, baseMipLevel, format);
        }
コード例 #7
0
ファイル: MipmapLoading.cs プロジェクト: Hengle/SFGraphics
        private static void LoadUncompressedMipLevel <T>(TextureTarget target, int width, int height,
                                                         T[] baseMipLevel, TextureFormatUncompressed format, int mipLevel) where T : struct
        {
            int border = 0;

            GL.TexImage2D(target, mipLevel, format.pixelInternalFormat, width, height, border,
                          format.pixelFormat, format.pixelType, baseMipLevel);
        }
コード例 #8
0
        /// <summary>
        /// Loads texture data of the specified format for the first mip level.
        /// Mipmaps are generated by OpenGL.
        /// </summary>
        /// <typeparam name="T">The data type of the image data</typeparam>
        /// <param name="width">The width of <paramref name="baseMipLevel"/> in pixels</param>
        /// <param name="height">The height of <paramref name="baseMipLevel"/> in pixels</param>
        /// <param name="baseMipLevel">The image data of the first mip level</param>
        /// <param name="format">The image format for all mipmaps</param>
        public void LoadImageData <T>(int width, int height, T[] baseMipLevel, TextureFormatUncompressed format)
            where T : struct
        {
            Width  = width;
            Height = height;

            Bind();
            MipmapLoading.LoadBaseLevelGenerateMipmaps(TextureTarget, width, height, baseMipLevel, format);
        }
コード例 #9
0
        public void UncompressedGenerateMipmaps()
        {
            var texture = new TextureCubeMap();
            var format  = new TextureFormatUncompressed(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float);

            texture.LoadImageData(128, format,
                                  mipmaps[0], mipmaps[0], mipmaps[0], mipmaps[0], mipmaps[0], mipmaps[0]);

            Assert.AreEqual(128, texture.Width);
            Assert.AreEqual(128, texture.Height);
        }
コード例 #10
0
        private static void LoadUncompressedMipLevel(TextureTarget target, int width, int height,
                                                     BufferObject imageBuffer, TextureFormatUncompressed format, int mipLevel)
        {
            imageBuffer.Bind(BufferTarget.PixelUnpackBuffer);

            GL.TexImage2D(target, mipLevel, format.pixelInternalFormat, width, height, border,
                          format.pixelFormat, format.pixelType, bufferOffset);

            // Unbind to avoid affecting other texture operations.
            GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
        }
コード例 #11
0
        /// <summary>
        /// Specifies the texture's dimensions and format but leaves the image data
        /// uninitialized.
        /// </summary>
        /// <param name="width">The new width in pixels</param>
        /// <param name="height">The new height in pixels</param>
        /// <param name="format">The format to store the image data</param>
        public void LoadImageData(int width, int height, TextureFormatUncompressed format)
        {
            Width  = width;
            Height = height;

            // This only works for uncompressed texture data.
            // GL.CompressedTexImage2D function will crash when using IntPtr.Zero.
            Bind();
            GL.TexImage2D(TextureTarget, 0, format.pixelInternalFormat, Width, Height, 0,
                          format.pixelFormat, format.pixelType, IntPtr.Zero);
        }
コード例 #12
0
ファイル: MipmapLoading.cs プロジェクト: Hengle/SFGraphics
        /// <summary>
        /// Loads image data for all six faces of a cubemap. No mipmaps are generated, so use a min filter
        /// that does not use mipmaps.
        /// </summary>
        /// <typeparam name="T">The value type used for the image data. This includes arithmetic types.</typeparam>
        /// <param name="length">The width and height of each cube map face in pixels</param>
        /// <param name="format"></param>
        /// <param name="posX"></param>
        /// <param name="negX"></param>
        /// <param name="posY"></param>
        /// <param name="negY"></param>
        /// <param name="posZ"></param>
        /// <param name="negZ"></param>
        public static void LoadFacesBaseLevel <T>(int length, TextureFormatUncompressed format,
                                                  T[] posX, T[] negX, T[] posY, T[] negY, T[] posZ, T[] negZ) where T : struct
        {
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapPositiveX, length, length, posX, format);
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapNegativeX, length, length, negX, format);

            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapPositiveY, length, length, posY, format);
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapNegativeY, length, length, negY, format);

            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapPositiveZ, length, length, posZ, format);
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapNegativeZ, length, length, negZ, format);
        }
コード例 #13
0
        /// <summary>
        /// Initializes an uncompressed cube map without mipmaps.
        /// Each face should have the same dimensions and image format.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="faceSideLength">The side length in pixels of each face.</param>
        /// <param name="format"></param>
        /// <param name="facePosX">The base mip level for the positive x target</param>
        /// <param name="faceNegX">The base mip level for the negative x target</param>
        /// <param name="facePosY">The base mip level for the positive y target</param>
        /// <param name="faceNegY">The base mip level for the negative y target</param>
        /// <param name="facePosZ">The base mip level for the positive z target</param>
        /// <param name="faceNegZ">The base mip level for the negative z target</param>
        public void LoadImageData <T>(int faceSideLength, TextureFormatUncompressed format,
                                      T[] facePosX, T[] faceNegX, T[] facePosY,
                                      T[] faceNegY, T[] facePosZ, T[] faceNegZ) where T : struct
        {
            Width  = faceSideLength;
            Height = faceSideLength;

            // Don't use mipmaps.
            MagFilter = TextureMagFilter.Linear;
            MinFilter = TextureMinFilter.Linear;

            MipmapLoading.LoadFacesBaseLevel(faceSideLength, format, facePosX, faceNegX, facePosY,
                                             faceNegY, facePosZ, faceNegZ);
        }
コード例 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T">The value type of the image data</typeparam>
        /// <param name="target">The target of the texture or cube face for loading mip maps</param>
        /// <param name="width">The width of the texture or cube map face in pixels</param>
        /// <param name="height">The height of the texture or cube map face in pixels</param>
        /// <param name="mipmaps">The collection of mipmaps to load for <paramref name="target"/></param>
        /// <param name="format">The format information</param>
        public static void LoadUncompressedMipmaps <T>(TextureTarget target, int width, int height,
                                                       IList <T[]> mipmaps, TextureFormatUncompressed format) where T : struct
        {
            SetMaxMipLevel(target, mipmaps);

            // Load mipmaps in the inclusive range [0, max level]
            for (int mipLevel = 0; mipLevel < mipmaps.Count; mipLevel++)
            {
                int mipWidth  = CalculateMipDimension(width, mipLevel);
                int mipHeight = CalculateMipDimension(height, mipLevel);

                LoadUncompressedMipLevel(target, mipWidth, mipHeight, mipmaps[mipLevel], format, mipLevel);
            }
        }
コード例 #15
0
        /// <summary>
        /// Loads image data for all six faces of a cubemap. No mipmaps are generated.
        /// </summary>
        /// <typeparam name="T">The value type of the image data</typeparam>
        /// <param name="length">The width and height of each cube map face in pixels</param>
        /// <param name="format">The image format</param>
        /// <param name="posX">Mip map data for the positive x target</param>
        /// <param name="negX">Mip map data for the negative x target</param>
        /// <param name="posY">Mip map data for the positive y target</param>
        /// <param name="negY">Mip map data for the negative y target</param>
        /// <param name="posZ">Mip map data for the positive z target</param>
        /// <param name="negZ">Mip map data for the negative z target</param>
        public static void LoadFacesBaseLevel <T>(int length, TextureFormatUncompressed format,
                                                  T[] posX, T[] negX, T[] posY, T[] negY, T[] posZ, T[] negZ) where T : struct
        {
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapPositiveX, length, length, posX, format);
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapNegativeX, length, length, negX, format);

            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapPositiveY, length, length, posY, format);
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapNegativeY, length, length, negY, format);

            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapPositiveZ, length, length, posZ, format);
            LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapNegativeZ, length, length, negZ, format);

            // Mipmaps can't be generated until the texture is cube map complete.
            GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);
        }
コード例 #16
0
ファイル: Framebuffer.cs プロジェクト: Hengle/SFGraphics
        private Texture2D CreateColorAttachment(int width, int height)
        {
            Texture2D texture = new Texture2D()
            {
                // Don't use mipmaps for color attachments.
                MinFilter = TextureMinFilter.Nearest,
                MagFilter = TextureMagFilter.Linear
            };
            // Necessary for texture completion.
            var format = new TextureFormatUncompressed(PixelInternalFormat, PixelFormat.Rgba, PixelType.Float);

            texture.LoadImageData(width, height, format);

            return(texture);
        }
コード例 #17
0
        private void LoadSpecularPbr()
        {
            var surfaceData = new List <List <byte[]> >();

            AddCubeMipmaps(surfaceData, "x+");
            AddCubeMipmaps(surfaceData, "x-");
            AddCubeMipmaps(surfaceData, "y+");
            AddCubeMipmaps(surfaceData, "y-");
            AddCubeMipmaps(surfaceData, "z+");
            AddCubeMipmaps(surfaceData, "z-");

            var format = new TextureFormatUncompressed(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float);

            SpecularPbr.LoadImageData(64, format, surfaceData[0], surfaceData[1], surfaceData[2], surfaceData[3], surfaceData[4], surfaceData[5]);
        }
コード例 #18
0
        public IRenderable GetRenderableNode()
        {
            // TODO: Some texture files are 0 bytes.
            if (Mipmaps.Count == 0)
            {
                return(null);
            }

            // Don't initialize more than once.
            // We'll assume the context isn't destroyed.
            if (renderableTexture == null)
            {
                renderableTexture = new RTexture
                {
                    IsSrgb = Format.ToString().ToLower().Contains("srgb")
                };

                if (internalFormatByNuTexFormat.ContainsKey(Format))
                {
                    // This may require a higher OpenGL version for BC7.
                    if (!SFGraphics.GlUtils.OpenGLExtensions.IsAvailable("GL_ARB_texture_compression_bptc"))
                    {
                        throw new Rendering.Exceptions.MissingExtensionException("GL_ARB_texture_compression_bptc");
                    }

                    var sfTex = new Texture2D()
                    {
                        // Set defaults until all the sampler parameters are added.
                        TextureWrapS = TextureWrapMode.Repeat,
                        TextureWrapT = TextureWrapMode.Repeat
                    };

                    if (TextureFormatTools.IsCompressed(internalFormatByNuTexFormat[Format]))
                    {
                        sfTex.LoadImageData(Width, Height, Mipmaps, internalFormatByNuTexFormat[Format]);
                    }
                    else
                    {
                        var format = new TextureFormatUncompressed((PixelInternalFormat)internalFormatByNuTexFormat[Format], pixelFormatByNuTexFormat[Format], PixelType.UnsignedByte);
                        sfTex.LoadImageData(Width, Height, Mipmaps, format);
                    }

                    renderableTexture.renderTexture = sfTex;
                }
            }

            return(renderableTexture);
        }
コード例 #19
0
ファイル: Attachments.cs プロジェクト: Hengle/SFGraphics
        public void AddAttachmentChangesDimensions()
        {
            Framebuffer framebuffer = new Framebuffer(FramebufferTarget.Framebuffer);

            var format = new TextureFormatUncompressed(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.Float);

            var texture1 = new Texture2D();

            texture1.LoadImageData(8, 4, format);
            framebuffer.AddAttachment(FramebufferAttachment.ColorAttachment0, texture1);

            Assert.AreEqual(8, framebuffer.Width);
            Assert.AreEqual(4, framebuffer.Height);

            Assert.AreEqual(FramebufferErrorCode.FramebufferComplete, framebuffer.GetStatus());
        }
コード例 #20
0
        /// <summary>
        /// Loads image data and mipmaps for all six faces of a cube map.
        /// </summary>
        /// <typeparam name="T">The value type of the image data</typeparam>
        /// <param name="length">The width and height of each cube map face in pixels</param>
        /// <param name="format">The image format</param>
        /// <param name="mipsPosX">Mip map data for the positive x target</param>
        /// <param name="mipsNegX">Mip map data for the negative x target</param>
        /// <param name="mipsPosY">Mip map data for the positive y target</param>
        /// <param name="mipsNegY">Mip map data for the negative y target</param>
        /// <param name="mipsPosZ">Mip map data for the positive z target</param>
        /// <param name="mipsNegZ">Mip map data for the negative z target</param>
        public static void LoadFacesMipmaps <T>(int length, TextureFormatUncompressed format,
                                                IList <T[]> mipsPosX, IList <T[]> mipsNegX, IList <T[]> mipsPosY,
                                                IList <T[]> mipsNegY, IList <T[]> mipsPosZ, IList <T[]> mipsNegZ) where T : struct
        {
            // Assume all the mipmap counts are the same.
            SetMaxMipLevel(TextureTarget.TextureCubeMap, mipsPosX);

            LoadUncompressedMipmaps(TextureTarget.TextureCubeMapPositiveX, length, length, mipsPosX, format);
            LoadUncompressedMipmaps(TextureTarget.TextureCubeMapNegativeX, length, length, mipsNegX, format);

            LoadUncompressedMipmaps(TextureTarget.TextureCubeMapPositiveY, length, length, mipsPosY, format);
            LoadUncompressedMipmaps(TextureTarget.TextureCubeMapNegativeY, length, length, mipsNegY, format);

            LoadUncompressedMipmaps(TextureTarget.TextureCubeMapPositiveZ, length, length, mipsPosZ, format);
            LoadUncompressedMipmaps(TextureTarget.TextureCubeMapNegativeZ, length, length, mipsNegZ, format);
        }
コード例 #21
0
ファイル: Attachments.cs プロジェクト: Hengle/SFGraphics
        public void DifferentSizedColorTextures()
        {
            Framebuffer framebuffer = new Framebuffer(FramebufferTarget.Framebuffer);
            var         format      = new TextureFormatUncompressed(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.Float);

            var texture1 = new Texture2D();

            texture1.LoadImageData(8, 8, format);
            framebuffer.AddAttachment(FramebufferAttachment.ColorAttachment0, texture1);

            var texture2 = new Texture2D();

            texture2.LoadImageData(1, 1, format);

            var e = Assert.ThrowsException <System.ArgumentOutOfRangeException>(() =>
                                                                                framebuffer.AddAttachment(FramebufferAttachment.ColorAttachment1, texture2));
        }
コード例 #22
0
ファイル: MipmapLoading.cs プロジェクト: Hengle/SFGraphics
        /// <summary>
        ///
        /// </summary>
        /// <param name="target">The target of the texture or cube face for loading mip maps</param>
        /// <param name="width">The width of the texture or cube map face in pixels</param>
        /// <param name="height">The height of the texture or cube map face in pixels</param>
        /// <param name="mipmaps"></param>
        /// <param name="format">The input format and internal format information</param>
        public static void LoadUncompressedMipmaps(TextureTarget target, int width, int height,
                                                   List <BufferObject> mipmaps, TextureFormatUncompressed format)
        {
            // The number of mipmaps needs to be specified first.
            if (!TextureFormatTools.IsCubeMapTarget(target))
            {
                int maxMipLevel = Math.Max(mipmaps.Count - 1, minMipLevel);
                GL.TexParameter(target, TextureParameterName.TextureMaxLevel, maxMipLevel);
            }

            // Load mipmaps in the inclusive range [0, max level]
            for (int mipLevel = 0; mipLevel < mipmaps.Count; mipLevel++)
            {
                int mipWidth  = CalculateMipDimension(width, mipLevel);
                int mipHeight = CalculateMipDimension(height, mipLevel);

                LoadUncompressedMipLevel(target, mipWidth, mipHeight, mipmaps[mipLevel], format, mipLevel);
            }
        }
コード例 #23
0
        private void LoadDiffusePbr()
        {
            var surfaceData = new List <List <byte[]> >();

            AddIrrFace(surfaceData, "x+");
            AddIrrFace(surfaceData, "x-");
            AddIrrFace(surfaceData, "y+");
            AddIrrFace(surfaceData, "y-");
            AddIrrFace(surfaceData, "z+");
            AddIrrFace(surfaceData, "z-");


            var format = new TextureFormatUncompressed(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float);

            DiffusePbr.LoadImageData(64, format, surfaceData[0], surfaceData[1], surfaceData[2], surfaceData[3], surfaceData[4], surfaceData[5]);

            // Don't Use mipmaps.
            DiffusePbr.MagFilter = TextureMagFilter.Linear;
            DiffusePbr.MinFilter = TextureMinFilter.Linear;
        }
コード例 #24
0
        public void DifferentSizedColorTextures()
        {
            Framebuffer framebuffer = new Framebuffer(FramebufferTarget.Framebuffer);
            var         format      = new TextureFormatUncompressed(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.Float);

            var texture1 = new Texture2D();

            texture1.LoadImageData(8, 8, format);
            framebuffer.AddAttachment(FramebufferAttachment.ColorAttachment0, texture1);

            var texture2 = new Texture2D();

            texture2.LoadImageData(1, 1, format);

            var e = Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
                                                                         framebuffer.AddAttachment(FramebufferAttachment.ColorAttachment1, texture2));

            Assert.IsTrue(e.Message.Contains("The attachment dimensions do not match the framebuffer's dimensions."));
            Assert.AreEqual("attachment", e.ParamName);
        }
コード例 #25
0
        /// <summary>
        /// Initializes an uncompressed cube map with mipmaps.
        /// Each face should have the same dimensions, image format, and number of mipmaps.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="faceSideLength">The side length in pixels of each face.</param>
        /// <param name="format">The image format</param>
        /// <param name="mipsPosX">Mipmaps for the positive x target</param>
        /// <param name="mipsNegX">Mipmaps for the negative x target</param>
        /// <param name="mipsPosY">Mipmaps for the positive y target</param>
        /// <param name="mipsNegY">Mipmaps for the negative y target</param>
        /// <param name="mipsPosZ">Mipmaps for the positive z target</param>
        /// <param name="mipsNegZ">Mipmaps for the negative z target</param>
        /// <exception cref="ArgumentException"><paramref name="format"/> is not a compressed format.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The mipmap counts are not equal for all faces.</exception>
        public void LoadImageData <T>(int faceSideLength, TextureFormatUncompressed format,
                                      IList <T[]> mipsPosX, IList <T[]> mipsNegX, IList <T[]> mipsPosY,
                                      IList <T[]> mipsNegY, IList <T[]> mipsPosZ, IList <T[]> mipsNegZ) where T : struct
        {
            Width  = faceSideLength;
            Height = faceSideLength;

            bool equalMipCounts = CheckCountEquality(mipsPosX, mipsNegX, mipsPosY, mipsNegY, mipsPosZ, mipsNegZ);

            if (!equalMipCounts)
            {
                throw new ArgumentOutOfRangeException(TextureExceptionMessages.cubeFaceMipCountDifferent);
            }

            // Necessary to access mipmaps past the base level.
            MinFilter = TextureMinFilter.LinearMipmapLinear;

            Bind();
            MipmapLoading.LoadFacesMipmaps(faceSideLength, format, mipsPosX, mipsNegX, mipsPosY,
                                           mipsNegY, mipsPosZ, mipsNegZ);
        }
コード例 #26
0
ファイル: SBSurface.cs プロジェクト: youdontown/StudioSB
        /// <summary>
        /// Gets the SFTexture of this surface
        /// </summary>
        /// <returns></returns>
        public Texture GetRenderTexture()
        {
            if (renderTexture == null)
            {
                if (Arrays.Count == 6)
                {
                    var cube = new TextureCubeMap()
                    {
                        MinFilter = TextureMinFilter.Linear,
                        MagFilter = TextureMagFilter.Linear
                    };
                    if (TextureFormatTools.IsCompressed(InternalFormat))
                    {
                        cube.LoadImageData(Width, InternalFormat,
                                           Arrays[0].Mipmaps, Arrays[1].Mipmaps, Arrays[2].Mipmaps,
                                           Arrays[3].Mipmaps, Arrays[4].Mipmaps, Arrays[5].Mipmaps);
                    }
                    else
                    {
                        var format = new TextureFormatUncompressed((PixelInternalFormat)PixelFormat, PixelFormat, PixelType);

                        cube.LoadImageData(Width, format,
                                           Arrays[0].Mipmaps[0], Arrays[1].Mipmaps[0], Arrays[2].Mipmaps[0],
                                           Arrays[3].Mipmaps[0], Arrays[4].Mipmaps[0], Arrays[5].Mipmaps[0]);
                    }
                    renderTexture = cube;
                }
                else
                {
                    var sfTex = new Texture2D()
                    {
                        // Set defaults until all the sampler parameters are added.
                        TextureWrapS = TextureWrapMode.Repeat,
                        TextureWrapT = TextureWrapMode.Repeat,
                    };

                    if (TextureFormatTools.IsCompressed(InternalFormat))
                    {
                        // hack
                        // trying to load mipmaps with similar sizes seems to not work
                        var mipTest  = new List <byte[]>();
                        int prevsize = 0;
                        foreach (var v in Arrays[0].Mipmaps)
                        {
                            if (v.Length == prevsize)
                            {
                                continue;
                            }
                            mipTest.Add(v);
                            prevsize = v.Length;
                        }
                        sfTex.LoadImageData(Width, Height, mipTest, InternalFormat);
                    }
                    else
                    {
                        // TODO: Uncompressed mipmaps
                        var format = new TextureFormatUncompressed(PixelInternalFormat.Rgba, PixelFormat, PixelType);
                        sfTex.LoadImageData(Width, Height, Arrays[0].Mipmaps, format);
                    }
                    renderTexture = sfTex;
                }
            }
            return(renderTexture);
        }