Merge branch 'master' into origin/TupleTest

This commit is contained in:
Marianne Gagnon 2014-07-17 20:01:27 -04:00
commit 6aa95f58b9
38 changed files with 635 additions and 594 deletions

View File

@ -15,8 +15,9 @@ before_install:
- sudo apt-get update -qq
# Install dependencies
- sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev
# Install mesa from an other repo (a newer version is required)
- sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted"
# Install mesa from an other repo (a newer version is required). Quantal is not supported anymore, saucy is only supported till July 2014,
# so we try to use trusty (precise which is what traiv uses a too old mesa version which doesn't link)
- sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty main restricted"
- sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32
- sudo apt-get update -qq
- sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev

View File

@ -17,6 +17,7 @@ layout(location = 8) in vec3 Orientation;
layout(location = 9) in vec3 Scale;
#else
in vec3 Position;
in vec4 Color;
in vec2 Texcoord;
in vec3 Origin;

View File

@ -60,7 +60,7 @@ void main(void)
vec2 uv = RHuv + offset * 0.01;
// Get world position and normal from the RSM sample
float depth = texture2D(dtex, uv).z;
float depth = texture(dtex, uv).z;
vec4 RSMPos = inverse(RSMMatrix) * (2. * vec4(uv, depth, 1.) - 1.);
RSMPos /= RSMPos.w;
vec3 RSMAlbedo = texture(ctex, uv).xyz;

View File

@ -8,11 +8,17 @@ uniform mat4 TextureMatrix =
0., 0., 1., 0.,
0., 0., 0., 1.);
#if __VERSION__ >= 330
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec4 Color;
layout(location = 3) in vec2 Texcoord;
#else
in vec3 Position;
in vec3 Normal;
in vec4 Color;
in vec2 Texcoord;
#endif
out vec3 nor;
out vec2 uv;

View File

@ -9,8 +9,13 @@ layout (std140) uniform MatrixesData
uniform mat4 ModelMatrix;
#if __VERSION__ >= 330
layout(location = 0) in vec3 Position;
layout(location = 3) in vec2 Texcoord;
#else
in vec3 Position;
in vec2 Texcoord;
#endif
#ifdef VSLayer
out vec2 uv;

View File

@ -10,9 +10,15 @@ layout (std140) uniform MatrixesData
uniform mat4 ModelMatrix;
uniform vec3 windDir;
#if __VERSION__ >= 330
layout(location = 0) in vec3 Position;
layout(location = 2) in vec4 Color;
layout(location = 3) in vec2 Texcoord;
#else
in vec3 Position;
in vec4 Color;
in vec2 Texcoord;
#endif
#ifdef VSLayer
out vec2 uv;

View File

@ -26,7 +26,7 @@ out float AO;
const float sigma = 1.;
const float tau = 7.;
const float beta = 0.001;
const float beta = 0.002;
const float epsilon = .00001;
const float radius = 1.;
const float k = 1.5;

View File

@ -1931,8 +1931,9 @@ void IrrDriver::update(float dt)
// =================================
if (!m_device->run())
{
GUIEngine::cleanUp();
GUIEngine::deallocate();
// Don't bother cleaning up GUI, has no use and may result in crashes
//GUIEngine::cleanUp();
//GUIEngine::deallocate();
main_loop->abort();
return;
}

View File

@ -266,10 +266,6 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
{
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00);
renderSolidFirstPass();
PROFILER_POP_CPU_MARKER();
// Shadows
{
PROFILER_PUSH_CPU_MARKER("- Shadow", 0x30, 0x6F, 0x90);
@ -283,6 +279,12 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
PROFILER_POP_CPU_MARKER();
}
PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00);
renderSolidFirstPass();
PROFILER_POP_CPU_MARKER();
// Lights
{
PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00);

View File

