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

Last change on this file since 299 was 299, checked in by epyon, 11 years ago
  • all bind and update function for graphics objects are done via context (will simplify directx device, and allow for handles instead of objects)
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
[228]17window* gl_device::create_window( uint16 width, uint16 height, bool fullscreen )
[38]18{
[228]19        return new gl_window( this, width, height, fullscreen );
[38]20}
21
[245]22window* nv::gl_device::adopt_window( void* sys_w_handle, void* sys_dc )
23{
24        return new gl_window( this, sys_w_handle, sys_dc );
25}
26
27
28
[38]29gl_device::gl_device()
30{
31        nv::load_sdl_library();
32        m_info = NULL;
33
[184]34        if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 )
[38]35        {
36                NV_LOG( LOG_CRITICAL, "Video initialization failed: " << SDL_GetError( ) );
37                return; // TODO: Error report
38        }
39
[171]40#if NV_SDL_VERSION == NV_SDL_12
[38]41        m_info = SDL_GetVideoInfo( );
42
43        if ( !m_info )
44        {
45                NV_LOG( LOG_CRITICAL, "Video query failed: " << SDL_GetError( ) );
46                return; // TODO: Error report
47        }
[171]48#endif
[38]49
50}
51
52program* gl_device::create_program( const string& vs_source, const string& fs_source )
53{
54        return new gl_program( vs_source, fs_source );
55}
56
[153]57vertex_buffer* gl_device::create_vertex_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
[42]58{
59        return new gl_vertex_buffer( hint, size, source );
60}
[38]61
[153]62index_buffer* gl_device::create_index_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
[44]63{
64        return new gl_index_buffer( hint, size, source );
65}
66
67vertex_array* gl_device::create_vertex_array()
68{
[299]69        return new vertex_array();
[44]70}
71
[90]72// this is a temporary function that will be removed once we find a way to
73// pass binary file data around
74image_data* nv::gl_device::create_image_data( const std::string& filename )
75{
76        load_sdl_image_library();
77        SDL_Surface* image = IMG_Load( filename.c_str() );
[120]78        if (!image)
79        {
80                NV_LOG( LOG_ERROR, "Image file " << filename.c_str() << " not found!" );
81                return nullptr;
82        }
[292]83        // TODO: BGR vs RGB, single channel
84        assert( image->format->BytesPerPixel > 2 );
85        image_format format(image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE );
86        image_data* data = new image_data( format, glm::ivec2( image->w, image->h ), (nv::uint8*)image->pixels );
[90]87        return data;
88}
89
[292]90texture2d* gl_device::create_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ )
[45]91{
[49]92        return new gl_texture2d( size, aformat, adatatype, asampler, data );
[45]93}
94
[92]95uint32 gl_device::get_ticks()
96{
97        return SDL_GetTicks();
98}
99
100void gl_device::delay( uint32 ms )
101{
102        return SDL_Delay( ms );
103}
104
[38]105gl_device::~gl_device()
106{
107        SDL_Quit();
108}
Note: See TracBrowser for help on using the repository browser.