2014-02-26 18:23:42 +00:00
|
|
|
#ifndef COMPONENTS_TERRAIN_BUFFERCACHE_H
|
|
|
|
#define COMPONENTS_TERRAIN_BUFFERCACHE_H
|
|
|
|
|
2015-06-02 23:18:36 +00:00
|
|
|
#include <osg/Array>
|
2016-02-19 14:00:50 +00:00
|
|
|
#include <osg/PrimitiveSet>
|
2015-06-02 23:18:36 +00:00
|
|
|
#include <osg/ref_ptr>
|
2014-02-26 18:23:42 +00:00
|
|
|
|
|
|
|
#include <map>
|
2020-06-25 19:46:07 +00:00
|
|
|
#include <mutex>
|
2014-02-26 18:23:42 +00:00
|
|
|
|
|
|
|
namespace Terrain
|
|
|
|
{
|
|
|
|
|
|
|
|
/// @brief Implements creation and caching of vertex buffers for terrain chunks.
|
|
|
|
class BufferCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// @param flags first 4*4 bits are LOD deltas on each edge, respectively (4 bits each)
|
|
|
|
/// next 4 bits are LOD level of the index buffer (LOD 0 = don't omit any vertices)
|
2016-02-09 19:57:30 +00:00
|
|
|
/// @note Thread safe.
|
2017-03-06 19:22:30 +00:00
|
|
|
osg::ref_ptr<osg::DrawElements> getIndexBuffer(unsigned int numVerts, unsigned int flags);
|
2014-02-26 18:23:42 +00:00
|
|
|
|
2016-02-09 19:57:30 +00:00
|
|
|
/// @note Thread safe.
|
2017-03-06 19:22:30 +00:00
|
|
|
osg::ref_ptr<osg::Vec2Array> getUVBuffer(unsigned int numVerts);
|
2015-06-02 23:18:36 +00:00
|
|
|
|
2017-08-21 02:34:41 +00:00
|
|
|
void clearCache();
|
|
|
|
|
2017-08-26 19:28:23 +00:00
|
|
|
void releaseGLObjects(osg::State* state);
|
2014-02-26 18:23:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Index buffers are shared across terrain batches where possible. There is one index buffer for each
|
|
|
|
// combination of LOD deltas and index buffer LOD we may need.
|
2017-03-06 19:22:30 +00:00
|
|
|
std::map<std::pair<int, int>, osg::ref_ptr<osg::DrawElements>> mIndexBufferMap;
|
2020-06-25 19:46:07 +00:00
|
|
|
std::mutex mIndexBufferMutex;
|
2014-02-26 18:23:42 +00:00
|
|
|
|
2015-06-02 23:18:36 +00:00
|
|
|
std::map<int, osg::ref_ptr<osg::Vec2Array>> mUvBufferMap;
|
2020-06-25 19:46:07 +00:00
|
|
|
std::mutex mUvBufferMutex;
|
2014-02-26 18:23:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|