Remove stk_mesh*

This commit is contained in:
Benau 2018-01-03 14:40:34 +08:00
parent 345f2bc64b
commit 2eabf87ffe
7 changed files with 3 additions and 1135 deletions

View File

@ -24,7 +24,6 @@
#include "graphics/central_settings.hpp" #include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/stk_mesh.hpp"
#include "utils/profiler.hpp" #include "utils/profiler.hpp"
#include "utils/cpp2011.hpp" #include "utils/cpp2011.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"

View File

@ -27,6 +27,7 @@
#include "graphics/glwrap.hpp" #include "graphics/glwrap.hpp"
#include "graphics/graphics_restrictions.hpp" #include "graphics/graphics_restrictions.hpp"
#include "graphics/light.hpp" #include "graphics/light.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp" #include "graphics/material_manager.hpp"
#include "graphics/particle_kind_manager.hpp" #include "graphics/particle_kind_manager.hpp"
#include "graphics/per_camera_node.hpp" #include "graphics/per_camera_node.hpp"
@ -40,7 +41,6 @@
#include "graphics/sp/sp_mesh.hpp" #include "graphics/sp/sp_mesh.hpp"
#include "graphics/sp/sp_mesh_node.hpp" #include "graphics/sp/sp_mesh_node.hpp"
#include "graphics/sp/sp_texture_manager.hpp" #include "graphics/sp/sp_texture_manager.hpp"
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/stk_tex_manager.hpp" #include "graphics/stk_tex_manager.hpp"
#include "graphics/stk_texture.hpp" #include "graphics/stk_texture.hpp"
#include "graphics/sun.hpp" #include "graphics/sun.hpp"
@ -1186,9 +1186,8 @@ scene::ISceneNode *IrrDriver::addMesh(scene::IMesh *mesh,
} }
else else
{ {
node = new STKMeshSceneNode(mesh, parent, m_scene_manager, -1, Log::warn("IrrDriver", "Use only spm in glsl");
debug_name, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), return NULL;
core::vector3df(1.0f, 1.0f, 1.0f), true);
} }
node->drop(); node->drop();

View File

@ -32,7 +32,6 @@
#include "graphics/rtts.hpp" #include "graphics/rtts.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/skybox.hpp" #include "graphics/skybox.hpp"
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/spherical_harmonics.hpp" #include "graphics/spherical_harmonics.hpp"
#include "graphics/sp/sp_base.hpp" #include "graphics/sp/sp_base.hpp"
#include "graphics/sp/sp_shader.hpp" #include "graphics/sp/sp_shader.hpp"

View File

