Changeset 300


Ignore:
Timestamp:
08/07/14 10:29:34 (11 years ago)
Author:
epyon
Message:
  • removed gl_names - too much bloat for too little gain
Location:
trunk
Files:
2 deleted
7 edited

Legend:

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

    r299 r300  
    1616#include <nv/interface/program.hh>
    1717#include <nv/string.hh>
    18 #include <nv/gl/gl_names.hh>
    1918
    2019namespace nv
     
    3736                unsigned int get_id() const     { return object_id;     }
    3837        private:
    39                 uint32 shader_type;
    40                 uint32 object_id;
     38                uint32   shader_type;
     39                unsigned object_id;
    4140        };
    4241
     
    5857                void load_uniforms();
    5958
    60                 gl_shader_name m_name;
     59                unsigned  glid;
    6160                gl_shader vertex_shader;
    6261                gl_shader fragment_shader;
  • trunk/nv/gl/gl_texture2d.hh

    r299 r300  
    1414
    1515#include <nv/interface/texture2d.hh>
    16 #include <nv/gl/gl_names.hh>
    1716
    1817namespace nv
     
    2524
    2625                gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr );
     26                ~gl_texture2d();
    2727        protected:
    28                 gl_texture_name m_name;
     28                unsigned glid;
    2929        };
    3030       
  • trunk/nv/gl/gl_vertex_buffer.hh

    r299 r300  
    1414
    1515#include <nv/interface/vertex_buffer.hh>
    16 #include <nv/gl/gl_names.hh>
    1716
    1817namespace nv
     
    2524
    2625                gl_vertex_buffer( buffer_hint hint, size_t size, const void* data = nullptr );
     26                ~gl_vertex_buffer();
    2727        private:
    28                 gl_buffer_name m_name;
     28                unsigned glid;
    2929        };
    3030
     
    3535
    3636                gl_index_buffer( buffer_hint hint, size_t size, const void* data = nullptr );
     37                ~gl_index_buffer();
    3738        private:
    38                 gl_buffer_name m_name;
     39                unsigned glid;
    3940        };
    4041
  • trunk/src/gl/gl_context.cc

    r299 r300  
    1616void gl_context::bind( texture2d* texture, texture_slot slot )
    1717{
    18         GLuint id = static_cast< gl_texture2d* >( texture )->m_name.get_value();
     18        GLuint id = static_cast< gl_texture2d* >( texture )->glid;
    1919        glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) );
    2020        glBindTexture( GL_TEXTURE_2D, id );
     
    2424{
    2525        gl_program* glp = static_cast< gl_program* >( p );
    26         glUseProgram( glp->m_name.get_value() );
     26        glUseProgram( glp->glid );
    2727        glp->update_uniforms();
    2828}
     
    3030void nv::gl_context::bind( vertex_buffer* b )
    3131{
    32         GLuint id = static_cast< gl_vertex_buffer* >( b )->m_name.get_value();
     32        GLuint id = static_cast< gl_vertex_buffer* >( b )->glid;
    3333        glBindBuffer( GL_ARRAY_BUFFER, id );
    3434}
     
    3636void nv::gl_context::bind( index_buffer* b )
    3737{
    38         GLuint id = static_cast< gl_index_buffer* >( b )->m_name.get_value();
     38        GLuint id = static_cast< gl_index_buffer* >( b )->glid;
    3939        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, id );
    4040}
     
    9696void gl_context::update( texture2d* texture, void* data )
    9797{
    98         GLuint id = static_cast< gl_texture2d* >( texture )->m_name.get_value();
     98        GLuint id = static_cast< gl_texture2d* >( texture )->glid;
    9999        image_format format = texture->get_format();
    100100        ivec2        size   = texture->get_size();
  • trunk/src/gl/gl_program.cc

    r299 r300  
    8888        : vertex_shader( GL_VERTEX_SHADER ), fragment_shader( GL_FRAGMENT_SHADER )
    8989{
     90        glid = glCreateProgram();
    9091        compile( vertex_program, fragment_program );
    9192}
     
    9394gl_program::~gl_program()
    9495{
    95         if ( is_valid() )
     96        if ( glid != 0 )
    9697        {
    9798                // Detach the shaders from the program
    98                 glDetachShader( m_name.get_value(), vertex_shader.get_id() );
    99                 glDetachShader( m_name.get_value(), fragment_shader.get_id() );
     99                glDetachShader( glid, vertex_shader.get_id() );
     100                glDetachShader( glid, fragment_shader.get_id() );
     101                glDeleteProgram( glid );
    100102        }
    101103}
     
    106108        if (!fragment_shader.compile( fragment_program )) { return false; }
    107109
    108         glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::POSITION   ), "nv_position"  );
    109         glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TEXCOORD   ), "nv_texcoord"  );
    110         glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::NORMAL     ), "nv_normal"    );
    111         glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::COLOR      ), "nv_color"     );
    112         glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TANGENT    ), "nv_tangent"   );
    113         glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::BONEINDEX  ), "nv_boneindex" );
    114         glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::BONEWEIGHT ), "nv_boneweight");
    115 
    116         glAttachShader( m_name.get_value(), fragment_shader.get_id() );
    117         glAttachShader( m_name.get_value(), vertex_shader.get_id() );
    118         glLinkProgram( m_name.get_value() );
     110        glBindAttribLocation( glid, static_cast<GLuint>( slot::POSITION   ), "nv_position"  );
     111        glBindAttribLocation( glid, static_cast<GLuint>( slot::TEXCOORD   ), "nv_texcoord"  );
     112        glBindAttribLocation( glid, static_cast<GLuint>( slot::NORMAL     ), "nv_normal"    );
     113        glBindAttribLocation( glid, static_cast<GLuint>( slot::COLOR      ), "nv_color"     );
     114        glBindAttribLocation( glid, static_cast<GLuint>( slot::TANGENT    ), "nv_tangent"   );
     115        glBindAttribLocation( glid, static_cast<GLuint>( slot::BONEINDEX  ), "nv_boneindex" );
     116        glBindAttribLocation( glid, static_cast<GLuint>( slot::BONEWEIGHT ), "nv_boneweight");
     117
     118        glAttachShader( glid, fragment_shader.get_id() );
     119        glAttachShader( glid, vertex_shader.get_id() );
     120        glLinkProgram( glid );
    119121
    120122        if (!validate())
     
    129131bool gl_program::is_valid() const
    130132{
    131         return m_name.is_valid();
     133        return glid != 0;
    132134}
    133135
     
    135137{
    136138        int params;
    137         glGetProgramiv( m_name.get_value(), GL_ACTIVE_ATTRIBUTES, &params );
     139        glGetProgramiv( glid, GL_ACTIVE_ATTRIBUTES, &params );
    138140
    139141        for ( unsigned i = 0; i < (unsigned)params; ++i )
     
    144146                char name_buffer[128];
    145147
    146                 glGetActiveAttrib( m_name.get_value(), i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer );
     148                glGetActiveAttrib( glid, i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer );
    147149
    148150                string name( name_buffer, size_t(attr_nlen) );
     
    151153                if ( name.substr(0,3) == "gl_" ) continue;
    152154
    153                 int attr_loc = glGetAttribLocation( m_name.get_value(), name.c_str() );
     155                int attr_loc = glGetAttribLocation( glid, name.c_str() );
    154156
    155157                m_attribute_map[ name ] = new attribute( name, attr_loc, gl_enum_to_datatype( attr_type ), attr_len );
     
    160162{
    161163        int params;
    162         glGetProgramiv( m_name.get_value(), GL_ACTIVE_UNIFORMS, &params );
     164        glGetProgramiv( glid, GL_ACTIVE_UNIFORMS, &params );
    163165
    164166        for ( unsigned i = 0; i < size_t(params); ++i )
     
    169171                char name_buffer[128];
    170172
    171                 glGetActiveUniform( m_name.get_value(), i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer );
     173                glGetActiveUniform( glid, i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer );
    172174
    173175                string name( name_buffer, size_t(uni_nlen) );
     
    176178                if ( name.substr(0,3) == "gl_" ) continue;
    177179
    178                 int uni_loc = glGetUniformLocation( m_name.get_value(), name.c_str() );
     180                int uni_loc = glGetUniformLocation( glid, name.c_str() );
    179181                datatype utype = gl_enum_to_datatype( uni_type );
    180182               
     
    232234        int status;
    233235
    234         glGetProgramiv( m_name.get_value(), GL_LINK_STATUS, &status );
    235         glGetProgramInfoLog( m_name.get_value(), buffer_size, &length, buffer );
    236 
    237         NV_LOG( LOG_INFO, "Program #" << m_name.get_value() << (status == GL_FALSE ? " failed to compile!" : " compiled successfully.") );
     236        glGetProgramiv( glid, GL_LINK_STATUS, &status );
     237        glGetProgramInfoLog( glid, buffer_size, &length, buffer );
     238
     239        NV_LOG( LOG_INFO, "Program #" << glid << (status == GL_FALSE ? " failed to compile!" : " compiled successfully.") );
    238240
    239241        if ( length > 0 )
    240242        {
    241                 NV_LOG( LOG_INFO, "Program #" << m_name.get_value() << " log: " << buffer );
     243                NV_LOG( LOG_INFO, "Program #" << glid << " log: " << buffer );
    242244        }
    243245
     
    247249        }
    248250
    249         glValidateProgram( m_name.get_value() );
    250         glGetProgramiv( m_name.get_value(), GL_VALIDATE_STATUS, &status );
     251        glValidateProgram( glid );
     252        glGetProgramiv( glid, GL_VALIDATE_STATUS, &status );
    251253
    252254        if ( status == GL_FALSE )
    253255        {
    254                 glGetProgramInfoLog( m_name.get_value(), buffer_size, &length, buffer );
    255                 NV_LOG( LOG_ERROR, "Program #" << m_name.get_value() << " validation error : " << buffer );
     256                glGetProgramInfoLog( glid, buffer_size, &length, buffer );
     257                NV_LOG( LOG_ERROR, "Program #" << glid << " validation error : " << buffer );
    256258                return false;
    257259        }
  • trunk/src/gl/gl_texture2d.cc

    r299 r300  
    1111
    1212nv::gl_texture2d::gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
    13         : texture2d( size, aformat, adatatype, asampler ), m_name()
     13        : texture2d( size, aformat, adatatype, asampler )
    1414{
    15         glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
     15        glGenTextures( 1, &glid );
     16
     17        glBindTexture( GL_TEXTURE_2D, glid );
    1618
    1719        // Detect if mipmapping was requested
     
    2729        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( m_sampler.wrap_t) );
    2830
    29         glBindTexture( GL_TEXTURE_2D, 0 );
    30 
    3131        if (data)
    3232        {
    33                 glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
    3433                glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(m_format.format), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format.format), nv::datatype_to_gl_enum(m_format.type), data );
    35                 glBindTexture( GL_TEXTURE_2D, 0 );
     34        }
     35
     36        glBindTexture( GL_TEXTURE_2D, 0 );
     37}
     38
     39nv::gl_texture2d::~gl_texture2d()
     40{
     41        if ( glid != 0 )
     42        {
     43                glDeleteTextures( 1, &glid );
    3644        }
    3745}
  • trunk/src/gl/gl_vertex_buffer.cc

    r299 r300  
    1111
    1212gl_vertex_buffer::gl_vertex_buffer( buffer_hint hint, size_t size, const void* data )
    13         : vertex_buffer( hint, size ), m_name()
     13        : vertex_buffer( hint, size )
    1414{
    15         glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() );
     15        glGenBuffers( 1, &glid );
     16        glBindBuffer( GL_ARRAY_BUFFER, glid );
    1617        glBufferData( GL_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
    1718        glBindBuffer( GL_ARRAY_BUFFER, 0 );
    1819}
    1920
     21nv::gl_vertex_buffer::~gl_vertex_buffer()
     22{
     23        if ( glid != 0 )
     24        {
     25                glDeleteBuffers( 1, &glid );
     26        }
     27}
     28
    2029gl_index_buffer::gl_index_buffer( buffer_hint hint, size_t size, const void* data )
    21         : index_buffer( hint, size ), m_name()
     30        : index_buffer( hint, size )
    2231{
    23         glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );
     32        glGenBuffers( 1, &glid );
     33
     34        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, glid );
    2435        glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
    2536        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
    2637}
    2738
     39nv::gl_index_buffer::~gl_index_buffer()
     40{
     41        if ( glid != 0 )
     42        {
     43                glDeleteBuffers( 1, &glid );
     44        }
     45}
Note: See TracChangeset for help on using the changeset viewer.