shaderPhong.h 3.65 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
25 26
#ifndef __CGOGN_SHADER_PHONG__
#define __CGOGN_SHADER_PHONG__
Pierre Kraemer's avatar
Pierre Kraemer committed
27

Sylvain Thery's avatar
Sylvain Thery committed
28
#include "Utils/GLSLShader.h"
Sylvain Thery's avatar
Sylvain Thery committed
29
#include "Geometry/vector_gen.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30

Sylvain Thery's avatar
Sylvain Thery committed
31
#include <string>
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33 34

namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
35

Sylvain Thery's avatar
Sylvain Thery committed
36
namespace Utils
Pierre Kraemer's avatar
Pierre Kraemer committed
37 38
{

Sylvain Thery's avatar
Sylvain Thery committed
39
class ShaderPhong : public GLSLShader
Pierre Kraemer's avatar
Pierre Kraemer committed
40
{
Sylvain Thery's avatar
Sylvain Thery committed
41 42 43
protected:
	// flag color per vertex or not
	bool m_with_color;
Pierre Kraemer's avatar
Pierre Kraemer committed
44

Sylvain Thery's avatar
Sylvain Thery committed
45 46 47
	// shader sources OGL3
    static std::string vertexShaderText;
    static std::string fragmentShaderText;
Pierre Kraemer's avatar
Pierre Kraemer committed
48

Sylvain Thery's avatar
Sylvain Thery committed
49 50 51 52 53 54
    // uniform locations
	GLuint m_unif_ambiant;
	GLuint m_unif_diffuse;
	GLuint m_unif_specular;
	GLuint m_unif_shininess;
	GLuint m_unif_lightPos;
Pierre Kraemer's avatar
Pierre Kraemer committed
55

Sylvain Thery's avatar
Sylvain Thery committed
56 57 58 59 60 61
	//values
	Geom::Vec4f m_ambiant;
	Geom::Vec4f m_diffuse;
	Geom::Vec4f m_specular;
	float m_shininess;
	Geom::Vec3f m_lightPos;
Pierre Kraemer's avatar
Pierre Kraemer committed
62

63 64 65 66
	VBO* m_vboPos;
	VBO* m_vboNormal;
	VBO* m_vboColor;

Sylvain Thery's avatar
Sylvain Thery committed
67 68 69
	void getLocations();

	void sendParams();
Pierre Kraemer's avatar
Pierre Kraemer committed
70

71 72
	void restoreUniformsAttribs();

Pierre Kraemer's avatar
Pierre Kraemer committed
73
public:
Sylvain Thery's avatar
Sylvain Thery committed
74
	ShaderPhong();
Pierre Kraemer's avatar
Pierre Kraemer committed
75

Sylvain Thery's avatar
Sylvain Thery committed
76 77
	// inviduals parameter setting functions
	void setAmbiant(const Geom::Vec4f& ambiant);
Pierre Kraemer's avatar
Pierre Kraemer committed
78

Sylvain Thery's avatar
Sylvain Thery committed
79
	void setDiffuse(const Geom::Vec4f& diffuse);
Pierre Kraemer's avatar
Pierre Kraemer committed
80

Sylvain Thery's avatar
Sylvain Thery committed
81 82 83 84
	void setSpecular(const Geom::Vec4f& specular);

	void setShininess(float shininess);

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
85
	void setLightPosition(Geom::Vec3f lp);
Sylvain Thery's avatar
Sylvain Thery committed
86

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
87
	const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
Pierre Kraemer's avatar
Pierre Kraemer committed
88

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
89
	const Geom::Vec4f& getDiffuse() const { return m_diffuse; }
Pierre Kraemer's avatar
Pierre Kraemer committed
90

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
91
	const Geom::Vec4f& getSpecular() const { return m_specular; }
Pierre Kraemer's avatar
Pierre Kraemer committed
92

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
93
	float getShininess() const { return m_shininess; }
Pierre Kraemer's avatar
Pierre Kraemer committed
94

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
95
	const Geom::Vec3f& getLightPosition() const { return m_lightPos; }
Pierre Kraemer's avatar
Pierre Kraemer committed
96

Sylvain Thery's avatar
Sylvain Thery committed
97 98 99 100 101 102
	/**
	 * set all parameter in on call (one bind also)
	 */
	void setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos);

	// attributes
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
103
	unsigned int setAttributePosition(VBO* vbo);
104

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
105
	unsigned int setAttributeNormal(VBO* vbo);
Sylvain Thery's avatar
Sylvain Thery committed
106

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
107 108
	// optional attributes
	unsigned int setAttributeColor(VBO* vbo);
Sylvain Thery's avatar
Sylvain Thery committed
109 110
	void unsetAttributeColor();
};
Pierre Kraemer's avatar
Pierre Kraemer committed
111

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
112 113 114 115
} // namespace Utils

} // namespace CGoGN

Pierre Kraemer's avatar
Pierre Kraemer committed
116
#endif