Ignore:
Timestamp:
09/09/14 20:08:33 (11 years ago)
Author:
epyon
Message:
  • texture types (1D,2D,Rect,3D,Cube - not all fully supported yet)
  • full framebuffer support
  • fixes to texture support
  • minor fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gl/gl_device.cc

    r326 r331  
    6262}
    6363
    64 nv::texture nv::gl_device::create_texture( ivec2 size, image_format aformat, sampler asampler, void* data /*= nullptr */ )
     64nv::texture nv::gl_device::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, void* data /*= nullptr */ )
    6565{
    6666        unsigned glid = 0;
     67        unsigned gl_type = texture_type_to_enum( type );
    6768        glGenTextures( 1, &glid );
    6869
    69         glBindTexture( GL_TEXTURE_2D, glid );
     70        glBindTexture( gl_type, glid );
    7071
    7172        // Detect if mipmapping was requested
    72         if (( asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) ||
    73                 ( asampler.filter_max != sampler::LINEAR && asampler.filter_max != sampler::NEAREST ))
    74         {
    75                 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    76         }
    77 
    78         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_min ) );
    79         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_max ) );
    80         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (int)nv::sampler_wrap_to_enum( asampler.wrap_s) );
    81         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( asampler.wrap_t) );
    82 
    83         if (data)
    84         {
    85                 glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(aformat.format), size.x, size.y, 0, nv::image_format_to_enum(aformat.format), nv::datatype_to_gl_enum(aformat.type), data );
    86         }
    87 
    88         glBindTexture( GL_TEXTURE_2D, 0 );
     73        if ( gl_type == GL_TEXTURE_2D && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
     74        {
     75                // TODO: This should not be done if we use framebuffers!
     76                glTexParameteri( gl_type, GL_GENERATE_MIPMAP, GL_TRUE);
     77        }
     78
     79        if ( asampler.filter_max != sampler::NEAREST )
     80        {
     81                asampler.filter_max = sampler::LINEAR;
     82        }
     83
     84        glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_min ) );
     85        glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_max ) );
     86        glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, (int)nv::sampler_wrap_to_enum( asampler.wrap_s) );
     87        glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( asampler.wrap_t) );
     88
     89        glTexImage2D( gl_type, 0, (GLint)nv::image_format_to_internal_enum(aformat.format), size.x, size.y, 0, nv::image_format_to_enum(aformat.format), nv::datatype_to_gl_enum(aformat.type), data );
     90
     91        glBindTexture( gl_type, 0 );
    8992
    9093        texture result = m_textures.create();
    9194        gl_texture_info* info = m_textures.get( result );
     95        info->type     = type;
    9296        info->format   = aformat;
    9397        info->tsampler = asampler;
Note: See TracChangeset for help on using the changeset viewer.