mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
embed image locally
This commit is contained in:
parent
057fc8adce
commit
d05a27e0e6
3 changed files with 17 additions and 42 deletions
BIN
interface/resources/images/preview.png
Normal file
BIN
interface/resources/images/preview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
|
@ -21,12 +21,11 @@
|
|||
#include <gl/GLWidget.h>
|
||||
#include <shared/NsightHelpers.h>
|
||||
|
||||
#include <NetworkAccessManager.h>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <gpu/DrawUnitQuadTexcoord_vert.h>
|
||||
#include <gpu/DrawTexture_frag.h>
|
||||
|
||||
#include <PathUtils.h>
|
||||
|
||||
#include "../Logging.h"
|
||||
#include "../CompositorHelper.h"
|
||||
|
||||
|
@ -65,33 +64,24 @@ bool HmdDisplayPlugin::internalActivate() {
|
|||
});
|
||||
|
||||
if (_previewTextureID == 0) {
|
||||
const QUrl previewURL("https://hifi-content.s3.amazonaws.com/samuel/preview.png");
|
||||
QNetworkAccessManager& manager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest request(previewURL);
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
auto rep = manager.get(request);
|
||||
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));
|
||||
QImage previewTexture(PathUtils::resourcesPath() + "images/preview.png");
|
||||
if (!previewTexture.isNull()) {
|
||||
glGenTextures(1, &_previewTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _previewTextureID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, previewTexture.width(), previewTexture.height(), 0,
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, previewTexture.mirrored(false, true).bits());
|
||||
using namespace oglplus;
|
||||
Texture::MinFilter(TextureTarget::_2D, TextureMinFilter::Linear);
|
||||
Texture::MagFilter(TextureTarget::_2D, TextureMagFilter::Linear);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
_previewAspect = ((float)previewTexture.width())/((float)previewTexture.height());
|
||||
_firstPreview = true;
|
||||
}
|
||||
}
|
||||
|
||||
return Parent::internalActivate();
|
||||
}
|
||||
|
||||
void HmdDisplayPlugin::downloadFinished() {
|
||||
QNetworkReply* reply = static_cast<QNetworkReply*>(sender());
|
||||
|
||||
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
||||
qDebug() << "HMDDisplayPlugin: error downloading preview image" << reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
_previewTexture.loadFromData(reply->readAll());
|
||||
|
||||
if (!_previewTexture.isNull()) {
|
||||
_previewAspect = ((float)_previewTexture.width())/((float)_previewTexture.height());
|
||||
_firstPreview = true;
|
||||
}
|
||||
}
|
||||
|
||||
void HmdDisplayPlugin::internalDeactivate() {
|
||||
if (_previewTextureID != 0) {
|
||||
glDeleteTextures(1, &_previewTextureID);
|
||||
|
@ -427,19 +417,8 @@ void HmdDisplayPlugin::internalPresent() {
|
|||
});
|
||||
swapBuffers();
|
||||
} else if (_firstPreview || windowSize != _prevWindowSize || devicePixelRatio != _prevDevicePixelRatio) {
|
||||
if (_firstPreview) {
|
||||
glGenTextures(1, &_previewTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _previewTextureID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _previewTexture.width(), _previewTexture.height(), 0,
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, _previewTexture.mirrored(false, true).bits());
|
||||
using namespace oglplus;
|
||||
Texture::MinFilter(TextureTarget::_2D, TextureMinFilter::Linear);
|
||||
Texture::MagFilter(TextureTarget::_2D, TextureMagFilter::Linear);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
_firstPreview = false;
|
||||
}
|
||||
useProgram(_previewProgram);
|
||||
glEnable (GL_BLEND);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
@ -449,6 +428,7 @@ void HmdDisplayPlugin::internalPresent() {
|
|||
glBindTexture(GL_TEXTURE_2D, _previewTextureID);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
swapBuffers();
|
||||
_firstPreview = false;
|
||||
_prevWindowSize = windowSize;
|
||||
_prevDevicePixelRatio = devicePixelRatio;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "../OpenGLDisplayPlugin.h"
|
||||
|
||||
class HmdDisplayPlugin : public OpenGLDisplayPlugin {
|
||||
Q_OBJECT
|
||||
using Parent = OpenGLDisplayPlugin;
|
||||
public:
|
||||
bool isHmd() const override final { return true; }
|
||||
|
@ -87,9 +86,6 @@ protected:
|
|||
FrameInfo _currentPresentFrameInfo;
|
||||
FrameInfo _currentRenderFrameInfo;
|
||||
|
||||
public slots:
|
||||
void downloadFinished();
|
||||
|
||||
private:
|
||||
bool _enablePreview { false };
|
||||
bool _monoPreview { true };
|
||||
|
@ -97,7 +93,6 @@ private:
|
|||
bool _firstPreview { true };
|
||||
|
||||
ProgramPtr _previewProgram;
|
||||
QImage _previewTexture;
|
||||
float _previewAspect { 0 };
|
||||
GLuint _previewTextureID { 0 };
|
||||
glm::uvec2 _prevWindowSize { 0, 0 };
|
||||
|
|
Loading…
Reference in a new issue