@ -32,6 +32,42 @@
#include <algorithm>
struct TexUnit
{
GLuint m_id;
bool m_premul_alpha;
TexUnit(GLuint id, bool premul_alpha)
{
m_id = id;
m_premul_alpha = premul_alpha;
}
};
template<typename Shader, typename...uniforms>
void draw(const GLMesh *mesh, uniforms... Args)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
Shader::setUniforms(Args...);
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex);
}
template<typename T, typename...uniforms>
void draw(const T *Shader, const GLMesh *mesh, uniforms... Args)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
Shader->setUniforms(Args...);
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex);
}
template<unsigned N>
struct unroll_args_instance
@ -60,8 +96,32 @@ void apply_instance(const T *Shader, const STK::Tuple<TupleType...> &arg)
//unroll_args_instance<STK::TupleSize<STK::Tuple<TupleType...> >::value >::template exec<T>(Shader, arg);
}
template<typename Shader, enum E_VERTEX_TYPE VertexType, typename... TupleType>
void renderMeshes1stPass(const std::vector<GLuint> &TexUnits, std::vector<STK::Tuple<TupleType...> > &meshes)
template<int...List>
struct custom_unroll_args;
template<>
struct custom_unroll_args<>
{
template<typename T, typename ...TupleTypes, typename ...Args>
static void exec(const T *Shader, const STK::Tuple<TupleTypes...> &t, Args... args)
{
draw<T>(Shader, STK::tuple_get<0>(t), args...);
}
};
template<int N, int...List>
struct custom_unroll_args<N, List...>
{
template<typename T, typename ...TupleTypes, typename ...Args>
static void exec(const T *Shader, const STK::Tuple<TupleTypes...> &t, Args... args)
{
custom_unroll_args<List...>::template exec<T>(Shader, t, STK::tuple_get<N>(t), args...);
}
};
template<typename Shader, enum E_VERTEX_TYPE VertexType, int ...List, typename... TupleType>
void renderMeshes1stPass(const std::vector<TexUnit> &TexUnits, std::vector<STK::Tuple<TupleType...> > &meshes)
{
glUseProgram(Shader::getInstance()->Program);
glBindVertexArray(getVAO(VertexType));
@ -72,8 +132,8 @@ void renderMeshes1stPass(const std::vector<GLuint> &TexUnits, std::vector<STK::T
{
if (!mesh.textures[j])
mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[j], true);
setTexture(TexUnits[j], getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
compressTexture(mesh.textures[j], TexUnits[j].m_premul_alpha);
setTexture(TexUnits[j].m_id, getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
if (mesh.VAOType != VertexType)
{
@ -82,7 +142,7 @@ void renderMeshes1stPass(const std::vector<GLuint> &TexUnits, std::vector<STK::T
#endif
continue;
}
apply_instance(Shader::getInstance(), meshes[i]);
custom_unroll_args<List...>::template exec(Shader::getInstance(), meshes[i]);
}
}
@ -99,11 +159,14 @@ void IrrDriver::renderSolidFirstPass()
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS);
ListDefaultStandardG::Arguments.clear();
ListDefault2TCoordG::Arguments.clear();
ListAlphaRefG::Arguments.clear();
ListNormalG::Arguments.clear();
ListGrassG::Arguments.clear();
ListMatDefault::Arguments.clear();
ListMatAlphaRef::Arguments.clear();
ListMatSphereMap::Arguments.clear();
ListMatDetails::Arguments.clear();
ListMatUnlit::Arguments.clear();
ListMatNormalMap::Arguments.clear();
ListMatGrass::Arguments.clear();
ListMatSplatting::Arguments.clear();
m_scene_manager->drawAll(scene::ESNRP_SOLID);
if (!UserConfigParams::m_dynamic_lights)
@ -111,19 +174,26 @@ void IrrDriver::renderSolidFirstPass()
{
ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS1));
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_STANDARD>(std::vector<GLuint>{ MeshShader::ObjectPass1Shader::getInstance<MeshShader::ObjectPass1Shader>()->TU_tex }, ListDefaultStandardG::Arguments);
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_2TCOORDS>(std::vector<GLuint>{ MeshShader::ObjectPass1Shader::getInstance<MeshShader::ObjectPass1Shader>()->TU_tex }, ListDefault2TCoordG::Arguments);
renderMeshes1stPass<MeshShader::ObjectRefPass1Shader, video::EVT_STANDARD>(std::vector<GLuint>{ MeshShader::ObjectRefPass1Shader::getInstance<MeshShader::ObjectRefPass1Shader>()->TU_tex }, ListAlphaRefG::Arguments);
renderMeshes1stPass<MeshShader::NormalMapShader, video::EVT_TANGENTS>(std::vector<GLuint>{ MeshShader::NormalMapShader::getInstance<MeshShader::NormalMapShader>()->TU_glossy,
MeshShader::NormalMapShader::getInstance<MeshShader::NormalMapShader>()->TU_normalmap }, ListNormalG::Arguments);
renderMeshes1stPass<MeshShader::GrassPass1Shader, video::EVT_STANDARD>(std::vector<GLuint>{ MeshShader::GrassPass1Shader::getInstance<MeshShader::GrassPass1Shader>()->TU_tex }, ListGrassG::Arguments);
std::vector<TexUnit> object_pass1_texunits{ TexUnit(MeshShader::ObjectPass1Shader::getInstance()->TU_tex, true) };
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_STANDARD, 2, 1>(object_pass1_texunits, ListMatDefault::Arguments);
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_STANDARD, 2, 1>(object_pass1_texunits, ListMatSphereMap::Arguments);
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_STANDARD, 2, 1>(object_pass1_texunits, ListMatUnlit::Arguments);
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_2TCOORDS, 2, 1>(object_pass1_texunits, ListMatDetails::Arguments);
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_2TCOORDS, 2, 1>(object_pass1_texunits, ListMatSplatting::Arguments);
renderMeshes1stPass<MeshShader::ObjectRefPass1Shader, video::EVT_STANDARD, 3, 2, 1>(std::vector<TexUnit>{ TexUnit(MeshShader::ObjectRefPass1Shader::getInstance()->TU_tex, true) }, ListMatAlphaRef::Arguments);
renderMeshes1stPass<MeshShader::GrassPass1Shader, video::EVT_STANDARD, 3, 2, 1>(std::vector<TexUnit>{ TexUnit(MeshShader::GrassPass1Shader::getInstance()->TU_tex, true) }, ListMatGrass::Arguments);
renderMeshes1stPass<MeshShader::NormalMapShader, video::EVT_TANGENTS, 2, 1>(std::vector<TexUnit>{
TexUnit(MeshShader::NormalMapShader::getInstance()->TU_glossy, true),
TexUnit(MeshShader::NormalMapShader::getInstance()->TU_normalmap, false)
}, ListMatNormalMap::Arguments);
}
}
template<typename T, enum E_VERTEX_TYPE VertexType, typename... TupleType>
void renderMeshes2ndPass(const T *Shader, const std::vector<GLuint> &TexUnits, std::vector<STK::Tuple<TupleType...> > &meshes)
template<typename Shader, enum E_VERTEX_TYPE VertexType, int...List, typename... TupleType>
void renderMeshes2ndPass(const std::vector<TexUnit> &TexUnits, std::vector<STK::Tuple<TupleType...> > &meshes)
{
glUseProgram(Shader->Program);
glUseProgram(Shader::getInstance()->Program);
glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < meshes.size(); i++)
{
@ -132,8 +202,8 @@ void renderMeshes2ndPass(const T *Shader, const std::vector<GLuint> &TexUnits, s
{
if (!mesh.textures[j])
mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[j], true);
setTexture(TexUnits[j], getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
compressTexture(mesh.textures[j], TexUnits[j].m_premul_alpha);
setTexture(TexUnits[j].m_id, getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
@ -153,7 +223,7 @@ void renderMeshes2ndPass(const T *Shader, const std::vector<GLuint> &TexUnits, s
#endif
continue;
}
apply_instance<T>(Shader, meshes[i]);
custom_unroll_args<List...>::template exec(Shader::getInstance(), meshes[i]);
}
}
@ -179,14 +249,6 @@ void IrrDriver::renderSolidSecondPass()
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
ListDefaultStandardSM::Arguments.clear();
ListDefaultTangentSM::Arguments.clear();
ListAlphaRefSM::Arguments.clear();
ListSphereMapSM::Arguments.clear();
ListUnlitSM::Arguments.clear();
ListDetailSM::Arguments.clear();
ListSplattingSM::Arguments.clear();
ListGrassSM::Arguments.clear();
setTexture(0, m_rtts->getRenderTarget(RTT_TMP1), GL_NEAREST, GL_NEAREST);
setTexture(1, m_rtts->getRenderTarget(RTT_TMP2), GL_NEAREST, GL_NEAREST);
setTexture(2, m_rtts->getRenderTarget(RTT_HALF1_R), GL_LINEAR, GL_LINEAR);
@ -196,22 +258,14 @@ void IrrDriver::renderSolidSecondPass()
m_scene_manager->drawAll(scene::ESNRP_SOLID);
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_STANDARD>(MeshShader::ObjectPass2ShaderInstance, std::vector<GLuint>{ MeshShader::ObjectPass2ShaderInstance->TU_Albedo }, ListDefaultStandardSM::Arguments);
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_TANGENTS>(MeshShader::ObjectPass2ShaderInstance, std::vector<GLuint>{ MeshShader::ObjectPass2ShaderInstance->TU_Albedo }, ListDefaultTangentSM::Arguments);
renderMeshes2ndPass<MeshShader::ObjectRefPass2Shader, video::EVT_STANDARD>(MeshShader::ObjectRefPass2ShaderInstance, std::vector<GLuint>{ MeshShader::ObjectRefPass2ShaderInstance->TU_Albedo }, ListAlphaRefSM::Arguments);
renderMeshes2ndPass<MeshShader::SphereMapShader, video::EVT_STANDARD>(MeshShader::SphereMapShaderInstance, std::vector<GLuint>{ MeshShader::SphereMapShaderInstance->TU_tex }, ListSphereMapSM::Arguments);
renderMeshes2ndPass<MeshShader::ObjectUnlitShader, video::EVT_STANDARD>(MeshShader::ObjectUnlitShaderInstance, std::vector<GLuint>{ MeshShader::ObjectUnlitShaderInstance->TU_tex }, ListUnlitSM::Arguments);
renderMeshes2ndPass<MeshShader::DetailledObjectPass2Shader, video::EVT_2TCOORDS>(MeshShader::DetailledObjectPass2ShaderInstance, std::vector<GLuint>{ MeshShader::DetailledObjectPass2ShaderInstance->TU_Albedo, MeshShader::DetailledObjectPass2ShaderInstance->TU_detail }, ListDetailSM::Arguments);
std::vector<GLuint> v;
v.push_back(8);
v.push_back(MeshShader::SplattingShaderInstance->TU_tex_layout);
v.push_back(MeshShader::SplattingShaderInstance->TU_tex_detail0);
v.push_back(MeshShader::SplattingShaderInstance->TU_tex_detail1);
v.push_back(MeshShader::SplattingShaderInstance->TU_tex_detail2);
v.push_back(MeshShader::SplattingShaderInstance->TU_tex_detail3);
renderMeshes2ndPass<MeshShader::SplattingShader, video::EVT_2TCOORDS>(MeshShader::SplattingShaderInstance, v,
ListSplattingSM::Arguments);
renderMeshes2ndPass<MeshShader::GrassPass2Shader, video::EVT_STANDARD>(MeshShader::GrassPass2ShaderInstance, std::vector<GLuint>{ MeshShader::GrassPass2ShaderInstance->TU_Albedo }, ListGrassSM::Arguments);
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_STANDARD, 4, 3, 1>({ { MeshShader::ObjectPass2Shader::getInstance()->TU_Albedo, true } }, ListMatDefault::Arguments);
renderMeshes2ndPass<MeshShader::ObjectRefPass2Shader, video::EVT_STANDARD, 4, 3, 1 >({ { MeshShader::ObjectRefPass2Shader::getInstance()->TU_Albedo, true } }, ListMatAlphaRef::Arguments);
renderMeshes2ndPass<MeshShader::SphereMapShader, video::EVT_STANDARD, 4, 2, 1>({ { MeshShader::SphereMapShader::getInstance()->TU_tex, true } }, ListMatSphereMap::Arguments);
renderMeshes2ndPass<MeshShader::DetailledObjectPass2Shader, video::EVT_2TCOORDS, 4, 1>({ { MeshShader::DetailledObjectPass2Shader::getInstance()->TU_Albedo, true }, { MeshShader::DetailledObjectPass2Shader::getInstance()->TU_detail, true } }, ListMatDetails::Arguments);
renderMeshes2ndPass<MeshShader::GrassPass2Shader, video::EVT_STANDARD, 4, 3, 1>({ { MeshShader::GrassPass2Shader::getInstance()->TU_Albedo, true } }, ListMatGrass::Arguments);
renderMeshes2ndPass<MeshShader::ObjectUnlitShader, video::EVT_STANDARD, 1>({ { MeshShader::ObjectUnlitShader::getInstance()->TU_tex, true } }, ListMatUnlit::Arguments);
renderMeshes2ndPass<MeshShader::SplattingShader, video::EVT_2TCOORDS, 3, 1>({ { 8, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_layout, false }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail0, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail1, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail2, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail3, true } }, ListMatSplatting::Arguments);
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_TANGENTS, 4, 3, 1>({ { MeshShader::ObjectPass2Shader::getInstance()->TU_Albedo, true } }, ListMatNormalMap::Arguments);
}
}
@ -238,16 +292,16 @@ void IrrDriver::renderTransparent()
if (World::getWorld() && World::getWorld()->isFogEnabled())
{
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>(MeshShader::TransparentFogShaderInstance, std::vector<GLuint>{ MeshShader::TransparentFogShaderInstance->TU_tex }, ListBlendTransparentFog::Arguments);
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD, 8, 7, 6, 5, 4, 3, 2, 1>({ { MeshShader::TransparentFogShader::getInstance()->TU_tex, true } }, ListBlendTransparentFog::Arguments);
glBlendFunc(GL_ONE, GL_ONE);
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>(MeshShader::TransparentFogShaderInstance, std::vector<GLuint>{ MeshShader::TransparentFogShaderInstance->TU_tex }, ListAdditiveTransparentFog::Arguments);
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD, 8, 7, 6, 5, 4, 3, 2, 1>({ { MeshShader::TransparentFogShader::getInstance()->TU_tex, true } }, ListAdditiveTransparentFog::Arguments);
}
else
{
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>(MeshShader::TransparentShaderInstance, std::vector<GLuint>{ MeshShader::TransparentShaderInstance->TU_tex }, ListBlendTransparent::Arguments);
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD, 2, 1>({ { MeshShader::TransparentShader::getInstance()->TU_tex, true } }, ListBlendTransparent::Arguments);
glBlendFunc(GL_ONE, GL_ONE);
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>(MeshShader::TransparentShaderInstance, std::vector<GLuint>{ MeshShader::TransparentShaderInstance->TU_tex }, ListAdditiveTransparent::Arguments);
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD, 2, 1>({ { MeshShader::TransparentShader::getInstance()->TU_tex, true } }, ListAdditiveTransparent::Arguments);
}
if (!UserConfigParams::m_dynamic_lights)
@ -329,48 +383,56 @@ void IrrDriver::renderTransparent()
}
template<typename T, enum E_VERTEX_TYPE VertexType, typename... Args>
void drawShadow(const T *Shader, const std::vector<GLuint> TextureUnits, const std::vector<STK::Tuple<GLMesh *, core::matrix4, Args...> >&t)
template<typename T, typename...uniforms>
void drawShadow(const T *Shader, const GLMesh *mesh, uniforms... Args)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
Shader->setUniforms(Args...);
glDrawElementsInstancedBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, 4, mesh->vaoBaseVertex);
}
template<int...List>
struct shadow_custom_unroll_args;
template<>
struct shadow_custom_unroll_args<>
{
template<typename T, typename ...TupleTypes, typename ...Args>
static void exec(const T *Shader, const STK::Tuple<TupleTypes...> &t, Args... args)
{
drawShadow<T>(Shader, STK::tuple_get<0>(t), args...);
}
};
template<int N, int...List>
struct shadow_custom_unroll_args<N, List...>
{
template<typename T, typename ...TupleTypes, typename ...Args>
static void exec(const T *Shader, const STK::Tuple<TupleTypes...> &t, Args... args)
{
shadow_custom_unroll_args<List...>::template exec<T>(Shader, t, STK::tuple_get<N>(t), args...);
}
};
template<typename T, enum E_VERTEX_TYPE VertexType, int...List, typename... Args>
void renderShadow(const T *Shader, const std::vector<GLuint> TextureUnits, const std::vector<STK::Tuple<GLMesh *, core::matrix4, Args...> >&t)
{
glUseProgram(Shader->Program);
glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < t.size(); i++)
{
const GLMesh *mesh = STK::tuple_get<0>(t[i]);
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
for (unsigned j = 0; j < TextureUnits.size(); j++)
{
compressTexture(mesh->textures[j], true);
setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
Shader->setUniforms(STK::tuple_get<1>(t[i]));
glDrawElementsInstancedBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, 4, mesh->vaoBaseVertex);
}
}
static void drawShadowGrass(const std::vector<GLuint> TextureUnits, const std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::vector3df> > &t)
{
glUseProgram(MeshShader::GrassShadowShaderInstance->Program);
glBindVertexArray(getVAO(EVT_STANDARD));
for (unsigned i = 0; i < t.size(); i++)
{
const GLMesh *mesh = STK::tuple_get<0>(t[i]);
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
for (unsigned j = 0; j < TextureUnits.size(); j++)
{
compressTexture(mesh->textures[j], true);
setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
MeshShader::GrassShadowShaderInstance->setUniforms(STK::tuple_get<1>(t[i]), STK::tuple_get<3>(t[i]));
glDrawElementsInstancedBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, 4, mesh->vaoBaseVertex);
shadow_custom_unroll_args<List...>::template exec<T>(Shader, t[i]);
}
}
@ -381,9 +443,11 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector<GLuint> Texture
glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < t.size(); i++)
{
const GLMesh *mesh = STK::tuple_get<0>(t[i]);
GLMesh *mesh = STK::tuple_get<0>(t[i]);
for (unsigned j = 0; j < TextureUnits.size(); j++)
{
if (!mesh->textures[j])
mesh->textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh->textures[j], true);
setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
@ -393,23 +457,36 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector<GLuint> Texture
void IrrDriver::renderShadows()
{
irr_driver->setPhase(SHADOW_PASS);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.5, 0.);
m_rtts->getShadowFBO().Bind();
glClear(GL_DEPTH_BUFFER_BIT);
glDrawBuffer(GL_NONE);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
irr_driver->setPhase(SHADOW_PASS);
ListMatDefault::Arguments.clear();
ListMatAlphaRef::Arguments.clear();
ListMatSphereMap::Arguments.clear();
ListMatDetails::Arguments.clear();
ListMatUnlit::Arguments.clear();
ListMatNormalMap::Arguments.clear();
ListMatGrass::Arguments.clear();
ListMatSplatting::Arguments.clear();
m_scene_manager->drawAll(scene::ESNRP_SOLID);
drawShadow<MeshShader::ShadowShader, EVT_STANDARD>(MeshShader::ShadowShaderInstance, std::vector<GLuint>(), ListDefaultStandardG::Arguments);
drawShadow<MeshShader::ShadowShader, EVT_2TCOORDS>(MeshShader::ShadowShaderInstance, std::vector<GLuint>(), ListDefault2TCoordG::Arguments);
drawShadow<MeshShader::ShadowShader, EVT_TANGENTS>(MeshShader::ShadowShaderInstance, std::vector<GLuint>(), ListNormalG::Arguments);
drawShadow<MeshShader::RefShadowShader, EVT_STANDARD>(MeshShader::RefShadowShaderInstance, std::vector<GLuint>{ MeshShader::RefShadowShaderInstance->TU_tex }, ListAlphaRefG::Arguments);
drawShadowGrass(std::vector<GLuint>{ MeshShader::GrassShadowShaderInstance->TU_tex }, ListGrassG::Arguments);
renderShadow<MeshShader::ShadowShader, EVT_STANDARD, 1>(MeshShader::ShadowShaderInstance, {}, ListMatDefault::Arguments);
renderShadow<MeshShader::ShadowShader, EVT_STANDARD, 1>(MeshShader::ShadowShaderInstance, {}, ListMatSphereMap::Arguments);
renderShadow<MeshShader::ShadowShader, EVT_STANDARD, 1>(MeshShader::ShadowShaderInstance, {}, ListMatUnlit::Arguments);
renderShadow<MeshShader::ShadowShader, EVT_2TCOORDS, 1>(MeshShader::ShadowShaderInstance, {}, ListMatDetails::Arguments);
renderShadow<MeshShader::ShadowShader, EVT_2TCOORDS, 1>(MeshShader::ShadowShaderInstance, {}, ListMatSplatting::Arguments);
renderShadow<MeshShader::ShadowShader, EVT_TANGENTS, 1>(MeshShader::ShadowShaderInstance, {}, ListMatNormalMap::Arguments);
renderShadow<MeshShader::RefShadowShader, EVT_STANDARD, 1>(MeshShader::RefShadowShaderInstance, { MeshShader::RefShadowShaderInstance->TU_tex }, ListMatAlphaRef::Arguments);
renderShadow<MeshShader::GrassShadowShader, EVT_STANDARD, 3, 1>(MeshShader::GrassShadowShaderInstance, { MeshShader::GrassShadowShaderInstance->TU_tex }, ListMatGrass::Arguments);
glDisable(GL_POLYGON_OFFSET_FILL);
@ -419,6 +496,9 @@ void IrrDriver::renderShadows()
m_rtts->getRSM().Bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawRSM<EVT_STANDARD>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::TU_tex }, ListDefaultStandardG::Arguments);
drawRSM<EVT_2TCOORDS>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::TU_tex }, ListDefault2TCoordG::Arguments);
}
drawRSM<EVT_STANDARD>(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatDefault::Arguments);
drawRSM<EVT_STANDARD>(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatSphereMap::Arguments);
drawRSM<EVT_STANDARD>(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatUnlit::Arguments);
drawRSM<EVT_2TCOORDS>(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatDetails::Arguments);
drawRSM<EVT_2TCOORDS>(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatSplatting::Arguments);
}

