Changeset 301
- Timestamp:
- 08/07/14 12:11:16 (11 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gl/gl_context.hh
r299 r301 23 23 public: 24 24 ~gl_context(); 25 virtual void bind( texture 2d* texture, texture_slot slot );25 virtual void bind( texture t, texture_slot slot ); 26 26 virtual void bind( program* p ); 27 27 virtual void bind( vertex_buffer* b ); … … 33 33 virtual void unbind( vertex_array* va ); 34 34 35 virtual void update( texture 2d* texture, void* data );35 virtual void update( texture t, void* data ); 36 36 virtual void update( index_buffer* b, const void* data, size_t offset, size_t size ); 37 37 virtual void update( vertex_buffer* b, const void* data, size_t offset, size_t size ); -
trunk/nv/gl/gl_device.hh
r292 r301 17 17 namespace nv 18 18 { 19 struct gl_texture_info : public texture_info 20 { 21 unsigned glid; 22 }; 23 19 24 class gl_device : public device 20 25 { … … 28 33 virtual vertex_array* create_vertex_array(); 29 34 virtual image_data* create_image_data( const std::string& filename ); // temporary 30 virtual texture2d* create_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr );31 35 virtual uint32 get_ticks(); 32 36 virtual void delay( uint32 ms ); 37 38 virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ); 39 virtual void release_texture( texture t ); 40 virtual const texture_info* get_texture_info( texture t ); 41 33 42 virtual ~gl_device(); 34 43 private: 35 44 const void* m_info; 45 entity_store< gl_texture_info, texture > m_textures; 36 46 }; 37 47 -
trunk/nv/gl/gl_enum.hh
r292 r301 17 17 #include <nv/interface/render_state.hh> 18 18 #include <nv/interface/vertex_buffer.hh> 19 #include <nv/interface/ texture2d.hh>19 #include <nv/interface/image_data.hh> 20 20 #include <nv/interface/context.hh> 21 21 -
trunk/nv/interface/context.hh
r299 r301 14 14 15 15 #include <nv/common.hh> 16 #include <nv/interface/device.hh> 16 17 #include <nv/interface/camera.hh> 17 18 #include <nv/interface/program.hh> … … 59 60 m_device = a_device; 60 61 } 61 virtual void bind( texture 2d*, texture_slot ) = 0;62 virtual void bind( texture, texture_slot ) = 0; 62 63 virtual void bind( vertex_buffer* ) = 0; 63 64 virtual void bind( index_buffer* ) = 0; … … 68 69 virtual void unbind( program* ) = 0; 69 70 virtual void unbind( vertex_array* ) = 0; 70 virtual void update( texture 2d*, void* ) = 0;71 virtual void update( texture, void* ) = 0; 71 72 virtual void update( index_buffer*, const void*, size_t /*offset*/, size_t /*size*/ ) = 0; 72 73 virtual void update( vertex_buffer*, const void*, size_t /*offset*/, size_t /*size*/ ) = 0; -
trunk/nv/interface/device.hh
r292 r301 15 15 #include <nv/common.hh> 16 16 #include <nv/string.hh> 17 #include <nv/handle.hh> 17 18 #include <nv/interface/mesh_data.hh> 18 19 #include <nv/interface/vertex_buffer.hh> 19 #include <nv/interface/texture2d.hh>20 20 #include <nv/interface/image_data.hh> 21 21 … … 24 24 class window; 25 25 class program; 26 27 struct sampler 28 { 29 enum filter 30 { 31 LINEAR, 32 NEAREST, 33 NEAREST_MIPMAP_NEAREST, 34 LINEAR_MIPMAP_NEAREST, 35 NEAREST_MIPMAP_LINEAR, 36 LINEAR_MIPMAP_LINEAR 37 }; 38 enum wrap 39 { 40 CLAMP_TO_EDGE, 41 CLAMP_TO_BORDER, 42 MIRRORED_REPEAT, 43 REPEAT 44 }; 45 46 filter filter_min; 47 filter filter_max; 48 wrap wrap_s; 49 wrap wrap_t; 50 51 sampler() : filter_min( LINEAR ), filter_max( LINEAR ), wrap_s( REPEAT ), wrap_t( REPEAT ) {} 52 sampler( filter min, filter max, wrap s, wrap t ) 53 : filter_min( min ), filter_max( max ), wrap_s( s ), wrap_t( t ) {} 54 sampler( filter f, wrap w ) 55 : filter_min( f ), filter_max( f ), wrap_s( w ), wrap_t( w ) {} 56 57 }; 58 59 struct texture_info 60 { 61 ivec2 size; 62 image_format format; 63 sampler sampler; 64 }; 65 66 67 struct texture_tag {}; 68 typedef handle< uint32, 16, 16, texture_tag > texture; 26 69 27 70 class device … … 35 78 virtual vertex_array* create_vertex_array() = 0; 36 79 virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary 37 virtual texture2d* create_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0; 80 virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) = 0; 81 virtual void release_texture( texture ) = 0; 82 virtual const texture_info* get_texture_info( texture ) = 0; 38 83 virtual uint32 get_ticks() = 0; 39 84 virtual void delay( uint32 ms ) = 0; 40 85 41 texture2d* create_texture2d( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr )86 virtual texture create_texture( image_data* data, sampler asampler ) 42 87 { 43 return create_texture2d( size, aformat.format, aformat.type, asampler, data ); 44 } 45 virtual texture2d* create_texture2d( image_data* data, sampler asampler ) 46 { 47 return create_texture2d( data->get_size(), data->get_format(), asampler, (void*)data->get_data() ); 88 return create_texture( data->get_size(), data->get_format(), asampler, (void*)data->get_data() ); 48 89 } 49 90 -
trunk/src/gl/gl_context.cc
r300 r301 8 8 #include "nv/lib/gl.hh" 9 9 #include "nv/lib/sdl.hh" 10 #include "nv/gl/gl_ texture2d.hh"10 #include "nv/gl/gl_device.hh" 11 11 #include "nv/gl/gl_program.hh" 12 12 #include "nv/gl/gl_vertex_buffer.hh" … … 14 14 using namespace nv; 15 15 16 void gl_context::bind( texture2d* texture, texture_slot slot ) 17 { 18 GLuint id = static_cast< gl_texture2d* >( texture )->glid; 19 glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) ); 20 glBindTexture( GL_TEXTURE_2D, id ); 16 void gl_context::bind( texture t, texture_slot slot ) 17 { 18 const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) ); 19 if ( info ) 20 { 21 glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) ); 22 glBindTexture( GL_TEXTURE_2D, info->glid ); 23 } 21 24 } 22 25 … … 94 97 } 95 98 96 void gl_context::update( texture2d* texture, void* data ) 97 { 98 GLuint id = static_cast< gl_texture2d* >( texture )->glid; 99 image_format format = texture->get_format(); 100 ivec2 size = texture->get_size(); 101 102 glBindTexture( GL_TEXTURE_2D, id ); 103 glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(format.format), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data ); 99 void nv::gl_context::update( texture t, void* data ) 100 { 101 const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) ); 102 if ( info ) 103 { 104 image_format format = info->format; 105 ivec2 size = info->size; 106 107 glBindTexture( GL_TEXTURE_2D, info->glid ); 108 glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(format.format), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data ); 109 } 104 110 } 105 111 -
trunk/src/gl/gl_device.cc
r299 r301 8 8 #include "nv/gl/gl_program.hh" 9 9 #include "nv/gl/gl_vertex_buffer.hh" 10 #include "nv/gl/gl_texture2d.hh"11 10 #include "nv/logging.hh" 12 11 #include "nv/lib/sdl.hh" 13 12 #include "nv/lib/sdl_image.hh" 13 #include "nv/gl/gl_enum.hh" 14 #include "nv/lib/gl.hh" 14 15 15 16 using namespace nv; … … 88 89 } 89 90 90 texture2d* gl_device::create_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )91 {92 return new gl_texture2d( size, aformat, adatatype, asampler, data );93 }94 95 91 uint32 gl_device::get_ticks() 96 92 { … … 105 101 gl_device::~gl_device() 106 102 { 103 // TODO: better use release_texture 104 for ( auto& t : m_textures ) glDeleteTextures( 1, &t.glid ); 105 107 106 SDL_Quit(); 108 107 } 108 109 nv::texture nv::gl_device::create_texture( ivec2 size, image_format aformat, sampler asampler, void* data /*= nullptr */ ) 110 { 111 unsigned glid = 0; 112 glGenTextures( 1, &glid ); 113 114 glBindTexture( GL_TEXTURE_2D, glid ); 115 116 // Detect if mipmapping was requested 117 if (( asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) || 118 ( asampler.filter_max != sampler::LINEAR && asampler.filter_max != sampler::NEAREST )) 119 { 120 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 121 } 122 123 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_min ) ); 124 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_max ) ); 125 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (int)nv::sampler_wrap_to_enum( asampler.wrap_s) ); 126 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( asampler.wrap_t) ); 127 128 if (data) 129 { 130 glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(aformat.format), size.x, size.y, 0, nv::image_format_to_enum(aformat.format), nv::datatype_to_gl_enum(aformat.type), data ); 131 } 132 133 glBindTexture( GL_TEXTURE_2D, 0 ); 134 135 texture result = m_textures.create(); 136 gl_texture_info* info = m_textures.get( result ); 137 info->format = aformat; 138 info->sampler = asampler; 139 info->size = size; 140 info->glid = glid; 141 return result; 142 } 143 144 void nv::gl_device::release_texture( texture t ) 145 { 146 gl_texture_info* info = m_textures.get( t ); 147 if ( info ) 148 { 149 glDeleteTextures( 1, &(info->glid) ); 150 m_textures.destroy( t ); 151 } 152 } 153 154 const texture_info* nv::gl_device::get_texture_info( texture t ) 155 { 156 return m_textures.get( t ); 157 } 158 -
trunk/src/gui/gui_renderer.cc
r299 r301 65 65 { 66 66 public: 67 screen_render_data( context* ctx, size_t initial_size )68 : buffer( ctx, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr), texture(nullptr)67 screen_render_data( context* actx, size_t initial_size ) 68 : buffer( actx, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr) 69 69 { 70 70 … … 74 74 delete shader; 75 75 delete varray; 76 delete texture;77 76 } 78 77 79 78 nv::sliced_buffer<gui_quad> buffer; 79 nv::texture tex; 80 80 nv::vertex_array* varray; 81 81 nv::program* shader; 82 nv::texture2d* texture;83 82 }; 84 83 … … 121 120 122 121 nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE ); 123 sr->tex ture = m_window->get_device()->create_texture2d( m_atlas.get_size(), nv::RGBA, nv::UBYTE, sampler, nullptr );122 sr->tex = m_window->get_device()->create_texture( m_atlas.get_size(), image_format( nv::RGBA, nv::UBYTE ), sampler, nullptr ); 124 123 125 124 m_render_state.depth_test.enabled = false; … … 262 261 if ( m_reupload ) 263 262 { 264 m_context->update( sr->tex ture, (void*)m_atlas.get_data() );263 m_context->update( sr->tex, (void*)m_atlas.get_data() ); 265 264 m_reupload = false; 266 265 } … … 273 272 sr->varray->update_vertex_buffer( nv::slot::COLOR, vb, false ); 274 273 } 275 m_context->bind( sr->tex ture, TEX_DIFFUSE );274 m_context->bind( sr->tex, TEX_DIFFUSE ); 276 275 m_context->draw( TRIANGLES, m_render_state, m_scene_state, sr->shader, sr->varray, sr->buffer.get_size() * 6 ); 277 276 } … … 283 282 delete p; 284 283 } 285 delete m_render_data; 286 } 284 if ( m_render_data ) 285 { 286 m_context->get_device()->release_texture( ((screen_render_data*)m_render_data)->tex ); 287 delete m_render_data; 288 } 289 }
Note: See TracChangeset
for help on using the changeset viewer.