GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_uniformshaderdata.cpp
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 #include <QtDebug>
25 
26 #include "shading/glc_shader.h"
27 #include "glc_context.h"
28 #include "glc_uniformshaderdata.h"
29 
30 
32 {
33 
34 
35 }
36 
38 {
39 
40 }
41 
43 // Set Functions
46 {
47 
48 }
49 
51 {
53  pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->enableLightingId(), enable);
54 }
55 
57 {
58  // Set model view matrix
59  const double* pMvmatrixData= modelView.getData();
60  GLfloat mvFloatMatrix[4][4];
61  GLfloat* pData= &(mvFloatMatrix[0][0]);
62  for (int i= 0; i < 16; ++i)
63  {
64  pData[i]= static_cast<GLfloat>(pMvmatrixData[i]);
65  }
66 
67  // Set model view projection matrix
68  GLC_Matrix4x4 modelViewProjectionMatrix= projection * modelView;
69  const double* pMvpmatrixData= modelViewProjectionMatrix.getData();
70  GLfloat mvpFloatMatrix[4][4];
71  pData= &(mvpFloatMatrix[0][0]);
72  for (int i= 0; i < 16; ++i)
73  {
74  pData[i]= static_cast<GLfloat>(pMvpmatrixData[i]);
75  }
76 
77  // Set the transpose of inv model view matrix (For normal computation)
78  GLC_Matrix4x4 invTransposeModelView= modelView.inverted();
79  invTransposeModelView.transpose();
80  GLfloat invTmdv[3][3];
81  {
82  const double* data= invTransposeModelView.getData();
83 
84  invTmdv[0][0]= static_cast<GLfloat>(data[0]); invTmdv[1][0]= static_cast<GLfloat>(data[4]); invTmdv[2][0]= static_cast<GLfloat>(data[8]);
85  invTmdv[0][1]= static_cast<GLfloat>(data[1]); invTmdv[1][1]= static_cast<GLfloat>(data[5]); invTmdv[2][1]= static_cast<GLfloat>(data[9]);
86  invTmdv[0][2]= static_cast<GLfloat>(data[2]); invTmdv[1][2]= static_cast<GLfloat>(data[6]); invTmdv[2][2]= static_cast<GLfloat>(data[10]);
87  }
88 
89  Q_ASSERT(GLC_Shader::hasActiveShader());
90 
92  pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->modelViewLocationId(), mvFloatMatrix);
93  pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->mvpLocationId(), mvpFloatMatrix);
94  pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->invModelViewLocationId(), invTmdv);
95 }
96 
98 {
100  setLightingState(pContext->lightingIsEnable());
101 }

©2005-2013 Laurent Ribon