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

Last change on this file since 170 was 170, checked in by epyon, 12 years ago
  • sdl - structure/define wise 2.0 support added (no functions yet)
  • sdl12 -> sdl
File size: 2.8 KB
RevLine 
[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"
[170]12#include "nv/lib/sdl.hh"
[90]13#include "nv/lib/sdl_image.hh"
[38]14
15using namespace nv;
16
17window* gl_device::create_window( uint16 width, uint16 height )
18{
[98]19        return new gl_window( this, width, height );
[38]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 );
[161]46        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
[38]47        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
[161]48
49        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
50        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );
51
[38]52}
53
54program* gl_device::create_program( const string& vs_source, const string& fs_source )
55{
56        return new gl_program( vs_source, fs_source );
57}
58
[153]59vertex_buffer* gl_device::create_vertex_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
[42]60{
61        return new gl_vertex_buffer( hint, size, source );
62}
[38]63
[153]64index_buffer* gl_device::create_index_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
[44]65{
66        return new gl_index_buffer( hint, size, source );
67}
68
69vertex_array* gl_device::create_vertex_array()
70{
71        return new gl_vertex_array();
72}
73
[90]74// this is a temporary function that will be removed once we find a way to
75// pass binary file data around
76image_data* nv::gl_device::create_image_data( const std::string& filename )
77{
78        load_sdl_image_library();
79        SDL_Surface* image = IMG_Load( filename.c_str() );
[120]80        if (!image)
81        {
82                NV_LOG( LOG_ERROR, "Image file " << filename.c_str() << " not found!" );
83                return nullptr;
84        }
[90]85        image_data* data = new image_data( glm::ivec2( image->w, image->h ), image->format->BytesPerPixel, (nv::uint8*)image->pixels );
86        return data;
87}
88
[70]89texture2d* gl_device::create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
[45]90{
[49]91        return new gl_texture2d( size, aformat, adatatype, asampler, data );
[45]92}
93
[92]94uint32 gl_device::get_ticks()
95{
96        return SDL_GetTicks();
97}
98
99void gl_device::delay( uint32 ms )
100{
101        return SDL_Delay( ms );
102}
103
[38]104gl_device::~gl_device()
105{
106        SDL_Quit();
107}
Note: See TracBrowser for help on using the repository browser.