Changeset 463 for trunk


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

Legend:

Unmodified
Added
Removed
  • trunk/nv/gl/gl_context.hh

    r406 r463  
    4343
    4444                virtual void attach( framebuffer f, output_slot slot, texture t );
    45                 virtual void attach( framebuffer f, texture depth );
     45                virtual void attach( framebuffer f, texture depth, int layer = -1 );
    4646                virtual void attach( framebuffer f, ivec2 size );
    4747                virtual bool check( framebuffer_slot ft );
  • trunk/nv/gl/gl_device.hh

    r439 r463  
    4747                virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr );
    4848                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr );
     49                virtual texture create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data = nullptr );
    4950
    5051                virtual void release( buffer b );
  • trunk/nv/interface/context.hh

    r430 r463  
    9696
    9797                virtual void attach( framebuffer f, output_slot slot, texture t ) = 0;
    98                 virtual void attach( framebuffer f, texture depth ) = 0;
     98                virtual void attach( framebuffer f, texture depth, int layer = -1 ) = 0;
    9999                virtual void attach( framebuffer f, ivec2 size ) = 0;
    100100
  • trunk/nv/interface/device.hh

    r462 r463  
    4949                TEXTURE_3D,
    5050                TEXTURE_CUBE,
     51                TEXTURE_1D_ARRAY,
     52                TEXTURE_2D_ARRAY,
    5153        };
    5254
     
    140142        {
    141143                texture_type type;
    142                 ivec2        size;
     144                ivec3        size;
    143145                image_format format;
    144146                sampler      tsampler;
     
    174176                virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr ) = 0;
    175177                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr ) = 0;
     178                virtual texture create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data = nullptr ) = 0;
    176179                // TODO: remove?
    177180                virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr ) { return create_texture( TEXTURE_2D, size, aformat, asampler, data ); }
  • trunk/nv/lib/detail/gl_ext/gl_ext_all_functions.inc

    r406 r463  
    11#include <nv/lib/detail/gl_ext/gl_ext_framebuffer_object_functions.inc>
    22#include <nv/lib/detail/gl_ext/gl_ext_framebuffer_blit_functions.inc>
     3#include <nv/lib/detail/gl_ext/gl_ext_texture_array_functions.inc>
  • trunk/nv/lib/detail/gl_ext/gl_ext_all_types.inc

    r406 r463  
    11#include <nv/lib/detail/gl_ext/gl_ext_framebuffer_object_types.inc>
    22#include <nv/lib/detail/gl_ext/gl_ext_framebuffer_blit_types.inc>
     3#include <nv/lib/detail/gl_ext/gl_ext_texture_array_types.inc>
  • trunk/nv/lib/detail/gl_ext/gl_ext_info.inc

    r406 r463  
    11NV_GL_EXTENSION( 1, FRAMEBUFFER_OBJECT, framebuffer_object )
    22NV_GL_EXTENSION( 2, FRAMEBUFFER_BLIT, framebuffer_blit )
     3NV_GL_EXTENSION( 3, TEXTURE_ARRAY, texture_array )
  • trunk/nv/lib/detail/gl_functions.inc

    r311 r463  
    180180NV_GL_FUN_EXT( void , glUniformMatrix4x3fv , ( GLint , GLsizei , GLboolean , const GLfloat *) );
    181181
     182// Unknown -
     183NV_GL_FUN_EXT( void , glTexImage3D, ( GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *) );
  • trunk/nv/lib/gl.hh

    r395 r463  
    8484#include <nv/lib/detail/gl_ext/gl_ext_info.inc>
    8585#undef NV_GL_EXTENSION
    86 //              EXT_PIXEL_BUFFER_OBJECT = 0x00000004,
    87 //              EXT_TEXTURE_CUBE_MAP    = 0x00000008,
    88 //              EXT_TEXTURE_3D          = 0x00000010,
    8986        };
    9087
  • 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
  • trunk/src/lib/gl.cc

    r440 r463  
    269269#include <nv/lib/detail/gl_ext/gl_ext_framebuffer_object_functions.inc>
    270270        } break;
     271        case GL_EXT_TEXTURE_ARRAY: {
     272#include <nv/lib/detail/gl_ext/gl_ext_texture_array_functions.inc>
     273        } break;
    271274        default : {
    272275                NV_LOG_ERROR( "load_gl_extension - unknown extension \"", name, "\"!" );
Note: See TracChangeset for help on using the changeset viewer.