[38] | 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_device.hh"
|
---|
| 6 |
|
---|
| 7 | #include "nv/gl/gl_window.hh"
|
---|
| 8 | #include "nv/gl/gl_program.hh"
|
---|
| 9 | #include "nv/logging.hh"
|
---|
| 10 | #include "nv/lib/sdl12.hh"
|
---|
| 11 |
|
---|
| 12 | using namespace nv;
|
---|
| 13 |
|
---|
| 14 | window* gl_device::create_window( uint16 width, uint16 height )
|
---|
| 15 | {
|
---|
| 16 | return new gl_window( width, height );
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | gl_device::gl_device()
|
---|
| 20 | {
|
---|
| 21 | nv::load_sdl_library();
|
---|
| 22 | m_info = NULL;
|
---|
| 23 |
|
---|
| 24 | if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
|
---|
| 25 | {
|
---|
| 26 | NV_LOG( LOG_CRITICAL, "Video initialization failed: " << SDL_GetError( ) );
|
---|
| 27 | return; // TODO: Error report
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | m_info = SDL_GetVideoInfo( );
|
---|
| 31 |
|
---|
| 32 | if ( !m_info )
|
---|
| 33 | {
|
---|
| 34 | NV_LOG( LOG_CRITICAL, "Video query failed: " << SDL_GetError( ) );
|
---|
| 35 | return; // TODO: Error report
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | // bpp = m_info->vfmt->BitsPerPixel;
|
---|
| 39 |
|
---|
| 40 | SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
|
---|
| 41 | SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
|
---|
| 42 | SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
|
---|
| 43 | SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
|
---|
| 44 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | program* gl_device::create_program( const string& vs_source, const string& fs_source )
|
---|
| 48 | {
|
---|
| 49 | return new gl_program( vs_source, fs_source );
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | gl_device::~gl_device()
|
---|
| 54 | {
|
---|
| 55 | SDL_Quit();
|
---|
| 56 | }
|
---|