source: trunk/nv/interface/device.hh @ 73

Last change on this file since 73 was 73, checked in by epyon, 12 years ago
  • shortcut create_vertex_array based on program and mesh
File size: 1.9 KB
Line 
1// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6/**
7 * @file device.hh
8 * @author Kornel Kisielewicz epyon@chaosforge.org
9 * @brief Device class
10 */
11
12#ifndef NV_DEVICE_HH
13#define NV_DEVICE_HH
14
15#include <nv/common.hh>
16#include <nv/string.hh>
17#include <nv/interface/mesh.hh>
18#include <nv/interface/vertex_buffer.hh>
19#include <nv/interface/texture2d.hh>
20
21namespace nv
22{
23        class window;
24        class program;
25
26        class device
27        {
28        public:
29                virtual window* create_window( uint16 width, uint16 height ) = 0;
30                virtual program* create_program( const string& vs_source, const string& fs_source ) = 0;
31                virtual vertex_buffer* create_vertex_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0;
32                virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0;
33                virtual vertex_array* create_vertex_array() = 0;
34                virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0;
35
36                virtual vertex_array* create_vertex_array( const mesh* m, const attribute_map* am, buffer_hint hint )
37                {
38                        vertex_array* result = create_vertex_array();
39                        for ( auto attr : m->get_attributes() )
40                        {
41                                // TODO : error checking
42                                vertex_buffer* vb = create_vertex_buffer( hint, attr.second->get_size(), attr.second->get_data() );
43                                result->add_vertex_buffer( am->at( attr.first )->get_location(), vb, attr.second->get_base_type(), attr.second->get_components() );
44                        }
45                        if ( m->has_indices() )
46                        {
47                                const vertex_attribute_base* i = m->get_indices();
48                                index_buffer* vb = create_index_buffer( hint, i->get_size(), i->get_data() );
49                                result->set_index_buffer( vb );
50                        }
51                        return result;
52                }
53        };
54
55} // namespace nv
56
57
58#endif // NV_DEVICE_HH
Note: See TracBrowser for help on using the repository browser.