Skip to content

Commit

Permalink
Mapblock mesh: Allow to use VBO
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBadAngel authored and paramat committed Feb 26, 2016
1 parent 8eb7ddb commit f9d7277
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
3 changes: 3 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ serverlist_file (Serverlist file) string favoriteservers.txt

[***Basic]

# Enable VBO
enable_vbo (VBO) bool true

# Whether to fog out the end of the visible area.
enable_fog (Fog) bool true

Expand Down
3 changes: 2 additions & 1 deletion src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ void set_default_settings(Settings *settings)
settings->setDefault("repeat_rightclick_time", "0.25");
settings->setDefault("enable_particles", "true");
settings->setDefault("enable_mesh_cache", "false");

settings->setDefault("enable_vbo", "true");

settings->setDefault("enable_minimap", "true");
settings->setDefault("minimap_shape_round", "true");
settings->setDefault("minimap_double_scan_height", "true");
Expand Down
28 changes: 19 additions & 9 deletions src/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
m_mesh(new scene::SMesh()),
m_minimap_mapblock(NULL),
m_gamedef(data->m_gamedef),
m_driver(m_gamedef->tsrc()->getDevice()->getVideoDriver()),
m_tsrc(m_gamedef->getTextureSource()),
m_shdrsrc(m_gamedef->getShaderSource()),
m_animation_force_timer(0), // force initial animation
Expand All @@ -1036,7 +1037,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
{
m_enable_shaders = data->m_use_shaders;
m_use_tangent_vertices = data->m_use_tangent_vertices;

m_enable_vbo = g_settings->getBool("enable_vbo");

if (g_settings->getBool("enable_minimap")) {
m_minimap_mapblock = new MinimapMapblock;
m_minimap_mapblock->getMinimapNodes(
Expand Down Expand Up @@ -1261,14 +1263,9 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
#endif

// Use VBO for mesh (this just would set this for ever buffer)
// This will lead to infinite memory usage because or irrlicht.
//m_mesh->setHardwareMappingHint(scene::EHM_STATIC);

/*
NOTE: If that is enabled, some kind of a queue to the main
thread should be made which would call irrlicht to delete
the hardware buffer and then delete the mesh
*/
if (m_enable_vbo) {
m_mesh->setHardwareMappingHint(scene::EHM_STATIC);
}
}

//std::cout<<"added "<<fastfaces.getSize()<<" faces."<<std::endl;
Expand All @@ -1282,6 +1279,12 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):

MapBlockMesh::~MapBlockMesh()
{
if (m_enable_vbo && m_mesh) {
for (u32 i = 0; i < m_mesh->getMeshBufferCount(); i++) {
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i);
m_driver->removeHardwareBuffer(buf);
}
}
m_mesh->drop();
m_mesh = NULL;
delete m_minimap_mapblock;
Expand Down Expand Up @@ -1362,6 +1365,10 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
// Day-night transition
if(!m_enable_shaders && (daynight_ratio != m_last_daynight_ratio))
{
// Force reload mesh to VBO
if (m_enable_vbo) {
m_mesh->setDirty();
}
for(std::map<u32, std::map<u32, std::pair<u8, u8> > >::iterator
i = m_daynight_diffs.begin();
i != m_daynight_diffs.end(); ++i)
Expand All @@ -1387,6 +1394,9 @@ void MapBlockMesh::updateCameraOffset(v3s16 camera_offset)
{
if (camera_offset != m_camera_offset) {
translateMesh(m_mesh, intToFloat(m_camera_offset-camera_offset, BS));
if (m_enable_vbo) {
m_mesh->setDirty();
}
m_camera_offset = camera_offset;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/mapblock_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ class MapBlockMesh
scene::IMesh *m_mesh;
MinimapMapblock *m_minimap_mapblock;
IGameDef *m_gamedef;
video::IVideoDriver *m_driver;
ITextureSource *m_tsrc;
IShaderSource *m_shdrsrc;

bool m_enable_shaders;
bool m_use_tangent_vertices;
bool m_enable_vbo;

// Must animate() be called before rendering?
bool m_has_animation;
Expand Down

0 comments on commit f9d7277

Please sign in to comment.