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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.