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