]> git.tdb.fi Git - libs/gl.git/blob - source/select.cpp
67420977323597738ebfac564c8c9514ce637799
[libs/gl.git] / source / select.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <GL/gl.h>
9 #include "except.h"
10 #include "select.h"
11
12 using namespace std;
13
14 namespace {
15
16 using namespace Msp::GL;
17
18 vector<SelectRecord> *select_buf=0;
19 vector<uint> select_buf_int;
20
21 }
22
23 namespace Msp {
24 namespace GL {
25
26 void select_buffer(vector<SelectRecord> &buf)
27 {
28         select_buf_int.resize(1024);
29         glSelectBuffer(select_buf_int.size(), &select_buf_int[0]);
30         select_buf=&buf;
31 }
32
33 void parse_select_records(const uint *buf, uint count, vector<SelectRecord> &tbuf)
34 {
35         uint i=0;
36         while(count--)
37         {
38                 SelectRecord record;
39
40                 uint n_names=buf[i++];
41                 record.min_depth=buf[i++];
42                 record.max_depth=buf[i++];
43
44                 record.names.reserve(n_names);
45                 while(n_names--)
46                         record.names.push_back(buf[i++]);
47                 
48                 tbuf.push_back(record);
49         }
50 }
51
52 void _parse_internal_select_records(uint count)
53 {
54         if(!select_buf)
55                 throw InvalidState("No select buffer specified");
56         parse_select_records(&select_buf_int[0], count, *select_buf);
57 }
58
59 } // namespace GL
60 } // namespace Msp