Changeset 461


Ignore:
Timestamp:
08/19/15 19:01:16 (10 years ago)
Author:
epyon
Message:
  • quaternion fixes
  • image_data/device/gl_device/gl_enum - single channel texture support (RED)
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/interface/device.hh

    r439 r461  
    5656                TEX_SPECULAR = 1,
    5757                TEX_NORMAL   = 2,
     58                TEX_GLOSS    = 3,
    5859                TEXTURE_0    = 0,
    5960                TEXTURE_1    = 1,
     
    295296                        factory_link_map[ "nv_t_specular"] = new engine_link_uniform_int<1>();
    296297                        factory_link_map[ "nv_t_normal"  ] = new engine_link_uniform_int<2>();
     298                        factory_link_map[ "nv_t_gloss"   ] = new engine_link_uniform_int<3>();
    297299                }
    298300                void destroy_engine_uniforms()
  • trunk/nv/interface/image_data.hh

    r440 r461  
    3030                BGR,
    3131                BGRA,
     32                RED,
    3233        };
    3334       
     
    5051                const ivec2 get_size() const { return m_size; }
    5152                // TODO : better depth check (template?)
    52                 size_t get_depth()    const { return m_format.format == RGB || m_format.format == BGR ? 3 : 4; }
     53                size_t get_depth() const { return m_format.format == RGB || m_format.format == BGR ? 3 : ( m_format.format == RED ? 1 : 4 ); }
    5354                image_format get_format() const { return m_format; }
    5455                ~image_data() { if (m_data) delete[] m_data; }
  • trunk/nv/stl/math/quaternion.hh

    r459 r461  
    4848
    4949                        constexpr tquat()
    50                                 : x( 0 ), y( 0 ), z( 0 ), w( 0 ) {};
     50                                : x( 0 ), y( 0 ), z( 0 ), w( 1 ) {};
    5151                        constexpr tquat( const tquat<T>& q )
    5252                                : x( q.x ), y( q.y ), z( q.z ), w( q.w ) {}
     
    8383                        inline tquat<T>& operator*=( const tquat<T>& q )
    8484                        {
    85                                 this->w = w * q.w - x * q.x - y * q.y - z * q.z;
    86                                 this->x = w * q.x + x * q.w + y * q.z - z * q.y;
    87                                 this->y = w * q.y + y * q.w + z * q.x - x * q.z;
    88                                 this->z = w * q.z + z * q.w + x * q.y - y * q.x;
     85                                tquat<T> p( *this );
     86                               
     87                                this->w = p.w * q.w - p.x * q.x - p.y * q.y - p.z * q.z;
     88                                this->x = p.w * q.x + p.x * q.w + p.y * q.z - p.z * q.y;
     89                                this->y = p.w * q.y + p.y * q.w + p.z * q.x - p.x * q.z;
     90                                this->z = p.w * q.z + p.z * q.w + p.x * q.y - p.y * q.x;
    8991                                return *this;
    9092                        }
     
    159161                inline tquat<T> normalize( const tquat<T>& q )
    160162                {
    161                         T len = length( q );
     163                        T len = math::length( q );
    162164                        if ( len <= T( 0 ) ) return tquat<T>( 1, 0, 0, 0 );
    163165                        T rlen = T( 1 ) / len;
     
    392394                        tquat<T> result( ctor::uninitialize );
    393395                        T sina = sin( angle * static_cast<T>( 0.5 ) );
    394                         result.w = ( angle * static_cast<T>( 0.5 ) );
     396                        result.w = cos( angle * static_cast<T>( 0.5 ) );
    395397                        result.x = v.x * sina;
    396398                        result.y = v.y * sina;
  • trunk/src/gl/gl_device.cc

    r439 r461  
    5151        }
    5252        // TODO: BGR vs RGB, single channel
    53         assert( image->format->BytesPerPixel > 2 );
    54         image_format format(image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE );
     53        pixel_format pformat = RGBA;
     54        switch ( image->format->BytesPerPixel )
     55        {
     56        case 4: pformat = RGBA; break;
     57        case 3: pformat = RGB; break;
     58        case 1: pformat = RED; break;
     59        default: NV_ASSERT( false, "BytesPerPixel != 4,3 or 1!" );
     60        }
     61        image_format format( pformat, UBYTE );
    5562        image_data* data = new image_data( format, ivec2( image->w, image->h ), static_cast<nv::uint8*>( image->pixels ) );
    5663        return data;
  • trunk/src/gl/gl_enum.cc

    r438 r461  
    184184        case BGR     : return GL_BGR;
    185185        case BGRA    : return GL_BGRA;
     186        case RED     : return GL_RED;
    186187        NV_RETURN_COVERED_DEFAULT( 0 );
    187188        }
     
    200201        case BGR     : return GL_RGB8;
    201202        case BGRA    : return GL_RGBA8;
     203        case RED     : return 0x8040; // GL_LUMINANCE8; // TODO: change to GL_R8!
     204
    202205        NV_RETURN_COVERED_DEFAULT( 0 );
    203206        }
Note: See TracChangeset for help on using the changeset viewer.