This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 10043 for ps


Ignore:
Timestamp:
08/20/11 19:56:12 (13 years ago)
Author:
Jan Wassenberg
Message:

feature request by philip: instead of refusing to load textures larger than the OpenGL limit, ensure they have mipmaps (unless it's s3tc, which would be too expensive to recompress) and skip levels until it fits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/lib/res/graphics/ogl_tex.cpp

    r9962 r10043  
    7878
    7979
    80 static bool filter_uses_mipmaps(GLint filter)
    81 {
     80static bool are_mipmaps_needed(size_t width, size_t height, GLint filter)
     81{
     82    // can't upload the entire texture; we're going to skip some
     83    // levels until it no longer exceeds the OpenGL dimension limit.
     84    if((GLint)width > ogl_max_tex_size || (GLint)height > ogl_max_tex_size)
     85        return true;
     86
    8287    switch(filter)
    8388    {
     
    467472        if(w == 0 || h == 0)
    468473            WARN_RETURN(ERR::_11);
    469         // .. greater than max supported tex dimension.
    470         //    no-op if ogl_Init not yet called
    471         if(w > (size_t)ogl_max_tex_size || h > (size_t)ogl_max_tex_size)
    472             WARN_RETURN(ERR::_12);
    473474        // .. not power-of-2.
    474475        //    note: we can't work around this because both NV_texture_rectangle
     
    477478        if(!is_pow2(w) || !is_pow2(h))
    478479            WARN_RETURN(ERR::_13);
     480
     481        // no longer verify dimensions are less than ogl_max_tex_size,
     482        // because we just use the higher mip levels in that case.
    479483    }
    480484
     
    755759    // decisions:
    756760    // .. does filter call for uploading mipmaps?
    757     const bool need_mipmaps = filter_uses_mipmaps(filter);
     761    const bool need_mipmaps = are_mipmaps_needed(t->w, t->h, filter);
    758762    // .. does the image data include mipmaps? (stored as separate
    759763    //    images after the regular texels)
     
    799803    if(*plevels_to_skip == 0)
    800804    {
     805        // if OpenGL's texture dimension limit is too small, use the
     806        // higher mipmap levels. NB: the minimum guaranteed size is
     807        // far too low, and menu background textures may be large.
     808        GLint w = (GLint)t->w, h = (GLint)t->h;
     809        while(w > ogl_max_tex_size || h > ogl_max_tex_size)
     810        {
     811            (*plevels_to_skip)++;
     812            w /= 2; h /= 2; // doesn't matter if either dimension drops to 0
     813        }
     814
    801815        // this saves texture memory by skipping some of the lower
    802816        // (high-resolution) mip levels.
     
    805819        // require uploading unused levels, which is wasteful.
    806820        // .. can be expanded to reduce to 1/4, 1/8 by encoding factor in q_flags.
    807         const size_t reduce = (q_flags & OGL_TEX_HALF_RES)? 2 : 1;
    808         *plevels_to_skip = (int)ceil_log2(reduce);
     821        if(q_flags & OGL_TEX_HALF_RES)
     822            (*plevels_to_skip)++;
    809823    }
    810824
Note: See TracChangeset for help on using the changeset viewer.