Changeset 171 for trunk/src


Ignore:
Timestamp:
07/18/13 00:50:12 (12 years ago)
Author:
epyon
Message:
  • sdl - full 2.0 version implemented in the same header
  • sdl - nova fully runs on SDL 2.0 *also*
Location:
trunk/src
Files:
4 edited

Legend:

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

    r157 r171  
    77#include "nv/gl/gl_enum.hh"
    88#include "nv/lib/gl.hh"
     9#include "nv/lib/sdl.hh"
    910
    1011using namespace nv;
     
    349350
    350351
    351 gl_context::gl_context( device* a_device )
    352         : context( a_device )
    353 {
     352gl_context::gl_context( device* a_device, void* a_win_handle )
     353        : context( a_device ), m_handle( nullptr )
     354{
     355#if NV_SDL_VERSION == NV_SDL_20
     356        m_handle = SDL_GL_CreateContext( static_cast<SDL_Window*>( a_win_handle ) );
     357
     358        if ( m_handle == 0 )
     359        {
     360                NV_LOG( LOG_CRITICAL, "GL Context creation failed: " << SDL_GetError( ) );
     361                return; // TODO: Error report
     362        }
     363#else
     364        NV_UNUSED( a_win_handle );
     365#endif
     366
     367        nv::load_gl_library();
     368        NV_LOG( LOG_INFO, "OpenGL Vendor       : " << glGetString(GL_VENDOR) );
     369        NV_LOG( LOG_INFO, "OpenGL Renderer     : " << glGetString(GL_RENDERER) );
     370        NV_LOG( LOG_INFO, "OpenGL Version      : " << glGetString(GL_VERSION) );
     371        NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
     372#if NV_SDL_VERSION == NV_SDL_20
     373//      SDL_GL_SetSwapInterval(1);
     374#endif
     375
    354376        // TODO: do we really need this?
    355377        glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
     378
    356379        force_apply_render_state( m_render_state );
    357380}
     381
     382
     383nv::gl_context::~gl_context()
     384{
     385#if NV_SDL_VERSION == NV_SDL_20
     386        SDL_GL_DeleteContext(static_cast<SDL_GLContext>( m_handle ) );
     387#endif
     388}
     389
    358390
    359391void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
  • trunk/src/gl/gl_device.cc

    r170 r171  
    3131        }
    3232
     33#if NV_SDL_VERSION == NV_SDL_12
    3334        m_info = SDL_GetVideoInfo( );
    3435
     
    3839                return; // TODO: Error report
    3940        }
     41#endif
    4042
    4143//      bpp = m_info->vfmt->BitsPerPixel;
     
    4951        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
    5052        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );
     53
     54#if NV_SDL_VERSION == NV_SDL_20
     55        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
     56        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
     57        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     58        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
     59#endif
    5160
    5261}
  • trunk/src/gl/gl_window.cc

    r170 r171  
    1818        kevent.key.code    = KEY_NONE;
    1919
     20#if NV_SDL_VERSION == NV_SDL_20
     21        uint32 ucode = ke.keysym.sym;
     22#else
     23        uint32 ucode = ke.keysym.unicode;
     24#endif
     25
    2026        // if result is a typable char place it into the structure
    21         if (ke.keysym.unicode >= 32 && ke.keysym.unicode < 128 )
    22         {
    23                 kevent.key.ascii = static_cast<char8>( ke.keysym.unicode );
     27        if (ucode >= 32 && ucode < 128 )
     28        {
     29                kevent.key.ascii = static_cast<char8>( ucode );
    2430        }
    2531
     
    6773        case SDLK_DELETE       : kevent.key.code = KEY_DELETE; break;
    6874        case SDLK_INSERT       : kevent.key.code = KEY_INSERT; break;
    69         case SDLK_KP5          : kevent.key.code = KEY_CENTER; break;
     75        //case SDLK_KP5          : kevent.key.code = KEY_CENTER; break;
    7076        case SDLK_ESCAPE       : kevent.key.code = KEY_ESCAPE; break;
    7177        case SDLK_QUOTE        : kevent.key.code = KEY_QUOTE; break;
     
    9197        mevent.mbutton.button  = MOUSE_NONE;
    9298        mevent.mbutton.pressed = (mb.state != SDL_RELEASED);
    93         mevent.mbutton.x       = mb.x;
    94         mevent.mbutton.y       = mb.y;
     99        mevent.mbutton.x       = static_cast< uint16 >( mb.x );
     100        mevent.mbutton.y       = static_cast< uint16 >( mb.y );
    95101
    96102        switch ( mb.button )
     
    99105        case SDL_BUTTON_MIDDLE    : mevent.mbutton.button = MOUSE_MIDDLE; break;
    100106        case SDL_BUTTON_RIGHT     : mevent.mbutton.button = MOUSE_RIGHT; break;
    101         case SDL_BUTTON_WHEELUP   : mevent.mbutton.button = MOUSE_WHEEL_UP; break;
    102         case SDL_BUTTON_WHEELDOWN : mevent.mbutton.button = MOUSE_WHEEL_DOWN; break;
     107        //case SDL_BUTTON_WHEELUP   : mevent.mbutton.button = MOUSE_WHEEL_UP; break;
     108        //case SDL_BUTTON_WHEELDOWN : mevent.mbutton.button = MOUSE_WHEEL_DOWN; break;
    103109        default : break;
    104110        }
     
    111117        mevent.type          = EV_MOUSE_MOVE;
    112118        mevent.mmove.pressed = (mm.state != SDL_RELEASED);
    113         mevent.mmove.x       = mm.x;
    114         mevent.mmove.y       = mm.y;
     119        mevent.mmove.x       = static_cast< uint16 >( mm.x );
     120        mevent.mmove.y       = static_cast< uint16 >( mm.y );
    115121        return true;
    116122}
     
    125131        case SDL_MOUSEBUTTONDOWN : return sdl_mouse_button_to_io_event( e.button, ioevent );
    126132        case SDL_MOUSEBUTTONUP   : return sdl_mouse_button_to_io_event( e.button, ioevent );
     133/* // SDL 2.0 incompatible
    127134        case SDL_ACTIVEEVENT     :
    128135                ioevent.type = EV_ACTIVE;
     
    134141                ioevent.resize.y = e.resize.h;
    135142                return true;
     143        case SDL_NOEVENT         : return false;
     144        case SDL_VIDEOEXPOSE     : return false;
     145*/
    136146        case SDL_SYSWMEVENT      : ioevent.type = EV_SYSTEM; return true;
    137147        case SDL_QUIT            : ioevent.type = EV_QUIT;   return true;
    138         case SDL_NOEVENT         : return false;
    139         case SDL_VIDEOEXPOSE     : return false;
    140148        case SDL_JOYAXISMOTION   : return false;
    141149        case SDL_JOYBALLMOTION   : return false;
     
    149157
    150158gl_window::gl_window( device* dev, uint16 width, uint16 height )
    151         : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_screen( nullptr )
    152 {
     159        : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr )
     160{
     161#if NV_SDL_VERSION == NV_SDL_12
    153162        uint32 flags = SDL_OPENGL;
    154        
    155         m_screen = SDL_SetVideoMode( width, height, 32, flags );
    156        
    157         if ( m_screen == 0 )
     163        m_handle = SDL_SetVideoMode( width, height, 32, flags );
     164#elif NV_SDL_VERSION == NV_SDL_20
     165        uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
     166        m_handle = SDL_CreateWindow("Nova Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
     167                width, height, flags );
     168#endif
     169        if ( m_handle == 0 )
    158170        {
    159171                NV_LOG( LOG_CRITICAL, "Video mode set failed: " << SDL_GetError( ) );
     
    161173        }
    162174
    163         nv::load_gl_library();
    164         NV_LOG( LOG_INFO, "OpenGL Vendor       : " << glGetString(GL_VENDOR) );
    165         NV_LOG( LOG_INFO, "OpenGL Renderer     : " << glGetString(GL_RENDERER) );
    166         NV_LOG( LOG_INFO, "OpenGL Version      : " << glGetString(GL_VERSION) );
    167         NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
    168 
    169         m_context = new gl_context( m_device );
     175        m_context = new gl_context( m_device, m_handle );
    170176        m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
    171177}
     
    188194void gl_window::set_title( const string& title )
    189195{
     196#if NV_SDL_VERSION == NV_SDL_20
     197        SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() );
     198#else
    190199        SDL_WM_SetCaption( title.c_str(), title.c_str() );
     200#endif
    191201        m_title = title;
    192202}
     
    206216void gl_window::swap_buffers()
    207217{
     218#if NV_SDL_VERSION == NV_SDL_20
     219        SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) );
     220#else
    208221        SDL_GL_SwapBuffers();
     222#endif
    209223}
    210224
     
    212226{
    213227        delete m_context;
    214 }
     228#if NV_SDL_VERSION == NV_SDL_20
     229        SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
     230#endif
     231}
  • trunk/src/lib/sdl.cc

    r170 r171  
    1313#define NV_SDL_FUN( rtype, fname, fparams ) rtype (NV_SDL_APIENTRY *fname) fparams = nullptr;
    1414#include <nv/lib/detail/sdl_functions.inc>
     15#if NV_SDL_VERSION == NV_SDL_12
     16#       include <nv/lib/detail/sdl_functions_12.inc>
     17#elif NV_SDL_VERSION == NV_SDL_20
     18#       include <nv/lib/detail/sdl_functions_20.inc>
     19#endif
    1520#undef NV_SDL_FUN
     21
     22
    1623
    1724bool nv::load_sdl_library( const char* path )
     
    2229#       define NV_SDL_FUN( rtype, fname, fparams ) *(void **) (&fname) = sdl_library.get(#fname);
    2330#       include <nv/lib/detail/sdl_functions.inc>
     31#       if NV_SDL_VERSION == NV_SDL_12
     32#               include <nv/lib/detail/sdl_functions_12.inc>
     33#       elif NV_SDL_VERSION == NV_SDL_20
     34#               include <nv/lib/detail/sdl_functions_20.inc>
     35#       endif
    2436#       undef NV_SDL_FUN
    2537        return true;
Note: See TracChangeset for help on using the changeset viewer.