@ -1,485 +0,0 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_mesh.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/shaders.hpp"
#include "graphics/stk_tex_manager.hpp"
#include <ISceneManager.h>
#include <IMaterialRenderer.h>
// ============================================================================
Material::ShaderType getMeshMaterialFromType(video::E_MATERIAL_TYPE material_type,
video::E_VERTEX_TYPE tp,
Material* material,
Material* layer2_material)
{
if (layer2_material != NULL &&
layer2_material->getShaderType() == Material::SHADERTYPE_SPLATTING)
return Material::SHADERTYPE_SPLATTING;
if (tp == video::EVT_SKINNED_MESH)
{
switch (material->getShaderType())
{
case Material::SHADERTYPE_SOLID:
if (material_type == Shaders::getShader(ES_NORMAL_MAP))
return Material::SHADERTYPE_NORMAL_MAP_SKINNED_MESH;
else
return Material::SHADERTYPE_SOLID_SKINNED_MESH;
case Material::SHADERTYPE_ALPHA_TEST:
return Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH;
case Material::SHADERTYPE_SOLID_UNLIT:
return Material::SHADERTYPE_SOLID_UNLIT_SKINNED_MESH;
default:
return Material::SHADERTYPE_SOLID_SKINNED_MESH;
}
}
switch (material->getShaderType())
{
default:
return material->getShaderType();
case Material::SHADERTYPE_SOLID:
if (material_type == Shaders::getShader(ES_NORMAL_MAP))
return Material::SHADERTYPE_NORMAL_MAP;
else if (tp == video::EVT_2TCOORDS)
return Material::SHADERTYPE_DETAIL_MAP;
return Material::SHADERTYPE_SOLID;
}
} // getMeshMaterialFromType
// ----------------------------------------------------------------------------
TransparentMaterial getTransparentMaterialFromType(video::E_MATERIAL_TYPE type,
video::E_VERTEX_TYPE tp,
f32 MaterialTypeParam,
Material* material)
{
if (tp == video::EVT_SKINNED_MESH)
return TM_TRANSLUCENT_SKN;
if (type == Shaders::getShader(ES_DISPLACE))
{
if (CVS->isDefferedEnabled())
return TM_DISPLACEMENT;
else if (tp == video::EVT_2TCOORDS)
return TM_TRANSLUCENT_2TC;
else
return TM_TRANSLUCENT_STD;
}
if (material->getShaderType() == Material::SHADERTYPE_ADDITIVE)
return TM_ADDITIVE;
return TM_DEFAULT;
}
// ----------------------------------------------------------------------------
video::E_VERTEX_TYPE getVTXTYPEFromStride(size_t stride)
{
if (stride == sizeof(video::S3DVertex))
return video::EVT_STANDARD;
else if (stride == sizeof(video::S3DVertex2TCoords))
return video::EVT_2TCOORDS;
assert(stride == sizeof(video::S3DVertexTangents));
return video::EVT_TANGENTS;
} // getVTXTYPEFromStride
// ----------------------------------------------------------------------------
GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type)
{
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
assert(vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
switch (type)
{
case video::EVT_STANDARD:
// Position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
getVertexPitchFromType(type), 0);
// Normal
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
getVertexPitchFromType(type), (GLvoid*)12);
// Color
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE,
getVertexPitchFromType(type), (GLvoid*)24);
// Texcoord
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE,
getVertexPitchFromType(type), (GLvoid*)28);
break;
case video::EVT_2TCOORDS:
// Position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
getVertexPitchFromType(type), 0);
// Normal
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
getVertexPitchFromType(type), (GLvoid*)12);
// Color
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE,
getVertexPitchFromType(type), (GLvoid*)24);
// Texcoord
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE,
getVertexPitchFromType(type), (GLvoid*)28);
// SecondTexcoord
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE,
getVertexPitchFromType(type), (GLvoid*)36);
break;
case video::EVT_TANGENTS:
// Position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), 0);
// Normal
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)12);
// Color
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(type), (GLvoid*)24);
// Texcoord
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)28);
// Tangent
glEnableVertexAttribArray(5);
glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)36);
// Bitangent
glEnableVertexAttribArray(6);
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)48);
break;
case video::EVT_SKINNED_MESH:
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)12);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(type), (GLvoid*)24);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)28);
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)36);
glEnableVertexAttribArray(11);
glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)48);
glEnableVertexAttribArray(5);
glVertexAttribIPointer(5, 4, GL_SHORT, getVertexPitchFromType(type), (GLvoid*)64);
glEnableVertexAttribArray(6);
glVertexAttribPointer(6, 4, GL_HALF_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)72);
break;
default:
assert(0 && "Wrong vertex type");
}
assert(idx);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx);
return vao;
} // createVAO
// ----------------------------------------------------------------------------
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb, const std::string& debug_name,
RenderInfo* render_info)
{
GLMesh result = {};
result.m_material = NULL;
result.m_render_info = NULL;
if (!mb)
return result;
result.mb = mb;
if (render_info != NULL)
{
result.m_render_info = render_info;
result.m_material = material_manager->getMaterialFor(mb
->getMaterial().getTexture(0), mb);
}
#ifdef DEBUG
result.debug_name = debug_name;
#endif
result.IndexCount = mb->getIndexCount();
switch (mb->getIndexType())
{
case irr::video::EIT_16BIT:
{
result.IndexType = GL_UNSIGNED_SHORT;
break;
}
case irr::video::EIT_32BIT:
{
result.IndexType = GL_UNSIGNED_INT;
break;
}
default:
{
assert(0 && "Wrong index size");
}
}
result.VAOType = mb->getVertexType();
result.Stride = getVertexPitchFromType(result.VAOType);
result.IndexCount = mb->getIndexCount();
switch (mb->getPrimitiveType())
{
case scene::EPT_POINTS:
result.PrimitiveType = GL_POINTS;
break;
case scene::EPT_TRIANGLE_STRIP:
result.PrimitiveType = GL_TRIANGLE_STRIP;
break;
case scene::EPT_TRIANGLE_FAN:
result.PrimitiveType = GL_TRIANGLE_FAN;
break;
case scene::EPT_LINES:
result.PrimitiveType = GL_LINES;
break;
case scene::EPT_TRIANGLES:
result.PrimitiveType = GL_TRIANGLES;
break;
case scene::EPT_POINT_SPRITES:
case scene::EPT_LINE_LOOP:
case scene::EPT_POLYGON:
case scene::EPT_LINE_STRIP:
case scene::EPT_QUAD_STRIP:
case scene::EPT_QUADS:
assert(0 && "Unsupported primitive type");
}
for (unsigned i = 0; i < 8; i++)
result.textures[i] = mb->getMaterial().getTexture(i);
result.texture_trans = core::vector2df(0.0f, 0.0f);
return result;
} // allocateMeshBuffer
// ----------------------------------------------------------------------------
static size_t getUnsignedSize(unsigned tp)
{
switch (tp)
{
case GL_UNSIGNED_SHORT:
return sizeof(u16);
case GL_UNSIGNED_INT:
return sizeof(u32);
default:
assert(0 && "Unsupported index type");
return 0;
}
} // getUnsignedSize
// ----------------------------------------------------------------------------
void fillLocalBuffer(GLMesh &mesh, scene::IMeshBuffer* mb)
{
glBindVertexArray(0);
glGenBuffers(1, &(mesh.vertex_buffer));
glGenBuffers(1, &(mesh.index_buffer));
glBindBuffer(GL_ARRAY_BUFFER, mesh.vertex_buffer);
const void* vertices = mb->getVertices();
const u32 vertexCount = mb->getVertexCount();
// This can happen for certain debug structures, e.g. ShowCurve
if (vertexCount == 0)
return;
const c8* vbuf = static_cast<const c8*>(vertices);
glBufferData(GL_ARRAY_BUFFER, vertexCount * mesh.Stride, vbuf,
GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.index_buffer);
const void* indices = mb->getIndices();
mesh.IndexCount = mb->getIndexCount();
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
mesh.IndexCount * getUnsignedSize(mesh.IndexType),
indices, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
} // fillLocalBuffer
// ----------------------------------------------------------------------------
core::matrix4 computeMVP(const core::matrix4 &model_matrix)
{
core::matrix4 ModelViewProjectionMatrix = irr_driver->getProjMatrix();
ModelViewProjectionMatrix *= irr_driver->getViewMatrix();
ModelViewProjectionMatrix *= model_matrix;
return ModelViewProjectionMatrix;
} // computeMVP
// ----------------------------------------------------------------------------
core::vector3df getWindDir()
{
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
GrassShaderProvider *gsp =
(GrassShaderProvider *)Shaders::getCallback(ES_GRASS);
return (gsp->getSpeed() * time * vector3df(1., 0., 0.));
} // getWindDir
// ----------------------------------------------------------------------------
bool isObject(video::E_MATERIAL_TYPE type)
{
if (type == Shaders::getShader(ES_OBJECTPASS))
return true;
if (type == Shaders::getShader(ES_OBJECTPASS_REF))
return true;
if (type == Shaders::getShader(ES_OBJECTPASS_RIMLIT))
return true;
if (type == Shaders::getShader(ES_NORMAL_MAP))
return true;
if (type == Shaders::getShader(ES_SPHERE_MAP))
return true;
if (type == Shaders::getShader(ES_SPLATTING))
return true;
if (type == Shaders::getShader(ES_GRASS))
return true;
if (type == Shaders::getShader(ES_GRASS_REF))
return true;
if (type == Shaders::getShader(ES_DISPLACE))
return true;
if (type == Shaders::getShader(ES_OBJECT_UNLIT))
return true;
if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
return true;
if (type == video::EMT_ONETEXTURE_BLEND)
return true;
if (type == video::EMT_TRANSPARENT_ADD_COLOR)
return true;
if (type == video::EMT_SOLID)
return true;
if (type == video::EMT_LIGHTMAP_LIGHTING)
return true;
if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF)
return true;
return false;
} // isObject
// ----------------------------------------------------------------------------
static void setTexture(GLMesh &mesh, unsigned i, bool is_srgb,
const std::string &mat_name)
{
if (!mesh.textures[i])
{
Log::error("STKMesh", "Missing texture %d for material %s", i,
mat_name.c_str());
// use unicolor texture to replace missing texture
mesh.textures[i] =
STKTexManager::getInstance()->getUnicolorTexture(video::SColor(255, 127, 127, 127));
}
#if !defined(USE_GLES2)
if (CVS->isAZDOEnabled())
{
if (!mesh.TextureHandles[i])
{
mesh.TextureHandles[i] = mesh.textures[i]->getHandle();
}
}
#endif
} // setTexture
// ----------------------------------------------------------------------------
static std::string getShaderTypeName(Material::ShaderType mat)
{
switch (mat)
{
default:
case Material::SHADERTYPE_SOLID:
return "Solid";
case Material::SHADERTYPE_ALPHA_TEST:
return "Alpha Test";
case Material::SHADERTYPE_VEGETATION:
return "Grass";
case Material::SHADERTYPE_SPHERE_MAP:
return "Sphere Map";
case Material::SHADERTYPE_SOLID_UNLIT:
return "Unlit";
case Material::SHADERTYPE_DETAIL_MAP:
return "Detail";
case Material::SHADERTYPE_NORMAL_MAP:
return "Normal";
case Material::SHADERTYPE_SPLATTING:
return "Splatting";
}
} // getShaderTypeName
// ----------------------------------------------------------------------------
void initTextures(GLMesh &mesh, Material::ShaderType mat)
{
switch (mat)
{
default:
case Material::SHADERTYPE_SOLID:
case Material::SHADERTYPE_ALPHA_TEST:
case Material::SHADERTYPE_SPHERE_MAP:
case Material::SHADERTYPE_SOLID_UNLIT:
case Material::SHADERTYPE_VEGETATION:
case Material::SHADERTYPE_SOLID_SKINNED_MESH:
case Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH:
case Material::SHADERTYPE_SOLID_UNLIT_SKINNED_MESH:
setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 2, false, getShaderTypeName(mat));
break;
case Material::SHADERTYPE_DETAIL_MAP:
case Material::SHADERTYPE_NORMAL_MAP:
case Material::SHADERTYPE_NORMAL_MAP_SKINNED_MESH:
setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 2, false, getShaderTypeName(mat));
setTexture(mesh, 3, false, getShaderTypeName(mat));
break;
case Material::SHADERTYPE_SPLATTING:
setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 2, true, getShaderTypeName(mat));
setTexture(mesh, 3, true, getShaderTypeName(mat));
setTexture(mesh, 4, true, getShaderTypeName(mat));
setTexture(mesh, 5, true, getShaderTypeName(mat));
setTexture(mesh, 6, false, getShaderTypeName(mat));
setTexture(mesh, 7, false, getShaderTypeName(mat));
break;
}
} // initTextures
// ----------------------------------------------------------------------------
void initTexturesTransparent(GLMesh &mesh)
{
if (!mesh.textures[0])
{
mesh.textures[0] = STKTexManager::getInstance()->getUnicolorTexture(video::SColor(255, 255, 255, 255));
}
#if !defined(USE_GLES2)
if (CVS->isAZDOEnabled())
{
if (!mesh.TextureHandles[0])
{
mesh.TextureHandles[0] = mesh.textures[0]->getHandle();
}
}
#endif
} // initTexturesTransparent
#endif // !SERVER_ONLY

