GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_context.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
23 
24 #ifndef GLC_CONTEXT_H_
25 #define GLC_CONTEXT_H_
26 
27 #include <QtOpenGL>
28 #include <QGLContext>
29 #include <QGLFormat>
30 #include <QSharedPointer>
31 #include <QtDebug>
32 
33 #include "glc_config.h"
34 #include "maths/glc_matrix4x4.h"
35 #include "glc_contextshareddata.h"
36 #include "glc_uniformshaderdata.h"
37 
39 
40 // OpenGL ES define
41 #if defined(QT_OPENGL_ES_2)
42 #define GLC_OPENGL_ES_2 1
43 
44 #define GL_MODELVIEW 0x1700
45 #define GL_PROJECTION 0x1701
46 #endif
47 
48 
49 //#define GLC_OPENGL_ES_2 1
50 
53 
58 
59 class GLC_LIB_EXPORT GLC_Context : public QGLContext
60 {
62 
64 
65 
66 public:
67  GLC_Context(const QGLFormat& format);
68  virtual ~GLC_Context();
69 
71 
72 
74 
75 public:
77  static GLC_Context* current();
78 
80  inline GLC_Matrix4x4 modelViewMatrix() const
81  {Q_ASSERT(m_MatrixStackHash.contains(GL_MODELVIEW)); return m_MatrixStackHash.value(GL_MODELVIEW)->top();}
82 
84  inline GLC_Matrix4x4 projectionMatrix() const
85  {Q_ASSERT(m_MatrixStackHash.contains(GL_PROJECTION)); return m_MatrixStackHash.value(GL_PROJECTION)->top();}
86 
88  inline bool lightingIsEnable() const
89  {return m_LightingIsEnable.top();}
91 
92 
94 
95 public:
97  void glcMatrixMode(GLenum mode);
98 
100  void glcLoadIdentity();
101 
103  void glcPushMatrix();
104  void glcPopMatrix();
105 
107  void glcLoadMatrix(const GLC_Matrix4x4& matrix);
108 
110  void glcMultMatrix(const GLC_Matrix4x4& matrix);
111 
113  inline void glcTranslated(double x, double y, double z)
114  {glcMultMatrix(GLC_Matrix4x4(x, y, z));}
115 
117  void glcScaled(double x, double y, double z);
118 
120  void glcOrtho(double left, double right, double bottom, double top, double nearVal, double farVal);
121 
123  void glcFrustum(double left, double right, double bottom, double top, double nearVal, double farVal);
124 
126  void glcEnableLighting(bool enable);
127 
129 
130 
132 
133 public:
134 
136  virtual void makeCurrent();
137 
139  virtual void doneCurrent();
140 
142  inline void updateUniformVariables()
143  {m_UniformShaderData.updateAll(this);}
144 
146 
147 
149 
150 protected:
152 
153  virtual bool chooseContext(const QGLContext* shareContext= 0);
155 
157 
159 
160 private:
162 
164  void init();
166 
167 
169 // Private members
171 private:
172 
175 
177  QHash<GLenum, QStack<GLC_Matrix4x4>* > m_MatrixStackHash;
178 
180  QSharedPointer<GLC_ContextSharedData> m_ContextSharedData;
181 
184 
187 
189  QStack<bool> m_LightingIsEnable;
190 
192  QHash<GLenum, bool> m_LightsEnableState;
193 
194 };
195 
196 #endif /* GLC_CONTEXT_H_ */

©2005-2013 Laurent Ribon