]> git.tdb.fi Git - libs/gl.git/blob - source/select.cpp
Use texture unit numbers instead of slot names in RenderPass
[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 "except.h"
9 #include "gl.h"
10 #include "select.h"
11
12 using namespace std;
13
14 namespace {
15
16 vector<Msp::GL::SelectRecord> *select_buf = 0;
17 vector<unsigned> select_buf_int;
18
19 }
20
21 namespace Msp {
22 namespace GL {
23
24 void select_buffer(vector<SelectRecord> &buf)
25 {
26         select_buf_int.resize(1024);
27         glSelectBuffer(select_buf_int.size(), &select_buf_int[0]);
28         select_buf = &buf;
29 }
30
31 void init_names()
32 {
33         glInitNames();
34 }
35
36 void push_name(unsigned n)
37 {
38         glPushName(n);
39 }
40
41 void pop_name()
42 {
43         glPopName();
44 }
45
46 void load_name(unsigned n)
47 {
48         glLoadName(n);
49 }
50
51 void parse_select_records(const unsigned *buf, unsigned count, vector<SelectRecord> &tbuf)
52 {
53         unsigned i = 0;
54         while(count--)
55         {
56                 SelectRecord record;
57
58                 unsigned n_names = buf[i++];
59                 record.min_depth = buf[i++];
60                 record.max_depth = buf[i++];
61
62                 record.names.reserve(n_names);
63                 while(n_names--)
64                         record.names.push_back(buf[i++]);
65                 
66                 tbuf.push_back(record);
67         }
68 }
69
70 void _parse_internal_select_records(unsigned count)
71 {
72         if(!select_buf)
73                 throw InvalidState("No select buffer specified");
74         parse_select_records(&select_buf_int[0], count, *select_buf);
75 }
76
77 } // namespace GL
78 } // namespace Msp