mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 02:16:51 +02:00
Rearrange model entity render to reduce flicker
This commit is contained in:
parent
3de5f73a1f
commit
984bacdae3
1 changed files with 39 additions and 37 deletions
|
@ -364,41 +364,16 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
assert(getType() == EntityTypes::Model);
|
assert(getType() == EntityTypes::Model);
|
||||||
|
|
||||||
if (hasModel()) {
|
if (hasModel()) {
|
||||||
if (_model) {
|
// Prepare the current frame
|
||||||
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
|
|
||||||
|
|
||||||
// check to see if when we added our models to the scene they were ready, if they were not ready, then
|
|
||||||
// fix them up in the scene
|
|
||||||
bool shouldShowCollisionHull = (args->_debugFlags & (int)RenderArgs::RENDER_DEBUG_HULLS) > 0;
|
|
||||||
if (_model->needsFixupInScene() || _showCollisionHull != shouldShowCollisionHull) {
|
|
||||||
_showCollisionHull = shouldShowCollisionHull;
|
|
||||||
render::PendingChanges pendingChanges;
|
|
||||||
|
|
||||||
_model->removeFromScene(scene, pendingChanges);
|
|
||||||
|
|
||||||
render::Item::Status::Getters statusGetters;
|
|
||||||
makeEntityItemStatusGetters(getThisPointer(), statusGetters);
|
|
||||||
_model->addToScene(scene, pendingChanges, statusGetters, _showCollisionHull);
|
|
||||||
|
|
||||||
scene->enqueuePendingChanges(pendingChanges);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: this seems like it could be optimized if we tracked our last known visible state in
|
|
||||||
// the renderable item. As it stands now the model checks it's visible/invisible state
|
|
||||||
// so most of the time we don't do anything in this function.
|
|
||||||
_model->setVisibleInScene(getVisible(), scene);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
remapTextures();
|
|
||||||
{
|
{
|
||||||
// float alpha = getLocalRenderAlpha();
|
|
||||||
|
|
||||||
if (!_model || _needsModelReload) {
|
if (!_model || _needsModelReload) {
|
||||||
// TODO: this getModel() appears to be about 3% of model render time. We should optimize
|
// TODO: this getModel() appears to be about 3% of model render time. We should optimize
|
||||||
PerformanceTimer perfTimer("getModel");
|
PerformanceTimer perfTimer("getModel");
|
||||||
EntityTreeRenderer* renderer = static_cast<EntityTreeRenderer*>(args->_renderer);
|
EntityTreeRenderer* renderer = static_cast<EntityTreeRenderer*>(args->_renderer);
|
||||||
getModel(renderer);
|
getModel(renderer);
|
||||||
|
|
||||||
|
// Remap textures immediately after loading to avoid flicker
|
||||||
|
remapTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_model) {
|
if (_model) {
|
||||||
|
@ -429,15 +404,42 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateModelBounds();
|
updateModelBounds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the URL has changed
|
// Enqueue updates for the next frame
|
||||||
// Do this last as the getModel is queued for the next frame,
|
if (_model) {
|
||||||
// and we need to keep state directing the model to reinitialize
|
|
||||||
auto& currentURL = getParsedModelURL();
|
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
|
||||||
if (currentURL != _model->getURL()) {
|
|
||||||
// Defer setting the url to the render thread
|
// FIXME: this seems like it could be optimized if we tracked our last known visible state in
|
||||||
getModel(_myRenderer);
|
// the renderable item. As it stands now the model checks it's visible/invisible state
|
||||||
}
|
// so most of the time we don't do anything in this function.
|
||||||
|
_model->setVisibleInScene(getVisible(), scene);
|
||||||
|
|
||||||
|
// Remap textures for the next frame to avoid flicker
|
||||||
|
remapTextures();
|
||||||
|
|
||||||
|
// check to see if when we added our models to the scene they were ready, if they were not ready, then
|
||||||
|
// fix them up in the scene
|
||||||
|
bool shouldShowCollisionHull = (args->_debugFlags & (int)RenderArgs::RENDER_DEBUG_HULLS) > 0;
|
||||||
|
if (_model->needsFixupInScene() || _showCollisionHull != shouldShowCollisionHull) {
|
||||||
|
_showCollisionHull = shouldShowCollisionHull;
|
||||||
|
render::PendingChanges pendingChanges;
|
||||||
|
|
||||||
|
_model->removeFromScene(scene, pendingChanges);
|
||||||
|
|
||||||
|
render::Item::Status::Getters statusGetters;
|
||||||
|
makeEntityItemStatusGetters(getThisPointer(), statusGetters);
|
||||||
|
_model->addToScene(scene, pendingChanges, statusGetters, _showCollisionHull);
|
||||||
|
|
||||||
|
scene->enqueuePendingChanges(pendingChanges);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& currentURL = getParsedModelURL();
|
||||||
|
if (currentURL != _model->getURL()) {
|
||||||
|
// Defer setting the url to the render thread
|
||||||
|
getModel(_myRenderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue