[DEV] add light management with simple add of Material and Light classes==> can be better, but a good start

This commit is contained in:
Edouard DUPIN 2013-03-06 21:53:47 +01:00
parent a602665e10
commit 1c8ce9488c
12 changed files with 250 additions and 25 deletions

View File

@ -7,12 +7,13 @@ attribute vec3 EW_coord3d;
attribute vec2 EW_texture2d;
attribute vec3 EW_normal;
uniform mat4 EW_MatrixTransformation;
uniform mat4 EW_MatrixPosition;
// output :
varying vec2 f_texcoord;
void main(void) {
gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0);
gl_Position = EW_MatrixTransformation * EW_MatrixPosition * vec4(EW_coord3d, 1.0);
// set texture output coord
f_texcoord = EW_texture2d;
}

2
external/etk vendored

@ -1 +1 @@
Subproject commit b99cabc6932dd7a00d3a17a286ef8b62a0d9e57e
Subproject commit d51539f32a108eea88e017abad8cb604907dacbf

View File

@ -134,10 +134,10 @@ void ewol::Shaper::Draw(void)
// position :
m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, m_coord);
// all entry parameters :
m_GLprogram->Uniform2fv(m_GLPropertySize, 1, &m_propertySize.m_floats[0]);
m_GLprogram->Uniform2fv(m_GLPropertyOrigin, 1, &m_propertyOrigin.m_floats[0]);
m_GLprogram->Uniform2fv(m_GLPropertyInsidePos, 1, &m_propertyInsidePosition.m_floats[0]);
m_GLprogram->Uniform2fv(m_GLPropertyInsideSize, 1, &m_propertyInsideSize.m_floats[0]);
m_GLprogram->Uniform2(m_GLPropertySize, m_propertySize);
m_GLprogram->Uniform2(m_GLPropertyOrigin, m_propertyOrigin);
m_GLprogram->Uniform2(m_GLPropertyInsidePos, m_propertyInsidePosition);
m_GLprogram->Uniform2(m_GLPropertyInsideSize, m_propertyInsideSize);
m_GLprogram->Uniform1i(m_GLStateOld, m_stateOld);
m_GLprogram->Uniform1i(m_GLStateNew, m_stateNew);
m_GLprogram->Uniform1f(m_GLStateTransition, m_stateTransition);

View File

@ -0,0 +1,49 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/renderer/Light.h>
#include <ewol/debug.h>
ewol::Light::Light(void) :
m_direction(0,0,0),
m_halfplane(0,0,0),
m_ambientColor(0,0,0,0),
m_diffuseColor(0,0,0,0),
m_specularColor(0,0,0,0),
m_GL_direction(0),
m_GL_halfplane(0),
m_GL_ambientColor(0),
m_GL_diffuseColor(0),
m_GL_specularColor(0)
{
// nothing to do else ...
}
ewol::Light::~Light(void)
{
}
void ewol::Light::Link(ewol::Program* prog, const etk::UString& baseName)
{
m_GL_direction = prog->GetUniform(baseName+".direction");
m_GL_halfplane = prog->GetUniform(baseName+".halfplane");
m_GL_ambientColor = prog->GetUniform(baseName+".ambientColor");
m_GL_diffuseColor = prog->GetUniform(baseName+".diffuseColor");
m_GL_specularColor = prog->GetUniform(baseName+".specularColor");
}
void ewol::Light::Draw(ewol::Program* prog)
{
prog->Uniform3(m_GL_direction, m_direction);
prog->Uniform3(m_GL_halfplane, m_halfplane);
prog->Uniform4(m_GL_ambientColor, m_ambientColor);
prog->Uniform4(m_GL_diffuseColor, m_diffuseColor);
prog->Uniform4(m_GL_specularColor, m_specularColor);
}

View File

