text: /*
  
  	Copyright 2011 Etay Meiri
  
      This program is free software: you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.
  
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
  
      You should have received a copy of the GNU General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  
  #include <limits.h>
  #include <string.h>
  
  #include "ds_light_pass_tech.h"
  #include "ogldev_util.h"
  
  
  DSLightPassTech::DSLightPassTech()
  {   
  }
  
  bool DSLightPassTech::Init()
  {
      m_WVPLocation = GetUniformLocation("gWVP");
  	m_posTextureUnitLocation = GetUniformLocation("gPositionMap");
  	m_colorTextureUnitLocation = GetUniformLocation("gColorMap");
  	m_normalTextureUnitLocation = GetUniformLocation("gNormalMap");
      m_eyeWorldPosLocation = GetUniformLocation("gEyeWorldPos");
      m_matSpecularIntensityLocation = GetUniformLocation("gMatSpecularIntensity");
      m_matSpecularPowerLocation = GetUniformLocation("gSpecularPower");
      m_screenSizeLocation = GetUniformLocation("gScreenSize");
  
  	if (m_WVPLocation == INVALID_UNIFORM_LOCATION ||
          m_posTextureUnitLocation == INVALID_UNIFORM_LOCATION ||
          m_colorTextureUnitLocation == INVALID_UNIFORM_LOCATION ||
  		m_normalTextureUnitLocation == INVALID_UNIFORM_LOCATION ||
          m_eyeWorldPosLocation == INVALID_UNIFORM_LOCATION ||
          m_matSpecularIntensityLocation == INVALID_UNIFORM_LOCATION ||
          m_matSpecularPowerLocation == INVALID_UNIFORM_LOCATION ||
          m_screenSizeLocation == INVALID_UNIFORM_LOCATION) {
          return false;
      }
  
  	return true;
  }
  
  
  void DSLightPassTech::SetWVP(const Matrix4f& WVP)
  {
      glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, (const GLfloat*)WVP.m);    
  }
  
  
  void DSLightPassTech::SetPositionTextureUnit(unsigned int TextureUnit)
  {
      glUniform1i(m_posTextureUnitLocation, TextureUnit);
  }
  
  
  void DSLightPassTech::SetColorTextureUnit(unsigned int TextureUnit)
  {
      glUniform1i(m_colorTextureUnitLocation, TextureUnit);
  }
  
  
  void DSLightPassTech::SetNormalTextureUnit(unsigned int TextureUnit)
  {
      glUniform1i(m_normalTextureUnitLocation, TextureUnit);
  }
  
  
  void DSLightPassTech::SetEyeWorldPos(const Vector3f& EyePos)
  {
  	glUniform3f(m_eyeWorldPosLocation, EyePos.x, EyePos.y, EyePos.z);
  }
  
  
  void DSLightPassTech::SetScreenSize(unsigned int Width, unsigned int Height)
  {
      glUniform2f(m_screenSizeLocation, (float)Width, (float)Height);
  }