From c1eb0bbe738c3cd2fd08ec90973ec916cba37747 Mon Sep 17 00:00:00 2001 From: Elderme Date: Sat, 7 Nov 2015 22:10:32 +0100 Subject: [PATCH] Moved Materials definition in a separate Materials file --- src/graphics/command_buffer.cpp | 28 ++-- src/graphics/command_buffer.hpp | 10 +- src/graphics/draw_calls.cpp | 6 +- src/graphics/geometry_passes.cpp | 244 +------------------------------ src/graphics/material_type.cpp | 19 --- src/graphics/material_type.hpp | 66 --------- src/graphics/materials.cpp | 78 ++++++++++ src/graphics/materials.hpp | 234 +++++++++++++++++++++++++++++ 8 files changed, 341 insertions(+), 344 deletions(-) delete mode 100644 src/graphics/material_type.cpp delete mode 100644 src/graphics/material_type.hpp create mode 100644 src/graphics/materials.cpp create mode 100644 src/graphics/materials.hpp diff --git a/src/graphics/command_buffer.cpp b/src/graphics/command_buffer.cpp index 13b18c305..5e7df80a9 100644 --- a/src/graphics/command_buffer.cpp +++ b/src/graphics/command_buffer.cpp @@ -76,6 +76,7 @@ m_offset(NULL), m_size(NULL), m_poly_count(0) CommandBuffer::~CommandBuffer() { + delete[] m_meshes; glDeleteBuffers(1, &m_draw_indirect_cmd_id); delete[] m_offset; delete[] m_size; @@ -85,12 +86,11 @@ CommandBuffer::~CommandBuffer() template void CommandBuffer::fillMaterial(int material_id, MeshMap *mesh_map, - std::vector &instanced_list, T *instance_buffer) { m_offset[material_id] = m_command_buffer_offset; FillInstances(mesh_map[material_id], - instanced_list, + m_meshes[material_id], instance_buffer, m_draw_indirect_cmd, m_instance_buffer_offset, @@ -102,16 +102,24 @@ void CommandBuffer::fillMaterial(int material_id, SolidCommandBuffer::SolidCommandBuffer(): CommandBuffer() { + m_meshes = new std::vector[static_cast(Material::SHADERTYPE_COUNT)]; m_offset = new size_t[static_cast(Material::SHADERTYPE_COUNT)]; m_size = new size_t[static_cast(Material::SHADERTYPE_COUNT)]; } -void SolidCommandBuffer::fill(MeshMap *mesh_map, std::vector instanced_lists[]) +void SolidCommandBuffer::fill(MeshMap *mesh_map) { m_instance_buffer_offset = 0; m_command_buffer_offset = 0; m_poly_count = 0; + //clear meshes + for(int i=0;i instanced material_id = static_cast(dual_tex_materials[i]); fillMaterial( material_id, mesh_map, - instanced_lists[material_id], instance_buffer_dual_tex); } @@ -186,7 +193,6 @@ void SolidCommandBuffer::fill(MeshMap *mesh_map, std::vector instanced material_id = static_cast(three_tex_materials[i]); fillMaterial( material_id, mesh_map, - instanced_lists[material_id], instance_buffer_three_tex); } @@ -199,11 +205,12 @@ void SolidCommandBuffer::fill(MeshMap *mesh_map, std::vector instanced ShadowCommandBuffer::ShadowCommandBuffer(): CommandBuffer() { + m_meshes = new std::vector[4 * static_cast(Material::SHADERTYPE_COUNT)]; m_offset = new size_t[4 * static_cast(Material::SHADERTYPE_COUNT)]; m_size = new size_t[4 * static_cast(Material::SHADERTYPE_COUNT)]; } -void ShadowCommandBuffer::fill(MeshMap *mesh_map, std::vector instanced_lists[]) +void ShadowCommandBuffer::fill(MeshMap *mesh_map) { m_instance_buffer_offset = 0; m_command_buffer_offset = 0; @@ -247,7 +254,6 @@ void ShadowCommandBuffer::fill(MeshMap *mesh_map, std::vector instance material_id = cascade * 7 + static_cast(materials[i]); fillMaterial( material_id, mesh_map, - instanced_lists[material_id], shadow_instance_buffer); } } @@ -262,12 +268,13 @@ void ShadowCommandBuffer::fill(MeshMap *mesh_map, std::vector instance ReflectiveShadowMapCommandBuffer::ReflectiveShadowMapCommandBuffer(): CommandBuffer() { + m_meshes = new std::vector[static_cast(Material::SHADERTYPE_COUNT)]; m_offset = new size_t[static_cast(Material::SHADERTYPE_COUNT)]; m_size = new size_t[static_cast(Material::SHADERTYPE_COUNT)]; } -void ReflectiveShadowMapCommandBuffer::fill(MeshMap *mesh_map, std::vector instanced_lists[]) +void ReflectiveShadowMapCommandBuffer::fill(MeshMap *mesh_map) { m_instance_buffer_offset = 0; m_command_buffer_offset = 0; @@ -308,7 +315,6 @@ void ReflectiveShadowMapCommandBuffer::fill(MeshMap *mesh_map, std::vector(materials[i]); fillMaterial( material_id, mesh_map, - instanced_lists[material_id], rsm_instance_buffer); } @@ -322,11 +328,12 @@ void ReflectiveShadowMapCommandBuffer::fill(MeshMap *mesh_map, std::vector[1]; m_offset = new size_t[1]; m_size = new size_t[1]; } -void GlowCommandBuffer::fill(MeshMap *mesh_map, std::vector instanced_lists[]) +void GlowCommandBuffer::fill(MeshMap *mesh_map) { m_instance_buffer_offset = 0; m_command_buffer_offset = 0; @@ -354,7 +361,6 @@ void GlowCommandBuffer::fill(MeshMap *mesh_map, std::vector instanced_ fillMaterial( 0, mesh_map, - instanced_lists[0], glow_instance_buffer); if (!CVS->supportsAsyncInstanceUpload()) diff --git a/src/graphics/command_buffer.hpp b/src/graphics/command_buffer.hpp index 13a00dc3f..d3533072b 100644 --- a/src/graphics/command_buffer.hpp +++ b/src/graphics/command_buffer.hpp @@ -107,6 +107,7 @@ void FillInstances( const MeshMap &gathered_GL_mesh, class CommandBuffer { protected: + std::vector *m_meshes; GLuint m_draw_indirect_cmd_id; DrawElementsIndirectCommand *m_draw_indirect_cmd; size_t *m_offset; @@ -118,7 +119,6 @@ protected: template void fillMaterial(int material_id, MeshMap *mesh_map, - std::vector &instanced_list, T *instance_buffer); public: @@ -163,28 +163,28 @@ class SolidCommandBuffer: public CommandBuffer { public: SolidCommandBuffer(); - void fill(MeshMap *mesh_map, std::vector instanced_lists[]); + void fill(MeshMap *mesh_map); }; class ShadowCommandBuffer: public CommandBuffer { public: ShadowCommandBuffer(); - void fill(MeshMap *mesh_map, std::vector instanced_lists[]); + void fill(MeshMap *mesh_map); }; class ReflectiveShadowMapCommandBuffer: public CommandBuffer { public: ReflectiveShadowMapCommandBuffer(); - void fill(MeshMap *mesh_map, std::vector instanced_lists[]); + void fill(MeshMap *mesh_map); }; class GlowCommandBuffer: public CommandBuffer { public: GlowCommandBuffer(); - void fill(MeshMap *mesh_map, std::vector instanced_lists[]); + void fill(MeshMap *mesh_map); }; #endif //HEADER_COMMAND_BUFFER_HPP diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index 95fa50f11..b68ae589f 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -547,16 +547,16 @@ void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices, scene::ICamer { //TODO - std::vector instanced_lists[Material::SHADERTYPE_COUNT]; + /*std::vector instanced_lists[Material::SHADERTYPE_COUNT]; instanced_lists[static_cast(Material::SHADERTYPE_SOLID)] = ListInstancedMatDefault::getInstance()->SolidPass; instanced_lists[static_cast(Material::SHADERTYPE_ALPHA_TEST)] = ListInstancedMatAlphaRef::getInstance()->SolidPass; instanced_lists[static_cast(Material::SHADERTYPE_SOLID_UNLIT)] = ListInstancedMatUnlit::getInstance()->SolidPass; instanced_lists[static_cast(Material::SHADERTYPE_SPHERE_MAP)] = ListInstancedMatSphereMap::getInstance()->SolidPass; instanced_lists[static_cast(Material::SHADERTYPE_VEGETATION)] = ListInstancedMatGrass::getInstance()->SolidPass; instanced_lists[static_cast(Material::SHADERTYPE_DETAIL_MAP)] = ListInstancedMatDetails::getInstance()->SolidPass; - instanced_lists[static_cast(Material::SHADERTYPE_NORMAL_MAP)] = ListInstancedMatNormalMap::getInstance()->SolidPass; + instanced_lists[static_cast(Material::SHADERTYPE_NORMAL_MAP)] = ListInstancedMatNormalMap::getInstance()->SolidPass;*/ - m_solid_cmd_buffer.fill(m_solid_pass_mesh, instanced_lists); + m_solid_cmd_buffer.fill(m_solid_pass_mesh); size_t offset = 0, current_cmd = 0; diff --git a/src/graphics/geometry_passes.cpp b/src/graphics/geometry_passes.cpp index ab747f4a6..b5f3c7f22 100644 --- a/src/graphics/geometry_passes.cpp +++ b/src/graphics/geometry_passes.cpp @@ -19,6 +19,7 @@ #include "graphics/callbacks.hpp" #include "graphics/draw_tools.hpp" #include "graphics/glwrap.hpp" +#include "graphics/materials.hpp" #include "graphics/post_processing.hpp" #include "graphics/rtts.hpp" #include "graphics/shaders.hpp" @@ -513,125 +514,6 @@ public: } // NormalVisualizer }; // NormalVisualizer -// ============================================================================ -struct DefaultMaterial -{ - typedef InstancedObjectPass1Shader InstancedFirstPassShader; - typedef InstancedObjectPass2Shader InstancedSecondPassShader; - typedef InstancedShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatDefault InstancedList; - typedef Shaders::ObjectPass1Shader FirstPassShader; - typedef Shaders::ObjectPass2Shader SecondPassShader; - typedef ShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatDefault List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; - static const enum Material::ShaderType MaterialType - = Material::SHADERTYPE_SOLID; - static const enum InstanceType Instance = InstanceTypeDualTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple<> ShadowTextures; - static const STK::Tuple RSMTextures; -}; // struct DefaultMaterial - -const STK::Tuple DefaultMaterial::FirstPassTextures - = STK::Tuple(1); -const STK::Tuple DefaultMaterial::SecondPassTextures - = STK::Tuple(0, 1); -const STK::Tuple<> DefaultMaterial::ShadowTextures; -const STK::Tuple DefaultMaterial::RSMTextures = STK::Tuple(0); - -// ---------------------------------------------------------------------------- -struct AlphaRef -{ - typedef InstancedObjectRefPass1Shader InstancedFirstPassShader; - typedef InstancedObjectRefPass2Shader InstancedSecondPassShader; - typedef InstancedRefShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatAlphaRef InstancedList; - typedef ObjectRefPass1Shader FirstPassShader; - typedef ObjectRefPass2Shader SecondPassShader; - typedef RefShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatAlphaRef List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; - static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_ALPHA_TEST; - static const enum InstanceType Instance = InstanceTypeDualTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple ShadowTextures; - static const STK::Tuple RSMTextures; -}; // struct AlphaRef - -// ---------------------------------------------------------------------------- -const STK::Tuple AlphaRef::FirstPassTextures - = STK::Tuple(0, 1); -const STK::Tuple AlphaRef::SecondPassTextures - = STK::Tuple(0, 1); -const STK::Tuple AlphaRef::ShadowTextures = STK::Tuple(0); -const STK::Tuple AlphaRef::RSMTextures = STK::Tuple(0); - -// ---------------------------------------------------------------------------- -struct SphereMap -{ - typedef InstancedObjectPass1Shader InstancedFirstPassShader; - typedef InstancedSphereMapShader InstancedSecondPassShader; - typedef InstancedShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatSphereMap InstancedList; - typedef Shaders::ObjectPass1Shader FirstPassShader; - typedef SphereMapShader SecondPassShader; - typedef ShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatSphereMap List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; - static const enum Material::ShaderType MaterialType - = Material::SHADERTYPE_SPHERE_MAP; - static const enum InstanceType Instance = InstanceTypeDualTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple<> ShadowTextures; - static const STK::Tuple RSMTextures; -}; // struct SphereMap - -// ---------------------------------------------------------------------------- -const STK::Tuple SphereMap::FirstPassTextures = STK::Tuple(1); -const STK::Tuple SphereMap::SecondPassTextures = STK::Tuple(0); -const STK::Tuple<> SphereMap::ShadowTextures; -const STK::Tuple SphereMap::RSMTextures = STK::Tuple(0); - -// ---------------------------------------------------------------------------- -struct UnlitMat -{ - typedef InstancedObjectRefPass1Shader InstancedFirstPassShader; - typedef InstancedObjectUnlitShader InstancedSecondPassShader; - typedef InstancedRefShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatUnlit InstancedList; - typedef ObjectRefPass1Shader FirstPassShader; - typedef ObjectUnlitShader SecondPassShader; - typedef RefShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatUnlit List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; - static const enum Material::ShaderType MaterialType = - Material::SHADERTYPE_SOLID_UNLIT; - static const enum InstanceType Instance = InstanceTypeDualTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple ShadowTextures; - static const STK::Tuple RSMTextures; -}; // struct UnlitMat - -// ---------------------------------------------------------------------------- -const STK::Tuple UnlitMat::FirstPassTextures - = STK::Tuple(0, 1); -const STK::Tuple UnlitMat::SecondPassTextures = STK::Tuple(0); -const STK::Tuple UnlitMat::ShadowTextures = STK::Tuple(0); -const STK::Tuple UnlitMat::RSMTextures = STK::Tuple(0); - // ============================================================================ class GrassPass1Shader : public TextureShader @@ -802,128 +684,8 @@ public: } // InstancedDetailedObjectPass2Shader }; // InstancedDetailedObjectPass2Shader -// ============================================================================ - -// ---------------------------------------------------------------------------- -struct GrassMat -{ - typedef InstancedGrassPass1Shader InstancedFirstPassShader; - typedef InstancedGrassPass2Shader InstancedSecondPassShader; - typedef InstancedGrassShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatGrass InstancedList; - typedef GrassPass1Shader FirstPassShader; - typedef GrassPass2Shader SecondPassShader; - typedef GrassShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatGrass List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; - static const enum Material::ShaderType MaterialType - = Material::SHADERTYPE_VEGETATION; - static const enum InstanceType Instance = InstanceTypeDualTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple ShadowTextures; - static const STK::Tuple RSMTextures; -}; // GrassMat - -// ---------------------------------------------------------------------------- -const STK::Tuple GrassMat::FirstPassTextures - = STK::Tuple(0, 1); -const STK::Tuple GrassMat::SecondPassTextures - = STK::Tuple(0, 1); -const STK::Tuple GrassMat::ShadowTextures = STK::Tuple(0); -const STK::Tuple GrassMat::RSMTextures = STK::Tuple(0); - -// ---------------------------------------------------------------------------- -struct NormalMat -{ - typedef InstancedNormalMapShader InstancedFirstPassShader; - typedef InstancedObjectPass2Shader InstancedSecondPassShader; - typedef InstancedShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatNormalMap InstancedList; - typedef NormalMapShader FirstPassShader; - typedef Shaders::ObjectPass2Shader SecondPassShader; - typedef ShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatNormalMap List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_TANGENTS; - static const enum Material::ShaderType MaterialType - = Material::SHADERTYPE_NORMAL_MAP; - static const enum InstanceType Instance = InstanceTypeThreeTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple<> ShadowTextures; - static const STK::Tuple RSMTextures; -}; // NormalMat - -// ---------------------------------------------------------------------------- -const STK::Tuple NormalMat::FirstPassTextures - = STK::Tuple(2, 1); -const STK::Tuple NormalMat::SecondPassTextures - = STK::Tuple(0, 1); -const STK::Tuple<> NormalMat::ShadowTextures; -const STK::Tuple NormalMat::RSMTextures = STK::Tuple(0); - -// ---------------------------------------------------------------------------- -struct DetailMat -{ - typedef InstancedObjectPass1Shader InstancedFirstPassShader; - typedef InstancedDetailedObjectPass2Shader InstancedSecondPassShader; - typedef InstancedShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatDetails InstancedList; - typedef Shaders::ObjectPass1Shader FirstPassShader; - typedef DetailedObjectPass2Shader SecondPassShader; - typedef ShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatDetails List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS; - static const enum Material::ShaderType MaterialType - = Material::SHADERTYPE_DETAIL_MAP; - static const enum InstanceType Instance = InstanceTypeThreeTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple<> ShadowTextures; - static const STK::Tuple RSMTextures; -}; // DetailMat - -// ---------------------------------------------------------------------------- -const STK::Tuple DetailMat::FirstPassTextures = STK::Tuple(1); -const STK::Tuple DetailMat::SecondPassTextures - = STK::Tuple(0, 2, 1); -const STK::Tuple<> DetailMat::ShadowTextures; -const STK::Tuple DetailMat::RSMTextures = STK::Tuple(0); - -// ---------------------------------------------------------------------------- -struct SplattingMat -{ - typedef Shaders::ObjectPass1Shader FirstPassShader; - typedef SplattingShader SecondPassShader; - typedef ShadowShader ShadowPassShader; - typedef SplattingRSMShader RSMShader; - typedef ListMatSplatting List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple<> ShadowTextures; - static const STK::Tuple RSMTextures; -}; // SplattingMat - -// ---------------------------------------------------------------------------- - -const STK::Tuple SplattingMat::FirstPassTextures = STK::Tuple(6); -const STK::Tuple - SplattingMat::SecondPassTextures - = STK::Tuple(1, 2, 3, 4, 5); -const STK::Tuple<> SplattingMat::ShadowTextures; -const STK::Tuple SplattingMat::RSMTextures - = STK::Tuple(1, 2, 3, 4, 5); // ============================================================================ - - namespace RenderGeometry { struct TexUnit @@ -1014,6 +776,9 @@ void renderInstancedMeshes1stPass(const DrawCalls& draw_calls, Args...args) { std::vector &meshes = T::InstancedList::getInstance()->SolidPass; T::InstancedFirstPassShader::getInstance()->use(); + T::InstancedFirstPassShader::getInstance()->setUniforms(args...); + + glBindVertexArray(VAOManager::getInstance()->getInstanceVAO(T::VertexType, T::Instance)); for (unsigned i = 0; i < meshes.size(); i++) { @@ -1028,7 +793,6 @@ void renderInstancedMeshes1stPass(const DrawCalls& draw_calls, Args...args) #endif TexExpander::template expandTex(*mesh, T::FirstPassTextures); - T::InstancedFirstPassShader::getInstance()->setUniforms(args...); draw_calls.drawIndirectSolidCmd(T::MaterialType, i); } } // renderInstancedMeshes1stPass diff --git a/src/graphics/material_type.cpp b/src/graphics/material_type.cpp deleted file mode 100644 index 676eac172..000000000 --- a/src/graphics/material_type.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 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. - -#include "graphics/material_type.hpp" - diff --git a/src/graphics/material_type.hpp b/src/graphics/material_type.hpp deleted file mode 100644 index d3f57a08a..000000000 --- a/src/graphics/material_type.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 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_MATERIAL_TYPE_HPP -#define HEADER_MATERIAL_TYPE_HPP - -#include "graphics/shader.hpp" - -/* -struct MaterialType -{ - Shader *m_first_pass_shader; - Shader *m_second_pass_shader; - Shader *m_shadow_shader; - Shader *m_reflective_shadow_map_shader; - - Material::ShaderType m_shader_type; -};*/ - -/* -// ============================================================================ -struct DefaultMaterial -{ - typedef InstancedObjectPass1Shader InstancedFirstPassShader; - typedef InstancedObjectPass2Shader InstancedSecondPassShader; - typedef InstancedShadowShader InstancedShadowPassShader; - typedef CInstancedRSMShader InstancedRSMShader; - typedef ListInstancedMatDefault InstancedList; - typedef Shaders::ObjectPass1Shader FirstPassShader; - typedef Shaders::ObjectPass2Shader SecondPassShader; - typedef ShadowShader ShadowPassShader; - typedef CRSMShader RSMShader; - typedef ListMatDefault List; - static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; - static const enum Material::ShaderType MaterialType - = Material::SHADERTYPE_SOLID; - static const enum InstanceType Instance = InstanceTypeDualTex; - static const STK::Tuple FirstPassTextures; - static const STK::Tuple SecondPassTextures; - static const STK::Tuple<> ShadowTextures; - static const STK::Tuple RSMTextures; -}; // struct DefaultMaterial - -const STK::Tuple DefaultMaterial::FirstPassTextures - = STK::Tuple(1); -const STK::Tuple DefaultMaterial::SecondPassTextures - = STK::Tuple(0, 1); -const STK::Tuple<> DefaultMaterial::ShadowTextures; -const STK::Tuple DefaultMaterial::RSMTextures = STK::Tuple(0); -*/ - -#endif //HEADER_MATERIAL_TYPE_HPP diff --git a/src/graphics/materials.cpp b/src/graphics/materials.cpp new file mode 100644 index 000000000..17ba8d1fb --- /dev/null +++ b/src/graphics/materials.cpp @@ -0,0 +1,78 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 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. + +#include "graphics/materials.hpp" + +const STK::Tuple DefaultMaterial::FirstPassTextures + = STK::Tuple(1); +const STK::Tuple DefaultMaterial::SecondPassTextures + = STK::Tuple(0, 1); +const STK::Tuple<> DefaultMaterial::ShadowTextures; +const STK::Tuple DefaultMaterial::RSMTextures = STK::Tuple(0); + +// ---------------------------------------------------------------------------- +const STK::Tuple AlphaRef::FirstPassTextures + = STK::Tuple(0, 1); +const STK::Tuple AlphaRef::SecondPassTextures + = STK::Tuple(0, 1); +const STK::Tuple AlphaRef::ShadowTextures = STK::Tuple(0); +const STK::Tuple AlphaRef::RSMTextures = STK::Tuple(0); + +// ---------------------------------------------------------------------------- +const STK::Tuple SphereMap::FirstPassTextures = STK::Tuple(1); +const STK::Tuple SphereMap::SecondPassTextures = STK::Tuple(0); +const STK::Tuple<> SphereMap::ShadowTextures; +const STK::Tuple SphereMap::RSMTextures = STK::Tuple(0); + +// ---------------------------------------------------------------------------- +const STK::Tuple UnlitMat::FirstPassTextures + = STK::Tuple(0, 1); +const STK::Tuple UnlitMat::SecondPassTextures = STK::Tuple(0); +const STK::Tuple UnlitMat::ShadowTextures = STK::Tuple(0); +const STK::Tuple UnlitMat::RSMTextures = STK::Tuple(0); + +// ---------------------------------------------------------------------------- +const STK::Tuple GrassMat::FirstPassTextures + = STK::Tuple(0, 1); +const STK::Tuple GrassMat::SecondPassTextures + = STK::Tuple(0, 1); +const STK::Tuple GrassMat::ShadowTextures = STK::Tuple(0); +const STK::Tuple GrassMat::RSMTextures = STK::Tuple(0); + +// ---------------------------------------------------------------------------- +const STK::Tuple NormalMat::FirstPassTextures + = STK::Tuple(2, 1); +const STK::Tuple NormalMat::SecondPassTextures + = STK::Tuple(0, 1); +const STK::Tuple<> NormalMat::ShadowTextures; +const STK::Tuple NormalMat::RSMTextures = STK::Tuple(0); + +// ---------------------------------------------------------------------------- +const STK::Tuple DetailMat::FirstPassTextures = STK::Tuple(1); +const STK::Tuple DetailMat::SecondPassTextures + = STK::Tuple(0, 2, 1); +const STK::Tuple<> DetailMat::ShadowTextures; +const STK::Tuple DetailMat::RSMTextures = STK::Tuple(0); + +// ---------------------------------------------------------------------------- +const STK::Tuple SplattingMat::FirstPassTextures = STK::Tuple(6); +const STK::Tuple + SplattingMat::SecondPassTextures + = STK::Tuple(1, 2, 3, 4, 5); +const STK::Tuple<> SplattingMat::ShadowTextures; +const STK::Tuple SplattingMat::RSMTextures + = STK::Tuple(1, 2, 3, 4, 5); diff --git a/src/graphics/materials.hpp b/src/graphics/materials.hpp new file mode 100644 index 000000000..a8a742f86 --- /dev/null +++ b/src/graphics/materials.hpp @@ -0,0 +1,234 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 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_MATERIAL_TYPE_HPP +#define HEADER_MATERIAL_TYPE_HPP + +#include "graphics/shader.hpp" +#include "graphics/shaders.hpp" +#include "graphics/stk_mesh.hpp" +#include "graphics/vao_manager.hpp" + +class InstancedObjectPass1Shader; +class InstancedObjectPass2Shader; +class InstancedShadowShader; +class CInstancedRSMShader; +class ListInstancedMatDefault; +class ShadowShader; +class CRSMShader; +class InstancedObjectRefPass1Shader; +class InstancedObjectRefPass2Shader; +class InstancedRefShadowShader; +class ObjectRefPass1Shader; +class ObjectRefPass2Shader; +class RefShadowShader; +class InstancedSphereMapShader; +class SphereMapShader; +class InstancedObjectUnlitShader; +class ObjectUnlitShader; +class InstancedGrassPass1Shader; +class InstancedGrassPass2Shader; +class InstancedGrassShadowShader; +class GrassPass1Shader; +class GrassPass2Shader; +class GrassShadowShader; +class InstancedNormalMapShader; +class NormalMapShader; +class InstancedDetailedObjectPass2Shader; +class DetailedObjectPass2Shader; +class SplattingShader; +class SplattingRSMShader; + + +// ============================================================================ +struct DefaultMaterial +{ + typedef InstancedObjectPass1Shader InstancedFirstPassShader; + typedef InstancedObjectPass2Shader InstancedSecondPassShader; + typedef InstancedShadowShader InstancedShadowPassShader; + typedef CInstancedRSMShader InstancedRSMShader; + typedef ListInstancedMatDefault InstancedList; + typedef Shaders::ObjectPass1Shader FirstPassShader; + typedef Shaders::ObjectPass2Shader SecondPassShader; + typedef ShadowShader ShadowPassShader; + typedef CRSMShader RSMShader; + typedef ListMatDefault List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; + static const enum Material::ShaderType MaterialType + = Material::SHADERTYPE_SOLID; + static const enum InstanceType Instance = InstanceTypeDualTex; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple<> ShadowTextures; + static const STK::Tuple RSMTextures; +}; // struct DefaultMaterial + +// ---------------------------------------------------------------------------- +struct AlphaRef +{ + typedef InstancedObjectRefPass1Shader InstancedFirstPassShader; + typedef InstancedObjectRefPass2Shader InstancedSecondPassShader; + typedef InstancedRefShadowShader InstancedShadowPassShader; + typedef CInstancedRSMShader InstancedRSMShader; + typedef ListInstancedMatAlphaRef InstancedList; + typedef ObjectRefPass1Shader FirstPassShader; + typedef ObjectRefPass2Shader SecondPassShader; + typedef RefShadowShader ShadowPassShader; + typedef CRSMShader RSMShader; + typedef ListMatAlphaRef List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; + static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_ALPHA_TEST; + static const enum InstanceType Instance = InstanceTypeDualTex; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple ShadowTextures; + static const STK::Tuple RSMTextures; +}; // struct AlphaRef + +// ---------------------------------------------------------------------------- +struct SphereMap +{ + typedef InstancedObjectPass1Shader InstancedFirstPassShader; + typedef InstancedSphereMapShader InstancedSecondPassShader; + typedef InstancedShadowShader InstancedShadowPassShader; + typedef CInstancedRSMShader InstancedRSMShader; + typedef ListInstancedMatSphereMap InstancedList; + typedef Shaders::ObjectPass1Shader FirstPassShader; + typedef SphereMapShader SecondPassShader; + typedef ShadowShader ShadowPassShader; + typedef CRSMShader RSMShader; + typedef ListMatSphereMap List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; + static const enum Material::ShaderType MaterialType + = Material::SHADERTYPE_SPHERE_MAP; + static const enum InstanceType Instance = InstanceTypeDualTex; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple<> ShadowTextures; + static const STK::Tuple RSMTextures; +}; // struct SphereMap + +// ---------------------------------------------------------------------------- +struct UnlitMat +{ + typedef InstancedObjectRefPass1Shader InstancedFirstPassShader; + typedef InstancedObjectUnlitShader InstancedSecondPassShader; + typedef InstancedRefShadowShader InstancedShadowPassShader; + typedef CInstancedRSMShader InstancedRSMShader; + typedef ListInstancedMatUnlit InstancedList; + typedef ObjectRefPass1Shader FirstPassShader; + typedef ObjectUnlitShader SecondPassShader; + typedef RefShadowShader ShadowPassShader; + typedef CRSMShader RSMShader; + typedef ListMatUnlit List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; + static const enum Material::ShaderType MaterialType = + Material::SHADERTYPE_SOLID_UNLIT; + static const enum InstanceType Instance = InstanceTypeDualTex; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple ShadowTextures; + static const STK::Tuple RSMTextures; +}; // struct UnlitMat + +// ---------------------------------------------------------------------------- +struct GrassMat +{ + typedef InstancedGrassPass1Shader InstancedFirstPassShader; + typedef InstancedGrassPass2Shader InstancedSecondPassShader; + typedef InstancedGrassShadowShader InstancedShadowPassShader; + typedef CInstancedRSMShader InstancedRSMShader; + typedef ListInstancedMatGrass InstancedList; + typedef GrassPass1Shader FirstPassShader; + typedef GrassPass2Shader SecondPassShader; + typedef GrassShadowShader ShadowPassShader; + typedef CRSMShader RSMShader; + typedef ListMatGrass List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; + static const enum Material::ShaderType MaterialType + = Material::SHADERTYPE_VEGETATION; + static const enum InstanceType Instance = InstanceTypeDualTex; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple ShadowTextures; + static const STK::Tuple RSMTextures; +}; // GrassMat + +// ---------------------------------------------------------------------------- +struct NormalMat +{ + typedef InstancedNormalMapShader InstancedFirstPassShader; + typedef InstancedObjectPass2Shader InstancedSecondPassShader; + typedef InstancedShadowShader InstancedShadowPassShader; + typedef CInstancedRSMShader InstancedRSMShader; + typedef ListInstancedMatNormalMap InstancedList; + typedef NormalMapShader FirstPassShader; + typedef Shaders::ObjectPass2Shader SecondPassShader; + typedef ShadowShader ShadowPassShader; + typedef CRSMShader RSMShader; + typedef ListMatNormalMap List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_TANGENTS; + static const enum Material::ShaderType MaterialType + = Material::SHADERTYPE_NORMAL_MAP; + static const enum InstanceType Instance = InstanceTypeThreeTex; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple<> ShadowTextures; + static const STK::Tuple RSMTextures; +}; // NormalMat + +// ---------------------------------------------------------------------------- +struct DetailMat +{ + typedef InstancedObjectPass1Shader InstancedFirstPassShader; + typedef InstancedDetailedObjectPass2Shader InstancedSecondPassShader; + typedef InstancedShadowShader InstancedShadowPassShader; + typedef CInstancedRSMShader InstancedRSMShader; + typedef ListInstancedMatDetails InstancedList; + typedef Shaders::ObjectPass1Shader FirstPassShader; + typedef DetailedObjectPass2Shader SecondPassShader; + typedef ShadowShader ShadowPassShader; + typedef CRSMShader RSMShader; + typedef ListMatDetails List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS; + static const enum Material::ShaderType MaterialType + = Material::SHADERTYPE_DETAIL_MAP; + static const enum InstanceType Instance = InstanceTypeThreeTex; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple<> ShadowTextures; + static const STK::Tuple RSMTextures; +}; // DetailMat + +// ---------------------------------------------------------------------------- +struct SplattingMat +{ + typedef Shaders::ObjectPass1Shader FirstPassShader; + typedef SplattingShader SecondPassShader; + typedef ShadowShader ShadowPassShader; + typedef SplattingRSMShader RSMShader; + typedef ListMatSplatting List; + static const enum video::E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS; + static const STK::Tuple FirstPassTextures; + static const STK::Tuple SecondPassTextures; + static const STK::Tuple<> ShadowTextures; + static const STK::Tuple RSMTextures; +}; // SplattingMat + + + +#endif //HEADER_MATERIAL_TYPE_HPP