mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:17:45 +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 <gl/GLWidget.h>
|
||||||
#include <shared/NsightHelpers.h>
|
#include <shared/NsightHelpers.h>
|
||||||
|
|
||||||
#include <NetworkAccessManager.h>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <gpu/DrawUnitQuadTexcoord_vert.h>
|
#include <gpu/DrawUnitQuadTexcoord_vert.h>
|
||||||
#include <gpu/DrawTexture_frag.h>
|
#include <gpu/DrawTexture_frag.h>
|
||||||
|
|
||||||
|
#include <PathUtils.h>
|
||||||
|
|
||||||
#include "../Logging.h"
|
#include "../Logging.h"
|
||||||
#include "../CompositorHelper.h"
|
#include "../CompositorHelper.h"
|
||||||
|
|
||||||
|
@ -65,33 +64,24 @@ bool HmdDisplayPlugin::internalActivate() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (_previewTextureID == 0) {
|
if (_previewTextureID == 0) {
|
||||||
const QUrl previewURL("https://hifi-content.s3.amazonaws.com/samuel/preview.png");
|
QImage previewTexture(PathUtils::resourcesPath() + "images/preview.png");
|
||||||
QNetworkAccessManager& manager = NetworkAccessManager::getInstance();
|
if (!previewTexture.isNull()) {
|
||||||
QNetworkRequest request(previewURL);
|
glGenTextures(1, &_previewTextureID);
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
glBindTexture(GL_TEXTURE_2D, _previewTextureID);
|
||||||
auto rep = manager.get(request);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, previewTexture.width(), previewTexture.height(), 0,
|
||||||
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));
|
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();
|
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() {
|
void HmdDisplayPlugin::internalDeactivate() {
|
||||||
if (_previewTextureID != 0) {
|
if (_previewTextureID != 0) {
|
||||||
glDeleteTextures(1, &_previewTextureID);
|
glDeleteTextures(1, &_previewTextureID);
|
||||||
|
@ -427,19 +417,8 @@ void HmdDisplayPlugin::internalPresent() {
|
||||||
});
|
});
|
||||||
swapBuffers();
|
swapBuffers();
|
||||||
} else if (_firstPreview || windowSize != _prevWindowSize || devicePixelRatio != _prevDevicePixelRatio) {
|
} 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);
|
useProgram(_previewProgram);
|
||||||
glEnable (GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
@ -449,6 +428,7 @@ void HmdDisplayPlugin::internalPresent() {
|
||||||
glBindTexture(GL_TEXTURE_2D, _previewTextureID);
|
glBindTexture(GL_TEXTURE_2D, _previewTextureID);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
swapBuffers();
|
swapBuffers();
|
||||||
|
_firstPreview = false;
|
||||||
_prevWindowSize = windowSize;
|
_prevWindowSize = windowSize;
|
||||||
_prevDevicePixelRatio = devicePixelRatio;
|
_prevDevicePixelRatio = devicePixelRatio;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "../OpenGLDisplayPlugin.h"
|
#include "../OpenGLDisplayPlugin.h"
|
||||||
|
|
||||||
class HmdDisplayPlugin : public OpenGLDisplayPlugin {
|
class HmdDisplayPlugin : public OpenGLDisplayPlugin {
|
||||||
Q_OBJECT
|
|
||||||
using Parent = OpenGLDisplayPlugin;
|
using Parent = OpenGLDisplayPlugin;
|
||||||
public:
|
public:
|
||||||
bool isHmd() const override final { return true; }
|
bool isHmd() const override final { return true; }
|
||||||
|
@ -87,9 +86,6 @@ protected:
|
||||||
FrameInfo _currentPresentFrameInfo;
|
FrameInfo _currentPresentFrameInfo;
|
||||||
FrameInfo _currentRenderFrameInfo;
|
FrameInfo _currentRenderFrameInfo;
|
||||||
|
|
||||||
public slots:
|
|
||||||
void downloadFinished();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _enablePreview { false };
|
bool _enablePreview { false };
|
||||||
bool _monoPreview { true };
|
bool _monoPreview { true };
|
||||||
|
@ -97,7 +93,6 @@ private:
|
||||||
bool _firstPreview { true };
|
bool _firstPreview { true };
|
||||||
|
|
||||||
ProgramPtr _previewProgram;
|
ProgramPtr _previewProgram;
|
||||||
QImage _previewTexture;
|
|
||||||
float _previewAspect { 0 };
|
float _previewAspect { 0 };
|
||||||
GLuint _previewTextureID { 0 };
|
GLuint _previewTextureID { 0 };
|
||||||
glm::uvec2 _prevWindowSize { 0, 0 };
|
glm::uvec2 _prevWindowSize { 0, 0 };
|
||||||
|
|
Loading…
Reference in a new issue