Changeset 90 for trunk


Ignore:
Timestamp:
06/02/13 22:33:59 (12 years ago)
Author:
epyon
Message:
  • common - windows SCL warnings proper suppression
  • common - NV_DEPRECATED added
  • interface/image_data added
  • image constructible from image_data by ownership transfer
  • device - create_image_data added (temporary)
  • gl_device - create_image_data implementation (temporary)
Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/common.hh

    r88 r90  
    77#ifndef NV_COMMON_HH
    88#define NV_COMMON_HH
    9 
    10 #include <typeinfo>
    11 #include <cstddef>
    12 #include <cassert>
    13 #include <nv/logging.hh>
    149
    1510// NV Library version
     
    114109#endif
    115110
     111
     112#if NV_COMPILER == NV_MSVC
     113#pragma warning(disable: 4201)
     114#undef _SCL_SECURE_NO_WARNINGS // to prevent redefinig
     115#define _SCL_SECURE_NO_WARNINGS
     116#endif
     117
     118#include <typeinfo>
     119#include <cstddef>
     120#include <cassert>
     121#include <nv/logging.hh>
     122
    116123#define NV_STRINGIZE_DETAIL(x) #x
    117124#define NV_STRINGIZE(x) NV_STRINGIZE_DETAIL(x)
     125
     126#if NV_COMPILER == NV_MSVC
     127#define NV_DEPRECATED(func) __declspec(deprecated) func
     128#elif NV_COMPILER == NV_GNUC
     129#define NV_DEPRECATED(func) func __attribute__ ((deprecated))
     130#else
     131#define NV_DEPRECATED(func) func
     132#endif
    118133
    119134#define NV_ASSERT(cond, msg) assert( (cond) && msg )
     
    122137        throw eobj( __VA_ARGS__ ); \
    123138}
    124 
    125 #if NV_COMPILER == NV_MSVC
    126 #pragma warning(disable: 4201)
    127 #endif
    128139
    129140namespace nv
  • trunk/nv/gfx/image.hh

    r89 r90  
    99
    1010#include <nv/common.hh>
     11#include <nv/interface/image_data.hh>
    1112#include <glm/glm.hpp>
    1213
     
    3031         * By an image we understand a group of pixels, limited to X and Y
    3132         * dimensions, of a certain depth (by depth we mean how rich
    32          * the colours are.
     33         * the colors are.
    3334         */
    3435        class image
     
    4243                 */
    4344                image( glm::ivec2 size, size_t depth );
     45                /**
     46                 * Constructor
     47                 *
     48                 * @arg[in] data : image data to be used - will be released, but not deleted!
     49                 */
     50                explicit image( image_data* data );
    4451                /**
    4552                 * Full constructor.
  • trunk/nv/gl/gl_device.hh

    r70 r90  
    2626                virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr );
    2727                virtual vertex_array* create_vertex_array();
     28                virtual image_data* create_image_data( const std::string& filename ); // temporary
    2829                virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr );
    2930                virtual ~gl_device();
  • trunk/nv/interface/device.hh

    r73 r90  
    1818#include <nv/interface/vertex_buffer.hh>
    1919#include <nv/interface/texture2d.hh>
     20#include <nv/interface/image_data.hh>
    2021
    2122namespace nv
     
    3233                virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0;
    3334                virtual vertex_array* create_vertex_array() = 0;
     35                virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary
    3436                virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0;
    3537
  • trunk/src/gfx/image.cc

    r89 r90  
    55#include "nv/gfx/image.hh"
    66
    7 #include <cstring>
     7#include <algorithm>
    88
    99using namespace nv;
     
    1515}
    1616
     17image::image( image_data* data )
     18        : m_size( data->get_size() ), m_depth( data->get_depth() ), m_data( data->release_data() )
     19{
     20        NV_ASSERT( m_data, "image created from empty image_data!" );
     21}
     22
     23
    1724image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed )
    1825        : m_size( size ), m_depth( depth ), m_data( nullptr )
    1926{
     27        std::size_t bsize = m_size.x * m_size.y * m_depth;
    2028        m_data = new uint8[ m_size.x * m_size.y * m_depth ];
    2129
    2230        if ( reversed )
    2331        {
    24                 for( int i = 0; i < size.y; ++i )
     32                std::size_t bline = m_size.x * m_depth;
     33                for( int i = 0; i < m_size.y; ++i )
    2534                {
    26                         memcpy( m_data + size.x * ( size.y - i - 1) * m_depth, data + i * size.x * m_depth, m_size.x * m_depth );
     35                        std::copy( data + i * bline, data + (i + 1) * bline, m_data + bsize - ( i + 1 ) * bline );
    2736                }
    2837
     
    3039        else
    3140        {
    32                 memcpy( m_data, data, m_size.x * m_size.y * m_depth );
     41                std::copy( data, data + bsize, m_data );
    3342        }
    3443}
     
    3645void image::fill( uint8 value )
    3746{
    38         memset( m_data, value, m_size.x * m_size.y * m_depth );
     47        std::fill( m_data, m_data + m_size.x * m_size.y * m_depth, value );
    3948}
    4049
    4150void image::set_region( region r, const uint8 * data, size_t stride )
    4251{
    43         if ( stride == 0 ) stride = r.size.x;
     52        if ( stride == 0 ) stride = r.size.x * m_depth;
     53       
     54        std::size_t bpos  = (r.pos.y*m_size.x + r.pos.x ) * m_depth;
     55        std::size_t bline = m_size.x*m_depth;
    4456
    4557        for( int i = 0; i < r.size.y; ++i )
    4658        {
    47                 memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth,
    48                         data + (i*stride), r.size.x * m_depth );
     59// TODO: test if same as old:
     60//              memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth,
     61//                      data + (i*stride), r.size.x * m_depth );
     62                std::copy( data + i*stride, data + (i+1)*stride, m_data + bpos + bline * i );
    4963        }
    5064}
  • trunk/src/gl/gl_device.cc

    r70 r90  
    1111#include "nv/logging.hh"
    1212#include "nv/lib/sdl12.hh"
     13#include "nv/lib/sdl_image.hh"
    1314
    1415using namespace nv;
     
    6768}
    6869
     70// this is a temporary function that will be removed once we find a way to
     71// pass binary file data around
     72image_data* nv::gl_device::create_image_data( const std::string& filename )
     73{
     74        load_sdl_image_library();
     75        SDL_Surface* image = IMG_Load( filename.c_str() );
     76        image_data* data = new image_data( glm::ivec2( image->w, image->h ), image->format->BytesPerPixel, (nv::uint8*)image->pixels );
     77        return data;
     78}
     79
    6980texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
    7081{
  • trunk/tests/render_test/rl.cc

    r89 r90  
    11#include <nv/lib/sdl12.hh>
    2 #include <nv/lib/sdl_image.hh>
    32#include <nv/interface/vertex_buffer.hh>
    43#include <nv/gl/gl_device.hh>
     
    8786        m_window = m_device->create_window( 800, 600 );
    8887       
    89         nv::load_sdl_image_library();
    90         SDL_Surface* texture = IMG_Load( "spritesheet.png" );
    91         nv::image sprites( glm::ivec2( texture->w, texture->h ), 4, (nv::uint8*)texture->pixels );
     88        nv::image_data* sprites = m_device->create_image_data( "spritesheet.png" );
    9289        nv::sampler sampler( nv::sampler::NEAREST, nv::sampler::REPEAT );
    93         m_texture = m_device->create_texture2d( sprites.get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)sprites.get_data() );
     90        m_texture = m_device->create_texture2d( sprites->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)sprites->get_data() );
     91        delete sprites;
    9492
    9593        m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
Note: See TracChangeset for help on using the changeset viewer.