Ignore:
Timestamp:
08/07/14 12:11:16 (11 years ago)
Author:
epyon
Message:
  • textures are now handled by lightweight handles
  • textures now need to be manually released via context
  • removed all old texture2d functionality
  • unreleased textures will be auto-released
  • textures are properly tracked via entity system
  • detailed stats and checking now possible
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gl/gl_device.cc

    r299 r301  
    88#include "nv/gl/gl_program.hh"
    99#include "nv/gl/gl_vertex_buffer.hh"
    10 #include "nv/gl/gl_texture2d.hh"
    1110#include "nv/logging.hh"
    1211#include "nv/lib/sdl.hh"
    1312#include "nv/lib/sdl_image.hh"
     13#include "nv/gl/gl_enum.hh"
     14#include "nv/lib/gl.hh"
    1415
    1516using namespace nv;
     
    8889}
    8990
    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 
    9591uint32 gl_device::get_ticks()
    9692{
     
    105101gl_device::~gl_device()
    106102{
     103        // TODO: better use release_texture
     104        for ( auto& t : m_textures ) glDeleteTextures( 1, &t.glid );
     105
    107106        SDL_Quit();
    108107}
     108
     109nv::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
     144void 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
     154const 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.