Ignore:
Timestamp:
05/05/16 19:37:28 (9 years ago)
Author:
epyon
Message:
 
File:
1 edited

Legend:

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

    r491 r492  
    7474        }
    7575
    76         for ( uint32 i = 0; i < info->count; ++i )
    77         {
    78                 glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
    79         }
     76//      for ( uint32 i = 0; i < info->count; ++i )
     77//      {
     78//              glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
     79//      }
    8080
    8181
     
    8383}
    8484
    85 nv::framebuffer nv::gl_context::create_framebuffer()
     85nv::framebuffer nv::gl_context::create_framebuffer( uint32 temp_samples )
    8686{
    8787        unsigned glid   = 0;
     
    9292        info->depth_rb_glid = 0;
    9393        info->color_attachment_count = 0;
     94        info->sample_count = temp_samples;
    9495        return result;
    9596}
     
    192193                glGenRenderbuffers( 1, &(info->depth_rb_glid) );
    193194                glBindRenderbuffer( GL_RENDERBUFFER, info->depth_rb_glid );
    194                 glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.x, size.y );
     195                if ( info->sample_count > 1 )
     196                        glRenderbufferStorageMultisample( GL_RENDERBUFFER, info->sample_count, GL_DEPTH_COMPONENT16, size.x, size.y );
     197                else
     198                        glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.x, size.y );
    195199                glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, info->depth_rb_glid );
    196200                glBindRenderbuffer( GL_RENDERBUFFER, 0 );
     
    211215
    212216
     217void nv::gl_context::blit( framebuffer from, framebuffer to, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 )
     218{
     219        gl_framebuffer_info* finfo = m_framebuffers.get( from );
     220        gl_framebuffer_info* tinfo = m_framebuffers.get( to );
     221        if ( finfo )
     222        {
     223                glBindFramebuffer( GL_READ_FRAMEBUFFER, finfo->glid );
     224                glBindFramebuffer( GL_DRAW_FRAMEBUFFER, tinfo ? tinfo->glid : 0 );
     225                unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;
     226                int remove_below;
     227                filter = GL_NEAREST;
     228                glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter );
     229                glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
     230                if ( tinfo ) glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
     231        }
     232}
     233
    213234bool nv::gl_context::check( framebuffer_slot ft )
    214235{
     
    220241        switch ( result )
    221242        {
     243        case GL_FRAMEBUFFER_UNDEFINED                     : NV_LOG_ERROR( "gl_context::check : Framebuffer undefined!" ); break;
     244        case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE        : NV_LOG_ERROR( "gl_context::check : Incomplete multisample!" ); break;
     245        case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS      : NV_LOG_ERROR( "gl_context::check : Incomplete layer targets!" ); break;
    222246        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT         : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete attachment!" ); break;
    223247        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : NV_LOG_ERROR( "gl_context::check : Framebuffer missing attachment!" ); break;
     
    255279        {
    256280                NV_ASSERT_ALWAYS( binfo->type == TEXTURE_BUFFER && tinfo->type == TEXTURE_1D_BUFFER, "bad texture or buffer type!" );
    257                 glActiveTexture( GL_TEXTURE0 );
    258                 glBindTexture( GL_TEXTURE_BUFFER, tinfo->glid );
     281                bind( t, TEXTURE_0 );
    259282                glTexBuffer( GL_TEXTURE_BUFFER, image_format_to_internal_enum( tinfo->format.format ), binfo->glid );
    260                 glBindTexture( GL_TEXTURE_BUFFER, 0 );
    261283        }
    262284}
     
    276298void gl_context::bind( texture t, texture_slot slot )
    277299{
    278         const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) );
    279         if ( info )
    280         {
    281                 glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) );
    282                 glBindTexture( texture_type_to_enum( info->type ), info->glid );
     300        if ( m_bound_textures[ slot ] != t )
     301        {
     302                const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) );
     303                if ( info )
     304                {
     305                        set_active_texture( slot );
     306                        glBindTexture( texture_type_to_enum( info->type ), info->glid );
     307                }
    283308        }
    284309}
     
    318343}
    319344
     345void nv::gl_context::set_active_texture( texture_slot slot )
     346{
     347        if ( slot != m_active_slot )
     348                glActiveTexture( GL_TEXTURE0 + static_cast<GLenum>( slot ) );
     349}
     350
    320351// void nv::gl_context::unbind( buffer b )
    321352// {
     
    352383        const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) );
    353384        NV_ASSERT_ALWAYS( info->type != TEXTURE_1D_BUFFER, "Buffer texture passed to update!" );
     385        NV_ASSERT_ALWAYS( info->type != TEXTURE_2D_MULTISAMPLE, "Multisample texture passed to update!" );
    354386        if ( info )
    355387        {
     
    358390                unsigned     gl_type = texture_type_to_enum( info->type );
    359391
    360                 glBindTexture( gl_type, info->glid );
     392                if ( m_bound_textures[ m_active_slot ] != t )
     393                        glBindTexture( gl_type, info->glid );
    361394                int this_should_be_subTexImage;
    362395                if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY )
     
    543576                glDepthMask( mask );
    544577                m_render_state.depth_mask = mask;
     578        }
     579}
     580
     581void gl_context::apply_multisample( bool multisample )
     582{
     583        if ( m_render_state.multisample != multisample )
     584        {
     585                glDepthMask( multisample );
     586                m_render_state.multisample = multisample;
    545587        }
    546588}
     
    727769        apply_color_mask( state.color_mask );
    728770        apply_depth_mask( state.depth_mask );
     771        apply_multisample( state.multisample );
    729772        apply_polygon_mode( state.polygon_mode );
    730773}
     
    736779        // TODO: configurable:
    737780//      load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY );
     781        m_active_slot = texture_slot( -1 );
    738782        force_apply_render_state( m_render_state );
    739783}
Note: See TracChangeset for help on using the changeset viewer.