[43] | 1 | // Copyright (C) 2012-2013 Kornel Kisielewicz
|
---|
| 2 | // This file is part of NV Libraries.
|
---|
| 3 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
| 4 |
|
---|
| 5 | #include "nv/gl/gl_texture2d.hh"
|
---|
| 6 |
|
---|
| 7 | #include "nv/gl/gl_enum.hh"
|
---|
| 8 | #include "nv/lib/gl.hh"
|
---|
| 9 |
|
---|
| 10 | using namespace nv;
|
---|
| 11 |
|
---|
[49] | 12 | nv::gl_texture2d::gl_texture2d( ivec2 size, image_format aformat, type adatatype, sampler asampler, void* data /*= nullptr */ )
|
---|
| 13 | : texture2d( size, aformat, adatatype, asampler ), m_name()
|
---|
[43] | 14 | {
|
---|
| 15 | glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
|
---|
| 16 |
|
---|
[49] | 17 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nv::sampler_filter_to_enum( m_sampler.filter_min ) );
|
---|
| 18 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nv::sampler_filter_to_enum( m_sampler.filter_max ) );
|
---|
| 19 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, nv::sampler_wrap_to_enum( m_sampler.wrap_s) );
|
---|
| 20 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, nv::sampler_wrap_to_enum( m_sampler.wrap_t) );
|
---|
[43] | 21 |
|
---|
| 22 | glBindTexture( GL_TEXTURE_2D, 0 );
|
---|
| 23 |
|
---|
| 24 | if (data)
|
---|
| 25 | {
|
---|
| 26 | assign(data);
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | void nv::gl_texture2d::assign( void* data )
|
---|
| 31 | {
|
---|
| 32 | glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
|
---|
[49] | 33 | glTexImage2D( GL_TEXTURE_2D, 0, nv::image_format_to_enum(m_format), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format), nv::type_to_gl_enum(m_datatype), data );
|
---|
[43] | 34 | glBindTexture( GL_TEXTURE_2D, 0 );
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | void nv::gl_texture2d::bind( int slot )
|
---|
| 38 | {
|
---|
| 39 | glActiveTexture( GL_TEXTURE0 + slot );
|
---|
| 40 | glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | void nv::gl_texture2d::unbind()
|
---|
| 44 | {
|
---|
| 45 | glBindTexture( GL_TEXTURE_2D, 0 );
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | bool nv::gl_texture2d::is_valid() const
|
---|
| 49 | {
|
---|
| 50 | return m_name.is_valid();
|
---|
| 51 | }
|
---|