View File

@ -1,262 +0,0 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_STK_MESH_H
#define HEADER_STK_MESH_H
#include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"
#include "utils/singleton.hpp"
#include <tuple>
#include <IMeshSceneNode.h>
#include <IMesh.h>
#include "../lib/irrlicht/source/Irrlicht/CMeshSceneNode.h"
#include <vector>
class RenderInfo;
enum TransparentMaterial
{
TM_DEFAULT,
TM_ADDITIVE,
TM_DISPLACEMENT,
TM_TRANSLUCENT_SKN,
TM_TRANSLUCENT_STD,
TM_TRANSLUCENT_TAN,
TM_TRANSLUCENT_2TC,
TM_COUNT
}; // TransparentMaterial
struct GLMesh
{
GLuint vao;
GLuint vertex_buffer;
GLuint index_buffer;
video::ITexture *textures[8];
GLenum PrimitiveType;
GLenum IndexType;
unsigned int IndexCount;
unsigned int Stride;
core::vector2df texture_trans;
unsigned int vaoBaseVertex;
intptr_t vaoOffset;
video::E_VERTEX_TYPE VAOType;
uint64_t TextureHandles[8];
scene::IMeshBuffer *mb;
RenderInfo* m_render_info;
Material* m_material;
#ifdef DEBUG
std::string debug_name;
#endif
}; // GLMesh
// ----------------------------------------------------------------------------
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb,
const std::string& debug_name,
RenderInfo* render_info);
void fillLocalBuffer(GLMesh &, scene::IMeshBuffer* mb);
video::E_VERTEX_TYPE getVTXTYPEFromStride(unsigned int stride);
GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type);
core::matrix4 computeMVP(const core::matrix4 &ModelViewProjectionMatrix);
bool isObject(video::E_MATERIAL_TYPE type);
core::vector3df getWindDir();
// ----------------------------------------------------------------------------
class STKMeshCommon
{
protected:
std::string m_debug_name;
public:
PtrVector<GLMesh, REF> MeshSolidMaterial[Material::SHADERTYPE_COUNT];
PtrVector<GLMesh, REF> TransparentMesh[TM_COUNT];
virtual void updateNoGL() = 0;
virtual void updateGL() = 0;
virtual bool glow() const = 0;
virtual bool isImmediateDraw() const { return false; }
const std::string& getMeshDebugName() const { return m_debug_name; }
}; // STKMeshCommon
// ----------------------------------------------------------------------------
template<typename T, typename... Args>
class MeshList : public Singleton<T>
{
public:
std::vector<std::tuple<Args...> > SolidPass, Shadows[4], RSM;
void clear()
{
SolidPass.clear();
RSM.clear();
for (unsigned i = 0; i < 4; i++)
Shadows[i].clear();
}
}; // MeshList
// ----------------------------------------------------------------------------
class ListSkinnedSolid : public MeshList<ListSkinnedSolid, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListSkinnedAlphaRef : public MeshList<ListSkinnedAlphaRef, GLMesh *,
core::matrix4, core::matrix4,
core::vector2df, core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListSkinnedNormalMap : public MeshList<ListSkinnedNormalMap, GLMesh *,
core::matrix4, core::matrix4,
core::vector2df, core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListSkinnedUnlit : public MeshList<ListSkinnedUnlit, GLMesh *,
core::matrix4, core::matrix4,
core::vector2df, core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListMatDefault : public MeshList<ListMatDefault, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatAlphaRef : public MeshList<ListMatAlphaRef, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatNormalMap : public MeshList<ListMatNormalMap, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatGrass : public MeshList<ListMatGrass, GLMesh *, core::matrix4,
core::matrix4, core::vector3df, core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatSphereMap : public MeshList<ListMatSphereMap, GLMesh *,
core::matrix4, core::matrix4,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatSplatting : public MeshList<ListMatSplatting, GLMesh *,
core::matrix4, core::matrix4>
{};
// ----------------------------------------------------------------------------
class ListMatUnlit : public MeshList<ListMatUnlit, GLMesh *, core::matrix4,
core::matrix4, core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatDetails : public MeshList<ListMatDetails, GLMesh *, core::matrix4,
core::matrix4, core::vector2df>
{};
// ----------------------------------------------------------------------------
// Transparent
template <typename T, typename ...Args>
class MiscList : public Singleton<T>, public std::vector<std::tuple<Args...> >
{};
// ----------------------------------------------------------------------------
class ListBlendTransparent : public MiscList<ListBlendTransparent, GLMesh *,
core::matrix4, core::vector2df,
float>
{};
// ----------------------------------------------------------------------------
class ListAdditiveTransparent : public MiscList<ListAdditiveTransparent,
GLMesh *, core::matrix4,
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucentSkinned : public MiscList<ListTranslucentSkinned,
GLMesh *, core::matrix4,
core::vector2df, int, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucentStandard : public MiscList<ListTranslucentStandard,
GLMesh *, core::matrix4,
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucentTangents : public MiscList<ListTranslucentTangents,
GLMesh *, core::matrix4,
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucent2TCoords : public MiscList<ListTranslucent2TCoords,
GLMesh *, core::matrix4,
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog,
GLMesh *, core::matrix4,
core::vector2df, float, float,
float, float, float,
video::SColorf>
{};
// ----------------------------------------------------------------------------
class ListAdditiveTransparentFog : public MiscList<ListAdditiveTransparentFog,
GLMesh *, core::matrix4,
core::vector2df, float, float,
float, float, float,
video::SColorf>
{};
// ----------------------------------------------------------------------------
class ListDisplacement : public MiscList<ListDisplacement, GLMesh *,
core::matrix4>
{};
// ----------------------------------------------------------------------------
Material::ShaderType getMeshMaterialFromType(video::E_MATERIAL_TYPE MaterialType,
video::E_VERTEX_TYPE tp,
Material* material,
Material* layer2Material);
// ----------------------------------------------------------------------------
TransparentMaterial getTransparentMaterialFromType(video::E_MATERIAL_TYPE,
video::E_VERTEX_TYPE tp,
f32 MaterialTypeParam,
Material* material);
// ----------------------------------------------------------------------------
void initTextures(GLMesh &mesh, Material::ShaderType);
// ----------------------------------------------------------------------------
void initTexturesTransparent(GLMesh &mesh);
#endif // STKMESH_H

