ProgramObject.cpp
Default mainpageApplicationProgramObject.cpp
Description Overview Included files Included by Source
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "ProgramObject.hpp"

ProgramObject::ProgramObject()
{
    program = glCreateProgramObjectARB();
}

ProgramObject::~ProgramObject()
{
    glDeleteObjectARB(program);
}

void ProgramObject::addShader(ShaderObject* shader)
{
    glAttachObjectARB(program, shader->getShader());
}

void ProgramObject::removeShader(ShaderObject* shader)
{
    glDetachObjectARB(program, shader->getShader());
}

void ProgramObject::link()
{
    GLint linked;

    glLinkProgramARB(program);

    glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &linked);

    assert(linked && "There was an error while linking the shader object");
}

void ProgramObject::begin()
{
    glUseProgramObjectARB(program);
}

void ProgramObject::end()
{
    glUseProgramObjectARB(0);
}

void ProgramObject::setUniform1f(const char* varname, GLfloat v0)
{
    glUniform1fARB(getUniformLocation(varname), v0);
}

void ProgramObject::setUniform2f(const char* varname, GLfloat v0, GLfloat v1)
{
    glUniform2fARB(getUniformLocation(varname), v0, v1);
}

void ProgramObject::setUniform3f(const char* varname, GLfloat v0, GLfloat v1, GLfloat v2)
{
    glUniform3fARB(getUniformLocation(varname), v0, v1, v2);
}

void ProgramObject::setUniform4f(const char* varname, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
{
    glUniform4fARB(getUniformLocation(varname), v0, v1, v2, v3);
}

void ProgramObject::setUniform1i(const char* varname, GLint v0)
{
    glUniform1iARB(getUniformLocation(varname), v0);
}

void ProgramObject::setUniform2i(const char* varname, GLint v0, GLint v1)
{
    glUniform2iARB(getUniformLocation(varname), v0, v1);
}

void ProgramObject::setUniform3i(const char* varname, GLint v0, GLint v1, GLint v2)
{
    glUniform3iARB(getUniformLocation(varname), v0, v1, v2);
}

void ProgramObject::setUniform4i(const char* varname, GLint v0, GLint v1, GLint v2, GLint v3)
{
    glUniform4iARB(getUniformLocation(varname), v0, v1, v2, v3);
}

void ProgramObject::setUniform1fv(const char* varname, GLsizei count, GLfloat *value)
{
    glUniform1fv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniform2fv(const char* varname, GLsizei count, GLfloat *value)
{
    glUniform2fv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniform3fv(const char* varname, GLsizei count, GLfloat *value)
{
    glUniform3fv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniform4fv(const char* varname, GLsizei count, GLfloat *value)
{
    glUniform4fv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniform1iv(const char* varname, GLsizei count, GLint *value)
{
    glUniform1iv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniform2iv(const char* varname, GLsizei count, GLint *value)
{
    glUniform2iv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniform3iv(const char* varname, GLsizei count, GLint *value)
{
    glUniform3iv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniform4iv(const char* varname, GLsizei count, GLint *value)
{
    glUniform4iv(getUniformLocation(varname), count, value);
}

void ProgramObject::setUniformMatrix2fv(const char* varname, GLsizei count, GLboolean transpose, GLfloat *value)
{

}

void ProgramObject::setUniformMatrix3fv(const char* varname, GLsizei count, GLboolean transpose, GLfloat *value)
{

}

void ProgramObject::setUniformMatrix4fv(const char* varname, GLsizei count, GLboolean transpose, GLfloat *value)
{

}

void ProgramObject::setVertexAttrib1f(GLuint index, GLfloat v0)
{

}

void ProgramObject::setVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1)
{

}

void ProgramObject::setVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2)
{

}

void ProgramObject::setVertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
{

}

GLint ProgramObject::getUniformLocation(const char* name)
{
    GLint location;

    location = glGetUniformLocationARB(program, name);

    assert(location != -1 && "Uniform variable not found");

    return(location);
}