View File

@ -328,19 +328,10 @@ void Shaders::loadShaders()
MeshShader::InstancedObjectPass1ShaderInstance = new MeshShader::InstancedObjectPass1Shader();
MeshShader::InstancedObjectRefPass1ShaderInstance = new MeshShader::InstancedObjectRefPass1Shader();
MeshShader::InstancedGrassPass1ShaderInstance = new MeshShader::InstancedGrassPass1Shader();
MeshShader::ObjectPass2ShaderInstance = new MeshShader::ObjectPass2Shader();
MeshShader::InstancedObjectPass2ShaderInstance = new MeshShader::InstancedObjectPass2Shader();
MeshShader::InstancedObjectRefPass2ShaderInstance = new MeshShader::InstancedObjectRefPass2Shader();
MeshShader::InstancedGrassPass2ShaderInstance = new MeshShader::InstancedGrassPass2Shader();
MeshShader::DetailledObjectPass2ShaderInstance = new MeshShader::DetailledObjectPass2Shader();
MeshShader::ObjectRefPass2ShaderInstance = new MeshShader::ObjectRefPass2Shader();
MeshShader::ObjectUnlitShaderInstance = new MeshShader::ObjectUnlitShader();
MeshShader::SphereMapShaderInstance = new MeshShader::SphereMapShader();
MeshShader::SplattingShaderInstance = new MeshShader::SplattingShader();
MeshShader::GrassPass2ShaderInstance = new MeshShader::GrassPass2Shader();
MeshShader::BubbleShader::init();
MeshShader::TransparentShaderInstance = new MeshShader::TransparentShader();
MeshShader::TransparentFogShaderInstance = new MeshShader::TransparentFogShader();
MeshShader::BillboardShader::init();
LightShader::PointLightShader::init();
MeshShader::DisplaceShaderInstance = new MeshShader::DisplaceShader();

View File

@ -198,7 +198,7 @@ public:
extern InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
class ObjectPass2Shader : public ShaderHelper<core::matrix4, core::matrix4, video::SColorf>
class ObjectPass2Shader : public ShaderHelperSingleton<ObjectPass2Shader, core::matrix4, core::matrix4, video::SColorf>
{
public:
GLuint TU_Albedo;
@ -206,8 +206,6 @@ public:
ObjectPass2Shader();
};
extern ObjectPass2Shader *ObjectPass2ShaderInstance;
class InstancedObjectPass2Shader : public ShaderHelper<video::SColorf>
{
public:
@ -228,7 +226,7 @@ public:
extern InstancedObjectRefPass2Shader *InstancedObjectRefPass2ShaderInstance;
class DetailledObjectPass2Shader : public ShaderHelper<core::matrix4, video::SColorf>
class DetailledObjectPass2Shader : public ShaderHelperSingleton<DetailledObjectPass2Shader, core::matrix4, video::SColorf>
{
public:
GLuint TU_Albedo, TU_detail;
@ -236,9 +234,7 @@ public:
DetailledObjectPass2Shader();
};
extern DetailledObjectPass2Shader *DetailledObjectPass2ShaderInstance;
class ObjectUnlitShader : public ShaderHelper<core::matrix4>
class ObjectUnlitShader : public ShaderHelperSingleton<ObjectUnlitShader, core::matrix4>
{
public:
GLuint TU_tex;
@ -246,9 +242,7 @@ public:
ObjectUnlitShader();
};
extern ObjectUnlitShader *ObjectUnlitShaderInstance;
class ObjectRefPass2Shader : public ShaderHelper<core::matrix4, core::matrix4, video::SColorf>
class ObjectRefPass2Shader : public ShaderHelperSingleton<ObjectRefPass2Shader, core::matrix4, core::matrix4, video::SColorf>
{
public:
GLuint TU_Albedo;
@ -256,9 +250,7 @@ public:
ObjectRefPass2Shader();
};
extern ObjectRefPass2Shader *ObjectRefPass2ShaderInstance;
class GrassPass2Shader : public ShaderHelper<core::matrix4, core::vector3df, video::SColorf>
class GrassPass2Shader : public ShaderHelperSingleton<GrassPass2Shader, core::matrix4, core::vector3df, video::SColorf>
{
public:
GLuint TU_Albedo;
@ -266,8 +258,6 @@ public:
GrassPass2Shader();
};
extern GrassPass2Shader *GrassPass2ShaderInstance;
class InstancedGrassPass2Shader : public ShaderHelper<core::vector3df, core::vector3df, video::SColorf>
{
public:
@ -278,7 +268,7 @@ public:
extern InstancedGrassPass2Shader *InstancedGrassPass2ShaderInstance;
class SphereMapShader : public ShaderHelper<core::matrix4, core::matrix4, video::SColorf>
class SphereMapShader : public ShaderHelperSingleton<SphereMapShader, core::matrix4, core::matrix4, video::SColorf>
{
public:
GLuint TU_tex;
@ -286,9 +276,7 @@ public:
SphereMapShader();
};
extern SphereMapShader *SphereMapShaderInstance;
class SplattingShader : public ShaderHelper<core::matrix4, video::SColorf>
class SplattingShader : public ShaderHelperSingleton<SplattingShader, core::matrix4, video::SColorf>
{
public:
GLuint TU_tex_layout, TU_tex_detail0, TU_tex_detail1, TU_tex_detail2, TU_tex_detail3;
@ -296,8 +284,6 @@ public:
SplattingShader();
};
extern SplattingShader *SplattingShaderInstance;
class BubbleShader
{
public:
@ -308,7 +294,7 @@ public:
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency);
};
class TransparentShader : public ShaderHelper<core::matrix4, core::matrix4>
class TransparentShader : public ShaderHelperSingleton<TransparentShader, core::matrix4, core::matrix4>
{
public:
GLuint TU_tex;
@ -316,9 +302,7 @@ public:
TransparentShader();
};
extern TransparentShader *TransparentShaderInstance;
class TransparentFogShader : public ShaderHelper<core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf>
class TransparentFogShader : public ShaderHelperSingleton<TransparentFogShader, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf>
{
public:
GLuint TU_tex;
@ -326,8 +310,6 @@ public:
TransparentFogShader();
};
extern TransparentFogShader *TransparentFogShaderInstance;
class BillboardShader
{
public:

View File

@ -8,7 +8,6 @@
#include "tracks/track.hpp"
#include "graphics/camera.hpp"
#include "utils/profiler.hpp"
#include "utils/tuple.hpp"
using namespace irr;
@ -40,10 +39,8 @@ void STKAnimatedMesh::setMesh(scene::IAnimatedMesh* mesh)
{
firstTime = true;
GLmeshes.clear();
for (unsigned i = 0; i < FPSM_COUNT; i++)
GeometricMesh[i].clearWithoutDeleting();
for (unsigned i = 0; i < SM_COUNT; i++)
ShadedMesh[i].clearWithoutDeleting();
for (unsigned i = 0; i < MAT_COUNT; i++)
MeshSolidMaterial[i].clearWithoutDeleting();
CAnimatedMeshSceneNode::setMesh(mesh);
}
@ -99,10 +96,8 @@ void STKAnimatedMesh::render()
}
else
{
GeometricMaterial GeometricType = MaterialTypeToGeometricMaterial(type, mb->getVertexType());
ShadedMaterial ShadedType = MaterialTypeToShadedMaterial(type, mesh.textures, mb->getVertexType());
GeometricMesh[GeometricType].push_back(&mesh);
ShadedMesh[ShadedType].push_back(&mesh);
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
MeshSolidMaterial[MatType].push_back(&mesh);
}
std::pair<unsigned, unsigned> p = getVAOOffsetAndBase(mb);
mesh.vaoBaseVertex = p.first;
@ -118,7 +113,7 @@ void STKAnimatedMesh::render()
const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i];
if (isObject(material.MaterialType))
{
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == TRANSPARENT_PASS)
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == TRANSPARENT_PASS || irr_driver->getPhase() == SHADOW_PASS)
{
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, getVBO(mb->getVertexType()));
@ -138,45 +133,24 @@ void STKAnimatedMesh::render()
continue;
}
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == SHADOW_PASS)
{
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
GLMesh* mesh;
for_in(mesh, GeometricMesh[FPSM_DEFAULT_STANDARD])
ListDefaultStandardG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, MeshSolidMaterial[MAT_DEFAULT])
ListMatDefault::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
for_in(mesh, GeometricMesh[FPSM_DEFAULT_2TCOORD])
ListDefault2TCoordG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, MeshSolidMaterial[MAT_ALPHA_REF])
ListMatAlphaRef::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
for_in(mesh, GeometricMesh[FPSM_ALPHA_REF_TEXTURE])
ListAlphaRefG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix));
for_in(mesh, MeshSolidMaterial[MAT_DETAIL])
ListMatDetails::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
return;
}
if (irr_driver->getPhase() == SOLID_LIT_PASS)
{
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
GLMesh* mesh;
for_in(mesh, ShadedMesh[SM_DEFAULT_STANDARD])
ListDefaultStandardSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_DEFAULT_TANGENT])
ListDefaultTangentSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_ALPHA_REF_TEXTURE])
ListAlphaRefSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight()));
for_in (mesh, ShadedMesh[SM_UNLIT])
ListUnlitSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation));
for_in(mesh, ShadedMesh[SM_DETAILS])
ListDetailSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, MeshSolidMaterial[MAT_UNLIT])
ListMatUnlit::Arguments.emplace_back(mesh, AbsoluteTransformation, core::matrix4::EM4CONST_IDENTITY);
return;
}
@ -211,16 +185,16 @@ void STKAnimatedMesh::render()
fogmax, startH, endH, start, end, col));
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparentFog::Arguments.push_back(
STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col));
}
else
{
for_in(mesh, TransparentMesh[TM_DEFAULT])
ListBlendTransparent::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
ListBlendTransparent::Arguments.emplace_back(mesh, AbsoluteTransformation, mesh->TextureMatrix);
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparent::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
ListAdditiveTransparent::Arguments.emplace_back(mesh, AbsoluteTransformation, mesh->TextureMatrix);
}
return;
}

