diff options
Diffstat (limited to 'src/render/backend/renderview.cpp')
-rw-r--r-- | src/render/backend/renderview.cpp | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp index bfdb68eb1..03f61b2d9 100644 --- a/src/render/backend/renderview.cpp +++ b/src/render/backend/renderview.cpp @@ -66,6 +66,7 @@ #include <Qt3DRender/private/buffermanager_p.h> #include <Qt3DRender/private/geometryrenderermanager_p.h> #include <Qt3DRender/private/rendercapture_p.h> +#include <Qt3DRender/private/buffercapture_p.h> #include <Qt3DRender/private/stringtoint_p.h> #include <Qt3DCore/qentity.h> #include <QtGui/qsurface.h> @@ -128,6 +129,8 @@ RenderView::StandardUniformsNameToTypeHash RenderView::initializeStandardUniform setters.insert(StringToInt::lookupId(QLatin1String("modelViewNormal")), ModelViewNormalMatrix); setters.insert(StringToInt::lookupId(QLatin1String("viewportMatrix")), ViewportMatrix); setters.insert(StringToInt::lookupId(QLatin1String("inverseViewportMatrix")), InverseViewportMatrix); + setters.insert(StringToInt::lookupId(QLatin1String("exposure")), Exposure); + setters.insert(StringToInt::lookupId(QLatin1String("gamma")), Gamma); setters.insert(StringToInt::lookupId(QLatin1String("time")), Time); setters.insert(StringToInt::lookupId(QLatin1String("eyePosition")), EyePosition); @@ -190,6 +193,10 @@ UniformValue RenderView::standardUniformValue(RenderView::StandardUniform standa viewportMatrix.viewport(resolveViewport(m_viewport, m_surfaceSize)); return UniformValue(viewportMatrix.inverted()); } + case Exposure: + return UniformValue(m_data.m_renderCameraLens->exposure()); + case Gamma: + return UniformValue(m_gamma); case Time: return UniformValue(float(m_renderer->time() / 1000000000.0f)); case EyePosition: @@ -201,9 +208,11 @@ UniformValue RenderView::standardUniformValue(RenderView::StandardUniform standa } RenderView::RenderView() - : m_renderer(nullptr) + : m_isDownloadBuffersEnable(false) + , m_renderer(nullptr) , m_devicePixelRatio(1.) , m_viewport(QRectF(0.0f, 0.0f, 1.0f, 1.0f)) + , m_gamma(2.2f) , m_surface(nullptr) , m_clearBuffer(QClearBuffers::None) , m_stateSet(nullptr) @@ -211,6 +220,7 @@ RenderView::RenderView() , m_compute(false) , m_frustumCulling(false) , m_memoryBarrier(QMemoryBarrier::None) + , m_environmentLight(nullptr) { m_workGroups[0] = 1; m_workGroups[1] = 1; @@ -352,6 +362,7 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit // is only accessed from the same thread UniformBlockValueBuilder *builder = new UniformBlockValueBuilder(); builder->shaderDataManager = m_manager->shaderDataManager(); + builder->textureManager = m_manager->textureManager(); m_localData.setLocalData(builder); QVector<RenderCommand *> commands; @@ -404,7 +415,12 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit ParameterInfoList globalParameters = passData.parameterInfo; // setShaderAndUniforms can initialize a localData // make sure this is cleared before we leave this function - setShaderAndUniforms(command, pass, globalParameters, *(node->worldTransform()), lightSources.mid(0, std::max(lightSources.size(), MAX_LIGHTS))); + setShaderAndUniforms(command, + pass, + globalParameters, + *(node->worldTransform()), + lightSources.mid(0, std::max(lightSources.size(), MAX_LIGHTS)), + m_environmentLight); // Store all necessary information for actual drawing if command is valid command->m_isValid = !command->m_attributes.empty(); @@ -470,6 +486,7 @@ QVector<RenderCommand *> RenderView::buildComputeRenderCommands(const QVector<En // is only accessed from the same thread UniformBlockValueBuilder *builder = new UniformBlockValueBuilder(); builder->shaderDataManager = m_manager->shaderDataManager(); + builder->textureManager = m_manager->textureManager(); m_localData.setLocalData(builder); // If the RenderView contains only a ComputeDispatch then it cares about @@ -503,7 +520,8 @@ QVector<RenderCommand *> RenderView::buildComputeRenderCommands(const QVector<En pass, globalParameters, *(node->worldTransform()), - QVector<LightSource>()); + QVector<LightSource>(), + nullptr); commands.append(command); } } @@ -579,7 +597,7 @@ void RenderView::setUniformBlockValue(ShaderParameterPack &uniformPack, // If two shaders define the same block with the exact same layout, in that case the UBO could be shared // but how do we know that ? We'll need to compare ShaderUniformBlocks - // Note: we assume that if a buffer is shared accross multiple shaders + // Note: we assume that if a buffer is shared across multiple shaders // then it implies that they share the same layout // Temporarly disabled @@ -691,7 +709,7 @@ void RenderView::buildSortingKey(RenderCommand *command) const } void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, ParameterInfoList ¶meters, const QMatrix4x4 &worldTransform, - const QVector<LightSource> &activeLightSources) const + const QVector<LightSource> &activeLightSources, EnvironmentLight *environmentLight) const { // The VAO Handle is set directly in the renderer thread so as to avoid having to use a mutex here // Set shader, technique, and effect by basically doing : @@ -812,13 +830,25 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, if (uniformNamesIds.contains(LIGHT_COUNT_NAME_ID)) setUniformValue(command->m_parameterPack, LIGHT_COUNT_NAME_ID, UniformValue(qMax(1, lightIdx))); - if (activeLightSources.isEmpty()) { + // If no active light sources and no environment light, add a default light + if (activeLightSources.isEmpty() && !environmentLight) { // Note: implicit conversion of values to UniformValue setUniformValue(command->m_parameterPack, LIGHT_POSITION_NAMES[0], QVector3D(10.0f, 10.0f, 0.0f)); setUniformValue(command->m_parameterPack, LIGHT_TYPE_NAMES[0], int(QAbstractLight::PointLight)); setUniformValue(command->m_parameterPack, LIGHT_COLOR_NAMES[0], QVector3D(1.0f, 1.0f, 1.0f)); setUniformValue(command->m_parameterPack, LIGHT_INTENSITY_NAMES[0], 0.5f); } + + // Environment Light + int envLightCount = 0; + if (environmentLight && environmentLight->isEnabled()) { + ShaderData *shaderData = m_manager->shaderDataManager()->lookupResource(environmentLight->shaderData()); + if (shaderData) { + setDefaultUniformBlockShaderDataValue(command->m_parameterPack, shader, shaderData, QStringLiteral("envLight")); + envLightCount = 1; + } + } + setUniformValue(command->m_parameterPack, StringToInt::lookupId(QStringLiteral("envLightCount")), envLightCount); } // Set frag outputs in the shaders if hash not empty if (!fragOutputs.isEmpty()) @@ -830,6 +860,16 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, } } +bool RenderView::isDownloadBuffersEnable() const +{ + return m_isDownloadBuffersEnable; +} + +void RenderView::setIsDownloadBuffersEnable(bool isDownloadBuffersEnable) +{ + m_isDownloadBuffersEnable = isDownloadBuffersEnable; +} + } // namespace Render } // namespace Qt3DRender |