Exemplo n.º 1
0
/*!
 Add all the variables of this material object to the shader program "program".
 It expects that the program already exits and that the names in _glsl_names are used
 @param program - the glsl shader program integer id
 */
bool GLSpotLightSource::addVariablesToProgram(GLuint program, int variable_index)
{
    
    if(program == -1)return false; // no program exits
    
    
    GLint params;
    glGetProgramiv( program, GL_LINK_STATUS, &params);
    if(params == GL_FALSE)
    {
        cerr << "[GLMaterial] Program " << program << " has not been linked. Materials cannot be added." << endl;
        return false;
    }
    
    
    // enable the program
    glUseProgram(program);
    
    
    // get the location of a uniform variable. Note, the program must be linked at this position.
    _cone_angleIdx = glGetUniformLocation(program, GetVariableName(_glsl_object, _glsl_names[0], variable_index).c_str());
                    checkUniform(_cone_angleIdx, GetVariableName(_glsl_object, _glsl_names[0], variable_index));
    _cone_directionIdx = glGetUniformLocation(program, GetVariableName(_glsl_object, _glsl_names[1], variable_index).c_str());
                    checkUniform(_cone_directionIdx, GetVariableName(_glsl_object, _glsl_names[1], variable_index));

    
    // call the funciton of the base function.
    GLLightSource::addVariablesToProgram(program,variable_index);
    
    // Send the light information to your shader program
    glUniform1f(_cone_angleIdx, _cone_angle);
    glUniform3fv(_cone_directionIdx, 1, &_cone_direction[0]);
    
    return true;
}
Exemplo n.º 2
0
/*!
 Add all the variables of this material object to the shader program "program".
 It expects that the program already exits and that the names in _glsl_names are used
 @param program - the glsl shader program integer id
 */
bool GLLightSource::addVariablesToProgram(GLuint program, int variable_index)
{

    if(program == -1)return false; // no program exits
    
    
    GLint params;
    glGetProgramiv( program, GL_LINK_STATUS, &params);
    if(params == GL_FALSE)
    {
        cerr << "[GLMaterial] Program " << program << " has not been linked. Materials cannot be added." << endl;
        return false;
    }
    
    
    // enable the program
    glUseProgram(program);
    
    
    // get the location of a uniform variable. Note, the program must be linked at this position.
    _ambientIdx = glGetUniformLocation(program, GetVariableName(_glsl_object, _glsl_names[2], variable_index).c_str());
                    checkUniform(_ambientIdx, GetVariableName(_glsl_object,_glsl_names[2], variable_index));
    
    _diffuseIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[1], variable_index).c_str()  );
                    checkUniform(_diffuseIdx,  GetVariableName(_glsl_object,_glsl_names[1], variable_index));
    
    
    _specularIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[0], variable_index).c_str() );
                    checkUniform(_specularIdx, GetVariableName(_glsl_object,_glsl_names[0], variable_index).c_str());
    
    _attenuation_coeffIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[3], variable_index).c_str());
                    checkUniform(_attenuation_coeffIdx, GetVariableName(_glsl_object,_glsl_names[3], variable_index));
    
    
    _lightPosIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[4], variable_index).c_str());
                    checkUniform(_lightPosIdx, GetVariableName(_glsl_object,_glsl_names[4], variable_index));

    
    // Send the light information to your shader program
    glUniform1f(_ambientIdx, _ambient_intensity );
    glUniform1f(_diffuseIdx, _diffuse_intensity);
    glUniform1f(_specularIdx, _specular_intensity);
    glUniform1f(_attenuation_coeffIdx, _attenuation_coeff);
    glUniform4fv(_lightPosIdx, 1, &_lightPos[0]);
    
    // disable the program
    // glUseProgram(0);
    
    return true;
}
//virtual
bool GLTexture::addVariablesToProgram(GLuint program, int variable_index )
{

    if(program == -1)return false; // no program exits
    
    
    GLint params;
    glGetProgramiv( program, GL_LINK_STATUS, &params);
    if(params == GL_FALSE)
    {
        cerr << "[GLTexture] Program " << program << " has not been linked. Textures cannot be added." << endl;
        return false;
    }
    
    // enable the program
    glUseProgram(program);
    
    
    // get the location of a uniform variable. Note, the program must be linked at this position.
    // location of the texture in the glsl program
    _textureIdx = glGetUniformLocation(program, _glsl_names[0].c_str() );
    checkUniform(_textureIdx, _glsl_names[0]);
    
    _textureBlendModelIdx = glGetUniformLocation(program, _glsl_names[1].c_str() );
    checkUniform(_textureBlendModelIdx, _glsl_names[1]);
    
    //****************************************************************************************************
    // Link the texture to the uniform variable and texture unit 0;
    
    /*
     glActiveTexture tells OpenGL which texture unit we want to use. GL_TEXTURE0 is the first texture unit, so we will just use that.
     */
    glActiveTexture(GL_TEXTURE0);
    
    
    //We use glBindTexture bind our texture into the active texture unit.
    glBindTexture(GL_TEXTURE_2D, _texture);
    
    /*
     Then we set the tex uniform of the shaders to the index of the texture unit. We used texture unit zero, so we set the tex uniform to the integer value 0.
     */
    glUniform1i(_textureIdx, 0);
    
    
    // update the variable
    dirty(program);
    
    return true;
}
Exemplo n.º 4
0
/*!
 Add all the variables of this material object to the shader program "program".
 It expects that the program already exits and that the names in _glsl_names are used
 @param program - the glsl shader program integer id
 */
