Ignore:
Timestamp:
04/29/16 12:42:28 (9 years ago)
Author:
epyon
Message:
  • mass update (will try to do atomic from now)
File:
1 edited

Legend:

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

    r487 r491  
    1717gl_device::gl_device()
    1818{
    19         m_shader_header.append( "#version 330\n" );
     19        m_shader_header.append( "#version 330 core\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!" );
     97        NV_ASSERT_ALWAYS( type != TEXTURE_1D_BUFFER && type != TEXTURE_3D && type != TEXTURE_2D_ARRAY, "2D texture type expected!" );
    9898        unsigned glid = 0;
    9999        unsigned gl_type = texture_type_to_enum( type );
     100        GLint gl_internal = GLint( nv::image_format_to_internal_enum( aformat.format ) );
     101        unsigned gl_enum = nv::image_format_to_enum( aformat.format );
    100102
    101103        bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
     
    106108
    107109        // Detect if mipmapping was requested
    108         if ( gl_type == GL_TEXTURE_2D && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
     110        if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
    109111        {
    110112                // TODO: This should not be done if we use framebuffers!
     
    119121        glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) );
    120122        glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) );
    121         glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s) ) );
    122         glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t) ) );
     123       
     124        if ( gl_enum != GL_RED_INTEGER )
     125        {
     126                glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) );
     127                glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) );
     128        }
    123129
    124130        if ( is_depth )
     
    140146//      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso );
    141147
    142         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 );
     148        glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum(aformat.type), data );
    143149
    144150        glBindTexture( gl_type, 0 );
     
    154160}
    155161
     162
     163nv::texture nv::gl_device::create_texture( texture_type type, pixel_format format )
     164{
     165        NV_ASSERT_ALWAYS( type == TEXTURE_1D_BUFFER );
     166        unsigned glid = 0;
     167        unsigned gl_type = texture_type_to_enum( type );
     168
     169        glGenTextures( 1, &glid );
     170
     171        texture result = m_textures.create();
     172        gl_texture_info* info = m_textures.get( result );
     173        info->type = type;
     174        info->format = format;
     175        info->tsampler = sampler();
     176        info->size = ivec3( 1, 1, 1 );
     177        info->glid = glid;
     178
     179        return result;
     180}
     181
    156182nv::texture nv::gl_device::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
    157183{
     
    234260nv::buffer nv::gl_device::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ )
    235261{
    236         unsigned glid   = 0;
     262        unsigned glid = 0;
    237263        unsigned glenum = buffer_type_to_enum( type );
    238264        glGenBuffers( 1, &glid );
    239265
    240         glBindBuffer( glenum, glid );
    241         glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( hint ) );
    242         glBindBuffer( glenum, 0 );
     266        if ( size > 0 )
     267        {
     268                glBindBuffer( glenum, glid );
     269                glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( hint ) );
     270                glBindBuffer( glenum, 0 );
     271        }
    243272
    244273        buffer result = m_buffers.create();
     
    249278        info->glid = glid;
    250279        return result;
     280}
     281
     282void nv::gl_device::create_buffer( buffer b, size_t size, const void* source )
     283{
     284        gl_buffer_info* info = m_buffers.get( b );
     285        if ( info )
     286        {
     287                unsigned glenum = buffer_type_to_enum( info->type );
     288                glBindBuffer( glenum, info->glid );
     289                glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( info->hint ) );
     290                glBindBuffer( glenum, 0 );
     291        }
    251292}
    252293
Note: See TracChangeset for help on using the changeset viewer.