View File

@ -1,309 +0,0 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/render_info.hpp"
#include "graphics/rtts.hpp"
#include "graphics/shaders.hpp"
#include "tracks/track.hpp"
#include "modes/world.hpp"
#include <IMaterialRenderer.h>
#include <ISceneManager.h>
// ============================================================================
class ColorizeShader : public Shader<ColorizeShader, core::matrix4,
video::SColorf>
{
public:
ColorizeShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "colorize.frag");
assignUniforms("ModelMatrix", "col");
}
}; // ColorizeShader
// ============================================================================
STKMeshSceneNode::STKMeshSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr,
irr::s32 id, const std::string& debug_name,
const irr::core::vector3df& position,
const irr::core::vector3df& rotation,
const irr::core::vector3df& scale, bool createGLMeshes, RenderInfo* render_info, bool all_parts_colorized) :
CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
{
isDisplacement = false;
immediate_draw = false;
update_each_frame = false;
isGlow = false;
m_got_animated_matrix = false;
m_debug_name = debug_name;
if (createGLMeshes)
this->createGLMeshes(render_info, all_parts_colorized);
}
void STKMeshSceneNode::setReloadEachFrame(bool val)
{
update_each_frame = val;
if (val)
immediate_draw = true;
}
void STKMeshSceneNode::createGLMeshes(RenderInfo* render_info, bool all_parts_colorized)
{
const u32 mb_count = Mesh->getMeshBufferCount();
for (u32 i = 0; i < mb_count; ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
GLmeshes.push_back(allocateMeshBuffer(mb, m_debug_name, NULL));
}
isMaterialInitialized = false;
isGLInitialized = false;
}
void STKMeshSceneNode::cleanGLMeshes()
{
for (u32 i = 0; i < GLmeshes.size(); ++i)
{
GLMesh mesh = GLmeshes[i];
if (!mesh.vertex_buffer)
continue;
if (mesh.vao)
glDeleteVertexArrays(1, &(mesh.vao));
if (mesh.vertex_buffer)
glDeleteBuffers(1, &(mesh.vertex_buffer));
if (mesh.index_buffer)
glDeleteBuffers(1, &(mesh.index_buffer));
}
GLmeshes.clear();
for (unsigned i = 0; i < Material::SHADERTYPE_COUNT; i++)
MeshSolidMaterial[i].clearWithoutDeleting();
for (unsigned i = 0; i < TM_COUNT; i++)
TransparentMesh[i].clearWithoutDeleting();
}
void STKMeshSceneNode::setMesh(irr::scene::IMesh* mesh)
{
CMeshSceneNode::setMesh(mesh);
cleanGLMeshes();
createGLMeshes();
}
STKMeshSceneNode::~STKMeshSceneNode()
{
cleanGLMeshes();
}
void STKMeshSceneNode::drawGlow(const GLMesh &mesh)
{
assert(mesh.VAOType == video::EVT_STANDARD);
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
unsigned int count = mesh.IndexCount;
ColorizeShader::getInstance()->setUniforms(AbsoluteTransformation, video::SColorf(glowcolor.getRed() / 255.f, glowcolor.getGreen() / 255.f, glowcolor.getBlue() / 255.f));
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
}
void STKMeshSceneNode::updatevbo()
{
for (unsigned i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
GLMesh &mesh = GLmeshes[i];
glDeleteBuffers(1, &(mesh.vertex_buffer));
glDeleteBuffers(1, &(mesh.index_buffer));
glDeleteVertexArrays(1, &(mesh.vao));
fillLocalBuffer(mesh, mb);
mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, mb->getVertexType());
}
}
void STKMeshSceneNode::updateNoGL()
{
Box = Mesh->getBoundingBox();
if (!isMaterialInitialized)
{
irr::video::IVideoDriver* driver = irr_driver->getVideoDriver();
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType;
f32 MaterialTypeParam = mb->getMaterial().MaterialTypeParam;
video::IMaterialRenderer* rnd = driver->getMaterialRenderer(type);
if (!isObject(type))
{
#ifdef DEBUG
Log::warn("material", "Unhandled (static) material type : %d", type);
#endif
continue;
}
GLMesh &mesh = GLmeshes[i];
video::E_VERTEX_TYPE vt = mb->getVertexType();
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
if (mesh.m_render_info != NULL && mesh.m_render_info->isTransparent() && !rnd->isTransparent())
{
assert(!immediate_draw);
if (mesh.VAOType == video::EVT_TANGENTS)
TransparentMesh[TM_TRANSLUCENT_TAN].push_back(&mesh);
else
TransparentMesh[TM_TRANSLUCENT_STD].push_back(&mesh);
}
else if (rnd->isTransparent())
{
TransparentMaterial TranspMat = getTransparentMaterialFromType(type, vt, MaterialTypeParam, material);
if (!immediate_draw)
TransparentMesh[TranspMat].push_back(&mesh);
else
additive = (TranspMat == TM_ADDITIVE);
}
else
{
assert(!isDisplacement);
Material* material2 = NULL;
if (mb->getMaterial().getTexture(1) != NULL)
material2 = material_manager->getMaterialFor(mb->getMaterial().getTexture(1), mb);
Material::ShaderType MatType = getMeshMaterialFromType(type, vt, material, material2);
if (!immediate_draw)
MeshSolidMaterial[MatType].push_back(&mesh);
}
}
isMaterialInitialized = true;
}
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (mb != NULL)
{
// Test if texture matrix needs to be updated every frame
const core::matrix4& mat = getMaterial(i).getTextureMatrix(0);
if (mat.isIdentity() && !m_got_animated_matrix)
continue;
else
{
m_got_animated_matrix = true;
GLmeshes[i].texture_trans.X = mat[8];
GLmeshes[i].texture_trans.Y = mat[9];
}
}
}
}
void STKMeshSceneNode::updateGL()
{
if (isGLInitialized)
return;
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
GLMesh &mesh = GLmeshes[i];
irr::video::IVideoDriver* driver = irr_driver->getVideoDriver();
video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType;
video::IMaterialRenderer* rnd = driver->getMaterialRenderer(type);
if (!rnd->isTransparent())
{
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
Material* material2 = NULL;
if (mb->getMaterial().getTexture(1) != NULL)
material2 = material_manager->getMaterialFor(mb->getMaterial().getTexture(1), mb);
Material::ShaderType MatType = getMeshMaterialFromType(type, mb->getVertexType(), material, material2);
if (!immediate_draw)
initTextures(mesh, MatType);
}
else if (!immediate_draw)
initTexturesTransparent(mesh);
fillLocalBuffer(mesh, mb);
mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, mb->getVertexType());
glBindVertexArray(0);
}
isGLInitialized = true;
}
void STKMeshSceneNode::OnRegisterSceneNode()
{
if (isDisplacement)
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
else
CMeshSceneNode::OnRegisterSceneNode();
}
void STKMeshSceneNode::render()
{
irr::video::IVideoDriver* driver = irr_driver->getVideoDriver();
if (!Mesh || !driver)
return;
++PassCount;
updateNoGL();
updateGL();
if (irr_driver->getPhase() == GLOW_PASS)
{
ColorizeShader::getInstance()->use();
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
glBindVertexArray(GLmeshes[i].vao);
drawGlow(GLmeshes[i]);
}
}
}
void STKMeshSceneNode::setIsDisplacement(bool v)
{
isDisplacement = v;
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
if (isDisplacement)
mb->getMaterial().MaterialType = Shaders::getShader(ES_DISPLACE);
}
}
#endif // !SERVER_ONLY

