Changeset 350


Ignore:
Timestamp:
02/04/15 16:37:00 (10 years ago)
Author:
epyon
Message:
  • massive untracked updates
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/handle.hh

    r347 r350  
    8484                        value_type i = get_free_entry();
    8585                        m_entries[i].counter++;
     86                        NV_ASSERT( m_entries[i].counter != 0, "Out of handles!" );
    8687                        m_entries[i].next_free = USED;
    8788                        return hop::create( i, m_entries[i].counter );
     
    9091                void free_handle( handle h )
    9192                {
    92                         m_entries[h.index()].next_free = NONE;
    93                         if ( m_last_free == -1 )
     93                        value_type index = h.index();
     94                        typedef handle_operator<HANDLE> hop;
     95                        NV_ASSERT( m_entries[index].next_free == USED, "Unused handle freed!" );
     96                        NV_ASSERT( m_entries[index].counter == hop::get_counter( h ), "Handle corruption!" );
     97                        m_entries[index].next_free = NONE;
     98                        if ( m_last_free == NONE )
    9499                        {
    95                                 m_first_free = m_last_free = h.index();
     100                                m_first_free = m_last_free = index;
    96101                                return;
    97102                        }
    98                         m_entries[(unsigned)m_last_free].next_free = h.index();
    99                         m_last_free = h.index();
     103                        m_entries[(unsigned)m_last_free].next_free = index;
     104                        m_last_free = index;
    100105                }
    101106
     
    120125                value_type get_free_entry()
    121126                {
    122                         if ( m_first_free != -1 )
     127                        if ( m_first_free != NONE )
    123128                        {
    124129                                value_type result = (value_type)m_first_free;
    125130                                m_first_free = m_entries[result].next_free;
    126131                                m_entries[result].next_free = USED;
    127                                 if ( m_first_free == -1 ) m_last_free = -1;
     132                                if ( m_first_free == NONE ) m_last_free = NONE;
    128133                                return result;
    129134                        }
  • trunk/nv/core/math.hh

    r319 r350  
    3131        typedef glm::detail::tvec3<sint16> i16vec3;
    3232        typedef glm::detail::tvec4<sint16> i16vec4;
     33
     34        typedef glm::detail::tvec2<uint8> u8vec2;
     35        typedef glm::detail::tvec3<uint8> u8vec3;
     36        typedef glm::detail::tvec4<uint8> u8vec4;
    3337
    3438        typedef glm::vec2 vec2;
     
    104108                BYTE_VECTOR_3,
    105109                BYTE_VECTOR_4,
     110                UBYTE_VECTOR_2,
     111                UBYTE_VECTOR_3,
     112                UBYTE_VECTOR_4,
    106113                QUAT,
    107114                TRANSFORM,
     
    140147                        { 1 * 3,  BYTE, 3 },  // BYTE_VECTOR_3,
    141148                        { 1 * 4,  BYTE, 4 },  // BYTE_VECTOR_4,
    142                         { 4 * 4,  FLOAT, 4 },      // QUAT,
     149                        { 1 * 2, UBYTE, 2 },  // UBYTE_VECTOR_2,
     150                        { 1 * 3, UBYTE, 3 },  // UBYTE_VECTOR_3,
     151                        { 1 * 4, UBYTE, 4 },  // UBYTE_VECTOR_4,
     152                        { 4 * 4, FLOAT, 4 },      // QUAT,
    143153                        { 7 * 4,  FLOAT, 7 },      // TRANSFORM,
    144154                };
     
    168178        template <> struct enum_to_type< BYTE_VECTOR_3 > { typedef i8vec3 type; };
    169179        template <> struct enum_to_type< BYTE_VECTOR_4 > { typedef i8vec4 type; };
     180
     181        template <> struct enum_to_type < UBYTE_VECTOR_2 > { typedef u8vec2 type; };
     182        template <> struct enum_to_type < UBYTE_VECTOR_3 > { typedef u8vec3 type; };
     183        template <> struct enum_to_type < UBYTE_VECTOR_4 > { typedef u8vec4 type; };
    170184
    171185        template <> struct enum_to_type< FLOAT_MATRIX_2 > { typedef mat2 type; };
     
    200214        template <> struct type_to_enum< i8vec4 > { static const datatype type = BYTE_VECTOR_4; };
    201215
     216        template <> struct type_to_enum < u8vec2 > { static const datatype type = UBYTE_VECTOR_2; };
     217        template <> struct type_to_enum < u8vec3 > { static const datatype type = UBYTE_VECTOR_3; };
     218        template <> struct type_to_enum < u8vec4 > { static const datatype type = UBYTE_VECTOR_4; };
     219
     220
    202221        template <> struct type_to_enum< mat2 > { static const datatype type = FLOAT_MATRIX_2; };
    203222        template <> struct type_to_enum< mat3 > { static const datatype type = FLOAT_MATRIX_3; };
  • trunk/nv/gl/gl_device.hh

    r347 r350  
    4141                gl_device();
    4242                virtual image_data* create_image_data( const std::string& filename ); // temporary
     43                virtual image_data* create_image_data( const uint8* data, uint32 size ); // temporary
    4344
    4445                virtual program create_program( const string& vs_source, const string& fs_source );
  • trunk/nv/gui/gui_style.hh

    r319 r350  
    2828                        style();
    2929                        void load_style( const std::string& filename );
    30                         bool get( element* e, const std::string& entry, std::string& s );
    31                         bool get( element* e, const std::string& entry, vec4& vec );
    32                         bool get( element* e, const std::string& entry, int& i );
    33                         bool get( element* e, const std::string& entry, double& d );
     30                        bool get( element* e, const char* centry, std::string& s );
     31                        bool get( element* e, const char* centry, vec4& vec );
     32                        bool get( element* e, const char* centry, int& i );
     33                        bool get( element* e, const char* centry, double& d );
    3434                        ~style();
    3535                protected:
    36                         bool resolve( element* e, const std::string& entry, int type );
     36                        bool resolve( const char* cid, const char* cclass, const char* centry, int type );
    3737                protected:
    3838                        lua::state m_lua; //!< separate lua state for style calculation
  • trunk/nv/interface/context.hh

    r342 r350  
    184184                {
    185185                        vertex_array va = create_vertex_array( v, vcount, hint );
    186                         buffer       ib = create_buffer( INDEX_BUFFER, hint, icount * sizeof( IDX ), i );
     186                        buffer       ib = m_device->create_buffer( INDEX_BUFFER, hint, icount * sizeof( IDX ), i );
    187187                        set_index_buffer( va, ib, type_to_enum< IDX >::type, true );
    188188                        return va;
  • trunk/nv/interface/device.hh

    r342 r350  
    162162                virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) { return create_texture( TEXTURE_2D, size, aformat, asampler, data ); }
    163163                virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary
     164                virtual image_data* create_image_data( const uint8* data, uint32 size ) = 0; // temporary
    164165                virtual void release( texture ) = 0;
    165166                virtual void release( buffer ) = 0;
  • trunk/src/gl/gl_device.cc

    r331 r350  
    4949        image_data* data = new image_data( format, glm::ivec2( image->w, image->h ), (nv::uint8*)image->pixels );
    5050        return data;
     51}
     52
     53// this is a temporary function that will be removed once we find a way to
     54// pass binary file data around
     55image_data* gl_device::create_image_data( const uint8* data, uint32 size )
     56{
     57        load_sdl_image_library();
     58        SDL_Surface* image = IMG_LoadTyped_RW( SDL_RWFromMem( (void*)data, size ), 1, "tga" );
     59        if ( !image )
     60        {
     61                NV_LOG( LOG_ERROR, "Image binary data cannot be loaded found!" );
     62                return nullptr;
     63        }
     64        // TODO: BGR vs RGB, single channel
     65        assert( image->format->BytesPerPixel > 2 );
     66        image_format format( image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE );
     67        image_data* idata = new image_data( format, glm::ivec2( image->w, image->h ), ( nv::uint8* )image->pixels );
     68        return idata;
    5169}
    5270
  • trunk/src/gl/gl_enum.cc

    r340 r350  
    296296        case BYTE_VECTOR_3  : return GL_INT_VEC3;
    297297        case BYTE_VECTOR_4  : return GL_INT_VEC4;
    298         default : return 0; // TODO: throw!
     298                // remove, error or ?
     299        case UBYTE_VECTOR_2: return GL_INT_VEC2;
     300        case UBYTE_VECTOR_3: return GL_INT_VEC3;
     301        case UBYTE_VECTOR_4: return GL_INT_VEC4;
     302        default: return 0; // TODO: throw!
    299303        }
    300304}
  • trunk/src/gui/gui_style.cc

    r319 r350  
    2121}
    2222
    23 bool style::get( element* e, const std::string& entry, std::string& s )
     23bool style::get( element* e, const char* centry, std::string& s )
    2424{
    2525        lua::stack_guard guard( m_lua );
    26         if ( !resolve( e, entry, LUA_TSTRING ) ) return false;
     26        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TSTRING ) ) return false;
    2727        s = lua_tostring( m_lua, -1 );
    2828        return true;
    2929}
    3030
    31 bool style::get( element* e, const std::string& entry, vec4& vec )
     31bool style::get( element* e, const char* centry, vec4& vec )
    3232{
    3333        lua::stack_guard guard( m_lua );
    34         if ( !resolve( e, entry, LUA_TTABLE ) ) return false;
     34        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TTABLE ) ) return false;
    3535        vec = vec4();
    3636        for (size_t i = 0; i < 4; ++i )
     
    4444}
    4545
    46 bool style::get( element* e, const std::string& entry, int& i )
     46bool style::get( element* e, const char* centry, int& i )
    4747{
    4848        lua::stack_guard guard( m_lua );
    49         if ( !resolve( e, entry, LUA_TNUMBER ) ) return false;
     49        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TNUMBER ) ) return false;
    5050        i = static_cast< int >( lua_tointeger( m_lua, -1 ) );
    5151        return true;
    5252}
    5353
    54 bool style::get( element* e, const std::string& entry, double& d )
     54bool style::get( element* e, const char* centry, double& d )
    5555{
    5656        lua::stack_guard guard( m_lua );
    57         if ( !resolve( e, entry, LUA_TNUMBER ) ) return false;
     57        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TNUMBER ) ) return false;
    5858        d = lua_tonumber( m_lua, -1 );
    5959        return true;
     
    6464}
    6565
    66 bool style::resolve( element* e, const std::string& entry, int type )
     66bool style::resolve( const char* cid, const char* cclass, const char* centry, int type )
    6767{
    68         const char* centry = entry.c_str();
    69         const char* cid    = e->m_id.c_str();
    70         const char* cclass = e->m_class.c_str();
    7168        lua_getglobal( m_lua, "default" );
    7269        int global = lua_gettop( m_lua );
Note: See TracChangeset for help on using the changeset viewer.