@ -0,0 +1,60 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_LIGHT_H__
#define __EWOL_LIGHT_H__
#include <etk/types.h>
#include <etk/math/Vector3D.h>
#include <etk/math/Vector4D.h>
#include <ewol/renderer/resources/Program.h>
namespace ewol
{
class Light
{
private:
// values
vec3 m_direction;
vec3 m_halfplane;
vec4 m_ambientColor;
vec4 m_diffuseColor;
vec4 m_specularColor;
private:
// GL index
int32_t m_GL_direction;
int32_t m_GL_halfplane;
int32_t m_GL_ambientColor;
int32_t m_GL_diffuseColor;
int32_t m_GL_specularColor;
public:
Light(void);
~Light(void);
void Link(ewol::Program* prog, const etk::UString& baseName);
void Draw(ewol::Program* prog);
void SetDirection(const vec3& val) {
m_direction = val;
}
void SetHalfPlane(const vec3& val) {
m_halfplane = val;
}
void SetAmbientColor(const vec4& val) {
m_ambientColor = val;
}
void SetDiffuseColor(const vec4& val) {
m_diffuseColor = val;
}
void SetSpecularColor(const vec4& val) {
m_specularColor = val;
}
};
};
#endif

View File

@ -0,0 +1,46 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/renderer/Material.h>
#include <ewol/debug.h>
ewol::Material::Material(void) :
m_ambientFactor(0,0,0,0),
m_diffuseFactor(0,0,0,0),
m_specularFactor(0,0,0,0),
m_shininess(0),
m_GL_ambientFactor(0),
m_GL_diffuseFactor(0),
m_GL_specularFactor(0),
m_GL_shininess(0)
{
// nothing to do else ...
}
ewol::Material::~Material(void)
{
}
void ewol::Material::Link(ewol::Program* prog, const etk::UString& baseName)
{
m_GL_ambientFactor = prog->GetUniform(baseName+".ambientFactor");
m_GL_diffuseFactor = prog->GetUniform(baseName+".diffuseFactor");
m_GL_specularFactor = prog->GetUniform(baseName+".specularFactor");
m_GL_shininess = prog->GetUniform(baseName+".shininess");
}
void ewol::Material::Draw(ewol::Program* prog)
{
prog->Uniform4(m_GL_ambientFactor, m_ambientFactor);
prog->Uniform4(m_GL_diffuseFactor, m_diffuseFactor);
prog->Uniform4(m_GL_specularFactor, m_specularFactor);
prog->Uniform1f(m_GL_shininess, m_shininess);
}

View File

@ -0,0 +1,55 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_MATERIAL_H__
#define __EWOL_MATERIAL_H__
#include <etk/types.h>
#include <etk/math/Vector3D.h>
#include <etk/math/Vector4D.h>
#include <ewol/renderer/resources/Program.h>
namespace ewol
{
class Material
{
private:
// values
vec4 m_ambientFactor;
vec4 m_diffuseFactor;
vec4 m_specularFactor;
float m_shininess;
private:
// GL index
int32_t m_GL_ambientFactor;
int32_t m_GL_diffuseFactor;
int32_t m_GL_specularFactor;
int32_t m_GL_shininess;
public:
Material(void);
~Material(void);
void Link(ewol::Program* prog, const etk::UString& baseName);
void Draw(ewol::Program* prog);
void SetAmbientFactor(const vec4& val) {
m_ambientFactor = val;
}
void SetDiffuseFactor(const vec4& val) {
m_diffuseFactor = val;
}
void SetSpecularFactor(const vec4& val) {
m_specularFactor = val;
}
void SetShininess(float val) {
m_shininess = val;
}
};
};
#endif

View File

@ -71,7 +71,8 @@ ewol::Mesh::Mesh(etk::UString genName, etk::UString shaderName) :
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLNormal = m_GLprogram->GetAttribute("EW_normal");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLMatrixPosition = m_GLprogram->GetUniform("EW_MatrixPosition");
m_GLtexID0 = m_GLprogram->GetUniform("EW_texID");
}
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer
@ -109,8 +110,9 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
// set Matrix : translation/positionMatrix
mat4 projMatrix = ewol::openGL::GetMatrix();
mat4 camMatrix = ewol::openGL::GetCameraMatrix();
mat4 tmpMatrix = projMatrix * camMatrix * positionMatrix;
mat4 tmpMatrix = projMatrix * camMatrix;
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
m_GLprogram->UniformMatrix4fv(m_GLMatrixPosition, 1, positionMatrix.m_mat);
// TextureID
m_GLprogram->SetTexture0(m_GLtexID0, m_texture0->GetId());
// position :

