From 682c9d8e7d05ca7462eda7fee9b07fb6ad94d860 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 17 Jun 2011 23:20:31 +0300 Subject: Moved stuff from mapblock{h,cpp} to mapblock_mesh.{h,cpp} and content_mapblock.{h,cpp} --- src/mapblock_mesh.h | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/mapblock_mesh.h (limited to 'src/mapblock_mesh.h') diff --git a/src/mapblock_mesh.h b/src/mapblock_mesh.h new file mode 100644 index 000000000..591172bc9 --- /dev/null +++ b/src/mapblock_mesh.h @@ -0,0 +1,143 @@ +/* +Minetest-c55 +Copyright (C) 2010-2011 celeron55, Perttu Ahola + +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 2 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., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef MAPBLOCK_MESH_HEADER +#define MAPBLOCK_MESH_HEADER + +#include "common_irrlicht.h" +#include "mapblock_nodemod.h" +#include "voxel.h" + +/* + Mesh making stuff +*/ + +/* + This is used because CMeshBuffer::append() is very slow +*/ +struct PreMeshBuffer +{ + video::SMaterial material; + core::array indices; + core::array vertices; +}; + +class MeshCollector +{ +public: + void append( + video::SMaterial material, + const video::S3DVertex* const vertices, + u32 numVertices, + const u16* const indices, + u32 numIndices + ) + { + PreMeshBuffer *p = NULL; + for(u32 i=0; ivertices.size(); + for(u32 i=0; i 65535) + { + dstream<<"FIXME: Meshbuffer ran out of indices"<indices.push_back(j); + } + for(u32 i=0; ivertices.push_back(vertices[i]); + } + } + + void fillMesh(scene::SMesh *mesh) + { + /*dstream<<"Filling mesh with "< + scene::SMeshBuffer *buf = new scene::SMeshBuffer(); + // Set material + buf->Material = p.material; + //((scene::SMeshBuffer*)buf)->Material = p.material; + // Use VBO + //buf->setHardwareMappingHint(scene::EHM_STATIC); + // Add to mesh + mesh->addMeshBuffer(buf); + // Mesh grabbed it + buf->drop(); + + buf->append(p.vertices.pointer(), p.vertices.size(), + p.indices.pointer(), p.indices.size()); + } + } + +private: + core::array m_prebuffers; +}; + +class MapBlock; + +struct MeshMakeData +{ + u32 m_daynight_ratio; + NodeModMap m_temp_mods; + VoxelManipulator m_vmanip; + v3s16 m_blockpos; + + /* + Copy central data directly from block, and other data from + parent of block. + */ + void fill(u32 daynight_ratio, MapBlock *block); +}; + +scene::SMesh* makeMapBlockMesh(MeshMakeData *data); + +#endif + -- cgit v1.2.3