Changeset 473 for trunk


Ignore:
Timestamp:
10/09/15 14:06:56 (10 years ago)
Author:
epyon
Message:
  • rtti updates
  • device/context initial uniform buffer support
  • fixes
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/base/rtti_support.hh

    r436 r473  
    1717
    1818#define NV_RTTI_DECLARE(T) \
    19 namespace nv { \
    20 template<> struct rtti_type_hash< T > { \
     19template<> struct ::nv::rtti_type_hash< T > { \
     20NV_MSVC_SUPRESS( 4307 )\
     21        static const nv::uint64 value = nv::rtti_const_hash(#T); \
    2122        static const char* name() { return #T; } \
    2223        static nv::uint64 hash() { \
    23 NV_MSVC_SUPRESS( 4307 )\
    24                 static const nv::uint64 value = nv::rtti_const_hash(#T); \
    2524                return value; \
    2625        } \
    27 };} \
     26}; \
    2827
    2928#define NV_RTTI_DECLARE_NAME(T,NAME) \
    30 namespace nv { \
    31 template<> struct rtti_type_hash< T > { \
     29template<> struct ::nv::rtti_type_hash< T > { \
     30NV_MSVC_SUPRESS( 4307 )\
     31        static const nv::uint64 value = nv::rtti_const_hash(#T); \
    3232        static const char* name() { return NAME; } \
    3333        static nv::uint64 hash() { \
    34 NV_MSVC_SUPRESS( 4307 )\
    35                 static const nv::uint64 value = nv::rtti_const_hash(#T); \
    3634                return value; \
    3735                                } \
    38 };} \
     36}; \
    3937
    4038namespace nv
  • trunk/nv/core/arcball.hh

    r454 r473  
    5050                        vec3 vb = get_arcball_vector( nposition );
    5151
    52                         m_angle = math::acos( math::min( 1.0f, math::dot( va, vb ) ) );
     52                        m_angle = nv::acos( math::min( 1.0f, math::dot( va, vb ) ) );
    5353                        m_axis  = math::cross( va, vb );
    5454                        m_last  = nposition;
  • trunk/nv/gl/gl_context.hh

    r463 r473  
    4848                virtual void bind( framebuffer f, framebuffer_slot ft = FRAMEBUFFER );
    4949                virtual void bind( texture t, texture_slot slot );
     50                virtual void bind( buffer b, uint32 index, size_t offset = 0, size_t size = 0 );
    5051
    5152                virtual void update( texture t, const void* data );
    5253                virtual void update( buffer b, const void* data, size_t offset, size_t size );
     54                virtual void update( buffer b, uint32 index, const void* data, size_t offset, size_t size );
    5355
    5456                virtual void clear( const clear_state& cs );
    5557                // temporary
    56                 virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count );
     58                virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count, size_t first = 0 );
    5759                virtual const ivec4& get_viewport();
    5860                virtual void set_viewport( const ivec4& viewport );
  • trunk/nv/gl/gl_device.hh

    r463 r473  
    5656
    5757                virtual int get_attribute_location( program p, const string_view& name, bool fatal = true ) const;
     58                virtual int get_block_location( program p, const string_view& name, bool fatal = true ) const;
    5859                virtual void prepare_program( program p );
    5960                virtual string_view get_shader_header() const { return m_shader_header; }
  • trunk/nv/interface/context.hh

    r469 r473  
    102102                virtual void bind( framebuffer f, framebuffer_slot slot = FRAMEBUFFER ) = 0;
    103103                virtual void bind( texture, texture_slot ) = 0;
     104                virtual void bind( buffer, uint32 /*index*/, size_t /*offset*/ = 0, size_t /*size */= 0 ) = 0;
     105
    104106                virtual void update( texture, const void* ) = 0;
    105107                virtual void update( buffer, const void*, size_t /*offset*/, size_t /*size*/ ) = 0;
     108                virtual void update( buffer, uint32 /*index*/, const void* , size_t /*offset*/, size_t /*size*/ ) = 0;
    106109
    107110                virtual void clear( const clear_state& cs ) = 0;
    108111                // temporary
    109                 virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count ) = 0;
    110 
    111                 void draw( primitive prim, const render_state& rs, const scene_state& s, program p, vertex_array va, size_t count )
     112                virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count, size_t first = 0 ) = 0;
     113
     114                void draw( primitive prim, const render_state& rs, const scene_state& s, program p, vertex_array va, size_t count, size_t first = 0 )
    112115                {
    113116                        apply_engine_uniforms(p,s);
    114                         draw( prim, rs, p, va, count );
     117                        draw( prim, rs, p, va, count, first );
    115118                }
    116119                virtual void apply_engine_uniforms( program p, const scene_state& s ) = 0;
  • trunk/nv/interface/device.hh

    r472 r473  
    8282        struct buffer_tag {};
    8383        struct program_tag {};
     84
    8485        typedef handle< uint32, 16, 16, buffer_tag >       buffer;
    8586        typedef handle< uint32, 16, 16, texture_tag >      texture;
    8687        typedef handle< uint32, 16, 16, program_tag >      program;
     88
     89        NV_RTTI_DECLARE_NAME( buffer,  "buffer" )
     90        NV_RTTI_DECLARE_NAME( texture, "texture" )
     91        NV_RTTI_DECLARE_NAME( program, "program" )
    8792
    8893        struct sampler
     
    129134                VERTEX_BUFFER,
    130135                INDEX_BUFFER,
     136                UNIFORM_BUFFER,
    131137        };
    132138
     
    198204                }
    199205
     206                int try_get_block_location( program p, const string_view& name ) const
     207                {
     208                        return get_block_location( p, name, false );
     209                }
     210
    200211                virtual int get_attribute_location( program p, const string_view& name, bool fatal = true ) const = 0;
     212                virtual int get_block_location( program p, const string_view& name, bool fatal = true ) const = 0;
     213
    201214
    202215                template < typename T >
  • trunk/nv/stl/string/short_string.hh

    r472 r473  
    145145                {
    146146                        Storage::reserve( new_size + 1 );
    147                         Storage::resize( min( new_size, capacity() - 1 ) );
     147                        Storage::resize( min( new_size, this->capacity() - 1 ) );
    148148                        this->data()[this->size()] = 0;
    149149                }
     
    172172                        else
    173173                        {
    174                                 result = capacity() - this->size() - 1;
    175                                 Storage::try_resize( capacity() - 1, true, 1 );
     174                                result = this->capacity() - this->size() - 1;
     175                                Storage::try_resize( this->capacity() - 1, true, 1 );
    176176                        }
    177177                        this->data()[this->size()] = 0;
  • trunk/src/gl/gl_context.cc

    r469 r473  
    205205        {
    206206                glBindFramebuffer( framebuffer_slot_to_enum(ft), 0 );
     207        }
     208}
     209
     210void nv::gl_context::bind( buffer b, uint32 index, size_t offset /*= 0*/, size_t size /*= 0 */ )
     211{
     212        const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
     213        if ( info )
     214        {
     215                if ( size == 0 )
     216                        glBindBufferBase( buffer_type_to_enum( info->type ), index, info->glid );
     217                else
     218                        glBindBufferRange( buffer_type_to_enum( info->type ), index, info->glid, offset, size );
    207219        }
    208220}
     
    339351                else
    340352                        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 );
     353        }
     354}
     355
     356void nv::gl_context::update( buffer b, uint32 index, const void* data, size_t offset, size_t size )
     357{
     358        const gl_buffer_info* info = static_cast<const gl_buffer_info*>( m_device->get_buffer_info( b ) );
     359        if ( info )
     360        {
     361                GLenum glenum = buffer_type_to_enum( info->type );
     362                if ( size == 0 )
     363                        glBindBufferBase( glenum, index, info->glid );
     364                else
     365                        glBindBufferRange( glenum, index, info->glid, offset, size );
     366                glBufferSubData( glenum, GLintptr( offset ), GLsizeiptr( size ), data );
    341367        }
    342368}
     
    750776}
    751777
    752 void gl_context::draw( primitive prim, const render_state& rs, program p, vertex_array va, nv::size_t count )
     778void gl_context::draw( primitive prim, const render_state& rs, program p, vertex_array va, nv::size_t count, nv::size_t first )
    753779{
    754780        apply_render_state( rs );
     
    760786                if ( info->index.is_valid() )
    761787                {
    762                         glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( info->index_type ), 0 );
     788                        glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( info->index_type ), reinterpret_cast< const void* >( get_datatype_info( info->index_type ).size * first ) );
    763789                }
    764790                else
    765791                {
    766                         glDrawArrays( primitive_to_enum(prim), 0, static_cast<GLsizei>( count ) );
     792                        glDrawArrays( primitive_to_enum(prim), first, static_cast<GLsizei>( count ) );
    767793                }
    768794                unbind( va );
  • trunk/src/gl/gl_device.cc

    r471 r473  
    337337                }
    338338        }
     339        return -1;
     340}
     341
     342int nv::gl_device::get_block_location( program p, const string_view& name, bool fatal /*= true */ ) const
     343{
    339344        return -1;
    340345}
     
    450455{
    451456        int params;
     457        int bparams;
    452458        glGetProgramiv( p->glid, GL_ACTIVE_UNIFORMS, &params );
     459        glGetProgramiv( p->glid, GL_ACTIVE_UNIFORM_BLOCKS, &bparams );
    453460
    454461        for ( unsigned i = 0; i < unsigned( params ); ++i )
     
    479486                NV_ASSERT( u, "Unknown uniform type!" );
    480487                (*p->m_uniform_map)[ name ] = u;
     488        }
     489
     490        for ( unsigned i = 0; i < unsigned( bparams ); ++i )
     491        {
     492                int uni_len;
     493                char name_buffer[128];
     494
     495                glGetActiveUniformBlockName( p->glid, i, 128, &uni_len, name_buffer );
     496                NV_LOG_INFO( string_view( name_buffer, size_t( uni_len ) ) );
    481497        }
    482498}
  • trunk/src/gl/gl_enum.cc

    r472 r473  
    168168        switch( type )
    169169        {
    170         case VERTEX_BUFFER : return GL_ARRAY_BUFFER;
    171         case INDEX_BUFFER  : return GL_ELEMENT_ARRAY_BUFFER;
     170        case VERTEX_BUFFER  : return GL_ARRAY_BUFFER;
     171        case INDEX_BUFFER   : return GL_ELEMENT_ARRAY_BUFFER;
     172        case UNIFORM_BUFFER : return GL_UNIFORM_BUFFER;
    172173                NV_RETURN_COVERED_DEFAULT( 0 );
    173174        }
Note: See TracChangeset for help on using the changeset viewer.