bool GLMaterial::addVariablesToProgram(GLuint program, int variable_index)
{

    if(program == -1)return false; // no program exits
    
    
    GLint params;
    glGetProgramiv( program, GL_LINK_STATUS, &params);
    if(params == GL_FALSE)
    {
        cerr << "[GLMaterial] Program " << program << " has not been linked. Materials cannot be added." << endl;
        return false;
    }
    
    
    // enable the program
    glUseProgram(program);
    
    glGetProgramiv( program, GL_ACTIVE_UNIFORMS, &params);
 

    GetVariableName(_glsl_struct, _glsl_names[0], variable_index);
    
    // get the location of a uniform variable. Note, the program must be linked at this position.
    _ambientColorPos = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[0], variable_index).c_str());
                        checkUniform(_ambientColorPos, _glsl_names[0]);
    
    _diffuseColorPos = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[1], variable_index).c_str());
                        checkUniform(_diffuseColorPos, _glsl_names[1]);
    
    _specularColorPos = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[2], variable_index).c_str());
                        checkUniform(_specularColorPos, _glsl_names[2]);
    
    _shininessIdx = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[3], variable_index).c_str());
                        checkUniform(_shininessIdx, _glsl_names[3]);
    
    
    // Send the material to your shader program
    glUniform3fv(_ambientColorPos, 1, &_ambient_material[0] );
    glUniform3fv(_diffuseColorPos, 1, &_diffuse_material[0]);
    glUniform3fv(_specularColorPos, 1, &_specular_material[0]);
    glUniform1f(_shininessIdx, _shininess);
    
    // disable the program
    // glUseProgram(0);
    
    return true;
}
Exemplo n.º 5
0
bool TriTexture::addVariablesToProgram(GLuint program, int variable_index) {
    if (program == -1) {
        return false; // no program exits
    }

    GLint params;
    glGetProgramiv(program, GL_LINK_STATUS, &params);
    if (params == GL_FALSE) {
        cerr << "[GLTexture] Program " << program << " has not been linked. Textures cannot be added." << endl;
        return false;
    }

    // enable the program
    glUseProgram(program);

    // get the location of a uniform variable. Note, the program must be linked at this position.
    // location of the texture in the glsl program
    _textureIdx1 = glGetUniformLocation(program, _glsl_names[0].c_str() );
    checkUniform(_textureIdx1, _glsl_names[0]);

    _textureIdx2 = glGetUniformLocation(program, _glsl_names[1].c_str() );
    checkUniform(_textureIdx2, _glsl_names[1]);

    _textureIdx3 = glGetUniformLocation(program, _glsl_names[2].c_str() );
    checkUniform(_textureIdx3, _glsl_names[2]);

    // Link the texture to the uniform variable and texture unit 0;

    // glActiveTexture tells OpenGL which texture unit we want to use
    glActiveTexture(GL_TEXTURE0);

    // We use glBindTexture bind our texture into the active texture unit.
    glBindTexture(GL_TEXTURE_2D, _texture_1);

    // Then we set the tex uniform of the shaders to the index of the texture unit
    glUniform1i(_textureIdx1, 0);

    // Do the same for the other textures
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, _texture_2);
    glUniform1i(_textureIdx2, 1);

    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, _texture_3);
    glUniform1i(_textureIdx3, 2);

    return true;
}
Exemplo n.º 6
0
 void Shader::uniMat4 (const char* uniName, const float* uniValue, int _count /* = 1*/)
 {
   GLuint uni = checkUniform (uniName);
   uniMat4 (uni, uniValue, _count);
 }
Exemplo n.º 7
0
 void Shader::uni4f (const char* uniName, float uniValue1, float uniValue2, float uniValue3, float uniValue4)
 {
   GLuint uni = checkUniform (uniName);
   uni4f (uni, uniValue1, uniValue2, uniValue3, uniValue4);
 }
Exemplo n.º 8
0
 void Shader::uni2f (const char* uniName, float uniValue1, float uniValue2)
 {
   GLuint uni = checkUniform (uniName);
   uni2f (uni, uniValue1, uniValue2);
 }
Exemplo n.º 9
0
 void Shader::uni4iv (const char* uniName, const int* uniValue, int _count /* = 1*/)
 {
   GLuint loc = checkUniform (uniName);
   uni4iv (loc, uniValue, _count);
 }
Exemplo n.º 10
0
 void Shader::uni4i (const char* uniName, int uniValue1, int uniValue2, int uniValue3, int uniValue4)
 {
   GLuint loc = checkUniform (uniName);
   uni4i (loc, uniValue1, uniValue2, uniValue3, uniValue4);
 }
Exemplo n.º 11
0
 void Shader::uni2i (const char* uniName, int uniValue1, int uniValue2)
 {
   GLuint loc = checkUniform (uniName);
   uni2i (loc, uniValue1, uniValue2);
 }