glc_uniformshaderdata.cpp

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 #include <QtDebug>
00025 
00026 #include "shading/glc_shader.h"
00027 #include "glc_context.h"
00028 #include "glc_uniformshaderdata.h"
00029 
00030 
00031 GLC_UniformShaderData::GLC_UniformShaderData()
00032 {
00033 
00034 
00035 }
00036 
00037 GLC_UniformShaderData::~GLC_UniformShaderData()
00038 {
00039 
00040 }
00041 
00043 // Set Functions
00045 void GLC_UniformShaderData::setLightValues(const GLC_Light& light)
00046 {
00047 
00048 }
00049 
00050 void GLC_UniformShaderData::setLightingState(bool enable)
00051 {
00052         GLC_Shader* pCurrentShader= GLC_Shader::currentShaderHandle();
00053         pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->enableLightingId(), enable);
00054 }
00055 
00056 void GLC_UniformShaderData::setModelViewProjectionMatrix(const GLC_Matrix4x4& modelView, const GLC_Matrix4x4& projection)
00057 {
00058         // Set model view matrix
00059         const double* pMvmatrixData= modelView.getData();
00060         GLfloat mvFloatMatrix[4][4];
00061         GLfloat* pData= &(mvFloatMatrix[0][0]);
00062         for (int i= 0; i < 16; ++i)
00063         {
00064                 pData[i]= static_cast<GLfloat>(pMvmatrixData[i]);
00065         }
00066 
00067         // Set model view projection matrix
00068         GLC_Matrix4x4 modelViewProjectionMatrix= projection * modelView;
00069         const double* pMvpmatrixData= modelViewProjectionMatrix.getData();
00070         GLfloat mvpFloatMatrix[4][4];
00071         pData= &(mvpFloatMatrix[0][0]);
00072         for (int i= 0; i < 16; ++i)
00073         {
00074                 pData[i]= static_cast<GLfloat>(pMvpmatrixData[i]);
00075         }
00076 
00077         // Set the transpose of inv model view matrix (For normal computation)
00078         GLC_Matrix4x4 invTransposeModelView= modelView.inverted();
00079         invTransposeModelView.transpose();
00080         GLfloat invTmdv[3][3];
00081         {
00082                 const double* data= invTransposeModelView.getData();
00083 
00084                 invTmdv[0][0]= static_cast<GLfloat>(data[0]); invTmdv[1][0]= static_cast<GLfloat>(data[4]); invTmdv[2][0]= static_cast<GLfloat>(data[8]);
00085                 invTmdv[0][1]= static_cast<GLfloat>(data[1]); invTmdv[1][1]= static_cast<GLfloat>(data[5]); invTmdv[2][1]= static_cast<GLfloat>(data[9]);
00086                 invTmdv[0][2]= static_cast<GLfloat>(data[2]); invTmdv[1][2]= static_cast<GLfloat>(data[6]); invTmdv[2][2]= static_cast<GLfloat>(data[10]);
00087         }
00088 
00089         Q_ASSERT(GLC_Shader::hasActiveShader());
00090 
00091         GLC_Shader* pCurrentShader= GLC_Shader::currentShaderHandle();
00092         pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->modelViewLocationId(), mvFloatMatrix);
00093         pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->mvpLocationId(), mvpFloatMatrix);
00094         pCurrentShader->programShaderHandle()->setUniformValue(pCurrentShader->invModelViewLocationId(), invTmdv);
00095 }
00096 
00097 void GLC_UniformShaderData::updateAll(const GLC_Context* pContext)
00098 {
00099         setModelViewProjectionMatrix(pContext->modelViewMatrix(), pContext->projectionMatrix());
00100         setLightingState(pContext->lightingIsEnable());
00101 }

SourceForge.net Logo

©2005-2011 Laurent Ribon