possibly fix threading crashes, mirror and fade

This commit is contained in:
SamGondelman 2017-09-26 16:17:59 -07:00
parent 030da7d850
commit 49512c95d7
6 changed files with 51 additions and 43 deletions

View file

@ -18,7 +18,6 @@
using RenderArgsPointer = std::shared_ptr<RenderArgs>; using RenderArgsPointer = std::shared_ptr<RenderArgs>;
void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) { void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) {
task.addJob<RenderShadowTask>("RenderShadowTask", cullFunctor); task.addJob<RenderShadowTask>("RenderShadowTask", cullFunctor);
const auto items = task.addJob<RenderFetchCullSortTask>("FetchCullSort", cullFunctor); const auto items = task.addJob<RenderFetchCullSortTask>("FetchCullSort", cullFunctor);
assert(items.canCast<RenderFetchCullSortTask::Output>()); assert(items.canCast<RenderFetchCullSortTask::Output>());
@ -30,14 +29,6 @@ void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render
} }
class SecondaryCameraJob { // Changes renderContext for our framebuffer and view. class SecondaryCameraJob { // Changes renderContext for our framebuffer and view.
QUuid _attachedEntityId{};
glm::vec3 _position{};
glm::quat _orientation{};
float _vFoV{};
float _nearClipPlaneDistance{};
float _farClipPlaneDistance{};
EntityPropertyFlags _attachedEntityPropertyFlags;
QSharedPointer<EntityScriptingInterface> _entityScriptingInterface;
public: public:
using Config = SecondaryCameraJobConfig; using Config = SecondaryCameraJobConfig;
using JobModel = render::Job::ModelO<SecondaryCameraJob, RenderArgsPointer, Config>; using JobModel = render::Job::ModelO<SecondaryCameraJob, RenderArgsPointer, Config>;
@ -55,13 +46,15 @@ public:
_vFoV = config.vFoV; _vFoV = config.vFoV;
_nearClipPlaneDistance = config.nearClipPlaneDistance; _nearClipPlaneDistance = config.nearClipPlaneDistance;
_farClipPlaneDistance = config.farClipPlaneDistance; _farClipPlaneDistance = config.farClipPlaneDistance;
_textureWidth = config.textureWidth;
_textureHeight = config.textureHeight;
} }
void run(const render::RenderContextPointer& renderContext, RenderArgsPointer& cachedArgs) { void run(const render::RenderContextPointer& renderContext, RenderArgsPointer& cachedArgs) {
auto args = renderContext->args; auto args = renderContext->args;
auto textureCache = DependencyManager::get<TextureCache>(); auto textureCache = DependencyManager::get<TextureCache>();
gpu::FramebufferPointer destFramebuffer; gpu::FramebufferPointer destFramebuffer;
destFramebuffer = textureCache->getSpectatorCameraFramebuffer(); // FIXME: Change the destination based on some unimplemented config var destFramebuffer = textureCache->getSpectatorCameraFramebuffer(_textureWidth, _textureHeight); // FIXME: Change the destination based on some unimplemented config var
if (destFramebuffer) { if (destFramebuffer) {
_cachedArgsPointer->_blitFramebuffer = args->_blitFramebuffer; _cachedArgsPointer->_blitFramebuffer = args->_blitFramebuffer;
_cachedArgsPointer->_viewport = args->_viewport; _cachedArgsPointer->_viewport = args->_viewport;
@ -98,6 +91,18 @@ public:
protected: protected:
RenderArgs _cachedArgs; RenderArgs _cachedArgs;
RenderArgsPointer _cachedArgsPointer; RenderArgsPointer _cachedArgsPointer;
private:
QUuid _attachedEntityId;
glm::vec3 _position;
glm::quat _orientation;
float _vFoV;
float _nearClipPlaneDistance;
float _farClipPlaneDistance;
int _textureWidth;
int _textureHeight;
EntityPropertyFlags _attachedEntityPropertyFlags;
QSharedPointer<EntityScriptingInterface> _entityScriptingInterface;
}; };
void SecondaryCameraJobConfig::setPosition(glm::vec3 pos) { void SecondaryCameraJobConfig::setPosition(glm::vec3 pos) {
@ -123,16 +128,10 @@ void SecondaryCameraJobConfig::enableSecondaryCameraRenderConfigs(bool enabled)
setEnabled(enabled); setEnabled(enabled);
} }
void SecondaryCameraJobConfig::resetSizeSpectatorCamera(int width, int height) { // Carefully adjust the framebuffer / texture. void SecondaryCameraJobConfig::resetSizeSpectatorCamera(int width, int height) {
qApp->getRenderEngine()->getConfiguration()->getConfig<SecondaryCameraRenderTask>()->resetSize(width, height); textureWidth = width;
} textureHeight = height;
emit dirty();
void SecondaryCameraRenderTaskConfig::resetSize(int width, int height) { // FIXME: Add an arg here for "destinationFramebuffer"
bool wasEnabled = isEnabled();
setEnabled(false);
auto textureCache = DependencyManager::get<TextureCache>();
textureCache->resetSpectatorCameraFramebuffer(width, height); // FIXME: Call the correct reset function based on the "destinationFramebuffer" arg
setEnabled(wasEnabled);
} }
class EndSecondaryCameraFrame { // Restores renderContext. class EndSecondaryCameraFrame { // Restores renderContext.

View file

@ -18,7 +18,6 @@
#include <RenderDeferredTask.h> #include <RenderDeferredTask.h>
#include <RenderForwardTask.h> #include <RenderForwardTask.h>
class MainRenderTask { class MainRenderTask {
public: public:
using JobModel = render::Task::Model<MainRenderTask>; using JobModel = render::Task::Model<MainRenderTask>;
@ -37,12 +36,15 @@ class SecondaryCameraJobConfig : public render::Task::Config { // Exposes second
Q_PROPERTY(float nearClipPlaneDistance MEMBER nearClipPlaneDistance NOTIFY dirty) // Secondary camera's near clip plane distance. In meters. Q_PROPERTY(float nearClipPlaneDistance MEMBER nearClipPlaneDistance NOTIFY dirty) // Secondary camera's near clip plane distance. In meters.
Q_PROPERTY(float farClipPlaneDistance MEMBER farClipPlaneDistance NOTIFY dirty) // Secondary camera's far clip plane distance. In meters. Q_PROPERTY(float farClipPlaneDistance MEMBER farClipPlaneDistance NOTIFY dirty) // Secondary camera's far clip plane distance. In meters.
public: public:
QUuid attachedEntityId{}; QUuid attachedEntityId;
glm::vec3 position{}; glm::vec3 position;
glm::quat orientation{}; glm::quat orientation;
float vFoV{ DEFAULT_FIELD_OF_VIEW_DEGREES }; float vFoV { DEFAULT_FIELD_OF_VIEW_DEGREES };
float nearClipPlaneDistance{ DEFAULT_NEAR_CLIP }; float nearClipPlaneDistance { DEFAULT_NEAR_CLIP };
float farClipPlaneDistance{ DEFAULT_FAR_CLIP }; float farClipPlaneDistance { DEFAULT_FAR_CLIP };
int textureWidth { TextureCache::DEFAULT_SPECTATOR_CAM_WIDTH };
int textureHeight { TextureCache::DEFAULT_SPECTATOR_CAM_HEIGHT };
SecondaryCameraJobConfig() : render::Task::Config(false) {} SecondaryCameraJobConfig() : render::Task::Config(false) {}
signals: signals:
void dirty(); void dirty();
@ -59,9 +61,6 @@ class SecondaryCameraRenderTaskConfig : public render::Task::Config {
Q_OBJECT Q_OBJECT
public: public:
SecondaryCameraRenderTaskConfig() : render::Task::Config(false) {} SecondaryCameraRenderTaskConfig() : render::Task::Config(false) {}
void resetSize(int width, int height);
signals:
void dirty();
}; };
class SecondaryCameraRenderTask { class SecondaryCameraRenderTask {

View file

@ -1003,6 +1003,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(QUrl resourceTextureUrl)
if (_spectatorCameraFramebuffer) { if (_spectatorCameraFramebuffer) {
texture = _spectatorCameraFramebuffer->getRenderBuffer(0); texture = _spectatorCameraFramebuffer->getRenderBuffer(0);
if (texture) { if (texture) {
texture->setSource(SPECTATOR_CAMERA_FRAME_URL.toString().toStdString());
_spectatorCameraNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight()); _spectatorCameraNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight());
return _spectatorCameraNetworkTexture; return _spectatorCameraNetworkTexture;
} }
@ -1016,6 +1017,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(QUrl resourceTextureUrl)
if (_hmdPreviewFramebuffer) { if (_hmdPreviewFramebuffer) {
texture = _hmdPreviewFramebuffer->getRenderBuffer(0); texture = _hmdPreviewFramebuffer->getRenderBuffer(0);
if (texture) { if (texture) {
texture->setSource(HMD_PREVIEW_FRAME_URL.toString().toStdString());
_hmdPreviewNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight()); _hmdPreviewNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight());
return _hmdPreviewNetworkTexture; return _hmdPreviewNetworkTexture;
} }
@ -1033,14 +1035,18 @@ const gpu::FramebufferPointer& TextureCache::getHmdPreviewFramebuffer(int width,
} }
const gpu::FramebufferPointer& TextureCache::getSpectatorCameraFramebuffer() { const gpu::FramebufferPointer& TextureCache::getSpectatorCameraFramebuffer() {
// If we're taking a screenshot and the spectator cam buffer hasn't been created yet, reset to the default size
if (!_spectatorCameraFramebuffer) { if (!_spectatorCameraFramebuffer) {
resetSpectatorCameraFramebuffer(2048, 1024); return getSpectatorCameraFramebuffer(DEFAULT_SPECTATOR_CAM_WIDTH, DEFAULT_SPECTATOR_CAM_HEIGHT);
} }
return _spectatorCameraFramebuffer; return _spectatorCameraFramebuffer;
} }
void TextureCache::resetSpectatorCameraFramebuffer(int width, int height) { const gpu::FramebufferPointer& TextureCache::getSpectatorCameraFramebuffer(int width, int height) {
_spectatorCameraFramebuffer.reset(gpu::Framebuffer::create("spectatorCamera", gpu::Element::COLOR_SRGBA_32, width, height)); // If we aren't taking a screenshot, we might need to resize or create the camera buffer
_spectatorCameraNetworkTexture.reset(); if (!_spectatorCameraFramebuffer || _spectatorCameraFramebuffer->getWidth() != width || _spectatorCameraFramebuffer->getHeight() != height) {
emit spectatorCameraFramebufferReset(); _spectatorCameraFramebuffer.reset(gpu::Framebuffer::create("spectatorCamera", gpu::Element::COLOR_SRGBA_32, width, height));
emit spectatorCameraFramebufferReset();
}
return _spectatorCameraFramebuffer;
} }

View file

@ -167,12 +167,13 @@ public:
gpu::TexturePointer getTextureByHash(const std::string& hash); gpu::TexturePointer getTextureByHash(const std::string& hash);
gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture); gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture);
/// SpectatorCamera rendering targets.
NetworkTexturePointer getResourceTexture(QUrl resourceTextureUrl); NetworkTexturePointer getResourceTexture(QUrl resourceTextureUrl);
const gpu::FramebufferPointer& getSpectatorCameraFramebuffer();
void resetSpectatorCameraFramebuffer(int width, int height);
const gpu::FramebufferPointer& getHmdPreviewFramebuffer(int width, int height); const gpu::FramebufferPointer& getHmdPreviewFramebuffer(int width, int height);
const gpu::FramebufferPointer& getSpectatorCameraFramebuffer();
const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(int width, int height);
static const int DEFAULT_SPECTATOR_CAM_WIDTH { 2048 };
static const int DEFAULT_SPECTATOR_CAM_HEIGHT { 1024 };
signals: signals:
void spectatorCameraFramebufferReset(); void spectatorCameraFramebufferReset();

View file

@ -16,8 +16,7 @@
#include <PathUtils.h> #include <PathUtils.h>
FadeEffect::FadeEffect() { FadeEffect::FadeEffect() {
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
_maskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
} }
void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& editableItems) { void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& editableItems) {
@ -29,11 +28,15 @@ void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& edi
task.addJob<FadeEditJob>("FadeEdit", fadeEditInput); task.addJob<FadeEditJob>("FadeEdit", fadeEditInput);
} }
render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() const { render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() {
return [this](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args*) { return [this](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args*) {
auto program = shapePipeline.pipeline->getProgram(); auto program = shapePipeline.pipeline->getProgram();
auto maskMapLocation = program->getTextures().findLocation("fadeMaskMap"); auto maskMapLocation = program->getTextures().findLocation("fadeMaskMap");
auto bufferLocation = program->getUniformBuffers().findLocation("fadeParametersBuffer"); auto bufferLocation = program->getUniformBuffers().findLocation("fadeParametersBuffer");
if (!_maskMap) {
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
_maskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
}
batch.setResourceTexture(maskMapLocation, _maskMap); batch.setResourceTexture(maskMapLocation, _maskMap);
batch.setUniformBuffer(bufferLocation, _configurations); batch.setUniformBuffer(bufferLocation, _configurations);
}; };

View file

@ -21,7 +21,7 @@ public:
void build(render::Task::TaskConcept& task, const task::Varying& editableItems); void build(render::Task::TaskConcept& task, const task::Varying& editableItems);
render::ShapePipeline::BatchSetter getBatchSetter() const; render::ShapePipeline::BatchSetter getBatchSetter();
render::ShapePipeline::ItemSetter getItemUniformSetter() const; render::ShapePipeline::ItemSetter getItemUniformSetter() const;
render::ShapePipeline::ItemSetter getItemStoredSetter(); render::ShapePipeline::ItemSetter getItemStoredSetter();