GenerateTextureNumberRange() публичный статический Метод

gets texture_extension_number++
public static GenerateTextureNumberRange ( int count ) : int
count int
Результат int
Пример #1
0
        private static byte[] _LightMaps = new byte[4 * MAX_LIGHTMAPS * BLOCK_WIDTH * BLOCK_HEIGHT]; // lightmaps

        /// <summary>
        /// GL_BuildLightmaps
        /// Builds the lightmap texture with all the surfaces from all brush models
        /// </summary>
        private static void BuildLightMaps()
        {
            Array.Clear(_Allocated, 0, _Allocated.Length);
            //memset (allocated, 0, sizeof(allocated));

            _FrameCount = 1;            // no dlightcache

            if (_LightMapTextures == 0)
            {
                _LightMapTextures = Drawer.GenerateTextureNumberRange(MAX_LIGHTMAPS);
            }

            Drawer.LightMapFormat = PixelFormat.Luminance;// GL_LUMINANCE;

            // default differently on the Permedia
            if (Scr.IsPermedia)
            {
                Drawer.LightMapFormat = PixelFormat.Rgba;
            }

            if (common.HasParam("-lm_1"))
            {
                Drawer.LightMapFormat = PixelFormat.Luminance;
            }

            if (common.HasParam("-lm_a"))
            {
                Drawer.LightMapFormat = PixelFormat.Alpha;
            }

            //if (Common.HasParam("-lm_i"))
            //    Drawer.LightMapFormat = PixelFormat.Intensity;

            //if (Common.HasParam("-lm_2"))
            //    Drawer.LightMapFormat = PixelFormat.Rgba4;

            if (common.HasParam("-lm_4"))
            {
                Drawer.LightMapFormat = PixelFormat.Rgba;
            }

            switch (Drawer.LightMapFormat)
            {
            case PixelFormat.Rgba:
                _LightMapBytes = 4;
                break;

            //case PixelFormat.Rgba4:
            //_LightMapBytes = 2;
            //break;

            case PixelFormat.Luminance:
            //case PixelFormat.Intensity:
            case PixelFormat.Alpha:
                _LightMapBytes = 1;
                break;
            }

            for (int j = 1; j < QDef.MAX_MODELS; j++)
            {
                model_t m = client.cl.model_precache[j];
                if (m == null)
                {
                    break;
                }

                if (m.name != null && m.name.StartsWith("*"))
                {
                    continue;
                }

                _CurrentVertBase = m.vertexes;
                _CurrentModel    = m;
                for (int i = 0; i < m.numsurfaces; i++)
                {
                    CreateSurfaceLightmap(m.surfaces[i]);
                    if ((m.surfaces[i].flags & Surf.SURF_DRAWTURB) != 0)
                    {
                        continue;
                    }

                    if ((m.surfaces[i].flags & Surf.SURF_DRAWSKY) != 0)
                    {
                        continue;
                    }

                    BuildSurfaceDisplayList(m.surfaces[i]);
                }
            }

            if (_glTexSort.Value == 0)
            {
                Drawer.SelectTexture(MTexTarget.TEXTURE1_SGIS);
            }

            //
            // upload all lightmaps that were filled
            //
            GCHandle handle = GCHandle.Alloc(_LightMaps, GCHandleType.Pinned);

            try
            {
                IntPtr ptr    = handle.AddrOfPinnedObject();
                long   lmAddr = ptr.ToInt64();

                for (int i = 0; i < MAX_LIGHTMAPS; i++)
                {
                    if (_Allocated[i, 0] == 0)
                    {
                        break;          // no more used
                    }
                    _LightMapModified[i]     = false;
                    _LightMapRectChange[i].l = BLOCK_WIDTH;
                    _LightMapRectChange[i].t = BLOCK_HEIGHT;
                    _LightMapRectChange[i].w = 0;
                    _LightMapRectChange[i].h = 0;
                    Drawer.Bind(_LightMapTextures + i);
                    Drawer.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear);

                    long addr = lmAddr + i * BLOCK_WIDTH * BLOCK_HEIGHT * _LightMapBytes;
                    GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)_LightMapBytes,
                                  BLOCK_WIDTH, BLOCK_HEIGHT, 0, Drawer.LightMapFormat, PixelType.UnsignedByte, new IntPtr(addr));
                }
            }
            finally
            {
                handle.Free();
            }

            if (_glTexSort.Value == 0)
            {
                Drawer.SelectTexture(MTexTarget.TEXTURE0_SGIS);
            }
        }