[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"
|
---|
[42] | 9 | #include "nv/gl/gl_vertex_buffer.hh"
|
---|
[45] | 10 | #include "nv/gl/gl_texture2d.hh"
|
---|
[38] | 11 | #include "nv/logging.hh"
|
---|
| 12 | #include "nv/lib/sdl12.hh"
|
---|
| 13 |
|
---|
| 14 | using namespace nv;
|
---|
| 15 |
|
---|
| 16 | window* gl_device::create_window( uint16 width, uint16 height )
|
---|
| 17 | {
|
---|
| 18 | return new gl_window( width, height );
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | gl_device::gl_device()
|
---|
| 22 | {
|
---|
| 23 | nv::load_sdl_library();
|
---|
| 24 | m_info = NULL;
|
---|
| 25 |
|
---|
| 26 | if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
|
---|
| 27 | {
|
---|
| 28 | NV_LOG( LOG_CRITICAL, "Video initialization failed: " << SDL_GetError( ) );
|
---|
| 29 | return; // TODO: Error report
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | m_info = SDL_GetVideoInfo( );
|
---|
| 33 |
|
---|
| 34 | if ( !m_info )
|
---|
| 35 | {
|
---|
| 36 | NV_LOG( LOG_CRITICAL, "Video query failed: " << SDL_GetError( ) );
|
---|
| 37 | return; // TODO: Error report
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | // bpp = m_info->vfmt->BitsPerPixel;
|
---|
| 41 |
|
---|
| 42 | SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
|
---|
| 43 | SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
|
---|
| 44 | SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
|
---|
| 45 | SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
|
---|
| 46 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | program* gl_device::create_program( const string& vs_source, const string& fs_source )
|
---|
| 50 | {
|
---|
| 51 | return new gl_program( vs_source, fs_source );
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[42] | 54 | vertex_buffer* gl_device::create_vertex_buffer( buffer_hint hint, int size, void* source /*= nullptr */ )
|
---|
| 55 | {
|
---|
| 56 | return new gl_vertex_buffer( hint, size, source );
|
---|
| 57 | }
|
---|
[38] | 58 |
|
---|
[44] | 59 | index_buffer* gl_device::create_index_buffer( buffer_hint hint, int size, void* source /*= nullptr */ )
|
---|
| 60 | {
|
---|
| 61 | return new gl_index_buffer( hint, size, source );
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | vertex_array* gl_device::create_vertex_array()
|
---|
| 65 | {
|
---|
| 66 | return new gl_vertex_array();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[70] | 69 | texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
|
---|
[45] | 70 | {
|
---|
[49] | 71 | return new gl_texture2d( size, aformat, adatatype, asampler, data );
|
---|
[45] | 72 | }
|
---|
| 73 |
|
---|
[38] | 74 | gl_device::~gl_device()
|
---|
| 75 | {
|
---|
| 76 | SDL_Quit();
|
---|
| 77 | }
|
---|