Changeset 301 for trunk/src/gl/gl_device.cc
- Timestamp:
- 08/07/14 12:11:16 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.