Changeset 90
- Timestamp:
- 06/02/13 22:33:59 (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/common.hh
r88 r90 7 7 #ifndef NV_COMMON_HH 8 8 #define NV_COMMON_HH 9 10 #include <typeinfo>11 #include <cstddef>12 #include <cassert>13 #include <nv/logging.hh>14 9 15 10 // NV Library version … … 114 109 #endif 115 110 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 116 123 #define NV_STRINGIZE_DETAIL(x) #x 117 124 #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 118 133 119 134 #define NV_ASSERT(cond, msg) assert( (cond) && msg ) … … 122 137 throw eobj( __VA_ARGS__ ); \ 123 138 } 124 125 #if NV_COMPILER == NV_MSVC126 #pragma warning(disable: 4201)127 #endif128 139 129 140 namespace nv -
trunk/nv/gfx/image.hh
r89 r90 9 9 10 10 #include <nv/common.hh> 11 #include <nv/interface/image_data.hh> 11 12 #include <glm/glm.hpp> 12 13 … … 30 31 * By an image we understand a group of pixels, limited to X and Y 31 32 * dimensions, of a certain depth (by depth we mean how rich 32 * the colo urs are.33 * the colors are. 33 34 */ 34 35 class image … … 42 43 */ 43 44 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 ); 44 51 /** 45 52 * Full constructor. -
trunk/nv/gl/gl_device.hh
r70 r90 26 26 virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ); 27 27 virtual vertex_array* create_vertex_array(); 28 virtual image_data* create_image_data( const std::string& filename ); // temporary 28 29 virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ); 29 30 virtual ~gl_device(); -
trunk/nv/interface/device.hh
r73 r90 18 18 #include <nv/interface/vertex_buffer.hh> 19 19 #include <nv/interface/texture2d.hh> 20 #include <nv/interface/image_data.hh> 20 21 21 22 namespace nv … … 32 33 virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0; 33 34 virtual vertex_array* create_vertex_array() = 0; 35 virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary 34 36 virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0; 35 37 -
trunk/src/gfx/image.cc
r89 r90 5 5 #include "nv/gfx/image.hh" 6 6 7 #include < cstring>7 #include <algorithm> 8 8 9 9 using namespace nv; … … 15 15 } 16 16 17 image::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 17 24 image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed ) 18 25 : m_size( size ), m_depth( depth ), m_data( nullptr ) 19 26 { 27 std::size_t bsize = m_size.x * m_size.y * m_depth; 20 28 m_data = new uint8[ m_size.x * m_size.y * m_depth ]; 21 29 22 30 if ( reversed ) 23 31 { 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 ) 25 34 { 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 ); 27 36 } 28 37 … … 30 39 else 31 40 { 32 memcpy( m_data, data, m_size.x * m_size.y * m_depth);41 std::copy( data, data + bsize, m_data ); 33 42 } 34 43 } … … 36 45 void image::fill( uint8 value ) 37 46 { 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 ); 39 48 } 40 49 41 50 void image::set_region( region r, const uint8 * data, size_t stride ) 42 51 { 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; 44 56 45 57 for( int i = 0; i < r.size.y; ++i ) 46 58 { 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 ); 49 63 } 50 64 } -
trunk/src/gl/gl_device.cc
r70 r90 11 11 #include "nv/logging.hh" 12 12 #include "nv/lib/sdl12.hh" 13 #include "nv/lib/sdl_image.hh" 13 14 14 15 using namespace nv; … … 67 68 } 68 69 70 // this is a temporary function that will be removed once we find a way to 71 // pass binary file data around 72 image_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 69 80 texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ ) 70 81 { -
trunk/tests/render_test/rl.cc
r89 r90 1 1 #include <nv/lib/sdl12.hh> 2 #include <nv/lib/sdl_image.hh>3 2 #include <nv/interface/vertex_buffer.hh> 4 3 #include <nv/gl/gl_device.hh> … … 87 86 m_window = m_device->create_window( 800, 600 ); 88 87 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" ); 92 89 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; 94 92 95 93 m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
Note: See TracChangeset
for help on using the changeset viewer.