Removed KRMeshManager's first-frame hackery for loading static meshes. They now load systematically.
This commit is contained in:
@@ -108,6 +108,7 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
|
||||
m_pTextureManager = std::make_unique<KRTextureManager>(*this);
|
||||
m_pMaterialManager = std::make_unique<KRMaterialManager>(*this, m_pTextureManager.get(), m_pPipelineManager.get());
|
||||
m_pMeshManager = std::make_unique<KRMeshManager>(*this);
|
||||
m_pMeshManager->init();
|
||||
m_pSceneManager = std::make_unique<KRSceneManager>(*this);
|
||||
m_pAnimationManager = std::make_unique<KRAnimationManager>(*this);
|
||||
m_pAnimationCurveManager = std::make_unique<KRAnimationCurveManager>(*this);
|
||||
|
||||
@@ -211,21 +211,6 @@ void KRMesh::preStream(float lodCoverage)
|
||||
}
|
||||
}
|
||||
|
||||
void KRMesh::load()
|
||||
{
|
||||
// Load immediately into the GPU rather than passing through the streamer
|
||||
getSubmeshes();
|
||||
getMaterials();
|
||||
|
||||
int cSubmeshes = (int)m_submeshes.size();
|
||||
for(int iSubmesh=0; iSubmesh<cSubmeshes; iSubmesh++) {
|
||||
for(auto vbo_data_itr = m_submeshes[iSubmesh]->vbo_data_blocks.begin(); vbo_data_itr != m_submeshes[iSubmesh]->vbo_data_blocks.end(); vbo_data_itr++) {
|
||||
(*vbo_data_itr)->resetPoolExpiry(1.0f);
|
||||
(*vbo_data_itr)->load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kraken_stream_level KRMesh::getStreamLevel()
|
||||
{
|
||||
kraken_stream_level stream_level = kraken_stream_level::STREAM_LEVEL_IN_HQ;
|
||||
@@ -390,13 +375,13 @@ void KRMesh::createDataBlocks(KRMeshManager::KRVBOData::vbo_type t)
|
||||
}
|
||||
vbo_index++;
|
||||
|
||||
|
||||
int vertex_draw_count = cVertexes;
|
||||
if(vertex_draw_count > index_count - index_group_offset) vertex_draw_count = index_count - index_group_offset;
|
||||
|
||||
cVertexes -= vertex_draw_count;
|
||||
index_group_offset = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
int cBuffers = (vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE;
|
||||
int iVertex = pSubmesh->start_vertex;
|
||||
@@ -761,6 +746,12 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
|
||||
// ----
|
||||
|
||||
optimize();
|
||||
|
||||
if (m_constant) {
|
||||
// Ensure that constant models loaded immediately by the streamer
|
||||
getSubmeshes();
|
||||
getMaterials();
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 KRMesh::getMinPoint() const {
|
||||
|
||||
@@ -217,8 +217,6 @@ public:
|
||||
|
||||
static int GetLODCoverage(const std::string &name);
|
||||
|
||||
void load(); // Load immediately into the GPU rather than passing through the streamer
|
||||
|
||||
protected:
|
||||
bool m_constant; // TRUE if this should be always loaded and should not be passed through the streamer
|
||||
|
||||
|
||||
@@ -38,18 +38,22 @@
|
||||
#include "KRMeshQuad.h"
|
||||
#include "KRMeshSphere.h"
|
||||
|
||||
KRMeshManager::KRMeshManager(KRContext &context) : KRResourceManager(context) {
|
||||
m_currentVBO = NULL;
|
||||
m_vboMemUsed = 0;
|
||||
m_memoryTransferredThisFrame = 0;
|
||||
m_first_frame = true;
|
||||
m_streamerComplete = true;
|
||||
KRMeshManager::KRMeshManager(KRContext& context)
|
||||
: KRResourceManager(context)
|
||||
, m_currentVBO(NULL)
|
||||
, m_vboMemUsed(0)
|
||||
, m_memoryTransferredThisFrame(0)
|
||||
, m_streamerComplete(true)
|
||||
, m_draw_call_logging_enabled(false)
|
||||
, m_draw_call_log_used(false)
|
||||
{
|
||||
|
||||
addModel(new KRMeshCube(context));
|
||||
addModel(new KRMeshQuad(context));
|
||||
addModel(new KRMeshSphere(context));
|
||||
m_draw_call_logging_enabled = false;
|
||||
m_draw_call_log_used = false;
|
||||
}
|
||||
|
||||
void KRMeshManager::init() {
|
||||
addModel(new KRMeshCube(*m_pContext));
|
||||
addModel(new KRMeshQuad(*m_pContext));
|
||||
addModel(new KRMeshSphere(*m_pContext));
|
||||
|
||||
// ---- Initialize stock models ----
|
||||
static const GLfloat _KRENGINE_VBO_3D_CUBE_VERTEX_DATA[] = {
|
||||
@@ -215,11 +219,6 @@ void KRMeshManager::startFrame(float deltaTime)
|
||||
}
|
||||
m_draw_calls.clear();
|
||||
|
||||
if(m_first_frame) {
|
||||
m_first_frame = false;
|
||||
firstFrame();
|
||||
}
|
||||
|
||||
// TODO - Implement proper double-buffering to reduce copy operations
|
||||
m_streamerFenceMutex.lock();
|
||||
|
||||
@@ -232,7 +231,11 @@ void KRMeshManager::startFrame(float deltaTime)
|
||||
for(auto itr=m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) {
|
||||
KRVBOData *activeVBO = (*itr).second;
|
||||
activeVBO->_swapHandles();
|
||||
if(activeVBO->getLastFrameUsed() + KRENGINE_VBO_EXPIRY_FRAMES < getContext().getCurrentFrame()) {
|
||||
if (activeVBO->getType() == KRVBOData::CONSTANT) {
|
||||
// Ensure that CONSTANT data is always loaded
|
||||
float priority = std::numeric_limits<float>::max();
|
||||
m_activeVBOs_streamer_copy.push_back(std::pair<float, KRVBOData*>(priority, activeVBO));
|
||||
} else if(activeVBO->getLastFrameUsed() + KRENGINE_VBO_EXPIRY_FRAMES < getContext().getCurrentFrame()) {
|
||||
// Expire VBO's that haven't been used in a long time
|
||||
|
||||
switch(activeVBO->getType()) {
|
||||
@@ -248,11 +251,9 @@ void KRMeshManager::startFrame(float deltaTime)
|
||||
}
|
||||
|
||||
expiredVBOs.insert(activeVBO);
|
||||
} else {
|
||||
if(activeVBO->getType() == KRVBOData::STREAMING) {
|
||||
float priority = activeVBO->getStreamPriority();
|
||||
m_activeVBOs_streamer_copy.push_back(std::pair<float, KRVBOData *>(priority, activeVBO));
|
||||
}
|
||||
} else if(activeVBO->getType() == KRVBOData::STREAMING) {
|
||||
float priority = activeVBO->getStreamPriority();
|
||||
m_activeVBOs_streamer_copy.push_back(std::pair<float, KRVBOData *>(priority, activeVBO));
|
||||
}
|
||||
}
|
||||
for(std::set<KRVBOData *>::iterator itr=expiredVBOs.begin(); itr != expiredVBOs.end(); itr++) {
|
||||
@@ -272,16 +273,6 @@ void KRMeshManager::endFrame(float deltaTime)
|
||||
|
||||
}
|
||||
|
||||
void KRMeshManager::firstFrame()
|
||||
{
|
||||
KRENGINE_VBO_DATA_3D_CUBE_VERTICES.load();
|
||||
KRENGINE_VBO_DATA_2D_SQUARE_VERTICES.load();
|
||||
|
||||
getModel("__sphere")[0]->load();
|
||||
getModel("__cube")[0]->load();
|
||||
getModel("__quad")[0]->load();
|
||||
}
|
||||
|
||||
void KRMeshManager::doStreaming(long &memoryRemaining, long &memoryRemainingThisFrame)
|
||||
{
|
||||
|
||||
@@ -566,6 +557,10 @@ void KRMeshManager::KRVBOData::init(KRMeshManager *manager, KRDataBlock &data, K
|
||||
if(m_index_data != NULL) {
|
||||
m_size += m_index_data->getSize();
|
||||
}
|
||||
|
||||
if (t == KRVBOData::CONSTANT) {
|
||||
m_manager->primeVBO(this);
|
||||
}
|
||||
}
|
||||
|
||||
KRMeshManager::KRVBOData::~KRVBOData()
|
||||
@@ -647,6 +642,7 @@ void KRMeshManager::KRVBOData::load()
|
||||
|
||||
void KRMeshManager::KRVBOData::unload()
|
||||
{
|
||||
// TODO - We need to properly unload these in the streamer thread
|
||||
if(isVBOLoaded()) {
|
||||
m_manager->m_vboMemUsed -= getSize();
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
static const int KRENGINE_MAX_RANDOM_PARTICLES=150000;
|
||||
|
||||
KRMeshManager(KRContext &context);
|
||||
void init();
|
||||
virtual ~KRMeshManager();
|
||||
|
||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
||||
@@ -55,7 +56,6 @@ public:
|
||||
|
||||
void startFrame(float deltaTime);
|
||||
void endFrame(float deltaTime);
|
||||
void firstFrame();
|
||||
|
||||
KRMesh *loadModel(const char *szName, KRDataBlock *pData);
|
||||
std::vector<KRMesh *> getModel(const char *szName);
|
||||
@@ -198,8 +198,6 @@ private:
|
||||
bool m_draw_call_logging_enabled;
|
||||
bool m_draw_call_log_used;
|
||||
|
||||
bool m_first_frame;
|
||||
|
||||
std::mutex m_streamerFenceMutex;
|
||||
bool m_streamerComplete;
|
||||
|
||||
|
||||
@@ -170,6 +170,11 @@ void KRPresentationThread::renderFrame()
|
||||
// TODO - Add error handling...
|
||||
}
|
||||
|
||||
// TODO - This needs to be moved to the Render thread...
|
||||
float deltaTime = 0.005; // TODO - Replace dummy value
|
||||
m_pContext->startFrame(deltaTime);
|
||||
m_pContext->endFrame(deltaTime);
|
||||
|
||||
VkSubmitInfo submitInfo{};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user