Ejemplo n.º 1
0
        public virtual void GL_CreateSurfaceLightmap(msurface_t surf)
        {
            if ((surf.flags & (Defines.SURF_DRAWSKY | Defines.SURF_DRAWTURB)) != 0)
            {
                return;
            }
            var   smax     = (surf.extents[0] >> 4) + 1;
            var   tmax     = (surf.extents[1] >> 4) + 1;
            pos_t lightPos = new pos_t(surf.light_s, surf.light_t);

            if (!LM_AllocBlock(smax, tmax, lightPos))
            {
                LM_UploadBlock(false);
                LM_InitBlock();
                lightPos = new pos_t(surf.light_s, surf.light_t);
                if (!LM_AllocBlock(smax, tmax, lightPos))
                {
                    Com.Error(Defines.ERR_FATAL, "Consecutive calls to LM_AllocBlock(" + smax + "," + tmax + ") failed\\n");
                }
            }

            surf.light_s            = lightPos.x;
            surf.light_t            = lightPos.y;
            surf.lightmaptexturenum = gl_lms.current_lightmap_texture;
            Int32Buffer base_renamed = gl_lms.lightmap_buffer;

            base_renamed.Position = surf.light_t * BLOCK_WIDTH + surf.light_s;
            R_SetCacheState(surf);
            R_BuildLightMap(surf, base_renamed.Slice(), BLOCK_WIDTH);
        }
Ejemplo n.º 2
0
        public virtual System.Boolean LM_AllocBlock(Int32 w, Int32 h, pos_t pos)
        {
            var   best = BLOCK_HEIGHT;
            var   x    = pos.x;
            Int32 best2;
            Int32 i, j;

            for (i = 0; i < BLOCK_WIDTH - w; i++)
            {
                best2 = 0;
                for (j = 0; j < w; j++)
                {
                    if (gl_lms.allocated[i + j] >= best)
                    {
                        break;
                    }
                    if (gl_lms.allocated[i + j] > best2)
                    {
                        best2 = gl_lms.allocated[i + j];
                    }
                }

                if (j == w)
                {
                    pos.x = x = i;
                    pos.y = best = best2;
                }
            }

            if (best + h > BLOCK_HEIGHT)
            {
                return(false);
            }
            for (i = 0; i < w; i++)
            {
                gl_lms.allocated[x + i] = best + h;
            }
            return(true);
        }
Ejemplo n.º 3
0
        public virtual void R_BlendLightmaps( )
        {
            Int32      i;
            msurface_t surf;
            msurface_t newdrawsurf = null;

            if (r_fullbright.value != 0)
            {
                return;
            }
            if (r_worldmodel.lightdata == null)
            {
                return;
            }
            GL.DepthMask(false);
            if (gl_lightmap.value == 0)
            {
                GL.Enable(EnableCap.Blend);
                if (gl_saturatelighting.value != 0)
                {
                    GL.BlendFunc(BlendingFactor.One, BlendingFactor.One);
                }
                else
                {
                    var format = gl_monolightmap.string_renamed.ToUpper()[0];
                    if (format != '0')
                    {
                        switch (format)
                        {
                        case 'I':
                            GL.BlendFunc(BlendingFactor.Zero, BlendingFactor.SrcColor);
                            break;

                        case 'L':
                            GL.BlendFunc(BlendingFactor.Zero, BlendingFactor.SrcColor);
                            break;

                        case 'A':
                        default:
                            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
                            break;
                        }
                    }
                    else
                    {
                        GL.BlendFunc(BlendingFactor.Zero, BlendingFactor.SrcColor);
                    }
                }
            }

            if (currentmodel == r_worldmodel)
            {
                c_visible_lightmaps = 0;
            }
            for (i = 1; i < MAX_LIGHTMAPS; i++)
            {
                if (gl_lms.lightmap_surfaces[i] != null)
                {
                    if (currentmodel == r_worldmodel)
                    {
                        c_visible_lightmaps++;
                    }
                    GL_Bind(gl_state.lightmap_textures + i);
                    for (surf = gl_lms.lightmap_surfaces[i]; surf != null; surf = surf.lightmapchain)
                    {
                        if (surf.polys != null)
                        {
                            DrawGLPolyChain(surf.polys, 0, 0);
                        }
                    }
                }
            }

            if (gl_dynamic.value != 0)
            {
                LM_InitBlock();
                GL_Bind(gl_state.lightmap_textures + 0);
                if (currentmodel == r_worldmodel)
                {
                    c_visible_lightmaps++;
                }
                newdrawsurf = gl_lms.lightmap_surfaces[0];
                for (surf = gl_lms.lightmap_surfaces[0]; surf != null; surf = surf.lightmapchain)
                {
                    Int32       smax, tmax;
                    Int32Buffer base_renamed;
                    smax = (surf.extents[0] >> 4) + 1;
                    tmax = (surf.extents[1] >> 4) + 1;
                    pos_t lightPos = new pos_t(surf.dlight_s, surf.dlight_t);
                    if (LM_AllocBlock(smax, tmax, lightPos))
                    {
                        surf.dlight_s         = lightPos.x;
                        surf.dlight_t         = lightPos.y;
                        base_renamed          = gl_lms.lightmap_buffer;
                        base_renamed.Position = surf.dlight_t * BLOCK_WIDTH + surf.dlight_s;
                        R_BuildLightMap(surf, base_renamed.Slice(), BLOCK_WIDTH);
                    }
                    else
                    {
                        msurface_t drawsurf;
                        LM_UploadBlock(true);
                        for (drawsurf = newdrawsurf; drawsurf != surf; drawsurf = drawsurf.lightmapchain)
                        {
                            if (drawsurf.polys != null)
                            {
                                DrawGLPolyChain(drawsurf.polys, (drawsurf.light_s - drawsurf.dlight_s) * (1F / 128F), (drawsurf.light_t - drawsurf.dlight_t) * (1F / 128F));
                            }
                        }

                        newdrawsurf = drawsurf;
                        LM_InitBlock();
                        if (!LM_AllocBlock(smax, tmax, lightPos))
                        {
                            Com.Error(Defines.ERR_FATAL, "Consecutive calls to LM_AllocBlock(" + smax + "," + tmax + ") failed (dynamic)\\n");
                        }

                        surf.dlight_s         = lightPos.x;
                        surf.dlight_t         = lightPos.y;
                        base_renamed          = gl_lms.lightmap_buffer;
                        base_renamed.Position = surf.dlight_t * BLOCK_WIDTH + surf.dlight_s;
                        R_BuildLightMap(surf, base_renamed.Slice(), BLOCK_WIDTH);
                    }
                }

                if (newdrawsurf != null)
                {
                    LM_UploadBlock(true);
                }
                for (surf = newdrawsurf; surf != null; surf = surf.lightmapchain)
                {
                    if (surf.polys != null)
                    {
                        DrawGLPolyChain(surf.polys, (surf.light_s - surf.dlight_s) * (1F / 128F), (surf.light_t - surf.dlight_t) * (1F / 128F));
                    }
                }
            }

            GL.Disable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.DepthMask(true);
        }