glc_context.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00023 
00024 #ifndef GLC_CONTEXT_H_
00025 #define GLC_CONTEXT_H_
00026 
00027 #include <QtOpenGL>
00028 #include <QGLContext>
00029 #include <QGLFormat>
00030 #include <QSharedPointer>
00031 #include <QtDebug>
00032 
00033 #include "glc_config.h"
00034 #include "maths/glc_matrix4x4.h"
00035 #include "glc_contextshareddata.h"
00036 #include "glc_uniformshaderdata.h"
00037 
00038 class GLC_ContextSharedData;
00039 
00040 // OpenGL ES define
00041 #if defined(QT_OPENGL_ES_2)
00042 #define GLC_OPENGL_ES_2 1
00043 
00044 #define GL_MODELVIEW                                    0x1700
00045 #define GL_PROJECTION                                   0x1701
00046 #endif
00047 
00048 
00049 //#define GLC_OPENGL_ES_2 1
00050 
00053 
00058 
00059 class GLC_LIB_EXPORT GLC_Context : public QGLContext
00060 {
00062 
00064 
00065 
00066 public:
00067         GLC_Context(const QGLFormat& format);
00068         virtual ~GLC_Context();
00069 
00071 
00072 
00074 
00075 public:
00077         static GLC_Context* current();
00078 
00080         inline GLC_Matrix4x4 modelViewMatrix() const
00081         {Q_ASSERT(m_MatrixStackHash.contains(GL_MODELVIEW)); return m_MatrixStackHash.value(GL_MODELVIEW)->top();}
00082 
00084         inline GLC_Matrix4x4 projectionMatrix() const
00085         {Q_ASSERT(m_MatrixStackHash.contains(GL_PROJECTION)); return m_MatrixStackHash.value(GL_PROJECTION)->top();}
00086 
00088         inline bool lightingIsEnable() const
00089         {return m_LightingIsEnable.top();}
00091 
00092 
00094 
00095 public:
00097         void glcMatrixMode(GLenum mode);
00098 
00100         void glcLoadIdentity();
00101 
00103         void glcPushMatrix();
00104         void glcPopMatrix();
00105 
00107         void glcLoadMatrix(const GLC_Matrix4x4& matrix);
00108 
00110         void glcMultMatrix(const GLC_Matrix4x4& matrix);
00111 
00113         inline void glcTranslated(double x, double y, double z)
00114         {glcMultMatrix(GLC_Matrix4x4(x, y, z));}
00115 
00117         void glcScaled(double x, double y, double z);
00118 
00120         void glcOrtho(double left, double right, double bottom, double top, double nearVal, double farVal);
00121 
00123         void glcFrustum(double left, double right, double bottom, double top, double nearVal, double farVal);
00124 
00126         void glcEnableLighting(bool enable);
00127 
00129 
00130 
00132 
00133 public:
00134 
00136         virtual void makeCurrent();
00137 
00139         virtual void doneCurrent();
00140 
00142         inline void updateUniformVariables()
00143         {m_UniformShaderData.updateAll(this);}
00144 
00146 
00147 
00149 
00150 protected:
00152 
00153         virtual bool chooseContext(const QGLContext* shareContext= 0);
00155 
00157 
00159 
00160 private:
00162 
00164         void init();
00166 
00167 
00169 // Private members
00171 private:
00172 
00174         GLenum m_CurrentMatrixMode;
00175 
00177         QHash<GLenum, QStack<GLC_Matrix4x4>* > m_MatrixStackHash;
00178 
00180         QSharedPointer<GLC_ContextSharedData> m_ContextSharedData;
00181 
00183         GLC_UniformShaderData m_UniformShaderData;
00184 
00186         static GLC_Context* m_pCurrentContext;
00187 
00189         QStack<bool> m_LightingIsEnable;
00190 
00192         QHash<GLenum, bool> m_LightsEnableState;
00193 
00194 };
00195 
00196 #endif /* GLC_CONTEXT_H_ */

SourceForge.net Logo

©2005-2011 Laurent Ribon