Changeset 501 for trunk/src


Ignore:
Timestamp:
06/15/16 18:34:37 (9 years ago)
Author:
epyon
Message:
  • particle engine updates
  • device/context redesign
  • caching of GL state - texture bindings and programs
  • camera view_perspective and view_perspective_inv
Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/engine/material_manager.cc

    r498 r501  
    2020        uint8 data[2 * 2 * 3];
    2121        nv::raw_fill_n( data, 2 * 2 * 3, 0 );
    22         m_default = m_context->get_device()->create_texture( ivec2(2,2), nv::image_format( nv::RGB ), nv::sampler(), data );
     22        m_default = m_context->create_texture( ivec2(2,2), nv::image_format( nv::RGB ), nv::sampler(), data );
    2323}
    2424
     
    3434                                if ( auto data = m_image_manager->get( mat->paths[i] ).lock() )
    3535                                {
    36                                         result->textures[i] = m_context->get_device()->create_texture( &*data, smp );
     36                                        result->textures[i] = m_context->create_texture( &*data, smp );
    3737                                }
    3838                        }
     
    5353        for ( const texture& t : m->textures )
    5454        {
    55                 m_context->get_device()->release( t );
     55                m_context->release( t );
    5656        }
    5757}
  • trunk/src/engine/particle_engine.cc

    r500 r501  
    320320
    321321        data.quota   = table.get<uint32>("quota", 1024 );
    322         data.local   = table.get<bool>("local_space", false );
     322//      data.local   = table.get<bool>("local_space", false );
    323323        data.accurate_facing = table.get<bool>("accurate_facing", false );
    324324        data.emmiter_count   = 0;
     
    467467{
    468468        m_context       = a_context;
    469         m_device        = a_context->get_device();
    470         m_program_local = m_device->create_program( nv_particle_engine_vertex_shader_local, nv_particle_engine_fragment_shader );
    471         m_program_world = m_device->create_program( nv_particle_engine_vertex_shader_world, nv_particle_engine_fragment_shader );
     469        m_program_local = m_context->create_program( nv_particle_engine_vertex_shader_local, nv_particle_engine_fragment_shader );
     470        m_program_world = m_context->create_program( nv_particle_engine_vertex_shader_world, nv_particle_engine_fragment_shader );
    472471
    473472        register_standard_emmiters();
     
    533532        info->count = 0;
    534533        info->quota = max_particles;
    535         info->vtx_buffer = m_device->create_buffer( VERTEX_BUFFER, STREAM_DRAW, info->quota * sizeof( particle_quad )/*, info->quads_[0].data*/ );
     534        info->vtx_buffer = m_context->create_buffer( VERTEX_BUFFER, STREAM_DRAW, info->quota * sizeof( particle_quad )/*, info->quads_[0].data*/ );
    536535        vertex_array_desc desc;
    537536        desc.add_vertex_buffers< particle_vtx >( info->vtx_buffer, true );
     
    545544{
    546545        clear();
    547         m_device->release( m_program_world );
    548         m_device->release( m_program_local );
     546        m_context->release( m_program_world );
     547        m_context->release( m_program_local );
    549548}
    550549
     
    785784        vec3 source;
    786785        mat3 orient;
    787         bool local = info->data->local;
     786//      bool local = info->data->local;
    788787//      if ( !local )
    789788//      {
  • trunk/src/engine/program_manager.cc

    r479 r501  
    3636        }
    3737
    38         add( id, m_context->get_device()->create_program( vsource, fsource ) );
     38        add( id, m_context->create_program( vsource, fsource ) );
    3939        return true;
    4040}
     
    4242void nv::program_manager::release( program p )
    4343{
    44         m_context->get_device()->release( p );
     44        m_context->release( p );
    4545}
    4646
  • trunk/src/gfx/debug_draw.cc

    r499 r501  
    3535        : m_context( a_context ), m_program(), m_va()
    3636{
    37         m_program = m_context->get_device()->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );
     37        m_program = m_context->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );
    3838        m_buffer_size = 0;
    3939}
     
    4545                if ( m_va.is_valid() ) m_context->release( m_va );
    4646                m_buffer_size = nv::max( m_data.size(), 4096U, m_buffer_size );
    47                 m_vb = m_context->get_device()->create_buffer( VERTEX_BUFFER, nv::STREAM_DRAW, m_buffer_size * sizeof( debug_vtx ) );
     47                m_vb = m_context->create_buffer( VERTEX_BUFFER, nv::STREAM_DRAW, m_buffer_size * sizeof( debug_vtx ) );
    4848                vertex_array_desc va_desc;
    4949                va_desc.add_vertex_buffers< debug_vtx >( m_vb, true );
     
    8989{
    9090        m_context->release( m_va );
    91         m_context->get_device()->release( m_program );
     91        m_context->release( m_program );
    9292}
  • trunk/src/gl/gl_context.cc

    r500 r501  
    6666                }
    6767        }
    68         glBindBuffer( GL_ARRAY_BUFFER, 0 );
    6968        glBindVertexArray( 0 );
    7069
     
    104103                {
    105104                        if ( info->attr[i].owner )
    106                                 m_device->release( info->attr[i].vbuffer );
    107                 }
    108                 if ( info->index.is_valid() && info->index_owner) m_device->release( info->index );
     105                                release( info->attr[i].vbuffer );
     106                }
     107                if ( info->index.is_valid() && info->index_owner) release( info->index );
    109108                glDeleteVertexArrays( 1, &info->glid );
    110109                m_vertex_arrays.destroy( va );
     
    223222                glBindFramebuffer( GL_DRAW_FRAMEBUFFER, tinfo ? tinfo->glid : 0 );
    224223                unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;
    225                 int remove_below;
    226                 filter = GL_NEAREST;
    227224                glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter );
    228225                glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
     
    270267}
    271268
     269
    272270void nv::gl_context::bind( buffer b, texture t )
    273271{
     
    304302                        set_active_texture( slot );
    305303                        glBindTexture( texture_type_to_enum( info->type ), info->glid );
     304                        m_bound_textures[slot] = t;
    306305                }
    307306        }
     
    314313        if ( info )
    315314        {
    316                 glUseProgram( info->glid );
     315                if ( m_bound_program != p )
     316                        glUseProgram( info->glid );
    317317                gdevice->update_uniforms( info );
    318318                if ( !info->validated )
     
    320320                        validate_program( p );
    321321                }
     322                m_bound_program = p;
    322323        }
    323324}
     
    369370void nv::gl_context::unbind( program )
    370371{
    371         glUseProgram( 0 );
     372        if ( m_bound_program )
     373                glUseProgram( 0 );
     374        m_bound_program = program();
    372375}
    373376
     
    375378{
    376379        if ( slot != m_active_slot )
     380        {
    377381                glActiveTexture( GL_TEXTURE0 + static_cast<GLenum>( slot ) );
     382                m_active_slot = slot;
     383        }
    378384}
    379385
     
    419425                unsigned     gl_type = texture_type_to_enum( info->type );
    420426
    421                 if ( m_bound_textures[ m_active_slot ] != t )
    422                         glBindTexture( gl_type, info->glid );
    423                 int this_should_be_subTexImage;
     427                bind( t, texture_slot::TEXTURE_0 );
    424428                if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY )
    425                         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 );
     429//                      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 );
     430                        glTexSubImage3D( gl_type, 0, 0, 0, 0, size.x, size.y, size.z, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data );
    426431                else
    427                         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 );
     432//                      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 );
     433                        glTexSubImage2D( gl_type, 0, 0, 0, size.x, size.y, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data );
    428434        }
    429435}
     
    518524void gl_context::set_viewport( const ivec4& viewport )
    519525{
    520         NV_ASSERT_ALWAYS( viewport.z > 0 && viewport.w > 0, "viewport dimensions must be greater than zero!" );
    521         m_viewport = viewport;
    522         glViewport( viewport.x, viewport.y, viewport.z, viewport.w );
     526        if ( m_viewport != viewport )
     527        {
     528                NV_ASSERT_ALWAYS( viewport.z > 0 && viewport.w > 0, "viewport dimensions must be greater than zero!" );
     529                m_viewport = viewport;
     530                glViewport( viewport.x, viewport.y, viewport.z, viewport.w );
     531        }
    523532}
    524533
     
    860869}
    861870
     871nv::texture nv::gl_context::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
     872{
     873        texture result = create_texture( type, aformat.format );
     874        gl_texture_info* info = static_cast<gl_device*>( m_device )->get_full_texture_info( result );
     875        bind( result, texture_slot::TEXTURE_0 );
     876        unsigned glid = info->glid;
     877        unsigned gl_type = texture_type_to_enum( type );
     878        GLenum gl_internal = GLenum( image_format_to_internal_enum( aformat.format ) );
     879        unsigned gl_enum = image_format_to_enum( aformat.format );
     880
     881        bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
     882
     883        // Detect if mipmapping was requested
     884        //      if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
     885        //      {
     886        //              // TODO: This should not be done if we use framebuffers!
     887        //              glTexParameteri( gl_type, GL_GENERATE_MIPMAP, GL_TRUE);
     888        //      }
     889
     890        if ( asampler.filter_max != sampler::NEAREST )
     891        {
     892                asampler.filter_max = sampler::LINEAR;
     893        }
     894
     895        if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE )
     896        {
     897                glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) );
     898                glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) );
     899        }
     900
     901        if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE && gl_enum != GL_RED_INTEGER )
     902        {
     903                glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) );
     904                glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) );
     905        }
     906
     907        if ( is_depth )
     908        {
     909                //              glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
     910                //              glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
     911
     912                // This is to allow usage of shadow2DProj function in the shader
     913                glTexParameteri( gl_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE );
     914                glTexParameteri( gl_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
     915        }
     916
     917        // #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
     918        // #define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
     919        //
     920        //      float aniso = 0.0f;
     921        //      glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso );
     922        //      NV_LOG_INFO( "Anisotropy at ", aniso, " (", int( aniso ), " ) " );
     923        //      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso );
     924
     925        if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE )
     926                glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum( aformat.type ), data );
     927        else
     928                glTexImage2DMultisample( gl_type, 4, gl_internal, size.x, size.y, 1 );
     929
     930        if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
     931        {
     932                // TODO: This should not be done if we use framebuffers!
     933                glGenerateMipmap( gl_type );
     934        }
     935
     936        bind( texture(), texture_slot::TEXTURE_0 );
     937
     938        info->type = type;
     939        info->format = aformat;
     940        info->tsampler = asampler;
     941        info->size = ivec3( size.x, size.y, 1 );
     942        info->glid = glid;
     943
     944        return result;
     945}
     946
     947nv::texture nv::gl_context::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
     948{
     949        texture result = create_texture( type, aformat.format );
     950        gl_texture_info* info = static_cast<gl_device*>( m_device )->get_full_texture_info( result );
     951        bind( result, texture_slot::TEXTURE_0 );
     952        unsigned glid = info->glid;
     953
     954        unsigned gl_type = texture_type_to_enum( type );
     955
     956        bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
     957
     958        if ( asampler.filter_max != sampler::NEAREST )
     959        {
     960                asampler.filter_max = sampler::LINEAR;
     961        }
     962
     963        glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) );
     964        glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) );
     965        glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) );
     966        glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) );
     967
     968        if ( is_depth )
     969        {
     970                glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
     971                glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
     972
     973                // This is to allow usage of shadow2DProj function in the shader
     974                glTexParameteri( gl_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE );
     975                glTexParameteri( gl_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
     976        }
     977
     978        //glTexStorage3D( GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount );
     979        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 );
     980
     981        bind( texture(), texture_slot::TEXTURE_0 );
     982
     983        info->type = type;
     984        info->format = aformat;
     985        info->tsampler = asampler;
     986        info->size = size;
     987        info->glid = glid;
     988
     989        return result;
     990}
     991
     992nv::buffer nv::gl_context::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ )
     993{
     994        buffer result = static_cast<gl_device*>( m_device )->create_buffer( type, hint );
     995        if ( size > 0 ) create_buffer( result, size, source );
     996        return result;
     997}
     998
     999void nv::gl_context::create_buffer( buffer b, size_t size, const void* source /*= nullptr */ )
     1000{
     1001        gl_buffer_info* info = static_cast<gl_device*>( m_device )->get_full_buffer_info( b );
     1002        if ( info )
     1003        {
     1004                unsigned glenum = buffer_type_to_enum( info->type );
     1005                glBindBuffer( glenum, info->glid );
     1006                glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( info->hint ) );
     1007                glBindBuffer( glenum, 0 );
     1008        }
     1009}
     1010
    8621011void nv::gl_context::set_draw_buffers( uint32 count, const output_slot* slots )
    8631012{
  • trunk/src/gl/gl_device.cc

    r498 r501  
    9494}
    9595
    96 nv::texture nv::gl_device::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
    97 {
    98         NV_ASSERT_ALWAYS( type != TEXTURE_1D_BUFFER && type != TEXTURE_3D && type != TEXTURE_2D_ARRAY, "2D texture type expected!" );
    99         unsigned glid = 0;
    100         unsigned gl_type = texture_type_to_enum( type );
    101         GLenum gl_internal = GLenum( nv::image_format_to_internal_enum( aformat.format ) );
    102         unsigned gl_enum = nv::image_format_to_enum( aformat.format );
    103 
    104         bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
    105 
    106         glGenTextures( 1, &glid );
    107 
    108         glBindTexture( gl_type, glid );
    109 
    110         // Detect if mipmapping was requested
    111 //      if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
    112 //      {
    113 //              // TODO: This should not be done if we use framebuffers!
    114 //              glTexParameteri( gl_type, GL_GENERATE_MIPMAP, GL_TRUE);
    115 //      }
    116 
    117         if ( asampler.filter_max != sampler::NEAREST )
    118         {
    119                 asampler.filter_max = sampler::LINEAR;
    120         }
    121 
    122         if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE )
    123         {
    124                 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) );
    125                 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) );
    126         }
    127        
    128         if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE && gl_enum != GL_RED_INTEGER )
    129         {
    130                 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) );
    131                 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) );
    132         }
    133 
    134         if ( is_depth )
    135         {
    136 //              glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    137 //              glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    138 
    139                 // This is to allow usage of shadow2DProj function in the shader
    140                 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE );
    141                 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
    142         }
    143 
    144 // #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
    145 // #define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
    146 //
    147 //      float aniso = 0.0f;
    148 //      glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso );
    149 //      NV_LOG_INFO( "Anisotropy at ", aniso, " (", int( aniso ), " ) " );
    150 //      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso );
    151 
    152         if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE )
    153                 glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum(aformat.type), data );
    154         else
    155                 glTexImage2DMultisample( gl_type, 4, gl_internal, size.x, size.y, 1 );
    156 
    157         if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
    158         {
    159                 // TODO: This should not be done if we use framebuffers!
    160                 glGenerateMipmap( gl_type );
    161         }
    162 
    163 
    164         glBindTexture( gl_type, 0 );
    165 
    166         texture result = m_textures.create();
    167         gl_texture_info* info = m_textures.get( result );
    168         info->type     = type;
    169         info->format   = aformat;
    170         info->tsampler = asampler;
    171         info->size     = ivec3( size.x, size.y, 1 );
    172         info->glid     = glid;
    173         return result;
    174 }
    175 
    176 
    17796nv::texture nv::gl_device::create_texture( texture_type type, pixel_format format )
    17897{
    179         NV_ASSERT_ALWAYS( type == TEXTURE_1D_BUFFER, "create_texture not texture buffer!" );
    18098        unsigned glid = 0;
    18199
     
    193111}
    194112
    195 nv::texture nv::gl_device::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
    196 {
    197         NV_ASSERT_ALWAYS( type == TEXTURE_3D || type == TEXTURE_2D_ARRAY, "3D texture type expected!" );
    198         unsigned glid = 0;
    199         unsigned gl_type = texture_type_to_enum( type );
    200 
    201         bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
    202 
    203         glGenTextures( 1, &glid );
    204         glBindTexture( gl_type, glid );
    205 
    206         if ( asampler.filter_max != sampler::NEAREST )
    207         {
    208                 asampler.filter_max = sampler::LINEAR;
    209         }
    210 
    211         glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) );
    212         glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) );
    213         glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) );
    214         glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) );
    215 
    216         if ( is_depth )
    217         {
    218                 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    219                 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    220 
    221                 // This is to allow usage of shadow2DProj function in the shader
    222                 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE );
    223                 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
    224         }
    225 
    226         //glTexStorage3D( GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount );
    227         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 );
    228         glBindTexture( gl_type, 0 );
    229 
    230         texture result = m_textures.create();
    231         gl_texture_info* info = m_textures.get( result );
    232         info->type = type;
    233         info->format = aformat;
    234         info->tsampler = asampler;
    235         info->size = size;
    236         info->glid = glid;
    237         return result;
    238 }
    239 
    240 
    241 
    242113void nv::gl_device::release( texture t )
    243114{
     
    271142}
    272143
    273 nv::buffer nv::gl_device::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ )
     144nv::buffer nv::gl_device::create_buffer( buffer_type type, buffer_hint hint )
    274145{
    275146        unsigned glid = 0;
    276147        unsigned glenum = buffer_type_to_enum( type );
    277148        glGenBuffers( 1, &glid );
    278 
    279         if ( size > 0 )
    280         {
    281                 glBindBuffer( glenum, glid );
    282                 glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( hint ) );
    283                 glBindBuffer( glenum, 0 );
    284         }
    285149
    286150        buffer result = m_buffers.create();
     
    288152        info->type = type;
    289153        info->hint = hint;
    290         info->size = size;
     154        info->size = 0;
    291155        info->glid = glid;
    292156        return result;
    293 }
    294 
    295 void nv::gl_device::create_buffer( buffer b, size_t size, const void* source )
    296 {
    297         gl_buffer_info* info = m_buffers.get( b );
    298         if ( info )
    299         {
    300                 unsigned glenum = buffer_type_to_enum( info->type );
    301                 glBindBuffer( glenum, info->glid );
    302                 glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( info->hint ) );
    303                 glBindBuffer( glenum, 0 );
    304         }
    305157}
    306158
     
    330182                m_programs.destroy( p );
    331183        }
     184}
     185
     186nv::gl_texture_info* nv::gl_device::get_full_texture_info( texture t )
     187{
     188        return m_textures.get( t );
     189
     190}
     191
     192nv::gl_buffer_info* nv::gl_device::get_full_buffer_info( buffer t )
     193{
     194        return m_buffers.get( t );
    332195}
    333196
  • trunk/src/gui/gui_gfx_renderer.cc

    r492 r501  
    116116        ~screen_render_data()
    117117        {
    118                 ctx->get_device()->release( shader );
     118                ctx->release( shader );
    119119                ctx->release( varray );
    120120        }
     
    157157        screen_render_data* sr = new screen_render_data( w->get_context(), 1024 );
    158158        m_render_data = sr;
    159         sr->shader = m_window->get_device()->create_program( nv_gui_vertex_shader, nv_gui_fragment_shader );
     159        sr->shader = m_window->get_context()->create_program( nv_gui_vertex_shader, nv_gui_fragment_shader );
    160160        m_scene_state.get_camera().set_ortho( 0.0f, float( m_window->get_width() ), float( m_window->get_height() ), 0.0f );
    161161
     
    166166
    167167        nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE );
    168         sr->tex = m_window->get_device()->create_texture( m_atlas.get_size(), image_format( nv::RGBA, nv::UBYTE ), sampler, nullptr );
     168        sr->tex = m_window->get_context()->create_texture( m_atlas.get_size(), image_format( nv::RGBA, nv::UBYTE ), sampler, nullptr );
    169169
    170170        m_render_state.depth_test.enabled = false;
     
    395395        if ( m_render_data )
    396396        {
    397                 m_context->get_device()->release( reinterpret_cast< screen_render_data* >( m_render_data )->tex );
     397                m_context->release( reinterpret_cast< screen_render_data* >( m_render_data )->tex );
    398398                delete m_render_data;
    399399        }
  • trunk/src/lib/gl.cc

    r492 r501  
    5555
    5656
    57 static void* load_gl_ext_symbol_impl( const nv::string_view& name, nv::log_level fail_level = nv::LOG_DEBUG )
    58 {
    59         void* result = gl_ext_loader( name.data() );
    60         NV_LOG( ( result ? nv::LOG_DEBUG : fail_level ), "load_gl_ext_symbol : ", name, ( result ? " succeded." : "failed." ) );
    61         return result;
    62 }
    63 
    64 static void* load_gl_ext_symbol( const nv::string_view& name, bool iterate, const nv::string_view& ext )
    65 {
    66         void * result        = nullptr;
    67         nv::string128 test_name = name + ext;
    68         result = load_gl_ext_symbol_impl( !ext.empty() ? test_name : name );
    69         if ( result ) return result;
    70         if ( iterate )
    71         {
    72                 test_name = name + "ARB"_ls;
    73                 result = gl_ext_loader( test_name.data() );
    74                 if ( result ) return result;
    75                 test_name = name + "EXT"_ls;
    76                 result = gl_ext_loader( test_name.data() );
    77                 if ( result ) return result;
    78         }
    79         return result;
    80 }
     57// static void* load_gl_ext_symbol_impl( const nv::string_view& name, nv::log_level fail_level = nv::LOG_DEBUG )
     58// {
     59//      void* result = gl_ext_loader( name.data() );
     60//      NV_LOG( ( result ? nv::LOG_DEBUG : fail_level ), "load_gl_ext_symbol : ", name, ( result ? " succeded." : "failed." ) );
     61//      return result;
     62// }
     63
     64// static void* load_gl_ext_symbol( const nv::string_view& name, bool iterate, const nv::string_view& ext )
     65// {
     66//      void * result        = nullptr;
     67//      nv::string128 test_name = name + ext;
     68//      result = load_gl_ext_symbol_impl( !ext.empty() ? test_name : name );
     69//      if ( result ) return result;
     70//      if ( iterate )
     71//      {
     72//              test_name = name + "ARB"_ls;
     73//              result = gl_ext_loader( test_name.data() );
     74//              if ( result ) return result;
     75//              test_name = name + "EXT"_ls;
     76//              result = gl_ext_loader( test_name.data() );
     77//              if ( result ) return result;
     78//      }
     79//      return result;
     80// }
    8181
    8282bool nv::load_gl_library( const char* path, bool force_reload )
Note: See TracChangeset for help on using the changeset viewer.