コード例 #1
0
        protected int computeMipmapLevel(int sourceWidth, int sourceHeight, Sector sourceSector,
                                         int destWidth, int destHeight, Sector destSector)
        {
            double sy = ((double)sourceHeight / (double)destHeight)
                        * (destSector.getDeltaLatDegrees() / sourceSector.getDeltaLatDegrees());
            double sx = ((double)sourceWidth / (double)destWidth)
                        * (destSector.getDeltaLonDegrees() / sourceSector.getDeltaLonDegrees());
            double scale = Math.Max(sx, sy);

            if (scale < 1)
            {
                return(0);
            }

            return((int)WWMath.LogBase2(scale));
        }
コード例 #2
0
        /**
         * Returns an OpenGL pixel format corresponding to the specified texture internal format. This maps internal format
         * to pixel format as follows: <code> <table> <tr><th>Internal Format</th><th>Estimated Bits Per Pixel</th></tr>
         * <tr><td>GL2.GL_ALPHA</td><td>8</td></tr> <tr><td>GL2.GL_ALPHA4</td><td>4</td></tr>
         * <tr><td>GL2.GL_ALPHA8</td><td>8</td></tr> <tr><td>GL2.GL_ALPHA12</td><td>12</td></tr>
         * <tr><td>GL2.GL_ALPHA16</td><td>16</td></tr> <tr><td>GL2.GL_COMPRESSED_ALPHA</td><td>0</td></tr>
         * <tr><td>GL2.GL_COMPRESSED_LUMINANCE</td><td>0</td></tr> <tr><td>GL2.GL_COMPRESSED_LUMINANCE_ALPHA</td><td>0</td></tr>
         * <tr><td>GL2.GL_COMPRESSED_INTENSITY</td><td>0</td></tr> <tr><td>GL2.GL_COMPRESSED_RGB</td><td>0</td></tr>
         * <tr><td>GL2.GL_COMPRESSED_RGBA</td><td>0</td></tr> <tr><td>GL2.GL_DEPTH_COMPONENT</td><td>24</td></tr>
         * <tr><td>GL2.GL_DEPTH_COMPONENT16</td><td>16</td></tr> <tr><td>GL2.GL_DEPTH_COMPONENT24</td><td>24</td></tr>
         * <tr><td>GL2.GL_DEPTH_COMPONENT32</td><td>32</td></tr> <tr><td>GL2.GL_LUMINANCE</td><td>8</td></tr>
         * <tr><td>GL2.GL_LUMINANCE4</td><td>4</td></tr> <tr><td>GL2.GL_LUMINANCE8</td><td>8</td></tr>
         * <tr><td>GL2.GL_LUMINANCE12</td><td>12</td></tr> <tr><td>GL2.GL_LUMINANCE16</td><td>16</td></tr>
         * <tr><td>GL2.GL_LUMINANCE_ALPHA</td><td>16</td></tr> <tr><td>GL2.GL_LUMINANCE4_ALPHA4</td><td>8</td></tr>
         * <tr><td>GL2.GL_LUMINANCE6_ALPHA2</td><td>8</td></tr> <tr><td>GL2.GL_LUMINANCE8_ALPHA8</td><td>16</td></tr>
         * <tr><td>GL2.GL_LUMINANCE12_ALPHA4</td><td>16</td></tr> <tr><td>GL2.GL_LUMINANCE12_ALPHA12</td><td>24</td></tr>
         * <tr><td>GL2.GL_LUMINANCE16_ALPHA16</td><td>32</td></tr> <tr><td>GL2.GL_INTENSITY</td><td>8</td></tr>
         * <tr><td>GL2.GL_INTENSITY4</td><td>4</td></tr> <tr><td>GL2.GL_INTENSITY8</td><td>8</td></tr>
         * <tr><td>GL2.GL_INTENSITY12</td><td>12</td></tr> <tr><td>GL2.GL_INTENSITY16</td><td>16</td></tr>
         * <tr><td>GL2.GL_R3_G3_B2</td><td>8</td></tr> <tr><td>GL2.GL_RGB</td><td>24</td></tr>
         * <tr><td>GL2.GL_RGB4</td><td>12</td></tr> <tr><td>GL2.GL_RGB5</td><td>16 (assume the driver allocates 16 bits per
         * pixel)</td></tr> <tr><td>GL2.GL_RGB8</td><td>24</td></tr> <tr><td>GL2.GL_RGB10</td><td>32 (assume the driver
         * allocates 32 bits per pixel)</td></tr> <tr><td>GL2.GL_RGB12</td><td>36</td></tr>
         * <tr><td>GL2.GL_RGB16</td><td>48</td></tr> <tr><td>GL2.GL_RGBA</td><td>32</td></tr>
         * <tr><td>GL2.GL_RGBA2</td><td>8</td></tr> <tr><td>GL2.GL_RGBA4</td><td>16</td></tr>
         * <tr><td>GL2.GL_RGB5_A1</td><td>16</td></tr> <tr><td>GL2.GL_RGBA8</td><td>32</td></tr>
         * <tr><td>GL2.GL_RGB10_A2</td><td>32</td></tr> <tr><td>GL2.GL_RGBA12</td><td>48</td></tr>
         * <tr><td>GL2.GL_RGBA16</td><td>64</td></tr> <tr><td>GL2.GL_SLUMINANCE</td><td>8</td></tr>
         * <tr><td>GL2.GL_SLUMINANCE8</td><td>8</td></tr> <tr><td>GL2.GL_SLUMINANCE_ALPHA</td><td>16</td></tr>
         * <tr><td>GL2.GL_SLUMINANCE8_ALPHA8</td><td>16<td></tr> <tr><td>GL2.GL_SRGB</td><td>24</td></tr>
         * <tr><td>GL2.GL_SRGB8</td><td>24</td></tr> <tr><td>GL2.GL_SRGB_ALPHA</td><td>32</td></tr>
         * <tr><td>GL2.GL_SRGB8_ALPHA8</td><td>32</td></tr> </code>
         * <p/>
         * The returned estimate assumes that the driver provides does not convert the formats to another supported, such
         * converting as <code>GL2.GL_ALPHA4</code> to <code>GL2.GL_ALPHA8</code>. This returns 0 if the internal format is
         * not one of the recognized types. This does not attempt to estimate a memory size for compressed internal
         * formats.
         *
         * @param internalFormat the OpenGL texture internal format.
         * @param width          the texture width, in pixels.
         * @param height         the texture height, in pixels.
         * @param includeMipmaps true to include the texture's mip map data in the estimated size; false otherwise.
         *
         * @return a pixel format corresponding to the texture internal format, or 0 if the internal format is not
         *         recognized.
         *
         * @throws ArgumentException if either the width or height is less than or equal to zero.
         */
        public static int estimateTextureMemorySize(int internalFormat, int width, int height, bool includeMipmaps)
        {
            if (width < 0)
            {
                String message = Logging.getMessage("Geom.WidthInvalid", width);
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (height < 0)
            {
                String message = Logging.getMessage("Geom.HeightInvalid", height);
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            int numPixels = width * height;

            // Add the number of pixels from each level in the mipmap chain to the total number of pixels.
            if (includeMipmaps)
            {
                int maxLevel = Math.Max((int)WWMath.LogBase2(width), (int)WWMath.LogBase2(height));
                for (int level = 1; level <= maxLevel; level++)
                {
                    int w = Math.Max(width >> level, 1);
                    int h = Math.Max(height >> level, 1);
                    numPixels += w * h;
                }
            }

            switch (internalFormat)
            {
            // 4 bits per pixel.
            case GL2.GL_ALPHA4:
            case GL2.GL_LUMINANCE4:
            case GL2.GL_INTENSITY4:
                return(numPixels / 2);

            // 8 bits per pixel.
            case GL2.GL_ALPHA:
            case GL2.GL_ALPHA8:
            case GL2.GL_LUMINANCE:
            case GL2.GL_LUMINANCE8:
            case GL2.GL_LUMINANCE4_ALPHA4:
            case GL2.GL_LUMINANCE6_ALPHA2:
            case GL2.GL_INTENSITY:
            case GL2.GL_INTENSITY8:
            case GL2.GL_R3_G3_B2:
            case GL2.GL_RGBA2:
            case GL2.GL_SLUMINANCE:
            case GL2.GL_SLUMINANCE8:
                return(numPixels);

            // 12 bits per pixel.
            case GL2.GL_ALPHA12:
            case GL2.GL_LUMINANCE12:
            case GL2.GL_INTENSITY12:
            case GL2.GL_RGB4:
                return(12 * numPixels / 8);

            // 16 bits per pixel.
            case GL2.GL_ALPHA16:
            case GL2.GL_DEPTH_COMPONENT16:
            case GL2.GL_LUMINANCE16:
            case GL2.GL_LUMINANCE_ALPHA:
            case GL2.GL_LUMINANCE8_ALPHA8:
            case GL2.GL_LUMINANCE12_ALPHA4:
            case GL2.GL_INTENSITY16:
            case GL2.GL_RGB5: // Assume the driver allocates 16 bits per pixel for GL_RGB5.
            case GL2.GL_RGBA4:
            case GL2.GL_RGB5_A1:
            case GL2.GL_SLUMINANCE_ALPHA:
            case GL2.GL_SLUMINANCE8_ALPHA8:
                return(2 * numPixels);

            // 24 bits per pixel.
            case GL2.GL_DEPTH_COMPONENT:
            case GL2.GL_DEPTH_COMPONENT24:
            case GL2.GL_LUMINANCE12_ALPHA12:
            case GL2.GL_RGB:
            case GL2.GL_RGB8:
            case GL2.GL_SRGB:
            case GL2.GL_SRGB8:
                return(3 * numPixels);

            // 32 bits per pixel.
            case GL2.GL_DEPTH_COMPONENT32:
            case GL2.GL_LUMINANCE16_ALPHA16:
            case GL2.GL_RGB10: // Assume the driver allocates 32 bits per pixel for GL_RGB10.
            case GL2.GL_RGBA:
            case GL2.GL_RGBA8:
            case GL2.GL_RGB10_A2:
            case GL2.GL_SRGB_ALPHA:
            case GL2.GL_SRGB8_ALPHA8:
                return(4 * numPixels);

            // 36 bits per pixel.
            case GL2.GL_RGB12:
                return(36 * numPixels / 8);

            // 48 bits per pixel.
            case GL2.GL_RGB16:
            case GL2.GL_RGBA12:
                return(6 * numPixels);

            // 64 bits per pixel.
            case GL2.GL_RGBA16:
                return(8 * numPixels);

            // Compressed internal formats. Don't try to estimate a size for compressed formats.
            case GL2.GL_COMPRESSED_ALPHA:
            case GL2.GL_COMPRESSED_LUMINANCE:
            case GL2.GL_COMPRESSED_LUMINANCE_ALPHA:
            case GL2.GL_COMPRESSED_INTENSITY:
            case GL2.GL_COMPRESSED_RGB:
            case GL2.GL_COMPRESSED_RGBA:
                return(0);

            default:
                return(0);
            }
        }