View File

@ -11,8 +11,7 @@ class STKAnimatedMesh : public irr::scene::CAnimatedMeshSceneNode
{
protected:
bool firstTime;
PtrVector<GLMesh, REF> GeometricMesh[FPSM_COUNT];
PtrVector<GLMesh, REF> ShadedMesh[SM_COUNT];
PtrVector<GLMesh, REF> MeshSolidMaterial[MAT_COUNT];
PtrVector<GLMesh, REF> TransparentMesh[TM_COUNT];
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix;

View File

@ -55,7 +55,7 @@ void STKInstancedSceneNode::createGLMeshes()
isMaterialInitialized = false;
}
void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat)
void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh)
{
mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
glGenBuffers(1, &instances_vbo);
@ -99,11 +99,9 @@ void STKInstancedSceneNode::setFirstTimeMaterial()
video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType;
GLMesh &mesh = GLmeshes[i];
GeometricMaterial GeometricType = MaterialTypeToGeometricMaterial(type, mb->getVertexType());
ShadedMaterial ShadedType = MaterialTypeToShadedMaterial(type, mesh.textures, mb->getVertexType());
initinstancedvaostate(mesh, GeometricType, ShadedType);
GeometricMesh[GeometricType].push_back(&mesh);
ShadedMesh[ShadedType].push_back(&mesh);
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
initinstancedvaostate(mesh);
MeshSolidMaterial[MatType].push_back(&mesh);
}
isMaterialInitialized = true;
}
@ -224,7 +222,7 @@ static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t i
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawSMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
static void drawSMDefault(GLMesh &mesh, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
@ -249,7 +247,7 @@ static void drawSMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjection
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawSMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
static void drawSMAlphaRefTexture(GLMesh &mesh, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
@ -275,7 +273,7 @@ static void drawSMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewPr
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawSMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDir, size_t instance_count)
static void drawSMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
@ -318,59 +316,59 @@ void STKInstancedSceneNode::render()
ModelViewProjectionMatrix = irr_driver->getProjMatrix();
ModelViewProjectionMatrix *= irr_driver->getViewMatrix();
if (!GeometricMesh[FPSM_DEFAULT_STANDARD].empty())
if (!MeshSolidMaterial[MAT_DEFAULT].empty())
glUseProgram(MeshShader::InstancedObjectPass1ShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT_STANDARD].size(); i++)
drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT_STANDARD][i], instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++)
drawFSPMDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9);
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
if (!MeshSolidMaterial[MAT_ALPHA_REF].empty())
glUseProgram(MeshShader::InstancedObjectRefPass1ShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++)
drawFSPMAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9);
windDir = getWind();
if (!GeometricMesh[FPSM_GRASS].empty())
if (!MeshSolidMaterial[MAT_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass1ShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++)
drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], windDir, instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++)
drawFSPMGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9);
return;
}
if (irr_driver->getPhase() == SOLID_LIT_PASS)
{
if (!ShadedMesh[SM_DEFAULT_STANDARD].empty())
if (!MeshSolidMaterial[MAT_DEFAULT].empty())
glUseProgram(MeshShader::InstancedObjectPass2ShaderInstance->Program);
for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT_STANDARD].size(); i++)
drawSMDefault(*ShadedMesh[SM_DEFAULT_STANDARD][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++)
drawSMDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9);
if (!ShadedMesh[SM_ALPHA_REF_TEXTURE].empty())
if (!MeshSolidMaterial[MAT_ALPHA_REF].empty())
glUseProgram(MeshShader::InstancedObjectRefPass2ShaderInstance->Program);
for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++)
drawSMAlphaRefTexture(*ShadedMesh[SM_ALPHA_REF_TEXTURE][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++)
drawSMAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9);
if (!ShadedMesh[SM_GRASS].empty())
if (!MeshSolidMaterial[MAT_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass2ShaderInstance->Program);
for (unsigned i = 0; i < ShadedMesh[SM_GRASS].size(); i++)
drawSMGrass(*ShadedMesh[SM_GRASS][i], ModelViewProjectionMatrix, windDir, instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++)
drawSMGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9);
return;
}
if (irr_driver->getPhase() == SHADOW_PASS)
{
if (!GeometricMesh[FPSM_DEFAULT_STANDARD].empty())
if (!MeshSolidMaterial[MAT_DEFAULT].empty())
glUseProgram(MeshShader::InstancedShadowShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT_STANDARD].size(); i++)
drawShadowDefault(*GeometricMesh[FPSM_DEFAULT_STANDARD][i], instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++)
drawShadowDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9);
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
if (!MeshSolidMaterial[MAT_ALPHA_REF].empty())
glUseProgram(MeshShader::InstancedRefShadowShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawShadowAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++)
drawShadowAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9);
if (!GeometricMesh[FPSM_GRASS].empty())
if (!MeshSolidMaterial[MAT_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassShadowShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++)
drawShadowGrass(*GeometricMesh[FPSM_GRASS][i], windDir, instance_pos.size() / 9);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++)
drawShadowGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9);
return;
}
}

View File

@ -8,8 +8,7 @@ class STKInstancedSceneNode : public irr::scene::CMeshSceneNode
{
protected:
int m_ref_count;
std::vector<GLMesh *> GeometricMesh[FPSM_COUNT];
std::vector<GLMesh *> ShadedMesh[SM_COUNT];
std::vector<GLMesh *> MeshSolidMaterial[MAT_COUNT];
std::vector<GLMesh> GLmeshes;
std::vector<float> instance_pos;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
@ -17,7 +16,7 @@ protected:
void createGLMeshes();
bool isMaterialInitialized;
void setFirstTimeMaterial();
void initinstancedvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat);
void initinstancedvaostate(GLMesh &mesh);
void cleanGL();
core::vector3df windDir;
public:

View File

