source: trunk/src/gl/gl_device.cc @ 121

Last change on this file since 121 was 121, checked in by epyon, 12 years ago
  • Nova builds with -Weverything/-Wall/-pedantic/etc on: on MSVC 2012 on GCC 4.6.3 on clang 3.2
  • ... without a single fucking warning.
File size: 2.7 KB
Line 
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/gl/gl_texture2d.hh"
11#include "nv/logging.hh"
12#include "nv/lib/sdl12.hh"
13#include "nv/lib/sdl_image.hh"
14
15using namespace nv;
16
17window* gl_device::create_window( uint16 width, uint16 height )
18{
19        return new gl_window( this, width, height );
20}
21
22gl_device::gl_device()
23{
24        nv::load_sdl_library();
25        m_info = NULL;
26
27        if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
28        {
29                NV_LOG( LOG_CRITICAL, "Video initialization failed: " << SDL_GetError( ) );
30                return; // TODO: Error report
31        }
32
33        m_info = SDL_GetVideoInfo( );
34
35        if ( !m_info )
36        {
37                NV_LOG( LOG_CRITICAL, "Video query failed: " << SDL_GetError( ) );
38                return; // TODO: Error report
39        }
40
41//      bpp = m_info->vfmt->BitsPerPixel;
42
43        SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
44        SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
45        SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
46        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
47        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
48}
49
50program* gl_device::create_program( const string& vs_source, const string& fs_source )
51{
52        return new gl_program( vs_source, fs_source );
53}
54
55vertex_buffer* gl_device::create_vertex_buffer( buffer_hint hint, size_t size, void* source /*= nullptr */ )
56{
57        return new gl_vertex_buffer( hint, size, source );
58}
59
60index_buffer* gl_device::create_index_buffer( buffer_hint hint, size_t size, void* source /*= nullptr */ )
61{
62        return new gl_index_buffer( hint, size, source );
63}
64
65vertex_array* gl_device::create_vertex_array()
66{
67        return new gl_vertex_array();
68}
69
70// this is a temporary function that will be removed once we find a way to
71// pass binary file data around
72image_data* nv::gl_device::create_image_data( const std::string& filename )
73{
74        load_sdl_image_library();
75        SDL_Surface* image = IMG_Load( filename.c_str() );
76        if (!image)
77        {
78                NV_LOG( LOG_ERROR, "Image file " << filename.c_str() << " not found!" );
79                return nullptr;
80        }
81        image_data* data = new image_data( glm::ivec2( image->w, image->h ), image->format->BytesPerPixel, (nv::uint8*)image->pixels );
82        return data;
83}
84
85texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
86{
87        return new gl_texture2d( size, aformat, adatatype, asampler, data );
88}
89
90uint32 gl_device::get_ticks()
91{
92        return SDL_GetTicks();
93}
94
95void gl_device::delay( uint32 ms )
96{
97        return SDL_Delay( ms );
98}
99
100gl_device::~gl_device()
101{
102        SDL_Quit();
103}
Note: See TracBrowser for help on using the repository browser.