cleanup, fixed texture corruption bug

This commit is contained in:
SamGondelman 2016-06-29 13:33:33 -07:00
parent af2a0ed924
commit 15d09bb4fa
2 changed files with 22 additions and 20 deletions

View file

@ -84,20 +84,10 @@ void HmdDisplayPlugin::downloadFinished() {
return; return;
} }
QImage previewTexture; _previewTexture.loadFromData(reply->readAll());
previewTexture.loadFromData(reply->readAll());
if (!previewTexture.isNull()) { if (!_previewTexture.isNull()) {
previewTexture = previewTexture.mirrored(false, true); _previewAspect = ((float)_previewTexture.width())/((float)_previewTexture.height());
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.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; _firstPreview = true;
} }
} }
@ -286,7 +276,7 @@ void HmdDisplayPlugin::customizeContext() {
using namespace oglplus; using namespace oglplus;
if (!_enablePreview) { if (!_enablePreview) {
std::string version("#version 410 core\n"); const std::string version("#version 410 core\n");
compileProgram(_previewProgram, version + DrawUnitQuadTexcoord_vert, version + DrawTexture_frag); compileProgram(_previewProgram, version + DrawUnitQuadTexcoord_vert, version + DrawTexture_frag);
PREVIEW_TEXTURE_LOCATION = Uniform<int>(*_previewProgram, "colorMap").Location(); PREVIEW_TEXTURE_LOCATION = Uniform<int>(*_previewProgram, "colorMap").Location();
} }
@ -436,7 +426,18 @@ void HmdDisplayPlugin::internalPresent() {
BufferSelectBit::ColorBuffer, BlitFilter::Nearest); BufferSelectBit::ColorBuffer, BlitFilter::Nearest);
}); });
swapBuffers(); swapBuffers();
} else if (_previewTextureID != 0 && (_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);
glClearColor(0, 0, 0, 1); glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -446,7 +447,6 @@ 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;
} }

View file

@ -14,8 +14,6 @@
#include "../OpenGLDisplayPlugin.h" #include "../OpenGLDisplayPlugin.h"
class QNetworkReply;
class HmdDisplayPlugin : public OpenGLDisplayPlugin { class HmdDisplayPlugin : public OpenGLDisplayPlugin {
Q_OBJECT Q_OBJECT
using Parent = OpenGLDisplayPlugin; using Parent = OpenGLDisplayPlugin;
@ -97,13 +95,17 @@ private:
bool _monoPreview { true }; bool _monoPreview { true };
bool _enableReprojection { true }; bool _enableReprojection { true };
bool _firstPreview { true }; bool _firstPreview { true };
ProgramPtr _previewProgram; ProgramPtr _previewProgram;
QImage _previewTexture;
float _previewAspect { 0 };
GLuint _previewTextureID { 0 }; GLuint _previewTextureID { 0 };
glm::uvec2 _prevWindowSize { 0, 0 }; glm::uvec2 _prevWindowSize { 0, 0 };
qreal _prevDevicePixelRatio { 0 }; qreal _prevDevicePixelRatio { 0 };
float _previewAspect { 0 };
ShapeWrapperPtr _sphereSection;
ProgramPtr _reprojectionProgram; ProgramPtr _reprojectionProgram;
ShapeWrapperPtr _sphereSection;
ProgramPtr _laserProgram; ProgramPtr _laserProgram;
ShapeWrapperPtr _laserGeometry; ShapeWrapperPtr _laserGeometry;
}; };