View File

@ -1,73 +0,0 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_STK_MESH_SCENE_NODE
#define HEADER_STK_MESH_SCENE_NODE
#include "graphics/stk_mesh.hpp"
#include "utils/ptr_vector.hpp"
class RenderInfo;
class STKMeshSceneNode : public irr::scene::CMeshSceneNode, public STKMeshCommon
{
protected:
PtrVector<RenderInfo> m_static_render_info;
bool m_got_animated_matrix;
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix;
core::vector3df windDir;
core::vector2df caustic_dir, caustic_dir2;
// Misc passes shaders (glow, displace...)
void drawGlow(const GLMesh &mesh);
void createGLMeshes(RenderInfo* render_info = NULL, bool all_parts_colorized = false);
void cleanGLMeshes();
void setFirstTimeMaterial();
void updatevbo();
bool isMaterialInitialized;
bool isGLInitialized;
bool immediate_draw;
bool additive;
bool update_each_frame;
bool isDisplacement;
bool isGlow;
video::SColor glowcolor;
public:
virtual void updateNoGL();
virtual void updateGL();
void setReloadEachFrame(bool);
STKMeshSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr,
irr::s32 id, const std::string& debug_name,
const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0),
const irr::core::vector3df& rotation = irr::core::vector3df(0, 0, 0),
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f),
bool createGLMeshes = true,
RenderInfo* render_info = NULL, bool all_parts_colorized = false);
virtual void render();
virtual void setMesh(irr::scene::IMesh* mesh);
virtual void OnRegisterSceneNode();
virtual ~STKMeshSceneNode();
virtual bool isImmediateDraw() const { return immediate_draw; }
void setIsDisplacement(bool v);
virtual bool glow() const { return isGlow; }
void setGlowColors(const video::SColor &c) { isGlow = true; glowcolor = c; }
video::SColor getGlowColor() const { return glowcolor; }
};
#endif