Lagrangian Liquid Simulation
Master Thesis project on simulation of liquids using Lagrangian approach and SPH
|
liase with ngl::ShaderLib to provide higher level access and manipulation to/from shaders More...
#include <ShaderLibrary.h>
Public Member Functions | |
ShaderLibrary () | |
ctor | |
~ShaderLibrary () | |
dtor | |
void | updateView (ngl::Camera *_cam) |
update the view matrix of the shaders | |
void | updateProjection (ngl::Camera *_cam) |
update the projection matrix of the shaders | |
void | updateViewProjection (ngl::Camera *_cam) |
update the view and projection matrices of the shaders | |
void | updateModel (const ngl::Matrix _matrix) |
update the model matrix of the shaders | |
void | updateModel (const std::string _name, const ngl::Matrix _matrix, const bool _exclusive=true) |
update the model matrix of a specific shader | |
void | updateColor (const std::string _name, const ngl::Colour _colour, const bool _exclusive=true) |
update the colour parameter of a specific shader | |
void | updateModelColor (const std::string _name, const ngl::Matrix _matrix, const ngl::Colour _colour, const bool _reset=true, const bool _exclusive=true) |
update the colour and model parameters of the shaders | |
void | useShader (const std::string _name) |
select a particular shader in the library as active | |
Private Attributes | |
ngl::ShaderManager * | m_shaders |
the list of shaders | |
std::vector< std::string > | m_names |
the list of shader names |
liase with ngl::ShaderLib to provide higher level access and manipulation to/from shaders
Definition at line 18 of file ShaderLibrary.h.
ShaderLibrary::ShaderLibrary | ( | ) |
ctor
Definition at line 14 of file ShaderLibrary.cpp.
References ShaderObject::getAttributes(), ShaderObject::getAttributeValues(), ShaderObject::getFragementFile(), ShaderObject::getIsSpecial(), ShaderObject::getShaderName(), ShaderObject::getVertexFile(), Configuration::initialiseShader(), m_names, and m_shaders.
{ //get an instance of the shader manager m_shaders = ngl::ShaderManager::instance(); //read values from settings file std::vector<ShaderObject*>* myShaders = Configuration::initialiseShader(); //load list of shaders BOOST_FOREACH(ShaderObject* item, *myShaders) { //save shader name m_names.push_back(item->getShaderName()); if (!item->getIsSpecial()) { //normal shader loading m_shaders->loadShader(item->getShaderName(), item->getVertexFile(), item->getFragementFile()); } else { //special shader loading with attributes std::string vertexName = item->getShaderName() + "Vertex"; std::string fragmentName = item->getShaderName() + "Fragment"; m_shaders->createShaderProgram(item->getShaderName()); m_shaders->attachShader(vertexName, ngl::VERTEX); m_shaders->attachShader(fragmentName, ngl::FRAGMENT); m_shaders->loadShaderSource(vertexName, item->getVertexFile()); m_shaders->loadShaderSource(fragmentName, item->getFragementFile()); m_shaders->compileShader(vertexName); m_shaders->compileShader(fragmentName); m_shaders->attachShaderToProgram(item->getShaderName(), vertexName); m_shaders->attachShaderToProgram(item->getShaderName(), fragmentName); for (int i = 0; i < item->getAttributes().size(); i++) { m_shaders->bindAttribute(item->getShaderName(), item->getAttributeValues()[i], item->getAttributes()[i]); } m_shaders->linkProgramObject(item->getShaderName()); } } //deleting shaders pointers for (int i = 0; i < myShaders->size(); i++) delete (*myShaders)[i]; myShaders->clear(); delete myShaders; }
ShaderLibrary::~ShaderLibrary | ( | ) | [inline] |
dtor
Definition at line 25 of file ShaderLibrary.h.
{ std::cout << "Shader Library deleted\n" << std::endl; }
void ShaderLibrary::updateColor | ( | const std::string | _name, |
const ngl::Colour | _colour, | ||
const bool | _exclusive = true |
||
) |
update the colour parameter of a specific shader
[in] | _name | the name of the shader to update |
[in] | _colour | the colour to set |
[in] | _exclusive | flag to determine whether this method is called on its own |
Definition at line 128 of file ShaderLibrary.cpp.
{ if (_exclusive) { //called entirely on its own and not part of a chain of commands //flush the shader states glFlush(); //enable the shader m_shaders->useShader(_name); } //set the colour param to the shader m_shaders->setShaderParam4f(_name, "inColor", _colour.m_r, _colour.m_g, _colour.m_b, _colour.m_a); }
void ShaderLibrary::updateModel | ( | const std::string | _name, |
const ngl::Matrix | _matrix, | ||
const bool | _exclusive = true |
||
) |
update the model matrix of a specific shader
[in] | _name | the name of the shader to update |
[in] | _matrix | the model matrix to set to the shader |
[in] | _exclusive | flag to determine whether this method is called on its own |
Definition at line 109 of file ShaderLibrary.cpp.
void ShaderLibrary::updateModel | ( | const ngl::Matrix | _matrix | ) |
update the model matrix of the shaders
[in] | _matrix | the model matrix to set to all the shaders |
Definition at line 98 of file ShaderLibrary.cpp.
References m_names, and m_shaders.
{ for (int i = 0; i < m_names.size(); i++) { //update model matrix for all shaders from matrix m_shaders->useShader(m_names[i]); m_shaders->setShaderParamFromMatrix(m_names[i],"ModelMatrix", _matrix); } }
void ShaderLibrary::updateModelColor | ( | const std::string | _name, |
const ngl::Matrix | _matrix, | ||
const ngl::Colour | _colour, | ||
const bool | _reset = true , |
||
const bool | _exclusive = true |
||
) |
update the colour and model parameters of the shaders
[in] | _name | the name of the shader to update |
[in] | _matrix | the model matrix to set to the shader |
[in] | _colour | the colour to set |
[in] | _reset | flag to set whether to flush shader states |
[in] | _exclusive | flag to determine whether to this shader as active |
Definition at line 150 of file ShaderLibrary.cpp.
{ if (_reset) { //flush the shader states glFlush(); } if (_exclusive) { //enable the shader m_shaders->useShader(_name); } //update model info to shader updateModel(_name, _matrix, false); //update color into to shader updateColor(_name, _colour, false); }
void ShaderLibrary::updateProjection | ( | ngl::Camera * | _cam | ) |
update the projection matrix of the shaders
[in] | _cam | the camera that will be used to get the projection matrix |
Definition at line 88 of file ShaderLibrary.cpp.
References m_names, and m_shaders.
{ for (int i = 0; i < m_names.size(); i++) { //update projection matrix for all shaders from cam info m_shaders->useShader(m_names[i]); m_shaders->setShaderParamFromMatrix(m_names[i],"projectionMatrix", _cam->getProjection()); } }
void ShaderLibrary::updateView | ( | ngl::Camera * | _cam | ) |
update the view matrix of the shaders
[in] | _cam | the camera that will be used to get the view matrix |
Definition at line 78 of file ShaderLibrary.cpp.
References m_names, and m_shaders.
{ for (int i = 0; i < m_names.size(); i++) { //update view matrix for all shaders from cam info m_shaders->useShader(m_names[i]); m_shaders->setShaderParamFromMatrix(m_names[i],"ViewMatrix", _cam->getModelView()); } }
void ShaderLibrary::updateViewProjection | ( | ngl::Camera * | _cam | ) |
update the view and projection matrices of the shaders
[in] | _cam | the camera that will be used to get the matrices |
Definition at line 71 of file ShaderLibrary.cpp.
References updateProjection(), and updateView().
{ //update view and projection matrices from cam info updateView(_cam); updateProjection(_cam); }
void ShaderLibrary::useShader | ( | const std::string | _name | ) | [inline] |
select a particular shader in the library as active
[in] | _name | the name of the shader to set as active |
Definition at line 82 of file ShaderLibrary.h.
References m_shaders.
{ m_shaders->useShader(_name); }
std::vector<std::string> ShaderLibrary::m_names [private] |
the list of shader names
Definition at line 89 of file ShaderLibrary.h.
ngl::ShaderManager* ShaderLibrary::m_shaders [private] |
the list of shaders
Definition at line 86 of file ShaderLibrary.h.