@ -9,37 +9,23 @@
#include "graphics/camera.hpp"
#include "modes/world.hpp"
GeometricMaterial MaterialTypeToGeometricMaterial(video::E_MATERIAL_TYPE MaterialType, video::E_VERTEX_TYPE tp)
MeshMaterial MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE MaterialType, video::E_VERTEX_TYPE tp)
{
if (MaterialType == irr_driver->getShader(ES_SPHERE_MAP))
return MAT_SPHEREMAP;
if (MaterialType == irr_driver->getShader(ES_NORMAL_MAP))
return FPSM_NORMAL_MAP;
return MAT_NORMAL_MAP;
else if (MaterialType == irr_driver->getShader(ES_OBJECTPASS_REF) || MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF)
return FPSM_ALPHA_REF_TEXTURE;
return MAT_ALPHA_REF;
else if (MaterialType == irr_driver->getShader(ES_GRASS) || MaterialType == irr_driver->getShader(ES_GRASS_REF))
return FPSM_GRASS;
return MAT_GRASS;
else if (MaterialType == irr_driver->getShader(ES_SPLATTING))
return MAT_SPLATTING;
else if (MaterialType == irr_driver->getShader(ES_OBJECT_UNLIT))
return MAT_UNLIT;
else if (tp == video::EVT_2TCOORDS)
return FPSM_DEFAULT_2TCOORD;
assert(tp == video::EVT_STANDARD);
return FPSM_DEFAULT_STANDARD;
}
ShadedMaterial MaterialTypeToShadedMaterial(video::E_MATERIAL_TYPE type, video::ITexture **textures, video::E_VERTEX_TYPE tp)
{
if (type == irr_driver->getShader(ES_SPHERE_MAP))
return SM_SPHEREMAP;
else if (type == irr_driver->getShader(ES_SPLATTING))
return SM_SPLATTING;
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF) || type == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF)
return SM_ALPHA_REF_TEXTURE;
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
return SM_GRASS;
else if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
return SM_UNLIT;
else if (tp == video::EVT_2TCOORDS)
return SM_DETAILS;
else if (tp == video::EVT_TANGENTS)
return SM_DEFAULT_TANGENT;
return SM_DEFAULT_STANDARD;
return MAT_DETAIL;
return MAT_DEFAULT;
}
TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE type, f32 MaterialTypeParam)
@ -307,22 +293,17 @@ bool isObject(video::E_MATERIAL_TYPE type)
return false;
}
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > ListDefaultStandardG::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > ListDefault2TCoordG::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4> > ListAlphaRefG::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > ListNormalG::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::vector3df> > ListGrassG::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > ListMatDefault::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > ListMatAlphaRef::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > ListMatSphereMap::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > ListMatDetails::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::vector3df, video::SColorf> > ListMatGrass::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > ListMatUnlit::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > ListMatSplatting::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > ListMatNormalMap::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > ListDefaultStandardSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > ListDefaultTangentSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > ListAlphaRefSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, video::SColorf> > ListSplattingSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > ListSphereMapSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4> > ListUnlitSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, video::SColorf> > ListDetailSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > ListBlendTransparent::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > ListAdditiveTransparent::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4> > ListDisplacement::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf> > ListBlendTransparentFog::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf> > ListAdditiveTransparentFog::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4, core::vector3df, video::SColorf> > ListGrassSM::Arguments;
std::vector<STK::Tuple<GLMesh *, core::matrix4> > ListDisplacement::Arguments;

View File

@ -9,30 +9,19 @@
#include <IMesh.h>
#include "../lib/irrlicht/source/Irrlicht/CMeshSceneNode.h"
//#include <STK::Tuple>
#include <vector>
enum GeometricMaterial
enum MeshMaterial
{
FPSM_DEFAULT_STANDARD,
FPSM_DEFAULT_2TCOORD,
FPSM_ALPHA_REF_TEXTURE,
FPSM_NORMAL_MAP,
FPSM_GRASS,
FPSM_COUNT
};
enum ShadedMaterial
{
SM_DEFAULT_STANDARD,
SM_DEFAULT_TANGENT,
SM_ALPHA_REF_TEXTURE,
SM_SPHEREMAP,
SM_SPLATTING,
SM_GRASS,
SM_UNLIT,
SM_DETAILS,
SM_COUNT
MAT_DEFAULT,
MAT_ALPHA_REF,
MAT_NORMAL_MAP,
MAT_GRASS,
MAT_SPHEREMAP,
MAT_SPLATTING,
MAT_UNLIT,
MAT_DETAIL,
MAT_COUNT
};
enum TransparentMaterial
@ -70,109 +59,54 @@ bool isObject(video::E_MATERIAL_TYPE type);
core::vector3df getWind();
// Pass 1 shader (ie shaders that outputs normals and depth)
class ListDefaultStandardG
class ListMatDefault
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListMatAlphaRef
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListMatNormalMap
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListMatGrass
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::vector3df, video::SColorf> > Arguments;
};
class ListMatSphereMap
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListMatSplatting
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListMatUnlit
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListDefault2TCoordG
class ListMatDetails
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListAlphaRefG
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4> > Arguments;
};
class ListNormalG
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListGrassG
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, core::vector3df> > Arguments;
};
template<typename Shader, typename...uniforms>
void draw(const GLMesh *mesh, uniforms... Args)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
Shader::setUniforms(Args...);
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex);
}
template<typename T, typename...uniforms>
void draw(const T *Shader, const GLMesh *mesh, uniforms... Args)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
Shader->setUniforms(Args...);
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex);
}
// Pass 2 shader (ie shaders that outputs final color)
class ListDefaultStandardSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListDefaultTangentSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListAlphaRefSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListSphereMapSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListSplattingSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, video::SColorf> > Arguments;
};
class ListUnlitSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4> > Arguments;
};
class ListDetailSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, video::SColorf> > Arguments;
};
class ListGrassSM
{
public:
static std::vector<STK::Tuple<GLMesh *, core::matrix4, core::vector3df, video::SColorf> > Arguments;
};
class ListBlendTransparent
{
@ -207,8 +141,7 @@ public:
// Forward pass (for transparents meshes)
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
GeometricMaterial MaterialTypeToGeometricMaterial(video::E_MATERIAL_TYPE, video::E_VERTEX_TYPE);
ShadedMaterial MaterialTypeToShadedMaterial(video::E_MATERIAL_TYPE, irr::video::ITexture **textures, video::E_VERTEX_TYPE tp);
MeshMaterial MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE, video::E_VERTEX_TYPE);
TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE, f32 MaterialTypeParam);
#endif // STKMESH_H

View File

@ -79,8 +79,7 @@ void STKMeshSceneNode::setFirstTimeMaterial()
else
{
assert(!isDisplacement);
GeometricMaterial GeometricType = MaterialTypeToGeometricMaterial(type, mb->getVertexType());
ShadedMaterial ShadedType = MaterialTypeToShadedMaterial(type, mesh.textures, mb->getVertexType());
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
if (immediate_draw)
{
fillLocalBuffer(mesh, mb);
@ -88,10 +87,7 @@ void STKMeshSceneNode::setFirstTimeMaterial()
glBindVertexArray(0);
}
else
{
GeometricMesh[GeometricType].push_back(&mesh);
ShadedMesh[ShadedType].push_back(&mesh);
}
MeshSolidMaterials[MatType].push_back(&mesh);
}
if (!immediate_draw)
@ -118,10 +114,8 @@ void STKMeshSceneNode::cleanGLMeshes()
glDeleteBuffers(1, &(mesh.index_buffer));
}
GLmeshes.clear();
for (unsigned i = 0; i < FPSM_COUNT; i++)
GeometricMesh[i].clearWithoutDeleting();
for (unsigned i = 0; i < SM_COUNT; i++)
ShadedMesh[i].clearWithoutDeleting();
for (unsigned i = 0; i < MAT_COUNT; i++)
MeshSolidMaterials[i].clearWithoutDeleting();
}
void STKMeshSceneNode::setMesh(irr::scene::IMesh* mesh)
@ -216,53 +210,65 @@ void STKMeshSceneNode::render()
GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0);
}
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS && immediate_draw)
{
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
if (immediate_draw)
glDisable(GL_CULL_FACE);
if (update_each_frame)
updatevbo();
glUseProgram(MeshShader::ObjectPass1Shader::getInstance()->Program);
// Only untextured
for (unsigned i = 0; i < GLmeshes.size(); i++)
{
glDisable(GL_CULL_FACE);
if (update_each_frame)
updatevbo();
glUseProgram(MeshShader::ObjectPass1Shader::getInstance()->Program);
// Only untextured
for (unsigned i = 0; i < GLmeshes.size(); i++)
{
irr_driver->IncreaseObjectCount();
GLMesh &mesh = GLmeshes[i];
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
irr_driver->IncreaseObjectCount();
GLMesh &mesh = GLmeshes[i];
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
MeshShader::ObjectPass1Shader::getInstance()->setUniforms(AbsoluteTransformation, invmodel);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
glBindVertexArray(0);
}
glEnable(GL_CULL_FACE);
return;
MeshShader::ObjectPass1Shader::getInstance()->setUniforms(AbsoluteTransformation, invmodel);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
glBindVertexArray(0);
}
glEnable(GL_CULL_FACE);
return;
}
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == SHADOW_PASS)
{
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
GLMesh* mesh;
for_in(mesh, GeometricMesh[FPSM_DEFAULT_STANDARD])
ListDefaultStandardG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, MeshSolidMaterials[MAT_DEFAULT])
ListMatDefault::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
for_in(mesh, GeometricMesh[FPSM_DEFAULT_2TCOORD])
ListDefault2TCoordG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, MeshSolidMaterials[MAT_ALPHA_REF])
ListMatAlphaRef::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
for_in(mesh, GeometricMesh[FPSM_ALPHA_REF_TEXTURE])
ListAlphaRefG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix));
for_in(mesh, MeshSolidMaterials[MAT_SPHEREMAP])
ListMatSphereMap::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
for_in(mesh, GeometricMesh[FPSM_NORMAL_MAP])
ListNormalG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, MeshSolidMaterials[MAT_DETAIL])
ListMatDetails::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
windDir = getWind();
for_in(mesh, GeometricMesh[FPSM_GRASS])
ListGrassG::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel, windDir));
for_in(mesh, MeshSolidMaterials[MAT_GRASS])
ListMatGrass::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, windDir, irr_driver->getSceneManager()->getAmbientLight());
for_in(mesh, MeshSolidMaterials[MAT_UNLIT])
ListMatUnlit::Arguments.emplace_back(mesh, AbsoluteTransformation, core::matrix4::EM4CONST_IDENTITY);
for_in(mesh, MeshSolidMaterials[MAT_SPLATTING])
ListMatSplatting::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, irr_driver->getSceneManager()->getAmbientLight());
for_in(mesh, MeshSolidMaterials[MAT_NORMAL_MAP])
ListMatNormalMap::Arguments.emplace_back(mesh, AbsoluteTransformation, invmodel, core::matrix4::EM4CONST_IDENTITY, irr_driver->getSceneManager()->getAmbientLight());
return;
}
@ -277,7 +283,7 @@ void STKMeshSceneNode::render()
glDisable(GL_CULL_FACE);
if (!spareWhiteTex)
spareWhiteTex = getUnicolorTexture(video::SColor(255, 255, 255, 255));
glUseProgram(MeshShader::ObjectPass2ShaderInstance->Program);
glUseProgram(MeshShader::ObjectPass2Shader::getInstance()->Program);
// Only untextured
for (unsigned i = 0; i < GLmeshes.size(); i++)
{
@ -287,8 +293,8 @@ void STKMeshSceneNode::render()
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(MeshShader::ObjectPass2ShaderInstance->TU_Albedo, getTextureGLuint(spareWhiteTex), GL_NEAREST, GL_NEAREST, false);
MeshShader::ObjectPass2ShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
setTexture(MeshShader::ObjectPass2Shader::getInstance()->TU_Albedo, getTextureGLuint(spareWhiteTex), GL_NEAREST, GL_NEAREST, false);
MeshShader::ObjectPass2Shader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
@ -298,31 +304,6 @@ void STKMeshSceneNode::render()
return;
}
GLMesh* mesh;
for_in(mesh, ShadedMesh[SM_DEFAULT_STANDARD])
ListDefaultStandardSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_DEFAULT_TANGENT])
ListDefaultTangentSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_ALPHA_REF_TEXTURE])
ListAlphaRefSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_SPHEREMAP])
ListSphereMapSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, invmodel, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_SPLATTING])
ListSplattingSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_UNLIT])
ListUnlitSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation));
for_in(mesh, ShadedMesh[SM_DETAILS])
ListDetailSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_GRASS])
ListGrassSM::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, windDir, irr_driver->getSceneManager()->getAmbientLight()));
return;
}
@ -351,7 +332,7 @@ void STKMeshSceneNode::render()
if (World::getWorld() && World::getWorld()->isFogEnabled())
{
glUseProgram(MeshShader::TransparentFogShaderInstance->Program);
glUseProgram(MeshShader::TransparentFogShader::getInstance()->Program);
for (unsigned i = 0; i < GLmeshes.size(); i++)
{
GLMesh &mesh = GLmeshes[i];
@ -375,8 +356,8 @@ void STKMeshSceneNode::render()
tmpcol.getBlue() / 255.0f);
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::TransparentFogShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col);
setTexture(MeshShader::TransparentFogShader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::TransparentFogShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
@ -386,7 +367,7 @@ void STKMeshSceneNode::render()
}
else
{
glUseProgram(MeshShader::TransparentShaderInstance->Program);
glUseProgram(MeshShader::TransparentShader::getInstance()->Program);
for (unsigned i = 0; i < GLmeshes.size(); i++)
{
irr_driver->IncreaseObjectCount();
@ -396,9 +377,9 @@ void STKMeshSceneNode::render()
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::TransparentShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(MeshShader::TransparentShader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::TransparentShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
MeshShader::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
@ -427,25 +408,23 @@ void STKMeshSceneNode::render()
tmpcol.getBlue() / 255.0f);
for_in(mesh, TransparentMesh[TM_DEFAULT])
ListBlendTransparentFog::Arguments.push_back(
STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col));
ListBlendTransparentFog::Arguments.emplace_back(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col);
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparentFog::Arguments.push_back(
STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col));
ListAdditiveTransparentFog::Arguments.emplace_back(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col);
}
else
{
for_in(mesh, TransparentMesh[TM_DEFAULT])
ListBlendTransparent::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
ListBlendTransparent::Arguments.emplace_back(mesh, AbsoluteTransformation, mesh->TextureMatrix);
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparent::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
ListAdditiveTransparent::Arguments.emplace_back(mesh, AbsoluteTransformation, mesh->TextureMatrix);
}
for_in(mesh, TransparentMesh[TM_DISPLACEMENT])
ListDisplacement::Arguments.push_back(STK::make_tuple(mesh, AbsoluteTransformation));
ListDisplacement::Arguments.emplace_back(mesh, AbsoluteTransformation);
if (!TransparentMesh[TM_BUBBLE].empty())
glUseProgram(MeshShader::BubbleShader::Program);