View File

@ -72,6 +72,7 @@ namespace ewol
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLMatrixPosition;
int32_t m_GLNormal;
int32_t m_GLtexture;
int32_t m_GLtexID0;

View File

@ -477,7 +477,7 @@ void ewol::Program::Uniform4i(int32_t idElem, int32_t value1, int32_t value2, in
//////////////////////////////////////////////////////////////////////////////////////////////
void ewol::Program::Uniform1fv(int32_t idElem, int32_t nbElement, float *value)
void ewol::Program::Uniform1fv(int32_t idElem, int32_t nbElement, const float *value)
{
if (0==m_program) {
return;
@ -500,7 +500,7 @@ void ewol::Program::Uniform1fv(int32_t idElem, int32_t nbElement, float *value)
glUniform1fv(m_elementList[idElem].m_elementId, nbElement, value);
//checkGlError("glUniform1fv", __LINE__);
}
void ewol::Program::Uniform2fv(int32_t idElem, int32_t nbElement, float *value)
void ewol::Program::Uniform2fv(int32_t idElem, int32_t nbElement, const float *value)
{
if (0==m_program) {
return;
@ -523,7 +523,7 @@ void ewol::Program::Uniform2fv(int32_t idElem, int32_t nbElement, float *value)
glUniform2fv(m_elementList[idElem].m_elementId, nbElement, value);
//checkGlError("glUniform2fv", __LINE__);
}
void ewol::Program::Uniform3fv(int32_t idElem, int32_t nbElement, float *value)
void ewol::Program::Uniform3fv(int32_t idElem, int32_t nbElement, const float *value)
{
if (0==m_program) {
return;
@ -546,7 +546,7 @@ void ewol::Program::Uniform3fv(int32_t idElem, int32_t nbElement, float *value)
glUniform3fv(m_elementList[idElem].m_elementId, nbElement, value);
//checkGlError("glUniform3fv", __LINE__);
}
void ewol::Program::Uniform4fv(int32_t idElem, int32_t nbElement, float *value)
void ewol::Program::Uniform4fv(int32_t idElem, int32_t nbElement, const float *value)
{
if (0==m_program) {
return;
@ -572,7 +572,7 @@ void ewol::Program::Uniform4fv(int32_t idElem, int32_t nbElement, float *value)
//////////////////////////////////////////////////////////////////////////////////////////////
void ewol::Program::Uniform1iv(int32_t idElem, int32_t nbElement, int32_t *value)
void ewol::Program::Uniform1iv(int32_t idElem, int32_t nbElement, const int32_t *value)
{
if (0==m_program) {
return;
@ -595,7 +595,7 @@ void ewol::Program::Uniform1iv(int32_t idElem, int32_t nbElement, int32_t *value
glUniform1iv(m_elementList[idElem].m_elementId, nbElement, value);
//checkGlError("glUniform1iv", __LINE__);
}
void ewol::Program::Uniform2iv(int32_t idElem, int32_t nbElement, int32_t *value)
void ewol::Program::Uniform2iv(int32_t idElem, int32_t nbElement, const int32_t *value)
{
if (0==m_program) {
return;
@ -618,7 +618,7 @@ void ewol::Program::Uniform2iv(int32_t idElem, int32_t nbElement, int32_t *value
glUniform2iv(m_elementList[idElem].m_elementId, nbElement, value);
//checkGlError("glUniform2iv", __LINE__);
}
void ewol::Program::Uniform3iv(int32_t idElem, int32_t nbElement, int32_t *value)
void ewol::Program::Uniform3iv(int32_t idElem, int32_t nbElement, const int32_t *value)
{
if (0==m_program) {
return;
@ -641,7 +641,7 @@ void ewol::Program::Uniform3iv(int32_t idElem, int32_t nbElement, int32_t *value
glUniform3iv(m_elementList[idElem].m_elementId, nbElement, value);
//checkGlError("glUniform3iv", __LINE__);
}
void ewol::Program::Uniform4iv(int32_t idElem, int32_t nbElement, int32_t *value)
void ewol::Program::Uniform4iv(int32_t idElem, int32_t nbElement, const int32_t *value)
{
if (0==m_program) {
return;
@ -666,6 +666,7 @@ void ewol::Program::Uniform4iv(int32_t idElem, int32_t nbElement, int32_t *value
}
//////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -10,6 +10,7 @@
#define __OPEN_GL__PROGRAM_H__
#include <etk/types.h>
#include <etk/math/Vector4D.h>
#include <ewol/debug.h>
#include <ewol/renderer/openGL.h>
#include <ewol/renderer/resources/Resource.h>
@ -175,28 +176,28 @@ namespace ewol
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform1fv(int32_t idElem, int32_t nbElement, float *value);
void Uniform1fv(int32_t idElem, int32_t nbElement, const float *value);
/**
* @brief Send "vec2" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform2fv(int32_t idElem, int32_t nbElement, float *value);
void Uniform2fv(int32_t idElem, int32_t nbElement, const float *value);
/**
* @brief Send "vec3" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform3fv(int32_t idElem, int32_t nbElement, float *value);
void Uniform3fv(int32_t idElem, int32_t nbElement, const float *value);
/**
* @brief Send "vec4" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform4fv(int32_t idElem, int32_t nbElement, float *value);
void Uniform4fv(int32_t idElem, int32_t nbElement, const float *value);
/**
* @brief Send "ivec1" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
@ -204,28 +205,35 @@ namespace ewol
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform1iv(int32_t idElem, int32_t nbElement, int32_t *value);
void Uniform1iv(int32_t idElem, int32_t nbElement, const int32_t *value);
/**
* @brief Send "ivec2" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the Attribute that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform2iv(int32_t idElem, int32_t nbElement, int32_t *value);
void Uniform2iv(int32_t idElem, int32_t nbElement, const int32_t *value);
/**
* @brief Send "ivec3" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform3iv(int32_t idElem, int32_t nbElement, int32_t *value);
void Uniform3iv(int32_t idElem, int32_t nbElement, const int32_t *value);
/**
* @brief Send "ivec4" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform4iv(int32_t idElem, int32_t nbElement, int32_t *value);
void Uniform4iv(int32_t idElem, int32_t nbElement, const int32_t *value);
inline void Uniform2(int32_t idElem, const vec2& value) { Uniform2fv(idElem, 1, &value.m_floats[0]); };
inline void Uniform3(int32_t idElem, const vec3& value) { Uniform3fv(idElem, 1, &value.m_floats[0]); };
inline void Uniform4(int32_t idElem, const vec4& value) { Uniform4fv(idElem, 1, &value.m_floats[0]); };
inline void Uniform2(int32_t idElem, const ivec2& value){ Uniform2iv(idElem, 1, &value.m_floats[0]); };
inline void Uniform3(int32_t idElem, const ivec3& value){ Uniform3iv(idElem, 1, &value.m_floats[0]); };
inline void Uniform4(int32_t idElem, const ivec4& value){ Uniform4iv(idElem, 1, &value.m_floats[0]); };
/**
* @brief Request the processing of this program

View File

@ -13,7 +13,9 @@ FILE_LIST+= ewol/eObject/EObject.cpp \
ewol/eObject/EObjectManager.cpp
#openGl Basic access abstraction (for the model matrix and include
FILE_LIST+= ewol/renderer/openGL.cpp
FILE_LIST+= ewol/renderer/openGL.cpp \
ewol/renderer/Light.cpp \
ewol/renderer/Material.cpp
# Operating System interface
FILE_LIST+= ewol/renderer/os/eSystem.cpp \