/** * Sets an uniform matrix. * Matrices are always of type float. * \warning uses glGetError(); * \param name - name of the parameter * \param m - a float array containing up to 16 floats for the matrix. * \param bTranspose - if true, the matrix will be transposed before uploading. * \return void * \author <a href="mailto:[email protected]">Jens Schneider</a> * \date Mar.2005 */ void GLSLProgram::SetUniformMatrix(const char *name,const float *m,bool bTranspose) const { assert(m_bEnabled); CheckGLError(); GLenum iType; GLint iLocation; try { iLocation = get_uniform_vector(name, m_hProgram, &iType); } catch(tuvok::GLError gl) { T_ERROR("Error (%d) obtaining uniform %s in '%s' or '%s'.", gl.errno(), name, m_sVS.c_str(), m_sFS.c_str()); return; } switch (iType) { case GL_FLOAT_MAT2: glUniformMatrix2fv(iLocation,1,bTranspose,m); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(iLocation,1,bTranspose,m); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(iLocation,1,bTranspose,m); break; default: T_ERROR("Unknown type (%d) for %s.", iType, name); break; } #ifdef GLSL_DEBUG CheckGLError("SetUniformMatrix(%s,float*,bool)",name); #endif }
void neb::Light::base::load(int o, neb::core::pose const & pose) { GLUTPP_DEBUG_1_FUNCTION; /** @todo way to ditinguish lights in shader */ auto p = neb::app::base::global()->current_program(); vec3 pos = pos_; pos += vec3(pose.pos_); p->get_uniform_vector(light_type_string_ + ".position")->load(o, pos); p->get_uniform_vector(light_type_string_ + ".ambient")->load(o, ambient_); p->get_uniform_vector(light_type_string_ + ".diffuse")->load(o, diffuse_); p->get_uniform_vector(light_type_string_ + ".specular")->load(o, specular_); }
/** * Sets an uniform vector parameter. * \warning uses glGetError(); * \param name - name of the parameter * \param x,y,z,w - up to four float components of the vector to set. * \return void * \author <a href="mailto:[email protected]">Jens Schneider</a> * \date Aug.2004 */ void GLSLProgram::SetUniformVector(const char *name, float x, float y, float z, float w) const { assert(m_bEnabled); CheckGLError(); GLenum iType; GLint iLocation; try { iLocation = get_uniform_vector(name, m_hProgram, &iType); } catch(tuvok::GLError gl) { T_ERROR("Error (%d) obtaining uniform %s in '%s' or '%s'.", gl.errno(), name, m_sVS.c_str(), m_sFS.c_str()); return; } switch (iType) { case GL_FLOAT: glUniform1f(iLocation,x); break; case GL_FLOAT_VEC2: glUniform2f(iLocation,x,y); break; case GL_FLOAT_VEC3: glUniform3f(iLocation,x,y,z); break; case GL_FLOAT_VEC4: glUniform4f(iLocation,x,y,z,w); break; #ifdef GLSL_ALLOW_IMPLICIT_CASTS case GL_INT: case GL_SAMPLER_1D: case GL_SAMPLER_2D: case GL_SAMPLER_3D: case GL_SAMPLER_CUBE: case GL_SAMPLER_1D_SHADOW: case GL_SAMPLER_2D_SHADOW: case GL_SAMPLER_2D_RECT_ARB: case GL_SAMPLER_2D_RECT_SHADOW_ARB: glUniform1i(iLocation,int(x)); break; case GL_INT_VEC2: glUniform2i(iLocation,int(x),int(y)); break; case GL_INT_VEC3: glUniform3i(iLocation,int(x),int(y),int(z)); break; case GL_INT_VEC4: glUniform4i(iLocation,int(x),int(y),int(z),int(w)); break; case GL_BOOL: glUniform1f(iLocation,x); break; case GL_BOOL_VEC2: glUniform2f(iLocation,x,y); break; case GL_BOOL_VEC3: glUniform3f(iLocation,x,y,z); break; case GL_BOOL_VEC4: glUniform4f(iLocation,x,y,z,w); break; #endif default: T_ERROR("Unknown type (%d) for %s.", iType, name); break; } #ifdef GLSL_DEBUG CheckGLError("SetUniformVector(%s,float,...)",name); #endif }
/** * Sets an uniform vector parameter. * \warning uses glGetError(); * \param name - name of the parameter * \param x,y,z,w - up to four bool components of the vector to set. * \return void * \author <a href="mailto:[email protected]">Jens Schneider</a> * \date Mar.2005 */ void GLSLProgram::SetUniformVector(const char *name,bool x, bool y, bool z, bool w) const { assert(m_bEnabled); CheckGLError(); GLenum iType; GLint iLocation; try { iLocation = get_uniform_vector(name, m_hProgram, &iType); } catch(tuvok::GLError gl) { T_ERROR("Error (%d) obtaining uniform %s in '%s' or '%s'.", gl.errno(), name, m_sVS.c_str(), m_sFS.c_str()); return; } switch (iType) { case GL_BOOL: glUniform1i(iLocation,(x ? 1 : 0)); break; case GL_BOOL_VEC2: glUniform2i(iLocation,(x ? 1 : 0),(y ? 1 : 0)); break; case GL_BOOL_VEC3: glUniform3i(iLocation,(x ? 1 : 0),(y ? 1 : 0),(z ? 1 : 0)); break; case GL_BOOL_VEC4: glUniform4i(iLocation,(x ? 1 : 0),(y ? 1 : 0),(z ? 1 : 0),(w ? 1 : 0)); break; #ifdef GLSL_ALLOW_IMPLICIT_CASTS case GL_FLOAT: glUniform1f(iLocation,(x ? 1.0f : 0.0f)); break; case GL_FLOAT_VEC2: glUniform2f(iLocation,(x ? 1.0f : 0.0f),(y ? 1.0f : 0.0f)); break; case GL_FLOAT_VEC3: glUniform3f(iLocation,(x ? 1.0f : 0.0f),(y ? 1.0f : 0.0f),(z ? 1.0f : 0.0f)); break; case GL_FLOAT_VEC4: glUniform4f(iLocation,(x ? 1.0f : 0.0f),(y ? 1.0f : 0.0f),(z ? 1.0f : 0.0f),(w ? 1.0f : 0.0f)); break; case GL_INT: glUniform1i(iLocation,(x ? 1 : 0)); break; case GL_INT_VEC2: glUniform2i(iLocation,(x ? 1 : 0),(y ? 1 : 0)); break; case GL_INT_VEC3: glUniform3i(iLocation,(x ? 1 : 0),(y ? 1 : 0),(z ? 1 : 0)); break; case GL_INT_VEC4: glUniform4i(iLocation,(x ? 1 : 0),(y ? 1 : 0),(z ? 1 : 0),(w ? 1 : 0)); break; #endif default: T_ERROR("Unknown type (%d) for %s.", iType, name); break; } #ifdef GLSL_DEBUG CheckGLError("SetUniformVector(%s,bool,...)",name); #endif }