View File

@ -7,8 +7,7 @@
class STKMeshSceneNode : public irr::scene::CMeshSceneNode
{
protected:
PtrVector<GLMesh, REF> GeometricMesh[FPSM_COUNT];
PtrVector<GLMesh, REF> ShadedMesh[SM_COUNT];
PtrVector<GLMesh, REF> MeshSolidMaterials[MAT_COUNT];
PtrVector<GLMesh, REF> TransparentMesh[TM_COUNT];
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix;

View File

@ -201,7 +201,6 @@
#include "utils/leak_check.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "utils/tuple.hpp"
static void cleanSuperTuxKart();
static void cleanUserConfig();
@ -1163,12 +1162,6 @@ void askForInternetPermission()
// ----------------------------------------------------------------------------
int main(int argc, char *argv[] )
{
STK::Tuple<int, float, std::string> tup(1, 3.14f, "Hello");
auto tup2 = STK::make_tuple(1, 3.14f, "Hello");
Log::info("TEST", "Tuple 1 : %i %f %s", STK::tuple_get<0>(tup), STK::tuple_get<1>(tup), STK::tuple_get<2>(tup).c_str());
Log::info("TEST", "Tuple 2 : %i %f %s", STK::tuple_get<0>(tup2), STK::tuple_get<1>(tup2), STK::tuple_get<2>(tup2));
CommandLine::init(argc, argv);
CrashReporting::installHandlers();

View File

@ -30,7 +30,7 @@
*/
class ClientNetworkManager : public NetworkManager
{
friend class Singleton<NetworkManager>;
friend class AbstractSingleton<NetworkManager>;
public:
/*! \brief Get the instance.
* This is a utility function to avoid passing templates parameters
@ -38,7 +38,7 @@ class ClientNetworkManager : public NetworkManager
*/
static ClientNetworkManager* getInstance()
{
return Singleton<NetworkManager>::getInstance<ClientNetworkManager>();
return AbstractSingleton<NetworkManager>::getInstance<ClientNetworkManager>();
}
/*! \brief Initializes network.

View File

@ -33,9 +33,9 @@
/** \class NetworkInterface
* \ingroup network
*/
class NetworkInterface : public Singleton<NetworkInterface>
class NetworkInterface : public AbstractSingleton<NetworkInterface>
{
friend class Singleton<NetworkInterface>;
friend class AbstractSingleton<NetworkInterface>;
public:
/*! \brief Used to init the network.

View File

@ -43,9 +43,9 @@
* Here are defined some functions that will be specifically implemented by
* the ServerNetworkManager and the ClientNetworkManager.
*/
class NetworkManager : public Singleton<NetworkManager>
class NetworkManager : public AbstractSingleton<NetworkManager>
{
friend class Singleton<NetworkManager>;
friend class AbstractSingleton<NetworkManager>;
public:
/** \brief Function to start the Network Manager (start threads) */
virtual void run();

View File

@ -34,9 +34,9 @@ class Item;
/*! \brief Manages the world updates during an online game
* This function's update is to be called instead of the normal World update
*/
class NetworkWorld : public Singleton<NetworkWorld>
class NetworkWorld : public AbstractSingleton<NetworkWorld>
{
friend class Singleton<NetworkWorld>;
friend class AbstractSingleton<NetworkWorld>;
public:
void update(float dt);

View File

@ -102,9 +102,9 @@ typedef struct EventProcessingInfo
* frames per second. Then, the management of protocols is thread-safe: any
* object can start/pause/stop protocols whithout problems.
*/
class ProtocolManager : public Singleton<ProtocolManager>
class ProtocolManager : public AbstractSingleton<ProtocolManager>
{
friend class Singleton<ProtocolManager>;
friend class AbstractSingleton<ProtocolManager>;
friend void* protocolManagerAsynchronousUpdate(void* data);
public:

View File

@ -27,11 +27,11 @@
class ServerNetworkManager : public NetworkManager
{
friend class Singleton<NetworkManager>;
friend class AbstractSingleton<NetworkManager>;
public:
static ServerNetworkManager* getInstance()
{
return Singleton<NetworkManager>::getInstance<ServerNetworkManager>();
return AbstractSingleton<NetworkManager>::getInstance<ServerNetworkManager>();
}
virtual void run();

View File

@ -37,6 +37,9 @@
// ----------------------------------------------------------------------------
/** Loads a grand prix definition from a file.
* \param filename Name of the file to load.
*/
GrandPrixData::GrandPrixData(const std::string& filename)
{
m_filename = filename;
@ -44,18 +47,34 @@ GrandPrixData::GrandPrixData(const std::string& filename)
StringUtils::removeExtension(filename));
m_editable = (filename.find(file_manager->getGPDir(), 0) == 0);
reload();
}
} // GrandPrixData
// ----------------------------------------------------------------------------
GrandPrixData::GrandPrixData(const unsigned int number_of_tracks,
const std::string& track_group,
const RandomGPInfoDialog::REVERSED use_reverse)
/** Creates a random grand prix from the specified parameters.
* \param number_of_tracks How many tracks to select.
* \param track_group From which track group to select the tracks.
* \param use_reverse How the reverse setting is to be determined.
* \param new_tracks If true, new tracks are selected, otherwise existing
* tracks will not be changed (used to e.g. increase the number of
* tracks in an already existing random grand prix).
*
*/
void GrandPrixData::createRandomGP(const unsigned int number_of_tracks,
const std::string &track_group,
const GPReverseType use_reverse,
bool new_tracks)
{
m_filename = "Random GP - Not loaded from a file!";
m_id = "random";
m_name = "Random Grand Prix";
m_editable = false;
if(new_tracks)
{
m_tracks.clear();
m_laps.clear();
m_reversed.clear();
}
m_tracks.reserve(number_of_tracks);
m_laps.reserve(number_of_tracks);
m_reversed.reserve(number_of_tracks);
@ -117,48 +136,64 @@ void GrandPrixData::changeTrackNumber(const unsigned int number_of_tracks,
}
// ----------------------------------------------------------------------------
void GrandPrixData::changeReverse(const RandomGPInfoDialog::REVERSED use_reverse)
/** Updates the GP data with newly decided reverse requirements.
* \param use_reverse How reverse setting for each track is to be determined.
*/
void GrandPrixData::changeReverse(const GrandPrixData::GPReverseType use_reverse)
{
for (unsigned int i = 0; i < m_tracks.size(); i++)
{
if (use_reverse == RandomGPInfoDialog::NO_REVERSE)
if (use_reverse == GP_NO_REVERSE)
m_reversed[i] = false;
else if (use_reverse == RandomGPInfoDialog::MIXED)
else if (use_reverse == GP_RANDOM_REVERSE)
if (track_manager->getTrack(m_tracks[i])->reverseAvailable())
m_reversed[i] = (rand() % 2 != 0);
else
m_reversed[i] = false;
else // all reversed
m_reversed[i] = track_manager->getTrack(m_tracks[i])->reverseAvailable();
}
}
} // for i < m_tracks.size()
} // changeReverse
// ----------------------------------------------------------------------------
/** Sets the id of this grand prix.
* \param id The new id.
*/
void GrandPrixData::setId(const std::string& id)
{
m_id = id;
}
} // setId
// ----------------------------------------------------------------------------
/** Sets the name of the grand prix.
* \param name New name.
*/
void GrandPrixData::setName(const irr::core::stringw& name)
{
m_name = name;
}
} // setName
// ----------------------------------------------------------------------------
/** Sets the filename of this grand prix.
* \param filename New filename.
*/
void GrandPrixData::setFilename(const std::string& filename)
{
m_filename = filename;
}
} // setFilename
// ----------------------------------------------------------------------------
/** Sets if this grand prix can be edited.
* \param editable New value.
*/
void GrandPrixData::setEditable(const bool editable)
{
m_editable = editable;
}
} // setEditable
// ----------------------------------------------------------------------------
/** Reloads grand prix from file.
*/
void GrandPrixData::reload()
{
m_tracks.clear();
@ -270,6 +305,8 @@ void GrandPrixData::reload()
} // reload()
// ----------------------------------------------------------------------------
/** Saves the grand prix data to a file.
*/
bool GrandPrixData::writeToFile()
{
try
@ -303,9 +340,12 @@ bool GrandPrixData::writeToFile()
m_filename.c_str(), e.what());
return false;
}
}
} // writeToFile
// ----------------------------------------------------------------------------
/** Checks if the grand prix data are consistent.
* \param log_error: If errors should be sent to the logger.
*/
bool GrandPrixData::checkConsistency(bool log_error) const
{
for (unsigned int i = 0; i < m_tracks.size(); i++)
@ -323,8 +363,7 @@ bool GrandPrixData::checkConsistency(bool log_error) const
}
}
return true;
}
} // checkConsistency
// ----------------------------------------------------------------------------
/** Returns true if the track is available. This is used to test if Fort Magma
@ -332,76 +371,99 @@ bool GrandPrixData::checkConsistency(bool log_error) const
* story mode, but will be available once all challenges are done and nolok
* is unlocked). It also prevents people from using the grand prix editor as
* a way to play tracks that still haven't been unlocked
* \param id Name of the track to test.
* \param include_locked If set to true, all tracks (including locked tracks)
* are considered to be available.
*/
bool GrandPrixData::isTrackAvailable(const std::string &id,
bool includeLocked ) const
bool include_locked ) const
{
if (includeLocked)
if (include_locked)
return true;
else if (id == "fortmagma")
return !PlayerManager::getCurrentPlayer()->isLocked("fortmagma");
else
return (!m_editable ||
!PlayerManager::get()->getCurrentPlayer()->isLocked(id));
}
} // isTrackAvailable
// ----------------------------------------------------------------------------
std::vector<std::string> GrandPrixData::getTrackNames(bool includeLocked) const
/** Returns the list of tracks that is available (i.e. unlocked) of this
* grand prix.
* \param include_locked If data for locked tracks should be included or not.
* \return A copy of the list of available tracks in this grand prix.
*/
std::vector<std::string> GrandPrixData::getTrackNames(bool include_locked) const
{
std::vector<std::string> names;
for (unsigned int i = 0; i < m_tracks.size(); i++)
{
if(isTrackAvailable(m_tracks[i], includeLocked))
if(isTrackAvailable(m_tracks[i], include_locked))
names.push_back(m_tracks[i]);
}
return names;
}
} // getTrackNames
// ----------------------------------------------------------------------------
std::vector<int> GrandPrixData::getLaps(bool includeLocked) const
/** Returns the laps for each available track of the grand prix.
* \param include_locked If data for locked tracks should be included or not.
* \return a std::vector containing the laps for each grand prix.
*/
std::vector<int> GrandPrixData::getLaps(bool include_locked) const
{
std::vector<int> laps;
for (unsigned int i = 0; i< m_tracks.size(); i++)
if(isTrackAvailable(m_tracks[i], includeLocked))
if(isTrackAvailable(m_tracks[i], include_locked))
laps.push_back(m_laps[i]);
return laps;
}
} // getLaps
// ----------------------------------------------------------------------------
std::vector<bool> GrandPrixData::getReverse(bool includeLocked) const
/** Returns the reverse setting for each available grand prix.
* \param include_locked If data for locked tracks should be included or not.
* \return A copy of alist with the reverse status for each track.
*/
std::vector<bool> GrandPrixData::getReverse(bool include_locked) const
{
std::vector<bool> reverse;
for (unsigned int i = 0; i< m_tracks.size(); i++)
if(isTrackAvailable(m_tracks[i], includeLocked))
if(isTrackAvailable(m_tracks[i], include_locked))
reverse.push_back(m_reversed[i]);
return reverse;
}
} // getReverse
// ----------------------------------------------------------------------------
/** Returns true if this grand prix can be edited.
*/
bool GrandPrixData::isEditable() const
{
return m_editable;
}
} // isEditable
// ----------------------------------------------------------------------------
/** Returns the number of tracks in this grand prix.
* \param include_locked If data for locked tracks should be included or not.
*/
unsigned int GrandPrixData::getNumberOfTracks(bool includeLocked) const
{
if (includeLocked)
return m_tracks.size();
else
return getTrackNames(false).size();
}
} // getNumberOfTracks
// ----------------------------------------------------------------------------
/** Returns the (translated) name of the track with the specified index.
*/
irr::core::stringw GrandPrixData::getTrackName(const unsigned int track) const
{
assert(track < getNumberOfTracks(true));
Track* t = track_manager->getTrack(m_tracks[track]);
assert(t != NULL);
return t->getName();
}
} // getTrackName
// ----------------------------------------------------------------------------
const std::string& GrandPrixData::getTrackId(const unsigned int track) const

