Added bypassUBO method to new shader base class.

This commit is contained in:
hiker 2015-04-23 17:11:19 +10:00
parent 262fc0c373
commit a51225ec36
6 changed files with 57 additions and 13 deletions

View File

@ -300,7 +300,7 @@ private:
u32 m_renderpass;
class STKMeshSceneNode *m_sun_interposer;
scene::ICameraSceneNode *m_suncam;
core::vector3df m_sundirection;
core::vector3df m_sun_direction;
video::SColorf m_suncolor;
std::pair<float, float> m_shadow_scales[4];
scene::ICameraSceneNode *m_shadow_camnodes[4];
@ -544,11 +544,11 @@ public:
// ------------------------------------------------------------------------
inline core::vector3df getWind() {return m_wind->getWind();}
// -----------------------------------------------------------------------
core::vector3df getSunDirection() const { return m_sundirection; };
const core::vector3df& getSunDirection() const { return m_sun_direction; };
// -----------------------------------------------------------------------
void setSunDirection(const core::vector3df &SunPos)
{
m_sundirection = SunPos;
m_sun_direction = SunPos;
}
// -----------------------------------------------------------------------
video::SColorf getSunColor() const { return m_suncolor; }

View File

@ -129,9 +129,9 @@ unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, fl
void IrrDriver::uploadLightingData()
{
float Lighting[36];
Lighting[0] = m_sundirection.X;
Lighting[1] = m_sundirection.Y;
Lighting[2] = m_sundirection.Z;
Lighting[0] = m_sun_direction.X;
Lighting[1] = m_sun_direction.Y;
Lighting[2] = m_sun_direction.Z;
Lighting[4] = m_suncolor.getRed();
Lighting[5] = m_suncolor.getGreen();
Lighting[6] = m_suncolor.getBlue();

View File

@ -20,6 +20,7 @@
#include "graphics/central_settings.hpp"
#include "graphics/gl_headers.hpp"
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
#include "utils/log.hpp"
@ -154,6 +155,49 @@ int ShaderBase::loadTFBProgram(const std::string &shader_name,
} // loadTFBProgram
// ----------------------------------------------------------------------------
void ShaderBase::bypassUBO() const
{
GLint VM = glGetUniformLocation(m_program, "ViewMatrix");
glUniformMatrix4fv(VM, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
GLint PM = glGetUniformLocation(m_program, "ProjectionMatrix");
glUniformMatrix4fv(PM, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
GLint IVM = glGetUniformLocation(m_program, "InverseViewMatrix");
glUniformMatrix4fv(IVM, 1, GL_FALSE, irr_driver->getInvViewMatrix().pointer());
GLint IPM = glGetUniformLocation(m_program, "InverseProjectionMatrix");
glUniformMatrix4fv(IPM, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer());
GLint Screen = glGetUniformLocation(m_program, "screen");
glUniform2f(Screen, irr_driver->getCurrentScreenSize().X,
irr_driver->getCurrentScreenSize().Y);
GLint bLmn = glGetUniformLocation(m_program, "blueLmn[0]");
glUniform1fv(bLmn, 9, irr_driver->blueSHCoeff);
GLint gLmn = glGetUniformLocation(m_program, "greenLmn[0]");
glUniform1fv(gLmn, 9, irr_driver->greenSHCoeff);
GLint rLmn = glGetUniformLocation(m_program, "redLmn[0]");
glUniform1fv(rLmn, 9, irr_driver->redSHCoeff);
GLint sun_dir = glGetUniformLocation(m_program, "sun_direction");
const core::vector3df &sd = irr_driver->getSunDirection();
glUniform3f(sun_dir, sd.X, sd.Y, sd.Z);
GLint sun_col = glGetUniformLocation(m_program, "sun_col");
const video::SColorf& sc = irr_driver->getSunColor();
glUniform3f(sun_col, sc.getRed(), sc.getGreen(), sc.getBlue());
GLint sun_angle = glGetUniformLocation(m_program, "sun_angle");
glUniform1f(sun_angle, 0.54f);
} // bypassUBO
// ----------------------------------------------------------------------------
/** Constructor, which adds the shader to all instantiated shaders (for the
* reload-all-shaders debug option).
*/
ShaderBase::ShaderBase()
{
m_all_shaders.push_back(this);

View File

@ -18,6 +18,7 @@
#ifndef HEADER_SHADER_HPP
#define HEADER_SHADER_HPP
#include "graphics/central_settings.hpp"
#include "graphics/gl_headers.hpp"
#include "utils/singleton.hpp"
@ -50,6 +51,8 @@ protected:
/** OpenGL's program id. */
GLuint m_program;
void bypassUBO() const;
private:
// ------------------------------------------------------------------------
// Ends vararg template
@ -216,8 +219,8 @@ public:
// ------------------------------------------------------------------------
void setUniforms(const Args & ... args) const
{
if (needsUBO())
bypassUBO(m_program);
if (!CVS->isARBUniformBufferObjectUsable())
bypassUBO();
setUniformsImpl(args...);
}

View File

@ -648,10 +648,6 @@ namespace UtilShader
}
using namespace UtilShader;
bool needsUBO()
{
return !CVS->isARBUniformBufferObjectUsable();
}
void setTextureSampler(GLenum tp, GLuint texunit, GLuint tid, GLuint sid)
{

View File

@ -18,6 +18,7 @@
#ifndef SHADERS_UTIL_HPP
#define SHADERS_UTIL_HPP
#include "graphics/central_settings.hpp"
#include "utils/singleton.hpp"
#include <vector>
#include <matrix4.h>
@ -222,7 +223,7 @@ public:
void setUniforms(const Args & ... args) const
{
if (needsUBO())
if (!CVS->isARBUniformBufferObjectUsable())
bypassUBO(Program);
UniformHelper::setUniformsHelper(uniforms, args...);
}