Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
precompile.cc
Go to the documentation of this file.
1 /*
2  * lib-controler : Un contrôleur générique de scène 3D.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-controler
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "view.hh"
26 #include "precompile.hh"
27 #include <cassert>
28 #include <iostream>
29 //******************************************************************************
30 CPrecompile::CPrecompile(unsigned int ANb) :
31  FToUpdate (true),
32  FEnable (true),
33  FNbView (ANb),
34  FNbEnabledView(0)
35 {
36 #ifndef NO_LIST_OPENGL
37  FCompiledList = -1;
38 #endif // NO_LIST_OPENGL
39 }
40 //******************************************************************************
41 CPrecompile::CPrecompile(const CPrecompile & APrecompile) :
42  FToUpdate (APrecompile.FToUpdate),
43  FEnable (APrecompile.FEnable),
44  FNbView (0),
45  FNbEnabledView(0)
46 {
47 #ifndef NO_LIST_OPENGL
48  FCompiledList = -1;
49 #endif // NO_LIST_OPENGL
50 }
51 //******************************************************************************
53 {
54 #ifndef NO_LIST_OPENGL
55  glDeleteLists(FCompiledList, 1);
56 #endif // NO_LIST_OPENGL
57 }
58 //******************************************************************************
60 {
61  if (isEnabled())
62  {
63 #ifndef NO_LIST_OPENGL
64  glCallList(FCompiledList);
65 #else
66  drawModel();
67 #endif // NO_LIST_OPENGL
68  }
69 }
70 //******************************************************************************
72 {
73 #ifndef NO_LIST_OPENGL
74  if (needToUpdate())
75  {
76  compileModel ();
77  unsetToUpdate();
78  }
79 #endif // NO_LIST_OPENGL
80 }
81 //******************************************************************************
82 void CPrecompile::pick(int /*x*/, int /*y*/, CView* /*AView*/)
83 {}
84 //******************************************************************************
86 { return FToUpdate; }
87 //******************************************************************************
89 { if (isEnabled()) FToUpdate = true; }
90 //******************************************************************************
92 { FToUpdate = false; }
93 //******************************************************************************
94 unsigned int CPrecompile::getNbView()
95 { return FNbView; }
96 //******************************************************************************
97 void CPrecompile::incNbView(unsigned int ADec)
98 { FNbView+=ADec; }
99 //******************************************************************************
100 void CPrecompile::decNbView(unsigned int ADec)
101 {
102  assert( ADec<=FNbView );
103 
104  FNbView-=ADec;
105  if ( FNbView==0 ) delete this;
106 }
107 //******************************************************************************
109 { return FNbEnabledView; }
110 //******************************************************************************
111 void CPrecompile::incNbEnabledView(unsigned int ADec)
112 {
113  if ( FNbEnabledView==0 && FEnable==true ) FToUpdate=true;
114  FNbEnabledView+=ADec;
115 }
116 //******************************************************************************
117 void CPrecompile::decNbEnabledView(unsigned int ADec)
118 {
119  assert( ADec<=FNbEnabledView );
120 
121  FNbEnabledView-=ADec;
122  if ( FNbEnabledView==0 && FEnable==true ) FToUpdate=true;
123 }
124 //******************************************************************************
126 { return ( FEnable && FNbEnabledView>0 ); }
127 //******************************************************************************
129 {
130  if (!FEnable)
131  {
132  if (FNbEnabledView>0) FToUpdate=true;
133  FEnable=true;
134  }
135 }
136 //******************************************************************************
138 {
139  if (FEnable)
140  {
141  if (FNbEnabledView>0) FToUpdate=true;
142  FEnable= false;
143  }
144 }
145 //******************************************************************************
147 {
148 #ifndef NO_LIST_OPENGL
149  if (FCompiledList == -1)
150  // Création du numéro de la liste compilée
151  FCompiledList = glGenLists(1);
152 
153  glNewList(FCompiledList, GL_COMPILE);
154 
155  if (isEnabled())
156  drawModel();
157 
158  glEndList();
159 #endif // NO_LIST_OPENGL
160 }
161 //******************************************************************************