Changeset 331 for trunk/src/gl/gl_device.cc
- Timestamp:
- 09/09/14 20:08:33 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_device.cc
r326 r331 62 62 } 63 63 64 nv::texture nv::gl_device::create_texture( ivec2 size, image_format aformat, sampler asampler, void* data /*= nullptr */ )64 nv::texture nv::gl_device::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, void* data /*= nullptr */ ) 65 65 { 66 66 unsigned glid = 0; 67 unsigned gl_type = texture_type_to_enum( type ); 67 68 glGenTextures( 1, &glid ); 68 69 69 glBindTexture( GL_TEXTURE_2D, glid );70 glBindTexture( gl_type, glid ); 70 71 71 72 // Detect if mipmapping was requested 72 if (( asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) || 73 ( asampler.filter_max != sampler::LINEAR && asampler.filter_max != sampler::NEAREST )) 74 { 75 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 76 } 77 78 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_min ) ); 79 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_max ) ); 80 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (int)nv::sampler_wrap_to_enum( asampler.wrap_s) ); 81 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( asampler.wrap_t) ); 82 83 if (data) 84 { 85 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 ); 86 } 87 88 glBindTexture( GL_TEXTURE_2D, 0 ); 73 if ( gl_type == GL_TEXTURE_2D && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) 74 { 75 // TODO: This should not be done if we use framebuffers! 76 glTexParameteri( gl_type, GL_GENERATE_MIPMAP, GL_TRUE); 77 } 78 79 if ( asampler.filter_max != sampler::NEAREST ) 80 { 81 asampler.filter_max = sampler::LINEAR; 82 } 83 84 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_min ) ); 85 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, (int)nv::sampler_filter_to_enum( asampler.filter_max ) ); 86 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, (int)nv::sampler_wrap_to_enum( asampler.wrap_s) ); 87 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( asampler.wrap_t) ); 88 89 glTexImage2D( gl_type, 0, (GLint)nv::image_format_to_internal_enum(aformat.format), size.x, size.y, 0, nv::image_format_to_enum(aformat.format), nv::datatype_to_gl_enum(aformat.type), data ); 90 91 glBindTexture( gl_type, 0 ); 89 92 90 93 texture result = m_textures.create(); 91 94 gl_texture_info* info = m_textures.get( result ); 95 info->type = type; 92 96 info->format = aformat; 93 97 info->tsampler = asampler;
Note: See TracChangeset
for help on using the changeset viewer.