Changeset 463 for trunk/src/gl


Ignore:
Timestamp:
08/28/15 18:28:34 (10 years ago)
Author:
epyon
Message:
  • 3D/2D_ARRAY texture support
Location:
trunk/src/gl
Files:
3 edited

Legend:

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

    r462 r463  
    111111}
    112112
    113 void nv::gl_context::attach( framebuffer f, texture depth )
     113void nv::gl_context::attach( framebuffer f, texture depth, int layer /*= -1*/ )
    114114{
    115115        // TODO: framebuffer variable, so no re-binding?
     
    121121                glBindFramebuffer( GL_FRAMEBUFFER, info->glid );
    122122                unsigned gl_type = texture_type_to_enum( tinfo->type );
    123                 if ( tinfo )
    124                 {
    125                         glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gl_type, tinfo->glid, 0 );
     123                unsigned glid = ( tinfo ? tinfo->glid : 0 );
     124                if ( layer >= 0 )
     125                {
     126                        glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, tinfo->glid, 0, layer );
    126127                }
    127128                else
    128129                {
    129                         glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gl_type, 0, 0 );
    130                 }
    131         }
     130                        glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gl_type, glid, 0 );
     131                }
     132        }
     133
    132134}
    133135
     
    328330        {
    329331                image_format format  = info->format;
    330                 ivec2        size    = info->size;
     332                ivec3        size    = info->size;
    331333                unsigned     gl_type = texture_type_to_enum( info->type );
    332334
    333335                glBindTexture( gl_type, info->glid );
    334                 glTexImage2D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum(format.format) ), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data );
     336                if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY )
     337                        glTexImage3D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum( format.format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data );
     338                else
     339                        glTexImage2D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum(format.format) ), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data );
    335340        }
    336341}
     
    690695{
    691696        // TODO: configurable:
    692         load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT );
     697        load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY );
    693698        force_apply_render_state( m_render_state );
    694699
  • trunk/src/gl/gl_device.cc

    r461 r463  
    1717gl_device::gl_device()
    1818{
    19         m_shader_header.append( "#version 120\n" );
     19        m_shader_header.append( "#version 120\n#extension GL_EXT_texture_array : require\n" );
    2020        for ( auto& i : get_uniform_factory() )
    2121                m_shader_header.append( "uniform "+datatype_to_glsl_type( i.second->get_datatype() )+" "+ i.first +";\n" );
     
    9595nv::texture nv::gl_device::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
    9696{
     97        NV_ASSERT_ALWAYS( type != TEXTURE_3D && type != TEXTURE_2D_ARRAY, "2D texture type expected!" );
    9798        unsigned glid = 0;
    9899        unsigned gl_type = texture_type_to_enum( type );
     100
     101        bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
     102
    99103        glGenTextures( 1, &glid );
    100104
     
    117121        glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s) ) );
    118122        glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t) ) );
     123
     124        if ( is_depth )
     125        {
     126#define GL_TEXTURE_DEPTH_SIZE 0x884A
     127#define GL_DEPTH_TEXTURE_MODE 0x884B
     128#define GL_TEXTURE_COMPARE_MODE 0x884C
     129#define GL_TEXTURE_COMPARE_FUNC 0x884D
     130#define GL_COMPARE_R_TO_TEXTURE 0x884E
     131
     132#define GL_INTENSITY 0x8049
     133#define GL_LUMINANCE 0x1909
     134//              glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
     135//              glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
     136//              glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE );
     137//              glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, 0 );
     138//              glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY );
     139        }
     140
     141// #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
     142// #define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
     143//
     144//      float aniso = 0.0f;
     145//      glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso );
     146//      NV_LOG_INFO( "Anisotropy at ", aniso, " (", int( aniso ), " ) " );
     147//      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso );
    119148
    120149        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 );
     
    127156        info->format   = aformat;
    128157        info->tsampler = asampler;
    129         info->size     = size;
     158        info->size     = ivec3( size.x, size.y, 1 );
    130159        info->glid     = glid;
    131160        return result;
    132161}
     162
     163nv::texture nv::gl_device::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
     164{
     165        NV_ASSERT_ALWAYS( type == TEXTURE_3D || type == TEXTURE_2D_ARRAY, "3D texture type expected!" );
     166        unsigned glid = 0;
     167        unsigned gl_type = texture_type_to_enum( type );
     168
     169        bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
     170
     171        glGenTextures( 1, &glid );
     172        glBindTexture( gl_type, glid );
     173
     174        if ( asampler.filter_max != sampler::NEAREST )
     175        {
     176                asampler.filter_max = sampler::LINEAR;
     177        }
     178
     179        glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) );
     180        glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) );
     181        glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) );
     182        glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) );
     183
     184        //glTexStorage3D( GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount );
     185        glTexImage3D( gl_type, 0, GLint( nv::image_format_to_internal_enum( aformat.format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( aformat.format ), nv::datatype_to_gl_enum( aformat.type ), data );
     186        glBindTexture( gl_type, 0 );
     187
     188        texture result = m_textures.create();
     189        gl_texture_info* info = m_textures.get( result );
     190        info->type = type;
     191        info->format = aformat;
     192        info->tsampler = asampler;
     193        info->size = size;
     194        info->glid = glid;
     195        return result;
     196}
     197
     198
    133199
    134200void nv::gl_device::release( texture t )
  • trunk/src/gl/gl_enum.cc

    r462 r463  
    1515        switch( type )
    1616        {
    17         case TEXTURE_1D   : return GL_TEXTURE_1D;
    18         case TEXTURE_2D   : return GL_TEXTURE_2D;
    19         case TEXTURE_RECT : return GL_TEXTURE_RECTANGLE;
    20         case TEXTURE_3D   : return GL_TEXTURE_3D;
    21         case TEXTURE_CUBE : return GL_TEXTURE_CUBE_MAP;
     17        case TEXTURE_1D      : return GL_TEXTURE_1D;
     18        case TEXTURE_2D      : return GL_TEXTURE_2D;
     19        case TEXTURE_RECT    : return GL_TEXTURE_RECTANGLE;
     20        case TEXTURE_3D      : return GL_TEXTURE_3D;
     21        case TEXTURE_CUBE    : return GL_TEXTURE_CUBE_MAP;
     22        case TEXTURE_1D_ARRAY: return GL_TEXTURE_1D_ARRAY;
     23        case TEXTURE_2D_ARRAY: return GL_TEXTURE_2D_ARRAY;
    2224        NV_RETURN_COVERED_DEFAULT( 0 );
    2325        }
     
    347349        case GL_SAMPLER_1D_SHADOW      : return INT;   
    348350        case GL_SAMPLER_2D_SHADOW      : return INT;
    349 // TODO: implement?
     351        case GL_SAMPLER_1D_ARRAY       : return INT;
     352        case GL_SAMPLER_2D_ARRAY       : return INT;
     353        case GL_SAMPLER_1D_ARRAY_SHADOW: return INT;
     354        case GL_SAMPLER_2D_ARRAY_SHADOW: return INT;
     355                // TODO: implement?
    350356//      case GL_BOOL   
    351357//      case GL_BOOL_VEC2
Note: See TracChangeset for help on using the changeset viewer.