Fixed coding style in stkmesh.
This commit is contained in:
parent
37d787ff38
commit
3cb0c6f4c2
@ -40,7 +40,7 @@
|
||||
You need to consider twice before adding a new material : in the worst case a material requires 8 shaders :
|
||||
one for each solid pass, one for shadow pass, one for RSM pass, and you need to double that for instanced version.
|
||||
|
||||
You need to declare a new enum in MeshMaterial and to write the corresponding dispatch code in MaterialTypeToMeshMaterial
|
||||
You need to declare a new enum in MeshMaterial and to write the corresponding dispatch code in getMeshMaterialFromType
|
||||
and to create 2 new List* structures (one for standard and one for instanced version).
|
||||
|
||||
Then you need to write the code in stkscenemanager.cpp that will add any mesh with the new material to their corresponding
|
||||
|
@ -121,12 +121,12 @@ void STKAnimatedMesh::updateNoGL()
|
||||
|
||||
if (rnd->isTransparent())
|
||||
{
|
||||
TransparentMaterial TranspMat = MaterialTypeToTransparentMaterial(type, MaterialTypeParam, material);
|
||||
TransparentMaterial TranspMat = getTransparentMaterialFromType(type, MaterialTypeParam, material);
|
||||
TransparentMesh[TranspMat].push_back(&mesh);
|
||||
}
|
||||
else
|
||||
{
|
||||
Material::ShaderType MatType = material->getShaderType();// MaterialTypeToMeshMaterial(type, mb->getVertexType(), material);
|
||||
Material::ShaderType MatType = material->getShaderType();// getMeshMaterialFromType(type, mb->getVertexType(), material);
|
||||
MeshSolidMaterial[MatType].push_back(&mesh);
|
||||
}
|
||||
}
|
||||
@ -167,11 +167,11 @@ void STKAnimatedMesh::updateGL()
|
||||
if (mb->getMaterial().getTexture(1) != NULL)
|
||||
material2 = material_manager->getMaterialFor(mb->getMaterial().getTexture(1), mb);
|
||||
|
||||
Material::ShaderType MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material, material2);
|
||||
InitTextures(mesh, MatType);
|
||||
Material::ShaderType MatType = getMeshMaterialFromType(type, mb->getVertexType(), material, material2);
|
||||
initTextures(mesh, MatType);
|
||||
}
|
||||
else
|
||||
InitTexturesTransparent(mesh);
|
||||
initTexturesTransparent(mesh);
|
||||
|
||||
if (CVS->isARBBaseInstanceUsable())
|
||||
{
|
||||
|
@ -32,10 +32,14 @@
|
||||
#include <IMaterialRenderer.h>
|
||||
|
||||
|
||||
Material::ShaderType MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE MaterialType, video::E_VERTEX_TYPE tp,
|
||||
Material* material, Material* layer2Material)
|
||||
// ============================================================================
|
||||
Material::ShaderType getMeshMaterialFromType(video::E_MATERIAL_TYPE material_type,
|
||||
video::E_VERTEX_TYPE tp,
|
||||
Material* material,
|
||||
Material* layer2_material)
|
||||
{
|
||||
if (layer2Material != NULL && layer2Material->getShaderType() == Material::SHADERTYPE_SPLATTING)
|
||||
if (layer2_material != NULL &&
|
||||
layer2_material->getShaderType() == Material::SHADERTYPE_SPLATTING)
|
||||
return Material::SHADERTYPE_SPLATTING;
|
||||
|
||||
switch (material->getShaderType())
|
||||
@ -43,15 +47,18 @@ Material::ShaderType MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE MaterialT
|
||||
default:
|
||||
return material->getShaderType();
|
||||
case Material::SHADERTYPE_SOLID:
|
||||
if (MaterialType == Shaders::getShader(ES_NORMAL_MAP))
|
||||
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 MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE type, f32 MaterialTypeParam, Material* material)
|
||||
// ----------------------------------------------------------------------------
|
||||
TransparentMaterial getTransparentMaterialFromType(video::E_MATERIAL_TYPE type,
|
||||
f32 MaterialTypeParam,
|
||||
Material* material)
|
||||
{
|
||||
if (type == Shaders::getShader(ES_DISPLACE))
|
||||
return TM_DISPLACEMENT;
|
||||
@ -60,6 +67,7 @@ TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE typ
|
||||
return TM_DEFAULT;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
video::E_VERTEX_TYPE getVTXTYPEFromStride(size_t stride)
|
||||
{
|
||||
if (stride == sizeof(video::S3DVertex))
|
||||
@ -68,8 +76,9 @@ video::E_VERTEX_TYPE getVTXTYPEFromStride(size_t stride)
|
||||
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;
|
||||
@ -82,53 +91,68 @@ GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type)
|
||||
case video::EVT_STANDARD:
|
||||
// Position
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), 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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
|
||||
getVertexPitchFromType(type), 0);
|
||||
// Normal
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)12);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
|
||||
getVertexPitchFromType(type), 0);
|
||||
// Normal
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)12);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE,
|
||||
getVertexPitchFromType(type), (GLvoid*)36);
|
||||
// Bitangent
|
||||
glEnableVertexAttribArray(6);
|
||||
glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)48);
|
||||
glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE,
|
||||
getVertexPitchFromType(type), (GLvoid*)48);
|
||||
break;
|
||||
default:
|
||||
assert(0 && "Wrong vertex type");
|
||||
@ -136,8 +160,9 @@ GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type)
|
||||
assert(idx);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx);
|
||||
return vao;
|
||||
}
|
||||
} // createVAO
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb, const std::string& debug_name)
|
||||
{
|
||||
GLMesh result = {};
|
||||
@ -202,10 +227,10 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb, const std::string& debug_name)
|
||||
result.TextureMatrix = 0;
|
||||
result.VAOType = mb->getVertexType();
|
||||
return result;
|
||||
}
|
||||
} // allocateMeshBuffer
|
||||
|
||||
static
|
||||
size_t getUnsignedSize(unsigned tp)
|
||||
// ----------------------------------------------------------------------------
|
||||
static size_t getUnsignedSize(unsigned tp)
|
||||
{
|
||||
switch (tp)
|
||||
{
|
||||
@ -217,8 +242,9 @@ size_t getUnsignedSize(unsigned tp)
|
||||
assert(0 && "Unsupported index type");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // getUnsignedSize
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void fillLocalBuffer(GLMesh &mesh, scene::IMeshBuffer* mb)
|
||||
{
|
||||
glBindVertexArray(0);
|
||||
@ -230,37 +256,41 @@ void fillLocalBuffer(GLMesh &mesh, scene::IMeshBuffer* mb)
|
||||
const u32 vertexCount = mb->getVertexCount();
|
||||
|
||||
const c8* vbuf = static_cast<const c8*>(vertices);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexCount * mesh.Stride, vbuf, GL_STREAM_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexCount * mesh.Stride, vbuf,
|
||||
GL_STREAM_DRAW);
|
||||
assert(vertexCount);
|
||||
|
||||
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);
|
||||
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 &ModelMatrix)
|
||||
// ----------------------------------------------------------------------------
|
||||
core::matrix4 computeMVP(const core::matrix4 &model_matrix)
|
||||
{
|
||||
core::matrix4 ModelViewProjectionMatrix = irr_driver->getProjMatrix();
|
||||
ModelViewProjectionMatrix *= irr_driver->getViewMatrix();
|
||||
ModelViewProjectionMatrix *= ModelMatrix;
|
||||
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);
|
||||
float m_speed = gsp->getSpeed();
|
||||
|
||||
return m_speed * vector3df(1., 0., 0.) * cos(time);
|
||||
}
|
||||
GrassShaderProvider *gsp =
|
||||
(GrassShaderProvider *)Shaders::getCallback(ES_GRASS);
|
||||
return (gsp->getSpeed() * cos(time)) * vector3df(1., 0., 0.);
|
||||
} // getWindDir
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool isObject(video::E_MATERIAL_TYPE type)
|
||||
{
|
||||
if (type == Shaders::getShader(ES_OBJECTPASS))
|
||||
@ -296,31 +326,38 @@ bool isObject(video::E_MATERIAL_TYPE type)
|
||||
if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
} // isObject
|
||||
|
||||
static void
|
||||
SetTexture(GLMesh &mesh, unsigned i, bool isSrgb, const std::string &matname)
|
||||
// ----------------------------------------------------------------------------
|
||||
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, matname.c_str());
|
||||
Log::error("STKMesh", "Missing texture %d for material %s", i,
|
||||
mat_name.c_str());
|
||||
// use unicolor texture to replace missing texture
|
||||
mesh.textures[i] = getUnicolorTexture(video::SColor(255, 127, 127, 127));
|
||||
mesh.textures[i] =
|
||||
getUnicolorTexture(video::SColor(255, 127, 127, 127));
|
||||
}
|
||||
compressTexture(mesh.textures[i], isSrgb);
|
||||
compressTexture(mesh.textures[i], is_srgb);
|
||||
if (CVS->isAZDOEnabled())
|
||||
{
|
||||
if (!mesh.TextureHandles[i])
|
||||
mesh.TextureHandles[i] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[i]), MeshShader::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
{
|
||||
mesh.TextureHandles[i] = glGetTextureSamplerHandleARB(
|
||||
getTextureGLuint(mesh.textures[i]),
|
||||
MeshShader::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
}
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[i]))
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[i]);
|
||||
}
|
||||
}
|
||||
} // setTexture
|
||||
|
||||
static std::string
|
||||
getShaderTypeName(Material::ShaderType Mat)
|
||||
// ----------------------------------------------------------------------------
|
||||
static std::string getShaderTypeName(Material::ShaderType mat)
|
||||
{
|
||||
switch (Mat)
|
||||
switch (mat)
|
||||
{
|
||||
default:
|
||||
case Material::SHADERTYPE_SOLID:
|
||||
@ -340,11 +377,12 @@ getShaderTypeName(Material::ShaderType Mat)
|
||||
case Material::SHADERTYPE_SPLATTING:
|
||||
return "Splatting";
|
||||
}
|
||||
}
|
||||
} // getShaderTypeName
|
||||
|
||||
void InitTextures(GLMesh &mesh, Material::ShaderType Mat)
|
||||
// ----------------------------------------------------------------------------
|
||||
void initTextures(GLMesh &mesh, Material::ShaderType mat)
|
||||
{
|
||||
switch (Mat)
|
||||
switch (mat)
|
||||
{
|
||||
default:
|
||||
case Material::SHADERTYPE_SOLID:
|
||||
@ -352,28 +390,29 @@ void InitTextures(GLMesh &mesh, Material::ShaderType Mat)
|
||||
case Material::SHADERTYPE_VEGETATION:
|
||||
case Material::SHADERTYPE_SPHERE_MAP:
|
||||
case Material::SHADERTYPE_SOLID_UNLIT:
|
||||
SetTexture(mesh, 0, true, getShaderTypeName(Mat));
|
||||
SetTexture(mesh, 1, false, getShaderTypeName(Mat));
|
||||
setTexture(mesh, 0, true, getShaderTypeName(mat));
|
||||
setTexture(mesh, 1, false, getShaderTypeName(mat));
|
||||
break;
|
||||
case Material::SHADERTYPE_DETAIL_MAP:
|
||||
case Material::SHADERTYPE_NORMAL_MAP:
|
||||
SetTexture(mesh, 0, true, getShaderTypeName(Mat));
|
||||
SetTexture(mesh, 1, false, getShaderTypeName(Mat));
|
||||
SetTexture(mesh, 2, false, getShaderTypeName(Mat));
|
||||
setTexture(mesh, 0, true, getShaderTypeName(mat));
|
||||
setTexture(mesh, 1, false, getShaderTypeName(mat));
|
||||
setTexture(mesh, 2, 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, 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));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // initTextures
|
||||
|
||||
void InitTexturesTransparent(GLMesh &mesh)
|
||||
// ----------------------------------------------------------------------------
|
||||
void initTexturesTransparent(GLMesh &mesh)
|
||||
{
|
||||
if (!mesh.textures[0])
|
||||
{
|
||||
@ -384,8 +423,12 @@ void InitTexturesTransparent(GLMesh &mesh)
|
||||
if (CVS->isAZDOEnabled())
|
||||
{
|
||||
if (!mesh.TextureHandles[0])
|
||||
mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), MeshShader::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
{
|
||||
mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(
|
||||
getTextureGLuint(mesh.textures[0]),
|
||||
MeshShader::ObjectPass1Shader::getInstance()->m_sampler_ids[0]);
|
||||
}
|
||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0]))
|
||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[0]);
|
||||
}
|
||||
}
|
||||
} // initTexturesTransparent
|
||||
|
@ -16,8 +16,8 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#ifndef STKMESH_H
|
||||
#define STKMESH_H
|
||||
#ifndef HEADER_STK_MESH_H
|
||||
#define HEADER_STK_MESH_H
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
@ -38,9 +38,10 @@ enum TransparentMaterial
|
||||
TM_ADDITIVE,
|
||||
TM_DISPLACEMENT,
|
||||
TM_COUNT
|
||||
};
|
||||
}; // TransparentMaterial
|
||||
|
||||
struct GLMesh {
|
||||
struct GLMesh
|
||||
{
|
||||
GLuint vao;
|
||||
GLuint vertex_buffer;
|
||||
GLuint index_buffer;
|
||||
@ -58,18 +59,20 @@ struct GLMesh {
|
||||
#ifdef DEBUG
|
||||
std::string debug_name;
|
||||
#endif
|
||||
};
|
||||
}; // GLMesh
|
||||
|
||||
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb, const std::string& debug_name);
|
||||
void fillLocalBuffer(GLMesh &, scene::IMeshBuffer* mb);
|
||||
// ----------------------------------------------------------------------------
|
||||
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb,
|
||||
const std::string& debug_name);
|
||||
void fillLocalBuffer(GLMesh &, scene::IMeshBuffer* mb);
|
||||
video::E_VERTEX_TYPE getVTXTYPEFromStride(size_t 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();
|
||||
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:
|
||||
@ -82,8 +85,9 @@ public:
|
||||
virtual void updateGL() = 0;
|
||||
virtual bool glow() const = 0;
|
||||
virtual bool isImmediateDraw() const { return false; }
|
||||
};
|
||||
}; // STKMeshCommon
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T, typename... Args>
|
||||
class MeshList : public Singleton<T>
|
||||
{
|
||||
@ -96,8 +100,9 @@ public:
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
Shadows[i].clear();
|
||||
}
|
||||
};
|
||||
}; // MeshList
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
class InstancedMeshList : public Singleton<T>
|
||||
{
|
||||
@ -110,90 +115,133 @@ public:
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
Shadows[i].clear();
|
||||
}
|
||||
};
|
||||
}; // InstancedMeshList
|
||||
|
||||
// -----------------------------------------Mat Default---------------------------------------------------- //
|
||||
class ListMatDefault : public MeshList<ListMatDefault, GLMesh *, core::matrix4, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatDefault : public MeshList<ListMatDefault, GLMesh *, core::matrix4,
|
||||
core::matrix4, core::matrix4>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedMatDefault : public InstancedMeshList<ListInstancedMatDefault>
|
||||
{};
|
||||
|
||||
|
||||
// -----------------------------------------Mat Alpha Ref---------------------------------------------------- //
|
||||
class ListMatAlphaRef : public MeshList<ListMatAlphaRef, GLMesh *, core::matrix4, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatAlphaRef : public MeshList<ListMatAlphaRef, GLMesh *, core::matrix4,
|
||||
core::matrix4, core::matrix4>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedMatAlphaRef : public InstancedMeshList<ListInstancedMatAlphaRef>
|
||||
{};
|
||||
|
||||
// -----------------------------------------Mat Normap Map---------------------------------------------------- //
|
||||
class ListMatNormalMap : public MeshList<ListMatNormalMap, GLMesh *, core::matrix4, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatNormalMap : public MeshList<ListMatNormalMap, GLMesh *, core::matrix4,
|
||||
core::matrix4, core::matrix4>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedMatNormalMap : public InstancedMeshList<ListInstancedMatNormalMap>
|
||||
{};
|
||||
|
||||
// -----------------------------------------Mat Grass---------------------------------------------------- //
|
||||
class ListMatGrass : public MeshList<ListMatGrass, GLMesh *, core::matrix4, core::matrix4, core::vector3df>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatGrass : public MeshList<ListMatGrass, GLMesh *, core::matrix4,
|
||||
core::matrix4, core::vector3df>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedMatGrass : public InstancedMeshList<ListInstancedMatGrass>
|
||||
{};
|
||||
|
||||
// -----------------------------------------Mat Sphere Map---------------------------------------------------- //
|
||||
class ListMatSphereMap : public MeshList<ListMatSphereMap, GLMesh *, core::matrix4, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatSphereMap : public MeshList<ListMatSphereMap, GLMesh *,
|
||||
core::matrix4, core::matrix4,
|
||||
core::matrix4>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedMatSphereMap : public InstancedMeshList<ListInstancedMatSphereMap>
|
||||
{};
|
||||
|
||||
// -----------------------------------------Mat Splatting---------------------------------------------------- //
|
||||
class ListMatSplatting : public MeshList<ListMatSplatting, GLMesh *, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatSplatting : public MeshList<ListMatSplatting, GLMesh *,
|
||||
core::matrix4, core::matrix4>
|
||||
{};
|
||||
|
||||
// -----------------------------------------Mat Unlit---------------------------------------------------- //
|
||||
class ListMatUnlit : public MeshList<ListMatUnlit, GLMesh *, core::matrix4, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatUnlit : public MeshList<ListMatUnlit, GLMesh *, core::matrix4,
|
||||
core::matrix4, core::matrix4>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedMatUnlit : public InstancedMeshList<ListInstancedMatUnlit>
|
||||
{};
|
||||
|
||||
// -----------------------------------------Mat Details---------------------------------------------------- //
|
||||
class ListMatDetails : public MeshList<ListMatDetails, GLMesh *, core::matrix4, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListMatDetails : public MeshList<ListMatDetails, GLMesh *, core::matrix4,
|
||||
core::matrix4, core::matrix4>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedMatDetails : public InstancedMeshList<ListInstancedMatDetails>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Transparent
|
||||
template <typename T, typename ...Args>
|
||||
class MiscList : public Singleton<T>, public std::vector<STK::Tuple<Args...> >
|
||||
{};
|
||||
|
||||
class ListBlendTransparent : public MiscList<ListBlendTransparent, GLMesh *, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListBlendTransparent : public MiscList<ListBlendTransparent, GLMesh *,
|
||||
core::matrix4, core::matrix4>
|
||||
{};
|
||||
|
||||
class ListAdditiveTransparent : public MiscList<ListAdditiveTransparent, GLMesh *, core::matrix4, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListAdditiveTransparent : public MiscList<ListAdditiveTransparent,
|
||||
GLMesh *, core::matrix4,
|
||||
core::matrix4>
|
||||
{};
|
||||
|
||||
class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog, GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog,
|
||||
GLMesh *, core::matrix4,
|
||||
core::matrix4, float, float,
|
||||
float, float, float,
|
||||
video::SColorf>
|
||||
{};
|
||||
|
||||
class ListAdditiveTransparentFog : public MiscList<ListAdditiveTransparentFog, GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListAdditiveTransparentFog : public MiscList<ListAdditiveTransparentFog,
|
||||
GLMesh *, core::matrix4,
|
||||
core::matrix4, float, float,
|
||||
float, float, float,
|
||||
video::SColorf>
|
||||
{};
|
||||
|
||||
class ListDisplacement : public MiscList<ListDisplacement, GLMesh *, core::matrix4>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListDisplacement : public MiscList<ListDisplacement, GLMesh *,
|
||||
core::matrix4>
|
||||
{};
|
||||
|
||||
class ListInstancedGlow : public Singleton<ListInstancedGlow>, public std::vector<GLMesh *>
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListInstancedGlow : public Singleton<ListInstancedGlow>
|
||||
, public std::vector<GLMesh *>
|
||||
{};
|
||||
|
||||
Material::ShaderType MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE MaterialType, video::E_VERTEX_TYPE tp,
|
||||
Material* material, Material* layer2Material);
|
||||
TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE, f32 MaterialTypeParam, Material* material);
|
||||
// ----------------------------------------------------------------------------
|
||||
Material::ShaderType getMeshMaterialFromType(video::E_MATERIAL_TYPE MaterialType,
|
||||
video::E_VERTEX_TYPE tp,
|
||||
Material* material,
|
||||
Material* layer2Material);
|
||||
// ----------------------------------------------------------------------------
|
||||
TransparentMaterial getTransparentMaterialFromType(video::E_MATERIAL_TYPE,
|
||||
f32 MaterialTypeParam,
|
||||
Material* material);
|
||||
|
||||
void InitTextures(GLMesh &mesh, Material::ShaderType);
|
||||
void InitTexturesTransparent(GLMesh &mesh);
|
||||
// ----------------------------------------------------------------------------
|
||||
void initTextures(GLMesh &mesh, Material::ShaderType);
|
||||
// ----------------------------------------------------------------------------
|
||||
void initTexturesTransparent(GLMesh &mesh);
|
||||
|
||||
#endif // STKMESH_H
|
||||
|
@ -157,7 +157,7 @@ void STKMeshSceneNode::updateNoGL()
|
||||
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
|
||||
if (rnd->isTransparent())
|
||||
{
|
||||
TransparentMaterial TranspMat = MaterialTypeToTransparentMaterial(type, MaterialTypeParam, material);
|
||||
TransparentMaterial TranspMat = getTransparentMaterialFromType(type, MaterialTypeParam, material);
|
||||
if (!immediate_draw)
|
||||
TransparentMesh[TranspMat].push_back(&mesh);
|
||||
else
|
||||
@ -169,7 +169,7 @@ void STKMeshSceneNode::updateNoGL()
|
||||
Material* material2 = NULL;
|
||||
if (mb->getMaterial().getTexture(1) != NULL)
|
||||
material2 = material_manager->getMaterialFor(mb->getMaterial().getTexture(1), mb);
|
||||
Material::ShaderType MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material, material2);
|
||||
Material::ShaderType MatType = getMeshMaterialFromType(type, mb->getVertexType(), material, material2);
|
||||
if (!immediate_draw)
|
||||
MeshSolidMaterial[MatType].push_back(&mesh);
|
||||
}
|
||||
@ -208,12 +208,12 @@ void STKMeshSceneNode::updateGL()
|
||||
Material* material2 = NULL;
|
||||
if (mb->getMaterial().getTexture(1) != NULL)
|
||||
material2 = material_manager->getMaterialFor(mb->getMaterial().getTexture(1), mb);
|
||||
Material::ShaderType MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material, material2);
|
||||
Material::ShaderType MatType = getMeshMaterialFromType(type, mb->getVertexType(), material, material2);
|
||||
if (!immediate_draw)
|
||||
InitTextures(mesh, MatType);
|
||||
initTextures(mesh, MatType);
|
||||
}
|
||||
else if (!immediate_draw)
|
||||
InitTexturesTransparent(mesh);
|
||||
initTexturesTransparent(mesh);
|
||||
|
||||
if (!immediate_draw && CVS->isARBBaseInstanceUsable())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user