View File

@ -24,7 +24,6 @@
#include <string>
#include <vector>
#include "states_screens/dialogs/random_gp_dialog.hpp"
#include "utils/translation.hpp"
using irr::core::stringw;
@ -69,21 +68,35 @@ private:
*/
bool isTrackAvailable(const std::string &id, bool includeLocked) const;
public:
/** Used to define the reverse setting when creating a random GP:
* No reverse, all reverse (if available on the track), random
* selection. */
enum GPReverseType
{
GP_NO_REVERSE = 0,
GP_ALL_REVERSE = 1,
GP_RANDOM_REVERSE = 2
}; // GPReverseType
public:
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
# pragma warning(disable:4290)
#endif
/** Load the GrandPrixData from the given filename */
GrandPrixData(const std::string& filename);
/** Needed for simple creation of an instance of GrandPrixData */
GrandPrixData() {};
/** Creates a new random GP */
GrandPrixData(const unsigned int number_of_tracks,
const std::string& track_group,
const RandomGPInfoDialog::REVERSED use_reverse);
void changeTrackNumber(const unsigned int number_of_tracks,
const std::string& track_group);
void changeReverse(const RandomGPInfoDialog::REVERSED use_reverse);
void changeReverse(const GPReverseType use_reverse);
void createRandomGP(const unsigned int number_of_tracks,
const std::string& track_group,
const GPReverseType use_reverse,
bool new_tracks=false);
// Methods for the GP editor
void setId(const std::string& id);

View File

