shaderPhong.h 3.59 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                                        *
*                                                                              *
*******************************************************************************/

Sylvain Thery's avatar
Sylvain Thery 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
29
#include "Utils/GLSLShader3.h"
#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
{
Sylvain Thery's avatar
Sylvain Thery committed
35
namespace Utils
Pierre Kraemer's avatar
Pierre Kraemer committed
36
37
{

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

Sylvain Thery's avatar
Sylvain Thery committed
44
45
46
	// shader sources OGL3
    static std::string vertexShaderText;
    static std::string fragmentShaderText;
Pierre Kraemer's avatar
Pierre Kraemer committed
47
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

Sylvain Thery's avatar
Sylvain Thery committed
63
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
64

Sylvain Thery's avatar
Sylvain Thery committed
65
66
67
	void getLocations();

	void sendParams();
Pierre Kraemer's avatar
Pierre Kraemer committed
68
69

public:
Sylvain Thery's avatar
Sylvain Thery committed
70
	ShaderPhong();
Pierre Kraemer's avatar
Pierre Kraemer committed
71

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

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

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

	void setShininess(float shininess);

	void setLightPosition( Geom::Vec3f lp);

	const Geom::Vec4f& getAmbiant() const { return m_ambiant;}
Pierre Kraemer's avatar
Pierre Kraemer committed
84

Sylvain Thery's avatar
Sylvain Thery committed
85
	const Geom::Vec4f& getDiffuse() const { return m_diffuse;}
Pierre Kraemer's avatar
Pierre Kraemer committed
86

Sylvain Thery's avatar
Sylvain Thery committed
87
	const Geom::Vec4f& getSpecular() const { return m_specular;}
Pierre Kraemer's avatar
Pierre Kraemer committed
88

Sylvain Thery's avatar
Sylvain Thery committed
89
	float getShininess() const { return m_shininess;}
Pierre Kraemer's avatar
Pierre Kraemer committed
90

Sylvain Thery's avatar
Sylvain Thery committed
91
	const Geom::Vec3f& getLightPosition() const { return m_lightPos;}
Pierre Kraemer's avatar
Pierre Kraemer committed
92

Sylvain Thery's avatar
Sylvain Thery committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
	/**
	 * 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
	void setAttributePosition(VBO& vbo)		{this->bindVA_VBO("VertexPosition", vbo);}
	void setAttributeNormal(VBO& vbo)		{this->bindVA_VBO("VertexNormal", vbo);}

	// optionnal attributes
	void setAttributeColor(VBO& vbo);
	void unsetAttributeColor();
};
Pierre Kraemer's avatar
Pierre Kraemer committed
107

Sylvain Thery's avatar
Sylvain Thery committed
108
109
}
}
Pierre Kraemer's avatar
Pierre Kraemer committed
110
#endif