mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 14:43:12 +02:00
working but often the spectator camera texture is not right.
This commit is contained in:
parent
f75cbfa087
commit
6d64261e94
3 changed files with 38 additions and 21 deletions
|
@ -30,7 +30,7 @@ void ResourceImageItem::setReady(bool ready) {
|
|||
if (ready != m_ready) {
|
||||
m_ready = ready;
|
||||
if (m_ready) {
|
||||
m_updateTimer.start(1000);
|
||||
m_updateTimer.start(100);
|
||||
} else {
|
||||
m_updateTimer.stop();
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ void ResourceImageItem::setReady(bool ready) {
|
|||
|
||||
void ResourceImageItemRenderer::synchronize(QQuickFramebufferObject* item) {
|
||||
ResourceImageItem* resourceImageItem = static_cast<ResourceImageItem*>(item);
|
||||
|
||||
bool urlChanged = false;
|
||||
if( _url != resourceImageItem->getUrl()) {
|
||||
_url = resourceImageItem->getUrl();
|
||||
|
@ -50,11 +51,27 @@ void ResourceImageItemRenderer::synchronize(QQuickFramebufferObject* item) {
|
|||
_ready = resourceImageItem->getReady();
|
||||
readyChanged = true;
|
||||
}
|
||||
|
||||
if (!_ready && readyChanged) {
|
||||
qDebug() << "clearing network texture!!!!!!!!!!!!!!!!!";
|
||||
_networkTexture.clear();
|
||||
}
|
||||
|
||||
_window = resourceImageItem->window();
|
||||
qDebug() << "synchronize called!!!!!!!";
|
||||
if (_ready && !_url.isNull() && !_url.isEmpty() && (readyChanged || urlChanged)) {
|
||||
if (_ready && !_url.isNull() && !_url.isEmpty() && (urlChanged || readyChanged || !_networkTexture)) {
|
||||
_networkTexture = DependencyManager::get<TextureCache>()->getTexture(_url);
|
||||
}
|
||||
|
||||
if (_networkTexture) {
|
||||
qDebug() << "copying texture";
|
||||
auto texture = _networkTexture->getGPUTexture();
|
||||
if (texture) {
|
||||
if (_fboMutex.tryLock()) {
|
||||
qApp->getActiveDisplayPlugin()->copyTextureToQuickFramebuffer(texture, framebufferObject());
|
||||
_fboMutex.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(const QSize& size) {
|
||||
|
@ -64,12 +81,7 @@ QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(con
|
|||
}
|
||||
|
||||
void ResourceImageItemRenderer::render() {
|
||||
qDebug() << "render called!!!!!!!!!!!!!!";
|
||||
if (_networkTexture && _ready) {
|
||||
auto texture = _networkTexture->getGPUTexture();
|
||||
if (texture) {
|
||||
qApp->getActiveDisplayPlugin()->copyTextureToQuickFramebuffer(texture, framebufferObject());
|
||||
_window->resetOpenGLState();
|
||||
}
|
||||
}
|
||||
_fboMutex.lock();
|
||||
_window->resetOpenGLState();
|
||||
_fboMutex.unlock();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,11 @@ public:
|
|||
private:
|
||||
bool _ready;
|
||||
QString _url;
|
||||
|
||||
NetworkTexturePointer _networkTexture;
|
||||
QQuickWindow* _window;
|
||||
QOpenGLFramebufferObject* _copyFbo;
|
||||
QMutex _fboMutex;
|
||||
};
|
||||
|
||||
class ResourceImageItem : public QQuickFramebufferObject {
|
||||
|
|
|
@ -221,7 +221,7 @@ gpu::TexturePointer TextureCache::cacheTextureByHash(const std::string& hash, co
|
|||
gpu::TexturePointer getFallbackTextureForType(image::TextureUsage::Type type) {
|
||||
gpu::TexturePointer result;
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
// Since this can be called on a background thread, there's a chance that the cache
|
||||
// Since this can be called on a background thread, there's a chance that the cache
|
||||
// will be destroyed by the time we request it
|
||||
if (!textureCache) {
|
||||
return result;
|
||||
|
@ -373,7 +373,7 @@ void NetworkTexture::makeRequest() {
|
|||
if (!_sourceIsKTX) {
|
||||
Resource::makeRequest();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We special-handle ktx requests to run 2 concurrent requests right off the bat
|
||||
PROFILE_ASYNC_BEGIN(resource, "Resource:" + getType(), QString::number(_requestID), { { "url", _url.toString() }, { "activeURL", _activeUrl.toString() } });
|
||||
|
@ -682,7 +682,7 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
|||
imageSizeRemaining -= (image._imageSize + ktx::IMAGE_SIZE_WIDTH);
|
||||
}
|
||||
|
||||
// We replace the texture with the one stored in the cache. This deals with the possible race condition of two different
|
||||
// We replace the texture with the one stored in the cache. This deals with the possible race condition of two different
|
||||
// images with the same hash being loaded concurrently. Only one of them will make it into the cache by hash first and will
|
||||
// be the winner
|
||||
texture = textureCache->cacheTextureByHash(filename, texture);
|
||||
|
@ -823,7 +823,7 @@ void ImageReader::read() {
|
|||
}
|
||||
}
|
||||
|
||||
// If we found the texture either because it's in use or via KTX deserialization,
|
||||
// If we found the texture either because it's in use or via KTX deserialization,
|
||||
// set the image and return immediately.
|
||||
if (texture) {
|
||||
QMetaObject::invokeMethod(resource.data(), "setImage",
|
||||
|
@ -862,7 +862,7 @@ void ImageReader::read() {
|
|||
const char* data = reinterpret_cast<const char*>(memKtx->_storage->data());
|
||||
size_t length = memKtx->_storage->size();
|
||||
auto& ktxCache = textureCache->_ktxCache;
|
||||
networkTexture->_file = ktxCache.writeFile(data, KTXCache::Metadata(hash, length)); //
|
||||
networkTexture->_file = ktxCache.writeFile(data, KTXCache::Metadata(hash, length)); //
|
||||
if (!networkTexture->_file) {
|
||||
qCWarning(modelnetworking) << _url << "file cache failed";
|
||||
} else {
|
||||
|
@ -872,7 +872,7 @@ void ImageReader::read() {
|
|||
qCWarning(modelnetworking) << "Unable to serialize texture to KTX " << _url;
|
||||
}
|
||||
|
||||
// We replace the texture with the one stored in the cache. This deals with the possible race condition of two different
|
||||
// We replace the texture with the one stored in the cache. This deals with the possible race condition of two different
|
||||
// images with the same hash being loaded concurrently. Only one of them will make it into the cache by hash first and will
|
||||
// be the winner
|
||||
texture = textureCache->cacheTextureByHash(hash, texture);
|
||||
|
@ -891,10 +891,12 @@ NetworkTexturePointer TextureCache::getResourceTexture(QUrl resourceTextureUrl)
|
|||
if (!_spectatorCameraNetworkTexture) {
|
||||
_spectatorCameraNetworkTexture.reset(new NetworkTexture(resourceTextureUrl));
|
||||
}
|
||||
texture = _spectatorCameraFramebuffer->getRenderBuffer(0);
|
||||
if (texture) {
|
||||
_spectatorCameraNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight());
|
||||
return _spectatorCameraNetworkTexture;
|
||||
if (_spectatorCameraFramebuffer) {
|
||||
texture = _spectatorCameraFramebuffer->getRenderBuffer(0);
|
||||
if (texture) {
|
||||
_spectatorCameraNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight());
|
||||
return _spectatorCameraNetworkTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue