void Shader::setParameter(const std::string& name, const Texture& texture)
{
    if (m_shaderProgram)
    {
        ensureGlContext();

        // Find the location of the variable in the shader
        int location = getParamLocation(name);
        if (location != -1)
        {
            // Store the location -> texture mapping
            TextureTable::iterator it = m_textures.find(location);
            if (it == m_textures.end())
            {
                // New entry, make sure there are enough texture units
                GLint maxUnits = getMaxTextureUnits();
                if (m_textures.size() + 1 >= static_cast<std::size_t>(maxUnits))
                {
                    err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
                    return;
                }

                m_textures[location] = &texture;
            }
            else
            {
                // Location already used, just replace the texture
                it->second = &texture;
            }
        }
    }
}
Ejemplo n.º 2
0
void Shader::setParameter(const std::string &name, CurrentTextureType) {
	if (mShaderProgram) {
		ensureGLContext();

		mCurrentTexture = getParamLocation(name);
	}
}
Ejemplo n.º 3
0
	inline bool CShader::set<float>( const std::string & pName, const float & v) const
	{
		const GLint iP= getParamLocation(pName);
		if (iP < 0) return false;
		glUniform1f(iP, static_cast<GLfloat>(v));CHECK_GLERROR("");
		return true;
	}
Ejemplo n.º 4
0
	inline bool CShader::set<float>( const std::string & pName, const float & v0, const float & v1 ) const
	{
		const GLint iP= getParamLocation(pName);
		if (iP < 0) return false;
		glUniform2f(iP, v0, v1);CHECK_GLERROR("");
		return true;
	}
Ejemplo n.º 5
0
	inline bool CShader::setArray<CVector4i>( const std::string & pName, int count, const CVector4i * v) const
	{
		const GLint iP= getParamLocation(pName);
		if (iP < 0) return false;
		glUniform4iv(iP, static_cast<const GLint>(count), (const GLint*)(v));CHECK_GLERROR("");
		return true;
	}
Ejemplo n.º 6
0
	inline bool CShader::set<int>( const std::string & pName, const int & v0, const int & v1, const int & v2, const int & v3 ) const
	{
		const GLint iP= getParamLocation(pName);
		if (iP < 0) return false;
		glUniform4i(iP, v0, v1, v2, v3);CHECK_GLERROR("");
		return true;
	}
void Shader::setParameter(const std::string& name, CurrentTextureType)
{
    if (m_shaderProgram)
    {
        ensureGlContext();

        // Find the location of the variable in the shader
        m_currentTexture = getParamLocation(name);
    }
}
Ejemplo n.º 8
0
void Shader::setParameter(const std::string &name, const Transform &transform) {
	if (mShaderProgram) {
		ensureGLContext();

		GLhandleARB program = glCheck(glGetHandleARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB)));
		glCheck(glUseProgramObjectARB(mShaderProgram));

		GLint location = getParamLocation(name);
		if (location != -1) {
			glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix()));
		}

		glCheck(glUseProgramObjectARB(program));
	}
}
Ejemplo n.º 9
0
void Shader::setParameter(const std::string &name, float x, float y, float z, float w) {
	if (mShaderProgram) {
		ensureGLContext();

		GLhandleARB program = glCheck(glGetHandleARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB)));
		glCheck(glUseProgramObjectARB(mShaderProgram));

		GLint location = getParamLocation(name);
		if (location != -1) {
			glCheck(glUniform4fARB(location, x, y, z, w));
		}

		glCheck(glUseProgramObjectARB(program));
	}
}
Ejemplo n.º 10
0
        void Shader::setParameter(const std::string& name, float x, float y, float z, float w)
        {
            if (m_shaderProgram)
            {
                ensureGlContext();
                // Enable program
                GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
                glCheck(glUseProgramObjectARB(m_shaderProgram));

                // Get parameter location and assign it new values
                GLint location = getParamLocation(name);
                if (location != -1)
                    glCheck(glUniform4fARB(location, x, y, z, w));

                // Disable program
                glCheck(glUseProgramObjectARB(program));
            }
        }
Ejemplo n.º 11
0
void Shader::setParameter(const std::string& name, const sf::Transform& transform)
{
    if (m_shaderProgram)
    {
        ensureGlContext();

        // Enable program
        GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
        glCheck(glUseProgramObjectARB(m_shaderProgram));

        // Get parameter location and assign it new values
        GLint location = getParamLocation(name);
        if (location != -1)
            glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix()));

        // Disable program
        glCheck(glUseProgramObjectARB(program));
    }
}
Ejemplo n.º 12
0
        void Shader::setParameter(const std::string& name, math::Matrix4f matrix)
        {
            if (m_shaderProgram)
            {
                ensureGlContext();
                // Enable program
                GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
                glCheck(glUseProgramObjectARB(m_shaderProgram));

                // Get parameter location and assign it new values
                GLint location = getParamLocation(name);
                if (location != -1) {
                    std::array<float, 16> glmatrix = matrix.toGlMatrix();
                    glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, glmatrix.data()));
                }
                // Disable program
                glCheck(glUseProgramObjectARB(program));
            }
        }
Ejemplo n.º 13
0
void Shader::setParameter(const std::string &name, const Texture &texture) {
	if (mShaderProgram) {
		ensureGLContext();

		GLint location = getParamLocation(name);
		if (location != -1) {
			TextureTable::iterator it = mTextures.find(location);
			if (it == mTextures.end()) {
				GLint maxUnits = getMaxTextureUnits();
				if (mTextures.size() + 1 >= staticCast_t(maxUnits)) {
					std::cerr << "Imposible to use texture \"" << name << "\" for shader, all available texture units are used.\n";
					return;
				}

				mTextures[location] = &texture;
			} else {
				it->second = &texture;
			}
		}
	}
}
void Shader::setParameter(const std::string& name, const Transform& transform)
{
    if (m_shaderProgram)
    {
        ensureGlContext();

        // Enable program
        GLEXT_GLhandle program;
        glCheck(program = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
        glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));

        // Get parameter location and assign it new values
        GLint location = getParamLocation(name);
        if (location != -1)
        {
            glCheck(GLEXT_glUniformMatrix4fv(location, 1, GL_FALSE, transform.getMatrix()));
        }

        // Disable program
        glCheck(GLEXT_glUseProgramObject(program));
    }
}
void Shader::setParameter(const std::string& name, float x, float y, float z, float w)
{
    if (m_shaderProgram)
    {
        ensureGlContext();

        // Enable program
        GLEXT_GLhandle program;
        glCheck(program = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
        glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));

        // Get parameter location and assign it new values
        GLint location = getParamLocation(name);
        if (location != -1)
        {
            glCheck(GLEXT_glUniform4f(location, x, y, z, w));
        }

        // Disable program
        glCheck(GLEXT_glUseProgramObject(program));
    }
}