- Timestamp:
- 08/07/14 12:11:16 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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.