Example #1
0
// Setup lighting
void OpenGLShaderPass::setUpLightingCalculation(OpenGLState& current,
                                                const RendererLight* light,
                                                const Vector3& viewer,
                                                const Matrix4& objTransform)
{
    assert(light);

    // Get the light shader and examine its first (and only valid) layer
    MaterialPtr lightShader = light->getShader()->getMaterial();

    if (lightShader->firstLayer() != 0) 
    {
        // Calculate viewer location in object space
        Matrix4 inverseObjTransform = objTransform.getInverse();
        Vector3 osViewer = matrix4_transformed_point(
                inverseObjTransform, viewer
        );

        // Get the XY and Z falloff texture numbers.
        GLuint attenuation_xy = 
            lightShader->firstLayer()->getTexture()->getGLTexNum();
        GLuint attenuation_z = 
            lightShader->lightFalloffImage()->getGLTexNum();

        // Bind the falloff textures
        assert(current.renderFlags & RENDER_TEXTURE_2D);

        setTextureState(
            current.texture3, attenuation_xy, GL_TEXTURE3, GL_TEXTURE_2D
        );
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

        setTextureState(
            current.texture4, attenuation_z, GL_TEXTURE4, GL_TEXTURE_2D
        );
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

        // Get the world-space to light-space transformation matrix
        Matrix4 world2light = light->getLightTextureTransformation();

        // Set the ambient factor - 1.0 for an ambient light, 0.0 for normal light
        float ambient = 0.0;
        if (lightShader->isAmbientLight())
            ambient = 1.0;

        // Bind the GL program parameters
        current.glProgram->applyRenderParams(
            osViewer,
            objTransform,
            light->getLightOrigin(),
            light->colour(),
            world2light,
            ambient
        );
    }
}
Example #2
0
void MeshDrawCommand::commandSetRenderState(ShaderProgram *shader, Material *material, GLuint vertices, GLuint indices, bool withoutTexture)
{
	if(shder != this->shaderProgream)
	{
		setShaderState();	
	}
	if(!withoutTexture)
	{
		setTextureState();
	}
	if(vertices != this->vbo[0] || indices != this->vbo[1])
	{
		setAttribState();
	}
}
Example #3
0
// Apply all textures to texture units
void OpenGLShaderPass::applyAllTextures(OpenGLState& current,
                                        unsigned requiredState)
{
    // Set the texture dimensionality from render flags. There is only a global
    // mode for all textures, we can't have texture1 as 2D and texture2 as
    // CUBE_MAP for example.
    GLenum textureMode = 0;
    if (requiredState & RENDER_TEXTURE_CUBEMAP) // cube map has priority
        textureMode = GL_TEXTURE_CUBE_MAP;
    else if (requiredState & RENDER_TEXTURE_2D)
        textureMode = GL_TEXTURE_2D;

    // Apply our texture numbers to the current state
    if (textureMode != 0) // only if one of the RENDER_TEXTURE options
    {
        if(GLEW_VERSION_1_3)
        {
            setTextureState(
                current.texture0, _state.texture0, GL_TEXTURE0, textureMode
            );
            setTextureState(
                current.texture1, _state.texture1, GL_TEXTURE1, textureMode
            );
            setTextureState(
                current.texture2, _state.texture2, GL_TEXTURE2, textureMode
            );
            setTextureState(
                current.texture3, _state.texture2, GL_TEXTURE2, textureMode
            );
            setTextureState(
                current.texture4, _state.texture2, GL_TEXTURE2, textureMode
            );
        }
        else
        {
            setTextureState(
                current.texture0, _state.texture0, textureMode
            );
        }
    }
}