source: trunk/src/gl/gl_texture2d.cc @ 300

Last change on this file since 300 was 300, checked in by epyon, 11 years ago
  • removed gl_names - too much bloat for too little gain
File size: 1.6 KB
Line 
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
10using namespace nv;
11
12nv::gl_texture2d::gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
13        : texture2d( size, aformat, adatatype, asampler )
14{
15        glGenTextures( 1, &glid );
16
17        glBindTexture( GL_TEXTURE_2D, glid );
18
19        // Detect if mipmapping was requested
20        if (( asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) ||
21                ( asampler.filter_max != sampler::LINEAR && asampler.filter_max != sampler::NEAREST ))
22        {
23                glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
24        }
25
26        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (int)nv::sampler_filter_to_enum( m_sampler.filter_min ) );
27        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (int)nv::sampler_filter_to_enum( m_sampler.filter_max ) );
28        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (int)nv::sampler_wrap_to_enum( m_sampler.wrap_s) );
29        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( m_sampler.wrap_t) );
30
31        if (data)
32        {
33                glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(m_format.format), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format.format), nv::datatype_to_gl_enum(m_format.type), data );
34        }
35
36        glBindTexture( GL_TEXTURE_2D, 0 );
37}
38
39nv::gl_texture2d::~gl_texture2d()
40{
41        if ( glid != 0 )
42        {
43                glDeleteTextures( 1, &glid );
44        }
45}
46
Note: See TracBrowser for help on using the repository browser.