Robotran C Documentation
OglShapeRenderer.hh
Go to the documentation of this file.
1 
7 #ifndef _OGL_SHAPE_RENDERER_HH_
8 #define _OGL_SHAPE_RENDERER_HH_
9 
10 #include "MbsShapeRenderer.hh"
11 #include "OglWorldRenderer.hh"
12 
13 #include <glm.hpp>
14 #include <vector>
15 
16 #include "Shader.hh"
17 
18 
19 namespace OpenGLMbs{
20 
21 
22 // forward declaration
23 class MbsWorld3D;
24 class MbsLight;
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
27 
31 {
32  public:
34  {
35  Clear();
36  }
37 
38  glm::vec4 pos;
39  glm::vec3 color;
40  glm::vec3 attenuation;
41  float ambientCoef;
42 
43  // specific to cones
44  float coneCosAngle;
45  glm::vec3 coneDir;
46 
47  // shadow
48  float shadowBias;
49 
50  MbsLight *light;
51 
53  void Clear()
54  {
55  pos = glm::vec4(0.0f);
56  color = glm::vec3(0.0f);
57  coneDir = glm::vec3(0.0f);
58  attenuation = glm::vec3(0.0f);
59 
60  ambientCoef = 0.0f;
61  coneCosAngle = 0.0f;
62 
63  shadowBias = 0.0f;
64 
65  light = NULL;
66  }
67 };
68 
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
71 
72 
77 {
78  public:
79 
81  OglShapeRenderer(std::string vertex_file, std::string fragment_file, MbsWorld3D* w, OglWorldRenderer *world_rend);
82  virtual ~OglShapeRenderer();
83 
86  virtual void Init(std::vector<glm::vec3> vertices,
87  std::vector<glm::vec3> colors,
88  std::vector<glm::vec3> normals,
89  std::vector<unsigned int> indexes);
90 
93  virtual void Update(glm::mat4 model_mat,
94  glm::mat4 MVP,
95  glm::mat3 M_inv_trans,
96  MbsWorld3D *world_3d,
97  float shiny_mat,
98  glm::vec3 const& specular_mat,
99  float transparency);
100 
101  virtual void ShadowDepth(int index);
102 
104  virtual void SetModelMat(glm::mat4 const& model_mat)
105  {
106  this->model_mat = model_mat;
107  }
108 
109  protected:
110 
111  glm::mat4 model_mat;
112 
114 
115  MbsWorld3D *world_3d;
117 
118  std::vector<ShaderLight> sh_lights;
119 
121 
122  Shader shader;
123  Shader *depth_shader;
124 
125  std::vector<GLuint> lightPosID;
126  std::vector<GLuint> lightColID;
127  std::vector<GLuint> lightAttID;
128  std::vector<GLuint> lightAmbID;
129  std::vector<GLuint> lightConAngID;
130  std::vector<GLuint> lightConDirID;
131 
132  GLuint mvpID;
133  GLuint modelMatID;
134  GLuint MInvTransID;
135 
136  glm::mat4 biasMatrix;
137 
138  std::vector<glm::mat4> mvpDepth;
139  std::vector<glm::mat4> depthBiasMVP;
140 
141  std::string depth_vert_sh;
142  std::string depth_frag_sh;
143 
144  //float transparency; //!< transparancy
145 
146  //float shiny_mat; //!< shiny material
147  //glm::vec3 specular_mat; //!< specular material
148 
149  bool light_init;
150 
151  GLuint VAO_id;
152  GLuint VBO_vertex_id;
153  GLuint VBO_color_id;
154  GLuint VBO_normal_id;
155  GLuint VBO_indexes_id;
156 
157  GLuint transID;
158  GLuint nbLightsID;
159  GLuint cameraID;
160  GLuint shininessID;
161  GLuint specularID;
162 
163  // shadow mapping
164  std::vector<GLuint> depthBiasID;
165  std::vector<GLuint> shadowMapID;
166  std::vector<GLuint> shadowBiasID;
167  std::vector<GLuint> spreadID;
168 
169  std::vector<GLuint> mvpDepthID;
170 
171  std::vector<GLuint> frameBuffer;
172  std::vector<GLuint> depthTexture;
173 
174  std::vector<int> depth_semi_x_width;
175  std::vector<int> depth_semi_y_width;
176 
177  std::vector<float> depth_ratio_width;
178 
179  // Lights function
180  void LightsInit(float shiny_mat, glm::vec3 const& specular_mat, float transparency);
181  void LightsUpdate();
182 
183  // utilities
184  std::string StringLoc(const char* fieldName, size_t index);
185  std::string StringLoc(const char* fieldName, const char* propertyName, size_t index);
186 
187  void MVPDepth(int index);
188 
189 
190 };
191 
192 } // close namespace
193 
194 #endif //_OGL_SHAPE_RENDERER_HH_
OpenGLMbs::OglShapeRenderer::VBO_indexes_id
GLuint VBO_indexes_id
VBO for indexes.
Definition: OglShapeRenderer.hh:155
MbsSpotLight.hh
MbsSpotLight class.
OpenGLMbs::OglShapeRenderer::StringLoc
std::string StringLoc(const char *fieldName, size_t index)
generate a string to get the location of a specific field (to communicate with fragment shader),...
Definition: OglShapeRenderer.cc:373
OpenGLMbs::OglShapeRenderer::sh_lights
std::vector< ShaderLight > sh_lights
shaders for lights
Definition: OglShapeRenderer.hh:118
OpenGLMbs::OglShapeRenderer::mvpDepthID
std::vector< GLuint > mvpDepthID
ID of the depth matrices MVP.
Definition: OglShapeRenderer.hh:169
OpenGLMbs::OglShapeRenderer
OglShapeRenderer class is an implementation of MbsShapeRenderer that render a MbsShape3D using Open G...
Definition: OglShapeRenderer.hh:76
OpenGLMbs::OglShapeRenderer::depth_frag_sh
std::string depth_frag_sh
fragment depth shader path
Definition: OglShapeRenderer.hh:142
OpenGLMbs
Definition: MpegFrameCaptureOptions.hh:6
OpenGLMbs::OglWorldRenderer
Implementation of MbsWorldRenderer class that render a MbsWorld3D using Open GL.
Definition: OglWorldRenderer.hh:26
OpenGLMbs::OglShapeRenderer::biasMatrix
glm::mat4 biasMatrix
bias matrix
Definition: OglShapeRenderer.hh:136
OpenGLMbs::OglShapeRenderer::Update
virtual void Update(glm::mat4 model_mat, glm::mat4 MVP, glm::mat3 M_inv_trans, MbsWorld3D *world_3d, float shiny_mat, glm::vec3 const &specular_mat, float transparency)
Execute the necessary code to render this shape: Update the Ogl transform and add it to the pipeline.
Definition: OglShapeRenderer.cc:520
OpenGLMbs::OglShapeRenderer::~OglShapeRenderer
virtual ~OglShapeRenderer()
destructor of the OglShapeRenderer
Definition: OglShapeRenderer.cc:78
OpenGLMbs::OglShapeRenderer::world_rend
OglWorldRenderer * world_rend
reference to the world renderer that creat this shape renderer
Definition: OglShapeRenderer.hh:116
OpenGLMbs::OglShapeRenderer::depth_semi_x_width
std::vector< int > depth_semi_x_width
X semi width of the shadow map depth textures (in pixels)
Definition: OglShapeRenderer.hh:174
OpenGLMbs::OglShapeRenderer::MVPDepth
void MVPDepth(int index)
update mvpDepth and depthBiasMVP (uniform matrices for shadow shaders)
Definition: OglShapeRenderer.cc:620
OpenGLMbs::OglShapeRenderer::mvpDepth
std::vector< glm::mat4 > mvpDepth
MVP depth matrix.
Definition: OglShapeRenderer.hh:138
OpenGLMbs::OglShapeRenderer::MInvTransID
GLuint MInvTransID
ID of transpose and inverse of the model matrix.
Definition: OglShapeRenderer.hh:134
OpenGLMbs::OglShapeRenderer::frameBuffer
std::vector< GLuint > frameBuffer
frame buffer
Definition: OglShapeRenderer.hh:171
MbsWorld3D.hh
MbsWorld3D class.
OpenGLMbs::OglShapeRenderer::depthBiasMVP
std::vector< glm::mat4 > depthBiasMVP
depth bias
Definition: OglShapeRenderer.hh:139
OpenGLMbs::OglShapeRenderer::transID
GLuint transID
ID of the transparency.
Definition: OglShapeRenderer.hh:157
OpenGLMbs::ShaderLight::attenuation
glm::vec3 attenuation
attenuation
Definition: OglShapeRenderer.hh:40
OpenGLMbs::ShaderLight::coneCosAngle
float coneCosAngle
cone opening angle
Definition: OglShapeRenderer.hh:44
OpenGLMbs::OglShapeRenderer::Init
virtual void Init(std::vector< glm::vec3 > vertices, std::vector< glm::vec3 > colors, std::vector< glm::vec3 > normals, std::vector< unsigned int > indexes)
Init the current shape renderer: create Ogl object necessary to represnet the shape.
Definition: OglShapeRenderer.cc:408
OpenGLMbs::OglShapeRenderer::shadowMapID
std::vector< GLuint > shadowMapID
ID of the shadow map.
Definition: OglShapeRenderer.hh:165
MbsPointLight.hh
MbsPointLight class.
OpenGLMbs::OglShapeRenderer::lightPosID
std::vector< GLuint > lightPosID
ID of the light position.
Definition: OglShapeRenderer.hh:125
OpenGLMbs::OglShapeRenderer::shader
Shader shader
main shader
Definition: OglShapeRenderer.hh:122
OpenGLMbs::OglShapeRenderer::lightAmbID
std::vector< GLuint > lightAmbID
ID of the light ambiance.
Definition: OglShapeRenderer.hh:128
OpenGLMbs::OglShapeRenderer::OglShapeRenderer
OglShapeRenderer(std::string vertex_file, std::string fragment_file, MbsWorld3D *w, OglWorldRenderer *world_rend)
Constructor.
Definition: OglShapeRenderer.cc:45
OpenGLMbs::ShaderLight::color
glm::vec3 color
light color
Definition: OglShapeRenderer.hh:39
OpenGLMbs::OglShapeRenderer::VBO_color_id
GLuint VBO_color_id
VBO for colors.
Definition: OglShapeRenderer.hh:153
OpenGLMbs::OglShapeRenderer::depthBiasID
std::vector< GLuint > depthBiasID
ID of the depth bias.
Definition: OglShapeRenderer.hh:164
OpenGLMbs::OglShapeRenderer::SetModelMat
virtual void SetModelMat(glm::mat4 const &model_mat)
set the model matrix
Definition: OglShapeRenderer.hh:104
MbsShapeRenderer.hh
MbsShapeRenderer class.
OpenGLMbs::OglShapeRenderer::lightConDirID
std::vector< GLuint > lightConDirID
ID of the light cone direction (for spots)
Definition: OglShapeRenderer.hh:130
OpenGLMbs::ShaderLight::shadowBias
float shadowBias
shadow bias
Definition: OglShapeRenderer.hh:48
MbsDirLight.hh
MbsDirLight class.
OpenGLMbs::OglShapeRenderer::depthTexture
std::vector< GLuint > depthTexture
depth textures
Definition: OglShapeRenderer.hh:172
OpenGLMbs::OglShapeRenderer::spreadID
std::vector< GLuint > spreadID
ID of the spread factor for Poisson disk.
Definition: OglShapeRenderer.hh:167
OpenGLMbs::OglShapeRenderer::shininessID
GLuint shininessID
ID of the shininess (shape material)
Definition: OglShapeRenderer.hh:160
OpenGLMbs::OglShapeRenderer::depth_semi_y_width
std::vector< int > depth_semi_y_width
X semi width of the shadow map depth textures (in pixels)
Definition: OglShapeRenderer.hh:175
OpenGLMbs::ShaderLight::coneDir
glm::vec3 coneDir
cone direction
Definition: OglShapeRenderer.hh:45
OpenGLMbs::OglShapeRenderer::world_3d
MbsWorld3D * world_3d
3D world
Definition: OglShapeRenderer.hh:115
OpenGLMbs::OglShapeRenderer::nb_indexes
int nb_indexes
size of the indexes vector
Definition: OglShapeRenderer.hh:113
Shader.hh
Shader class.
OpenGLMbs::OglShapeRenderer::light_init
bool light_init
flag to know if the ligth is initialized
Definition: OglShapeRenderer.hh:149
OpenGLMbs::OglShapeRenderer::lightConAngID
std::vector< GLuint > lightConAngID
ID of the light cone angle (for spots)
Definition: OglShapeRenderer.hh:129
OpenGLMbs::OglShapeRenderer::VBO_vertex_id
GLuint VBO_vertex_id
VBO for vertices.
Definition: OglShapeRenderer.hh:152
OglWorldRenderer.hh
OglShapeRenderer class and utilities.
OpenGLMbs::OglShapeRenderer::shadowBiasID
std::vector< GLuint > shadowBiasID
ID of the shadow bias.
Definition: OglShapeRenderer.hh:166
OpenGLMbs::MbsShapeRenderer
MbsShapeRenderer is an abstract class that defines the property need to render a MbsShape3D....
Definition: MbsShapeRenderer.hh:29
OpenGLMbs::OglShapeRenderer::lightAttID
std::vector< GLuint > lightAttID
ID of the light attenuation.
Definition: OglShapeRenderer.hh:127
OpenGLMbs::OglShapeRenderer::depth_shader
Shader * depth_shader
depth shader
Definition: OglShapeRenderer.hh:123
OpenGLMbs::OglShapeRenderer::modelMatID
GLuint modelMatID
ID of the model matrix.
Definition: OglShapeRenderer.hh:133
MbsLight.hh
MbsLight class.
OpenGLMbs::ShaderLight::ambientCoef
float ambientCoef
ambient coefficient
Definition: OglShapeRenderer.hh:41
OpenGLMbs::OglShapeRenderer::depth_ratio_width
std::vector< float > depth_ratio_width
ration between the X and Y width components of the depth texture
Definition: OglShapeRenderer.hh:177
OpenGLMbs::OglShapeRenderer::LightsInit
void LightsInit(float shiny_mat, glm::vec3 const &specular_mat, float transparency)
initalize the lights
Definition: OglShapeRenderer.cc:109
OpenGLMbs::OglShapeRenderer::depth_vert_sh
std::string depth_vert_sh
vertex depth shader path
Definition: OglShapeRenderer.hh:141
OpenGLMbs::ShaderLight::light
MbsLight * light
pointer to the related 'MbsLight' component
Definition: OglShapeRenderer.hh:50
OpenGLMbs::OglShapeRenderer::cameraID
GLuint cameraID
ID of the camera.
Definition: OglShapeRenderer.hh:159
OpenGLMbs::ShaderLight::ShaderLight
ShaderLight()
Definition: OglShapeRenderer.hh:33
OpenGLMbs::OglWorldRenderer::GetDepthXWidth
int GetDepthXWidth(int i) const
get the depth texture width along the X axis (in pixels)
Definition: OglWorldRenderer.hh:64
OpenGLMbs::OglShapeRenderer::LightsUpdate
void LightsUpdate()
update the lights
Definition: OglShapeRenderer.cc:314
OpenGLMbs::ShaderLight::Clear
void Clear()
clear the current light shader
Definition: OglShapeRenderer.hh:53
OpenGLMbs::OglWorldRenderer::GetDepthTexture
GLuint GetDepthTexture(int i) const
get a depth texture
Definition: OglWorldRenderer.hh:58
OpenGLMbs::OglShapeRenderer::nbLightsID
GLuint nbLightsID
ID of the number of lights.
Definition: OglShapeRenderer.hh:158
OpenGLMbs::OglWorldRenderer::GetFrameBuffer
GLuint GetFrameBuffer(int i) const
get a frame buffer
Definition: OglWorldRenderer.hh:61
OpenGLMbs::OglShapeRenderer::ShadowDepth
virtual void ShadowDepth(int index)
update of the shadow depth buffer
Definition: OglShapeRenderer.cc:697
OpenGLMbs::OglShapeRenderer::shader_flag
int shader_flag
flag for shaders
Definition: OglShapeRenderer.hh:120
OpenGLMbs::OglShapeRenderer::VAO_id
GLuint VAO_id
VAO.
Definition: OglShapeRenderer.hh:151
OpenGLMbs::ShaderLight
shader light class
Definition: OglShapeRenderer.hh:30
OpenGLMbs::OglShapeRenderer::specularID
GLuint specularID
ID of the specular value (shape material)
Definition: OglShapeRenderer.hh:161
OpenGLMbs::ShaderLight::pos
glm::vec4 pos
light position
Definition: OglShapeRenderer.hh:38
OpenGLMbs::OglWorldRenderer::GetDepthYWidth
int GetDepthYWidth(int i) const
get the depth texture width along the Y axis (in pixels)
Definition: OglWorldRenderer.hh:67
OpenGLMbs::OglShapeRenderer::lightColID
std::vector< GLuint > lightColID
ID of the light color.
Definition: OglShapeRenderer.hh:126
OpenGLMbs::OglWorldRenderer::GetNbDepthTextures
int GetNbDepthTextures() const
get the number of depth textures
Definition: OglWorldRenderer.hh:55
OpenGLMbs::OglShapeRenderer::mvpID
GLuint mvpID
ID of the MVP matrix.
Definition: OglShapeRenderer.hh:132
OpenGLMbs::OglShapeRenderer::VBO_normal_id
GLuint VBO_normal_id
VBO for normals.
Definition: OglShapeRenderer.hh:154
OglShapeRenderer.hh
OpenGLMbs::OglShapeRenderer::model_mat
glm::mat4 model_mat
model matrix ==> the same as the one stored in MbsShape3D
Definition: OglShapeRenderer.hh:111