@ -34,7 +34,6 @@ const char* GrandPrixManager::SUFFIX = ".grandprix";
// ----------------------------------------------------------------------------
GrandPrixManager::GrandPrixManager()
{
m_random_gp = NULL; // better do it explicitly and avoid weird stuff
loadFiles();
} // GrandPrixManager
@ -42,10 +41,7 @@ GrandPrixManager::GrandPrixManager()
GrandPrixManager::~GrandPrixManager()
{
for(unsigned int i=0; i<m_gp_data.size(); i++)
{
delete m_gp_data[i];
}
delete m_random_gp;
} // ~GrandPrixManager
// ----------------------------------------------------------------------------
@ -97,7 +93,7 @@ void GrandPrixManager::load(const std::string& filename)
catch (std::runtime_error& e)
{
Log::error("GrandPrixManager",
"Ignoring grand prix %s (%s)\n", filename.c_str(), e.what());
"Ignoring Grand Prix %s (%s)\n", filename.c_str(), e.what());
}
} // load
@ -156,9 +152,6 @@ GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
// ----------------------------------------------------------------------------
GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s) const
{
if (s == "random")
return m_random_gp;
for(unsigned int i=0; i<m_gp_data.size(); i++)
{
if(m_gp_data[i]->getId() == s)

View File

@ -22,7 +22,8 @@
#include <vector>
#include <string>
#include "race/grand_prix_data.hpp"
#include "irrlicht.h"
class GrandPrixData;
/**
* \ingroup race
@ -47,10 +48,6 @@ private:
bool existsName(const irr::core::stringw& name) const;
public:
/** saved here by a random GP dialog to avoid dangling pinters or
* memory leaks */
GrandPrixData* m_random_gp;
GrandPrixManager();
~GrandPrixManager();
void reload();

View File

@ -53,8 +53,8 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident)
doInit();
m_curr_time = 0.0f;
m_gp = grand_prix_manager->getGrandPrix(gp_ident);
m_gp->checkConsistency();
m_gp = *grand_prix_manager->getGrandPrix(gp_ident);
m_gp.checkConsistency();
m_under_title = m_area.getHeight()/7;
m_over_body = m_area.getHeight()/7;
@ -72,7 +72,7 @@ GPInfoDialog::~GPInfoDialog()
{
GUIEngine::Screen* curr_screen = GUIEngine::getCurrentScreen();
if (curr_screen->getName() == "tracks.stkgui")
static_cast<TracksScreen*>(curr_screen)->setFocusOnGP(m_gp->getId());
static_cast<TracksScreen*>(curr_screen)->setFocusOnGP(m_gp.getId());
}
// ----------------------------------------------------------------------------
@ -81,7 +81,7 @@ void GPInfoDialog::addTitle()
{
core::rect< s32 > area_top(0, 0, m_area.getWidth(), m_under_title);
IGUIStaticText* title = GUIEngine::getGUIEnv()->addStaticText(
translations->fribidize(m_gp->getName()),
translations->fribidize(m_gp.getName()),
area_top, false, true, // border, word wrap
m_irrlicht_window);
title->setTabStop(false);
@ -92,7 +92,7 @@ void GPInfoDialog::addTitle()
void GPInfoDialog::addTracks()
{
const std::vector<std::string> tracks = m_gp->getTrackNames();
const std::vector<std::string> tracks = m_gp.getTrackNames();
const unsigned int track_amount = tracks.size();
int height_of_one_line = std::min((m_lower_bound - m_over_body)/(track_amount+1),
@ -185,7 +185,7 @@ void GPInfoDialog::addScreenshot()
m_screenshot_widget->m_h = m_area.getWidth()*3/8; // *(3/4)*(1/2)
}
Track* track = track_manager->getTrack(m_gp->getTrackNames()[0]);
Track* track = track_manager->getTrack(m_gp.getTrackNames()[0]);
m_screenshot_widget->m_properties[GUIEngine::PROP_ICON] = (track->getScreenshotFile().c_str());
m_screenshot_widget->setParent(m_irrlicht_window);
m_screenshot_widget->add();
@ -203,7 +203,7 @@ void GPInfoDialog::addButtons()
SavedGrandPrix* saved_gp = SavedGrandPrix::getSavedGP( StateManager::get()
->getActivePlayerProfile(0)
->getUniqueID(),
m_gp->getId(),
m_gp.getId(),
race_manager->getDifficulty(),
race_manager->getNumberOfKarts(),
race_manager->getNumLocalPlayers());
@ -250,7 +250,7 @@ void GPInfoDialog::addButtons()
void GPInfoDialog::onEnterPressedInternal()
{
// Save the GP id because dismiss() will destroy this instance
std::string gp_id = m_gp->getId();
std::string gp_id = m_gp.getId();
ModalDialog::dismiss();
// Disable accidentally unlocking of a challenge
PlayerManager::getCurrentPlayer()->setCurrentChallenge("");
@ -264,7 +264,7 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& event_
if (event_source == "start" || event_source == "continue")
{
// Save GP identifier, since dismiss will delete this object.
std::string gp_id = m_gp->getId();
std::string gp_id = m_gp.getId();
// Also create a copy of the string: it is a reference to data
// in a widget in the dialog - so if we call dismiss, this reference
// becomes invalid!
@ -288,7 +288,7 @@ void GPInfoDialog::onUpdate(float dt)
m_curr_time += dt;
int frameAfter = (int)(m_curr_time / 1.5f);
const std::vector<std::string> tracks = m_gp->getTrackNames();
const std::vector<std::string> tracks = m_gp.getTrackNames();
if (frameAfter >= (int)tracks.size())
{
frameAfter = 0;

View File

@ -20,7 +20,7 @@
#define HEADER_GP_INFO_DIALOG_HPP
#include "guiengine/modaldialog.hpp"
// Don't include grand_prix_data.hpp here or the compilation will fail
#include "race/grand_prix_data.hpp"
class GrandPrixData;
@ -39,7 +39,9 @@ class GPInfoDialog : public GUIEngine::ModalDialog
protected: // Necessary for RandomGPInfoDialog
GUIEngine::IconButtonWidget* m_screenshot_widget;
float m_curr_time;
GrandPrixData* m_gp;
/** The grand prix data. */
GrandPrixData m_gp;
/** height of the separator over the body */
int m_over_body;

View File

@ -33,11 +33,12 @@ using irr::gui::IGUIStaticText;
typedef GUIEngine::SpinnerWidget Spinner;
RandomGPInfoDialog::RandomGPInfoDialog()
{
// Defaults - loading selection from last time frrom a file would be better
m_number_of_tracks = 2; // We can assume that there are at least 2 standard tracks
m_trackgroup = "standard";
m_use_reverse = NO_REVERSE;
m_use_reverse = GrandPrixData::GP_NO_REVERSE;
doInit();
m_curr_time = 0.0f;
@ -46,14 +47,7 @@ RandomGPInfoDialog::RandomGPInfoDialog()
m_over_body = m_area.getHeight()/7 + SPINNER_HEIGHT + 10; // 10px space
m_lower_bound = m_area.getHeight()*6/7;
// The GP manager is be used to make the GP live longer than this dialog
if (grand_prix_manager->m_random_gp)
{
delete grand_prix_manager->m_random_gp;
grand_prix_manager->m_random_gp = NULL;
}
m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
grand_prix_manager->m_random_gp = m_gp;
m_gp.createRandomGP(m_number_of_tracks, m_trackgroup, m_use_reverse);
addTitle();
addSpinners();
@ -141,15 +135,17 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent(
{
if (eventSource == "start")
{
// Save GP data, since dismiss will delete this object.
GrandPrixData gp = m_gp;
ModalDialog::dismiss();
race_manager->startGP(grand_prix_manager->m_random_gp, false, false);
race_manager->startGP(&gp, false, false);
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "Number of tracks")
{
// The old gp can be reused because there's only track deletion/adding
m_number_of_tracks = getWidget<Spinner>("Number of tracks")->getValue();
m_gp->changeTrackNumber(m_number_of_tracks, m_trackgroup);
m_gp.changeTrackNumber(m_number_of_tracks, m_trackgroup);
addTracks();
}
else if (eventSource == "Trackgroup")
@ -171,22 +167,22 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent(
if (s->getValue() > (signed)max)
s->setValue(max);
delete m_gp;
m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
grand_prix_manager->m_random_gp = m_gp;
// Create a new (i.e. with new tracks) random gp, since the old
// tracks might not all belong to the newly selected group.
m_gp.createRandomGP(m_number_of_tracks, m_trackgroup, m_use_reverse,
/*new_tracks*/true);
addTracks();
}
else if (eventSource == "reverse")
{
Spinner* r = getWidget<Spinner>("reverse");
m_use_reverse = static_cast<REVERSED>(r->getValue());
m_gp->changeReverse(m_use_reverse);
m_use_reverse = static_cast<GrandPrixData::GPReverseType>(r->getValue());
m_gp.changeReverse(m_use_reverse);
}
else if (eventSource == "reload")
{
delete m_gp;
m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
grand_prix_manager->m_random_gp = m_gp;
m_gp.createRandomGP(m_number_of_tracks, m_trackgroup, m_use_reverse,
/*new_tracks*/true);
addTracks();
}

View File

@ -24,17 +24,15 @@
class RandomGPInfoDialog : public GPInfoDialog
{
public:
enum REVERSED
{
NO_REVERSE = 0,
ALL_REVERSE = 1,
MIXED = 2
};
private:
/** How many tracks to pick. */
unsigned int m_number_of_tracks;
/** Name of the track group from which to pick tracks. */
std::string m_trackgroup;
REVERSED m_use_reverse;
/** How reverse settings should be determined. */
GrandPrixData::GPReverseType m_use_reverse;
public:
static const int SPINNER_HEIGHT = 40;

View File

@ -108,7 +108,7 @@ RaceGUI::RaceGUI()
int n = race_manager->getNumberOfKarts();
m_animation_states.resize(n);
m_rank_animation_start_times.resize(n);
m_rank_animation_duration.resize(n);
m_last_ranks.resize(n);
} // RaceGUI
@ -211,7 +211,7 @@ void RaceGUI::renderPlayerView(const Camera *camera, float dt)
if(!World::getWorld()->isRacePhase()) return;
drawPowerupIcons (kart, viewport, scaling);
drawSpeedEnergyRank(kart, viewport, scaling);
drawSpeedEnergyRank(kart, viewport, scaling, dt);
if (!m_is_tutorial)
drawLap(kart, viewport, scaling);
@ -601,10 +601,18 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart,
} // drawEnergyMeter
//-----------------------------------------------------------------------------
/** Draws the rank of a player.
* \param kart The kart of the player.
* \param offset Offset of top left corner for this display (for splitscreen).
* \param min_ratio Scaling of the screen (for splitscreen).
* \param meter_width Width of the meter (inside which the rank is shown).
* \param meter_height Height of the meter (inside which the rank is shown).
* \param dt Time step size.
*/
void RaceGUI::drawRank(const AbstractKart *kart,
const core::vector2df &offset,
float min_ratio, int meter_width,
int meter_height)
int meter_height, float dt)
{
// Draw rank
WorldWithRank *world = dynamic_cast<WorldWithRank*>(World::getWorld());
@ -617,10 +625,14 @@ void RaceGUI::drawRank(const AbstractKart *kart,
{
if (m_last_ranks[id] != kart->getPosition())
{
m_rank_animation_start_times[id] = world->getTime();
m_rank_animation_duration[id] = 0.0f;
m_animation_states[id] = AS_SMALLER;
}
}
else
{
m_rank_animation_duration[id] += dt;
}
float scale = 1.0f;
int rank = kart->getPosition();
@ -628,13 +640,12 @@ void RaceGUI::drawRank(const AbstractKart *kart,
const float MIN_SHRINK = 0.3f;
if (m_animation_states[id] == AS_SMALLER)
{
scale = 1.0f - (world->getTime() - m_rank_animation_start_times[id])
/ DURATION;
scale = 1.0f - m_rank_animation_duration[id]/ DURATION;
rank = m_last_ranks[id];
if (scale < MIN_SHRINK)
{
m_animation_states[id] = AS_BIGGER;
m_rank_animation_start_times[id] = world->getTime();
m_rank_animation_duration[id] = 0.0f;
// Store the new rank
m_last_ranks[id] = kart->getPosition();
scale = MIN_SHRINK;
@ -642,8 +653,7 @@ void RaceGUI::drawRank(const AbstractKart *kart,
}
else if (m_animation_states[id] == AS_BIGGER)
{
scale = (world->getTime() - m_rank_animation_start_times[id])
/ DURATION + MIN_SHRINK;
scale = m_rank_animation_duration[id] / DURATION + MIN_SHRINK;
rank = m_last_ranks[id];
if (scale > 1.0f)
{
@ -680,10 +690,12 @@ void RaceGUI::drawRank(const AbstractKart *kart,
* \param kart The kart for which to show the data.
* \param viewport The viewport to use.
* \param scaling Which scaling to apply to the speedometer.
* \param dt Time step size.
*/
void RaceGUI::drawSpeedEnergyRank(const AbstractKart* kart,
const core::recti &viewport,
const core::vector2df &scaling)
const core::vector2df &scaling,
float dt)
{
float min_ratio = std::min(scaling.X, scaling.Y);
const int SPEEDWIDTH = 128;
@ -712,7 +724,7 @@ void RaceGUI::drawSpeedEnergyRank(const AbstractKart* kart,
const float speed = kart->getSpeed();
drawRank(kart, offset, min_ratio, meter_width, meter_height);
drawRank(kart, offset, min_ratio, meter_width, meter_height, dt);
if(speed <=0) return; // Nothing to do if speed is negative.

View File

@ -89,8 +89,8 @@ private:
enum AnimationState {AS_NONE, AS_SMALLER, AS_BIGGER};
std::vector<AnimationState> m_animation_states;
/** When the animation state was changed. */
std::vector<float> m_rank_animation_start_times;
/** How long the rank animation has been shown. */
std::vector<float> m_rank_animation_duration;
/** Stores the previous rank for each kart. Used for the rank animation. */
std::vector<int> m_last_ranks;
@ -103,14 +103,14 @@ private:
const core::vector2df &scaling);
void drawSpeedEnergyRank (const AbstractKart* kart,
const core::recti &viewport,
const core::vector2df &scaling);
const core::vector2df &scaling, float dt);
void drawLap (const AbstractKart* kart,
const core::recti &viewport,
const core::vector2df &scaling);
void drawRank (const AbstractKart *kart,
const core::vector2df &offset,
float min_ratio, int meter_width,
int meter_height);
int meter_height, float dt);
/** Display items that are shown once only (for all karts). */
void drawGlobalMiniMap ();

View File

@ -31,13 +31,13 @@
* classes.
*/
template <typename T>
class Singleton
class AbstractSingleton
{
protected:
/*! \brief Constructor */
Singleton () { m_singleton = NULL; }
AbstractSingleton() { m_singleton = NULL; }
/*! \brief Destructor */
virtual ~Singleton ()
virtual ~AbstractSingleton()
{
Log::info("Singleton", "Destroyed singleton.");
}
@ -80,6 +80,44 @@ class Singleton
static T *m_singleton;
};
template <typename T> T *AbstractSingleton<T>::m_singleton = NULL;
template <typename T>
class Singleton
{
protected:
/*! \brief Constructor */
Singleton() { m_singleton = NULL; }
/*! \brief Destructor */
virtual ~Singleton()
{
Log::info("Singleton", "Destroyed singleton.");
}
public:
/*! \brief Used to get the instance. */
static T *getInstance()
{
if (m_singleton == NULL)
m_singleton = new T;
return m_singleton;
}
/*! \brief Used to kill the singleton, if needed. */
static void kill()
{
if (m_singleton)
{
delete m_singleton;
m_singleton = NULL;
}
}
private:
static T *m_singleton;
};
template <typename T> T *Singleton<T>::m_singleton = NULL;
#endif // SINGLETON_HPP